• 编译gdb和gdbserver


    0、参考文章:

    https://www.cnblogs.com/Dennis-mi/articles/5018745.html
    https://blog.csdn.net/zhaoxd200808501/article/details/77838933

    1、源码下载:http://ftp.gnu.org/gnu/gdb/

    2、解压

    tar.xz:tar xvJf ./gdb-7.8.tar.xz
    tar.gz:tar -zxvf ./gdb-7.8.tar.gz

    3、生成Makefile

    ./configure --host=arm-mol-linux-uclibcgnueabihf --target=arm-mol-linux-uclibcgnueabihf --program-prefix=arm-mol-linux-uclibcgnueabihf- --prefix=$PWD/__install
    –host:表示主机使用的编译工具链,一般是arm-linux,也可以是芯片平台的编译工具链。
    –target:表示芯片平台的编译工具链,如arm-mol-linux-uclibcgnueabihf
    –program-prefix:表示目标生成的前缀名字。
    –prefix:表示make install输出的目录。

    4、编译make -j29

    5、编译安装:make install,输出到前指定的目录中

    6、gdb和gdbserver在./__install/bin目录下

    7、其他:如果交叉编译工具链版本较老,第4步编译过程可能会遇到一些编译问题。如下:

    7.1 编译7.8版本GDB时遇到的问题

    Q1:undefined reference to `exp’
    A1:修改makefile、增加-lm编译指令

    7.2 编译10.2版本GDB时遇到问题

    Q1:‘log2’ is not a member of ‘std’

    dwarf2/index-write.c: In member function 'void debug_names::build()':
    dwarf2/index-write.c:780:32: error: 'log2' is not a member of 'std'
           (std::pow (2, std::ceil (std::log2 (name_count * 4 / 3))));
                                    ^
    dwarf2/index-write.c:780:32: note: suggested alternative:
    In file included from /opt/molchip/arm-molchip-linux/arm-mol-linux-uclibcgnueabihf/sysroot/usr/include/features.h:416:0,
                     from /opt/molchip/arm-molchip-linux/arm-mol-linux-uclibcgnueabihf/sysroot/usr/include/stdio.h:28,
                     from ./../gnulib/import/stdio.h:43,
                     from ./../gdbsupport/common-defs.h:86,
                     from ./defs.h:28,
                     from dwarf2/index-write.c:20:
    /opt/molchip/arm-molchip-linux/arm-mol-linux-uclibcgnueabihf/sysroot/usr/include/bits/mathcalls.h:158:1: note:   'log2'
     __MATHCALL (log2,, (_Mdouble_ __x))
     ^
      CXX    frame-base.o
      CXX    frame-unwind.o
      CXX    frame.o
      CXX    gcore.o
      CXX    gdb-demangle.o
      CXX    gdb_bfd.o
      CXX    gdb_obstack.o
      CXX    gdb_regex.o
    make[2]: *** [dwarf2/index-write.o] 错误 1
    make[2]: *** 正在等待未完成的任务....
    make[2]:正在离开目录 `/data1/hongmiao/work/Code/MyCode/gdb-10.2/gdb'
    make[1]: *** [all-gdb] 错误 2
    make[1]:正在离开目录 `/data1/hongmiao/work/Code/MyCode/gdb-10.2'
    make: *** [all] 错误 2
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28

    A1:使用log函数替换log2方法
    将./gdb/dwarf2/index-write.c出错的行

    m_bucket_table.resize
      (std::pow (2, std::ceil (std::log2 (name_count * 4 / 3))));
    
    • 1
    • 2

    使用log函数替换log2方法

    m_bucket_table.resize
      (std::pow (2, std::ceil (std::log(name_count * 4 / 3) / std::log((float)2.0))));
    
    • 1
    • 2

    Q2:undefined reference to ‘_obstack_free’

    /opt/molchip/arm-molchip-linux/bin/../lib/gcc/arm-mol-linux-uclibcgnueabihf/4.9.4/../../../../arm-mol-linux-uclibcgnueabihf/bin/ld.bfd: ada-exp.o: in function `ada_parse(parser_state*)':
    /data1/hongmiao/work/Code/MyCode/gdb-10.2/gdb/ada-exp.y:738: undefined reference to `_obstack_free'
    /opt/molchip/arm-molchip-linux/bin/../lib/gcc/arm-mol-linux-uclibcgnueabihf/4.9.4/../../../../arm-mol-linux-uclibcgnueabihf/bin/ld.bfd: ada-lang.o: in function `ada_clear_symbol_cache()':
    /data1/hongmiao/work/Code/MyCode/gdb-10.2/gdb/ada-lang.c:4568: undefined reference to `_obstack_free'
    /opt/molchip/arm-molchip-linux/bin/../lib/gcc/arm-mol-linux-uclibcgnueabihf/4.9.4/../../../../arm-mol-linux-uclibcgnueabihf/bin/ld.bfd: ada-lang.o: in function `~auto_obstack':
    /data1/hongmiao/work/Code/MyCode/gdb-10.2/gdb/gdb_obstack.h:126: undefined reference to `_obstack_free'
    /opt/molchip/arm-molchip-linux/bin/../lib/gcc/arm-mol-linux-uclibcgnueabihf/4.9.4/../../../../arm-mol-linux-uclibcgnueabihf/bin/ld.bfd: /data1/hongmiao/work/Code/MyCode/gdb-10.2/gdb/gdb_obstack.h:126: undefined reference to `_obstack_free'
    /opt/molchip/arm-molchip-linux/bin/../lib/gcc/arm-mol-linux-uclibcgnueabihf/4.9.4/../../../../arm-mol-linux-uclibcgnueabihf/bin/ld.bfd: ada-lang.o: in function `ada_free_symbol_cache':
    /data1/hongmiao/work/Code/MyCode/gdb-10.2/gdb/ada-lang.c:4539: undefined reference to `_obstack_free'
    /opt/molchip/arm-molchip-linux/bin/../lib/gcc/arm-mol-linux-uclibcgnueabihf/4.9.4/../../../../arm-mol-linux-uclibcgnueabihf/bin/ld.bfd: c-exp.o:/data1/hongmiao/work/Code/MyCode/gdb-10.2/gdb/c-exp.y:2351: more undefined references to `_obstack_free' follow
    collect2: error: ld returned 1 exit status
    make[2]: *** [gdb] 错误 1
    make[2]:正在离开目录 `/data1/hongmiao/work/Code/MyCode/gdb-10.2/gdb'
    make[1]: *** [all-gdb] 错误 2
    make[1]:正在离开目录 `/data1/hongmiao/work/Code/MyCode/gdb-10.2'
    make: *** [all] 错误 2
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    A2:使用宏定义使用_obstack_free函数替换obstack_free
    在./include/obstack.h中增加定义

    #ifndef obstack_free
    #define _obstack_free obstack_free
    #endif
    
    • 1
    • 2
    • 3

    Q3:configure: error: no termcap library found
    A3:https://www.codenong.com/cs109695462/

  • 相关阅读:
    数据库事务概述
    【JavaEE重点知识归纳】第6节:数组
    JWT 弊端解决思路(主动过期\权限更新)
    防止显卡掉卡的一种方法:nvidia-smi -pm 1
    详细说明idea中的war和war exploded的区别
    Ext JS 如何定义公用方法(单例类 or 静态方法)
    一套轻量、安全的问卷系统基座,提供面向个人和企业的一站式产品级解决方案
    小程序项目业务逻辑回忆4
    【QML】QML中的ui文件
    Android安全性优化——APP加固
  • 原文地址:https://blog.csdn.net/SanShuiGeGe/article/details/128192427