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.
This commit is contained in:
Tom Tromey 2022-04-27 15:22:56 -06:00
parent 12f26cb22e
commit bdc8cfc1e4
7 changed files with 48 additions and 20 deletions

View file

@ -253,10 +253,7 @@ frapy_read_register (PyObject *self, PyObject *args)
if (!gdbpy_parse_register_id (get_frame_arch (frame), pyo_reg_id,
&regnum))
{
PyErr_SetString (PyExc_ValueError, "Bad register");
return NULL;
}
return nullptr;
gdb_assert (regnum >= 0);
val = value_of_register (regnum, frame);