From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14062 invoked by alias); 6 Jan 2011 20:55:20 -0000 Received: (qmail 14054 invoked by uid 22791); 6 Jan 2011 20:55:19 -0000 X-SWARE-Spam-Status: No, hits=-6.9 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 06 Jan 2011 20:55:14 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id p06KtD1k016606 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 6 Jan 2011 15:55:13 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p06KtCx7015063; Thu, 6 Jan 2011 15:55:13 -0500 Received: from opsy.redhat.com (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p06KtCeK003791; Thu, 6 Jan 2011 15:55:12 -0500 Received: by opsy.redhat.com (Postfix, from userid 500) id 938D33784A7; Thu, 6 Jan 2011 13:55:11 -0700 (MST) From: Tom Tromey To: gdb-patches@sourceware.org Subject: RFA: add gdb.newest_frame method Date: Thu, 06 Jan 2011 20:55:00 -0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-01/txt/msg00143.txt.bz2 I needed a "newest_frame" method to go along with "selected_frame". This patch adds this method, documentation, and a test case. This needs a doc review. Built and regtested on x86-64 (compile farm). Ok? Tom 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. 2011-01-06 Tom Tromey * gdb.texinfo (Frames In Python): Document gdb.newest_thread. 2011-01-06 Tom Tromey * gdb.python/py-frame.exp: Test gdb.newest_frame. diff --git a/gdb/NEWS b/gdb/NEWS index 7c2b494..1f02dfc 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/gdb.texinfo b/gdb/doc/gdb.texinfo index f6a3747..6a27e9d 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -22514,6 +22514,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 3e11db1..a52c8c7 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 c9630c3..80d0763 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 770744e..375042c 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/gdb.python/py-frame.exp b/gdb/testsuite/gdb.python/py-frame.exp index 0956398..e3b5629 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)"