我根據(jù)arm-linux-gdb的調(diào)試對象,把調(diào)試分為二大類。即底層代碼的調(diào)試,如u-boot、裸機程序等;或者應(yīng)用程序的調(diào)試,即elf格式的可執(zhí)行文件。根據(jù)我的經(jīng)驗,應(yīng)用程序的調(diào)試相對要容易很多。下面,詳細(xì)闡述調(diào)試經(jīng)歷……
應(yīng)用篇:用arm-linux-gdb調(diào)試應(yīng)用程序 開發(fā)機,即我電腦虛擬機中的ubuntu;目標(biāo)機,即跑有l(wèi)inux系統(tǒng)的arm開發(fā)板。開發(fā)機和目標(biāo)機通過網(wǎng)線連接在一個局域網(wǎng)內(nèi),一個網(wǎng)段,確保相互要ping得通。 在開發(fā)機中,通過minicom、ssh或者telnet登錄開發(fā)板,要能看到開發(fā)板的文件系統(tǒng)。步驟如下:(ubuntu的IP是192.168.16.200, arm板的IP是192.168.16.40,兩者均使用2015端口通信) 【1 打開終端,遠(yuǎn)程登錄開發(fā)板】 wuxian@ubuntu:~$ ssh root@192.168.16.40 root@192.168.16.40's password: 123 #
【2 另啟終端,編譯elf可執(zhí)行文件】 wuxian@ubuntu:~$ touch hello.c 1 #include<stdio.h> 2 3 intmain(int argc, char *argv[]) 4 { 5 for(inti=0; i<100; i++) 6 { 7 printf("hello,world!\n"); 8 } 9 return0; 11 } wuxian@ubuntu:~$ arm-linux-gcc -g hello.c -o hello --std=c99
【3 拷貝文件到目標(biāo)開發(fā)板】 wuxian@ubuntu:~$ scp ./hello root@192.168.16.40:/root root@192.168.16.40's password: hello 100%6200 6.1KB/s 00:00
【4 上目標(biāo)機查看拷貝情況】 # ls hello # pwd /root #
【5 在目標(biāo)機上打開gdbserver】準(zhǔn)備為客戶端arm-linux-gdb服務(wù) # gdbserver 192.168.16.200:2015 hello //192.168.16.200是開發(fā)機的ip,2015是監(jiān)聽端口, Process hello created; pid = 27991 //提示信息 Listening on port 2015
【6 在開發(fā)機上打開arm-linux-gdb】準(zhǔn)備調(diào)試 wuxian@ubuntu:/opt/arm/4.3.2/bin$ ./arm-linux-gdb ~/hello GNU gdb (Sourcery G++ Lite 2008q3-72)6.8.50.20080821-cvs Copyright (C) 2008 Free SoftwareFoundation, Inc. License GPLv3+: GNU GPL version 3 orlater <http:///licenses/gpl.html> This is free software: you are free tochange and redistribute it. There is NO WARRANTY, to the extentpermitted by law. Type "showcopying" and "show warranty" fordetails. This GDB was configured as "--host=i686-pc-linux-gnu--target=arm-none-linux-gnueabi". For bug reporting instructions, pleasesee: <https://support./GNUToolchain/>... (gdb) target remote 192.168.16.40:2015 Remote debugging using192.168.16.40:2015 warning: Unable to find dynamic linkerbreakpoint function. GDB will be unable to debug sharedlibrary initializers and track explicitly loaded dynamiccode. 0x400cc8c0 in ?? () (gdb) l 1 1 #include<stdio.h> 2 3 intmain(int argc, char *argv[]) 4 { 5 for(inti=0; i<100; i++) 6 { 7 printf("hello,world!\n"); 8 } 9 10 return0; (gdb) 11 } (gdb) b main Breakpoint 1 at 0x8480: file hello.c,line 5. (gdb) c Continuing. Error while mapping shared librarysections: /lib/libc.so.0: No such file ordirectory. Error while mapping shared librarysections: /lib/ld-uClibc.so.0: No such file ordirectory.
Breakpoint 1, main (argc=1,argv=0xbe9bad74) at hello.c:5 5 for(inti=0; i<100; i++) (gdb) n 7 printf("hello,world!\n"); (gdb) n 5 for(inti=0; i<100; i++) (gdb)
【7 再看看目標(biāo)機上的反應(yīng)】 # gdbserver 192.168.16.200:2015 hello Process hello created; pid = 27991 Listening on port 2015 Remote debugging from host 192.168.16.200 hello,world!
|
|