1 //test.cpp
2 #include
3 int g_var = 0;
4 void print_line(char *str)
5 {
6 if (str != NULL)
7 printf("%s\r\n", str);
8 else
9 printf("null string\r\n");
10 }
11 int main (int argc, char **argv)
12 {
13 int l_var = 1;
14 print_line("hello world!");
15 printf("g_var = %d, l_var = %d.\r\n", g_var, l_var);
16 return 0;
17 }
View Code
launch.json
1 {
2 "version": "0.2.0",
3 "configurations": [
4 {
5 "name": "(gdb) Launch",
6 "type": "cppdbg",
7 "request": "launch",
8 "program": "${workspaceRoot}/test.exe",
9 "args": [],
10 "stopAtEntry": false,
11 "cwd": "${workspaceRoot}",
12 "environment": [],
13 "externalConsole": true,
14 "MIMode": "gdb",
15 "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
16 "setupCommands": [
17 {
18 "description": "Enable pretty-printing for gdb",
19 "text": "-enable-pretty-printing",
20 "ignoreFailures": true
21 }
22 ]
23 }
24 ]
25 }
View Code
tasks.json
1 {
2 // See https://go.microsoft.com/fwlink/?LinkId=733558
3 // for the documentation about the tasks.json format
4 "version": "2.0.0",
5 "tasks": [
6 {
7 "taskName": "test",
8 "type": "shell",
9 "command": "g++",
10 "args": ["-g", "${file}", "-o", "${workspaceRoot}/test.exe"]
11 }
12 ]
13 }
View Code
编译成功后,在源码中设置断点,却无法命中断点。
后来查看官方c++编译调试文档和尝试,在launch.json文件的
“setupCommands”: [
{
“description”: “Enable pretty-printing for gdb”,
“text”: “-enable-pretty-printing”,
“ignoreFailures”: true
}
]
后面加上
“preLaunchTask”: “test” 配置,调试时就可以正常命中断点了。
注意:别忘了”setupCommands”的中括号’ ] ‘后面加上一个逗号。
Original: https://www.cnblogs.com/lisuyun/p/7604571.html
Author: 言止予思
Title: vscode c++ 编译生成后,调试时无法命中断点
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/536251/
转载文章受原作者版权保护。转载请注明原作者出处!