【问题标题】:Where to add -g flag in vs code for debugging在vs代码中在哪里添加-g标志进行调试
【发布时间】:2019-01-31 12:25:06
【问题描述】:

我有两个问题。我刚刚安装了 VS 代码并设法让它编译 C 代码并显示输出。但我无法调试。当我添加断点和调试时,红色圆圈变灰。

I read on github that adding a -g flag will work

第一季度。但是在哪里以及如何添加-g 标志?我还阅读了:

How to add compile flag -g to a make file?

但它从我的脑海中掠过。

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}/try.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\gdb.exe",
            "preLaunchTask": "echo",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "C:\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\lib\\gcc\\i686-w64-mingw32\\8.1.0\\include\\c++"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\gcc.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

tasks.json:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "echo",
            "type": "shell",
            "command": "gcc",
            "args": [
                "-Wall", "try.c", "-o", "try"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

我尝试将tasks.json 中的args-o 更改为-g,但它也阻止了它的编译,这至少以前可以工作。如果我在-o之外添加,程序仍然没有调试。

编辑:

第二季度。另外还告诉我是否可以在tasks.json这里添加C++的路径而不是C?

因为我找不到 C 的路径。互联网上的教程是针对 C++ 的,他们告诉在那里设置 C++ 路径。但我想编译 C 代码,虽然它们现在正在编译。

"includePath": [
                "${workspaceFolder}/**",
                "C:\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\lib\\gcc\\i686-w64-mingw32\\8.1.0\\include\\c++"

【问题讨论】:

    标签: c debugging visual-studio-code vscode-debugger vscode-tasks


    【解决方案1】:

    你应该添加标志,而不是替换"-o"标志。

    -o 标志告诉编译器输出文件的名称。

    所以改为有例如

    "-Wall", "-g", "try.c", "-o", "try"
    

    【讨论】:

    • 太棒了!还请回答我的问题的编辑部分中写的问题
    猜你喜欢
    • 1970-01-01
    • 2015-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-07
    • 2020-11-21
    • 1970-01-01
    相关资源
    最近更新 更多