gdb本地調(diào)試版本移植至ARM-Linux系統(tǒng)
本文使用的ncurses版本為ncurses-5.9.tar.gz
下載地址:https://ftp.gnu.org/gnu/ncurses/ncurses-5.9.tar.gz
1. 將ncurses壓縮包拷貝至Linux主機(jī)或使用wget命令下載并解壓
tar-zxvf ncurses-5.9.tar.gz
2. 解壓后進(jìn)入到ncurses-5.9目錄下
cdncurses-5.9
3. 在ncurses-5.9目錄下創(chuàng)建編譯完成后生成文件位置
mkdiroutput
cdoutput
mkdirarm-linux
4. 生成Makefile文件
./configure--target=arm-none-linux-gnueabi --prefix=$PWD/output/arm-linux --enable-termcap --with-shared --without-ada
l --target表示編譯器的前綴,需要根據(jù)編譯的不同需求進(jìn)行修改
l --prefix表示編譯完成后生成文件的位置
l --nable-termcap表示 關(guān)鍵代碼使用 termcap(terminalcapabilities)數(shù)據(jù)庫(kù) [自動(dòng)檢測(cè)]
l --with-shared表示動(dòng)態(tài)編譯
5. 編譯
make
當(dāng)遇到如下報(bào)錯(cuò)時(shí)
Makefile:794:recipe for target '../obj_s/lib_gen.o' failed
make[1]:*** [../obj_s/lib_gen.o] Error 1
make[1]:Leaving directory '.../ncurses-5.9/ncurses'
Makefile:109:recipe for target 'all' failed
make:*** [all] Error 2
需要進(jìn)入ncurses-5.9/include文件夾,修改 curses.tail 文件下的如下內(nèi)容,將注釋 /* generated */ 去掉
externNCURSES_EXPORT(bool) mouse_trafo(int*, int*, bool); /* generated*/
6. 安裝
Makeinstall
7. 安裝完成后會(huì)在/output/arm-linux目錄下生成庫(kù)文件,我們只需將lib目錄下的libncurses.so.5 庫(kù)拷貝至開發(fā)板
移植gdb
本文使用的gdb版本為gdb-7.12.tar.gz
下載地址:https://ftp.gnu.org/gnu/gdb/gdb-7.12.tar.gz
1. 將gdb壓縮包拷貝至Linux主機(jī)或使用wget命令下載并解壓
tar-zxvf gdb-7.12.tar.gz
2. 解壓后進(jìn)入到ncurses-5.9目錄下
cdgdb-7.12
3. 生成Makefile文件
./configure -host=arm-none-linux-gnueabi CC=/home/vanxoak/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi-gcc --enable-shared--prefix=$PWD/output/arm-linux --disable-werror --without-x --disable-gdbtk--disable-tui --without-included-regex --without-included-gettextLDFLAGS="-L$PWD/../output/arm-linux/lib"CPPFLASS="-I$PWD/../output/arm-linux/include"
l --host=arm-none-linux-gnueabi 用arm-none-linux-gnueabi編譯
l CC為交叉編譯器絕對(duì)路徑
l --enable-shared 動(dòng)態(tài)編譯
l prefix=“$PWD/output/arm-linux” 安裝目錄
l --disable-werror 屏蔽werror報(bào)警
l --without-x 取消x windows 支持
l --disable-gdbtk 取消gdbtk
l --disable-tui 取消tui 界面
l --without-included-gettext 去掉用于多語(yǔ)言處理的gettext庫(kù)
l "LDFLAGS=XXX"指交叉編譯完成的ncurse的lib目錄路徑
l "CPPFLAGS=XXX"指是交叉編譯完成的ncurse的include目錄路徑
4. 編譯
make
5. 安裝
makeinstall
安裝完成后會(huì)在.../gdb-7.12/output/arm-linux/bin/目錄下生成gdb可執(zhí)行程序。
移植至HDT3-EVM 開發(fā)板
1. 將libncurses.so.5庫(kù) 文件拷貝至/usr/lib目錄下,若/usr目錄下無lib目錄可手動(dòng)創(chuàng)建mkdir lib
2. 將gdb程序拷貝至/bin目錄下
測(cè)試調(diào)試
1. 編寫可執(zhí)行測(cè)試程序,示例hello.c代碼如下,該代碼執(zhí)行后會(huì)打印Hello World。
#include<stdio.h>
intmain(int argc, char *argv[])
{
printf("Hello World\n");
return 0;
}
2. 使用交叉編譯器進(jìn)行編譯,需要注意的是,要使用gdb調(diào)試程序,需要在使用交叉編譯器編譯源代碼時(shí)加上 " -g " 參數(shù)保留調(diào)試信息,否則不能使用GDB進(jìn)行調(diào)試且報(bào)如下最后一行所示錯(cuò)誤:
/home# gdb hello
GNUgdb (GDB) 7.12
Copyright(C) 2016 Free Software Foundation, Inc.
LicenseGPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
Thisis free software: you are free to change and redistribute it.
Thereis NO WARRANTY, to the extent permitted by law. Type "show copying"
and"show warranty" for details.
ThisGDB was configured as "arm-none-linux-gnueabi".
Type"show configuration" for configuration details.
Forbug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Findthe GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
Forhelp, type "help".
Type"apropos word" to search for commands related to "word"...
Readingsymbols from hello...(no debugging symbols found)...done.
3. 使用交叉編譯器編譯測(cè)試程序
arm-none-linux-gnueabi-gcc-g -o hello hello.c
4. 將生成的hello文件拷貝至HDT3-EVM 開發(fā)板上并使用sync命令保存
5. 輸入gbd命令啟動(dòng)gdb程序
/home# gdb
GNUgdb (GDB) 7.12
Copyright(C) 2016 Free Software Foundation, Inc.
LicenseGPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
Thisis free software: you are free to change and redistribute it.
Thereis NO WARRANTY, to the extent permitted by law. Type "show copying"
and"show warranty" for details.
ThisGDB was configured as "arm-none-linux-gnueabi".
Type"show configuration" for configuration details.
Forbug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Findthe GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
Forhelp, type "help".
Type"apropos word" to search for commands related to "word".
(gdb)
上述代碼(gdb)為GBD內(nèi)部命令引導(dǎo)符,表示等待用戶輸入gbd命令
6. 使用 " file hello " 命令載入被調(diào)試的測(cè)試程序
(gdb)file hello
Readingsymbols from hello...done.
顯示Reading symbols from hello...done.表示被測(cè)程序加載成功
7. 使用 " r "命令執(zhí)行調(diào)試測(cè)試程序
(gdb)r
Startingprogram: /home/hello
HelloWorld
[Inferior1 (process 849) exited normally]
如上述代碼顯示 " Hello World " 即表示hello程序執(zhí)行完成
(gdb)help
Listof classes of commands:
aliases-- Aliases of other commands
breakpoints-- Making program stop at certain points
data-- Examining data
files-- Specifying and examining files
internals-- Maintenance commands
obscure-- Obscure features
running-- Running the program
stack-- Examining the stack
status-- Status inquiries
support-- Support facilities
tracepoints-- Tracing of program execution without stopping the program
user-defined-- User-defined commands
Type"help" followed by a class name for a list of commands in that class.
Type"help all" for the list of all commands.
Type"help" followed by command name for full documentation.
Type"apropos word" to search for commands related to "word".
Commandname abbreviations are allowed if unambiguous.
*博客內(nèi)容為網(wǎng)友個(gè)人發(fā)布,僅代表博主個(gè)人觀點(diǎn),如有侵權(quán)請(qǐng)聯(lián)系工作人員刪除。