gh-142095: Use thread local frame info in `py-bt` and `py-bt-full` when available
In optimized and -Og builds, arguments and local variables are frequently unavailable in gdb. This makes py-bt fail to print anything useful. Use the PyThreadState* pointers _Py_tss_gilstate and Py_tss_tstate to find the interpreter frame if we can't get the frame from the _PyEval_EvalFrameDefault call.
- Issue: gh-142095
:robot: New build scheduled with the buildbot fleet by @colesbury for commit 64a5436b7e9d0c9da8780b61e781dd0badb27871 :robot:
Results will be shown at:
https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F143371%2Fmerge
If you want to schedule another build, you need to add the :hammer: test-with-buildbots label again.
:robot: New build scheduled with the buildbot fleet by @colesbury for commit 9d0e6bab8bc8a5c896f9d3a71f7ceb8a4610f09d :robot:
Results will be shown at:
https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F143371%2Fmerge
If you want to schedule another build, you need to add the :hammer: test-with-buildbots label again.
:robot: New build scheduled with the buildbot fleet by @colesbury for commit a44b2a75ab34da4049dddbffd2712e8c7173588b :robot:
Results will be shown at:
https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F143371%2Fmerge
If you want to schedule another build, you need to add the :hammer: test-with-buildbots label again.
ooo
thank you so much :sob:
$ gdb python3
GNU gdb (Debian 16.3-1) 16.3
Copyright (C) 2024 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-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from python3...
Reading symbols from /usr/lib/debug/.build-id/22/c2082c4e6b2d096ae773dc6902a9465c23c213.debug...
(gdb) r
Starting program: /usr/bin/python3
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Python 3.13.5 (main, Jun 25 2025, 18:55:22) [GCC 14.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Program received signal SIGINT, Interrupt.
__internal_syscall_cancel (a1=140737349371808, a2=1, a3=a3@entry=100, a4=a4@entry=0, a5=a5@entry=0, a6=a6@entry=0, nr=7) at ./nptl/cancellation.c:44
warning: 44 ./nptl/cancellation.c: No such file or directory
(gdb) py-bt
Traceback (most recent call first):
File "/usr/lib/python3.13/_pyrepl/unix_console.py", line 432, in wait
or bool(self.pollob.poll(timeout))
File "/usr/lib/python3.13/_pyrepl/reader.py", line 705, in handle1
self.console.wait(100)
File "/usr/lib/python3.13/_pyrepl/reader.py", line 750, in readline
self.handle1()
File "/usr/lib/python3.13/_pyrepl/readline.py", line 389, in multiline_input
return reader.readline()
File "/usr/lib/python3.13/_pyrepl/simple_interact.py", line 146, in run_multiline_interactive_console
statement = multiline_input(more_lines, ps1, ps2)
File "/usr/lib/python3.13/_pyrepl/main.py", line 59, in interactive_console
run_multiline_interactive_console(console)
File "/usr/lib/python3.13/_pyrepl/__main__.py", line 10, in <module>
__pyrepl_interactive_console()
<built-in method exec of module object at remote 0x7ffff7b91850>
File "<frozen runpy>", line 88, in _run_code
File "<frozen runpy>", line 198, in _run_module_as_main
I suggest backporting this change to 3.13 and 3.14 branches.
Thanks @colesbury for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. 🐍🍒⛏🤖
Sorry, @colesbury, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 49c3b0a67a77bb42e736cea7dcbc1aa8fa704074 3.13
GH-143566 is a backport of this pull request to the 3.14 branch.
GH-143567 is a backport of this pull request to the 3.13 branch.
I think 3.13's libpython.py can be simply overwritten.