diff options
author | Andrew Burgess <aburgess@redhat.com> | 2023-03-14 11:22:35 +0000 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2023-04-06 14:57:32 +0100 |
commit | d2d62da62ec9c5486b19d8ffc7b4ef4070e8df7a (patch) | |
tree | 2186c1226037e7937600edd7c01b19c5592ea50d /gdb/testsuite | |
parent | cf141dd8ccd36efe833aae3ccdb060b517cc1112 (diff) | |
download | gdb-d2d62da62ec9c5486b19d8ffc7b4ef4070e8df7a.zip gdb-d2d62da62ec9c5486b19d8ffc7b4ef4070e8df7a.tar.gz gdb-d2d62da62ec9c5486b19d8ffc7b4ef4070e8df7a.tar.bz2 |
gdb/python: have UnwindInfo.add_saved_register accept named args
Update gdb.UnwindInfo.add_saved_register to accept named keyword
arguments.
As part of this update we now use gdb_PyArg_ParseTupleAndKeywords
instead of PyArg_UnpackTuple to parse the function arguments.
By switching to gdb_PyArg_ParseTupleAndKeywords, we can now use 'O!'
as the argument format for the function's value argument. This means
that we can check the argument type (is gdb.Value) as part of the
argument processing rather than manually performing the check later in
the function. One result of this is that we now get a better error
message (at least, I think so). Previously we would get something
like:
ValueError: Bad register value
Now we get:
TypeError: argument 2 must be gdb.Value, not XXXX
It's unfortunate that the exception type changed, but I think the new
exception type actually makes more sense.
My preference for argument names is to use full words where that's not
too excessive. As such, I've updated the name of the argument from
'reg' to 'register' in the documentation, which is the argument name
I've made GDB look for here.
For existing unwinder code that doesn't throw any exceptions nothing
should change with this commit. It is possible that a user has some
code that throws and catches the ValueError, and this code will break
after this commit, but I think this is going to be sufficiently rare
that we can take the risk here.
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Reviewed-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/testsuite')
-rw-r--r-- | gdb/testsuite/gdb.python/py-unwind.exp | 15 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/py-unwind.py | 28 |
2 files changed, 31 insertions, 12 deletions
diff --git a/gdb/testsuite/gdb.python/py-unwind.exp b/gdb/testsuite/gdb.python/py-unwind.exp index d0a1960..e7c4c23 100644 --- a/gdb/testsuite/gdb.python/py-unwind.exp +++ b/gdb/testsuite/gdb.python/py-unwind.exp @@ -131,10 +131,17 @@ gdb_test "disable unwinder global \"test unwinder\"" \ check_for_broken_backtrace "stack is broken after command disabling" check_info_unwinder "info unwinder after command disabling" off -# 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" \ +# Check that invalid register names and values cause errors. +gdb_test "python print(add_saved_register_errors\[\"unknown_name\"\])" \ + "Bad register" \ + "add_saved_register error when an unknown register name is used" +gdb_test "python print(add_saved_register_errors\[\"unknown_number\"\])" \ + "Bad register" \ + "add_saved_register error when an unknown register number is used" +gdb_test "python print(add_saved_register_errors\[\"bad_value\"\])" \ + "argument 2 must be gdb.Value, not int" \ + "add_saved_register error when invalid register value is used" +gdb_test "python print(read_register_error)" "Bad register" \ "read_register error" # Try to create an unwinder object with a non-string name. diff --git a/gdb/testsuite/gdb.python/py-unwind.py b/gdb/testsuite/gdb.python/py-unwind.py index 4e110c5..5853abc 100644 --- a/gdb/testsuite/gdb.python/py-unwind.py +++ b/gdb/testsuite/gdb.python/py-unwind.py @@ -18,7 +18,7 @@ from gdb.unwinder import Unwinder, FrameId # These are set to test whether invalid register names cause an error. -add_saved_register_error = False +add_saved_register_errors = {} read_register_error = False @@ -94,9 +94,9 @@ class TestUnwinder(Unwinder): try: pending_frame.read_register("nosuchregister") - except ValueError: + except ValueError as ve: global read_register_error - read_register_error = True + read_register_error = str(ve) frame_id = FrameId( pending_frame.read_register(TestUnwinder.AMD64_RSP), @@ -104,13 +104,25 @@ class TestUnwinder(Unwinder): ) unwind_info = pending_frame.create_unwind_info(frame_id) 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) + unwind_info.add_saved_register(value=previous_ip, register="rip") + unwind_info.add_saved_register(register="rsp", value=previous_sp) + + global add_saved_register_errors try: unwind_info.add_saved_register("nosuchregister", previous_sp) - except ValueError: - global add_saved_register_error - add_saved_register_error = True + except ValueError as ve: + add_saved_register_errors["unknown_name"] = str(ve) + + try: + unwind_info.add_saved_register(999, previous_sp) + except ValueError as ve: + add_saved_register_errors["unknown_number"] = str(ve) + + try: + unwind_info.add_saved_register("rsp", 1234) + except TypeError as ve: + add_saved_register_errors["bad_value"] = str(ve) + return unwind_info except (gdb.error, RuntimeError): return None |