From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13577 invoked by alias); 10 Jul 2009 14:34:33 -0000 Received: (qmail 13569 invoked by uid 22791); 10 Jul 2009 14:34:32 -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; Fri, 10 Jul 2009 14:34:24 +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 n6AEYMFF016831 for ; Fri, 10 Jul 2009 10:34:23 -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 n6AEYMaO025138 for ; Fri, 10 Jul 2009 10:34:22 -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 n6AEYLO2030239 for ; Fri, 10 Jul 2009 10:34:21 -0400 Message-ID: <4A57512A.7090208@redhat.com> Date: Fri, 10 Jul 2009 15:10:00 -0000 From: Sami Wagiaalla User-Agent: Thunderbird 2.0.0.17 (X11/20081009) MIME-Version: 1.0 To: GDB Patches Subject: [patch] Perform a namespace lookup at every block level 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-07/txt/msg00307.txt.bz2 Now that import information is stored in the nearest block, this patch changes things so that a namespace lookup is correctly performed at every block level. 2009-07-09 Sami Wagiaalla * symtab.c: Import cp-support.h. (lookup_symbol_aux_local): Continue lookup through static block and stop at global block. Do a namespace at each block level via lookup_namespace_scope. Now takes 'enum language' argument. * cp-support.h: Added extern lookup_namespace_scope prototype. * cp-namespace.c (lookup_namespace_scope): Removed static qualifier. (cp_lookup_symbol_nonlocal): Calls lookup_symbol_file if call to lookup_namespace_scope fails. (cp_lookup_symbol_namespace): Return NULL if no namespace is specified. 2009-07-09 Sami Wagiaalla * gdb.cp/namespace-using.exp: Add test for printing of namespaces imported into file scope. * gdb.cp/namespace-using.cc (marker5): New function. diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c index d2d8f2e..75cac01 100644 --- a/gdb/cp-namespace.c +++ b/gdb/cp-namespace.c @@ -35,13 +35,6 @@ static struct using_direct *cp_copy_usings (struct using_direct *using, struct obstack *obstack); -static struct symbol *lookup_namespace_scope (const char *name, - const char *linkage_name, - const struct block *block, - const domain_enum domain, - const char *scope, - int scope_len); - static struct symbol *lookup_symbol_file (const char *name, const char *linkage_name, const struct block *block, @@ -265,8 +258,15 @@ cp_lookup_symbol_nonlocal (const char *name, const struct block *block, const domain_enum domain) { - return lookup_namespace_scope (name, linkage_name, block, domain, + struct symbol *sym; + + sym = lookup_namespace_scope (name, linkage_name, block, domain, block_scope (block), 0); + if ( sym != NULL) + return sym; + + return lookup_symbol_file (name, linkage_name, block, + domain, 0); } /* Lookup NAME at namespace scope (or, in C terms, in static and @@ -284,7 +284,7 @@ cp_lookup_symbol_nonlocal (const char *name, "A::x", and if that call fails, then the first call looks for "x". */ -static struct symbol * +struct symbol * lookup_namespace_scope (const char *name, const char *linkage_name, const struct block *block, @@ -364,8 +364,7 @@ cp_lookup_symbol_namespace (const char *namespace, if (namespace[0] == '\0') { - return lookup_symbol_file (name, linkage_name, block, - domain, 0); + return NULL; } else { diff --git a/gdb/cp-support.h b/gdb/cp-support.h index b5a5c5f..2016024 100644 --- a/gdb/cp-support.h +++ b/gdb/cp-support.h @@ -101,6 +101,13 @@ extern struct symbol *cp_lookup_symbol_nonlocal (const char *name, const struct block *block, const domain_enum domain); +extern struct symbol *lookup_namespace_scope (const char *name, + const char *linkage_name, + const struct block *block, + const domain_enum domain, + const char *scope, + int scope_len); + extern struct symbol *cp_lookup_symbol_namespace (const char *namespace, const char *name, const char *linkage_name, diff --git a/gdb/symtab.c b/gdb/symtab.c index 009c52d..ca6a476 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -42,6 +42,7 @@ #include "ada-lang.h" #include "p-lang.h" #include "addrmap.h" +#include "cp-support.h" #include "hashtab.h" @@ -95,7 +96,8 @@ static struct symbol *lookup_symbol_aux_local (const char *name, const char *linkage_name, const struct block *block, - const domain_enum domain); + const domain_enum domain, + enum language language); static struct symbol *lookup_symbol_aux_symtabs (int block_index, @@ -1291,7 +1293,7 @@ lookup_symbol_aux (const char *name, const char *linkage_name, /* Search specified block and its superiors. Don't search STATIC_BLOCK or GLOBAL_BLOCK. */ - sym = lookup_symbol_aux_local (name, linkage_name, block, domain); + sym = lookup_symbol_aux_local (name, linkage_name, block, domain, language); if (sym != NULL) return sym; @@ -1361,27 +1363,41 @@ lookup_symbol_aux (const char *name, const char *linkage_name, } /* Check to see if the symbol is defined in BLOCK or its superiors. - Don't search STATIC_BLOCK or GLOBAL_BLOCK. */ + Don't search GLOBAL_BLOCK. + In the case of C++ perform a namespace lookup and every block. */ static struct symbol * lookup_symbol_aux_local (const char *name, const char *linkage_name, const struct block *block, - const domain_enum domain) + const domain_enum domain, + enum language language) { struct symbol *sym; - const struct block *static_block = block_static_block (block); + const struct block *global_block = block_global_block (block); + const struct language_defn *langdef; + + langdef = language_def (language); /* Check if either no block is specified or it's a global block. */ - if (static_block == NULL) + if (global_block == NULL) return NULL; - while (block != static_block) + while (block != global_block) { sym = lookup_symbol_aux_block (name, linkage_name, block, domain); if (sym != NULL) return sym; + if ( language == language_cplus ) + { + sym = lookup_namespace_scope (name, linkage_name, block, domain, + block_scope (block), 0); + + if (sym != NULL) + return sym; + } + if (BLOCK_FUNCTION (block) != NULL && block_inlined_p (block)) break; block = BLOCK_SUPERBLOCK (block); diff --git a/gdb/testsuite/gdb.cp/namespace-using.cc b/gdb/testsuite/gdb.cp/namespace-using.cc index 4786fd5..00fd47f 100644 --- a/gdb/testsuite/gdb.cp/namespace-using.cc +++ b/gdb/testsuite/gdb.cp/namespace-using.cc @@ -4,12 +4,26 @@ namespace A int x = 2; } -int marker4(){ - using A::x; - return 0; +namespace C +{ + int cc = 3; +} + +using namespace C; +int marker5() +{ + cc; + return 0; } -int marker3(){ +int marker4() +{ + using A::x; + return marker5(); +} + +int marker3() +{ return marker4(); } diff --git a/gdb/testsuite/gdb.cp/namespace-using.exp b/gdb/testsuite/gdb.cp/namespace-using.exp index f24973f..210bfd7 100644 --- a/gdb/testsuite/gdb.cp/namespace-using.exp +++ b/gdb/testsuite/gdb.cp/namespace-using.exp @@ -28,6 +28,10 @@ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {deb return -1 } +if [get_compiler_info ${binfile}] { + return -1; +} + # Get things started. gdb_exit @@ -73,7 +77,13 @@ gdb_test "print B::a" "= 1" gdb_breakpoint "marker3" gdb_continue_to_breakpoint "marker3" -gdb_test "print _a" "No symbol \"_a\" in current context." "Print a without import" +# gcc-4-3 puts import statements for aliases in +# the global scope instead of the corresponding +# function scope. These wrong import statements throw +# this test off. This is fixed in gcc-4-4. +if [test_compiler_info gcc-4-3-*] then { setup_xfail *-*-* } + +gdb_test "print _a" "No symbol \"_a\" in current context." "Print _a without import" ############################################ # Test printing of individually imported elements @@ -85,3 +95,15 @@ if ![runto marker4] then { } gdb_test "print x" "= 2" + + +############################################ +# test printing of namespace imported into +# file scope. + +if ![runto marker5] then { + perror "couldn't run to marker5" + continue +} + +gdb_test "print cc" "= 3"