小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

使用gdbserver遠(yuǎn)程調(diào)試

 xsx2008 2014-01-23

使用gdbserver遠(yuǎn)程調(diào)試
 
1.默認(rèn)crosstool交叉編譯器沒有自帶gdbserver,需要自行編譯
到GNU官方FTP下載,目前最新版的是gdb-6.7.1
下載地址:http://ftp./gnu/gdb/
注:若已有g(shù)dbserver,可以直接跳到步驟4
 
2.編譯gdbserver
編譯GDB源碼時(shí)只需要編譯出gdbserver就可以了,交叉編譯器自帶arm-linux-gdb(client端)可以使用。
gdb-6.7.1
# cd gdb-6.7.1/gdb/gdbserver/
#./configure --host=arm-linux --prefix=/work/install/gdbserver
#make
#make install
這時(shí)會(huì)在/work/install/gdbserver目錄下生成bin/gdbserver,將其拷貝到nfs文件系統(tǒng)
#cd /work/install/gdbserver
#cp bin/gdbserver /work/nfs/rootfs/bin
 
3.庫問題
這里需要注意的是運(yùn)行g(shù)dbserver還需要libthread_db庫,若你自己做的文件系統(tǒng)內(nèi)沒有這個(gè)庫的話需要從交叉編譯器內(nèi)拷一個(gè)過去。
# gdbserver -h (target)
gdbserver: error while loading shared libraries: libthread_db.so.1: cannot open shared object file: No such file or directory
# cp -avf lib/libthread_db* /work/nfs/rootfs_bluetooth_omap/lib/
`/lib/libthread_db-1.0.so' -> `/work/nfs/rootfs/lib/libthread_db-1.0.so'
`/lib/libthread_db.so.1' -> `/work/nfs/rootfs/lib/libthread_db.so.1'
注:若不知道缺少什么庫可以根據(jù)運(yùn)行時(shí)錯(cuò)誤提示拷貝或者用先用strace跟蹤一下:
#strace -f -F -o strace.log gdbserver -h
#vi strace.log 
發(fā)現(xiàn)如下字段:
872   writev(2, [{"gdbserver", 9}, {": ", 2}, {"error while loading shared libra"..., 36}, {": ", 2}, {"libthread_db.so.1", 17}, {": ", 2}, {"cannot open shared object file", 30}, {": ", 2}, {"No such file or directory", 25}, {"\n", 1}], 10) = 126
872   exit_group(127)                   = ?
得知缺少libthread_db.so.1庫(紅色部分標(biāo)出)。
 
4.調(diào)試過程
1)Target端建立遠(yuǎn)程調(diào)試服務(wù)
# gdbserver 192.168.167.170:1234 obexftp (target)
Process obexftp created; pid = 858
Listening on port 1234
 
2)Host端GDB加載要調(diào)試的程序
這里要調(diào)試的程序得是交叉編譯過的,并且加了-g參數(shù)。不過大部分編譯程序默認(rèn)就是加了-g參數(shù)的,這點(diǎn)可以從編譯時(shí)的log看出。
# arm-linux-gdb obexftp
GNU gdb 6.6.50.20070301 (MontaVista 6.6.50-2.0.1.0702865 2007-03-26)
Copyright (C) 2007 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=armv5tl-montavista-linux-gnueabi"...
 
3)連接到目標(biāo)板調(diào)試服務(wù)
(gdb) target remote 192.168.167.15:1234
Remote debugging using 192.168.167.15:1234
Error while reading shared library symbols:
Dwarf Error: Can't read DWARF data from '/opt/montavista/pro/devkit/arm/v5t_le/target/usr/lib/debug/lib/ld-2.5.90.so.debug'
0x400007a0 in _start () from /opt/montavista/pro/devkit/arm/v5t_le/target/lib/ld-linux.so.3
注:上面兩行錯(cuò)誤信息暫時(shí)不用管,原因還不清楚,但是暫時(shí)發(fā)現(xiàn)不影響使用。
連接成功后ARM板上的信息應(yīng)該是這樣的:
# ./gdbserver 192.168.0.29:1234 arm0702_8.out
Process arm0702_8.out created; pid = 228
Remote debugging from host 192.168.0.29  <----多出這一行
上面這行表示宿主機(jī)和開發(fā)板連接成功?,F(xiàn)在我們就可以在Host端像調(diào)試本地程序一樣調(diào)試ARM板上程序。不過,需要注意的是這里執(zhí)行程序要用“c”,不能用“r”。因?yàn)槌绦蛞呀?jīng)在Target Board上面由gdbserver啟動(dòng)了。

調(diào)試過程如下:
(gdb) b main
Breakpoint 1 at 0x9870: file obexftp.c, line 376.
(gdb) info b
Num Type           Disp Enb Address    What
1   breakpoint     keep y   0x00009870 in main at obexftp.c:376
(gdb) c
Continuing.
Error while mapping shared library sections:
/work/install/bluetooth//lib/libobexftp.so.0: No such file or directory.
Error while mapping shared library sections:
/work/install/bluetooth//lib/libc.so.6: No such file or directory.
Breakpoint 1, main (argc=1, argv=0xbed0dec4) at obexftp.c:384
384             if (strstr(argv[0], "ls") != NULL)      most_recent_cmd = 'l';
(gdb)
若產(chǎn)生這個(gè)錯(cuò)誤主要是由于該調(diào)試的應(yīng)用程序使用到了額外的庫,而這個(gè)庫在gdb默認(rèn)的搜索路徑內(nèi)沒有
(相對(duì)與遠(yuǎn)程調(diào)試,gdb默認(rèn)搜索的路徑即為交叉編譯器的庫路徑,下面我會(huì)介紹到)
因此,這里我們需要修改一下gdb默認(rèn)的共享庫搜索路徑。
修改的辦法是設(shè)置GDB的環(huán)境變量:
(gdb) show solib-absolute-prefix
The current system root is "/opt/montavista/pro/devkit/arm/v5t_le/target".
上面這個(gè)路徑即GDB默認(rèn)的絕對(duì)搜索路徑,即交叉編譯器庫路徑
(gdb) show solib-search-path
The search path for loading non-absolute shared library symbol files is .
(gdb) set solib-search-path /work/install/bluetooth/lib
這個(gè)路徑為若在solib-absolute-prefix指定的路徑內(nèi)沒有搜索到庫,則再繼續(xù)嘗試從該路徑進(jìn)行搜索。
這點(diǎn)倒有點(diǎn)類似于系統(tǒng)默認(rèn)庫搜索路徑與LD_LIBRARY_PATH的關(guān)系。
詳細(xì)參考GDB手冊(cè)中相關(guān)部分:
http://wiki./index.php/GDB_Manual_15_1

設(shè)置好solib-search-path后再運(yùn)行程序:
(gdb) set solib-search-path /work/install/bluetooth/lib/
(gdb) c
Continuing.
Error while reading shared library symbols:
Dwarf Error: Can't read DWARF data from '/opt/montavista/pro/devkit/arm/v5t_le/target/usr/lib/debug/lib/ld-2.5.90.so.debug'
Breakpoint 1, main (argc=1, argv=0xbe896eb4) at obexftp.c:384
384             if (strstr(argv[0], "ls") != NULL)      most_recent_cmd = 'l';
(gdb) l
379             char *output_file = NULL;
380             char *move_src = NULL;
381             /* char *inbox; */
382
383             /* preset mode of operation depending on our name */
384             if (strstr(argv[0], "ls") != NULL)      most_recent_cmd = 'l';
385             if (strstr(argv[0], "get") != NULL)     most_recent_cmd = 'g';
386             if (strstr(argv[0], "put") != NULL)     most_recent_cmd = 'p';
387             if (strstr(argv[0], "rm") != NULL)      most_recent_cmd = 'k';
388
(gdb)
運(yùn)行成功
 
 
注:使用GDB調(diào)試時(shí)查看代碼不是很方便。CLWEN使用VIM作為GDB前端界面,結(jié)合gdb的遠(yuǎn)程調(diào)試功能,動(dòng)態(tài)的將程序當(dāng)前運(yùn)行的代碼顯示在VIM上,查看起來十分方便。其遠(yuǎn)程調(diào)試方法和GDB+GDB Server一樣,但是多了一個(gè)GUI界面(VIM)。
參考:《使用CLEWN遠(yuǎn)程調(diào)試》

 
分類: 編譯器

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多