小编给大家分享一下vscode不能命中断点的解决方法,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
vscode不能命中断点如何解决?
vscode c++ 编译生成后,调试时无法命中断点的解决办法
//test.cpp
#include <stdio.h>
int g_var = 0;
void print_line(char *str)
{
if (str != NULL)
printf("%s\r\n", str);
else
printf("null string\r\n");
}
int main (int argc, char **argv)
{
int l_var = 1;
print_line("hello world!");
printf("g_var = %d, l_var = %d.\r\n", g_var, l_var);
return 0;
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/test.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"taskName": "test",
"type": "shell",
"command": "g++",
"args": ["-g", "${file}", "-o", "${workspaceRoot}/test.exe"]
}
]
}
编译成功后,在源码中设置断点,却无法命中断点。
后来查看官方c++编译调试文档和尝试,在launch.json文件的
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
后面加上
"preLaunchTask": "test" 配置,调试时就可以正常命中断点了。
注意:别忘了"setupCommands"的中括号’ ] ‘后面加上一个逗号。
以上是“vscode不能命中断点的解决方法”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。