-
Enable the debuginfo package repository.
In
/etc/yum.repos.d/photon-debuginfo.repo
changeenabled=0
toenable=1
./etc/yum.repos.d/photon-debuginfo.repo
should look like this[photon-debuginfo] name=VMware Photon Linux debuginfo $releasever ($basearch) baseurl=https://packages.vmware.com/photon/$releasever/photon_debuginfo_$releasever_$basearch gpgkey=file:///etc/pki/rpm-gpg/VMWARE-RPM-GPG-KEY gpgcheck=1 enabled=1 skip_if_unavailable=True
-
Install matching gdb, python3, python3-devel, and python3-debuginfo packages. At the time of this writting the
python3-debuginfo
package is older than the current python3 packages.tdnf install gdb python3==3.7.0 python3-devel==3.7.0 python3-debuginfo
-
Download the python extensions for gdb from cypthon's source tree. Download the version from the tag matching the python version we installed. (3.7.0 in this case).
wget https://raw.githubusercontent.com/python/cpython/v3.7.0/Tools/gdb/libpython.py
-
Start gdb with the
-p
option to attach to our running python process.gdb -p <pid>
-
If everything goes well, you will see gdb load python's debug headers.
Reading symbols from /usr/bin/python3.7...Reading symbols from /usr/lib/debug/bin/python3.7-3.7.0-6.ph3.x86_64.debug...done.
-
Source the python extension in your gdb session
source libpython.py
-
Now get a python backtrace from gdb using
py-bt
(gdb) source libpython.py (gdb) py-bt Traceback (most recent call first): <built-in method sleep of module object at remote 0x7f3b243b7d18> File "/usr/lib/python3.7/site-packages/salt/utils/process.py", line 662, in run time.sleep(10) <built-in method next of module object at remote 0x7f3b2460cc28> File "/usr/lib/python3.7/site-packages/salt/ext/tornado/gen.py", line 309, in wrapper yielded = next(result) File "/usr/lib/python3.7/site-packages/salt/master.py", line 831, in start self.process_manager.run() File "/usr/lib/python3.7/site-packages/salt/cli/daemons.py", line 217, in start self.master.start() File "/usr/lib/python3.7/site-packages/salt/scripts.py", line 104, in salt_master master.start() File "/usr/bin/salt-master", line 11, in <module> load_entry_point('salt==3002.5', 'console_scripts', 'salt-master')()
-
Check out some of the other python extenssion commands:
py-bt-full, py-down, py-list, py-locals, py-print, py-up, python, python-interactive
Last active
May 31, 2023 00:42
-
-
Save dwoz/2269ccbfbde79476a556d7ec4f6c508a to your computer and use it in GitHub Desktop.
Debug python3 with gdb on photon linux
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment