#linux# gdb交叉编译arm-linux-gnueabihf-gdb

#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 <http://gnu.org/licenses/gpl.html>
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
      $ <full path to your sources>/gdb-VERSION/configure [etc...]
      $ 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

源码经过编译生成可执行程序。根据执行编译操作的平台、可执行程序的运行平台、可执行的程序的处理平台,可以将编译操作分为多种类型,对应的三个配置参数如下:

  • --build:运行编译工具链的平台,也就是正在执行编译操作的平台。如果未指定此参数,则通过 config.guess 猜测得到。通常都不指定此参数。
  • --host:可执行程序将运行的平台。如果未指定此参数,则和 --build 相同。如果 --host 和 --build 不同,是交叉编译;否则是普通编译。
  • --target:可执行程序将处理的平台。如果未指定此参数,则和 --host 相同。一般来说,程序运行在什么平台,处理的就是什么平台,此参数值和 --host 参数相同,不需显式指定,所以通常不会关注到此参数。但在制作交叉编译工具 (如 gcc、gdb 等) 这种特殊情况下,此值和 --host 不同,例如交叉编译器 arm-linux-gcc,它运行在 x86-linux 平台 (--host 参数),但处理的是 arm-linux 平台 (--target 参数)。如果是交叉编译一个普通的应用,如运行于 arm-linux 平台的 tftp 程序,则它的运行平台和处理平台都是 arm-linux 平台
  • --program-prefix:指定将被加到所安装程序的名字上的前缀.例如,使用'--program-prefix=arm-linux-gnueabihf'来configure,编译的gdb文件名为arm-linux-gnueabihf-gdb
  • --prefix:编译的时候用来指定程序存放路径 。不指定prefix,可执行文件默认放在/usr /local/bin,库文件默认放在/usr/local/lib,配置文件默认放在/usr/local/etc。其它的资源文件放在/usr /local/share。

编译结果如下:

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 <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.


 

发布了170 篇原创文章 · 获赞 207 · 访问量 459万+

猜你喜欢

转载自blog.csdn.net/xiaoting451292510/article/details/105166739