I moved from emacs to VS Code few months back. We have a large C++ code base. In emacs, I used to debug using gud-gdb interface. However, I have not been able to successfully setup gdb with vs code.
I just want gdb to get launched and load the binary (not start the run). This is because, I have gdb python script that I use to setup PATH and LD_LIBRARY_PATH depending upon MYPROG_HOME env variables and I want to use that as well set args before running the program.
I have tried following launch.json -
{
"version": "0.2.0",
"configurations": [
{
"name": "GDB Debug Manual Mode",
"type": "cppdbg",
"request": "launch",
// "program": "${BUILD_PATH}/bin-linux64/myprog-G",
"program": <full-path to myprog-G>,
"cwd": "<test dir where I want to debug>",
"MIMode": "gdb",
"miDebuggerPath": "<path to gdb>",
"stopAtEntry": true,
"launchCompleteCommand": "None",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
]
}
]
}
But when I invoke gdb from the Run and Debug option, gdb prompt comes up. But when I try any gdb commands (like show env MYPROG_HOME), it gives me below error message:
Unable to perform this action because the process is running.
Waiting for longer time (5-10 min) does not help. I must be missing something. Can somebody guide me what am I missing or how to debug it further to understand the issue?
I am using gdb 14.2 version (cannot override this to newer version as we cannot install a new version).
Edit 2 (after edit by another user):
I tried enabling logging using following:
"logging": {
"engineLogging": true,
"trace": true,
"traceResponse": true,
},
And now when the gdb prompt comes, if I type "show env PATH", I get following o/p -
show env PATH
<-- C (evaluate-25): {"command":"evaluate","arguments":{"expression":"show env PATH","context":"repl"},"type":"request","seq":25}
--> R (evaluate-25): {"type":"response","request_seq":25,"success":false,"command":"evaluate","message":"Failed to handle EvaluateRequest","body":{"error":{"id":1105,"format":"Unable to perform this action because the process is running."}},"seq":215}
Unable to perform this action because the process is running.
Does it mean "stopAtEntry" : true not working for some reason. Is it possible to specify to break at main?
stopAtEntry? Or just putting whatever commands you need to run insetupCommands? Or using a .gdbinit filestopAtEntrywith both true and false - both give sameUnable to ...message."targetArchitecture": "x86_64"and"stopAtConnect": true. But nothing helped.