aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2023-03-10 10:19:58 +0000
committerAndrew Burgess <aburgess@redhat.com>2023-03-30 10:25:46 +0100
commit7e6af18d0c7df5d1ee6144ef0e09b32db3a347e7 (patch)
tree3b767b5ffed5469d25531261cb25de45f4842b04 /gdb/testsuite
parent86b35b7116a325ae0179e5b74692e4e7a1e8b2d7 (diff)
downloadgdb-7e6af18d0c7df5d1ee6144ef0e09b32db3a347e7.zip
gdb-7e6af18d0c7df5d1ee6144ef0e09b32db3a347e7.tar.gz
gdb-7e6af18d0c7df5d1ee6144ef0e09b32db3a347e7.tar.bz2
gdb/python: add __repr__ for PendingFrame and UnwindInfo
Having a useful __repr__ method can make debugging Python code that little bit easier. This commit adds __repr__ for gdb.PendingFrame and gdb.UnwindInfo classes, along with some tests. Reviewed-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/gdb.python/py-unwind.exp19
-rw-r--r--gdb/testsuite/gdb.python/py-unwind.py16
2 files changed, 34 insertions, 1 deletions
diff --git a/gdb/testsuite/gdb.python/py-unwind.exp b/gdb/testsuite/gdb.python/py-unwind.exp
index f670da5..7e6ac9a 100644
--- a/gdb/testsuite/gdb.python/py-unwind.exp
+++ b/gdb/testsuite/gdb.python/py-unwind.exp
@@ -152,6 +152,25 @@ check_for_broken_backtrace "backtrace to capture a PendingFrame object"
# Check the captured PendingFrame is not valid.
gdb_test "python print(captured_pending_frame.is_valid())" "False"
+# Check the __repr__ of an invalid PendingFrame.
+gdb_test "python print(repr(captured_pending_frame))" \
+ "<gdb.PendingFrame \\(invalid\\)>"
+
+# Check the __repr__ of an UnwindInfo for an invalid PendingFrame.
+gdb_test "python print(captured_unwind_info)"
+gdb_test "python print(repr(captured_unwind_info))" \
+ "<gdb.UnwindInfo for an invalid frame>"
+
+# Check the repr of a PendingFrame that was copied (as a string) at a
+# time the PendingFrame was valid.
+gdb_test "python print(captured_pending_frame_repr)" \
+ "<gdb.PendingFrame level=0, sp=$hex, pc=$hex>"
+
+# Check the repr of an UnwindInfo that was copied (as a string) at a
+# time the UnwindInfo was valid.
+gdb_test "python print(captured_unwind_info_repr)" \
+ "<gdb.UnwindInfo frame #0, saved_regs=\\(rip, rbp, rsp\\)>"
+
# Call methods on the captured gdb.PendingFrame and check we see the
# expected error.
gdb_test_no_output "python pf = captured_pending_frame"
diff --git a/gdb/testsuite/gdb.python/py-unwind.py b/gdb/testsuite/gdb.python/py-unwind.py
index 8e3c1f3..f8f04b7 100644
--- a/gdb/testsuite/gdb.python/py-unwind.py
+++ b/gdb/testsuite/gdb.python/py-unwind.py
@@ -133,8 +133,11 @@ class TestUnwinder(Unwinder):
global_test_unwinder = TestUnwinder()
gdb.unwinder.register_unwinder(None, global_test_unwinder, True)
-# This is filled in by the simple_unwinder class.
+# These are filled in by the simple_unwinder class.
captured_pending_frame = None
+captured_pending_frame_repr = None
+captured_unwind_info = None
+captured_unwind_info_repr = None
class simple_unwinder(Unwinder):
@@ -143,11 +146,22 @@ class simple_unwinder(Unwinder):
def __call__(self, pending_frame):
global captured_pending_frame
+ global captured_pending_frame_repr
+ global captured_unwind_info
+ global captured_unwind_info_repr
assert pending_frame.is_valid()
if captured_pending_frame is None:
captured_pending_frame = pending_frame
+ captured_pending_frame_repr = repr(pending_frame)
+ fid = FrameId(gdb.Value(0x123), gdb.Value(0x456))
+ uw = pending_frame.create_unwind_info(fid)
+ uw.add_saved_register("rip", gdb.Value(0x123))
+ uw.add_saved_register("rbp", gdb.Value(0x456))
+ uw.add_saved_register("rsp", gdb.Value(0x789))
+ captured_unwind_info = uw
+ captured_unwind_info_repr = repr(uw)
return None