首页 > 应用开发 > > ubuntu vscode调试C++代码
在CentOS 7中使用VS Code编译调试C++项目
https://www.cnblogs.com/lenmom/p/9193388.html
使用 VS Code 开发 RT-Thread
https://www.rt-thread.org/document/site/application-note/setup/qemu/vscode/an0021-qemu-vscode/
ubuntu vscode调试C++代码,在unbutn 18.04 x64 , vscode 1.33.1通过
1、安装vscode
2、安装C++插件

3、添加工作区文件夹,ctrl+shift+d 打开调试栏,点击齿轮图标后自动生成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) Launch",
"type": "cppdbg",
"request": "launch",
//"program": "enter program name, for example ${workspaceFolder}/a.out", <<默认生成的内容,根据需要修改为下行内容
"program": "${workspaceFolder}/${fileBasenameNoExtension}.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
//"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"preLaunchTask": "g++ build active file", <<默认没有这项,自己添加的,表示调试前要执行的动作,这里需要调试前做编译,名称与后面task.json中的描述对应。
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
4、CTRL+SHIFT+P,打开任务栏,选择:配置任务
TASK: configure task或 配置默认编译任务TASK: configure default build task,之后根据编译需要选择g++ 或 gcc 或 自定义,这时会生成task.json文件,可根据需要修改
{
// 有关 tasks.json 格式的文档,请参见
// https://go.microsoft.com/fwlink/?LinkId=733558
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++ build active file", <<这个名称与launch.json中"preLaunchTask": 项的名称对应。
"command": "/usr/bin/g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.out"
],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
5、之后F5,就可以断点调试了。
使用 VS Code 开发 RT-Thread
https://www.rt-thread.org/document/site/application-note/setup/qemu/vscode/an0021-qemu-vscode/
vs调试窗口仅有基本的watch项,如变量监视,如果想用高级的调试功能可在调试控制台中调用gdb的功能,方法是用-exec 命令
如:查看寄存器
-exec info registers

查看内存
-exec x /3u 0x7fffffffdca8

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2480/viewspace-3151531/ ,如需转载,请注明出处,否则将追究法律责任。