Or Yaacov
Or Yaacov

Reputation: 3880

How to use GCC for compilation and debug on VSCode

I have found out a few different ways to debug C with the GCC compiler, however I want to have debugging on by default. Is there any way I can do this with a setting in my launch.json in VSCode?

Here is my launch.json:

{
    // 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": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/a.out",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

Upvotes: 1

Views: 5003

Answers (1)

S.S. Anne
S.S. Anne

Reputation: 15576

Add these to your CFLAGS: -gdwarf-4 -g3

To do that, run this command:

export CFLAGS="${CFLAGS} -gdwarf-4 -g3"

See this link for more information and this link for running commands in launch.json.

Upvotes: 2

Related Questions