如何为 gdb 安装 python 调试信息?

How to install python debug-info for gdb?

我想使用 gdb 来调试 python 脚本。启动gdb后,输出:

[root@localhost scripts]# gdb python
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-51.el7
Copyright (C) 2013 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-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /usr/bin/python2.7...Reading symbols from /usr/bin/python2.7...(no debugging symbols found)..
.done.
(no debugging symbols found)...done.
Missing separate debuginfos, use: debuginfo-install python-2.7.5-16.el7.x86_64

根据它的提示,我执行debuginfo-install python-2.7.5-16.el7.x86_64命令,输出结果为:

[root@localhost scripts]# debuginfo-install python-2.7.5-16.el7.x86_64
Loaded plugins: product-id
centos-extra                                                                               | 3.4 kB  00:00:00
rhel                                                                                       | 4.1 kB  00:00:00
centos-extra/primary_db                                                                    | 563 kB  00:00:00
Could not find debuginfo for main pkg: python-2.7.5-16.el7.x86_64
Could not find debuginfo pkg for dependency package glibc-2.17-55.el7.x86_64
Could not find debuginfo pkg for dependency package python-libs-2.7.5-16.el7.x86_64
No debuginfo packages available to install

P.S.:有2个yum数据源:RHEL 7.0 iso和CentOS link:

[rhel]
name=rhel 7.0
baseurl=file:///mnt/iso
enabled=1
gpgcheck=0


[centos-extra]
name=centos extra
baseurl=http://cbs.centos.org/repos/virt7-testing/x86_64/os/
enabled=1
gpgcheck=0

如何安装 python 调试信息?

I want to use gdb to debug python script

我认为调试信息用于调试 Python 解释器本身,而不是 Python 脚本。据我所知,gdb 不知道 Python 脚本。如果您启动 gdb python,您要求 gdb 调试 python 解释器。

要调试 Python 脚本,您可以使用 pdb(而不是 gdb),它的命令有一些相似之处...

import pdb

....code...
pdb.set_trace()      # This introduces a breakpoint
... code...

编辑:所以问题是如何为 Python 安装调试信息。您确定要调试 Python 本身吗?

这里有一些想法:RHEL iso 可能不是 -devel 信息的正确来源。我认为原始 iso 不会包含您需要的信息。

我在几个地方找到了你原来的 python 包的调试信息包,但是有一个警告(例如 http://rpm.pbone.net/index.php3/stat/4/idpl/26126276/dir/redhat_7.x/com/python-debuginfo-2.7.5-16.el7.x86_64.rpm.html)说:

This package is obsolete.

http://buildlogs.centos.org/c7.00.04/python/20140617165351/2.7.5-16.el7.x86_64/ 上的调试信息版本。我使用 yum 已经有好几年了,但我相信您可以手动下载该软件包,然后在下载的软件包上 运行 yum 进行安装。根据您原始问题中的消息,您还必须为 glibc 安装 debuginfo 和 python-libs(或者可能首先)。类似于:yum --nogpgcheck localinstall packagename.arch.rpm

有一些关于如何在各种 OS 上安装 python-debuginfo 的说明 here

具体来说:

Fedora:

sudo yum install gdb python-debuginfo

Ubuntu:

sudo apt-get install gdb python2.7-dbg

Centos*:

sudo yum install yum-utils

sudo debuginfo-install glibc

sudo yum install gdb python-debuginfo