From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23157 invoked by alias); 13 Mar 2010 00:25:16 -0000 Received: (qmail 23136 invoked by uid 22791); 13 Mar 2010 00:25:15 -0000 X-SWARE-Spam-Status: No, hits=-7.3 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 13 Mar 2010 00:25:10 +0000 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o2D0P8MT012736 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 12 Mar 2010 19:25:08 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o2D0P7Nm014295; Fri, 12 Mar 2010 19:25:07 -0500 Received: from opsy.redhat.com (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o2D0P6Ot012968; Fri, 12 Mar 2010 19:25:06 -0500 Received: by opsy.redhat.com (Postfix, from userid 500) id B61DF3782C5; Fri, 12 Mar 2010 17:25:05 -0700 (MST) From: Tom Tromey To: gdb-patches@sourceware.org Subject: FYI: fix PR 9708 Reply-To: tromey@redhat.com Date: Sat, 13 Mar 2010 00:25:00 -0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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: 2010-03/txt/msg00480.txt.bz2 I'm checking this in. This fixes PR c++/9708. The bug is that a method-scoped static variable can't currently be printed by gdb. This happens because the variable is erroneously put into a namespace. Built and regtested on x86-64 (compile farm). New test case included. Tom 2010-03-12 Tom Tromey PR c++/9708: * dwarf2read.c (die_needs_namespace) : A variable in a lexical block does not need a namespace. (new_symbol) : Put extern variables on list_in_scope in all cases. 2010-03-12 Tom Tromey PR c++/9708: * gdb.cp/m-static.exp: Add regression test. * gdb.cp/m-static.cc (method): New method. (main): Call it. diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 53e2e1e..2d21edb 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -3204,6 +3204,8 @@ process_die (struct die_info *die, struct dwarf2_cu *cu) static int die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu) { + struct attribute *attr; + switch (die->tag) { case DW_TAG_namespace: @@ -3231,11 +3233,17 @@ die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu) spec_cu); } - if (dwarf2_attr (die, DW_AT_external, cu) - || die->parent->tag == DW_TAG_namespace) - return 1; - - return 0; + attr = dwarf2_attr (die, DW_AT_external, cu); + if (attr == NULL && die->parent->tag != DW_TAG_namespace) + return 0; + /* A variable in a lexical block of some kind does not need a + namespace, even though in C++ such variables may be external + and have a mangled name. */ + if (die->parent->tag == DW_TAG_lexical_block + || die->parent->tag == DW_TAG_try_block + || die->parent->tag == DW_TAG_catch_block) + return 0; + return 1; default: return 0; @@ -8413,7 +8421,15 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) var_decode_location (attr, sym, cu); attr2 = dwarf2_attr (die, DW_AT_external, cu); if (attr2 && (DW_UNSND (attr2) != 0)) - add_symbol_to_list (sym, &global_symbols); + { + 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); + add_symbol_to_list (sym, list_to_add); + } else add_symbol_to_list (sym, cu->list_in_scope); } diff --git a/gdb/testsuite/gdb.cp/m-static.cc b/gdb/testsuite/gdb.cp/m-static.cc index 2a0b61c..7f997ef 100644 --- a/gdb/testsuite/gdb.cp/m-static.cc +++ b/gdb/testsuite/gdb.cp/m-static.cc @@ -15,6 +15,12 @@ protected: public: gnu_obj_1(antiquities a, long l) {} + + long method () + { + static bool svar = true; + return key2; + } }; const bool gnu_obj_1::test; @@ -70,5 +76,8 @@ int main() test4.dummy = test4.elsewhere; test4.dummy = 0; - return test4.dummy; // breakpoint: constructs-done + + test1.method (); // breakpoint: constructs-done + + return test4.dummy; } diff --git a/gdb/testsuite/gdb.cp/m-static.exp b/gdb/testsuite/gdb.cp/m-static.exp index f207462..7b4e0ca 100644 --- a/gdb/testsuite/gdb.cp/m-static.exp +++ b/gdb/testsuite/gdb.cp/m-static.exp @@ -132,5 +132,10 @@ gdb_test "print test4.nowhere" "field nowhere is nonexistent or has been optimis # that GDB's current behavior in such situations is either consistent # across platforms or optimal, so I'm not including one now. +# Step into test1.method and examine the method-scoped static. +# This is a regression test for PR 9708. +gdb_test "step" "gnu_obj_1::method.*" +gdb_test "print svar" " = true" + gdb_exit return 0