如何构建可重定位、带Python支持且无Msys2依赖的GDB12.1
构建环境与问题背景
- 基础环境:64位Win10系统,使用搭载GCC 11.3的msys64环境构建GDB 12.1
- 平台信息:主机平台为
x86_64-w64-mingw32,目标调试平台为i686-elf - 交付要求:输出自带Python支持的GDB程序,客户机无需预装msys64环境即可运行
初始构建执行命令如下:
$GDB_SRCDIR/$GDB_VERSION/configure --target=$TARGET --with-expat=yes --enable-static=yes --with-python> configure.log 2>&1 make > make.log 2>&1
msys64环境正常时,上述命令构建出的GDB12.1可正常启动运行。
现有其他软件包内预安装的GDB10.1版本可脱离本地Python环境运行,其构建时使用了可重定位Python路径参数:
--with-python=/mingw64 (relocatable) --with-python-libdir=/mingw64/lib (relocatable)
但本次构建的GDB12.1硬编码了Python绝对路径:
--with-python=C:/msys64/mingw64 --with-python-libdir=C:/msys64/mingw64/lib
已尝试编写GDB启动脚本配置Python路径,脚本内容如下:
python import sys import os sys.path.insert (0, "\\Python") sys.path.append ("\\lib") sys.path.append ("\\share") end
部署的程序目录结构如下,gdb-12.1根目录下共设4个子文件夹:
gdb-12.1/ ├─ bin/ 存放构建生成的GDB及所需依赖DLL ├─ lib/ 存放Python 3.9.12版本的相关库文件 ├─ Python/ 存放GDB及libstdcxx支持脚本 └─ share/ 存放GCC11.3的相关支持文件
重命名msys64文件夹模拟无msys64环境后启动GDB12.1,触发如下报错:
Could not find platform independent libraries <prefix> Could not find platform dependent libraries <exec_prefix> Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] Python path configuration: PYTHONHOME = (not set) PYTHONPATH = (not set) program name = 'c:\msys64\mingw64/bin/python' isolated = 0 environment = 1 user site = 1 import site = 1 sys._base_executable = 'c:\\msys64\\mingw64/bin/python' sys.base_prefix = 'D:\\a\\msys64\\mingw64' sys.base_exec_prefix = 'D:\\a\\msys64\\mingw64' sys.platlibdir = 'lib' sys.executable = 'c:\\msys64\\mingw64/bin/python' sys.prefix = 'D:\\a\\msys64\\mingw64' sys.exec_prefix = 'D:\\a\\msys64\\mingw64' sys.path = [ 'D:\\a\\msys64\\mingw64\\lib\\python39.zip', 'D:\\a\\msys64\\mingw64\\lib\\python3.9', 'D:\\a\\msys64\\mingw64\\lib\\lib-dynload', '', ] Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding Python runtime state: core initialized ModuleNotFoundError: No module named 'encodings' Current thread 0x0000a5a0 (most recent call first): <no Python frame>
此前曾尝试使用--with-python=C:\Python39\参数构建GDB12.1,移除C:\Python39和C:\msys64路径依赖后GDB12.1可正常启动,但无法响应CTRL+C中断信号,该功能为调试工作必需的核心能力。
待解决问题
- 如何配置构建参数,编译出和GDB10.1一样使用可重定位Python路径的GDB12.1版本?
- 是否有其他方案可以实现GDB12.1内置Python支持,无需依赖本地安装的Python环境?
- 上述基于C:\Python39路径构建的GDB12.1版本无法响应CTRL+C中断的问题如何修复?
内容的提问来源于stack exchange,提问作者DNO
相关产品推荐
相关产品推荐

