Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug in vscode already compiled executable?

When trying to debug in vscode, the vscode generate launch.json config file. When I try to debug, it first tries to compile the source and then debug the exe. I would like to just debug already compiled executable (compiled with gcc -g option).

The json file is:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "gcc-10 - Build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [
                "-pthread",
                "common.c"
            ],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: gcc-10 build active file",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}

Can I make somehow the vsode to not compile but just debug with already compiled source to "program":"${fileDirname}/${fileBasenameNoExtension}", I have compiled to the very same name - no extension in current directory, as the property suggest. So how to make vscode to take this executable as its debug file?

like image 666
milanHrabos Avatar asked Jul 04 '26 21:07

milanHrabos


1 Answers

I'm using google tests for testing my application layer. But I also needed step through debugging of my tests when they fail.

Here is my launch.json generated by vscode with some minor tweaks

 {
        "name": "Debug debug_test",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceFolder}/test/build/app/debug/logging_test.exe",
        "args": [
            "${cmake.testArgs}"
        ],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": false,
        "MIMode": "gdb",
        "miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe",
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            },
            {
                "description": "Set Disassembly Flavor to Intel",
                "text": "-gdb-set disassembly-flavor intel",
                "ignoreFailures": true
            }
        ]
    }

This is executed with the run and debug toolbar on vscode. Im using a ninja build script, with cmake. cmake is using the ninja-multicondig generator. Compiler is from msys2 websitesite. Also there is a .exe and .pdb within the folder. I think both are needed.

like image 162
cagney Avatar answered Jul 06 '26 11:07

cagney



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!