svaante / dape

Debug Adapter Protocol for Emacs
GNU General Public License v3.0
501 stars 34 forks source link

Unable to start gdb to debug C++ project #158

Closed ezaquarii closed 1 month ago

ezaquarii commented 1 month ago

Shortly after dape gdb is started, it dies with [jsonrpc] Server exited with status 9

*dape-repl*:

* Adapter started with "gdb --interpreter=dap" *
GNU gdb (Fedora Linux) 14.2-2.fc39
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
No source file named /home/tn/Devel/cdbg/main.cpp.
Breakpoint 1 (-source /home/tn/Devel/cdbg/main.cpp -line 5) pending.
* Adapter started with "gdb --interpreter=dap" *
GNU gdb (Fedora Linux) 14.2-2.fc39
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
No source file named /home/tn/Devel/cdbg/main.cpp.
Breakpoint 1 (-source /home/tn/Devel/cdbg/main.cpp -line 5) pending.

*dape-connection events*:

[jsonrpc] e[01:19:22.301] --> initialize[1] {"type":"request","seq":1,"command":"initialize","arguments":{"clientID":"dape","adapterID":null,"pathFormat":"path","linesStartAt1":true,"columnsStartAt1":true,"supportsRunInTerminalRequest":true,"supportsProgressReporting":true,"supportsStartDebuggingRequest":true}}
[jsonrpc] e[01:19:22.480] <-- output {"type": "event", "event": "output", "body": {"category": "stdout", "output": "GNU gdb (Fedora Linux) 14.2-2.fc39\n"}, "seq": 1}
[jsonrpc] e[01:19:22.481] <-- output {"type": "event", "event": "output", "body": {"category": "stdout", "output": "Copyright (C) 2023 Free Software Foundation, Inc.\n"}, "seq": 2}
[jsonrpc] e[01:19:22.482] <-- output {"type": "event", "event": "output", "body": {"category": "stdout", "output": "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n"}, "seq": 3}
[jsonrpc] e[01:19:22.483] <-- output {"type": "event", "event": "output", "body": {"category": "stdout", "output": "This is free software: you are free to change and redistribute it.\n"}, "seq": 4}
[jsonrpc] e[01:19:22.484] <-- output {"type": "event", "event": "output", "body": {"category": "stdout", "output": "There is NO WARRANTY, to the extent permitted by law.\n"}, "seq": 5}
[jsonrpc] e[01:19:22.485] <-- output {"type": "event", "event": "output", "body": {"category": "stdout", "output": "Type \"show copying\" and \"show warranty\" for details.\n"}, "seq": 6}
[jsonrpc] e[01:19:22.486] <-- output {"type": "event", "event": "output", "body": {"category": "stdout", "output": "This GDB was configured as \"x86_64-redhat-linux-gnu\".\n"}, "seq": 7}
[jsonrpc] e[01:19:22.487] <-- output {"type": "event", "event": "output", "body": {"category": "stdout", "output": "Type \"show configuration\" for configuration details.\n"}, "seq": 8}
[jsonrpc] e[01:19:22.488] <-- output {"type": "event", "event": "output", "body": {"category": "stdout", "output": "For bug reporting instructions, please see:\n"}, "seq": 9}
[jsonrpc] e[01:19:22.489] <-- output {"type": "event", "event": "output", "body": {"category": "stdout", "output": "<https://www.gnu.org/software/gdb/bugs/>.\n"}, "seq": 10}
[jsonrpc] e[01:19:22.490] <-- output {"type": "event", "event": "output", "body": {"category": "stdout", "output": "Find the GDB manual and other documentation resources online at:\n"}, "seq": 11}
[jsonrpc] e[01:19:22.491] <-- output {"type": "event", "event": "output", "body": {"category": "stdout", "output": "    <http://www.gnu.org/software/gdb/documentation/>.\n"}, "seq": 12}
[jsonrpc] e[01:19:22.492] <-- output {"type": "event", "event": "output", "body": {"category": "stdout", "output": "\n"}, "seq": 13}
[jsonrpc] e[01:19:22.493] <-- output {"type": "event", "event": "output", "body": {"category": "stdout", "output": "For help, type \"help\".\n"}, "seq": 14}
[jsonrpc] e[01:19:22.494] <-- output {"type": "event", "event": "output", "body": {"category": "stdout", "output": "Type \"apropos word\" to search for commands related to \"word\".\n"}, "seq": 15}
[jsonrpc] e[01:19:22.495] <-- initialize[1] {"request_seq": 1, "type": "response", "command": "initialize", "body": {"supportsTerminateRequest": true, "supportTerminateDebuggee": true, "supportsLoadedSourcesRequest": true, "supportsLogPoints": true, "supportsConditionalBreakpoints": true, "supportsHitConditionalBreakpoints": true, "supportsFunctionBreakpoints": true, "supportsInstructionBreakpoints": true, "exceptionBreakpointFilters": [{"filter": "assert", "label": "Ada assertions", "supportsCondition": true}, {"filter": "exception", "label": "Ada exceptions", "supportsCondition": true}, {"filter": "throw", "label": "C++ exceptions, when thrown", "supportsCondition": true}, {"filter": "rethrow", "label": "C++ exceptions, when re-thrown", "supportsCondition": true}, {"filter": "catch", "label": "C++ exceptions, when caught", "supportsCondition": true}], "supportsExceptionFilterOptions": true, "supportsModulesRequest": true, "supportsDelayedStackTraceLoading": true, "supportsDisassembleRequest": true, "supportsValueFormattingOptions": true, "supportsEvaluateForHovers": true, "supportsSetExpression": true, "supportsSetVariable": true, "supportsConfigurationDoneRequest": true, "supportsBreakpointLocationsRequest": true, "supportsReadMemoryRequest": true, "supportsWriteMemoryRequest": true, "supportsSingleThreadExecutionRequests": true, "supportsSteppingGranularity": true}, "success": true, "seq": 16}
[jsonrpc] e[01:19:22.495] <-- initialized {"type": "event", "event": "initialized", "seq": 17}
[jsonrpc] e[01:19:22.495] --> setExceptionBreakpoints[2] {"type":"request","seq":2,"command":"setExceptionBreakpoints","arguments":{"filters":[]}}
[jsonrpc] e[01:19:22.503] <-- setExceptionBreakpoints[2] {"request_seq": 2, "type": "response", "command": "setExceptionBreakpoints", "body": {"breakpoints": []}, "success": true, "seq": 18}
[jsonrpc] e[01:19:22.503] --> setBreakpoints[3] {"type":"request","seq":3,"command":"setBreakpoints","arguments":{"source":{"name":"main.cpp","path":"/home/tn/Devel/cdbg/main.cpp"},"breakpoints":[{"line":5}],"lines":[5]}}
[jsonrpc] e[01:19:22.508] <-- breakpoint {"type": "event", "event": "breakpoint", "body": {"reason": "changed", "breakpoint": {"id": 1, "verified": true}}, "seq": 19}
[jsonrpc] e[01:19:22.509] <-- breakpoint {"type": "event", "event": "breakpoint", "body": {"reason": "changed", "breakpoint": {"id": 1, "verified": true}}, "seq": 20}
[jsonrpc] e[01:19:22.510] <-- output {"type": "event", "event": "output", "body": {"category": "stdout", "output": "No source file named /home/tn/Devel/cdbg/main.cpp.\n"}, "seq": 21}
[jsonrpc] e[01:19:22.511] <-- output {"type": "event", "event": "output", "body": {"category": "stdout", "output": "Breakpoint 1 (-source /home/tn/Devel/cdbg/main.cpp -line 5) pending.\n"}, "seq": 22}
[jsonrpc] e[01:19:22.512] <-- setBreakpoints[3] {"request_seq": 3, "type": "response", "command": "setBreakpoints", "body": {"breakpoints": [{"id": 1, "verified": true}]}, "success": true, "seq": 23}
[jsonrpc] e[01:19:22.512] --> configurationDone[4] {"type":"request","seq":4,"command":"configurationDone"}
[jsonrpc] e[01:19:22.517] <-- configurationDone[4] {"request_seq": 4, "type": "response", "command": "configurationDone", "success": true, "seq": 24}
[jsonrpc] e[01:19:22.517] --> launch[5] {"type":"request","seq":5,"command":"launch","arguments":{"request":"launch","program":"a.out","args":[],"stopAtBeginningOfMainSubprogram":false}}
[jsonrpc] e[01:19:22.523] <-- launch[5] {"request_seq": 5, "type": "response", "command": "launch", "success": true, "seq": 25}
[jsonrpc] e[01:19:22.523] <-- module {"type": "event", "event": "module", "body": {"reason": "new", "module": {"id": "/home/tn/Devel/cdbg/a.out", "name": "/home/tn/Devel/cdbg/a.out", "path": "/home/tn/Devel/cdbg/a.out"}}, "seq": 26}
[jsonrpc] e[01:19:22.528] <-- breakpoint {"type": "event", "event": "breakpoint", "body": {"reason": "changed", "breakpoint": {"id": 1, "verified": true, "source": {"name": "main.cpp", "path": "/home/tn/Devel/cdbg/main.cpp"}, "line": 5, "instructionReference": "0x40116e"}}, "seq": 27}

Dape version 0.15.0

luluman commented 1 month ago

I'm experiencing the same issue with dape while using Emacs 30 with native JSON support. The problem is that dape is unable to execute the stopAtBeginningOfMainSubprogram. I noticed that the variable dape--connection-selected is set to nil, despite the fact that JSON-RPC appears to be functioning correctly.

svaante commented 1 month ago

@ezaquarii Have you compiled your binary with -g flag?

Depending on your gdb version (and dape) you might have to flip defer-launch-attach to nil in gdb configuration, this is an workaround for an gdb bug.

@luluman dape--connection-selected should be nil, its used to manage adapters which use several connections so its unfortunately an red herring. What gdb version are you using and are you using dape from github or melpa?

luluman commented 1 month ago

emacs version: 30.0.91 (with commit 52746ceb ) gdb version: 14.2 dape version: dape-0.15.0.0.20241006.212252

luluman commented 1 month ago

emacs version: 30.0.91 (with commit 52746ceb ) gdb version: 14.2 dape version: dape-0.15.0.0.20241006.212252

And dape does not hit the breakpoint when I execute the command: gdb command-cwd "/workspace/test/" :program "/workspace/test/test" :stopAtBeginningOfMainSubprogram t

The dape-repl buffer:

* Welcome to Dape REPL! *
Available Dape commands: debug, next, continue, pause, step, out, up, down, restart, kill, disconnect, quit
Empty input will rerun last command.

* Adapter started with "gdb --interpreter=dap" *
GNU gdb (GDB) 14.2
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".

The dape-connection events log:

[jsonrpc] e[02:45:00.549] --> initialize[1] {"type":"request","seq":1,"command":"initialize","arguments":{"clientID":"dape","adapterID":null,"pathFormat":"path","linesStartAt1":true,"columnsStartAt1":true,"supportsRunIn\
TerminalRequest":true,"supportsProgressReporting":true,"supportsStartDebuggingRequest":true}}
[stderr]
[stderr]
[stderr]  nil
[stderr]  nil
[stderr]  Process dape adapter stderr finished
[jsonrpc] e[02:45:00.712] <-- output {"type": "event", "event": "output", "body": {"category": "stdout", "output": "GNU gdb (GDB) 14.2\n"}, "seq": 1}
[jsonrpc] e[02:45:00.714] <-- output {"type": "event", "event": "output", "body": {"category": "stdout", "output": "Copyright (C) 2023 Free Software Foundation, Inc.\n"}, "seq": 2}
[jsonrpc] e[02:45:00.714] <-- output {"type": "event", "event": "output", "body": {"category": "stdout", "output": "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n"}, "seq": 3}
[jsonrpc] e[02:45:00.715] <-- output {"type": "event", "event": "output", "body": {"category": "stdout", "output": "This is free software: you are free to change and redistribute it.\n"}, "seq": 4}
[jsonrpc] e[02:45:00.715] <-- output {"type": "event", "event": "output", "body": {"category": "stdout", "output": "There is NO WARRANTY, to the extent permitted by law.\n"}, "seq": 5}
[jsonrpc] e[02:45:00.716] <-- output {"type": "event", "event": "output", "body": {"category": "stdout", "output": "Type \"show copying\" and \"show warranty\" for details.\n"}, "seq": 6}
[jsonrpc] e[02:45:00.716] <-- output {"type": "event", "event": "output", "body": {"category": "stdout", "output": "This GDB was configured as \"x86_64-pc-linux-gnu\".\n"}, "seq": 7}
[jsonrpc] e[02:45:00.716] <-- output {"type": "event", "event": "output", "body": {"category": "stdout", "output": "Type \"show configuration\" for configuration details.\n"}, "seq": 8}
[jsonrpc] e[02:45:00.716] <-- output {"type": "event", "event": "output", "body": {"category": "stdout", "output": "For bug reporting instructions, please see:\n"}, "seq": 9}
[jsonrpc] e[02:45:00.717] <-- output {"type": "event", "event": "output", "body": {"category": "stdout", "output": "<https://www.gnu.org/software/gdb/bugs/>.\n"}, "seq": 10}
[jsonrpc] e[02:45:00.717] <-- output {"type": "event", "event": "output", "body": {"category": "stdout", "output": "Find the GDB manual and other documentation resources online at:\n"}, "seq": 11}
[jsonrpc] e[02:45:00.717] <-- output {"type": "event", "event": "output", "body": {"category": "stdout", "output": "    <http://www.gnu.org/software/gdb/documentation/>.\n"}, "seq": 12}
[jsonrpc] e[02:45:00.718] <-- output {"type": "event", "event": "output", "body": {"category": "stdout", "output": "\n"}, "seq": 13}
[jsonrpc] e[02:45:00.718] <-- output {"type": "event", "event": "output", "body": {"category": "stdout", "output": "For help, type \"help\".\n"}, "seq": 14}
[jsonrpc] e[02:45:00.718] <-- output {"type": "event", "event": "output", "body": {"category": "stdout", "output": "Type \"apropos word\" to search for commands related to \"word\".\n"}, "seq": 15}
[jsonrpc] e[02:45:00.719] <-- initialize[1] {"request_seq": 1, "type": "response", "command": "initialize", "body": {"supportsTerminateRequest": true, "supportTerminateDebuggee": true, "supportsLoadedSourcesRequest": tr\
ue, "supportsLogPoints": true, "supportsConditionalBreakpoints": true, "supportsHitConditionalBreakpoints": true, "supportsFunctionBreakpoints": true, "supportsInstructionBreakpoints": true, "exceptionBreakpointFilters"\
: [{"filter": "assert", "label": "Ada assertions", "supportsCondition": true}, {"filter": "exception", "label": "Ada exceptions", "supportsCondition": true}, {"filter": "throw", "label": "C++ exceptions, when thrown", "\
supportsCondition": true}, {"filter": "rethrow", "label": "C++ exceptions, when re-thrown", "supportsCondition": true}, {"filter": "catch", "label": "C++ exceptions, when caught", "supportsCondition": true}], "supportsE\
xceptionFilterOptions": true, "supportsModulesRequest": true, "supportsDelayedStackTraceLoading": true, "supportsDisassembleRequest": true, "supportsValueFormattingOptions": true, "supportsEvaluateForHovers": true, "sup\
portsSetExpression": true, "supportsSetVariable": true, "supportsConfigurationDoneRequest": true, "supportsBreakpointLocationsRequest": true, "supportsReadMemoryRequest": true, "supportsWriteMemoryRequest": true, "suppo\
rtsSingleThreadExecutionRequests": true, "supportsSteppingGranularity": true}, "success": true, "seq": 16}
[jsonrpc] e[02:45:00.719] <-- initialized {"type": "event", "event": "initialized", "seq": 17}
[jsonrpc] e[02:45:00.719] --> setExceptionBreakpoints[2] {"type":"request","seq":2,"command":"setExceptionBreakpoints","arguments":{"filters":[]}}
[jsonrpc] e[02:45:00.721] <-- setExceptionBreakpoints[2] {"request_seq": 2, "type": "response", "command": "setExceptionBreakpoints", "body": {"breakpoints": []}, "success": true, "seq": 18}
[jsonrpc] e[02:45:00.721] --> configurationDone[3] {"type":"request","seq":3,"command":"configurationDone"}
[jsonrpc] e[02:45:00.722] <-- configurationDone[3] {"request_seq": 3, "type": "response", "command": "configurationDone", "success": true, "seq": 19}
[jsonrpc] e[02:45:00.722] --> launch[4] {"type":"request","seq":4,"command":"launch","arguments":{"request":"launch","program":"/workspace/test/test","args":[],"stopAtBeginningOfMainSubprogram":true}}
[jsonrpc] e[02:45:00.723] <-- launch[4] {"request_seq": 4, "type": "response", "command": "launch", "success": true, "seq": 20}
[jsonrpc] e[02:45:00.725] <-- module {"type": "event", "event": "module", "body": {"reason": "new", "module": {"id": "/workspace/test/test", "name": "/workspace/test/test", "path": "/workspace/test/test"}}, "seq": 21}
[jsonrpc] e[02:45:00.726] <-- breakpoint {"type": "event", "event": "breakpoint", "body": {"reason": "new", "breakpoint": {"id": 1, "verified": true, "source": {"name": "test.c", "path": "/workspace/test/test.c"}, "line\
": 10, "instructionReference": "0x1196"}}, "seq": 22}
ezaquarii commented 1 month ago

@svaante Not happening anymore on Fedora 40, Dape 0.15.0 stable, gdb 15.1.1. Since I upgraded my workstation, I won't be able to add anything new here.

ezaquarii commented 1 month ago

@luluman try with newer GDB, it worked for me.