gdb-multiarch + gdbserver调试linux arm应用程序

首先安装gdb-multiarch

sudo apt-get install gdb-multiarch

把编译好的gdbserver发送到板子目录下
在这里插入图片描述
查看gdbsever版本

  gdbserver --version

新建程序test.c
test touch test.c

test.c内容

#include <stdio.h>

int main(int argc, char *argv[])
{
	printf("hello,world1!\n");
	printf("hello,world2!\n");
	return 0;
}

编译可执行程序test编译要加-g,在执行程序里面包含调试信息

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

开发板ip 192.168.1.2
ubuntu ip 192.168.1.3

先把ubuntu编译好test程序发给板子
比如调试名为test的可执行程序
板子运行gdbserver 监听,等待ubuntu远程gdb-multiarch 连接
[root@imx6ull:~]# gdbserver 192.168.1.3:1234 test #通信端口设置为1234,也可以设置成其他
Process /root/test created; pid = 374
Listening on port 1234

1、不带tui的gdb-multiarch调试

ubuntu gdb-multiarch 调试test
book@100ask:~/root_fs$ gdb-multiarch test
GNU gdb (Ubuntu 8.1-0ubuntu3.2) 8.1.0.20180409-git
Copyright © 2018 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 “x86_64-linux-gnu”.
Type “show configuration” for configuration details.
For bug reporting instructions, please see:
http://www.gnu.org/software/gdb/bugs/.
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”…
Reading symbols from test…done.
(gdb) target remote 192.168.1.2:1234 #端口是1234跟gdbserver 一致

这样就可以用gdb命令调试应用程序了。。。

2、下面是带tui的gdb-multiarch调试

-tui表示gdb工具以ui的方式展示。开起来舒服一点。
gdbserver 跟上面一样

[root@imx6ull:~]# gdbserver 192.168.1.3:1234 test #通信端口设置为1234,也可以设置成其他
Process /root/test created; pid = 374
Listening on port 1234

ubuntu gdb-multiarch 调试test
book@100ask:~/root_fs$ gdb-multiarch ui

(gdb)set architecture arm #选择gdb支持的arm架构

(gdb)symbol-file test #test 文件路径 这句话的作用是导入调试文件的符号表

(gdb)target remote 192.168.1.2:1234 #板子ip 92.168.1.2 通信端口1234

这样就可以用gdb命令调试应用程序了。。。

猜你喜欢

转载自blog.csdn.net/u014783785/article/details/107860638