if (!gdbpy_parse_register_id (get_frame_arch (frame), pyo_reg_id,
®num))
- {
- PyErr_SetString (PyExc_ValueError, "Bad register");
- return NULL;
- }
+ return nullptr;
gdb_assert (regnum >= 0);
val = value_of_register (regnum, frame);
{
*reg_num = user_reg_map_name_to_regnum (gdbarch, reg_name.get (),
strlen (reg_name.get ()));
- return *reg_num >= 0;
+ if (*reg_num >= 0)
+ return true;
+ PyErr_SetString (PyExc_ValueError, "Bad register");
}
}
/* The register could be its internal GDB register number. */
else if (PyLong_Check (pyo_reg_id))
{
long value;
- if (gdb_py_int_as_long (pyo_reg_id, &value) && (int) value == value)
+ if (gdb_py_int_as_long (pyo_reg_id, &value) == 0)
{
- if (user_reg_map_regnum_to_name (gdbarch, value) != NULL)
- {
- *reg_num = (int) value;
- return true;
- }
+ /* Nothing -- error. */
}
+ else if ((int) value == value
+ && user_reg_map_regnum_to_name (gdbarch, value) != NULL)
+ {
+ *reg_num = (int) value;
+ return true;
+ }
+ else
+ PyErr_SetString (PyExc_ValueError, "Bad register");
}
/* The register could be a gdb.RegisterDescriptor object. */
else if (PyObject_IsInstance (pyo_reg_id,
PyErr_SetString (PyExc_ValueError,
_("Invalid Architecture in RegisterDescriptor"));
}
+ else
+ PyErr_SetString (PyExc_TypeError, _("Invalid type for register"));
gdb_assert (PyErr_Occurred ());
return false;
&pyo_reg_id, &pyo_reg_value))
return NULL;
if (!gdbpy_parse_register_id (pending_frame->gdbarch, pyo_reg_id, ®num))
- {
- 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
if (!PyArg_UnpackTuple (args, "read_register", 1, 1, &pyo_reg_id))
return NULL;
if (!gdbpy_parse_register_id (pending_frame->gdbarch, pyo_reg_id, ®num))
- {
- PyErr_SetString (PyExc_ValueError, "Bad register");
- return NULL;
- }
+ return nullptr;
try
{
If a register is parsed successfully then *REG_NUM will have been
updated, and true is returned. Otherwise the contents of *REG_NUM are
- undefined, and false is returned.
+ undefined, and false is returned. When false is returned, the
+ Python error is set.
The PYO_REG_ID object can be a string, the name of the register. This
is the slowest approach as GDB has to map the name to a number for each
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"
# 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"
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
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),
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