From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 129899 invoked by alias); 5 Feb 2016 16:35:53 -0000 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 Received: (qmail 129886 invoked by uid 89); 5 Feb 2016 16:35:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=it! X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 05 Feb 2016 16:35:51 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 200AEE1B72; Fri, 5 Feb 2016 16:35:50 +0000 (UTC) Received: from [10.36.112.51] (ovpn-112-51.ams2.redhat.com [10.36.112.51]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u15GZmqF031517; Fri, 5 Feb 2016 11:35:49 -0500 Subject: Re: [PATCH 4/7] py-symbol: Require a frame for lookup_symbol only when necessary To: jeffm@suse.com, gdb-patches@sourceware.org References: <1454606973-31017-1-git-send-email-jeffm@suse.com> <1454606973-31017-5-git-send-email-jeffm@suse.com> From: Phil Muldoon Message-ID: <56B4CF64.50007@redhat.com> Date: Fri, 05 Feb 2016 16:35:00 -0000 MIME-Version: 1.0 In-Reply-To: <1454606973-31017-5-git-send-email-jeffm@suse.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2016-02/txt/msg00153.txt.bz2 On 04/02/16 17:29, jeffm@suse.com wrote: > From: Jeff Mahoney > > gdbpy_lookup_symbol requires a frame prior to doing the symbol lookup but > a frame isn't necessary for many symbol types. Calling > symbol_read_needs_frame will tell us if it's necessary but we need to > have already looked up the symbol to use it. This patch puts the > lookup first and then only resolves the frame if one is required. > > This allows us to lookup static symbols directly from python rather > than using gdb.eval_and_parse. Thanks. I've rewritten this patch email reply from the garbled so hopefully you can make sense of it! ;) All of these patches need documentation in the user manual, and also new tests for functionality. > --- > gdb/python/py-symbol.c | 31 +++++++++++++++++-------------- > 1 file changed, 17 insertions(+), 14 deletions(-) > > diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c > index cbbc9e2..c7f0ff8 100644 > --- a/gdb/python/py-symbol.c > +++ b/gdb/python/py-symbol.c > @@ -382,14 +382,28 @@ gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw) > > if (block_obj) > block = block_object_to_block (block_obj); > - else > + > + TRY > + { > + symbol = lookup_symbol (name, block, (domain_enum) domain, > + &is_a_field_of_this).symbol; > + } > + CATCH (except, RETURN_MASK_ALL) > + { > + GDB_PY_HANDLE_EXCEPTION (except); > + } > + END_CATCH > + > + if (symbol && !block) > { > struct frame_info *selected_frame; > > TRY > { > - selected_frame = get_selected_frame (_("No frame selected.")); > - block = get_frame_block (selected_frame, NULL); > + if (symbol_read_needs_frame(symbol)) { Space after the function name and before the (. This and others. > + selected_frame = get_selected_frame (_("No frame selected.")); > + block = get_frame_block (selected_frame, NULL); > + } > } > CATCH (except, RETURN_MASK_ALL) > { > @@ -398,17 +412,6 @@ gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw) > END_CATCH > } > > - TRY > - { > - symbol = lookup_symbol (name, block, (domain_enum) domain, > - &is_a_field_of_this).symbol; > - } > - CATCH (except, RETURN_MASK_ALL) > - { > - GDB_PY_HANDLE_EXCEPTION (except); > - } > - END_CATCH > - > ret_tuple = PyTuple_New (2); > if (!ret_tuple) > return NULL; My only concern here is (and the context is not meaningful enough to see), is that you've removed an "else" above which is an unconditional branch, and replaced it with an IF instead. What happens when both IFs can fail? Cheers Phil