From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31208 invoked by alias); 18 Aug 2009 20:34:57 -0000 Received: (qmail 31199 invoked by uid 22791); 18 Aug 2009 20:34:56 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx2.redhat.com (HELO mx2.redhat.com) (66.187.237.31) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 18 Aug 2009 20:34:48 +0000 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n7IKYkum008334 for ; Tue, 18 Aug 2009 16:34:46 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n7IKYinf017944; Tue, 18 Aug 2009 16:34:45 -0400 Received: from toner.yyz.redhat.com (toner.yyz.redhat.com [10.15.16.55]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n7IKYhKH027152; Tue, 18 Aug 2009 16:34:44 -0400 Message-ID: <4A8B0FD9.7010603@redhat.com> Date: Tue, 18 Aug 2009 20:46:00 -0000 From: Sami Wagiaalla User-Agent: Thunderbird 2.0.0.17 (X11/20081009) MIME-Version: 1.0 To: Sami Wagiaalla , GDB Patches Subject: [patch 2/2] Perform a namespace lookup at every block level References: <4A57512A.7090208@redhat.com> <20090710194949.GA2064@caradoc.them.org> <4A5B68A4.30006@redhat.com> <4A68B91D.2080206@redhat.com> In-Reply-To: <4A68B91D.2080206@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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-08/txt/msg00294.txt.bz2 In cases like this namespace A{ int ax; } namespace B{ using namespace A; } namespace C{ using namespace B; } using namespace A void foo(){ C::ax; } And this: namespace{ namespace{ in xx; } } void foo(){ xx; } A recursive search must be performed. This patch provides that functionality: 2009-08-14 Sami Wagiaalla * cp-support.h: Add 'searched' feild to using_direct struct. * cp-namespace.c (cp_lookup_symbol_imports): Perform recursive search. (cp_add_using): Initialize 'searched' feild. (cp_copy_usings): Copy searched feild. diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c index a0ccd7f..909ec2c 100644 --- a/gdb/cp-namespace.c +++ b/gdb/cp-namespace.c @@ -229,6 +229,7 @@ cp_add_using (const char *dest, retval->import_src = savestring (src, strlen(src)); retval->import_dest = savestring (dest, strlen(dest)); retval->next = next; + retval->searched = 0; return retval; } @@ -255,6 +256,8 @@ cp_copy_usings (struct using_direct *using, obstack); retval->next = cp_copy_usings (using->next, obstack); + retval->searched = using->searched; + xfree (using->import_src); xfree (using->import_dest); xfree (using); @@ -408,7 +411,7 @@ cp_lookup_symbol_imports (const char *scope, const struct block *block, const domain_enum domain) { - const struct using_direct *current; + struct using_direct *current; struct symbol *sym; /* First, try to find the symbol in the given namespace. */ @@ -428,13 +431,20 @@ cp_lookup_symbol_imports (const char *scope, /* If the import destination is the current scope or one of its ancestors then it is applicable. */ - if (strncmp (scope, current->import_dest, strlen(current->import_dest)) == 0) + if (strncmp (scope, current->import_dest, + strlen(current->import_dest)) == 0 && + !current->searched ) { - sym = cp_lookup_symbol_in_namespace (current->import_src, + /* Mark this import as searched so that the recursive call does not + search it again. */ + current->searched = 1; + sym = cp_lookup_symbol_namespace (current->import_src, name, linkage_name, block, domain); + + current->searched = 0; if (sym != NULL) return sym; } diff --git a/gdb/cp-support.h b/gdb/cp-support.h index b5a5c5f..c9d53e5 100644 --- a/gdb/cp-support.h +++ b/gdb/cp-support.h @@ -47,6 +47,9 @@ struct using_direct char *import_src; char *import_dest; struct using_direct *next; + + /* Used during import search to temporarly mark this node as searced. */ + int searched; }; diff --git a/gdb/testsuite/gdb.cp/namespace-recursive.cc b/gdb/testsuite/gdb.cp/namespace-recursive.cc new file mode 100644 index 0000000..9368ad8 --- /dev/null +++ b/gdb/testsuite/gdb.cp/namespace-recursive.cc @@ -0,0 +1,30 @@ +namespace A{ + int ax = 9; +} + +namespace B{ + using namespace A; +} + +namespace C{ + using namespace B; +} + +//--------------- +namespace D{ + using namespace D; + int dx = 99; +} +using namespace C; + +//--------------- +namespace{ + namespace{ + int xx = 999; + } +} + +int main(){ + using namespace D; + return ax + dx + xx; +} \ No newline at end of file diff --git a/gdb/testsuite/gdb.cp/namespace-recursive.exp b/gdb/testsuite/gdb.cp/namespace-recursive.exp new file mode 100644 index 0000000..ebc898f --- /dev/null +++ b/gdb/testsuite/gdb.cp/namespace-recursive.exp @@ -0,0 +1,66 @@ +# Copyright 2008 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +if $tracelevel then { + strace $tracelevel +} + +set prms_id 0 +set bug_id 0 + +set testfile namespace-recursive +set srcfile ${testfile}.cc +set binfile ${objdir}/${subdir}/${testfile} +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } { + untested "Couldn't compile test program" + return -1 +} + +if [get_compiler_info ${binfile}] { + return -1; +} + + +# Get things started. + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +if ![runto_main] then { + perror "couldn't run to breakpoint main" + continue +} + +############################################ +# test printing from namespace imported into +# imported namespace + +gdb_test "print ax" "= 9" + +############################################ +# test that gdb can print without falling +# into search loop + +gdb_test "print dx" "= 99" + +############################################ +# test printing from namespace imported into +# imported namespace where imports are implicit +# anonymous namespace imports. + +gdb_test "print xx" "= 999" +