vadimcn / codelldb

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

Can't debug Rust program through gdbserver #1024

Open davidjohnbell opened 8 months ago

davidjohnbell commented 8 months ago

OS: 6.5.8-arch1-1 VSCode version: 1.83.1 CodeLLDB version: 1.10.0 Compiler: rustc Debuggee: rust

My end goal is to debug a rust program inside of a docker container however after reworking my configuration several times I've found that I can't even debug a local binary over gdbserver.

src/mains.rs

use std::time::Duration;

fn main() {
    println!("Hello, world!");
    let mut counter = 0;
    loop {
        std::thread::sleep(Duration::from_secs(5));
        println!("hello world {}", counter);
        counter += 1;
    }
}

.vscode/launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "lldb",
            "request": "custom",
            "name": "remote debug hello_world",
            "targetCreateCommands": [
                "target create ${workspaceFolder}/target/debug/hello_world",
            ],
            "processCreateCommands": ["gdb-remote 127.0.0.1:5001"],
        }
    ]
}

Reproduce

  1. cargo build
  2. sudo gdbserver :5001 ./target/debug/hello_world
  3. place breakpoint on first line (line 4)
  4. click the start debugging button in VS Code
    • SIGTRAP and VS Code pauses to some assembly
  5. click continue
    • SIGTRAP and in some assembly
  6. click continue
    • SIGTRAP on line 4 of my program
  7. click continue
    • SIGSEGV and in some assembly
  8. click continue
    • SIGSEGV and in some assembly
  9. click continue
    • debugger exits with Child terminated with signal = 0xb (SIGSEGV)
Initial debug configuration: {
  type: 'lldb',
  request: 'custom',
  name: 'remote debug hello_world',
  targetCreateCommands: [ 'target create ${workspaceFolder}/target/debug/hello_world' ],
  processCreateCommands: [ 'gdb-remote 127.0.0.1:5001' ],
  __configurationTarget: 6
}
Resolved debug configuration: {
  type: 'lldb',
  request: 'launch',
  name: 'remote debug hello_world',
  targetCreateCommands: [ 'target create ${workspaceFolder}/target/debug/hello_world' ],
  processCreateCommands: [ 'gdb-remote 127.0.0.1:5001' ],
  __configurationTarget: 6,
  custom: true,
  relativePathBase: '/home/david/Documents/hello_world',
  _adapterSettings: {
    displayFormat: 'auto',
    showDisassembly: 'auto',
    dereferencePointers: true,
    suppressMissingSourceFiles: true,
    evaluationTimeout: 5,
    consoleMode: 'commands',
    sourceLanguages: null,
    terminalPromptClear: null,
    evaluateForHovers: true,
    commandCompletions: true,
    reproducer: false
  }
}