0

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?

7
  • Have you tried setting stopAtEntry? Or just putting whatever commands you need to run in setupCommands? Or using a .gdbinit file Commented May 31 at 5:41
  • Tried stopAtEntry with both true and false - both give same Unable to ... message. Commented Jun 2 at 21:33
  • One observation - along with the debug console, it launches a terminal too and the terminal is stuck (no prompt etc.). If I interrupt the terminal, the gdb session dies - not sure if this is expected or not. Commented Jun 2 at 22:34
  • Tried adding "targetArchitecture": "x86_64" and "stopAtConnect": true. But nothing helped. Commented Jun 3 at 20:50
  • @AzuxirenLeadGuy - can you suggest what I may be doing wrong or how to debug the issue? I saw you responded to a similar issue few years ago. Commented Jun 3 at 20:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.