【问题标题】:having trouble debugging a C file in vscode在 vscode 中调试 C 文件时遇到问题
【发布时间】:2019-12-18 15:55:10
【问题描述】:

我有一个 C 文件,我正在尝试调试但失败了。 我在 Windows 10 上使用 vscode。 文件比较大,这里就不复制了。

这就是我的 launch.json 文件在我正在工作的文件夹中的 .vscode 文件夹中的样子:

{
    // 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.exe build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "gcc.exe build active file"
        }
    ]
}

这就是我的 tasks.json 在同一个 .vscode 文件夹中的样子:

{
    "tasks": [
        {
            "type": "shell",
            "label": "gcc.exe build active file",
            "command": "C:\\MinGW\\bin\\gcc.exe",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "C:\\MinGW\\bin"
            }
        }
    ],
    "version": "2.0.0"
}

当我按下“开始调试”按钮时,屏幕冻结,程序停止,然后 vscode 崩溃

【问题讨论】:

  • 编译后,可执行文件是否也在其他所有文件(头文件、c文件等)所在的文件夹中?尝试“硬编码”程序的路径,例如"program": "${workspaceFolder}/message_queue.exe"。 workspaceFolder 是我的文件夹,在 vs code 中打开,message_queue.exe 是我的 .exe 文件。
  • 请尝试在没有 vs 代码的情况下运行 gdb.exe。它有效吗? C:\mingw\bin\gdb.exe YOUR_PROGRAM_NAME.exe
  • @derallbert 没有任何工作,我想我别无选择,只能下载 Visual Studio。啊啊啊好烦

标签: debugging visual-studio-code


【解决方案1】:

我设法找到了一个解决方案,我删除了旧文件,点击调试,它要我创建一个新配置,选择 gcc 启动然后有一个选项 'gcc.exe build and debug active file' ,点击它,现在一切正常。 如果将来有人遇到同样的问题,我已将上述文件的内容更新为它们现在的样子。

【讨论】:

    猜你喜欢
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-27
    • 2021-10-23
    • 2012-09-28
    • 2017-07-21
    • 1970-01-01
    相关资源
    最近更新 更多