vadimcn / codelldb

A native debugger extension for VSCode based on LLDB
https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb
MIT License
2.43k stars 237 forks source link

"Invalid thread id" error when debugging (qemu gdb remote) #932

Closed kylewlacy closed 1 year ago

kylewlacy commented 1 year ago

OS: Ubuntu 22.04 via WSL remote (Windows 11) VSCode version: 1.78.1 CodeLLDB version: 1.9.1 (also tested against 1.9.0) Compiler: clang 15.0.6 Debuggee: Bare metal aarch64 assembly, via qemu + gdb-remote


I've been using CodeLLDB while debugging a small bare-metal aarch64 side project. A little over a week ago, I got my debugging setup working smoothly, and thoroughly tested setting breakpoints, continuing/pausing execution, setting watch expressions, and stepping in/out/over lines of code. I put the project on pause for a few days, but I found that when I came back to it, my debugging setup had broken. In the meantime, I believe both CodeLLDB and VS Code had been updated, but I don't believe I had updated any other relevant packages on my system (but I may be wrong about that). I can't seem to figure out if there's some setting I need to change to get things working again, but I believe this could be a bug in CodeLLDB itself (maybe caused by an upstream VSCode change)? The relevant log line I see now is the following (full log output also provided):

[ERROR codelldb::debug_session] Received invalid thread id in step request.
[ERROR codelldb::debug_session] Internal debugger error: Invalid thread id.

I also created a small example repo that should reliably reproduce this issue here: https://github.com/kylewlacy/codelldb-demo-qemu (requires qemu-system-aarch64, clang, lld, objcopy, and make).

Steps to reproduce

  1. Clone the example repo and open it as a VS Code workspace
  2. Set a breakpoint on asm/raspi3/boot.S:6
  3. Run the "Debug: Start Debugging" action (F5). The debugging session should start paused on address 0x00000000 (this is expected).
  4. Press "Continue" on the debug panel (F5), followed by "Step over" (F10)

Expected outcome

"Continue" should have continued debugging, or "Step over" should have jumped over a single asm instruction. Either button previously had worked exactly as expected.

Actual outcome

Neither "Continue" nor "Step over" seem to do anything in the debug session. Clicking both is what seems to lead to the above log message, for some reason.


Standard log output
Initial debug configuration: {
  type: 'lldb',
  sourceLanguages: [ 'rust' ],
  name: 'Debug (Raspberry Pi 3B+)',
  request: 'custom',
  preLaunchTask: 'make raspi3-emu-gdb',
  targetCreateCommands: [ 'target create ${workspaceFolder}/build/raspi3/kernel8.elf' ],
  processCreateCommands: [ 'gdb-remote localhost:1234' ],
  __configurationTarget: 6
}
Resolved debug configuration: {
  type: 'lldb',
  sourceLanguages: [ 'rust' ],
  name: 'Debug (Raspberry Pi 3B+)',
  request: 'launch',
  preLaunchTask: 'make raspi3-emu-gdb',
  targetCreateCommands: [ 'target create ${workspaceFolder}/build/raspi3/kernel8.elf' ],
  processCreateCommands: [ 'gdb-remote localhost:1234' ],
  __configurationTarget: 6,
  custom: true,
  relativePathBase: '/home/kyle/Development/Projects/codelldb-demo-qemu',
  _adapterSettings: {
    displayFormat: 'auto',
    showDisassembly: 'auto',
    dereferencePointers: true,
    suppressMissingSourceFiles: true,
    evaluationTimeout: 5,
    consoleMode: 'commands',
    sourceLanguages: null,
    terminalPromptClear: null,
    evaluateForHovers: true,
    commandCompletions: true,
    reproducer: false
  }
}
[ERROR codelldb::debug_session] Received invalid thread id in step request.
[ERROR codelldb::debug_session] Internal debugger error: Invalid thread id.
Verbose log
...truncated...

[DEBUG codelldb::dap_codec] <-- {"seq":120,"type":"event","event":"output","body":{"output":"codelldb         <   1> read packet: +\ncodelldb         <  20> read packet: $0000000000000000#00\n"}}
[DEBUG codelldb::dap_codec] <-- {"seq":121,"type":"event","event":"output","body":{"output":"codelldb         <   1> send packet: +\n"}}
[DEBUG codelldb::dap_codec] <-- {"seq":122,"type":"event","event":"output","body":{"output":"tokio-runtime-w  <  16> send packet: $jThreadsInfo#c1\n"}}
[DEBUG codelldb::debug_session] gdb-remote localhost:1234 -> SuccessFinishNoResult, Error:  Success
[DEBUG codelldb::dap_codec] <-- {"seq":123,"type":"event","event":"output","body":{"output":"tokio-runtime-w  <   1> read packet: +\ntokio-runtime-w  <   4> read packet: $#00\n"}}
[DEBUG codelldb::dap_codec] <-- {"seq":124,"type":"event","event":"output","body":{"category":"stderr","output":"Stop reason: signal SIGTRAP\n"}}
[DEBUG codelldb::dap_codec] <-- {"seq":125,"type":"event","event":"stopped","body":{"allThreadsStopped":true,"reason":"signal","text":"signal SIGTRAP","threadId":1}}
[DEBUG codelldb::dap_codec] <-- {"seq":126,"type":"event","event":"output","body":{"output":"tokio-runtime-w  <   1> send packet: +\n"}}
[DEBUG codelldb::debug_session] Debug event: 0x55f93491b5e8 Event: broadcaster = 0x55f9344fa0d0 (lldb.target), type = 0x00000002 (modules-loaded), data = {kernel8.elf}
[DEBUG codelldb::dap_codec] <-- {"seq":127,"type":"response","request_seq":2,"success":true,"command":"launch"}
[DEBUG codelldb::debug_session] Debug event: 0x55f9338ce8d0 Event: broadcaster = 0x55f93493a5c8 (lldb.process), type = 0x00000001 (state-changed), data = { process = 0x55f93493a590 (pid = 1), state = stopped}
[DEBUG codelldb::dap_codec] <-- {"seq":128,"type":"response","request_seq":8,"success":true,"command":"configurationDone"}
[DEBUG codelldb::dap_codec] <-- {"seq":129,"type":"event","event":"module","body":{"module":{"addressRange":"80000","id":"80000","name":"kernel8.elf","path":"/home/kyle/Development/Projects/codelldb-demo-qemu/build/raspi3/kernel8.elf","symbolFilePath":"/home/kyle/Development/Projects/codelldb-demo-qemu/build/raspi3/kernel8.elf","symbolStatus":"Symbols loaded."},"reason":"new"}}
[DEBUG codelldb::dap_codec] <-- {"seq":130,"type":"event","event":"output","body":{"category":"stderr","output":"Stop reason: signal SIGTRAP\n"}}
[DEBUG codelldb::dap_codec] <-- {"seq":131,"type":"event","event":"stopped","body":{"allThreadsStopped":true,"reason":"signal","text":"signal SIGTRAP","threadId":1}}
[DEBUG codelldb::dap_codec] --> {"command":"threads","type":"request","seq":9}
[DEBUG codelldb::dap_codec] <-- {"seq":132,"type":"response","request_seq":9,"success":true,"command":"threads","body":{"threads":[{"id":1,"name":"1: tid=1"},{"id":2,"name":"2: tid=2"},{"id":3,"name":"3: tid=3"},{"id":4,"name":"4: tid=4"}]}}
[DEBUG codelldb::dap_codec] --> {"command":"threads","type":"request","seq":10}
[DEBUG codelldb::dap_codec] <-- {"seq":133,"type":"response","request_seq":10,"success":true,"command":"threads","body":{"threads":[{"id":1,"name":"1: tid=1"},{"id":2,"name":"2: tid=2"},{"id":3,"name":"3: tid=3"},{"id":4,"name":"4: tid=4"}]}}
[DEBUG codelldb::dap_codec] --> {"command":"stackTrace","arguments":{"threadId":1,"startFrame":0,"levels":1},"type":"request","seq":11}
[DEBUG codelldb::disassembly] 0x00000000
[DEBUG codelldb::dap_codec] <-- {"seq":134,"type":"event","event":"output","body":{"output":"codelldb         <   8> send packet: $x0,0#04\n"}}
[DEBUG codelldb::dap_codec] <-- {"seq":135,"type":"event","event":"output","body":{"output":"codelldb         <   1> read packet: +\ncodelldb         <   4> read packet: $#00\n"}}
[DEBUG codelldb::dap_codec] <-- {"seq":136,"type":"event","event":"output","body":{"output":"codelldb         <   1> send packet: +\n"}}
[DEBUG codelldb::dap_codec] <-- {"seq":137,"type":"event","event":"output","body":{"output":"codelldb         <  10> send packet: $m0,200#5b\n"}}
[DEBUG codelldb::dap_codec] <-- {"seq":138,"type":"event","event":"output","body":{"output":"codelldb         <   1> read packet: +\n"}}
[DEBUG codelldb::dap_codec] <-- {"seq":139,"type":"event","event":"output","body":{"output":"codelldb         <1028> read packet: $c0000058e1031faae2031faae3031faa8400005880001fd600010000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000050000000100415401000000001000000000000004000000020041540000003c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"}}
[DEBUG codelldb::dap_codec] <-- {"seq":140,"type":"response","request_seq":11,"success":true,"command":"stackTrace","body":{"stackFrames":[{"column":0,"id":1001,"instructionPointerReference":"0x0","line":3,"name":"0","presentationHint":"subtle","source":{"name":"@0..80","sourceReference":1000}}],"totalFrames":1}}
[DEBUG codelldb::dap_codec] <-- {"seq":141,"type":"event","event":"output","body":{"output":"00000000000000000000000000000000000000#b4\ncodelldb         <   1> send packet: +\n"}}
[DEBUG codelldb::dap_codec] --> {"command":"source","arguments":{"sourceReference":1000,"source":{"name":"@0..80","sourceReference":1000}},"type":"request","seq":12}
[DEBUG codelldb::dap_codec] <-- {"seq":142,"type":"response","request_seq":12,"success":true,"command":"source","body":{"content":"; No Symbol Info\n; Source location: unknown\n00000000: C0 00 00 58                ldr    x0, #0x18\n00000004: E1 03 1F AA                mov    x1, xzr\n00000008: E2 03 1F AA                mov    x2, xzr\n0000000C: E3 03 1F AA                mov    x3, xzr\n00000010: 84 00 00 58                ldr    x4, #0x10\n00000014: 80 00 1F D6                br     x4\n00000018: 00 01 00 00                udf    #0x100\n0000001C: 00 00 00 00                udf    #0x0\n00000020: 00 00 08 00                .long  0x00080000  ; unknown opcode\n00000024: 00 00 00 00                udf    #0x0\n00000028: 00 00 00 00                udf    #0x0\n0000002C: 00 00 00 00                udf    #0x0\n00000030: 00 00 00 00                udf    #0x0\n00000034: 00 00 00 00                udf    #0x0\n00000038: 00 00 00 00                udf    #0x0\n0000003C: 00 00 00 00                udf    #0x0\n00000040: 00 00 00 00                udf    #0x0\n00000044: 00 00 00 00                udf    #0x0\n00000048: 00 00 00 00                udf    #0x0\n0000004C: 00 00 00 00                udf    #0x0\n00000050: 00 00 00 00                udf    #0x0\n00000054: 00 00 00 00                udf    #0x0\n00000058: 00 00 00 00                udf    #0x0\n0000005C: 00 00 00 00                udf    #0x0\n00000060: 00 00 00 00                udf    #0x0\n00000064: 00 00 00 00                udf    #0x0\n00000068: 00 00 00 00                udf    #0x0\n0000006C: 00 00 00 00                udf    #0x0\n00000070: 00 00 00 00                udf    #0x0\n00000074: 00 00 00 00                udf    #0x0\n00000078: 00 00 00 00                udf    #0x0\n0000007C: 00 00 00 00                udf    #0x0\n00000080: 00 00 00 00                udf    #0x0\n","mimeType":"text/x-lldb.disassembly"}}
[DEBUG codelldb::dap_codec] --> {"command":"stackTrace","arguments":{"threadId":1,"startFrame":1,"levels":19},"type":"request","seq":13}
[DEBUG codelldb::dap_codec] <-- {"seq":143,"type":"response","request_seq":13,"success":true,"command":"stackTrace","body":{"stackFrames":[],"totalFrames":1}}
[DEBUG codelldb::dap_codec] --> {"command":"threads","type":"request","seq":14}
[DEBUG codelldb::dap_codec] <-- {"seq":144,"type":"response","request_seq":14,"success":true,"command":"threads","body":{"threads":[{"id":1,"name":"1: tid=1"},{"id":2,"name":"2: tid=2"},{"id":3,"name":"3: tid=3"},{"id":4,"name":"4: tid=4"}]}}
[DEBUG codelldb::dap_codec] --> {"command":"stackTrace","arguments":{"threadId":1,"startFrame":0,"levels":1},"type":"request","seq":15}
[DEBUG codelldb::dap_codec] <-- {"seq":145,"type":"response","request_seq":15,"success":true,"command":"stackTrace","body":{"stackFrames":[{"column":0,"id":1002,"instructionPointerReference":"0x0","line":3,"name":"0","presentationHint":"subtle","source":{"name":"@0..80","sourceReference":1000}}],"totalFrames":1}}
[DEBUG codelldb::dap_codec] --> {"command":"scopes","arguments":{"frameId":1002},"type":"request","seq":16}
[DEBUG codelldb::dap_codec] <-- {"seq":146,"type":"response","request_seq":16,"success":true,"command":"scopes","body":{"scopes":[{"expensive":false,"name":"Local","variablesReference":1003},{"expensive":false,"name":"Static","variablesReference":1004},{"expensive":false,"name":"Global","variablesReference":1005},{"expensive":false,"name":"Registers","variablesReference":1006}]}}
[DEBUG codelldb::dap_codec] --> {"command":"variables","arguments":{"variablesReference":1003},"type":"request","seq":17}
[DEBUG codelldb::dap_codec] <-- {"seq":147,"type":"response","request_seq":17,"success":true,"command":"variables","body":{"variables":[]}}
[DEBUG codelldb::dap_codec] --> {"command":"stackTrace","arguments":{"threadId":1,"startFrame":1,"levels":19},"type":"request","seq":18}
[DEBUG codelldb::dap_codec] <-- {"seq":148,"type":"response","request_seq":18,"success":true,"command":"stackTrace","body":{"stackFrames":[],"totalFrames":1}}
[DEBUG codelldb::dap_codec] --> {"command":"evaluate","arguments":{"expression":"00","frameId":1002,"context":"hover"},"type":"request","seq":19}
[DEBUG codelldb::dap_codec] <-- {"seq":149,"type":"response","request_seq":19,"success":true,"command":"evaluate","body":{"result":"0","type":"long long","variablesReference":0}}
[DEBUG codelldb::dap_codec] --> {"command":"continue","arguments":{"threadId":1},"type":"request","seq":20}
[DEBUG codelldb::dap_codec] <-- {"seq":150,"type":"event","event":"output","body":{"output":"b-remote.async>  <  17> send packet: $vCont;c:p1.-1#0f\n"}}
[DEBUG codelldb::dap_codec] <-- {"seq":151,"type":"response","request_seq":20,"success":true,"command":"continue","body":{"allThreadsContinued":true}}
[DEBUG codelldb::debug_session] Debug event: 0x55f934946620 Event: broadcaster = 0x55f93493a5c8 (lldb.process), type = 0x00000001 (state-changed), data = { process = 0x55f93493a590 (pid = 1), state = running}
[DEBUG codelldb::dap_codec] <-- {"seq":152,"type":"event","event":"output","body":{"output":"b-remote.async>  <   1> read packet: +\n"}}
[DEBUG codelldb::dap_codec] <-- {"seq":153,"type":"event","event":"continued","body":{"allThreadsContinued":true,"threadId":0}}
[DEBUG codelldb::dap_codec] --> {"command":"next","arguments":{"threadId":1},"type":"request","seq":21}
[ERROR codelldb::debug_session] Received invalid thread id in step request.
[ERROR codelldb::debug_session] Internal debugger error: Invalid thread id.
[DEBUG codelldb::dap_codec] <-- {"seq":154,"type":"response","request_seq":21,"success":false,"command":"","message":"Internal debugger error: Invalid thread id.","show_user":true}
vadimcn commented 1 year ago

Sounds similar to https://github.com/microsoft/vscode/issues/181485

kylewlacy commented 1 year ago

Based on the VS Code discussions, I gave this a test in VS Code Insiders as well since there was already a proposed fix in place. I can confirm that I don't have this issue in VS Code Insiders, so it seems like this was an upstream issue! Since the fix is already available on the Insiders channel, plus reverting to VS Code 1.77 would also work as a workaround, I'm going to close this issue because it doesn't seem like there's anything to do on CodeLLDB's side.