#windows# gdb交叉编译arm-linux-gnueabihf-gdb
https://blog.csdn.net/xiaoting451292510/article/details/105228162
GDB(GNU symbolic debugger)简单地说就是一个调试工具。它是一个受通用公共许可证即GPL保护的自由软件。
像所有的调试器一样,GDB可以让你调试一个程序,包括让程序在你希望的地方停下,此时你可以查看变量、寄存器、内存及堆栈。更进一步你可以修改变量及内存值。GDB是一个功能很强大的调试器,它可以调试多种语言。在此我们仅涉及 C 和 C++ 的调试,而不包括其它语言。还有一点要说明的是,GDB是一个调试器,而不像 VC 是一个集成环境。你可以使用一些前端工具如XXGDB、DDD等。他们都有图形化界面,因此使用更方便,但它们仅是GDB的一层外壳。因此,你仍应熟悉GDB命令。事实上,当你使用这些图形化界面时间较长时,你才会发现熟悉GDB命令的重要性。
嵌入式Linux的GDB调试环境由Host端(PC机)和Target端(ARM)两部分组成,Host端使用arm-linux-gdb调试工具,而Target端需要运行gdbserver,两者之间可通过串口或者网口连接,把ARM应用程序在Target端的执行情况返回Host。调试跟踪命令从Host端的arm-linux-gdb中发出。因此,你需要GDB交叉调试。
你可以从http://ftp.gnu.org/gnu/gdb/网址下载对应版本GDB。目前最新版本gdb-9.1.tar.xz,建议如果在PC上运行arm-linux-gnueabihf的话,安装成PC端gdb同一个版本比较好。查看GDB版本gdb -v,如下,我的PC端为GNU gdb (Ubuntu 8.2-0ubuntu1~16.04.1) 8.2
$ gdb -v
GNU gdb (Ubuntu 8.2-0ubuntu1~16.04.1) 8.2
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
编译gdb过程中需要使用texinfo, 先安装texinfo
sudo apt-get install texinfo
解压配置编译
arm-linux-gnueabihf端:--host=arm-linux-gnueabihf
pc端:--host不用配置,默认即可
./configure --target=arm-linux-gnueabihf --host=arm-linux-gnueabihf --program-prefix=arm-linux-gnueabihf- CC=arm-linux-gnueabihf-gcc --prefix=/opt/arm-linux-gnueabihf-gdb-8.2
新版本的gdb会提示如下信息。即配置编译不能与源码一个目录操作,按要求创建build在build目录里再次配置编译
configure: error: GDB must be configured and built in a directory separate from its sources.
To do so, create a dedicated directory for your GDB build and invoke
the configure script from that directory:
$ mkdir build
$ cd build
$
$ make
再使用source命令配置编译
source /home/cll/99_temp/1/gdb-9.1/configure --target=arm-linux-gnueabihf --host=arm-linux-gnueabihf --program-prefix=arm-linux-gnueabihf- CC=arm-linux-gnueabihf-gcc --prefix=/opt/arm-linux-gnueabihf-gdb
编译,make install 根据设置的目录,如有权限问题,请使用sudo make install
make -j4
make install
源码经过编译生成可执行程序。根据执行编译操作的平台、可执行程序的运行平台、可执行的程序的处理平台,可以将编译操作分为多种类型,对应的三个配置参数如下:
编译结果如下:
arm-linux-gnueabihf端:将文件拷贝到arm-linux-gnueabihf端运行
PC端:在~/.bashrc文件中配置bin路径及lib路径
export PATH=$PATH:/opt/arm-linux-gnueabihf-gdb-8.2/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/arm-linux-gnueabihf-gdb-8.2/lib
确认lib及bin路径添加正确
查看arm-linux-gnueabih-gdb 版本信息
$ arm-linux-gnueabih-gdb -v
GNU gdb (GDB) 8.2
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.