diff --git a/gdb/NEWS b/gdb/NEWS index 36bbd12..ffe56f1 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -39,6 +39,9 @@ Lynx 178 PowerPC powerpc-*-lynx*178 ** Python 3 is now supported (in addition to Python 2.4 or later) + ** New method 'arch_name' added to gdb.Frame class which returns + the name of the frame's architecture. + * New Python-based convenience functions: ** $_memeq(buf1, buf2, length) diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index f973263..9d66588 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -25111,6 +25111,10 @@ newest frame. @end table @end defun +@defun Frame.arch_name () +Returns the name (string value) of the frame's architecture. +@end defun + @defun Frame.unwind_stop_reason () Return an integer representing the reason why it's not possible to find more frames toward the outermost frame. Use diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c index 4b025db..f1bade0 100644 --- a/gdb/python/py-frame.c +++ b/gdb/python/py-frame.c @@ -167,6 +167,30 @@ frapy_type (PyObject *self, PyObject *args) return PyInt_FromLong (type); } +/* Implementation of gdb.Frame.arch_name (self) -> String. + Returns the name of frame's architecture. */ + +static PyObject * +frapy_arch_name (PyObject *self, PyObject *args) +{ + struct frame_info *frame; + frame_object *obj = (frame_object *) self; + PyObject *py_str = NULL; + const char *arch_name; + volatile struct gdb_exception except; + + TRY_CATCH (except, RETURN_MASK_ALL) + { + FRAPY_REQUIRE_VALID (self, frame); + + arch_name = gdbarch_bfd_arch_info (obj->gdbarch)->printable_name; + py_str = PyString_FromString (arch_name); + } + GDB_PY_HANDLE_EXCEPTION (except); + + return py_str; +} + /* Implementation of gdb.Frame.unwind_stop_reason (self) -> Integer. Returns one of the gdb.FRAME_UNWIND_* constants. */ @@ -632,6 +656,9 @@ Return the function name of the frame, or None if it can't be determined." }, { "type", frapy_type, METH_NOARGS, "type () -> Integer.\n\ Return the type of the frame." }, + { "arch_name", frapy_arch_name, METH_NOARGS, + "arch_name () - > String.\n\ +Return the name of the frame's architecture." }, { "unwind_stop_reason", frapy_unwind_stop_reason, METH_NOARGS, "unwind_stop_reason () -> Integer.\n\ Return the reason why it's not possible to find frames older than this." }, diff --git a/gdb/testsuite/gdb.python/py-frame.exp b/gdb/testsuite/gdb.python/py-frame.exp index aa4d937..fcad68d 100644 --- a/gdb/testsuite/gdb.python/py-frame.exp +++ b/gdb/testsuite/gdb.python/py-frame.exp @@ -43,6 +43,10 @@ gdb_test "python print (bf1.read_var(\"i\"))" "\"stuff\"" "test i" gdb_test "python print (bf1.read_var(\"f\"))" "\"foo\"" "test f" gdb_test "python print (bf1.read_var(\"b\"))" "\"bar\"" "test b" +# Test Frame.arch_name() +gdb_py_test_silent_cmd "python show_arch = (gdb.execute(\"show architecture\", to_string=True))" "get arch name" 0 +gdb_test "python print bf1.arch_name() in show_arch" "True" "test Frame.arch_name()" + # Test the read_var function in another block other than the current # block (in this case, the super block). Test thar read_var is reading # the correct variables of i and f but they are the correct value and type.