oxidecomputer / humility

Debugger for Hubris
Mozilla Public License 2.0
529 stars 51 forks source link

humility hangs in hid_close() after failed USB transfer #466

Closed jclulow closed 7 months ago

jclulow commented 7 months ago

This humility invocation is reliably hanging on edgar right now:

edgar # pargs $(pgrep humility)
686:    humility hiffy -c Sequencer.get_state
argv[0]: humility
argv[1]: hiffy
argv[2]: -c
argv[3]: Sequencer.get_state

Long story short, we're hanging in hid_close() waiting for some event that will never arrive:

edgar # pstack $(pgrep humility) | demangle
686:    humility hiffy -c Sequencer.get_state
--------------------- thread# 1 / lwp# 1 ---------------------
 fffffc7fe7f4aa7a lwp_wait (6, fffffc7fffdf1abc)
 fffffc7fe7f3fbb8 _thrp_join (6, 0, 0, 1) + 168
 fffffc7fe7f3fc5f pthread_join (6, 0) + 2f
 000000000291dd3b hid_close () + 3b
 0000000002919482 <hidapi::HidDevice as core::ops::drop::Drop>::drop::hc2ceee22d996f5ec () + 12
 0000000002807aa6 probe_rs::probe::cmsisdap::CmsisDap::new_from_device::hc1d7ce7318b3d614 () + 316
 00000000021ef5ea <probe_rs::probe::cmsisdap::CmsisDap as probe_rs::probe::DebugProbe>::new_from_selector::ha22bd7c67f6ff832 () + 12a
 00000000022208d0 probe_rs::probe::Probe::open::h8f67aefa5a7fc578 () + 70
 00000000022688c4 humility_core::core::attach_to_chip::haf79f49127feb2e9 () + 594
 000000000225f8d2 humility_core::core::attach::h9ad2d2f438fdac03 () + 52
 00000000020f6b44 humility_cmd::attach_live::h896f2eec12a397b0 () + 84
 000000000165425d humility_cmd::attach::h84d6f52eae82d20d () + 1fd
 000000000165bdc3 humility::cmd::subcommand::h51158805441e4648 () + 483
 000000000165f9bd humility::main::h2d64e5203bc5454e () + b1d
 0000000001656736 std::sys_common::backtrace::__rust_begin_short_backtrace::h7b1b5b868d3f8ad1 () + 6
 0000000001656781 std::rt::lang_start::_$u7b$$u7b$closure$u7d$$u7d$::hb0bf6b8bb4a678bb (.llvm.15284836038652647814) () + 11
 0000000002a64a93 std::rt::lang_start_internal::h8e4b16a9f4a17dcc () + 2c3
 0000000001660663 main () + 33
 0000000001640f37 _start_crt () + 87
 0000000001640e98 _start () + 18

This is ultimately because of a failed libusb_submit_transfer() call, where the return code was totally ignored. This was apparently fixed in hidapi quite some time ago:

https://github.com/libusb/hidapi/commit/5ce9051e2f2e65013485bc4c83897610df82f3c9

I'm going to backport this fix to our stable hidapi branch.

jclulow commented 7 months ago

With the patch applied, humility exits promptly with an error message:

+ pfexec /tmp/humility hiffy -c Sequencer.get_state
humility hiffy failed: An error specific to a probe type occured

Caused by:
    0: Error handling CMSIS-DAP command Info
    1: Error in the USB HID access
    2: hidapi error: hid_error is not implemented yet
jclulow commented 7 months ago

There is now an oxide-stable branch of hidapi itself: https://github.com/oxidecomputer/hidapi/commits/oxide-stable/

I updated our oxide-stable branch of hidapi-rs to use it: https://github.com/oxidecomputer/hidapi-rs/commit/69f84deac74461bfc08adefd1feb8abe4fcdda26

And... I guess I have to make a PR here, sigh.