此问题在此处已有答案:
GCC option that can cause trouble when debugging with GDB(2个答案)
5天前关闭。
我的问题基本上和breakpoint wrong place - vue问题一样。但是它出现在c++中。
当我通过单击槽线设置行断点时,断点被创建在错误的行中。例如,我单击了第28行,但断点被创建在第34行(视觉上和调试器停止)。
虽然在某些行上设置断点可以正常工作,但大多数似乎会跳转到不正确的行。
下面是来自发动机日志的日志。
1: (41828) <-1052-break-insert -f B_Not_Quite_Latin_Square.cpp:28
1: (41837) ->1052^done,bkpt={number="12",type="breakpoint",disp="keep",enabled="y",addr="0x00007ff6e0de1880",
func="std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char)",
file="C:\\Data\\CompetitiveProgramming\\B_Not_Quite_Latin_Square.cpp",
fullname="C:\\Data\\CompetitiveProgramming\\B_Not_Quite_Latin_Square.cpp",
line="34",thread-groups=["i1"],times="0",original-location="B_Not_Quite_Latin_Square.cpp:28"
字符串
我已经点击了第28行作为断点。但是在日志的最后一行,调试器返回了line=“34”中插入的断点。
下面是我的tasks.json和launch.json配置。tasks.json:
{
"tasks": [
{
"label": "build",
"type": "cppbuild",
"command": "C:/Program Files/mingw64/bin/g++.exe",
"args": [
"-x",
"c++",
"-g",
"-O2",
"-std=gnu++20",
"-static",
"-fdiagnostics-color=always",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:/Program Files/mingw64/bin"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
}
}
],
"version": "2.0.0"
}
型
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Debug",
"preLaunchTask": "build",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files\\mingw64\\bin\\gdb.exe",
"logging": {"engineLogging":true},
"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
}
]
}
]
}
型
试用
我试着将sourceFileMap
添加到launch.json中,但是问题没有解决。
"sourceFileMap":{
"${fileDirname}": {
"editorPath": "${fileDirname}",
"useForBreakpoints": true
}
},
型
1条答案
按热度按时间50pmv0ei1#
从构建任务中删除
-O2
选项解决了此问题。这个问题与gdb有关,而与vscode集成调试器无关。
关于这个问题还有其他的答案。
GCC option that can cause trouble when debugging with GDB
gdb breakpoint gets hit in the wrong line number的