0) gdb源碼下載:http://ftp.gnu.org/gnu/gdb/
1) 編譯arm-linux-gdb
指定交叉編譯工具鏈的位置
export PATH=$PATH:/usr/local/arm/3.4.1/bin
開始配置和編譯
$cd gdb-6.6
$./configure --target=arm-linux --prefix=/usr/local/arm/gdb -v
$make
中間會出現一些地方編譯過去,如
gdb declared with attribute warn_unused_result
檢查了下,發現是由於檢查太嚴格了,把 Makefile 里面 -Wall 類似的強制警告檢查都去掉就可以過了
2) 編譯gdbserver
$cd gdb/gdbserver
$./configure --target=arm-linux --host=arm-linux
target含義同前,host指明編譯生成的gdbserver運行在arm-linux上,前者沒有設定host的原因是
arm-linux-gdb是在pc linux上運行的,就像arm-linux-gcc (很好理解的:))
$make CC=/usr/local/arm/3.4.1/bin/arm-linux-gcc
#gdbserver 192.168.1.200:7777 test
Process test created; pid
Listening on port 7777
主機shell下
$cd ~/tftpboot
$arm-linux-gdb test
GNU gdb 6.6
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "--host=i686-pc-linux-gnu --target=arm-linux"...
(gdb)
注意一下顯示信息的最后--host=i686-pc-linux-gnu --target=arm-linux,明白了吧。。。
target remote 192.168.1.168:7777 --連接gdbserver
Remote debugging using 192.168.1.168:7777
0x40000dd0 in _start () from /lib/ld-linux.so.2
表示連接上了服務器,:),接下來就可以調試了。arm-linux-gdb和GDB的用法一樣,只是沒有r這個命
令,運行程序用c命令。
(gdb) l
1 #include<stdio.h>
2
3 int main()
4 {
5 char *ptr = "csdn";
6 printf("%c/n",*(ptr++));
7 return 0;
8 }
(gdb) b 3
Breakpoint 1 at 0x83d0: file test.c, line 3.
另外由於程序是在目標板上運行,調試是在PC下,程序的結果還是會在目標板上顯示的,
例如:minicom,lcd等。
btw,附近一篇介紹GDB使用的文章:http://blog.csdn.net/haoel/archive/2003/07.aspx,這下全了吧。哈