From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4177 invoked by alias); 13 Nov 2009 21:44:57 -0000 Received: (qmail 4166 invoked by uid 22791); 13 Nov 2009 21:44:55 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL,BAYES_00,KAM_STOCKGEN X-Spam-Check-By: sourceware.org Received: from NaN.false.org (HELO nan.false.org) (208.75.86.248) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 13 Nov 2009 21:44:51 +0000 Received: from nan.false.org (localhost [127.0.0.1]) by nan.false.org (Postfix) with ESMTP id 84EC410E87 for ; Fri, 13 Nov 2009 21:44:49 +0000 (GMT) Received: from caradoc.them.org (209.195.188.212.nauticom.net [209.195.188.212]) by nan.false.org (Postfix) with ESMTP id 4586C10661 for ; Fri, 13 Nov 2009 21:44:49 +0000 (GMT) Received: from drow by caradoc.them.org with local (Exim 4.69) (envelope-from ) id 1N93wm-0007zc-Jz for gdb-patches@sourceware.org; Fri, 13 Nov 2009 16:44:48 -0500 Date: Fri, 13 Nov 2009 21:44:00 -0000 From: Daniel Jacobowitz To: gdb-patches@sourceware.org Subject: RFC: Skip declarations in "info variables" Message-ID: <20091113214448.GA30270@caradoc.them.org> Mail-Followup-To: gdb-patches@sourceware.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-IsSubscribed: yes 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: 2009-11/txt/msg00303.txt.bz2 This has bugged me for a while, but today it caused me a test failure: I added a reference to an otherwise unused variable in gdb.base/included.c. The info var integer output became: All variables matching regular expression "integer": File .../included.c: static int integer; int integer; There's two problems here. First, one of the copies is static. The dwarf2read.c portion of the patch below fixes this. We now add external symbols without a location to list_in_scope, in order to correctly support: int x; { extern int x; // x here references the global } But that caused us to display this as a static variable: extern int x; So we should special-case file scope variables. The second problem is that integer is listed twice. Jan pointed me to GCC PR 37982; the file has a declaration and definition for the variable if it is referenced (only a definition, otherwise). I don't think we should display the declaration. So I've changed search_symbols not to display variables of class LOC_UNRESOLVED, and updated the documentation to match. While this is a change of behavior, I don't think it's problematic. Any comments? OK to commit? Tested on arm-none-eabi and x86_64-linux. 2009-11-13 Daniel Jacobowitz * dwarf2read.c (new_symbol): Add file-scope external unresolved symbols to global_symbols. * symtab.c (search_symbols): Skip LOC_UNRESOLVED symbols. * gdb.texinfo (Symbols): "info variables" prints definitions, not declarations. --- gdb/doc/gdb.texinfo | 2 +- gdb/dwarf2read.c | 9 ++++++++- gdb/symtab.c | 5 ++++- 3 files changed, 13 insertions(+), 3 deletions(-) Index: src/gdb/dwarf2read.c =================================================================== --- src.orig/gdb/dwarf2read.c 2009-11-13 16:22:50.000000000 -0500 +++ src/gdb/dwarf2read.c 2009-11-13 16:27:57.000000000 -0500 @@ -8441,8 +8441,15 @@ new_symbol (struct die_info *die, struct if (attr2 && (DW_UNSND (attr2) != 0) && dwarf2_attr (die, DW_AT_type, cu) != NULL) { + struct pending **list_to_add; + + /* A variable with DW_AT_external is never static, but it + may be block-scoped. */ + list_to_add = (cu->list_in_scope == &file_symbols + ? &global_symbols : cu->list_in_scope); + SYMBOL_CLASS (sym) = LOC_UNRESOLVED; - add_symbol_to_list (sym, cu->list_in_scope); + add_symbol_to_list (sym, list_to_add); } else if (!die_is_declaration (die, cu)) { Index: src/gdb/symtab.c =================================================================== --- src.orig/gdb/symtab.c 2009-11-13 16:22:50.000000000 -0500 +++ src/gdb/symtab.c 2009-11-13 16:27:57.000000000 -0500 @@ -3234,7 +3234,9 @@ search_symbols (char *regexp, domain_enu && ((regexp == NULL || re_exec (SYMBOL_NATURAL_NAME (*psym)) != 0) && ((kind == VARIABLES_DOMAIN && SYMBOL_CLASS (*psym) != LOC_TYPEDEF - && SYMBOL_CLASS (*psym) != LOC_BLOCK) + && SYMBOL_CLASS (*psym) != LOC_UNRESOLVED + && SYMBOL_CLASS (*psym) != LOC_BLOCK + && SYMBOL_CLASS (*psym) != LOC_CONST) || (kind == FUNCTIONS_DOMAIN && SYMBOL_CLASS (*psym) == LOC_BLOCK) || (kind == TYPES_DOMAIN && SYMBOL_CLASS (*psym) == LOC_TYPEDEF)))) { @@ -3310,6 +3312,7 @@ search_symbols (char *regexp, domain_enu && ((regexp == NULL || re_exec (SYMBOL_NATURAL_NAME (sym)) != 0) && ((kind == VARIABLES_DOMAIN && SYMBOL_CLASS (sym) != LOC_TYPEDEF + && SYMBOL_CLASS (sym) != LOC_UNRESOLVED && SYMBOL_CLASS (sym) != LOC_BLOCK && SYMBOL_CLASS (sym) != LOC_CONST) || (kind == FUNCTIONS_DOMAIN && SYMBOL_CLASS (sym) == LOC_BLOCK) Index: src/gdb/doc/gdb.texinfo =================================================================== --- src.orig/gdb/doc/gdb.texinfo 2009-11-13 16:28:20.000000000 -0500 +++ src/gdb/doc/gdb.texinfo 2009-11-13 16:28:43.000000000 -0500 @@ -12920,7 +12920,7 @@ that conflict with the regular expressio @kindex info variables @item info variables -Print the names and data types of all variables that are declared +Print the names and data types of all variables that are defined outside of functions (i.e.@: excluding local variables). @item info variables @var{regexp} -- Daniel Jacobowitz CodeSourcery