登录  /  注册
首页 > 开发工具 > VSCode > 正文

vscode如何使用gdb调试

王林
发布: 2020-02-12 14:00:50
原创
9939人浏览过

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进行调试。

相关推荐:vscode教程

以上就是vscode如何使用gdb调试的详细内容,更多请关注php中文网其它相关文章!

智能AI问答
PHP中文网智能助手能迅速回答你的编程问题,提供实时的代码和解决方案,帮助你解决各种难题。不仅如此,它还能提供编程资源和学习指导,帮助你快速提升编程技能。无论你是初学者还是专业人士,AI智能助手都能成为你的可靠助手,助力你在编程领域取得更大的成就。
相关标签:
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
关于CSS思维导图的课件在哪? 课件
凡人来自于2024-04-16 10:10:18
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号