daveleroy / SublimeDebugger

Graphical Debugger for Sublime Text for debuggers that support the debug adapter protocol
MIT License
369 stars 42 forks source link

Debugger doesn't seem to work with gdb #170

Closed samueldavidthomas closed 2 years ago

samueldavidthomas commented 2 years ago

Attempting to run the debugger using g++ and gdb creates this error:

... an error occured, TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
    at validateString (internal/validators.js:112:11)
    at Object.isAbsolute (path.js:353:5)
    at MI2.load (C:\Users\DELL\AppData\Roaming\Sublime Text\Packages\Debugger\data\adapters\gdb\extension\out\src\backend\mi2\mi2.js:64:19)
    at GDBDebugSession.launchRequest (C:\Users\DELL\AppData\Roaming\Sublime Text\Packages\Debugger\data\adapters\gdb\extension\out\src\gdb.js:56:29)
    at GDBDebugSession.dispatchRequest (C:\Users\DELL\AppData\Roaming\Sublime Text\Packages\Debugger\data\adapters\gdb\extension\node_modules\vscode-debugadapter\lib\debugSession.js:378:22)
    at GDBDebugSession.handleMessage (C:\Users\DELL\AppData\Roaming\Sublime Text\Packages\Debugger\data\adapters\gdb\extension\node_modules\vscode-debugadapter\lib\protocol.js:61:18)
    at GDBDebugSession._handleData (C:\Users\DELL\AppData\Roaming\Sublime Text\Packages\Debugger\data\adapters\gdb\extension\node_modules\vscode-debugadapter\lib\protocol.js:155:34)
    at Socket.<anonymous> (C:\Users\DELL\AppData\Roaming\Sublime Text\Packages\Debugger\data\adapters\gdb\extension\node_modules\vscode-debugadapter\lib\protocol.js:80:44)
    at Socket.emit (events.js:223:5)
    at addChunk (_stream_readable.js:309:12)

I'm running nodeJS version 12.15.0, Windows 10. I copied the Compile task from the cpp example page, replacing clangwithg++:

{
    "folders": [
        {
            "path": ".",
        },
    ],
    "debugger_tasks": [
        {
            "name": "Compile",
            "working_dir": "${project_path}",
            "shell_cmd": "g++ -std=c++14 -g double.cpp -o double",
            "file_regex": "(..[^:]*):([0-9]+):([0-9]+)?:? error: (.*)",
        },
    ],
    "debugger_configurations":
    [
        {
            "type": "gdb",
            "request": "launch",
            "name": "Debug C++",
            "pre_debug_task": "Compile",
            "program": "${project_path}/double",
            "args": [],
            "cwd": "${folder}",
            "terminal": "console"
        },
    ],
}
daveleroy commented 2 years ago

I think program is supposed to be target

Now you need to change target to the application you want to debug relative to the cwd. (Which is the workspace root by default https://github.com/WebFreak001/code-debug

{
    "type": "gdb",
    "request": "launch",
    "name": "Launch Program",
    "target": "./bin/executable",
    "cwd": "${folder}",
}
samueldavidthomas commented 2 years ago

That works perfectly - thank you so much!

gwenzek commented 1 year ago

Just for future user stumbling here, because they have issues with GDB.

The config json is "documented" here: https://github.com/WebFreak001/code-debug/blob/master/src/gdb.ts#L7

Notably "arguments" allows to pass a full string to your program as arguments.

daveleroy commented 1 year ago

With LSP-json you can get a list of parameters and validation checking for most adapters by triggering auto completion after filling in type/name/request