From: Sami Wagiaalla <swagiaal@redhat.com>
To: GDB Patches <gdb-patches@sourceware.org>
Subject: [patch] Perform a namespace lookup at every block level
Date: Fri, 10 Jul 2009 15:10:00 -0000 [thread overview]
Message-ID: <4A57512A.7090208@redhat.com> (raw)
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 <swagiaal@redhat.com>
* 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 <swagiaal@redhat.com>
* 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"
next reply other threads:[~2009-07-10 14:34 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-10 15:10 Sami Wagiaalla [this message]
2009-07-10 20:16 ` Daniel Jacobowitz
2009-07-13 17:55 ` Sami Wagiaalla
2009-07-23 19:46 ` Sami Wagiaalla
2009-07-23 22:19 ` Sami Wagiaalla
2009-07-29 22:12 ` Tom Tromey
2009-08-18 20:34 ` [patch 1/2] " Sami Wagiaalla
2009-10-13 19:47 ` Tom Tromey
2009-10-20 20:50 ` Sami Wagiaalla
2009-11-10 22:23 ` Tom Tromey
2009-11-10 22:26 ` Tom Tromey
2009-11-16 15:32 ` Sami Wagiaalla
2009-11-16 19:16 ` Sami Wagiaalla
2009-11-24 19:06 ` Sami Wagiaalla
2009-12-21 21:44 ` Tom Tromey
2009-08-18 20:46 ` [patch 2/2] " Sami Wagiaalla
2009-09-04 16:57 ` Sami Wagiaalla
2009-10-13 20:22 ` Tom Tromey
2009-10-22 17:47 ` Sami Wagiaalla
2009-11-10 22:52 ` Tom Tromey
2009-11-16 17:55 ` Sami Wagiaalla
2009-11-24 19:12 ` Sami Wagiaalla
2009-12-21 21:55 ` Tom Tromey
2010-01-11 21:24 ` Sami Wagiaalla
2010-01-12 17:43 ` Tom Tromey
2010-01-14 16:47 ` Sami Wagiaalla
2010-01-14 20:18 ` Sami Wagiaalla
2010-01-15 18:06 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4A57512A.7090208@redhat.com \
--to=swagiaal@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox