MSYS2下gdb-8.2编译安装

1,编译环境:

1)操作系统环境:

系统版本:Windows 10 专业版

系统类型:64位操作系统,基于x64的处理器

2)MSYS2环境:

mintty 2.9.4 (x86_64-pc-msys)

gcc (GCC) 7.3.0

GNU Make 4.2.1

2,gdb源代码:

可以去gun上下载,http://www.gnu.org/prep/ftp.html里面列出了下载的镜像站点,我们可以找一个国内的下载,比如https://mirrors.ustc.edu.cn/gnu/,gdb就在https://mirrors.ustc.edu.cn/gnu/gdb/,从列表里可以找到,我下载了目前最新版gdb-8.2.tar.gz这个版本。

然后把gdb-8.2.tar.gz拷贝到home\src下,这里的home目录是在MSYS2的安装目录下,以下所说的home都是这样的

3,编译arm-linux-gdb:(我的目的是编译调试Android下的,所以--target=arm-linux)

$ cd /home/src

$ tar zxf gdb-8.2.tar.gz

$ cd gdb-8.2/

$ mkdir build

$ cd build/

$ ../configure --prefix=/home/tools/gdb --target=arm-linux

$ make -j4

可能遇到如下错误:

/home/src/gdb-8.2/missing:行81: makeinfo: 未找到命令

WARNING: 'makeinfo' is missing on your system.

You should only need it if you modified a '.texi' file, or

any other file indirectly affecting the aspect of the manual.

You might want to install the Texinfo package:

<http://www.gnu.org/software/texinfo/>

The spurious makeinfo call might also be the consequence of

using a buggy 'make' (AIX, DU, IRIX), in which case you might

want to install GNU make:

<http://www.gnu.org/software/make/>

需要在MSYS2终端执行如下安装命令:

pacman -S texinfo

然后继续编译安装

$ make -j4

$ make install -j4

根据--prefix=/home/tools/gdb的配置,最后会安装到/home/tools/gdb下面,要想方便的执行arm-linux-gdb,最好是把/home/tools/gdb/bin加到PATH中。

修改PATH方法:打开/etc/profile文件,找到export PATH的这行,在前面增加PATH="$PATH:/home/tools/gdb/bin",然后重启一下MSYS2就可以了。

其实,对于MSYS2下使用的话,一般都是个人电脑,所以--prefix可以不用配置,直接默认安装到/usr/bin下即可直接使用。

4,使用中遇到的问题

在通过gdb远程调试时,客户端输入bt等命令是会提示以下错误

Remote 'g' packet reply is too long (expected 168 bytes, got 328 bytes): fcffffff28d56ebe10000000ffffffff0000000008000000000000005a010000000000002c497ba800000000e0487ba8e8d46ebed8d46ebee905c0a554e4c2a510000f600000000000000000000000000000000000000000000000000000000000000000e8b66b1301000000caac82ad0cc56ebed0f520714551f1a430127ba800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a86b1360ebb97060ebb97060ebb970ffffffffffffffffffffffffffffffffe1ffffffe1ffffffe1ffffffe1ffffff0000008000000080000000800000008000040000002400000044000000640000ffffffff00000000ffffffff000000005f933f0000000000000000000000000093000060

需要修改gdb/remote.c文件的第8038行,修改

/////////start////////

/////////end////////

之间的代码

  /* Further sanity checks, with knowledge of the architecture.  */
  if (buf_len > 2 * rsa->sizeof_g_packet)
/////////start////////
//    error (_("Remote 'g' packet reply is too long (expected %ld bytes, got %d "
//	     "bytes): %s"), rsa->sizeof_g_packet, buf_len / 2, rs->buf);
  {
    rsa->sizeof_g_packet = buf_len;
    for (i = 0; i < gdbarch_num_regs (gdbarch); i++)
    {
      if (rsa->regs[i].pnum == -1)
        continue;
      if (rsa->regs[i].offset >= rsa->sizeof_g_packet)
        rsa->regs[i].in_g_packet = 0;
      else
        rsa->regs[i].in_g_packet = 1;
    }
  }
/////////end////////
  /* Save the size of the packet sent to us by the target.  It is used
     as a heuristic when determining the max size of packets that the
     target can safely receive.  */

这样修改并重新编译之后就可以正常使用了。

5,参考文章

https://blog.csdn.net/u013592097/article/details/70549657

猜你喜欢

转载自blog.csdn.net/hanq4998/article/details/84779097