codelldb icon indicating copy to clipboard operation
codelldb copied to clipboard

Debugging fails to start on Ubuntu + Rust, "Connection shut down by remote side..."

Open digama0 opened this issue 2 years ago • 8 comments

OS: Ubuntu 22.04.1 LTS VSCode version: 1.75.1 CodeLLDB version: v1.8.1 Compiler: rustc 1.69.0-nightly (5243ea5c2 2023-02-20) Debuggee: x86_64-unknown-linux-gnu

I get an error Connection shut down by remote side while waiting for reply to initial handshake packet whenever I try to use CodeLLDB for anything. For the test below I did cargo new hello-lldb, then opened main.rs and pressed F5 in vscode, and followed the prompt to create a default launch configuration, whereupon I get that error dialog. The LLDB log in the output window is shown below.

Verbose log
Initial debug configuration: {
  type: 'lldb',
  request: 'launch',
  name: "Debug executable 'hello-lldb'",
  cargo: {
    args: [ 'build', '--bin=hello-lldb', '--package=hello-lldb' ],
    filter: { name: 'hello-lldb', kind: 'bin' }
  },
  args: [],
  cwd: '${workspaceFolder}',
  __configurationTarget: 6
}
Raw artifacts:
{
  fileName: '/home/mario/Documents/hello-lldb/target/debug/hello-lldb',
  name: 'hello-lldb',
  kind: 'bin'
}
Filtered artifacts: 
{
  fileName: '/home/mario/Documents/hello-lldb/target/debug/hello-lldb',
  name: 'hello-lldb',
  kind: 'bin'
}
Resolved debug configuration: {
  type: 'lldb',
  request: 'launch',
  name: "Debug executable 'hello-lldb'",
  args: [],
  cwd: '${workspaceFolder}',
  __configurationTarget: 6,
  relativePathBase: '/home/mario/Documents/hello-lldb',
  program: '/home/mario/Documents/hello-lldb/target/debug/hello-lldb',
  sourceLanguages: [ 'rust' ],
  _adapterSettings: {
    displayFormat: 'auto',
    showDisassembly: 'auto',
    dereferencePointers: true,
    suppressMissingSourceFiles: true,
    evaluationTimeout: 5,
    consoleMode: 'commands',
    sourceLanguages: null,
    terminalPromptClear: null,
    evaluateForHovers: true,
    commandCompletions: true,
    reproducer: false
  }
}
liblldb: /home/mario/.vscode/extensions/vadimcn.vscode-lldb-1.8.1/lldb/lib/liblldb.so
environment: {}
params: {
  evaluateForHovers: true,
  commandCompletions: true,
  sourceLanguages: [ 'rust' ]
}
[2023-03-07T00:58:15.447Z DEBUG codelldb] New debug session
[2023-03-07T00:58:15.583Z DEBUG codelldb::dap_codec] --> {"command":"initialize","arguments":{"clientID":"vscode","clientName":"Visual Studio Code","adapterID":"lldb","pathFormat":"path","linesStartAt1":true,"columnsStartAt1":true,"supportsVariableType":true,"supportsVariablePaging":true,"supportsRunInTerminalRequest":true,"locale":"en","supportsProgressReporting":true,"supportsInvalidatedEvent":true,"supportsMemoryReferences":true,"supportsArgsCanBeInterpretedByShell":true,"supportsMemoryEvent":true},"type":"request","seq":1}
[2023-03-07T00:58:15.584Z DEBUG codelldb::dap_codec]  {"command":"launch","arguments":{"type":"lldb","request":"launch","name":"Debug executable 'hello-lldb'","args":[],"cwd":"/home/mario/Documents/hello-lldb","__configurationTarget":6,"relativePathBase":"/home/mario/Documents/hello-lldb","program":"/home/mario/Documents/hello-lldb/target/debug/hello-lldb","sourceLanguages":["rust"],"_adapterSettings":{"displayFormat":"auto","showDisassembly":"auto","dereferencePointers":true,"suppressMissingSourceFiles":true,"evaluationTimeout":5,"consoleMode":"commands","sourceLanguages":null,"terminalPromptClear":null,"evaluateForHovers":true,"commandCompletions":true,"reproducer":false},"__sessionId":"516fba75-92ff-4721-b3a7-e3a4de06ee03"},"type":"request","seq":2}
[2023-03-07T00:58:15.587Z DEBUG codelldb::dap_codec]  {"command":"setFunctionBreakpoints","arguments":{"breakpoints":[]},"type":"request","seq":3}
[2023-03-07T00:58:15.629Z DEBUG codelldb::dap_codec]  {"command":"setDataBreakpoints","arguments":{"breakpoints":[]},"type":"request","seq":4}
[2023-03-07T00:58:15.629Z DEBUG codelldb::dap_codec]  {"command":"setExceptionBreakpoints","arguments":{"filters":["rust_panic"]},"type":"request","seq":5}
[2023-03-07T00:58:15.634Z DEBUG codelldb::debug_session] Debug event: 0x5573db0a0020 Event: broadcaster = 0x5573dacff3e0 (lldb.target), type = 0x00000001 (breakpoint-changed), data = {bkpt: 1 type: breakpoint added}
[2023-03-07T00:58:15.635Z DEBUG codelldb::dap_codec]  {"command":"configurationDone","type":"request","seq":6}
[2023-03-07T00:58:15.713Z DEBUG codelldb::dap_codec]  {"command":"threads","type":"request","seq":7}
[2023-03-07T00:58:15.724Z DEBUG codelldb::dap_codec]  {"type":"response","seq":8,"command":"runInTerminal","request_seq":5,"success":true,"body":{"shellProcessId":584289}}
[2023-03-07T00:58:16.804Z DEBUG codelldb::dap_codec]  {"command":"disconnect","arguments":{"restart":false},"type":"request","seq":9}
[2023-03-07T00:58:17.312Z ERROR codelldb::debug_session] Internal debugger error: Sending isconnect packet failed.
[2023-03-07T00:58:17.312Z DEBUG codelldb::dap_codec] 

Using lldb directly seems to work:

$ lldb target/debug/hello-lldb
(lldb) target create "target/debug/hello-lldb"
Current executable set to '/home/mario/Documents/hello-lldb/target/debug/hello-lldb' (x86_64).
(lldb) r
Process 600307 launched: '/home/mario/Documents/hello-lldb/target/debug/hello-lldb' (x86_64)
Hello, world!
Process 600307 exited with status = 0 (0x00000000) 
(lldb) exit

(edited to remove an unrelated error caused by llvm/llvm-project#55575)

digama0 avatar Mar 07 '23 01:03 digama0

All I can say from the log is that the lldb-server process fails in some manner. Is there anything unusual about this machine?

vadimcn avatar Mar 10 '23 21:03 vadimcn

Not that I know of. It is a regular linux laptop. Do you have any ideas of what I can do to troubleshoot, for example calling lldb-server directly?

digama0 avatar Mar 10 '23 22:03 digama0

Do you have any ideas of what I can do to troubleshoot, for example calling lldb-server directly?

You could try remote debugging configuration. This will allow you to launch lldb-server directly (normally lldb does this for you), and perhaps you will be able to see some error message in its output. It is also possible to enable extra logging in lldb-server.

vadimcn avatar Mar 10 '23 22:03 vadimcn

Even the most basic version of that configuration fails:

{
  "name": "Remote launch",
  "type": "lldb",
  "request": "launch",
  "program": "${workspaceFolder}/target/debug/hello-lldb",
  "initCommands": []
}

yields the same error, even before getting to the part where it connects with the remote. (The lldb-server platform --server --listen "*:2020" part works fine, although it isn't doing much without a client to connect to.)

digama0 avatar Mar 10 '23 23:03 digama0

Here's something: if I call lldb-server directly (LMK if I'm doing this right) I get an execve permission error (although the error message seems to be sometimes missing for unknown reasons), even when run as admin:

$ sudo lldb-server g :0 target/debug/hello-lldb
error: failed to launch 'target/debug/hello-lldb': execve failed: 
$ sudo lldb-server g :0 target/debug/hello-lldb
error: failed to launch 'target/debug/hello-lldb': execve failed: Permission denied

digama0 avatar Mar 10 '23 23:03 digama0

Sorry, no idea. Googling "execve failed: Permission denied" suggests that this might be related to AppArmor, if CodeLLDB somehow ended up in the sandbox. BTW, which lldb-server did you use, the one that comes in your distro, or the one bundled with CodeLLDB?

vadimcn avatar Mar 11 '23 00:03 vadimcn

I would also check /var/log/syslog

vadimcn avatar Mar 11 '23 00:03 vadimcn