From d34b3ef84d26c4f0accba8095374f561c58c96a1 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Tue, 3 Jan 2023 09:56:57 -0500 Subject: [PATCH] gh-89419: gdb: fix bug causing AttributeError in py-locals when no frame is available (GH-100611) ``` Unable to read information on python frame Python Exception : 'NoneType' object has no attribute 'co_name' ``` Regression in commit b4903afd4debbbd71dc49a2c8fefa74a3b6c6832. While refactoring the code into a while loop, the previous early return when no frame exists went missing. We have just printed a message that we cannot get information about this, so the frame will be None, and we cannot attempt to use it. Discovered on python 3.11, in python 3.12a2 this should error out with `.is_shim()` instead of `co_name`. (cherry picked from commit 85869498331f7020e18bb243c89cd694f674b911) --- .../next/Tools-Demos/2022-12-29-19-22-11.bpo-45256.a0ee_H.rst | 1 + Tools/gdb/libpython.py | 1 + 2 files changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Tools-Demos/2022-12-29-19-22-11.bpo-45256.a0ee_H.rst diff --git a/Misc/NEWS.d/next/Tools-Demos/2022-12-29-19-22-11.bpo-45256.a0ee_H.rst b/Misc/NEWS.d/next/Tools-Demos/2022-12-29-19-22-11.bpo-45256.a0ee_H.rst new file mode 100644 index 00000000000000..9c1aa57625834e --- /dev/null +++ b/Misc/NEWS.d/next/Tools-Demos/2022-12-29-19-22-11.bpo-45256.a0ee_H.rst @@ -0,0 +1 @@ +Fix a bug that caused an :exc:`AttributeError` to be raised in ``python-gdb.py`` when ``py-locals`` is used without a frame. diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py index 857e52f00a06eb..a99ce945265f67 100755 --- a/Tools/gdb/libpython.py +++ b/Tools/gdb/libpython.py @@ -2126,6 +2126,7 @@ def invoke(self, args, from_tty): while True: if not pyop_frame: print(UNABLE_READ_INFO_PYTHON_FRAME) + break sys.stdout.write('Locals for %s\n' % (pyop_frame.co_name.proxyval(set())))