ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

在gdb中加载python支持

2019-07-11 00:51:16  阅读:243  来源: 互联网

标签:python linux gdb archlinux


我遇到了在gdb中使用特定于python的命令的问题.我有一般的python支持包括:

(gdb) python print(True)
True

我已经安装了标准脚本:

$ls /usr/share/gdb/python/gdb/
command  FrameDecorator.py  FrameIterator.py  frames.py  function  __init__.py  printer  printing.py  prompt.py  __pycache__  types.py  unwinder.py  xmethod.py

我确保使用所有路径启用加载:

$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中没有这些命令,则表示包含它们的脚本未自动加载.

要找出原因,请启用自动加载调试:

(gdb) set debug auto-load

并尝试加载Python可执行文件:

(gdb) file python3

您应该看到与此类似的输出:

Reading symbols from python3...Reading symbols from /usr/lib/debug/.build-id/58/bce0c98a07039868053ed4b27e79959caadb9d.debug...done.
auto-load: Attempted file "/usr/lib/debug/.build-id/58/bce0c98a07039868053ed4b27e79959caadb9d.debug-gdb.gdb" does not exist.
auto-load: Expanded $-variables to "/usr/lib/debug:/usr/share/gdb/auto-load".
auto-load: Searching 'set auto-load scripts-directory' path "$debugdir:$datadir/auto-load".
auto-load: Attempted file "/usr/lib/debug/usr/lib/debug/.build-id/58/bce0c98a07039868053ed4b27e79959caadb9d.debug-gdb.gdb" does not exist.
auto-load: Attempted file "/usr/share/gdb/auto-load/usr/lib/debug/.build-id/58/bce0c98a07039868053ed4b27e79959caadb9d.debug-gdb.gdb" does not exist.
auto-load: Attempted file "/usr/lib/debug/.build-id/58/bce0c98a07039868053ed4b27e79959caadb9d.debug-gdb.py" does not exist.
auto-load: Expanded $-variables to "/usr/lib/debug:/usr/share/gdb/auto-load".
auto-load: Searching 'set auto-load scripts-directory' path "$debugdir:$datadir/auto-load".
auto-load: Attempted file "/usr/lib/debug/usr/lib/debug/.build-id/58/bce0c98a07039868053ed4b27e79959caadb9d.debug-gdb.py" does not exist.
auto-load: Attempted file "/usr/share/gdb/auto-load/usr/lib/debug/.build-id/58/bce0c98a07039868053ed4b27e79959caadb9d.debug-gdb.py" does not exist.
done.
auto-load: Attempted file "/usr/bin/python3.6-gdb.gdb" does not exist.
auto-load: Expanded $-variables to "/usr/lib/debug:/usr/share/gdb/auto-load".
auto-load: Searching 'set auto-load scripts-directory' path "$debugdir:$datadir/auto-load".
auto-load: Attempted file "/usr/lib/debug/usr/bin/python3.6-gdb.gdb" does not exist.
auto-load: Attempted file "/usr/share/gdb/auto-load/usr/bin/python3.6-gdb.gdb" does not exist.
auto-load: Attempted file "/usr/bin/python3.6-gdb.py" does not exist.
auto-load: Expanded $-variables to "/usr/lib/debug:/usr/share/gdb/auto-load".
auto-load: Searching 'set auto-load scripts-directory' path "$debugdir:$datadir/auto-load".
auto-load: Attempted file "/usr/lib/debug/usr/bin/python3.6-gdb.py" does not exist.
auto-load: Attempted file "/usr/share/gdb/auto-load/usr/bin/python3.6-gdb.py" exists.
auto-load: Loading python script "/usr/share/gdb/auto-load/usr/bin/python3.6-gdb.py" by extension for objfile "/usr/bin/python3.6".
auto-load: Matching file "/usr/share/gdb/auto-load/usr/bin/python3.6-gdb.py" to pattern "/usr/lib/debug"
auto-load: Not matched - pattern "/usr/lib/debug".
auto-load: Matching file "/usr/share/gdb/auto-load/usr/bin/python3.6-gdb.py" to pattern "/usr/share/gdb/auto-load"
auto-load: Matched - file "/usr/share/gdb/auto-load" to pattern "/usr/share/gdb/auto-load".
auto-load: File "/usr/share/gdb/auto-load/usr/bin/python3.6-gdb.py" matches directory "/usr/share/gdb/auto-load".

GDB用于查找要自动加载的脚本的规则如下所述:

https://sourceware.org/gdb/current/onlinedocs/gdb/Auto_002dloading-extensions.html

在简化的形式中,它在遵循符号链接后获取加载的目标文件的绝对文件路径,向其附加-gdb.(gdb | py | scm)扩展名并尝试查找其路径以其中一个开头的文件开头的文件.加载脚本 – 目录目录,并以构造的脚本名称结束.

如果找不到这样的脚本,请检查系统上实际可用的脚本.您可能正在尝试调试,例如一个python3可执行文件,它是python3.6的符号链接,而你的系统的GDB安装可能只提供python3.5可执行文件的GDB脚本.由于脚本名称的构造方式,可执行文件的名称实际上很重要.

另外,检查GDB是否使用了相应的脚本目录:

(gdb) show auto-load scripts-directory
List of directories from which to load auto-loaded scripts is $debugdir:$datadir/auto-load.

并在必要时更新它们.加载启用了自动加载调试的目标文件时,请执行以下操作:

auto-load: Expanded $-variables to "/usr/lib/debug:/usr/share/gdb/auto-load".

显示scripts-directory的扩展值.

最后,检查自动加载安全路径的值:

(gdb) show auto-load safe-path
List of directories from which it is safe to auto-load files is $debugdir:$datadir/auto-load.

并在必要时进行更新.

顺便说一下,你的〜/ .gdbinit文件中可能不需要任何额外的add-auto-load-scripts-directory或add-auto-load-safe-path命令,因为默认的自动加载脚本目录和安全路径通常是包括$datadir / auto-load,它通常扩展到/usr/share / gdb / auto-load,这通常是系统范围的GDB脚本的默认位置,其中usr / bin / python * -gdb.py文件最多可能会被发现.

标签:python,linux,gdb,archlinux
来源: https://codeday.me/bug/20190711/1429378.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有