VSCode GDB调试配置

VSCode GDB调试配置

1. vscode启动debug窗口

按Ctrl+Shift+D,打开Debug窗口

默认是“No configurations”, 点击“F5”,会提示你配置GDB参数(选择gcc build and debug active file),配置文件名称为launch.json(配置参考3)

配置完成后,再按F5, 会提示配置GCC,选择“Configure Task”, 选择“C/C++: build and debug active file”, 配置文件名称为task.json(配置参考2)

2. GCC配置

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "gcc build active file",
            "command": "/usr/share/mips-gcc-4.6/staging_dir/bin/mips-linux-gcc",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "/usr/bin"
            },
            "problemMatcher": [
                "$gcc"
            ]
        }
    ]
}

“command”: 编译链的地址

3. GDB配置

{
    // 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": "gcc build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "miDebuggerServerAddress": "192.168.0.1:10000",
            "program": "/home/renyinshan/work/p53/apps/cmdlib/test",
            "args": [],
            "stopAtEntry": true,
            "cwd": "/home/renyinshan/work/p53/apps/cmdlib/",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "gcc build active file",
            "miDebuggerPath": "/home/renyinshan/work/p53/apps/gdb/install/bin/mips-linux-gdb"
        }
    ]
}

“program”: 要调试的程序名(包含路径,最好绝对路径,免得麻烦)
“miDebuggerServerAddress”: 服务器的地址和端口
“cwd”: 调试程度的路径
“miDebuggerPath”: gdb的路径

4. GDB server编译及运行

1)编译
P53编译时,请打开如下开关; P59需要从编译链目录拷贝一个。

scripts/tozedap-router_4g_industry/config.tozedap-router_4g_industry:564:export NO_CPP_LIB=0

GDB运行需要libstdc++.so.6的库,所以需要把此开关打开。
./cool 3 gdb_build

等待完成即可

编译完成后的文件如下

renyinshan@renyinshan:~/work/p53/build$ ls ../apps/gdb/install/*
../apps/gdb/install/bin:
mips-linux-gdb  mips-linux-gdb-add-index  mips-linux-run

../apps/gdb/install/include:
gdb

../apps/gdb/install/lib:
libmips-linux-sim.a

../apps/gdb/install/share:
gdb  info  locale  man

renyinshan@renyinshan:~/work/p53/build$ ls ../apps/gdb/installgdbserver/bin/
mips-linux-gdbserver
renyinshan@renyinshan:~/work/p53/build$ 

说明:
install/bin 目录的mips-linux-gdb为vscode中配置需要的;
installgdbserver/bin/ 目录中的mips-linux-gdbserver,需要拷贝到板子中;

2)ssh登录设备,下载gdbserver到/tmp目录中, 并增加+x权限
3)ssh登录设备,下载可执行程序到/tmp目录中, 并增加+x权限
4)运行

/tmp # ./mips-linux-gdbserver :10000 ./test

调试输出:

/tmp # ./mips-linux-gdbserver :10000 test 
Process /tmp/test created; pid = 22608
Listening on port 10000
Remote debugging from host 192.168.0.245
APP is running! 

备注说明:
1) 下载的可执行程序,必须保证是设备所需编译链编译的;
2) vscode中按F5调试时,GCC编译的配置和GDB参考1和2;

5. 调试

准备完成, 在VSCode进行调试。(断电,单步等)

非常实用,可以经常使用 !!!

  • 6
    点赞
  • 39
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
VSCode是一款非常流行的代码编辑器,它提供了丰富的插件来支持各种编程语言的开发和调试。其中,GDB是一种常用的调试器,可以用于调试C、C++等编程语言。下面是在VSCode中使用GDB进行调试的方法: 1. 安装插件:首先,在VSCode中安装C/C++插件和CodeLLDB插件。C/C++插件提供了基本的C/C++开发支持,而CodeLLDB插件则提供了与GDB集成的功能。 2. 配置调试环境:在VSCode中打开你的项目文件夹,并创建一个名为`.vscode`的文件夹。在该文件夹中创建一个名为`launch.json`的文件,并在其中添加以下配置: ```json { "version": "0.2.0", "configurations": [ { "name": "Debug with GDB", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/your_program", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "gdb" } ] } ``` 请将`your_program`替换为你要调试的程序的路径。 3. 开始调试:在VSCode中按下`F5`键,或者点击左侧的调试按钮,选择`Debug with GDB`配置,然后点击开始调试按钮。VSCode将会启动GDB,并在调试控制台中显示调试信息。 4. 设置断点:在你希望进行调试的代码行上设置断点。当程序执行到断点时,调试器会暂停程序的执行,并允许你查看变量的值、执行表达式等。 5. 调试操作:在调试过程中,你可以使用调试控制台中的命令来控制程序的执行,例如继续执行、单步执行、跳过当前函数等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值