aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.python
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2022-04-27 15:22:56 -0600
committerTom Tromey <tom@tromey.com>2022-08-21 08:03:42 -0600
commitbdc8cfc1e43ebc4029cf130c678b9e1a4e4e5682 (patch)
tree8bfc24e3261a01621b4c01020a35db142213c9de /gdb/testsuite/gdb.python
parent12f26cb22e56ab8c26dd5a00f32158af561da4cb (diff)
downloadfsf-binutils-gdb-bdc8cfc1e43ebc4029cf130c678b9e1a4e4e5682.zip
fsf-binutils-gdb-bdc8cfc1e43ebc4029cf130c678b9e1a4e4e5682.tar.gz
fsf-binutils-gdb-bdc8cfc1e43ebc4029cf130c678b9e1a4e4e5682.tar.bz2
Fix crash in gdbpy_parse_register_id
I noticed that gdbpy_parse_register_id would assert if passed a Python object of a type it was not expecting. The included test case shows this crash. This patch fixes the problem and also changes gdbpy_parse_register_id to be more "Python-like" -- it always ensures the Python error is set when it fails, and the callers now simply propagate the existing exception.
Diffstat (limited to 'gdb/testsuite/gdb.python')
-rw-r--r--gdb/testsuite/gdb.python/py-frame.exp6
-rw-r--r--gdb/testsuite/gdb.python/py-unwind.exp6
-rw-r--r--gdb/testsuite/gdb.python/py-unwind.py16
3 files changed, 28 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.python/py-frame.exp b/gdb/testsuite/gdb.python/py-frame.exp
index 4991e8a..56e1ecd 100644
--- a/gdb/testsuite/gdb.python/py-frame.exp
+++ b/gdb/testsuite/gdb.python/py-frame.exp
@@ -134,3 +134,9 @@ gdb_test "python print(gdb.selected_frame().language())" "c"
gdb_test "set language ada"
gdb_test "python print(gdb.selected_frame().language())" "c" \
"frame language is not affected by global language"
+
+# This previously caused a crash -- the implementation was missing the
+# case where a register had an unexpected type.
+gdb_test "python print(gdb.selected_frame().read_register(list()))" \
+ ".*Invalid type for register.*" \
+ "test Frame.read_register with list"
diff --git a/gdb/testsuite/gdb.python/py-unwind.exp b/gdb/testsuite/gdb.python/py-unwind.exp
index cdf9034..798e765 100644
--- a/gdb/testsuite/gdb.python/py-unwind.exp
+++ b/gdb/testsuite/gdb.python/py-unwind.exp
@@ -57,3 +57,9 @@ gdb_test_sequence "where" "Backtrace restored by unwinder" {
# Check that the Python unwinder frames can be flushed / released.
gdb_test "maint flush register-cache" "Register cache flushed\\." "flush frames"
+
+# Check that invalid register names cause errors.
+gdb_test "python print(add_saved_register_error)" "True" \
+ "add_saved_register error"
+gdb_test "python print(read_register_error)" "True" \
+ "read_register error"
diff --git a/gdb/testsuite/gdb.python/py-unwind.py b/gdb/testsuite/gdb.python/py-unwind.py
index 15dba59..319bb63 100644
--- a/gdb/testsuite/gdb.python/py-unwind.py
+++ b/gdb/testsuite/gdb.python/py-unwind.py
@@ -17,6 +17,11 @@ import gdb
from gdb.unwinder import Unwinder
+# These are set to test whether invalid register names cause an error.
+add_saved_register_error = False
+read_register_error = False
+
+
class FrameId(object):
def __init__(self, sp, pc):
self._sp = sp
@@ -101,6 +106,12 @@ class TestUnwinder(Unwinder):
previous_ip = self._read_word(bp + 8)
previous_sp = bp + 16
+ try:
+ pending_frame.read_register("nosuchregister")
+ except ValueError:
+ global read_register_error
+ read_register_error = True
+
frame_id = FrameId(
pending_frame.read_register(TestUnwinder.AMD64_RSP),
pending_frame.read_register(TestUnwinder.AMD64_RIP),
@@ -109,6 +120,11 @@ class TestUnwinder(Unwinder):
unwind_info.add_saved_register(TestUnwinder.AMD64_RBP, previous_bp)
unwind_info.add_saved_register("rip", previous_ip)
unwind_info.add_saved_register("rsp", previous_sp)
+ try:
+ unwind_info.add_saved_register("nosuchregister", previous_sp)
+ except ValueError:
+ global add_saved_register_error
+ add_saved_register_error = True
return unwind_info
except (gdb.error, RuntimeError):
return None