Linux系统调试篇——GDBSERVER远程调试

本篇讲解如何使用gdbserver对目标开发板上的程序进行远程调试。

安装 GDBSERVER


首先在开发板上安装 gdbserver:

apt install gdbserver

gdbserver 用法


gdbserver用法描述:

Usage:  gdbserver [OPTIONS] COMM PROG [ARGS ...]
        gdbserver [OPTIONS] --attach COMM PID
        gdbserver [OPTIONS] --multi COMM

COMM may either be a tty device (for serial debugging),
HOST:PORT to listen for a TCP connection, or '-' or 'stdio' to use
stdin/stdout of gdbserver.
PROG is the executable program.  ARGS are arguments passed to inferior.
PID is the process ID to attach to, when --attach is specified.

Operating modes:

  --attach              Attach to running process PID.
  --multi               Start server without a specific program, and
                        only quit when explicitly commanded.
  --once                Exit after the first connection has closed.
  --help                Print this message and then exit.
  --version             Display version information and exit.

使用gdbserver很简单,主要就是先在开发板上开启gdbserver,然后宿主机运行gdb远程连接到gdbserver

具体步骤


一:在目标开发板上启动 gdbserver 服务

要进行gdb调试,首先要在目标开发板上启动gdbserver服务。在gdbserver所在目录下输入命令:

gdbserver :12345 helloworld

此时gdbserver监听端口号12345,并等待客户端连接。这里的端口号是自己指定的,helloworld是你要调试的程序

二:在宿主机上运行 GDB:

宿主机通常就是在你的Linux虚拟机上,然后找到开发板对应工具链下的gdb,然后运行:

riscv64-linux-gnu-gdb helloworld

(gdb) target remote 192.168.1.4:12345

192.168.1.4是开发板的ip地址,12345是开发板启动gdbserver服务时指定的端口号。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

嵌入式Linux充电站

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值