gdb本地调试版本移植至ARM-Linux系统
2023年12月12日 15:21 发布者:武汉万象奥科
https://18821080.s21i.faiusr.com/2/ABUIABACGAAgkPnfqwYoi9XfYDD4BTjoAQ.jpg移植ncurses库本文使用的ncurses版本为ncurses-5.9.tar.gz下载地址:https://ftp.gnu.org/gnu/ncurses/ncurses-5.9.tar.gz1. 将ncurses压缩包拷贝至Linux主机或使用wget命令下载并解压
tar-zxvf ncurses-5.9.tar.gz
2. 解压后进入到ncurses-5.9目录下
cdncurses-5.9
3. 在ncurses-5.9目录下创建编译完成后生成文件位置mkdiroutputcdoutputmkdirarm-linux
4. 生成Makefile文件./configure--target=arm-none-linux-gnueabi --prefix=$PWD/output/arm-linux --enable-termcap --with-shared --without-adal --target表示编译器的前缀,需要根据编译的不同需求进行修改l --prefix表示编译完成后生成文件的位置l --nable-termcap表示 关键代码使用 termcap(terminalcapabilities)数据库 [自动检测]l --with-shared表示动态编译
5. 编译make当遇到如下报错时Makefile:794:recipe for target '../obj_s/lib_gen.o' failedmake:*** [../obj_s/lib_gen.o] Error 1make:Leaving directory '.../ncurses-5.9/ncurses'Makefile:109:recipe for target 'all' failedmake:*** Error 2
需要进入ncurses-5.9/include文件夹,修改 curses.tail 文件下的如下内容,将注释 /* generated */ 去掉externNCURSES_EXPORT(bool) mouse_trafo(int*, int*, bool); /* generated*/
6. 安装Makeinstall
7. 安装完成后会在/output/arm-linux目录下生成库文件,我们只需将lib目录下的libncurses.so.5 库拷贝至开发板
移植gdb本文使用的gdb版本为gdb-7.12.tar.gz下载地址:https://ftp.gnu.org/gnu/gdb/gdb-7.12.tar.gz
1. 将gdb压缩包拷贝至Linux主机或使用wget命令下载并解压
tar-zxvf gdb-7.12.tar.gz
2. 解压后进入到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为交叉编译器绝对路径l --enable-shared 动态编译l prefix=“$PWD/output/arm-linux” 安装目录l --disable-werror 屏蔽werror报警l --without-x 取消x windows 支持l --disable-gdbtk 取消gdbtkl --disable-tui 取消tui 界面l --without-included-gettext 去掉用于多语言处理的gettext库l "LDFLAGS=XXX"指交叉编译完成的ncurse的lib目录路径l "CPPFLAGS=XXX"指是交叉编译完成的ncurse的include目录路径
4. 编译make
5. 安装makeinstall
安装完成后会在.../gdb-7.12/output/arm-linux/bin/目录下生成gdb可执行程序。
移植至HDT3-EVM 开发板1. 将libncurses.so.5库 文件拷贝至/usr/lib目录下,若/usr目录下无lib目录可手动创建mkdir lib2. 将gdb程序拷贝至/bin目录下https://18821080.s21i.faiusr.com/2/ABUIABACGAAgq4S0qQYouOni4AQwnRc4iQ0.jpg
测试调试1. 编写可执行测试程序,示例hello.c代码如下,该代码执行后会打印Hello World。#include
3. 使用交叉编译器编译测试程序arm-none-linux-gnueabi-gcc-g -o hello hello.c
4. 将生成的hello文件拷贝至HDT3-EVM 开发板上并使用sync命令保存
5. 输入gbd命令启动gdb程序/home# gdbGNUgdb (GDB) 7.12Copyright(C) 2016 Free Software Foundation, Inc.LicenseGPLv3+: GNU GPL version 3 or later
上述代码(gdb)为GBD内部命令引导符,表示等待用户输入gbd命令
6. 使用 " file hello " 命令载入被调试的测试程序(gdb)file helloReadingsymbols from hello...done.
显示Reading symbols from hello...done.表示被测程序加载成功
7. 使用 " r "命令执行调试测试程序(gdb)rStartingprogram: /home/helloHelloWorld如上述代码显示 " Hello World " 即表示hello程序执行完成
(gdb)helpListof classes of commands:
aliases-- Aliases of other commandsbreakpoints-- Making program stop at certain pointsdata-- Examining datafiles-- Specifying and examining filesinternals-- Maintenance commandsobscure-- Obscure featuresrunning-- Running the programstack-- Examining the stackstatus-- Status inquiriessupport-- Support facilitiestracepoints-- Tracing of program execution without stopping the programuser-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.