如何为MSYS2版GDB获取debuginfod支持?
问题描述
我尝试用gdb tclsh调试Tcl C扩展,但MSYS2版GDB提示Support for debuginfod is not compiled into GDB.,而且读取tclsh.exe时显示(No debugging symbols found in tclsh.exe),导致调试无法进行。参考了某GitHub评论里的方法,但Windows平台找不到MSYS2相关的debuginfod资料,想知道怎么让GDB获得该支持,实现评论里的调试效果。
控制台输出:
GNU gdb (GDB) 15.1 Copyright (C) 2024 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. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-w64-mingw32". Type "show configuration" for configuration details. For bug reporting instructions, please see: <https://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from tclsh.exe... (No debugging symbols found in tclsh.exe) [New Thread 23524.0x78e4] [New Thread 23524.0x5a50] [New Thread 23524.0x3394] [New Thread 23524.0x4cd4] [Thread 23524.0x4cd4 exited with code 0] [Thread 23524.0x3394 exited with code 0] [Thread 23524.0x5a50 exited with code 0] [Thread 23524.0x78e4 exited with code 0] [Inferior 1 (process 23524) exited normally] (gdb) set debuginfod enabled on Support for debuginfod is not compiled into GDB. (gdb)
编译内容:
Building Tkhtml 3 COMPILE = x86_64-w64-mingw32-gcc -g -DUSE_TCL_STUBS=1 -DUSE_TK_STUBS=1 -IC:/Users/billa/OneDrive/Documents/test1/htmlwidget/tkhtml/src/ -O - TCLSH = tclsh $(COMPILE) -c C:/Users/billa/OneDrive/Documents/test1/htmlwidget/tkhtml//src/htmldraw.c -o htmldraw.o x86_64-w64-mingw32-gcc -shared htmlparse.o htmldraw.o htmltcl.o htmlimage.o htmltree.o htmltagdb.o css.o cssprop.o csssearch.o htmlstyle.o mlutil.o cssparser.o htmlPs.o "/mingw64/lib/libtclstub86.a" "/mingw64/lib/libtkstub86.a" -LC:/Tcl/lib -o Tkhtml30g.dll strip Tkhtml30g.dll echo 'package ifneeded Tkhtml 3.0 [list load [file join $dir Tkhtml30g.dll]]' > pkgIndex.tcl
解决方法
1. 替换带debuginfod支持的MSYS2 GDB包
MSYS2的不同仓库中,部分gdb包默认未编译debuginfod支持,可尝试更换安装源:
- 打开MinGW64终端,先卸载现有GDB:
pacman -R mingw-w64-x86_64-gdb - 重新安装最新版MinGW64 GDB,安装前可先查看包信息确认是否包含debuginfod:
pacman -Si mingw-w64-x86_64-gdb pacman -S mingw-w64-x86_64-gdb - 如果上述包仍无debuginfod,切换到MSYS2原生shell(非MinGW环境),安装MSYS2版本的GDB:
pacman -S gdb
2. 手动编译带debuginfod支持的GDB
若官方包无debuginfod支持,可手动编译:
- 安装编译依赖:
pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-make mingw-w64-x86_64-libcurl mingw-w64-x86_64-libarchive - 下载对应版本的GDB源码,解压后进入源码目录,配置编译选项:
./configure --target=x86_64-w64-mingw32 --enable-debuginfod --with-libcurl --with-libarchive - 编译并安装:
make -j$(nproc) make install
3. 绕开debuginfod,手动配置调试符号
debuginfod的核心作用是自动拉取符号,Windows下可通过以下方式直接解决符号问题:
- 获取带调试符号的
tclsh.exe:从Tcl官方下载带调试信息的二进制包,或自行编译Tcl时添加--enable-symbols选项,编译完成后不要执行strip命令。 - 保留扩展的调试符号:你的编译脚本中执行了
strip Tkhtml30g.dll,该命令会移除调试符号,注释掉这一行后重新编译扩展。 - 手动加载符号文件:若已有单独的符号文件(如
.pdb或.debug),可在GDB中通过以下命令加载:
扩展基地址可通过(gdb) file tclsh.exe (gdb) add-symbol-file Tkhtml30g.dll 0x<扩展基地址>info sharedlibrary命令查看加载后的地址。
内容的提问来源于stack exchange,提问作者Zamyatin
相关产品推荐
相关产品推荐

