aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorPhil Muldoon <pmuldoon@redhat.com>2013-08-30 10:12:19 +0000
committerPhil Muldoon <pmuldoon@redhat.com>2013-08-30 10:12:19 +0000
commit96d9056e29036d7d841e71f60648018f115d808e (patch)
tree06a57faccd1fc32c944c05e6eeeee02aafefb05f /gdb
parente2668a1a80552dc09c288886591f0be9ecbebd83 (diff)
downloadgdb-96d9056e29036d7d841e71f60648018f115d808e.zip
gdb-96d9056e29036d7d841e71f60648018f115d808e.tar.gz
gdb-96d9056e29036d7d841e71f60648018f115d808e.tar.bz2
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-30 Phil Muldoon <pmuldoon@redhat.com> * gdb.python/py-arch.exp: Tests for invalid architecture.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog8
-rw-r--r--gdb/python/py-arch.c27
-rw-r--r--gdb/testsuite/ChangeLog4
-rw-r--r--gdb/testsuite/gdb.python/py-arch.exp8
4 files changed, 43 insertions, 4 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index f676c3f..a03e72c 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,11 @@
+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"
diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c
index 7098a8a..a31ffdd 100644
--- a/gdb/python/py-arch.c
+++ b/gdb/python/py-arch.c
@@ -30,6 +30,18 @@ typedef struct arch_object_type_object {
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");
@@ -82,9 +94,14 @@ gdbarch_to_arch_object (struct gdbarch *gdbarch)
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;
}
@@ -104,7 +121,9 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)
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))
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 3b259c7..67dc813 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2013-08-30 Phil Muldoon <pmuldoon@redhat.com>
+
+ * gdb.python/py-arch.exp: Tests for invalid architecture.
+
2013-08-29 Sterling Augustine <saugustine@google.com>
* boards/remote-stdio-gdbserver.exp: Set rcp_prog and
diff --git a/gdb/testsuite/gdb.python/py-arch.exp b/gdb/testsuite/gdb.python/py-arch.exp
index 7413b44..174b151 100644
--- a/gdb/testsuite/gdb.python/py-arch.exp
+++ b/gdb/testsuite/gdb.python/py-arch.exp
@@ -26,6 +26,14 @@ if ![runto_main] {
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