Skip to content

Commit 9a1aa37

Browse files
[3.15] gh-163039: Add support for float to python-gdb.py (GH-163040) (#163048)
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 45f9d5c commit 9a1aa37

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
@@ -355,6 +355,7 @@ def subclass_from_type(cls, t):
355355
'frozendict' : PyDictObjectPtr,
356356
'builtin_function_or_method' : PyCFunctionObjectPtr,
357357
'method-wrapper': wrapperobject,
358+
'float': PyFloatObjectPtr,
358359
}
359360
if tp_name in name_map:
360361
return name_map[tp_name]
@@ -978,6 +979,16 @@ class PyNoneStructPtr(PyObjectPtr):
978979
def proxyval(self, visited):
979980
return None
980981

982+
class PyFloatObjectPtr(PyObjectPtr):
983+
"""
984+
Class wrapping a gdb.Value that's a PyFloatObject*.
985+
"""
986+
_typename = 'PyFloatObject'
987+
988+
def proxyval(self, visited):
989+
fval = float(self.field('ob_fval'))
990+
return fval
991+
981992
class PyFrameObjectPtr(PyObjectPtr):
982993
_typename = 'PyFrameObject'
983994

0 commit comments

Comments
 (0)