vadimcn / codelldb

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

lldb debugserver fails to attach only over remote session #1045

Open DavidMSCode opened 11 months ago

DavidMSCode commented 11 months ago

OS: Mac OS Sonoma VSCode version: 1.85.1 CodeLLDB version: 1.10, 1.9.2, 1.9.1 Compiler: clang Debuggee: arm64-apple-darwin

When connecting to the vscode server on my mac over ssh (from a windows client) and trying to debug using the lldb launch config, I receive an error where it seems to be saying that I don't have permission to debug. When running vscode locally on the same mac under the same user I do not have this issue. in addition I only recieve this message on 1.9.x. On 1.10 the debug session just loads forever on the windows client and an error is never received. But checking the logs I see a similar inability to attach.

LLDB Output
[ERROR codelldb::debug_session] process exited with status -1 (this is a non-interactive debug session, cannot get permission to debug processes.)
Debug adapter exit code=0 (0x0), signal=null.

Checking the mac system logs I can see that debugserver is trying to attach to the PID for the program, but ultimately fails, repeats 10 times and gives up.

Console Log
error: [LaunchAttach] MachTask::TaskPortForProcessID task_for_pid(20904) failed: ::task_for_pid ( target_tport = 0x0203, pid = 20904, &task ) => err = 0x00000005 ((os/kern) failure)

This does not occur when debugging on the machine locally. Using the default vscode c++ debugger works locally and remotely (well, it attaches, the default debugger still has its own set of issues which is why I've been using codeLLDB). I've attempted common troubleshooting suggestions like deleting the debugserver binary bundled with code lldb, making sure I'm in developer mode and adding the _developer group to my user account to no avail. I upgraded to Sonoma last week but this issue has only started occurring today. As far as I can tell I haven't seen anyone run into this permissions issue over just SSH. "this is a non-interactive debug session, cannot get permission to debug processes." only brings up some xcode issues for debugging locally.

Verbose LLDB Output
Initial debug configuration: {
  type: 'lldb',
  request: 'launch',
  name: 'Launch',
  program: '${command:cmake.launchTargetPath}',
  args: [],
  preLaunchTask: 'CMake: build',
  cwd: '${workspaceFolder}/bin',
  __configurationTarget: 6
}
Resolved debug configuration: {
  type: 'lldb',
  request: 'launch',
  name: 'Launch',
  program: '${command:cmake.launchTargetPath}',
  args: [],
  preLaunchTask: 'CMake: build',
  cwd: '${workspaceFolder}/bin',
  __configurationTarget: 6,
  relativePathBase: '/Users/{user}/Github/APC',
  _adapterSettings: {
    displayFormat: 'auto',
    showDisassembly: 'auto',
    dereferencePointers: true,
    suppressMissingSourceFiles: true,
    evaluationTimeout: 5,
    consoleMode: 'commands',
    sourceLanguages: null,
    terminalPromptClear: null,
    evaluateForHovers: true,
    commandCompletions: true,
    reproducer: false
  }
}
liblldb: /Users/{user}/.vscode-server/extensions/vadimcn.vscode-lldb-1.9.2/lldb/lib/liblldb.dylib
environment: {}
settings: { evaluateForHovers: true, commandCompletions: true }
[DEBUG codelldb] Connecting to 127.0.0.1:51620
[DEBUG codelldb] New debug session
[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,"supportsStartDebuggingRequest":true},"type":"request","seq":1}
[DEBUG codelldb::dap_codec] <-- {"seq":1,"type":"response","request_seq":1,"success":true,"command":"initialize","body":{"exceptionBreakpointFilters":[{"default":true,"filter":"cpp_throw","label":"C++: on throw","supportsCondition":true},{"default":false,"filter":"cpp_catch","label":"C++: on catch","supportsCondition":true}],"supportTerminateDebuggee":true,"supportsCancelRequest":true,"supportsCompletionsRequest":true,"supportsConditionalBreakpoints":true,"supportsConfigurationDoneRequest":true,"supportsDataBreakpoints":true,"supportsDelayedStackTraceLoading":true,"supportsDisassembleRequest":true,"supportsEvaluateForHovers":true,"supportsExceptionFilterOptions":true,"supportsExceptionInfoRequest":true,"supportsFunctionBreakpoints":true,"supportsGotoTargetsRequest":true,"supportsHitConditionalBreakpoints":true,"supportsInstructionBreakpoints":true,"supportsLogPoints":true,"supportsReadMemoryRequest":true,"supportsSetVariable":true,"supportsSteppingGranularity":true,"supportsWriteMemoryRequest":true}}
[DEBUG codelldb::dap_codec] --> {"command":"launch","arguments":{"type":"lldb","request":"launch","name":"Launch","program":"/Users/{user}/Github/APC/build/src/main_bootstrap","args":[],"preLaunchTask":"CMake: build","cwd":"/Users/{user}/Github/APC/bin","__configurationTarget":6,"relativePathBase":"/Users/{user}/Github/APC","_adapterSettings":{"displayFormat":"auto","showDisassembly":"auto","dereferencePointers":true,"suppressMissingSourceFiles":true,"evaluationTimeout":5,"consoleMode":"commands","sourceLanguages":null,"terminalPromptClear":null,"evaluateForHovers":true,"commandCompletions":true,"reproducer":false},"__sessionId":"7537f580-bfee-4f0a-804e-1d51391f36a7"},"type":"request","seq":2}
[DEBUG codelldb::dap_codec] <-- {"seq":2,"type":"event","event":"output","body":{"category":"console","output":"Console is in 'commands' mode, prefix expressions with '?'.\n"}}
INFO(Python) 18:13:07 formatters: Initializing
INFO(Python) 18:13:07 formatters.rust: Initializing
[DEBUG codelldb::dap_codec] <-- {"seq":3,"type":"event","event":"initialized"}
[DEBUG codelldb::debug_session] Debug event: 0x600003c1ead8 Event: broadcaster = 0x10bdd9608 (lldb.target), type = 0x00000002 (modules-loaded), data = {main_bootstrap}
[DEBUG codelldb::dap_codec] <-- {"seq":4,"type":"event","event":"module","body":{"module":{"addressRange":"FFFFFFFFFFFFFFFF","id":"FFFFFFFFFFFFFFFF","name":"main_bootstrap","path":"/Users/{user}/Github/APC/build/src/main_bootstrap","symbolFilePath":"/Users/{user}/Github/APC/build/src/main_bootstrap","symbolStatus":"Symbols loaded."},"reason":"new"}}
[DEBUG codelldb::dap_codec] <-- {"seq":5,"type":"request","command":"runInTerminal","arguments":{"args":["/Users/{user}/.vscode-server/extensions/vadimcn.vscode-lldb-1.9.2/adapter/codelldb","terminal-agent","--connect=51623"],"cwd":"","kind":"integrated","title":"Launch"}}
[DEBUG codelldb::dap_codec] --> {"command":"setBreakpoints","arguments":{"source":{"name":"RK45.cpp","path":"/Users/{user}/Github/APC/src/RK45.cpp"},"lines":[35],"breakpoints":[{"line":35}],"sourceModified":false},"type":"request","seq":3}
[DEBUG codelldb::dap_codec] --> {"command":"setFunctionBreakpoints","arguments":{"breakpoints":[]},"type":"request","seq":4}
[DEBUG codelldb::dap_codec] --> {"command":"setDataBreakpoints","arguments":{"breakpoints":[]},"type":"request","seq":5}
[DEBUG codelldb::dap_codec] --> {"command":"setInstructionBreakpoints","arguments":{"breakpoints":[]},"type":"request","seq":6}
[DEBUG codelldb::dap_codec] --> {"command":"setExceptionBreakpoints","arguments":{"filters":[],"filterOptions":[{"filterId":"cpp_throw"}]},"type":"request","seq":7}
[DEBUG codelldb::debug_session] Debug event: 0x600003c04a98 Event: broadcaster = 0x10bdd9608 (lldb.target), type = 0x00000001 (breakpoint-changed), data = {bkpt: 1 type: breakpoint added}
[DEBUG codelldb::dap_codec] <-- {"seq":6,"type":"response","request_seq":3,"success":true,"command":"setBreakpoints","body":{"breakpoints":[{"id":1,"message":"Resolved locations: 0","verified":false}]}}
[DEBUG codelldb::dap_codec] <-- {"seq":7,"type":"response","request_seq":4,"success":true,"command":"setFunctionBreakpoints","body":{"breakpoints":[]}}
[DEBUG codelldb::debug_session] Debug event: 0x600003c28958 Event: broadcaster = 0x10bdd9608 (lldb.target), type = 0x00000001 (breakpoint-changed), data = {bkpt: 2 type: breakpoint added}
[DEBUG codelldb::dap_codec] <-- {"seq":8,"type":"response","request_seq":5,"success":true,"command":"setDataBreakpoints","body":{"breakpoints":[]}}
[DEBUG codelldb::debug_session] Debug event: 0x600003c28a58 Event: broadcaster = 0x10bdd9608 (lldb.target), type = 0x00000001 (breakpoint-changed), data = {bkpt: 2 type: breakpoint disabled}
[DEBUG codelldb::debug_session] Debug event: 0x600003c28a98 Event: broadcaster = 0x10bdd9608 (lldb.target), type = 0x00000001 (breakpoint-changed), data = {bkpt: 2 type: breakpoint removed}
[DEBUG codelldb::dap_codec] <-- {"seq":9,"type":"response","request_seq":6,"success":true,"command":"setInstructionBreakpoints","body":{"breakpoints":[]}}
[DEBUG codelldb::debug_session] Debug event: 0x600003c28a58 Event: broadcaster = 0x10bdd9608 (lldb.target), type = 0x00000001 (breakpoint-changed), data = {bkpt: 3 type: breakpoint added}
[DEBUG codelldb::dap_codec] <-- {"seq":10,"type":"response","request_seq":7,"success":true,"command":"setExceptionBreakpoints"}
[DEBUG codelldb::dap_codec] --> {"command":"configurationDone","type":"request","seq":8}
[DEBUG codelldb::dap_codec] --> {"type":"response","seq":9,"command":"runInTerminal","request_seq":5,"success":true,"body":{"shellProcessId":9874}}
[DEBUG codelldb::dap_codec] <-- {"seq":11,"type":"event","event":"output","body":{"category":"console","output":"Launching: /Users/{user}/Github/APC/build/src/main_bootstrap\n"}}
[ERROR codelldb::debug_session] process exited with status -1 (this is a non-interactive debug session, cannot get permission to debug processes.)
[DEBUG codelldb::dap_codec] <-- {"seq":12,"type":"response","request_seq":2,"success":false,"command":"","message":"process exited with status -1 (this is a non-interactive debug session, cannot get permission to debug processes.)","show_user":true}
[DEBUG codelldb::dap_codec] <-- {"seq":13,"type":"response","request_seq":8,"success":true,"command":"configurationDone"}
[DEBUG codelldb::dap_codec] --> {"command":"disconnect","arguments":{"restart":false},"type":"request","seq":10}
[DEBUG codelldb::dap_codec] <-- {"seq":14,"type":"response","request_seq":10,"success":true,"command":"disconnect"}
[DEBUG codelldb::dap_session] Client has disconnected
[DEBUG codelldb::debug_session] End of the requests stream
[DEBUG codelldb::debug_session] DebugSession::drop()
[DEBUG codelldb] End of the debug session
[DEBUG codelldb] Exiting
Debug adapter exit code=0 (0x0), signal=null.
dolby360 commented 10 months ago

+1

DavidMSCode commented 6 months ago

Alright so after messing with this over multiple attempts I found that the workaround in #456 works but you have to be mindful of the fact that vscode-server keeps a separate extensions folder.

So steps to solve for remote debugging:

  1. Make sure the codeLLDB extension is installed remotely on the mac
  2. On the remote mac go to ~/.vscode-server/extensions/vadimcn.vscode-lldb-1.{x}.{x}/lldb/bin (replace 1.{x}.{x} with the offending version number and make sure you aren't in ~/.vscode/... )
  3. Delete 'debugserver'
  4. Launching an lldb session remotely should now use the system's debugserver.

While this workaround does work it also indicates that for some reason the debugserver that comes with the current version of codelldb is requiring interactive authentication even though developer mode is on and the user is in the _developer group.