Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Siva Chandra <sivachandra@google.com>
To: gdb-patches@sourceware.org
Cc: Phil Muldoon <pmuldoon@redhat.com>
Subject: [RFC] New method gdb.Frame.arch_name which return's the name of frame's architecture
Date: Fri, 11 Jan 2013 14:56:00 -0000	[thread overview]
Message-ID: <CAGyQ6gw4zq4NQhKQ+-Gzuma+=sLTvnuzi5J5tVnKTdHJMZX=NA@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 933 bytes --]

Hello,

Attached is a patch which adds a new method 'arch_name' to the class
gdb.Frame. This new method returns the name of the frame's
architecture as a string value.

Phil Muldoon (copied in this mail) asked sometime back whether I
intend to expose frame's architecture as an object by itself. All I
want for now is a way to get the name  of the frame's architecture.

Changelog:
2013-01-11  Siva Chandra Reddy  <sivachandra@google.com>

        New method gdb.Frame.arch_name() which returns the name of
        frame's architecture.

        * NEWS: Add entry about the new method.
        * python/py-frame.c (frapy_arch_name): Implementation of
        gdb.Frame.arch_name.
        (frame_object_methods): Add method table entry for the new
        method.

doc/

        * gdb.texinfo: Add description of the new method.

testsuite/

        * gdb.python/py-frame.exp: Add a test to test the new method.

Thanks,
Siva Chandra

[-- Attachment #2: frame_arch_name_patch.txt --]
[-- Type: text/plain, Size: 3284 bytes --]

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.

             reply	other threads:[~2013-01-11 14:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-11 14:56 Siva Chandra [this message]
2013-01-11 15:43 ` Eli Zaretskii
2013-01-14 21:44 ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAGyQ6gw4zq4NQhKQ+-Gzuma+=sLTvnuzi5J5tVnKTdHJMZX=NA@mail.gmail.com' \
    --to=sivachandra@google.com \
    --cc=gdb-patches@sourceware.org \
    --cc=pmuldoon@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox