gdb linux arm low.c,gdb在arm-linux上的移植

博主分享了如何从传统的printf调试方法转向使用GDB进行ARM-Linux程序调试的经验。在遇到复杂的、难以定位的错误时,如double free或内存 corruption问题,博主通过移植GDB5.2.1到开发板,并解决了编译过程中遇到的错误,最终成功实现了远程调试。调试步骤包括在x86上编译客户端GDB、在目标服务器端编译GDBserver,以及如何使用GDB进行调试。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

以前一直用打桩法来调试arm-linux程序,即通过添加printf()来调试。

这一方法在通常情况下是很有用,而且也是很简单实用的。但是对于一些

很特殊很隐蔽的错误,在这时这个方法可能就不太管用了,因为你总不能

在每条语句之后都加上printf()吧。而且对于多线程的大中型应用程序,

如果你不熟悉编译器,又或者你本身就是新手的话,程序的一个小bug就有

可能让你几天睡不好觉。就像今天我遇到的一个错误,同样的程序在两块

正常的板子上跑,其中有一块板子的程序中途出现错误

*** glibc detected *** : double free or corruption (!prev):

0x001fc688 ***

导致程序崩溃,系统只能重启。这种错误根本没办法用printf()来定位。

于是我想到了使用gdb来跟踪程序,这样才能快速定位。所以赶紧将gdb5.2.1

搬出来,移植到了开发板上。

下面简单介绍下我的移植过程及遇到的问题

-----------------------------------------------------------------

编译环境

编译器:arm-linux-gcc3.4.1

源码:gdb-5.2.1

-----------------------------------------------------------------

1.编译gdb过程(x86上客户端):

#cd /home/arm/gdb

#mkdir output

#mkdir libs

#tar zxvf gdb-5.2.1.tgz

#cd ./gdb

#./configure --host=i686-pc-linux-gnu --target=arm-linux --prefix=

/home/arm/gdb/output/ --nfp -v --norecursion

(--host也可以不写)

#./configure --target=arm-linux --prefix=/home/arm/gdb/output/ --nfp

-v --norecursion

#make

#make install

编译出现问题:

错误1:

gdbtypes.c: In function ‘recursive_dump_type’:

gdbtypes.c:3059: error: invalid lvalue in increment

解决方法:替换下面几个宏,打上补丁(参照下面资料)

gcc 3.4.x issues no errors nor even warnings on this code. Seems like gcc 4.x.x

is more pedantic. Replace obstack_ptr_grow() (and obstack_int_grow()) macro

definition in obstack.h with the same from newer version of gdb:

# define obstack_ptr_grow(OBSTACK,datum) \

__extension__ \

({ struct obstack *__o = (OBSTACK); \

if (__o->next_free + sizeof (void *) > __o->chunk_limit) \

_obstack_newchunk (__o, sizeof (void *)); \

obstack_ptr_grow_fast (__o, datum); })

# define obstack_int_grow(OBSTACK,datum) \

__extension__ \

({ struct obstack *__o = (OBSTACK); \

if (__o->next_free + sizeof (int) > __o->chunk_limit) \

_obstack_newchunk (__o, sizeof (int)); \

obstack_int_grow_fast (__o, datum); })

# define obstack_ptr_grow_fast(OBSTACK,aptr) \

__extension__ \

({ struct obstack *__o1 = (OBSTACK); \

*(const void **) __o1->next_free = (aptr); \

__o1->next_free += sizeof (const void *); \

(void) 0; })

# define obstack_int_grow_fast(OBSTACK,aint) \

__extension__ \

({ struct obstack *__o1 = (OBSTACK); \

*(int *) __o1->next_free = (aint); \

__o1->next_free += sizeof (int); \

(void) 0; })

错误2:

/gdb-5.2.1/gdb/arm-tdep.c:2692: error: label at end of compound statement

解决方法:该版本 arm-tdep.c 2692一行default语句少了个分号!加上即可通过.

------------------------------------------------------------------------------

2.编译gdbserver过程(target服务器端)

#cd gdb/gdbserver

#./configure --host=arm-linux --target=arm-linux --prefix=/home/arm/gdb/output/ --nfp -v

#make CC=/usr/local/arm/3.4.1/bin/arm-linux-gcc

#make install

出错信息:

linux-arm-low.c:26:21: sys/reg.h: No such file or directory

make: *** [linux-arm-low.o] Error 1

解决方法:

删除gdb/gdbserver/linux-arm-low.c 中 #include .

-------------------------------------------------------------------------------

3.应用

这个gdb跟linux上的用法基本一样,如果不熟悉可以翻开资料复习一下.

学而时习之,不亦说乎哦...

温故而知新,可以为师矣哈:-)

调试:

arm上跑gdbserver,主机linux上就可以用arm-linux-gdb调试了.

#gdbserver 192.168.100.103:1234 hello

Process hello created; pid = 1583

Listening on port 1234

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值