From patchwork Tue Aug 13 18:26:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 34073 Received: (qmail 46468 invoked by alias); 13 Aug 2019 18:26:31 -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 45853 invoked by uid 89); 13 Aug 2019 18:26:30 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=spots, HX-Languages-Length:3742, HContent-Transfer-Encoding:8bit X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 13 Aug 2019 18:26:28 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id E5B4556049; Tue, 13 Aug 2019 14:26:26 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id kpadMDuHQQA1; Tue, 13 Aug 2019 14:26:26 -0400 (EDT) Received: from murgatroyd.Home (97-122-178-82.hlrn.qwest.net [97.122.178.82]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id 926EB56046; Tue, 13 Aug 2019 14:26:26 -0400 (EDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Fix Fortran regression with variables in nested functions Date: Tue, 13 Aug 2019 12:26:24 -0600 Message-Id: <20190813182624.15135-1-tromey@adacore.com> MIME-Version: 1.0 Sergio pointed out that commit commit aa3b6533 ("Allow nested function displays") regressed a few gdb.fortran tests. I was able to reproduce these failures with gcc head. The bug is that some spots calling contained_in will in fact do the wrong thing if nested functions are considered as contained. In the particular case of the Fortran regression, it was the call in block_innermost_frame, being called from get_hosting_frame -- in this case, the caller is specifically trying to avoid the nested case. This patch fixes the problem by adding an "allow_nested" parameter to contained_in, essentially reverting the change for most callers. gdb/ChangeLog 2019-08-13 Tom Tromey * printcmd.c (do_one_display, info_display_command): Update. * block.h (contained_in): Return bool. Add allow_nested parameter. * block.c (contained_in): Return bool. Add allow_nested parameter. --- gdb/ChangeLog | 8 ++++++++ gdb/block.c | 19 +++++++++++-------- gdb/block.h | 10 +++++++++- gdb/printcmd.c | 5 +++-- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/gdb/block.c b/gdb/block.c index 5c6faa85045..ca4dc22cf30 100644 --- a/gdb/block.c +++ b/gdb/block.c @@ -65,25 +65,28 @@ block_gdbarch (const struct block *block) return get_objfile_arch (block_objfile (block)); } -/* Return Nonzero if block a is lexically nested within block b, - or if a and b have the same pc range. - Return zero otherwise. */ +/* See block.h. */ -int -contained_in (const struct block *a, const struct block *b) +bool +contained_in (const struct block *a, const struct block *b, + bool allow_nested) { if (!a || !b) - return 0; + return false; do { if (a == b) - return 1; + return true; + /* If A is a function block, then A cannot be contained in B, + except if A was inlined. */ + if (!allow_nested && BLOCK_FUNCTION (a) != NULL && !block_inlined_p (a)) + return false; a = BLOCK_SUPERBLOCK (a); } while (a != NULL); - return 0; + return true; } diff --git a/gdb/block.h b/gdb/block.h index 9291deb6131..4c02e01d906 100644 --- a/gdb/block.h +++ b/gdb/block.h @@ -219,7 +219,15 @@ extern struct symbol *block_containing_function (const struct block *); extern int block_inlined_p (const struct block *block); -extern int contained_in (const struct block *, const struct block *); +/* Return true if block A is lexically nested within block B, or if a + and b have the same pc range. Return false otherwise. If + ALLOW_NESTED is true, then block A is considered to be in block B + if A is in a nested function in B's function. If ALLOW_NESTED is + false (the default), then blocks in nested functions are not + considered to be contained. */ + +extern bool contained_in (const struct block *a, const struct block *b, + bool allow_nested = false); extern const struct blockvector *blockvector_for_pc (CORE_ADDR, const struct block **); diff --git a/gdb/printcmd.c b/gdb/printcmd.c index 7529842e73b..9b29b53ca74 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -1936,7 +1936,8 @@ do_one_display (struct display *d) if (d->block) { if (d->pspace == current_program_space) - within_current_scope = contained_in (get_selected_block (0), d->block); + within_current_scope = contained_in (get_selected_block (0), d->block, + true); else within_current_scope = 0; } @@ -2098,7 +2099,7 @@ Num Enb Expression\n")); else if (d->format.format) printf_filtered ("/%c ", d->format.format); puts_filtered (d->exp_string); - if (d->block && !contained_in (get_selected_block (0), d->block)) + if (d->block && !contained_in (get_selected_block (0), d->block, true)) printf_filtered (_(" (cannot be evaluated in the current context)")); printf_filtered ("\n"); }