解压后, 通过./configure && make && make install 编译安装,这里我手动指定了安装路径:
1
./configure --prefix=/home/geduer/elfutils-0.179
在 configure 时会遇到下面报错:
1 2 3 4 5
checking for libmicrohttpd... no checking for libcurl... no checking for sqlite3... no checking for libarchive... no configure: error: C++ compiler or dependencies not found, use --disable-debuginfod to disable.
原因是系统下缺少 libmicrohttpd、libcurl 、sqlite3、libarchive 这四个依赖库,通过 apt 来安装这些依赖库,还需要安装对应的 dev 开发包,所以选择直接安装 dev 包,默认会把依赖库也安装。
./configure --prefix=/home/geduer/gdb/install --enable-tui --with-debuginfod make && make install
虽然已经安装了 debuginfod,但是 gdb 编译还是同样报错:
1 2 3 4 5
checking for aarch64-unknown-linux-gnu-pkg-config... /usr/bin/aarch64-unknown-linux-gnu-pkg-config checking pkg-config is at least version 0.9.0... yes checking whether to use debuginfod... yes checking for libdebuginfod >= 0.179... no configure: error: "--with-debuginfod was given, but libdebuginfod is missing or unusable."
$ /usr/bin/aarch64-unknown-linux-gnu-pkg-config --exists --print-errors "libdebuginfod >= 0.179" Package libdebuginfod was not found in the pkg-config search path. Perhaps you should add the directory containing `libdebuginfod.pc' to the PKG_CONFIG_PATH environment variable No package 'libdebuginfod' found
启动 gdb-13.1,通过命令 show debuginfod 查看 debuginfod 配置,主要包括三个配置:
每次启动 gdb 会主动询问是否开启 debuginfod 功能,可以把命令 set debuginfod enabled on 添加到 ~/.gdbinit 里永久开启;
设置 debuginfod 服务器地址,不同发行版厂商会维护自己的 debuginfod 服务器。
打开 debuginfod 运行时的详细输出信息,可以通过命令 set debuginfod verbose 0 关闭符号下载过程信息打印。
1 2 3 4 5
(gdb) show debuginfod debuginfod enabled: Debuginfod functionality is currently set to "ask". debuginfod urls: Debuginfod URLs are currently set to: https://debuginfod.ubuntu.com debuginfod verbose: Debuginfod verbose output is set to 1.
gdb 里和 debuginfod 相关的命令如下,主要用来设置和显示上述的三个配置。
1 2 3 4 5 6 7 8 9 10
(gdb) apropos debuginfod set debuginfod -- Set debuginfod options. set debuginfod enabled -- Set whether to use debuginfod. set debuginfod urls -- Set the list of debuginfod server URLs. set debuginfod verbose -- Set verbosity of debuginfod output. show debuginfod -- Show debuginfod options. show debuginfod enabled -- Show whether to use debuginfod. show debuginfod urls -- Show the list of debuginfod server URLs. show debuginfod verbose -- Show debuginfod debugging. (gdb)
使用演示
通过 gdb 调试 git,启动后输入 y 启用 debuginfod 后便自动下载调试符号:
1 2 3 4 5 6 7 8 9
geduer@gdk8:~/gdb/install/bin$ ./gdb /usr/bin/git -q Reading symbols from /usr/bin/git... This GDB supports auto-downloading debuginfo from the following URLs: <https://debuginfod.ubuntu.com> Enable debuginfod for this session? (y or [n]) y Debuginfod has been enabled. To make this setting permanent, add 'set debuginfod enabled on' to .gdbinit. Downloading separate debug info for /usr/bin/git [#################################### ] 32% (4.19 M)
Reading symbols from /home/geduer/.cache/debuginfod_client/f1b3574e4c6c4600819de4fe860b1912235a8be3/debuginfo... (gdb) b main Download failed: Invalid argument. Continuing without source file ./common-main.c. Breakpoint 1 at 0x17108: file common-main.c, line 27. (gdb) !sudo apt source git Reading package lists... Done NOTICE: 'git' packaging is maintained in the 'Git' version control system at: https://repo.or.cz/r/git/debian.git/ Please use: git clone https://repo.or.cz/r/git/debian.git/ to retrieve the latest (possibly unreleased) updates to the package. Skipping already downloaded file 'git_2.17.1-1ubuntu0.18.dsc' Skipping already downloaded file 'git_2.17.1.orig.tar.xz' Skipping already downloaded file 'git_2.17.1-1ubuntu0.18.debian.tar.xz' Need to get 0 B of source archives. Skipping unpack of already unpacked source in git-2.17.1 (gdb) directory git-2.17.1/ Source directories searched: /home/geduer/gdb/install/bin/git-2.17.1:$cdir:$cwd
(gdb) run Starting program: /usr/bin/git Downloading separate debug info for /lib/ld-linux-aarch64.so.1 Downloading separate debug info for system-supplied DSO at 0x7ff7ffc000 Downloading separate debug info for /lib/aarch64-linux-gnu/libpcre.so.3 Downloading separate debug info for /lib/aarch64-linux-gnu/libz.so.1 Downloading separate debug info for /lib/aarch64-linux-gnu/libpthread.so.0 [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/aarch64-linux-gnu/libthread_db.so.1". Downloading separate debug info for /lib/aarch64-linux-gnu/libc.so.6
Breakpoint 1, main (argc=1, argv=0x7ffffff3d8) at common-main.c:27 warning: Source file is more recent than executable. 27 { (gdb) l 22 sigprocmask(SIG_UNBLOCK, &unblock, NULL); 23 signal(SIGPIPE, SIG_DFL); 24 } 25 26 int main(int argc, const char **argv) 27 { 28 /* 29 * Always open file descriptors 0/1/2 to avoid clobbering files 30 * in die(). It also avoids messing up when the pipes are dup'ed 31 * onto stdin/stdout/stderr in the child processes we spawn.