在gdb中使用python特定的命令时遇到了一个问题。我提供了对python的一般支持:
(gdb) python print(True)
True
我已经安装了标准脚本:
^{pr2}$我确保加载已启用所有路径,我可以:
$ cat ~/.gdbinit
add-auto-load-safe-path /usr/share/gdb/python/gdb/
add-auto-load-safe-path /usr/share/gdb/python/
add-auto-load-safe-path /usr/share/gdb/
set auto-load python-scripts on
但出于某些原因,gdb仍然不喜欢这样:
(gdb) info auto-load
gdb-scripts: No auto-load scripts.
guile-scripts: No auto-load scripts.
libthread-db: No auto-loaded libthread-db.
local-gdbinit: Local .gdbinit file was not found.
python-scripts: No auto-load scripts.
我想在加载gdb
之后使py-bt
命令正常工作。在
py-bt
和相关命令通常在GDB脚本文件python*-gdb.py
中定义,该文件往往存在于/usr/share/gdb/auto-load/usr/bin/
中。如果在调试Python对象文件时GDB中没有这些命令,则表示包含这些命令的脚本没有自动加载。在要找出原因,请启用
auto-load
调试:并尝试加载Python可执行文件:
^{pr2}$您应该会看到类似的输出:
GDB用于查找
auto-load
的脚本的规则如下:https://sourceware.org/gdb/current/onlinedocs/gdb/Auto_002dloading-extensions.html
在一个简化的形式中,它在符号链接之后获取加载的对象文件的绝对文件路径,在它后面附加一个
-gdb.(gdb|py|scm)
扩展名,并尝试查找路径以auto-load
scripts-directory
目录之一开始并以构造的脚本名称结束的文件。在如果找不到这样的脚本,请检查哪些脚本在您的系统上实际可用。您可能正在尝试调试例如
python3
可执行文件,它是python3.6
的符号链接,而系统的GDB安装可能只为python3.5
可执行文件提供GDB脚本。由于脚本名称的构造方式,可执行文件的名称实际上并不重要。在此外,请检查GDB是否正在使用适当的脚本目录:
必要时更新。在启用
auto-load
调试的情况下加载对象文件时,以下行:显示
scripts-directory
的展开值。在最后,检查
auto-load
安全路径的值:如果有必要,也要更新它。在
顺便说一句,您很可能不需要在
~/.gdbinit
文件中添加任何额外的add-auto-load-scripts-directory
或add-auto-load-safe-path
命令,因为默认的auto-load
脚本目录和安全路径通常包括$datadir/auto-load
,它通常扩展到/usr/share/gdb/auto-load
,这通常是系统范围GDB脚本的默认位置,在那里可以找到usr/bin/python*-gdb.py
文件。在相关问题 更多 >
编程相关推荐