跳转到主内容
趣航编程网 - 趣学编程,启航技术之路!

vscode不能命中断点如何解决

vscode不能命中断点如何解决? vscode c++ 编译生成后,调试时无法命中断点的解决办法
//test.cpp #include int g_var = 0; void print_line(char *str) { if (str != NULL) printf("%s ", str); else printf("null string "); } int main (int argc, char **argv) { int l_var = 1; print_line("hello world!"); printf("g_var = %d, l_var = %d. ", 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文件的 VSCode 1.118 微软正式发布 Visual Studio Code 1.118 版本 。本次更新重点强化了 AI 开发体验与企业管理能力,其中最引人注目的是新增 Copilot CLI 远程控制功能,允许开发者通过手机或网页远程监控和接管 AI 会话 。同时,为了提高 AI 的运行性价比,新版本优化了令牌缓存策略以降低成本 。此外,1.118 版还引入了 Chronicle 本地历史追踪、TypeScript 7.0 支持以及更严格的企业级访问管控 。 下载
"setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ]
后面加上 "preLaunchTask": "test" 配置,调试时就可以正常命中断点了。 注意:别忘了"setupCommands"的中括号’ ] ‘后面加上一个逗号。 相关推荐: vscode教程

相关文章