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教程
以上就是vscode不能命中断点如何解决的详细内容。