+2013-08-30 Phil Muldoon <pmuldoon@redhat.com>
+
+ PR python/15461
+
+ * python/py-arch.c (ARCHPY_REQUIRE_VALID): New macro.
+ (archpy_name): Check for valid architecture.
+ (archpy_disassemble): Ditto.
+
2013-08-29 Joel Brobecker <brobecker@adacore.com>
* rs6000-nat.c (rs6000_ptrace32): Cast "addr" to "uintptr_t"
static struct gdbarch_data *arch_object_data = NULL;
+/* Require a valid Architecture. */
+#define ARCHPY_REQUIRE_VALID(arch_obj, arch) \
+ do { \
+ arch = arch_object_to_gdbarch (arch_obj); \
+ if (arch == NULL) \
+ { \
+ PyErr_SetString (PyExc_RuntimeError, \
+ _("Architecture is invalid.")); \
+ return NULL; \
+ } \
+ } while (0)
+
static PyTypeObject arch_object_type
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("arch_object");
static PyObject *
archpy_name (PyObject *self, PyObject *args)
{
- struct gdbarch *gdbarch = arch_object_to_gdbarch (self);
- const char *name = (gdbarch_bfd_arch_info (gdbarch))->printable_name;
- PyObject *py_name = PyString_FromString (name);
+ struct gdbarch *gdbarch = NULL;
+ const char *name;
+ PyObject *py_name;
+
+ ARCHPY_REQUIRE_VALID (self, gdbarch);
+
+ name = (gdbarch_bfd_arch_info (gdbarch))->printable_name;
+ py_name = PyString_FromString (name);
return py_name;
}
gdb_py_ulongest start_temp;
long count = 0, i;
PyObject *result_list, *end_obj = NULL, *count_obj = NULL;
- struct gdbarch *gdbarch = arch_object_to_gdbarch (self);
+ struct gdbarch *gdbarch = NULL;
+
+ ARCHPY_REQUIRE_VALID (self, gdbarch);
if (!PyArg_ParseTupleAndKeywords (args, kw, GDB_PY_LLU_ARG "|OO", keywords,
&start_temp, &end_obj, &count_obj))
return -1
}
+# Test python/15461. Invalid architectures should not trigger an
+# internal GDB assert.
+gdb_py_test_silent_cmd "python empty = gdb.Architecture()" "get empty arch" 0
+gdb_test "python print(empty.name())" ".*Architecture is invalid.*" \
+ "Test empty architecture.name does not trigger an assert"
+gdb_test "python print(empty.disassemble())" ".*Architecture is invalid.*" \
+ "Test empty architecture.disassemble does not trigger an assert"
+
gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "get frame" 0
gdb_py_test_silent_cmd "python arch = frame.architecture()" "get arch" 0
gdb_py_test_silent_cmd "python pc = frame.pc()" "get pc" 0