From: Tom Tromey Date: Sun, 7 Oct 2018 04:57:19 +0000 (-0600) Subject: Add Inferior.architecture method X-Git-Tag: users/ARM/embedded-binutils-master-2018q4~493 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=add5ded5e476918ef8b05823801531de2f51fa9c;p=external%2Fbinutils.git Add Inferior.architecture method I've written a couple of gdb unwinders in Python, and while doing so, I wanted to find the architecture of the inferior. (In an unwinder in particular, one can't use the frame's architecture, because there is no frame.) This patch adds Inferior.architecture to allow this. Normally I think I would have chosen an attribute and not a method here, but seeing that Frame.architecture is a method, I chose a method as well, for consistency. gdb/ChangeLog 2018-10-06 Tom Tromey PR python/19399: * python/py-inferior.c: Add "architecture" entry. (infpy_architecture): New function. gdb/doc/ChangeLog 2018-10-06 Tom Tromey PR python/19399: * python.texi (Inferiors In Python): Document Inferior.Architecture. gdb/testsuite/ChangeLog 2018-10-06 Tom Tromey PR python/19399: * gdb.python/py-inferior.exp: Add architecture test. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index aac1c6d..d896bf4 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,11 @@ 2018-10-06 Tom Tromey + PR python/19399: + * python/py-inferior.c: Add "architecture" entry. + (infpy_architecture): New function. + +2018-10-06 Tom Tromey + PR python/21765: * python/py-symbol.c (gdbpy_initialize_symbols): Redefine SYMBOL_VARIABLES_DOMAIN, SYMBOL_FUNCTIONS_DOMAIN, diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog index 2e28949..acf68ce 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,5 +1,11 @@ 2018-10-06 Tom Tromey + PR python/19399: + * python.texi (Inferiors In Python): Document + Inferior.Architecture. + +2018-10-06 Tom Tromey + PR python/21765: * python.texi (Symbols In Python): Document the module and common-block domains. Remove documentation for incorrect diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 0a8f7a1..dc53cfa 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -2860,6 +2860,13 @@ when it is called. If there are no valid threads, the method will return an empty tuple. @end defun +@defun Inferior.architecture () +Return the @code{gdb.Architecture} (@pxref{Architectures In Python}) +for this inferior. This represents the architecture of the inferior +as a whole. Some platforms can have multiple architectures in a +single address space, so this may not match the architecture of a +particular frame (@pxref{Frames in Python}). + @findex Inferior.read_memory @defun Inferior.read_memory (address, length) Read @var{length} addressable memory units from the inferior, starting at diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c index 5bba676..e987cfe 100644 --- a/gdb/python/py-inferior.c +++ b/gdb/python/py-inferior.c @@ -855,6 +855,18 @@ infpy_thread_from_thread_handle (PyObject *self, PyObject *args, PyObject *kw) Py_RETURN_NONE; } +/* Implementation of gdb.Inferior.architecture. */ + +static PyObject * +infpy_architecture (PyObject *self, PyObject *args) +{ + inferior_object *inf = (inferior_object *) self; + + INFPY_REQUIRE_VALID (inf); + + return gdbarch_to_arch_object (inf->inferior->gdbarch); +} + /* Implement repr() for gdb.Inferior. */ static PyObject * @@ -988,6 +1000,9 @@ Return a long with the address of a match, or None." }, METH_VARARGS | METH_KEYWORDS, "thread_from_thread_handle (handle) -> gdb.InferiorThread.\n\ Return thread object corresponding to thread handle." }, + { "architecture", (PyCFunction) infpy_architecture, METH_NOARGS, + "architecture () -> gdb.Architecture\n\ +Return architecture of this inferior." }, { NULL } }; diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index f43936b..9473646 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,5 +1,10 @@ 2018-10-06 Tom Tromey + PR python/19399: + * gdb.python/py-inferior.exp: Add architecture test. + +2018-10-06 Tom Tromey + * gdb.base/gnu-ifunc.exp (build): Use standard_output_file. * gdb.trace/unavailable-dwarf-piece.exp: Use standard_output_file. diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp index 38f5257..7b1a01b 100644 --- a/gdb/testsuite/gdb.python/py-inferior.exp +++ b/gdb/testsuite/gdb.python/py-inferior.exp @@ -299,3 +299,11 @@ with_test_prefix "__repr__" { "\\\(, \\\)" \ "print all inferiors 2" } + +# Test architecture. +with_test_prefix "architecture" { + gdb_test "inferior 1" ".*" "switch to first inferior" + gdb_test "python print(gdb.selected_frame().architecture() is gdb.selected_inferior().architecture())" \ + "True" \ + "inferior architecture matches frame architecture" +}