Skip to content

Commit 9b88897

Browse files
[3.14] gh-163039: Add support for float to python-gdb.py (GH-163040) (#163049)
gh-163039: Add support for float to python-gdb.py (GH-163040) (cherry picked from commit 90a0b90) Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent 70a7fbd commit 9b88897

3 files changed

Lines changed: 19 additions & 0 deletions

File tree

‎Lib/test/test_gdb/test_pretty_print.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ def test_int(self):
7171
self.assertGdbRepr(1000000000000)
7272
self.assertGdbRepr(-1000000000000000)
7373

74+
@support.requires_resource('cpu')
75+
def test_float(self):
76+
'Verify the pretty-printing of various float values'
77+
self.assertGdbRepr(1.5)
78+
self.assertGdbRepr(1e-9)
79+
7480
def test_singletons(self):
7581
'Verify the pretty-printing of True, False and None'
7682
self.assertGdbRepr(True)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add support for :class:`float` numbers to ``python-gdb.py``. Patch by Victor
2+
Stinner.

‎Tools/gdb/libpython.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ def subclass_from_type(cls, t):
354354
'frozenset' : PySetObjectPtr,
355355
'builtin_function_or_method' : PyCFunctionObjectPtr,
356356
'method-wrapper': wrapperobject,
357+
'float': PyFloatObjectPtr,
357358
}
358359
if tp_name in name_map:
359360
return name_map[tp_name]
@@ -967,6 +968,16 @@ class PyNoneStructPtr(PyObjectPtr):
967968
def proxyval(self, visited):
968969
return None
969970

971+
class PyFloatObjectPtr(PyObjectPtr):
972+
"""
973+
Class wrapping a gdb.Value that's a PyFloatObject*.
974+
"""
975+
_typename = 'PyFloatObject'
976+
977+
def proxyval(self, visited):
978+
fval = float(self.field('ob_fval'))
979+
return fval
980+
970981
class PyFrameObjectPtr(PyObjectPtr):
971982
_typename = 'PyFrameObject'
972983

0 commit comments

Comments
 (0)