【发布时间】: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