From d8e227793f4a8ce420f2b4a068844b5b6ec39490 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 6 Jan 2011 21:10:53 +0000 Subject: [PATCH] gdb PR python/12367: * NEWS: Add item. * python/python.c (GdbMethods): Add "newest_frame" method. * python/python-internal.h (gdbpy_newest_frame): Declare. * python/py-frame.c (gdbpy_newest_frame): New function. gdb/doc * gdb.texinfo (Frames In Python): Document gdb.newest_thread. gdb/testsuite * gdb.python/py-frame.exp: Test gdb.newest_frame. --- gdb/ChangeLog | 8 ++++++++ gdb/NEWS | 3 +++ gdb/doc/ChangeLog | 4 ++++ gdb/doc/gdb.texinfo | 5 +++++ gdb/python/py-frame.c | 20 ++++++++++++++++++++ gdb/python/python-internal.h | 1 + gdb/python/python.c | 3 +++ gdb/testsuite/ChangeLog | 4 ++++ gdb/testsuite/gdb.python/py-frame.exp | 7 +++++++ 9 files changed, 55 insertions(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index bed9bce8450..b1edadfc5d5 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2011-01-06 Tom Tromey + + PR python/12367: + * NEWS: Add item. + * python/python.c (GdbMethods): Add "newest_frame" method. + * python/python-internal.h (gdbpy_newest_frame): Declare. + * python/py-frame.c (gdbpy_newest_frame): New function. + 2010-01-06 Paul Pluzhnikov * jit.h (struct jit_code_entry): use ULONGEST for symfile_size. diff --git a/gdb/NEWS b/gdb/NEWS index 7c2b49469f0..1f02dfc051e 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -43,6 +43,9 @@ ** gdb.parameter("directories") is now available. + ** New function gdb.newest_frame returns the newest frame in the + selected thread. + * C++ Improvements: ** GDB now puts template parameters in scope when debugging in an diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog index 992476888c3..8835a3155b8 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,7 @@ +2011-01-06 Tom Tromey + + * gdb.texinfo (Frames In Python): Document gdb.newest_thread. + 2010-01-06 Paul Pluzhnikov * gdb.texinfo (Debugging Output): Document "set debug jit". diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index a16cf8359ed..d47a48443f1 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -22519,6 +22519,11 @@ The following frame-related functions are available in the @code{gdb} module: Return the selected frame object. (@pxref{Selection,,Selecting a Frame}). @end defun +@findex gdb.newest_frame +@defun newest_frame +Return the newest frame object for the selected thread. +@end defun + @defun frame_stop_reason_string reason Return a string explaining the reason why @value{GDBN} stopped unwinding frames, as expressed by the given @var{reason} code (an integer, see the diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c index 3e11db1a85c..a52c8c7ca79 100644 --- a/gdb/python/py-frame.c +++ b/gdb/python/py-frame.c @@ -498,6 +498,26 @@ frapy_select (PyObject *self, PyObject *args) Py_RETURN_NONE; } +/* Implementation of gdb.newest_frame () -> gdb.Frame. + Returns the newest frame object. */ + +PyObject * +gdbpy_newest_frame (PyObject *self, PyObject *args) +{ + struct frame_info *frame; + PyObject *frame_obj = NULL; /* Initialize to appease gcc warning. */ + volatile struct gdb_exception except; + + TRY_CATCH (except, RETURN_MASK_ALL) + { + frame = get_current_frame (); + frame_obj = frame_info_to_frame_object (frame); + } + GDB_PY_HANDLE_EXCEPTION (except); + + return frame_obj; +} + /* Implementation of gdb.selected_frame () -> gdb.Frame. Returns the selected frame object. */ diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index c9630c32da2..80d0763454e 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -110,6 +110,7 @@ PyObject *gdbpy_history (PyObject *self, PyObject *args); PyObject *gdbpy_breakpoints (PyObject *, PyObject *); PyObject *gdbpy_frame_stop_reason_string (PyObject *, PyObject *); PyObject *gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw); +PyObject *gdbpy_newest_frame (PyObject *self, PyObject *args); PyObject *gdbpy_selected_frame (PyObject *self, PyObject *args); PyObject *gdbpy_block_for_pc (PyObject *self, PyObject *args); PyObject *gdbpy_lookup_type (PyObject *self, PyObject *args, PyObject *kw); diff --git a/gdb/python/python.c b/gdb/python/python.c index 770744e98f4..375042c57d9 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -1121,6 +1121,9 @@ static PyMethodDef GdbMethods[] = { "objfiles", gdbpy_objfiles, METH_NOARGS, "Return a sequence of all loaded objfiles." }, + { "newest_frame", gdbpy_newest_frame, METH_NOARGS, + "newest_frame () -> gdb.Frame.\n\ +Return the newest frame object." }, { "selected_frame", gdbpy_selected_frame, METH_NOARGS, "selected_frame () -> gdb.Frame.\n\ Return the selected frame object." }, diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 3675e27dfed..7ba15acad79 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2011-01-06 Tom Tromey + + * gdb.python/py-frame.exp: Test gdb.newest_frame. + 2011-01-06 Joel Brobecker * gdb.ada/array_bounds.exp, gdb.ada/array_return.exp, diff --git a/gdb/testsuite/gdb.python/py-frame.exp b/gdb/testsuite/gdb.python/py-frame.exp index 095639811d0..e3b56292f10 100644 --- a/gdb/testsuite/gdb.python/py-frame.exp +++ b/gdb/testsuite/gdb.python/py-frame.exp @@ -73,11 +73,18 @@ gdb_test "python print bf1.read_var(\"i\", sb).type" "int" "test int i" gdb_breakpoint "f2" gdb_continue_to_breakpoint "breakpoint at f2" +gdb_py_test_silent_cmd "python bframe = gdb.selected_frame()" \ + "get bottommost frame" 0 gdb_test "up" ".*" "" gdb_py_test_silent_cmd "python f1 = gdb.selected_frame ()" "get second frame" 0 gdb_py_test_silent_cmd "python f0 = f1.newer ()" "get first frame" 0 +gdb_test "python print f1 == gdb.newest_frame()" False \ + "selected frame -vs- newest frame" +gdb_test "python print bframe == gdb.newest_frame()" True \ + "newest frame -vs- newest frame" + gdb_test "python print 'result =', f0 == f1" " = False" "test equality comparison (false)" gdb_test "python print 'result =', f0 == f0" " = True" "test equality comparison (true)" gdb_test "python print 'result =', f0 != f1" " = True" "test inequality comparison (true)" -- 2.30.2