From: Siva Chandra Reddy Date: Sun, 13 May 2012 11:33:44 +0000 (+0000) Subject: 2012-05-13 Siva Chandra Reddy X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7efc75aaf903ab9bf93b8411260740d5a5ee6056;p=binutils-gdb.git 2012-05-13 Siva Chandra Reddy 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. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 3746f921cfe..46e3b9c048e 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2012-05-13 Siva Chandra Reddy + + 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. + 2012-05-12 Pedro Alves * amd64-linux-tdep.c (_initialize_amd64_linux_tdep): Call diff --git a/gdb/NEWS b/gdb/NEWS index f89359322f1..dd1ab24043c 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -53,6 +53,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. diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog index 4d23eb0adb4..8eef5882607 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,8 @@ +2012-05-13 Siva Chandra Reddy + + * gdb.texinfo (Basic Python): Add description about the function + gdb.find_pc_line + 2012-05-12 Jan Kratochvil Eli Zaretskii diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 86f1dd340f0..a5c6879e2a1 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -22508,6 +22508,15 @@ compute values, for example, it is the only way to get the value of a 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 diff --git a/gdb/python/python.c b/gdb/python/python.c index 938275a5bb0..5e5f980de63 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -631,6 +631,24 @@ gdbpy_parse_and_eval (PyObject *self, PyObject *args) 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." }, diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index b66ef43f57f..b6a209252be 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2012-05-13 Siva Chandra Reddy + + * gdb.python/python.c: Add a new breakpoint comment. + * gdb.python/python.exp: Add tests to test gdb.find_pc_line. + 2011-12-26 Kwok Cheung Yeung * gdb.base/info-os.exp: New file. diff --git a/gdb/testsuite/gdb.python/python.c b/gdb/testsuite/gdb.python/python.c index d9f02cda658..50bee21a39f 100644 --- a/gdb/testsuite/gdb.python/python.c +++ b/gdb/testsuite/gdb.python/python.c @@ -23,6 +23,6 @@ int main (int argc, char *argv[]) { func1 (); - func2 (); + func2 (); /* Break at func2 call site. */ return 0; /* Break to end. */ } diff --git a/gdb/testsuite/gdb.python/python.exp b/gdb/testsuite/gdb.python/python.exp index 7333e26e136..ef0cdcf87a3 100644 --- a/gdb/testsuite/gdb.python/python.exp +++ b/gdb/testsuite/gdb.python/python.exp @@ -367,3 +367,23 @@ gdb_test_multiple "python gdb.prompt_hook = error_prompt" "set the hook" { 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"