diff options
author | Andrew Burgess <aburgess@redhat.com> | 2022-09-01 14:01:11 +0100 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2022-10-02 14:21:24 +0100 |
commit | 7df4240040277fb752fd010f5a947cf2d32bc3a5 (patch) | |
tree | a32440970f906c64b01f1d547a583250b0dcb76c /gdb/gdbarch.c | |
parent | 9a103324fee16bf4d0bc4fa7b19f5d937d47b881 (diff) | |
download | gdb-7df4240040277fb752fd010f5a947cf2d32bc3a5.zip gdb-7df4240040277fb752fd010f5a947cf2d32bc3a5.tar.gz gdb-7df4240040277fb752fd010f5a947cf2d32bc3a5.tar.bz2 |
gdb: add asserts to gdbarch_register_name
This commit adds asserts to gdbarch_register_name that validate the
parameters, and the return value.
The interesting thing here is that gdbarch_register_name is generated
by gdbarch.py, and so, to add these asserts, I need to update the
generation script.
I've added two new arguments for Functions and Methods (as declared in
gdbarch-components.py), these arguments are 'param_checks' and
'result_checks'. Each of these new arguments can be used to list some
expressions that are then used within gdb_assert calls in the
generated code.
The asserts that validate the API as described in the comment I added
to gdbarch_register_name a few commits back; the register number
passed in needs to be a valid cooked register number, and the result
being returned should not be nullptr.
Diffstat (limited to 'gdb/gdbarch.c')
-rw-r--r-- | gdb/gdbarch.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c index be73d39..4b0c10b 100644 --- a/gdb/gdbarch.c +++ b/gdb/gdbarch.c @@ -2235,9 +2235,13 @@ gdbarch_register_name (struct gdbarch *gdbarch, int regnr) { gdb_assert (gdbarch != NULL); gdb_assert (gdbarch->register_name != NULL); + gdb_assert (regnr >= 0); + gdb_assert (regnr < gdbarch_num_cooked_regs (gdbarch)); if (gdbarch_debug >= 2) gdb_printf (gdb_stdlog, "gdbarch_register_name called\n"); - return gdbarch->register_name (gdbarch, regnr); + auto result = gdbarch->register_name (gdbarch, regnr); + gdb_assert (result != nullptr); + return result; } void |