如何使用GCC在VSCode上进行编译和调试

时间:2019-03-03 13:23:25

标签: c gcc visual-studio-code

我发现了使用GCC编译器调试C的几种不同方法,但是我想默认启用调试功能。我可以通过VSCode中的launch.json中的设置来执行此操作吗?

这是我的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
                }
            ]
        }
    ]
}

1 个答案:

答案 0 :(得分:3)

将这些添加到CFLAGS:-gdwarf-4 -g3

为此,请运行以下命令:

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

有关更多信息,请参见this链接,有关在launch.json中运行命令的信息,请参见this链接。