VScode设置断点调试(以cpp为例)
-
首先得到launch.json文件和task.json文件

运行和调试–>打开launch.json(类似设置的按钮) 打开launch.json文件

ctrl+shift+p打开搜索框输入tasks–>配置默认生成任务得到task.json文件
-
launch.json内容
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "(gdb) 启动", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/a.out",//gdb目标的路径 "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}",//当前工作目录 "environment": [], "externalConsole": false, "MIMode": "gdb", "setupCommands": [ { "description": "为 gdb 启用整齐打印", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "g++"//前置任务 对应tasks.json的label } ] } -
tasks.json内容
{ // 有关 tasks.json 格式的文档,请参见 // https://go.microsoft.com/fwlink/?LinkId=733558 "version": "2.0.0", "tasks": [ { "type": "shell", "label": "g++",//对应launch的preLaunchTask "command": "/usr/bin/g++",//执行的命令 "args": [ "-g", "${file}", "-o", "a.out"//生成的可执行文件名称 对应launch.json的program ], "options": { "cwd": "${workspaceFolder}" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true } } ] } -
设置断点 进行调试

本文介绍如何在VScode中为C++项目设置断点和调试。通过运行和调试菜单创建launch.json文件,然后配置launch.json和task.json以进行编译和调试。在代码中设置断点后,即可开始调试过程。
3万+

被折叠的 条评论
为什么被折叠?



