ubuntu下aarch64-linux-gnu(交叉编译) gdb/gdbserver(一)

ubuntu下aarch64-linux-gnu(交叉编译) gdb/gdbserver

gdb是一款开源的、强大的、跨平台的程序调试工具。主要用于在程序运行时对程序进行控制和检查,如设置断点、单步执行、查看变量值、修改内存数据等,从而帮助开发者定位和修复代码中的错误。

gdbserver则是GDB的一个辅助工具,主要用于调试嵌入式系统或者没有图形界面的目标系统上的程序。GDBServer在目标设备上运行,将目标程序的状态信息通过网络发送给宿主机上的GDB,使GDB能够像调试本地程序一样调试远程的目标程序。这样,开发人员就可以在宿主机上使用GDB的各种功能,而不需要在目标设备上安装和运行复杂的调试环境。

说明:本教程适用于ubuntu环境下交叉编译gdbserver,目标架构为aarch64小端。

一、准备阶段

根据需求,准备gdb源代码和aarch64-linux-gnu交叉编译工具链。

博主选择的gdb源代码以及aarch64-linux-gnu交叉编译工具链分别是,gdb8.3gcc-arm-8.3-2019.02-x86_64-aarch64-linux-gnu.tar.xz(aarch64小端)

gdb源代码地址: gdb源代码下载地址

在这里插入图片描述

gnu交叉编译工具链地址:交叉编译工具链下载地址

在这里插入图片描述

注意:在选择交叉编译工具链时,一定要明确目标架构大小端。

二、编译安装gdb
首先通过configure配置gdb编译选项,再进行编译和安装。

(一)、配置gdb编译选项

cd gdb8.3
./configure --target=aarch64-linux-gnu --prefix=/home/hhl/gdbserver
参数说明:
	--target 目标架构
	--prefix 自定义gdb编译安装路径

在这里插入图片描述

(二)、编译gdb

cd gdb8.3
make -j8
参数说明:
	--j8 并行编译(8

在这里插入图片描述

(三)、安装gdb

cd gdb8.3
make install

在这里插入图片描述
在这里插入图片描述

三、交叉编译gdbserver
(一)、配置gdbserver编译选项

由于gdbserver需要移植到目标环境中运行,为了避免环境的影响,因此采取静态编译的方式。

cd gdb8.3/gdb/gdbserver
LDFLAGS="-static" ./configure --target=aarch64-linux-gnu --host=aarch64-linux-gnu  --disable-shared --enable-static 
参数说明:
	LDFLAGS="-static"  静态编译
	--target 目标架构
	--prefix 自定义gdb编译安装路径
	--disable-shared --enable-static 可选参数,静态编译。

(二)、交叉编译gdbserver

使用绝对路径正确配置gcc和g++的路径。

make CC=/home/hhl/gcc-arm-8.3-2019.02-x86_64-aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc CXX=/home/hhl/gcc-arm-8.3-2019.02-x86_64-aarch64-linux-gnu/bin/aarch64-linux-gnu-g++ -j8
参数说明:
	CC gcc路径
	cXX g++路径

在这里插入图片描述

交叉编译成功后,gdbservergdb8.3/gdb/gdbserver路径下

关于gdb远程调试,请参考博文二

install -d -m0755 /home/felix/mydisk/enterprise_gateway/bin/cn913x-cn25g-vpp_v1/packages ipkg-build -c -o 0 -g 0 /home/felix/mydisk/enterprise_gateway/build_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/gdb-8.1/ipkg-cn913x/gdb /home/felix/mydisk/enterprise_gateway/bin/cn913x-cn25g-vpp_v1/packages Packaged contents of /home/felix/mydisk/enterprise_gateway/build_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/gdb-8.1/ipkg-cn913x/gdb into /home/felix/mydisk/enterprise_gateway/bin/cn913x-cn25g-vpp_v1/packages/gdb_8.1-1_cn913x.ipk rm -rf /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/root-cn913x/tmp-gdb mkdir -p /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/root-cn913x/stamp /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/root-cn913x/tmp-gdb install -d -m0755 /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/root-cn913x/tmp-gdb/usr/bin /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/root-cn913x/tmp-gdb/usr/sbin/ install -m0755 /home/felix/mydisk/enterprise_gateway/build_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/gdb-8.1/ipkg-install/usr/bin/gdb /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/root-cn913x/tmp-gdb/usr/bin/ install -m0755 ./files/usr/sbin/pstack /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/root-cn913x/tmp-gdb/usr/sbin/ SHELL= /home/felix/mydisk/enterprise_gateway/staging_dir/host/bin/flock /home/felix/mydisk/enterprise_gateway/tmp/.root-copy.flock -c 'cp -fpR /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/root-cn913x/tmp-gdb/. /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/root-cn913x/' rm -rf /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/root-cn913x/tmp-gdb touch /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/root-cn913x/stamp/.gdb_installed if [ -f /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/pkginfo/gdb.default.install.clean ]; then rm -f /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/pkginfo/gdb.default.install /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/pkginfo/gdb.default.install.clean; fi; echo "gdb" >> /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/pkginfo/gdb.default.install WARNING: skipping gdbserver -- package not selected make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/package/devel/gdb' make[2]: Leaving directory '/home/felix/mydisk/enterprise_gateway' package/Makefile:190: recipe for target '/home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/stamp/.package_compile' failed make[1]: *** [/home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/stamp/.package_compile] Error 2 make[1]: Leaving directory '/home/felix/mydisk/enterprise_gateway' /home/felix/mydisk/enterprise_gateway/include/toplevel.mk:171: recipe for target 'world' failed make: *** [world] Error 2
最新发布
07-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

进击的铁甲小宝

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

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

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

打赏作者

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

抵扣说明:

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

余额充值