码迷,mamicode.com
首页 > 编程语言 > 详细

vscode c++ 编译生成后,调试时无法命中断点

时间:2017-09-28 00:33:36      阅读:686      评论:0      收藏:0      [点我收藏+]

标签:[]   config   文件的   ace   one   ros   task   logs   ring   

技术分享
 1 //test.cpp
 2 #include <stdio.h>
 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"的中括号’ ] ‘后面加上一个逗号。
 
 

 

vscode c++ 编译生成后,调试时无法命中断点

标签:[]   config   文件的   ace   one   ros   task   logs   ring   

原文地址:http://www.cnblogs.com/lisuyun/p/7604571.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!