gdbserver 指南

文章目录

  • 1. 前言
  • 2. gdbserver 远程调试
    • 2.1 准备工作
      • 2.1.1 准备 `客户端 gdb` 程序
      • 2.1.2 准备 `服务端 gdbserver`
      • 2.1.3 准备 被调试程序
    • 2.2 调试
      • 2.2.1 通过网络远程调试
        • 2.2.1.1 通过 gdbserver 直接启动程序调试
        • 2.2.1.2 通过 gdbserver 挂接到已运行程序调试
      • 2.2.2 通过串口远程调试
        • 2.2.2.1 通过 gdbserver 直接启动程序调试
        • 2.2.2.2 通过 gdbserver 挂接到已运行程序调试
  • 3. 参考资料

1. 前言

限于作者能力水平,本文可能存在谬误,因此而给读者带来的损失,作者不做任何承诺。

2. gdbserver 远程调试

GDB 远程调试同时需要 服务端 gdbserver客户端 gdb 两个程序。本文以 ARM32 嵌入式设备内程序的调试为例,对 GDB 远程调试方法进行说明。

先对 服务端 gdbserver客户端 gdb 连接拓扑做一个梗概描绘:
在这里插入图片描述

2.1 准备工作

2.1.1 准备 客户端 gdb 程序

客户端 gdb 通过和 服务端 gdbserver 的交互,对运行于目标机器的程序进行调试。笔者使用 Ubuntu 系统作为调试客户端的宿主机,即 客户端 gdb 运行于 Ubuntu 下。

笔者测试使用的嵌入式设备 SDK 的交叉编译工具链已经包含了 客户端 gdb 程序,无需额外准备:

$ arm-linux-gnueabihf-gdb --version
GNU gdb (Linaro GDB 2016.02) 7.10.1.20160210-cvs
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-unknown-linux-gnu --target=arm-linux-gnueabihf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://bugs.launchpad.net/gcc-linaro>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".

如果读者的交叉编译工具链没有包含 gdb,在 Ubuntu 下可通过命令安装适用于多架构平台的 gdb 客户端程序

sudo apt-get install gdb-multiarch

2.1.2 准备 服务端 gdbserver

gdbserver 运行于被调试的目标机器,在本文中目标机器指 ARM 嵌入式设备。笔者是通过 buildroot 构建的 gdbserver,不想使用 buildroot 的读者,可自行查阅相关资料进行 gdbserver 的构建。

构建好 gdbserver 后,将其拷贝到目标机器。笔者是将其拷贝到目标机器/usr/bin 目录,这样可以不用指定路径运行。

2.1.3 准备 被调试程序

/* test.c */

#include <unistd.h>

int main(void)
{
	while (1)
		sleep(5);

	return 0;
}

编译,然后将测试程序 test 拷贝到目标机器

$ arm-linux-gnueabihf-gcc -o test test.c

2.2 调试

2.2.1 通过网络远程调试

在这里插入图片描述

2.2.1.1 通过 gdbserver 直接启动程序调试

首先,在目标机器(本文是指 ARM32 嵌入式设备)上运行命令:

# gdbserver :2345 test 
Process test created; pid = 440
Listening on port 2345

然后,在调试器客户端机器(本文是指 Ubuntu)上运行下列命令:

$ arm-linux-gnueabihf-gdb
GNU gdb (Linaro GDB 2016.02) 7.10.1.20160210-cvs
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-unknown-linux-gnu --target=arm-linux-gnueabihf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://bugs.launchpad.net/gcc-linaro>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb) target remote 192.168.3.8:2345
Remote debugging using 192.168.3.8:2345
Reading /root/test from remote target...
warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead.
Reading /root/test from remote target...
Reading symbols from target:/root/test...done.
Reading /lib/ld-linux-armhf.so.3 from remote target...
Reading /lib/ld-linux-armhf.so.3 from remote target...
Reading symbols from target:/lib/ld-linux-armhf.so.3...(no debugging symbols found)...done.
0xb6fd7a00 in _start () from target:/lib/ld-linux-armhf.so.3
(gdb)

客户端宿主机(本文指 Ubuntu)启动 arm-linux-gnueabihf-gdb 后,通过命令 target remote 192.168.3.8:2345 连接到目标机器。其中,192.168.3.8 是目标机器的的 IP。

这时候,目标机器(本文是指 ARM 嵌入设备)会输出 gdb 客户端连接的消息 Remote debugging from host 192.168.3.168

# gdbserver :2345 test 
Process test created; pid = 440
Listening on port 2345
Remote debugging from host 192.168.3.168

到此,就可以通过 gdb 在客户端宿主机(本文指 Ubuntu),调试目标机器(本文是指 ARM 嵌入设备)的 test 程序了。

2.2.1.2 通过 gdbserver 挂接到已运行程序调试

如果 test 已经运行,可以通过 attach 方式启动 gdbserver,挂接到 test 程序进行调试。

先在目标机器(本文是指 ARM32 嵌入式设备)上启动 test 程序,放入后台运行:

# ./test &
# ps -ef | grep -v grep | grep "test"
  445 root     ./test

gdbserver 挂接到 test 进程:

# gdbserver --attach :2345 445
Attached; pid = 445
Listening on port 2345

客户端宿主机(本文指 Ubuntu)启动 arm-linux-gnueabihf-gdb,然后通过命令 target remote 192.168.3.8:2345 连接到目标机器调试程序:

$ arm-linux-gnueabihf-gdb
GNU gdb (Linaro GDB 2016.02) 7.10.1.20160210-cvs
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-unknown-linux-gnu --target=arm-linux-gnueabihf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://bugs.launchpad.net/gcc-linaro>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb) target remote 192.168.3.8:2345
Remote debugging using 192.168.3.8:2345
Reading /root/test from remote target...
warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead.
Reading /root/test from remote target...
Reading symbols from target:/root/test...done.
Reading /lib/libc.so.6 from remote target...
Reading /lib/ld-linux-armhf.so.3 from remote target...
Reading symbols from target:/lib/libc.so.6...(no debugging symbols found)...done.
Reading symbols from target:/lib/ld-linux-armhf.so.3...(no debugging symbols found)...done.
Reading /lib/ld-linux-armhf.so.3 from remote target...
0xb6e9e134 in nanosleep () from target:/lib/libc.so.6
(gdb)

2.2.2 通过串口远程调试

在这里插入图片描述

2.2.2.1 通过 gdbserver 直接启动程序调试

目标机运行命令:

gdbserver /dev/ttyS1 test

其中,/dev/ttyS1目标机上和客户端宿主机连接的串口设备对象。

客户端宿主机运行命令:

$ arm-linux-gnueabihf-gdb
[......]
(gdb) target remote /dev/ttyUSB0

其中,/dev/ttyUSB0客户端宿主机上和目标机连接的串口设备对象。

2.2.2.2 通过 gdbserver 挂接到已运行程序调试

目标机上依次运行下列命令:

# test &
# ps -ef | grep -v grep | grep "test" ## 查询 test 进程 PID
# gdbserver --attach /dev/ttyS1 445

客户端宿主机运行命令:

$ arm-linux-gnueabihf-gdb
[......]
(gdb) target remote /dev/ttyUSB0

3. 参考资料

[1] Using the gdbserver program
[2] gdbserver(1) — Linux manual page

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/769219.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

WPF对象样式

基本样式设置 Style 设置指定对象的属性 属性&#xff1a; TargetType 引用在哪个类型上面&#xff0c;例如Button、Textblock。。 如果在控件对象里面设置Style&#xff0c;则TargetType必须指定当前控件名 只在作用域里面有效果&#xff0c;其他的相同控件没有影响&…

昇思25天学习打卡营第13天|ResNet50图像分类

1. 学习内容复盘 图像分类是最基础的计算机视觉应用&#xff0c;属于有监督学习类别&#xff0c;如给定一张图像(猫、狗、飞机、汽车等等)&#xff0c;判断图像所属的类别。本章将介绍使用ResNet50网络对CIFAR-10数据集进行分类。 ResNet网络介绍 ResNet50网络是2015年由微软…

Linux应用---内存映射

写在前面&#xff1a; 在进程间通信中&#xff0c;有一种方式内存映射。内存映射也是进程间通信的方式之一&#xff0c;其效率高&#xff0c;可以直接对内存进行操作。本节我们对内存映射进行学习&#xff0c;并结合案例进行实践。 1、基本理论 内存映射&#xff1a;是将磁盘文…

ODN网络弱光聚类定界与整治

01 ODN网络弱光运维现状 ODN网络是家庭宽带连接系统-无源光网络 (PON) 的重要组成部分&#xff0c;是连接局端 OLT 和用户 ONT 之间的光路通道&#xff0c;其质量直接影响整个PON系统的性能及可靠性。ODN光纤链路包括OLT PON口、ODF、主干光纤、一级分光器、分支光纤、二级分光…

登录功能和校验

基础版 controller package com.web.management.controller;import com.web.management.pojo.Emp; import com.web.management.pojo.Result; import com.web.management.service.EmpService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.anno…

如何用Vue3和Plotly.js绘制交互式漏斗图

本文由ScriptEcho平台提供技术支持 项目地址&#xff1a;传送门 Plotly.js 绘制漏斗图 应用场景 漏斗图常用于可视化业务流程中的各个阶段的转换率&#xff0c;例如销售漏斗或营销漏斗。它可以帮助用户识别流程中的瓶颈和改进机会。 基本功能 本代码使用 Plotly.js 库绘制…

【微机原理及接口技术】中断控制器8259A

【微机原理及接口技术】中断控制器8259A 文章目录 【微机原理及接口技术】中断控制器8259A前言一、介绍二、8259A的内部结构和引脚三、8259A的中断工作过程四、8259A的工作方式五、8259A的编程六、外部中断服务程序总结 前言 本篇文章将就8259芯片展开介绍&#xff0c;8259A的…

【多媒体】富客户端应用程序GUI框架 JavaFX 2.0 简介

JavaFX 最初是由 Oracle 推出的一个用于开发富客户端应用程序的框架&#xff0c;它提供了丰富的用户界面控件、布局容器、3D图形绘制、媒体播放和动画等功能&#xff0c;旨在取代较旧的 Swing 框架。JavaFX 于 2007 年推出&#xff0c;2011 年 10 月发布了2.0 版本。JavaFX 2.0…

OpenLayers使用

初学ol&#xff0c;实现了高德地图不同图层的切换、交互性地图飞行以及加载本地JSON数据。 说一下不同图层切换的想法&#xff1a; 1.对于标准地图和卫星地图&#xff1a;二者最初便挂载到map上&#xff0c;两个图层是叠加显示的&#xff1b;当点击按钮时&#xff0c;其实是使…

VSCode里python代码不扩展/级联了的解决办法

如图 解决办法&#xff1a;重新下载新的扩展工具 步骤如下 1、在左边工具栏打开Extensions 2、搜索框输入python&#xff0c;选择别的扩展工具&#xff0c;点击Install - 3在扩展工具所在的目录下&#xff0c;新建一个文件&#xff0c;就可以用了

指定IP地址通过远程桌面访问WINDOWS10

1:登录Windows10系统&#xff0c;在控制面板找到系统和安全&#xff0c;打开Windows Defender防火墙。 2&#xff1a;点击感觉设置。 3&#xff1a;在入站规则中&#xff0c;找到远程桌面。查看自己的网络现在是公用&#xff0c;域&#xff0c;还是专用。选择对应的网络。 4&am…

Oracle EBS PO采购订单预审批状态处理

系统版本 RDBMS : 12.1.0.2.0 Oracle Applications : 12.2.6 问题症状: 采购订单状态:预审批 采购订单流程报错如下: po.plsql.PO_DOCUMENT_ACTION_AUTH.approve:90:archive_po not successful - po.plsql.PO_DOCUMENT_ACTION_PVT.do_action:110:unexpected error in acti…

js生成器,迭代器和可迭代对象详解

1.生成器函数和生成器 生成器函数是可以返回一个可迭代对象的特殊函数&#xff0c; 生成器是一个特殊的迭代器&#xff0c; 在js中可以使用function*来定义一个非连续执行的函数作为迭代算法&#xff0c; function* name() {yield value;yield value;yield value; }name: 函…

基于YOLOv5的人脸目标检测

本文是在之前的基于yolov5的人脸关键点检测项目上扩展来的。因为人脸目标检测的效果将直接影响到人脸关键点检测的效果&#xff0c;因此本文主要讲解利用yolov5训练人脸目标检测(关键点检测可以看我人脸关键点检测文章) 基于yolov5的人脸关键点检测&#xff1a;人脸关键点检测…

ROS学习笔记(18):建图与定位(2)

0.前言 上文提到现在的我们已经进入到了SLAM领域的学习&#xff0c;会涉及到大量专业知识&#xff0c;作为一个自学的大三&#xff08;好吧也快大四了&#xff09;萌新并不能保证每次文章的专业性和准确性&#xff0c;所以&#xff0c;本人推荐大家能自己去查阅一些相关书籍和…

TOB传输、承载网拓扑图

1、用户面&#xff1a;GNODEB>UPE>SPE>NPE>UPF>CMNET网 2、控制面&#xff1a;GNODEB>UPE>SPE>NPE>IP承载网>核心网

充分利用智慧校园人事系统,提升党政职务管理

智慧校园人事系统中的党政职务管理功能&#xff0c;是专为高校及教育机构设计的&#xff0c;旨在高效、精确地处理与党政职务相关的各类事务&#xff0c;包括职务任命、任期管理、职责分配、考核评估等&#xff0c;以信息化手段促进党务及行政工作的透明化、规范化。 该模块首先…

redis主从复制哨兵模式集群管理

主从复制&#xff1a; 主从复制是高可用Redis的基础&#xff0c;哨兵和集群都是在主从复制基础上实现高可用的。主从复制主要实现了数据的多机备份&#xff0c;以及对于读操作的负载均衡和简单的故障恢复。缺陷&#xff1a;故障恢复无法自动化&#xff1b;写操作无法负载均衡&…

像学Excel 一样学 Pandas系列-创建数据分析维度

嗨&#xff0c;小伙伴们。又到喜闻乐见的Python 数据分析王牌库 Pandas 的学习时间。按照数据分析处理过程&#xff0c;这次轮到了新增维度的部分了。 老样子&#xff0c;我们先来回忆一下&#xff0c;一个完整数据分析的过程&#xff0c;包含哪些部分内容。 其中&#xff0c…

好久不见!写了一个自动截图神器~【附源码】

文章目录 前言新增功能介绍截图功能快捷键设置 程序设计和使用介绍操作菜单栏选择点击坐标点选择图片选择截图区域快捷键设置 表格循环次数状态栏 使用案例源代码 前言 好久没更新文章了。上一次更新是在4月16日差不多&#xff0c;也只是写了一个错误集&#xff0c;没什么太多…