我尝试使用断点在vscode中调试我的C,但每次运行调试器时,调试器似乎都跳过了断点(断点的颜色从红色变成灰色)。我看了这个question,它本质上是我的同一个问题。我试了那里所有的答案,没有一个有效(没有一个被提问的人设置为“答案”,因此我再次问这个问题)。所以我的问题是,如何让vscode断点在C中工作?
Vscode版本:在Windows 10上为1.73.1
gdb版本:12.1
启动.json
{
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc.exe build active file",
}
]
任务.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe build active file",
"command": "make",
"args": [
"all"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
生成文件
dynamic_array: dynamic_array.c dynamic_array.h
gcc -c dynamic_array.c
test: test.c dynamic_array.h
gcc -c test.c
all: dynamic_array.o test.o
gcc -o test.exe dynamic_array.o test.o
clean:
del -f *.o & del -f *.exe & del -f *.out
1条答案
按热度按时间7rtdyuoh1#
你的makefile有很多问题。首先,你构建的目标是
all
,它依赖于dynamic_array.o
和test.o
,但是,没有构建这些的规则,只有构建dynamic_array
和test
的规则。因此,
make
将使用其默认规则来构建.o
文件,即:这导致了下一个问题,这可能就是您看到的断点问题的原因-无论是隐式规则还是您试图编写的规则,都不包括
gcc
的-g
标志。-g
标志打开调试信息的生成。我至少会将makefile重写为: