C++中的断点设置在Visual Studio代码中的错误行[重复]

tkclm6bt  于 2024-01-09  发布在  其他
关注(0)|答案(1)|浏览(196)

此问题在此处已有答案

GCC option that can cause trouble when debugging with GDB(2个答案)
5天前关闭。
我的问题基本上和breakpoint wrong place - vue问题一样。但是它出现在c++中。
当我通过单击槽线设置行断点时,断点被创建在错误的行中。例如,我单击了第28行,但断点被创建在第34行(视觉上和调试器停止)。
虽然在某些行上设置断点可以正常工作,但大多数似乎会跳转到不正确的行。
下面是来自发动机日志的日志。

  1. 1: (41828) <-1052-break-insert -f B_Not_Quite_Latin_Square.cpp:28
  2. 1: (41837) ->1052^done,bkpt={number="12",type="breakpoint",disp="keep",enabled="y",addr="0x00007ff6e0de1880",
  3. func="std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char)",
  4. file="C:\\Data\\CompetitiveProgramming\\B_Not_Quite_Latin_Square.cpp",
  5. fullname="C:\\Data\\CompetitiveProgramming\\B_Not_Quite_Latin_Square.cpp",
  6. 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:

  1. {
  2. "tasks": [
  3. {
  4. "label": "build",
  5. "type": "cppbuild",
  6. "command": "C:/Program Files/mingw64/bin/g++.exe",
  7. "args": [
  8. "-x",
  9. "c++",
  10. "-g",
  11. "-O2",
  12. "-std=gnu++20",
  13. "-static",
  14. "-fdiagnostics-color=always",
  15. "${file}",
  16. "-o",
  17. "${fileDirname}\\${fileBasenameNoExtension}.exe"
  18. ],
  19. "options": {
  20. "cwd": "C:/Program Files/mingw64/bin"
  21. },
  22. "problemMatcher": ["$gcc"],
  23. "group": {
  24. "kind": "build",
  25. "isDefault": true
  26. }
  27. }
  28. ],
  29. "version": "2.0.0"
  30. }


launch.json:

  1. {
  2. "version": "0.2.0",
  3. "configurations": [
  4. {
  5. "name": "(gdb) Debug",
  6. "preLaunchTask": "build",
  7. "type": "cppdbg",
  8. "request": "launch",
  9. "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
  10. "args": [],
  11. "stopAtEntry": false,
  12. "cwd": "${fileDirname}",
  13. "environment": [],
  14. "externalConsole": false,
  15. "MIMode": "gdb",
  16. "miDebuggerPath": "C:\\Program Files\\mingw64\\bin\\gdb.exe",
  17. "logging": {"engineLogging":true},
  18. "setupCommands": [
  19. {
  20. "description": "Enable pretty-printing for gdb",
  21. "text": "-enable-pretty-printing",
  22. "ignoreFailures": true
  23. },
  24. {
  25. "description": "Set Disassembly Flavor to Intel",
  26. "text": "-gdb-set disassembly-flavor intel",
  27. "ignoreFailures": true
  28. }
  29. ]
  30. }
  31. ]
  32. }

试用

我试着将sourceFileMap添加到launch.json中,但是问题没有解决。

  1. "sourceFileMap":{
  2. "${fileDirname}": {
  3. "editorPath": "${fileDirname}",
  4. "useForBreakpoints": true
  5. }
  6. },

50pmv0ei

50pmv0ei1#

从构建任务中删除-O2选项解决了此问题。
这个问题与gdb有关,而与vscode集成调试器无关。
关于这个问题还有其他的答案。
GCC option that can cause trouble when debugging with GDB
gdb breakpoint gets hit in the wrong line number

相关问题