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

@ -260,10 +260,7 @@ unwind_infopy_add_saved_register (PyObject *self, PyObject *args)
&pyo_reg_id, &pyo_reg_value))
return NULL;
if (!gdbpy_parse_register_id (pending_frame->gdbarch, pyo_reg_id, &regnum))
{
PyErr_SetString (PyExc_ValueError, "Bad register");
return NULL;
}
return nullptr;
/* If REGNUM identifies a user register then *maybe* we can convert this
to a real (i.e. non-user) register. The maybe qualifier is because we
@ -381,10 +378,7 @@ pending_framepy_read_register (PyObject *self, PyObject *args)
if (!PyArg_UnpackTuple (args, "read_register", 1, 1, &pyo_reg_id))
return NULL;
if (!gdbpy_parse_register_id (pending_frame->gdbarch, pyo_reg_id, &regnum))
{
PyErr_SetString (PyExc_ValueError, "Bad register");
return NULL;
}
return nullptr;
try
{