【问题标题】:Setting up VSCode for C/C++ debugging on Window 7 with gcc, g++ and gdb使用 gcc、g++ 和 gdb 在 Window 7 上为 C/C++ 调试设置 VSCode
【发布时间】:2017-07-31 18:33:34
【问题描述】:

我按照here 的指示进行操作。安装了 cpptools。创建tasks.json,内容如下:

{
    "version": "0.1.0",
    "command": "g++",
    "isShellCommand": true,
    "showOutput": "always",
    "args": ["-g", "helloworld.c"]
}

还有launch.json,内容如下:

{
    "version": "0.2.0",
    "configurations": [

        {
            "name": "C++ Launch (Windows)",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${workspaceRoot}/a.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}",
            "environment": [],
            "externalConsole": false,
            "windows": {
                "MIMode" : "gdb",
                "miDebuggerPath": "C:\\Mahesh\\Program Files\\mingw\\MinGW\\bin\\gdb.exe"
            }

        },
        {
            "name": "C++ Attach (Windows)",
            "program": "${workspaceRoot}/a.exe",
            "type": "cppvsdbg",
            "request": "attach",
            "processId": "${command.pickProcess}",
            "windows": {
                "MIMode" : "gdb",
                "miDebuggerPath": "C:\\Mahesh\\Program Files\\mingw\\MinGW\\bin\\gdb.exe"
            }
        }
    ]
}

当我执行Ctrl+Shift+B 时,代码构建,生成a.exe。当我运行调试时,它会给出以下输出:

--------------------------------------------------------------------------------
You may only use the C/C++ Extension for Visual Studio Code with Visual Studio
Code, Visual Studio or Xamarin Studio software to help you develop and test your
applications.
--------------------------------------------------------------------------------
Loaded 'C:\Mahesh\repos\VSCodeC\polyaddition\a.exe'. Symbols are not loaded.
Loaded 'C:\Windows\System32\ntdll.dll'. Symbols are not loaded.
Loaded 'C:\Windows\System32\kernel32.dll'. Symbols are not loaded.
Loaded 'C:\Windows\System32\KernelBase.dll'. Symbols are not loaded.
Loaded 'C:\Windows\System32\sysfer.dll'. Symbols are not loaded.
Loaded 'C:\Windows\System32\msvcr100.dll'. Symbols are not loaded.
Loaded 'C:\Windows\System32\QIPCAP64.dll'. Symbols are not loaded.
Loaded 'C:\Windows\System32\oleaut32.dll'. Symbols are not loaded.
Loaded 'C:\Windows\System32\ole32.dll'. Symbols are not loaded.
Loaded 'C:\Windows\System32\msvcrt.dll'. Symbols are not loaded.
Loaded 'C:\Windows\System32\gdi32.dll'. Symbols are not loaded.
Loaded 'C:\Windows\System32\user32.dll'. Symbols are not loaded.
Loaded 'C:\Windows\System32\lpk.dll'. Symbols are not loaded.
Loaded 'C:\Windows\System32\usp10.dll'. Symbols are not loaded.
Loaded 'C:\Windows\System32\rpcrt4.dll'. Symbols are not loaded.
Loaded 'C:\Windows\System32\imm32.dll'. Symbols are not loaded.
Loaded 'C:\Windows\System32\msctf.dll'. Symbols are not loaded.
The thread 9524 has exited with code 0 (0x0).
Hello World!!!
The program '[7876] a.exe' has exited with code 0 (0x0).

但是代码没有达到我在代码中设置的调试点。你可以看到,它正在打印“Hello World!!!”。我该如何配置才能让我在调试时单步执行代码?

环境:

  • 程序“[7876] a.exe”已退出,代码为 0 (0x0), 配置为“i686-pc-mingw32”。
  • gcc.exe (x86_64-win32-seh-rev201506, mingwpy build) 4.9.2
  • g++.exe (x86_64-win32-seh-rev201506, mingwpy build) 4.9.2

更新

  • comments 的讨论中,我被要求运行带有m32 标志的gcc,因为我的编译器是64 位的,它可能会生成64 位二进制文​​件。但是gcc -m32 helloworld.c 给出了this 之类的错误。 comment here-m32 选项解释它。它要求在编译时添加i686-w64-mingw32/x86_64-w64-mingw32 标志。但是gcc -x86_64-w64-mingw32 helloworld.c 给出了language not recognized 错误,gcc -i686-w64-mingw32 helloworld.c 给出了unrecognized command line option。我做错了什么?
  • 另外,this 文章说目前只能在 linux 上进行调试,而在 Windows 上则不行。是这样吗?

【问题讨论】:

  • 您需要设置调试符号的路径。 symbolSearchPath=C:\\path_1;D:\\path_2;etc...
  • 关于配置launch.json 的 GitHub VSCode 小文章。希望它会有所帮助。 github.com/Microsoft/vscode-cpptools/blob/master/launch.md
  • @Ingenioushax 但是那些调试符号在哪里?正如我所说的,gcc -g helloworld.c 不会生成任何调试符号。
  • 注意 Mahesh,您在“程序文件”中安装了 Mingw

标签: c++ c g++ visual-studio-code vscode-settings


【解决方案1】:

我相信您正在尝试使用 VS 代码调试器 (cppvsdbg) 而不是 gdb (cppdbg)。修改后的 launch.json 对我有用,将 TDM-GCC 和 gdb 作为调试器:

{
"version": "0.2.0",
"configurations": [
    {
        "name": "C++ Launch",
        "type": "cppdbg",
        "request": "launch",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceRoot}",
        "environment": [],
        "externalConsole": true,

        "linux": {
            "program": "${workspaceRoot}/a.out",
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        },
        "osx": {
            "MIMode": "lldb"
        },
        "windows": {
            "miDebuggerPath": "C:\\TDM-GCC-64\\bin\\gdb.exe",
            "program": "${workspaceRoot}\\a.exe",
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    },
    {
        "name": "C++ Attach",
        "miDebuggerPath": "C:\\TDM-GCC-64\\bin\\gdb.exe",
        "type": "cppdbg",
        "request": "attach",
        "program": "${workspaceRoot}/a.exe",
        "processId": "${command:pickProcess}",
        "linux": {
            "MIMode": "gdb",
            "program": "${workspaceRoot}/a.out",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        },
        "osx": {
            "MIMode": "lldb"
        },
        "windows": {
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\TDM-GCC-64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    }
    ]
}

【讨论】:

    【解决方案2】:

    如果你想让 command.PickProcess 工作..

    应该是 ':' 而不是 '.' - 因此:

    {
        "name": ".NET Core Attach",
        "type": "coreclr",
        "request": "attach",
        "processId": "${command:pickProcess}"
    }
    

    应该帮你解决掉:)

    【讨论】:

      【解决方案3】:

      我以前遇到过这个问题。就我而言,编译器默认生成了一个发布应用程序。它没有用于调试的符号。

      所以,请确保您已生成调试应用程序以进行调试。

      祝你好运!

      【讨论】:

      • 这是什么意思?
      猜你喜欢
      • 2020-06-02
      • 2021-06-02
      • 2016-09-02
      • 2018-04-17
      • 2021-10-28
      • 1970-01-01
      • 2023-02-26
      • 2017-04-11
      • 1970-01-01
      相关资源
      最近更新 更多