Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Siva Chandra <sivachandra@google.com>
To: Doug Evans <dje@google.com>
Cc: Eli Zaretskii <eliz@gnu.org>, gdb-patches@sourceware.org
Subject: Re: [RFC] - Exposing find_pc_line through Python API
Date: Fri, 11 May 2012 16:35:00 -0000	[thread overview]
Message-ID: <CAGyQ6gxQ=LbL5MS-xX2x4ifmpxZQTj3Jh1NkjKocGVtza8H_WA@mail.gmail.com> (raw)
In-Reply-To: <CADPb22TvTO=1FEDPMORYUG8kOfvshf9jzW2g_ycN_QWNN7OhUg@mail.gmail.com>

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

On Fri, May 11, 2012 at 2:45 AM, Doug Evans <dje@google.com> wrote:
> I think we need to specify what the result is if there is no sal for
> the specified pc.
> ...
> "actual" can be deleted now.

I have addressed these two comments.  The patch is attached.

2012-05-11  Siva Chandra Reddy  <sivachandra@google.com>

        Add a new function gdb.find_pc_line to the Python API.
        * NEWS (Python Scripting): Add entry about the new function.
        * python/python.c (gdbpy_find_pc_line): New function which
        implements gdb.find_pc_line.
        (GdbMethods): Add entry for the new function.

        doc/
        * gdb.texinfo (Basic Python): Add description about the function
        gdb.find_pc_line

        testsuite/
        * gdb.python/python.c: Add a new breakpoint comment.
        * gdb.python/python.exp: Add tests to test gdb.find_pc_line.

Thanks,
Siva Chandra

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

Index: NEWS
===================================================================
RCS file: /cvs/src/src/gdb/NEWS,v
retrieving revision 1.514
diff -u -p -r1.514 NEWS
--- NEWS	3 May 2012 07:07:24 -0000	1.514
+++ NEWS	11 May 2012 16:29:52 -0000
@@ -43,6 +43,9 @@
      which return the global and static blocks (as gdb.Block objects),
      of the underlying symbol table, respectively.
 
+  ** New function gdb.find_pc_line which returns the gdb.Symtab_and_line
+     object associated with a PC value.
+
 * Go language support.
   GDB now supports debugging programs written in the Go programming
   language.
Index: doc/gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.957
diff -u -p -r1.957 gdb.texinfo
--- doc/gdb.texinfo	9 May 2012 19:29:25 -0000	1.957
+++ doc/gdb.texinfo	11 May 2012 16:30:15 -0000
@@ -22394,6 +22394,15 @@ compute values, for example, it is the o
 convenience variable (@pxref{Convenience Vars}) as a @code{gdb.Value}.
 @end defun
 
+@findex gdb.find_pc_line
+@defun gdb.find_pc_line (pc)
+Return the @code{gdb.Symtab_and_line} object corresponding to the
+@var{pc} value.  @xref{Symbol Tables In Python}.  If an invalid
+value of @var{pc} is passed as an argument, then the @code{symtab} and
+@code{line} attributes of the returned @code{gdb.Symtab_and_line} object
+will be @code{None} and 0 respectively.
+@end defun
+
 @findex gdb.post_event
 @defun gdb.post_event (event)
 Put @var{event}, a callable object taking no arguments, into
Index: python/python.c
===================================================================
RCS file: /cvs/src/src/gdb/python/python.c,v
retrieving revision 1.86
diff -u -p -r1.86 python.c
--- python/python.c	30 Mar 2012 20:05:55 -0000	1.86
+++ python/python.c	11 May 2012 16:30:16 -0000
@@ -631,6 +631,24 @@ gdbpy_parse_and_eval (PyObject *self, Py
   return value_to_value_object (result);
 }
 
+/* Implementation of gdb.find_pc_line function.
+   Returns the gdb.Symtab_and_line object corresponding to a PC value.  */
+
+static PyObject *
+gdbpy_find_pc_line (PyObject *self, PyObject *args)
+{
+  struct symtab_and_line sal;
+  CORE_ADDR pc;
+  unsigned long long pc_llu;
+
+  if (!PyArg_ParseTuple (args, GDB_PY_LLU_ARG, &pc_llu))
+    return NULL;
+
+  pc = (CORE_ADDR) pc_llu;
+  sal = find_pc_line (pc, 0);
+  return symtab_and_line_to_sal_object (sal);
+}
+
 /* Read a file as Python code.
    FILE is the file to run.  FILENAME is name of the file FILE.
    This does not throw any errors.  If an exception occurs python will print
@@ -1458,6 +1476,9 @@ gdb.Symtab_and_line objects (or None)."}
     "parse_and_eval (String) -> Value.\n\
 Parse String as an expression, evaluate it, and return the result as a Value."
   },
+  { "find_pc_line", gdbpy_find_pc_line, METH_VARARGS,
+    "find_pc_line (pc) -> Symtab_and_line.\n\
+Return the gdb.Symtab_and_line object corresponding to the pc value." },
 
   { "post_event", gdbpy_post_event, METH_VARARGS,
     "Post an event into gdb's event loop." },
Index: testsuite/gdb.python/python.c
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.python/python.c,v
retrieving revision 1.4
diff -u -p -r1.4 python.c
--- testsuite/gdb.python/python.c	4 Jan 2012 08:27:49 -0000	1.4
+++ testsuite/gdb.python/python.c	11 May 2012 16:30:19 -0000
@@ -23,6 +23,6 @@ int
 main (int argc, char *argv[])
 {
   func1 ();
-  func2 ();
+  func2 ();      /* Break at func2 call site.  */
   return 0;      /* Break to end.  */
 }
Index: testsuite/gdb.python/python.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.python/python.exp,v
retrieving revision 1.32
diff -u -p -r1.32 python.exp
--- testsuite/gdb.python/python.exp	30 Mar 2012 19:16:52 -0000	1.32
+++ testsuite/gdb.python/python.exp	11 May 2012 16:30:19 -0000
@@ -367,3 +367,23 @@ gdb_test_multiple "python gdb.prompt_hoo
 
 gdb_py_test_silent_cmd "python gdb.prompt_hook = None" \
     "set the hook to default" 1
+
+# Start with a fresh gdb.
+clean_restart ${testfile}
+
+# The following tests require execution.
+
+if ![runto_main] then {
+    fail "Can't run to main"
+    return 0
+}
+
+runto [gdb_get_line_number "Break at func2 call site."]
+
+gdb_py_test_silent_cmd "python line = gdb.selected_frame().find_sal().line" "Get line number of func2 call site" 1
+gdb_test "python print gdb.find_pc_line(gdb.selected_frame().pc()).line == line" "True" "Test find_pc_line at func2 call site"
+
+gdb_py_test_silent_cmd "step" "Step into func2" 1
+gdb_py_test_silent_cmd "up" "Step out of func2" 1
+
+gdb_test "python print gdb.find_pc_line(gdb.selected_frame().pc()).line > line" "True" "Test find_pc_line with resume address"

  reply	other threads:[~2012-05-11 16:35 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-07 18:11 Siva Chandra
2012-05-07 19:36 ` Eli Zaretskii
2012-05-08  2:35   ` Siva Chandra
2012-05-09  7:35   ` Siva Chandra
2012-05-09 20:05     ` Eli Zaretskii
2012-05-10 21:16     ` Doug Evans
2012-05-11 16:35       ` Siva Chandra [this message]
2012-05-11 18:14         ` Doug Evans
2012-05-13 11:37           ` Siva Chandra

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='CAGyQ6gxQ=LbL5MS-xX2x4ifmpxZQTj3Jh1NkjKocGVtza8H_WA@mail.gmail.com' \
    --to=sivachandra@google.com \
    --cc=dje@google.com \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    /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