This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
[python][rfc] Replace gdb.Frame.addr_in_block withgdb.Frame.function.
- From: Thiago Jung Bauermann <bauerman at br dot ibm dot com>
- To: archer ml <archer at sourceware dot org>
- Date: Mon, 16 Mar 2009 00:04:02 -0300
- Subject: [python][rfc] Replace gdb.Frame.addr_in_block withgdb.Frame.function.
Hi folks,
When posting upstream the patch for the Frames in Python API, this
thought about gdb.Frame.addr_in_block came up:
> The only use I have for this function right now is to obtain an address
> to pass to the function gdb.find_pc_function, which returns a gdb.Symbol
> object for the function containing the given address.
>
> This usage directly reflects the way things are done in the GDB
> internals. Perhaps I should depart from it, remove gdb.find_pc_function
> and gdb.Frame.address_in_block and directly provide a gdb.Frame.function
> method which returns the gdb.Symbol object for the function
> corresponding to the frame?
This patch implements what's described in the last sentence above. WDYT?
I'm posting as RFC because this patch changes the current Python API.
--
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center
gdb/
* python/lib/gdb/command/backtrace.py: Use gdb.Frame.function
instead of gdb.Frame.addr_in_block and gdb.find_pc_function.
* python/python-frame.c (frapy_addr_in_block): Remove.
(frapy_function): New function.
(frame_object_methods): Remove entry for `addr_in_block'.
Add entry for `function'.
* python/python.c (gdbpy_find_pc_function): Remove.
(GdbMethods): Remove entry for `find_pc_function'.
gdb/testsuite/
* gdb.python/python-frame.exp: Remove test for
gdb.Frame.addr_in_block. Add test for gdb.function.
gdb/doc/
* gdb.texinfo (Frames In Python): Remove documentation of
Frame.addr_in_block. Add documentation for Frame.function.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 382f0c1..bdd175e 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -19537,8 +19537,8 @@ Returns the frame's resume address.
Returns the frame's code block. @c (@pxref{Block,,Code Blocks and Scopes}).
@end defmethod
-@defmethod Frame address_in_block
-Returns an address which falls within the frame's code block.
+@defmethod Frame function
+Returns the symbol for the function corresponding to this frame. @c (@pxref{Symbols In Python}).
@end defmethod
@defmethod Frame older
diff --git a/gdb/python/lib/gdb/command/backtrace.py b/gdb/python/lib/gdb/command/backtrace.py
index f07696e..17b1c18 100644
--- a/gdb/python/lib/gdb/command/backtrace.py
+++ b/gdb/python/lib/gdb/command/backtrace.py
@@ -92,7 +92,7 @@ class FrameWrapper:
stream.write (" 0x%08x in" % pc)
stream.write (" " + name + " (")
- func = gdb.find_pc_function (self.frame.addr_in_block ())
+ func = self.frame.function ()
self.print_frame_args (stream, func)
stream.write (")")
diff --git a/gdb/python/python-frame.c b/gdb/python/python-frame.c
index dc3f45e..a2626e4 100644
--- a/gdb/python/python-frame.c
+++ b/gdb/python/python-frame.c
@@ -253,13 +253,13 @@ frapy_block (PyObject *self, PyObject *args)
}
-/* Implementation of gdb.Frame.addr_in_block (self) -> Long.
- Returns an address which falls within the frame's code block. */
+/* Implementation of gdb.Frame.function (self) -> gdb.Symbol.
+ Returns the symbol for the function corresponding to this frame. */
static PyObject *
-frapy_addr_in_block (PyObject *self, PyObject *args)
+frapy_function (PyObject *self, PyObject *args)
{
- CORE_ADDR pc = 0; /* Initialize to appease gcc warning. */
+ struct symbol *sym = NULL;
struct frame_info *frame;
volatile struct gdb_exception except;
@@ -267,11 +267,14 @@ frapy_addr_in_block (PyObject *self, PyObject *args)
{
FRAPY_REQUIRE_VALID ((frame_object *) self, frame);
- pc = get_frame_address_in_block (frame);
+ sym = find_pc_function (get_frame_address_in_block (frame));
}
GDB_PY_HANDLE_EXCEPTION (except);
- return PyLong_FromUnsignedLongLong (pc);
+ if (sym)
+ return symbol_to_symbol_object (sym);
+
+ Py_RETURN_NONE;
}
/* Convert a frame_info struct to a Python Frame object.
@@ -634,9 +637,9 @@ Return the frame's resume address." },
{ "block", frapy_block, METH_NOARGS,
"block () -> gdb.Block.\n\
Return the frame's code block." },
- { "addr_in_block", frapy_addr_in_block, METH_NOARGS,
- "addr_in_block () -> Long.\n\
-Return an address which falls within the frame's code block." },
+ { "function", frapy_function, METH_NOARGS,
+ "function () -> gdb.Symbol.\n\
+Returns the symbol for the function corresponding to this frame." },
{ "older", frapy_older, METH_NOARGS,
"older () -> gdb.Frame.\n\
Return the frame immediately older (outer) to this frame." },
diff --git a/gdb/python/python.c b/gdb/python/python.c
index c15e718..c94a252 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -312,23 +312,6 @@ gdbpy_solib_address (PyObject *self, PyObject *args)
return str_obj;
}
-static PyObject *
-gdbpy_find_pc_function (PyObject *self, PyObject *args)
-{
- unsigned long long pc;
- struct symbol *sym;
- PyObject *sym_obj;
-
- if (!PyArg_ParseTuple (args, "K", &pc))
- return NULL;
-
- sym = find_pc_function (pc);
- if (sym)
- return symbol_to_symbol_object (sym);
-
- Py_RETURN_NONE;
-}
-
/* Adds GDB value V to the pattern buffer in *PATTERN_BUF. If SIZE is not zero,
it specifies the number of bytes from V to copy to *PATTERN_BUF. The
function increases the size of *PATTERN_BUF as necessary, adjusting
@@ -1897,9 +1880,6 @@ a boolean indicating if name is a field of the current implied argument\n\
"solib_address (Long) -> String.\n\
Return the name of the shared library holding a given address, or None." },
- { "find_pc_function", gdbpy_find_pc_function, METH_VARARGS,
- "Return the function containing the given pc value, or None." },
-
{ "block_for_pc", gdbpy_block_for_pc, METH_VARARGS,
"Return the block containing the given pc value, or None." },
diff --git a/gdb/testsuite/gdb.python/python-frame.exp b/gdb/testsuite/gdb.python/python-frame.exp
index 674c25e..93a3d21 100644
--- a/gdb/testsuite/gdb.python/python-frame.exp
+++ b/gdb/testsuite/gdb.python/python-frame.exp
@@ -78,7 +78,7 @@ gdb_test "python print 'result =', f0.type () == gdb.NORMAL_FRAME" " = True" "te
gdb_test "python print 'result =', f0.unwind_stop_reason () == gdb.FRAME_UNWIND_NO_REASON" " = True" "test Frame.type"
gdb_test "python print 'result =', gdb.frame_stop_reason_string (gdb.FRAME_UNWIND_INNER_ID)" " = previous frame inner to this frame \\(corrupt stack\\?\\)" "test gdb.frame_stop_reason_string"
gdb_test "python print 'result =', f0.pc ()" " = \[0-9\]+" "test Frame.pc"
-gdb_test "python print 'result =', f0.addr_in_block ()" " = \[0-9\]+" "test Frame.addr_in_block"
+gdb_test "python print 'result =', f0.function ()" " = symbol for f2" "test Frame.function"
gdb_test "python print 'result =', f0.older ().equals (f1)" " = True" "test Frame.older"
gdb_test "python print 'result =', f1.newer ().equals (f0)" " = True" "test Frame.newer"
gdb_test "python print 'result =', f0.read_var ('variable_which_surely_doesnt_exist')" \