簡體   English   中英

在 vs 代碼中在哪里添加 -g 標志以進行調試

[英]Where to add -g flag in vs code for debugging

我有兩個問題。 我剛剛安裝了 VS 代碼並設法讓它編譯 C 代碼並顯示輸出。 但我無法調試。 當我添加斷點和調試時,紅色圓圈變灰。

我在 github 上讀到添加 -g 標志會起作用

一季度。 但是在哪里以及如何添加-g標志? 我還讀到:

如何將編譯標志 -g 添加到 make 文件?

但它從我頭上掠過。

啟動.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
}

任務.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之外添加,程序仍然沒有調試。

編輯:

Q2。 另外還告訴我是否可以在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++"

您應該添加該標志,而不是替換"-o"標志。

-o標志告訴編譯器輸出文件的名稱。

因此,例如

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

你可以在 vs code 幫助中心網站上詢問

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM