From patchwork Fri Aug 7 08:55:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 8081 Received: (qmail 25501 invoked by alias); 7 Aug 2015 08:56:10 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 25491 invoked by uid 89); 7 Aug 2015 08:56:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.1 required=5.0 tests=BAYES_50, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 X-HELO: mail-wi0-f171.google.com Received: from mail-wi0-f171.google.com (HELO mail-wi0-f171.google.com) (209.85.212.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Fri, 07 Aug 2015 08:56:07 +0000 Received: by wibxm9 with SMTP id xm9so56768281wib.1 for ; Fri, 07 Aug 2015 01:56:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=zTKbtbHyuo7DB4if/Ee5QUUmHBfvaD3iMFN/Ehce0aw=; b=Gt05ECGHlGjn+JKObMLhcffHea28l8kIyTkcUWIZ8syFOxuO6gpLCV2sSgD2aaYrmz R3VyBjpbO1/V14cFp/FqCSE3bLu3E59vN0MOSQbDuHb3PctYhNqQkQbds92VSQ5TDE3z +GqgvP5PVQIrMFUf0qqOEaKvP9zn/V8e+AxgheMpKClIRBns1dXFlFOJ10TLR9QXMe9J j95stAhn/blFuXv6Blrem3OTLFJ0qOavw+F0ATifpy0BzvcuAIsZyGZzuZJAsXjdM/t4 wLocVk0ixt2WtKZuoLXPNUWx8HMfmtWNFciA1UoWAHylBkpPrIbAjRYxOpSqTesjczTE F4Kw== X-Gm-Message-State: ALoCoQmYuwNLL658adu2O5cSokDI/31yxkxIBgWLiubTrrYFuB9L5V/Y4d1eFqCMa7snNuHlItZF X-Received: by 10.194.9.102 with SMTP id y6mr12527892wja.91.1438937764370; Fri, 07 Aug 2015 01:56:04 -0700 (PDT) Received: from localhost (vpn-konference.ms.mff.cuni.cz. [195.113.20.101]) by smtp.gmail.com with ESMTPSA id r8sm7451380wiz.5.2015.08.07.01.56.03 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Aug 2015 01:56:03 -0700 (PDT) Date: Fri, 7 Aug 2015 09:55:57 +0100 From: Andrew Burgess To: Pedro Alves Cc: gdb-patches@sourceware.org Subject: Re: [PATCH 1/2] gdb: get_frame_language now takes a frame parameter. Message-ID: <20150807085557.GA30204@embecosm.com> References: <27becf0497c6090b676523ee45069d3e5e6afa17.1438699523.git.andrew.burgess@embecosm.com> <55C0E222.1030006@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <55C0E222.1030006@redhat.com> X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes * Pedro Alves [2015-08-04 17:02:42 +0100]: > On 08/04/2015 04:40 PM, Andrew Burgess wrote: > > > > - flang = get_frame_language (); > > - if (flang != language_unknown && > > - language_mode == language_mode_manual && > > - current_language->la_language != flang) > > - printf_filtered ("%s\n", lang_frame_mismatch_warn); > > + if (target_has_execution) > > target_has_execution can't be right. What about core files? Switched to has_stack_frames, which, given we're working with stack frames seems like a much better check. > > > + { > > + frame = get_selected_frame (NULL); > > + flang = get_frame_language (frame); > > + if (flang != language_unknown && > > + language_mode == language_mode_manual && > > + current_language->la_language != flang) > > Please put the &&'s at the beginning of the next line while at it. Done. > > > > /* First make sure that a new frame has been selected, in case the > > command or the hooks changed the program state. */ > > - deprecated_safe_get_selected_frame (); > > + frame = deprecated_safe_get_selected_frame (); > > if (current_language != expected_language) > > { > > if (language_mode == language_mode_auto && info_verbose) > > @@ -348,11 +349,11 @@ check_frame_language_change (void) > > /* FIXME: This should be cacheing the frame and only running when > > the frame changes. */ > > > > - if (has_stack_frames ()) > > + if (has_stack_frames () && frame != NULL) > > If has_stack_frames() returns true, how can FRAME be NULL? Good point. Pointless check removed. New version below. Thanks, Andrew --- As part of a drive to remove deprecated_safe_get_selected_frame, make the get_frame_language function take a frame parameter. Given the name of the function this actually seems to make a lot of sense. The task of fetching a suitable frame is then passed to the calling functions. For get_frame_language there are not many callers, these are updated to get the selected frame in a suitable way. gdb/ChangeLog: * language.c (show_language_command): Find selected frame before asking for the language of that frame. (set_language_command): Likewise. * language.h (get_frame_language): Add frame parameter. * stack.c (get_frame_language): Add frame parameter, assert parameter is not NULL, update comment and reindent. * top.c (check_frame_language_change): Pass the selected frame into get_frame_language. --- gdb/ChangeLog | 11 +++++++++++ gdb/language.c | 33 +++++++++++++++++++++++-------- gdb/language.h | 2 +- gdb/stack.c | 61 ++++++++++++++++++++++++++++------------------------------ gdb/top.c | 5 +++-- 5 files changed, 69 insertions(+), 43 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index af41072..223d2e5 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,14 @@ +2015-08-04 Andrew Burgess + + * language.c (show_language_command): Find selected frame before + asking for the language of that frame. + (set_language_command): Likewise. + * language.h (get_frame_language): Add frame parameter. + * stack.c (get_frame_language): Add frame parameter, assert + parameter is not NULL, update comment and reindent. + * top.c (check_frame_language_change): Pass the selected frame + into get_frame_language. + 2015-08-04 Jan Kratochvil * infcmd.c (signal_command): Call do_cleanups for args_chain. diff --git a/gdb/language.c b/gdb/language.c index a8b432e..75d4497 100644 --- a/gdb/language.c +++ b/gdb/language.c @@ -118,7 +118,8 @@ static void show_language_command (struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value) { - enum language flang; /* The language of the current frame. */ + struct frame_info *frame; + enum language flang; /* The language of the frame. */ if (language_mode == language_mode_auto) fprintf_filtered (gdb_stdout, @@ -130,11 +131,15 @@ show_language_command (struct ui_file *file, int from_tty, _("The current source language is \"%s\".\n"), current_language->la_name); - flang = get_frame_language (); - if (flang != language_unknown && - language_mode == language_mode_manual && - current_language->la_language != flang) - printf_filtered ("%s\n", lang_frame_mismatch_warn); + if (has_stack_frames ()) + { + frame = get_selected_frame (NULL); + flang = get_frame_language (frame); + if (flang != language_unknown + && language_mode == language_mode_manual + && current_language->la_language != flang) + printf_filtered ("%s\n", lang_frame_mismatch_warn); + } } /* Set command. Change the current working language. */ @@ -142,7 +147,7 @@ static void set_language_command (char *ignore, int from_tty, struct cmd_list_element *c) { int i; - enum language flang; + enum language flang = language_unknown; /* Search the list of languages for a match. */ for (i = 0; i < languages_size; i++) @@ -155,7 +160,19 @@ set_language_command (char *ignore, int from_tty, struct cmd_list_element *c) /* Enter auto mode. Set to the current frame's language, if known, or fallback to the initial language. */ language_mode = language_mode_auto; - flang = get_frame_language (); + TRY + { + struct frame_info *frame; + + frame = get_selected_frame (NULL); + flang = get_frame_language (frame); + } + CATCH (ex, RETURN_MASK_ERROR) + { + flang = language_unknown; + } + END_CATCH + if (flang != language_unknown) set_language (flang); else diff --git a/gdb/language.h b/gdb/language.h index 4ecb103..8782ef0 100644 --- a/gdb/language.h +++ b/gdb/language.h @@ -544,7 +544,7 @@ extern const char *language_str (enum language); extern void add_language (const struct language_defn *); -extern enum language get_frame_language (void); /* In stack.c */ +extern enum language get_frame_language (struct frame_info *frame); /* In stack.c */ /* Check for a language-specific trampoline. */ diff --git a/gdb/stack.c b/gdb/stack.c index b4cfdbd..31a723d 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -2560,46 +2560,43 @@ func_command (char *arg, int from_tty) select_and_print_frame (frame); } -/* Gets the language of the current frame. */ +/* Gets the language of FRAME. */ enum language -get_frame_language (void) +get_frame_language (struct frame_info *frame) { - struct frame_info *frame = deprecated_safe_get_selected_frame (); + CORE_ADDR pc = 0; + int pc_p = 0; - if (frame) - { - CORE_ADDR pc = 0; - int pc_p = 0; + gdb_assert (frame!= NULL); - /* We determine the current frame language by looking up its - associated symtab. To retrieve this symtab, we use the frame - PC. However we cannot use the frame PC as is, because it - usually points to the instruction following the "call", which - is sometimes the first instruction of another function. So - we rely on get_frame_address_in_block(), it provides us with - a PC that is guaranteed to be inside the frame's code - block. */ + /* We determine the current frame language by looking up its + associated symtab. To retrieve this symtab, we use the frame + PC. However we cannot use the frame PC as is, because it + usually points to the instruction following the "call", which + is sometimes the first instruction of another function. So + we rely on get_frame_address_in_block(), it provides us with + a PC that is guaranteed to be inside the frame's code + block. */ - TRY - { - pc = get_frame_address_in_block (frame); - pc_p = 1; - } - CATCH (ex, RETURN_MASK_ERROR) - { - if (ex.error != NOT_AVAILABLE_ERROR) - throw_exception (ex); - } - END_CATCH + TRY + { + pc = get_frame_address_in_block (frame); + pc_p = 1; + } + CATCH (ex, RETURN_MASK_ERROR) + { + if (ex.error != NOT_AVAILABLE_ERROR) + throw_exception (ex); + } + END_CATCH - if (pc_p) - { - struct compunit_symtab *cust = find_pc_compunit_symtab (pc); + if (pc_p) + { + struct compunit_symtab *cust = find_pc_compunit_symtab (pc); - if (cust != NULL) - return compunit_language (cust); - } + if (cust != NULL) + return compunit_language (cust); } return language_unknown; diff --git a/gdb/top.c b/gdb/top.c index 3e88ac6..0130acf 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -329,10 +329,11 @@ void check_frame_language_change (void) { static int warned = 0; + struct frame_info *frame; /* First make sure that a new frame has been selected, in case the command or the hooks changed the program state. */ - deprecated_safe_get_selected_frame (); + frame = deprecated_safe_get_selected_frame (); if (current_language != expected_language) { if (language_mode == language_mode_auto && info_verbose) @@ -352,7 +353,7 @@ check_frame_language_change (void) { enum language flang; - flang = get_frame_language (); + flang = get_frame_language (frame); if (!warned && flang != language_unknown && flang != current_language->la_language)