|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
PC主机:Ubuntu 10.4
' W [1 s5 O5 Y$ |6 K# m
* n9 z0 J6 P g, r' t目标板:TQ2440开发板,linux内核2.6.30
" c4 b- G& N; I( u+ b
& k' E9 ^! P* b9 R1 X3 lNOTE:为了使用gdb进行调试,强烈建议使用nfs服务,否则调试会非常麻烦。: X/ s! n% P: k7 Y1 p, |6 c
& s2 b- S8 [2 L5 J4 i( c: U) l使用nfs服务可以参考:S3C2440挂载NFS文件系统
4 s' }0 f e, q8 R: a; t0 G# l3 q. K$ y1 L4 m6 M2 W2 T/ z% b( Z
1. 概述9 w, _& ~6 x9 x5 v) m: e' @' |
所谓远程调试,就是开发板上建立一个gdb服务端,同时待调试的程序也位于开发板,然后在PC机上使用gdb发起远程连接来进行调试。也就是说,在PC端调试开发板上的程序。请注意,在PC端需要包含被调试程序的符号调试信息(symbolic debug information),因此强烈建议使用NFS,否则需要两份被调试的应用程序,一份供gdb使用,另一份供gdbserver使用。# ^9 h7 U$ j# Z& C" e# W9 g& C& q
( P. l* `7 v# Z; s
2. 安装GDB服务
- }# c: s1 A3 d, E& V下载gdb安装包,下载地址:http://ftp.gnu.org/gnu/gdb/
3 ] t1 _2 X8 H% ^( ~6 i' w( Y3 W0 j* y! B. Q7 P) X1 `) h" Y
这里使用的是7.4。
E7 g$ j, J3 ~: W1 z/ \7 z ^/ B" ?9 ?. y
解压安装包:
2 t# Z& J& A( f, I- g4 D3 v1 y* r% E9 R: w: C1 I' U- @1 X
yj423@ubuntu:~/work_yj423$ tar -xvf gdb-7.4/
0 `* h6 @3 h6 y/ G5 m7 S, l, _ X2 p& P! c- ~
yj423@ubuntu:~/work_yj423/gdb-7.4$ pwd! G( ?5 A2 g1 x5 m5 X
/home/yj423/work_yj423/gdb-7.4/ b- i$ _. w" K* c7 F, P
. g- S. k: N; f! Z# u在开始编译之前,你必须知道你的交叉编译器的名字。我的交叉编译器是ARM-unknown-linux-gnueabi-gcc,在下面将会用到该名字。
% J: a& a" y- o0 B3 e3 I9 q% v
% [0 @: C8 V3 G* B7 z' _1 X; Q3 R8 n$ d |4 Z' ~0 ?; @
9 X: u4 x+ H) V Y% U7 f0 G# Y
首先编译gdbserver,该程序运行在开发板上。0 M. `, o' D2 i- C& d1 B
+ M, @7 ^# L& o* n
执行下列命令:
4 `7 S5 c0 M8 |
7 i# ]: X/ t9 Y' Y1 Zyj423@ubuntu:~/work_yj423/gdb-7.4$ cd gdb/gdbserver/0 G# g2 S* I% ^5 k
yj423@ubuntu:~/work_yj423/gdb-7.4/gdb/gdbserver$ ./configure --host=arm-unknown-linux-gnueabi --target=arm-unknown-linux-gnueab3 B- ~, S# ]4 w8 A- S
yj423@ubuntu:~/work_yj423/gdb-7.4/gdb/gdbserver$ make. w2 x9 K0 S7 V3 r
% n& M4 Z# G% a5 l) g. c
在make以后,会在当前目录下生成可执行文件gdbserver。
/ }5 e% X0 G4 c
+ U- v/ c* E: Q; I: {$ V! A' }) L* d+ w4 N2 l
- G2 K/ D) f3 T% H接着编译gdb,该程序运行在PC机上。# O2 w4 \2 a9 q! O# D. _& i
% Q8 X7 H7 k- U' W4 i执行下列命令:: H* B: D( X$ K+ h" R" X/ f
, a7 v; P- |5 u5 [ T$ F6 \; n2 h
yj423@ubuntu:~/work_yj423/gdb-7.4/gdb/gdbserver$ cd ../../
) E/ m6 B* E0 }6 X; [+ syj423@ubuntu:~/work_yj423/gdb-7.4$ sudo ./configure --targe=arm-unknown-linux-gnueabi C! ~! |8 u5 L. c# K
yj423@ubuntu:~/work_yj423/gdb-7.4$ make* J0 M3 c; s5 B$ P* B+ O
# b* e/ N5 b' o9 J+ T请注意执行命令时所在的目录。执行完以后会在gdb-7.4/gdb/下生成可执行文件gdb。我将gdb改命为armgdb。
u; V6 J, a, S; V% N( a4 }3 d7 n2 C! n3 _0 [
3. 使用gdb调试
: z. S: B4 C4 D; h3 h& y测试程序为hello.c,程序如下:
# \+ ~0 s: R' r, L7 W" w/ J; L0 W
' |) A1 ~+ Y: J# I3 Z#include <stdio.h>' W# g8 }5 V5 r; r1 l5 j
- \5 W2 c: U4 F* l( Q$ Ivoid main()/ P2 U [3 |* f# o
{
7 q6 k, a: u# V printf("hello world\n");5 J3 v+ N2 R# d
printf("hello world\n");
0 B/ _; W6 {0 f H: g( S6 r% a}0 |9 C0 g' ^' M9 o. A. I4 c P
使用交叉编译器编译该文件,使用-g参数,生成hello。将gdbserver和hello复制到NFS的挂载点,我的挂载点为/home/yj423/nfswork。2 ~; ~& V. @. ^2 p$ E$ C( q
yj423@ubuntu:~/nfswork$ ls
* Z" O# v0 Y$ l7 A- @ M+ _bin dev gdbserver home linuxrc proc sbin tmp var9 c# G( d1 v2 P! t
boot etc hello lib mnt root sys usr welcome5 [5 @. y- Z- E; l) v% A3 I
4 l$ f3 Y' a& W" z可以看到gdbserver和hello。0 ^( I: J: Z+ p) h, c
$ ~. p3 a* `* h/ ^% Z1 y4 {
接着,在开发板上使用NFS:
% w' z& N7 K& h( p: }1 _% L[root@yj423 /]#mount -o nolock 192.168.1.103:/home/yj423/nfswork /mnt/nfs6 y) }% t" L4 z8 z
[root@yj423 /]#cd /mnt/nfs
% V. l* U* c/ k) ~7 c4 @[root@yj423 nfs]#ls
$ m3 s1 y& h7 Mbin dev gdbserver home linuxrc proc sbin tmp var* H: Q$ n1 y8 g; A8 ~9 Z ]0 ?* G
boot etc hello lib mnt root sys usr welcome2 h$ t8 Q ^4 j
! c. Y2 O2 s8 C: g1 D7 s' z/ C" q- S( p7 A
然后执行gdbserver:, N. M8 d5 X* I# Z& ?
( c2 l b( `/ h! o2 N
[root@yj423 nfs]#./gdbserver localhost:2001 hello
# X% T5 m$ |) k2 z9 hProcess hello created; pid = 948
; Z7 C2 e G9 ` R) {Listening on port 20016 R" `8 W, ~5 S. x4 L4 _
8 ~. k9 g& y9 c6 P. R+ u9 X3 q a8 j2001为端口号,hello表示要调试的程序。此时gdbserver等待PC机进行链接。
& Z8 [" r) k# C1 }* w
9 r3 i$ Y) Q5 r% k1 i/ M6 f" w$ L; Q! C8 s
7 r6 s, Y# D6 s. T0 L$ x在PC机上执行gdb:6 y. @! @- I P3 R8 H( _, `
' s2 K M/ Q) W# F! D. |
( B7 g- ]: l c9 E' A
yj423@ubuntu:~$ ./armgdb -q /home/yj423/nfswork/hello7 m+ b1 `5 E, M
Reading symbols from /home/yj423/nfswork/hello...done.
8 j+ j* E4 O, m( j7 [' O
* C9 h; d% X6 O; a3 j执行远程链接:4 l# b. V0 C& f3 z x( y: N
q z+ H4 P9 A
(gdb) target remote 192.168.1.6:2001, K- n7 T9 B0 q
Remote debugging using 192.168.1.6:2001
. }$ e% Z( W% P" w+ Xwarning: Unable to find dynamic linker breakpoint function.
1 P& J) `+ T, o2 F. dGDB will be unable to debug shared library initializers7 E8 _9 B7 t: T7 i# h
and track explicitly loaded dynamic code./ l0 ?6 i' |% D) K, y& I
0x400007b0 in ?? ()( }5 U+ o7 n( h' o* ~) V* d
(gdb)
- D. J7 O7 ~9 \- F9 g) ~8 e6 _( c: M
这里的192.168.1.6为开发板的IP地址。) W. G; Y$ b1 U
2 D, r( o* M8 z1 f Q2 p7 X
至此PC端的gdb和开发板的gdbserver已经建立连接,接下来可以调试。
! J1 ^# t& u! x4 x8 ~' d5 @9 ~4 e
(gdb) b main n1 b8 i" E; x+ _1 y7 U
Cannot access memory at address 0x0
2 w0 }5 L( {' n- @, W. C0 L2 iBreakpoint 1 at 0x83e0: file hello.c, line 5.( i' X1 Y: o/ i2 g( v W7 z
(gdb) c
% }0 ]! s9 h4 B3 Z+ Q3 [Continuing.
2 `6 j0 q4 b6 W* \* W8 pwarning: `/lib/libc.so.6': Shared library architecture unknown is not compatible with target architecture arm.
7 H, a' q, I6 F, N; s; X: rwarning: Could not load shared library symbols for /lib/ld-linux.so.3.
$ p' J. c! C3 f: ZDo you need "set solib-search-path" or "set sysroot"?
: E2 s( J5 O1 k2 Q/ a8 K% qBreakpoint 1, main () at hello.c:5
4 q3 z: l4 a8 W5 printf("hello world\n");" h9 B0 C+ q& Z* @, S; @' b
(gdb) n3 y2 I" Q9 H- s2 A( b/ s$ ^* L8 g
6 printf("hello world\n");
# [& x" H) k5 U3 q(gdb) n
t8 z6 x; T o& P6 x/ s7 }
# I9 f. M' s& Q7 c) m0 F$ j- ?. B0 j# Z1 \& i7 _0 T1 ^
这里只是简单的调试。后面还会有共享库调试和多进程调试,尽请期待!
: z$ N5 j+ D h4 e3 V& m1 P) w- _! X3 _: a$ Q
$ ^& b* P" Y& g3 w8 l
- E. V0 {% t2 t' _7 d2 M |
|