diff --git a/Lib/test/test_gdb/test_pretty_print.py b/Lib/test/test_gdb/test_pretty_print.py index 04e06a64aaa5bb..7f1bb4b6921afd 100644 --- a/Lib/test/test_gdb/test_pretty_print.py +++ b/Lib/test/test_gdb/test_pretty_print.py @@ -71,6 +71,12 @@ def test_int(self): self.assertGdbRepr(1000000000000) self.assertGdbRepr(-1000000000000000) + @support.requires_resource('cpu') + def test_float(self): + 'Verify the pretty-printing of various float values' + self.assertGdbRepr(1.5) + self.assertGdbRepr(1e-9) + def test_singletons(self): 'Verify the pretty-printing of True, False and None' self.assertGdbRepr(True) diff --git a/Misc/NEWS.d/next/Tools-Demos/2026-12-03-00-57-28.gh-issue-163039.0ygkWr.rst b/Misc/NEWS.d/next/Tools-Demos/2026-12-03-00-57-28.gh-issue-163039.0ygkWr.rst new file mode 100644 index 00000000000000..617fecb17895f4 --- /dev/null +++ b/Misc/NEWS.d/next/Tools-Demos/2026-12-03-00-57-28.gh-issue-163039.0ygkWr.rst @@ -0,0 +1,2 @@ +Add support for :class:`float` numbers to ``python-gdb.py``. Patch by Victor +Stinner. diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py index a7f89442dd21db..562693e0bb9dbf 100755 --- a/Tools/gdb/libpython.py +++ b/Tools/gdb/libpython.py @@ -355,6 +355,7 @@ def subclass_from_type(cls, t): 'frozendict' : PyDictObjectPtr, 'builtin_function_or_method' : PyCFunctionObjectPtr, 'method-wrapper': wrapperobject, + 'float': PyFloatObjectPtr, } if tp_name in name_map: return name_map[tp_name] @@ -978,6 +979,16 @@ class PyNoneStructPtr(PyObjectPtr): def proxyval(self, visited): return None +class PyFloatObjectPtr(PyObjectPtr): + """ + Class wrapping a gdb.Value that's a PyFloatObject*. + """ + _typename = 'PyFloatObject' + + def proxyval(self, visited): + fval = float(self.field('ob_fval')) + return fval + class PyFrameObjectPtr(PyObjectPtr): _typename = 'PyFrameObject'