From patchwork Sat Jul 27 16:22:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 33831 Received: (qmail 29421 invoked by alias); 27 Jul 2019 16:22:56 -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 29378 invoked by uid 89); 27 Jul 2019 16:22:56 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=H*RU:209.85.128.65, HX-Spam-Relays-External:209.85.128.65 X-HELO: mail-wm1-f65.google.com Received: from mail-wm1-f65.google.com (HELO mail-wm1-f65.google.com) (209.85.128.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 27 Jul 2019 16:22:54 +0000 Received: by mail-wm1-f65.google.com with SMTP id s3so50335463wms.2 for ; Sat, 27 Jul 2019 09:22:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=P094VAnZB9nT6yyE2+DEyn0nPjJBlJVN+Y0yo7Q0yuU=; b=VxbIJYb3wEkgNZGsY2o4jS8VZqbGOCxwnpnOSuvMdUA1QPITIZ66tnZrzoD7ZpuCjK zq38UqJrvIopOMN1X6BNhDKJ26DsMTzhyUz/G1jIRd+iPdwHgJRtYGyGvJHAoBZuWvbT V+nxqx7MQru30WEsdlUoMfu+OFqM3yKqMx3jL6ld6hDyI5dy6vua/vF7aPQP+1e+gf+W aAPG8N0QKFqvh3pr+4h80ig6+dLVZQAdl16LufmBHqiSx8sJq5THqGGuqGPZPqN828Da MjQFUu3I0CBPm1dejJdvcRNA9e3tkxF7SfGGUJh9elQ20TEBdX4YD8uDZ6YQcq3X9b25 fu6g== Return-Path: Received: from localhost (188.29.165.26.threembb.co.uk. [188.29.165.26]) by smtp.gmail.com with ESMTPSA id p12sm42609606wrt.13.2019.07.27.09.22.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 27 Jul 2019 09:22:51 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Richard Bunt , Andrew Burgess Subject: [PATCH 3/7] gdb/fortran: Include module variables in 'info variables' output Date: Sat, 27 Jul 2019 17:22:31 +0100 Message-Id: <2105892b16a74d81bbca277b480b0d6ba61595a8.1564243858.git.andrew.burgess@embecosm.com> In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes Due to a work around in dwarf2read.c for gFortran issue #40040, non-constant module variables don't show up in 'info variables' output. The reason is that issue #40040 means that the debug symbol definition for these module variables can sometimes have the incorrect location information attached to it. The work around in GDB is to ignore the location information from the debug information, and mark these symbols as LOC_UNRESOLVED, GDB will then fall back to using the non-debug symbols in order to figure out the location of these symbols. The problem with this is that GDB uses LOC_UNRESOLVED to indicate a variable declaration, and doesn't include such symbols in its output. In an earlier commit I extended each symbol to now explicitly track if it is marked as a declaration in the DWARF, so GDB can now use this information rather than LOC_UNRESOLVED to exclude declarations from the 'info variables' output. You might think that we could just switch from checking: SYMBOL_CLASS (sym) != LOC_UNRESOLVED to checking: !SYMBOL_IS_DECLARATION (sym) However, this is not good enough, often in C or C++ the declaration is _also_ the definition, in which case the symbol will be marked as a declaration, but will _not_ be of address class LOC_UNRESOLVED. The correct condition then is that we shouldn't show declarations that are of class LOC_UNRESOLVED. The preserves the existing C/C++ behaviour in every case I've tried so far, and also fixes the gFortran issues that I was seeing. gdb/ChangeLog: * dwarf2read.c (new_symbol): Mark symbol as declaration when appropriate. * symtab.h (struct symbol): Add 'is_declaration' flag. (SYMBOL_IS_DECLARATION): Define. gdb/testsuite/ChangeLog: * gdb.fortran/module.exp: Extend with 'info variables' test. --- gdb/symtab.c | 3 ++- gdb/testsuite/ChangeLog | 4 ++++ gdb/testsuite/gdb.fortran/module.exp | 24 ++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/gdb/symtab.c b/gdb/symtab.c index 1925edeeaa3..84038d15dff 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -4520,8 +4520,9 @@ search_symbols (const char *regexp, enum search_domain kind, || preg->exec (SYMBOL_NATURAL_NAME (sym), 0, NULL, 0) == 0) && ((kind == VARIABLES_DOMAIN + && !(SYMBOL_CLASS (sym) == LOC_UNRESOLVED + && SYMBOL_IS_DECLARATION (sym)) && SYMBOL_CLASS (sym) != LOC_TYPEDEF - && SYMBOL_CLASS (sym) != LOC_UNRESOLVED && SYMBOL_CLASS (sym) != LOC_BLOCK /* LOC_CONST can be used for more than just enums, e.g., c++ static const diff --git a/gdb/testsuite/gdb.fortran/module.exp b/gdb/testsuite/gdb.fortran/module.exp index 4d71e7efac5..276f7dc3c24 100644 --- a/gdb/testsuite/gdb.fortran/module.exp +++ b/gdb/testsuite/gdb.fortran/module.exp @@ -13,6 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +load_lib "fortran.exp" + standard_testfile .f90 if { [prepare_for_testing "failed to prepare" $testfile $srcfile {debug f90}] } { @@ -32,6 +34,28 @@ if ![runto MAIN__] then { continue } +set int_type [fortran_int4] + +# Test 'info variables' can find module variables. +gdb_test "info variables -n" \ + [multi_line \ + "All defined variables:" \ + "" \ + "File .*$srcfile:" \ + "18:\[ \t\]+${int_type} mod1::var_const;" \ + "17:\[ \t\]+${int_type} mod1::var_i;" \ + "23:\[ \t\]+${int_type} mod2::var_i;" \ + "28:\[ \t\]+${int_type} mod3::mod1;" \ + "27:\[ \t\]+${int_type} mod3::mod2;" \ + "29:\[ \t\]+${int_type} mod3::var_i;" \ + "33:\[ \t\]+${int_type} modmany::var_a;" \ + "33:\[ \t\]+${int_type} modmany::var_b;" \ + "33:\[ \t\]+${int_type} modmany::var_c;" \ + "33:\[ \t\]+${int_type} modmany::var_i;" \ + "37:\[ \t\]+${int_type} moduse::var_x;" \ + "37:\[ \t\]+${int_type} moduse::var_y;" ] + + # Do not use simple single-letter names as GDB would pick up for expectedly # nonexisting symbols some static variables from system libraries debuginfos.