public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [RFA] Fix namespace aliases (c++/7539, c++/10541)
@ 2013-07-26 19:15 Keith Seitz
  2013-07-29 20:28 ` Tom Tromey
  0 siblings, 1 reply; 7+ messages in thread
From: Keith Seitz @ 2013-07-26 19:15 UTC (permalink / raw)
  To: gdb-patches@sourceware.org ml

[-- Attachment #1: Type: text/plain, Size: 1749 bytes --]

Hi,

This is an attempt to fix namespace alias bugs reported in c++/7539 and 
c++/10541.

There are several problems here. First, previous versions of gcc did not 
output the proper debuginfo. As a result, I've resorted to using the 
DWARF assembler for testing. Basically any gcc > 4.2.4 should work, 
though. [I know that's ancient, but ...]

The next problem was getting all the aliases recorded into the symbol 
table. I've made some changes to dwarf2read.c to do this.

With this change, the expression parser pretty much works as-is. The 
remaining problem is the linespec parser.

That was resolved by modifying cp_canonical_string_no_typedefs to do 
namespace alias substitutions. [I really think I should have named this 
cp_canonicalize_string_for_lookup or something similar.]

With this find_linespec_symbols can then properly look for an actual 
symbol that is in the symbol table.

Tested, regression-free, with x86_64 native and native-gdbserver.

Keith

ChangeLog
2013-07-26  Keith Seitz  <keiths@redhat.com>

	PR c++/7539
	PR c++/10541
	* cp-support.c (insepct_type): Add support for substituting
	namespace aliases, too.
	* dwarf2read.c (scan_partial_symbols): Add a partial symbol
	for DW_TAG_imported_declaration.
	(add_partial_symbol): Likewise.
	(process_die): Handle namespace aliases.
	(die_needs_namespace): Add DW_TAG_imported_declaration.
	(load_partial_dies): Load DW_TAG_imported_declaration, too.
	(new_symbol_full): Handle DW_TAG_imported_declaration.

testsuite/ChangeLog
2013-07-26  Keith Seitz  <keiths@redhat.com>

	PR c++/7935
	PR c++/10541
	* gdb.cp/nsalias.exp: New file.
	* gdb.cp/nsalias.cc: New file.
	* gdb.cp/nsrecurs.exp: Remove kfails. Conditionally run
	tests only on known, working compiler versions.


[-- Attachment #2: namespace-aliases.patch --]
[-- Type: text/x-patch, Size: 11115 bytes --]

diff --git a/gdb/cp-support.c b/gdb/cp-support.c
index 3c1442d..623c0da 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -200,8 +200,9 @@ inspect_type (struct demangle_parse_info *info,
 	  return 0;
 	}
 
-      /* If the type is a typedef, replace it.  */
-      if (TYPE_CODE (otype) == TYPE_CODE_TYPEDEF)
+      /* If the type is a typedef or namespace alias, replace it.  */
+      if (TYPE_CODE (otype) == TYPE_CODE_TYPEDEF
+	  || TYPE_CODE (otype) == TYPE_CODE_NAMESPACE)
 	{
 	  long len;
 	  int is_anon;
@@ -212,6 +213,13 @@ inspect_type (struct demangle_parse_info *info,
 	  /* Get the real type of the typedef.  */
 	  type = check_typedef (otype);
 
+	  /* If the symbol is a namespace and its name is no different
+	     than the name we looked up, this symbol is not a namespace
+	     alias and does not need to be substituted.  */
+	  if (TYPE_CODE (otype) == TYPE_CODE_NAMESPACE
+	      && strcmp (TYPE_NAME (type), name) == 0)
+	    return 0;
+
 	  is_anon = (TYPE_TAG_NAME (type) == NULL
 		     && (TYPE_CODE (type) == TYPE_CODE_ENUM
 			 || TYPE_CODE (type) == TYPE_CODE_STRUCT
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 04993c2..cd74abf 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -6244,6 +6244,9 @@ scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
 			       cu->per_cu->imported_symtabs, per_cu);
 	      }
 	      break;
+	    case DW_TAG_imported_declaration:
+	      add_partial_symbol (pdi, cu);
+	      break;
 	    default:
 	      break;
 	    }
@@ -6515,6 +6518,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
 			   &objfile->static_psymbols,
 			   0, (CORE_ADDR) 0, cu->language, objfile);
       break;
+    case DW_TAG_imported_declaration:
     case DW_TAG_namespace:
       add_psymbol_to_list (actual_name, strlen (actual_name),
 			   built_actual_name != NULL,
@@ -7732,6 +7736,32 @@ process_die (struct die_info *die, struct dwarf2_cu *cu)
       read_module (die, cu);
       break;
     case DW_TAG_imported_declaration:
+      {
+	struct attribute *attr;
+
+	attr = dwarf2_attr (die, DW_AT_import, cu);
+	if (attr != NULL)
+	  {
+	    /* If the die does not have a name, this is not a namespace
+	       alias.  */
+	    attr = dwarf2_attr (die, DW_AT_name, cu);
+	    if (attr != NULL)
+	      {
+		struct type *type;
+		sect_offset offset = dwarf2_get_ref_die_offset (attr);
+
+		type = get_die_type_at_offset (offset, cu->per_cu);
+		if (type != NULL && TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
+		  {
+		    /* This declaration is a global namespace alias.  Add
+		       a symbol for it whose type is the aliased namespace.  */
+		    new_symbol (die, type, cu);
+		    break;
+		  }
+	      }
+	  }
+      }
+      /* The declaration is not a global namespace alias: fall through.  */
     case DW_TAG_imported_module:
       cu->processing_has_namespace_info = 1;
       if (die->child != NULL && (die->tag == DW_TAG_imported_declaration
@@ -7774,6 +7804,7 @@ die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu)
     case DW_TAG_enumerator:
     case DW_TAG_subprogram:
     case DW_TAG_member:
+    case DW_TAG_imported_declaration:
       return 1;
 
     case DW_TAG_variable:
@@ -14013,7 +14044,8 @@ load_partial_dies (const struct die_reader_specs *reader,
 	  && abbrev->tag != DW_TAG_namespace
 	  && abbrev->tag != DW_TAG_module
 	  && abbrev->tag != DW_TAG_member
-	  && abbrev->tag != DW_TAG_imported_unit)
+	  && abbrev->tag != DW_TAG_imported_unit
+	  && abbrev->tag != DW_TAG_imported_declaration)
 	{
 	  /* Otherwise we skip to the next sibling, if any.  */
 	  info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev);
@@ -16731,6 +16763,7 @@ new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
 			   ? &global_symbols : cu->list_in_scope);
 	  }
 	  break;
+	case DW_TAG_imported_declaration:
 	case DW_TAG_namespace:
 	  SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
 	  list_to_add = &global_symbols;
diff --git a/gdb/testsuite/gdb.cp/nsalias.cc b/gdb/testsuite/gdb.cp/nsalias.cc
new file mode 100644
index 0000000..be2dfbe
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/nsalias.cc
@@ -0,0 +1,23 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2013 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 <http://www.gnu.org/licenses/>.  */
+
+int
+main ()
+{
+  return 0;
+}
+
diff --git a/gdb/testsuite/gdb.cp/nsalias.exp b/gdb/testsuite/gdb.cp/nsalias.exp
new file mode 100644
index 0000000..a23f293
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/nsalias.exp
@@ -0,0 +1,226 @@
+# Copyright 2013 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 <http://www.gnu.org/licenses/>.
+
+# Test namespace aliases.
+# PRs c++/7935, c++/10541
+
+load_lib dwarf.exp
+
+if {![dwarf2_support]} {
+    return 0
+}
+
+if {[skip_cplus_tests]} {
+    continue
+}
+
+standard_testfile .cc nsalias-dw.S
+
+# Make the DWARF used for the test.  This is necessary to work
+# around compiler issues.  Not all versions of gcc output the
+# correct debuginfo we need.
+#
+# This should create the equivalent DWARF to:
+#
+# namespace outer
+# {
+#   namespace inner
+#   {
+#     namespace innermost
+#     {
+#       const int x = 2;
+#       int foo (void) { return x; }
+#     }
+#
+#     namespace Innermost = innermost;
+#
+#     const int x = 1;
+#     int foo (void) { return x + Innermost::foo (); }
+#   }
+#
+#   namespace Inner = inner;
+#
+#   const int x = 0;
+#   int foo (void) { return x + Inner::foo (); }
+# }
+#
+# namespace Outer = outer;
+
+set asm_file [standard_output_file $srcfile2]
+Dwarf::assemble $asm_file {
+    cu {} {
+	compile_unit {{language @DW_LANG_C_plus_plus}} {
+	    declare_labels int_label outer_label inner_label innermost_label
+	    declare_labels im_foo_label i_foo_label o_foo_label
+
+	    int_label: base_type {
+		{name int}
+		{encoding @DW_ATE_signed}
+		{byte_size 4 DW_FORM_sdata}
+	    }
+
+	    outer_label: DW_TAG_namespace {
+		{name outer}
+	    } {
+		inner_label: DW_TAG_namespace {
+		    {name inner}
+		} {
+		    innermost_label: DW_TAG_namespace {
+			{name innermost}
+		    } {
+			DW_TAG_variable {
+			    {name x}
+			    {type :$int_label}
+			    {const_value 2 DW_FORM_data1}
+			}
+
+			im_foo_label: DW_TAG_subprogram {
+			    {name foo}
+			    {external 1}
+			    {declaration 1}
+			}
+		    }
+
+		    imported_declaration {
+			{name Innermost}
+			{import :$innermost_label}
+		    }
+
+		    DW_TAG_variable {
+			{name x}
+			{type :$int_label}
+			{const_value 1 DW_FORM_data1}
+		    }
+
+		    i_foo_label: subprogram {
+			{name foo}
+			{external 1}
+			{declaration 1}
+		    }
+		}
+
+		imported_declaration {
+		    {name Inner}
+		    {import :$inner_label}
+		}
+
+		DW_TAG_variable {
+		    {name x}
+		    {type :$int_label}
+		    {const_value 0 DW_FORM_data1}
+		}
+
+		o_foo_label: subprogram {
+		    {name foo}
+		    {external 1}
+		    {declaration 1}
+		}
+	    }
+
+	    imported_declaration {
+		{name Outer}
+		{import :$outer_label}
+	    }
+
+	    subprogram {
+		{specification :$im_foo_label}
+		{low_pc 0x0}
+		{high_pc 0x1}
+	    }
+
+	    subprogram {
+		{specification :$i_foo_label}
+		{low_pc 0x2}
+		{high_pc 0x3}
+	    }
+
+	    subprogram {
+		{specification :$o_foo_label}
+		{low_pc 0x4}
+		{high_pc 0x5}
+	    }
+	}
+    }
+}
+
+if {[gdb_compile $srcdir/$subdir/$srcfile ${binfile}1.o \
+	 object {c++ debug}] != ""} {
+    return -1
+}
+
+if {[gdb_compile $asm_file ${binfile}2.o object {nodebug}] != ""} {
+    return -1
+}
+
+if {[gdb_compile [list ${binfile}1.o ${binfile}2.o] \
+	 $binfile executable {c++}] != ""} {
+    return -1
+}
+
+clean_restart $testfile
+
+# A procedure to run various tests on aliased namespaces.
+proc do_alias_tests {ns} {
+
+    # The "real" namespace is simply NS in all lowercase.
+    set real [string tolower $ns]
+
+    # The value of `x' is the number of '::' in NS.
+    set x [expr {[llength [split $ns ":"]] / 2}]
+
+    # Test "whatis"
+    gdb_test "whatis $ns" "type = $real"
+
+    # Test "ptype"
+    gdb_test "ptype $ns" "type = namespace $real"
+
+    # Print 'x'
+    send_log "expecting x = $x\n"
+    gdb_test "print ${ns}::x" " = $x"
+
+    # Attempt to list the function.
+    gdb_test_no_output "list ${ns}::foo"
+
+    # Attempt to break on the start of the function.
+    gdb_breakpoint "*${ns}::foo"
+
+    # And then erase it
+    with_test_prefix "($ns)" {
+	gdb_test_no_output "delete \$bpnum"
+    }
+}
+
+# This is a list of all the permutations to be tested.  For troubleshooting
+# purposes, this list is explicitly enumerated.
+
+set permutations {}
+lappend permutations "outer"
+lappend permutations "Outer"
+lappend permutations "outer::inner"
+lappend permutations "Outer::inner"
+lappend permutations "outer::Inner"
+lappend permutations "Outer::Inner"
+lappend permutations "outer::inner::innermost"
+lappend permutations "outer::inner::Innermost"
+lappend permutations "outer::Inner::innermost"
+lappend permutations "outer::Inner::Innermost"
+lappend permutations "Outer::inner::innermost"
+lappend permutations "Outer::inner::Innermost"
+lappend permutations "Outer::Inner::innermost"
+lappend permutations "Outer::Inner::Innermost"
+
+foreach p $permutations {
+    do_alias_tests $p
+}
diff --git a/gdb/testsuite/gdb.cp/nsrecurs.exp b/gdb/testsuite/gdb.cp/nsrecurs.exp
index 0537e89..9cf4331 100644
--- a/gdb/testsuite/gdb.cp/nsrecurs.exp
+++ b/gdb/testsuite/gdb.cp/nsrecurs.exp
@@ -52,8 +52,10 @@ gdb_test "print xx" "= 999"
 # Test printing using recursive namespace
 # aliases.
 
-setup_kfail "gdb/10541" "*-*-*"
-gdb_test "ptype G::GF" "= namespace F"
+if {![test_compiler_info {gcc-[0-3]-*}]} {
+    gdb_test "ptype G::GF" "= namespace F"
 
-setup_kfail "gdb/10541" "*-*-*"
-gdb_test "print G::GF::FE::ex" "= 9999"
+    if {![test_compiler_info {gcc-4-[0-3]-*}]} {
+	gdb_test "print G::GF::FE::ex" "= 9999"
+    }
+}

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFA] Fix namespace aliases (c++/7539, c++/10541)
  2013-07-26 19:15 [RFA] Fix namespace aliases (c++/7539, c++/10541) Keith Seitz
@ 2013-07-29 20:28 ` Tom Tromey
  2013-07-30 22:44   ` Keith Seitz
  0 siblings, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2013-07-29 20:28 UTC (permalink / raw)
  To: Keith Seitz; +Cc: gdb-patches@sourceware.org ml

>>>>> "Keith" == Keith Seitz <keiths@redhat.com> writes:

Keith> This is an attempt to fix namespace alias bugs reported in c++/7539
Keith> and c++/10541.

Thanks for working on this.

Keith> @@ -212,6 +213,13 @@ inspect_type (struct demangle_parse_info *info,
Keith>  	  /* Get the real type of the typedef.  */
Keith>  	  type = check_typedef (otype);
 
Keith> +	  /* If the symbol is a namespace and its name is no different
Keith> +	     than the name we looked up, this symbol is not a namespace
Keith> +	     alias and does not need to be substituted.  */
Keith> +	  if (TYPE_CODE (otype) == TYPE_CODE_NAMESPACE
Keith> +	      && strcmp (TYPE_NAME (type), name) == 0)
Keith> +	    return 0;
Keith> +

Ok, I think I see what is going on here.  For an alias A we have a
symbol named A, whose type is the type of the referent.

I think the comment here is a bit confusing since it says "its name",
but really it means the symbol's type's name.


I'm curious how this copes with some other situations.

For example, an import of a declaration from another namespace, where
the imported declaration is itself an import.

Or, if the program is stopped in a function inside a namespace, can the
user use the "local" (not fully qualified) alias?

I don't think either of these situations is tested.

Keith> @@ -7732,6 +7736,32 @@ process_die (struct die_info *die, struct dwarf2_cu *cu)
Keith>        read_module (die, cu);
Keith>        break;
Keith>      case DW_TAG_imported_declaration:
Keith> +      {
Keith> +	struct attribute *attr;
Keith> +
Keith> +	attr = dwarf2_attr (die, DW_AT_import, cu);
Keith> +	if (attr != NULL)
Keith> +	  {
Keith> +	    /* If the die does not have a name, this is not a namespace
Keith> +	       alias.  */
Keith> +	    attr = dwarf2_attr (die, DW_AT_name, cu);
Keith> +	    if (attr != NULL)
Keith> +	      {

It's customary not to have a body of code in process_die, but to instead
call a helper function.

Tom

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFA] Fix namespace aliases (c++/7539, c++/10541)
  2013-07-29 20:28 ` Tom Tromey
@ 2013-07-30 22:44   ` Keith Seitz
  2013-07-31 18:46     ` Tom Tromey
  0 siblings, 1 reply; 7+ messages in thread
From: Keith Seitz @ 2013-07-30 22:44 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches@sourceware.org ml

[-- Attachment #1: Type: text/plain, Size: 2922 bytes --]

On 07/29/2013 01:28 PM, Tom Tromey wrote:
> Ok, I think I see what is going on here.  For an alias A we have a
> symbol named A, whose type is the type of the referent.
>
> I think the comment here is a bit confusing since it says "its name",
> but really it means the symbol's type's name.

I've updated the comment to make this less ambiguous.

> I'm curious how this copes with some other situations.
>
> For example, an import of a declaration from another namespace, where
> the imported declaration is itself an import.

I wouldn't expect a compiler to actually do this (gcc does not), but 
I've updated the code to handle this case.

BTW, while investigating this, I found a buglet in my original patch. At 
the last minute, I thought I'd be paranoid and add a test for 
DW_AT_name. Unfortunately, in my haste, I fetched DW_AT_name /after/ 
DW_AT_import. That was bad. Very bad. I've fixed this in this version.

> Or, if the program is stopped in a function inside a namespace, can the
> user use the "local" (not fully qualified) alias?

This particular feature is c++/13884. That is an entirely different 
problem. I've updated the bug with some comments explaining what's going on.

> I don't think either of these situations is tested.

I've added tests for the recursive alias. If/when I get around to fixing 
13384, I'll add tests for that.

>
> Keith> @@ -7732,6 +7736,32 @@ process_die (struct die_info *die, struct dwarf2_cu *cu)
> Keith>        read_module (die, cu);
> Keith>        break;
> Keith>      case DW_TAG_imported_declaration:
> Keith> +      {
> Keith> +	struct attribute *attr;
> Keith> +
> Keith> +	attr = dwarf2_attr (die, DW_AT_import, cu);
> Keith> +	if (attr != NULL)
> Keith> +	  {
> Keith> +	    /* If the die does not have a name, this is not a namespace
> Keith> +	       alias.  */
> Keith> +	    attr = dwarf2_attr (die, DW_AT_name, cu);
> Keith> +	    if (attr != NULL)
> Keith> +	      {
>
> It's customary not to have a body of code in process_die, but to instead
> call a helper function.

Done.

Updated patch attached.

Keith

ChangeLog
2013-07-30  Keith Seitz  <keiths@redhat.com>

	PR c++/7539
	PR c++/10541
	* cp-support.c (insepct_type): Add support for substituting
	namespace aliases, too.
	* dwarf2read.c (scan_partial_symbols): Add a partial symbol
	for DW_TAG_imported_declaration.
	(add_partial_symbol): Likewise.
	(process_die): Handle namespace aliases with
	read_namespace_alias.
	(die_needs_namespace): Add DW_TAG_imported_declaration.
	(read_namespace_alias): New function.
	(load_partial_dies): Load DW_TAG_imported_declaration, too.
	(new_symbol_full): Handle DW_TAG_imported_declaration.

testsuite/ChangeLog
2013-07-30  Keith Seitz  <keiths@redhat.com>

	PR c++/7935
	PR c++/10541
	* gdb.cp/nsalias.exp: New file.
	* gdb.cp/nsalias.cc: New file.
	* gdb.cp/nsrecurs.exp: Remove kfails. Conditionally run
	tests only on known, working compiler versions.



[-- Attachment #2: namespace-aliases.patch --]
[-- Type: text/x-patch, Size: 13098 bytes --]

diff --git a/gdb/cp-support.c b/gdb/cp-support.c
index 3c1442d..087bf0b 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -200,8 +200,9 @@ inspect_type (struct demangle_parse_info *info,
 	  return 0;
 	}
 
-      /* If the type is a typedef, replace it.  */
-      if (TYPE_CODE (otype) == TYPE_CODE_TYPEDEF)
+      /* If the type is a typedef or namespace alias, replace it.  */
+      if (TYPE_CODE (otype) == TYPE_CODE_TYPEDEF
+	  || TYPE_CODE (otype) == TYPE_CODE_NAMESPACE)
 	{
 	  long len;
 	  int is_anon;
@@ -212,6 +213,13 @@ inspect_type (struct demangle_parse_info *info,
 	  /* Get the real type of the typedef.  */
 	  type = check_typedef (otype);
 
+	  /* If the symbol is a namespace and its type name is no different
+	     than the name we looked up, this symbol is not a namespace
+	     alias and does not need to be substituted.  */
+	  if (TYPE_CODE (otype) == TYPE_CODE_NAMESPACE
+	      && strcmp (TYPE_NAME (type), name) == 0)
+	    return 0;
+
 	  is_anon = (TYPE_TAG_NAME (type) == NULL
 		     && (TYPE_CODE (type) == TYPE_CODE_ENUM
 			 || TYPE_CODE (type) == TYPE_CODE_STRUCT
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 04993c2..89799e9 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -1537,6 +1537,8 @@ static void read_module (struct die_info *die, struct dwarf2_cu *cu);
 
 static void read_import_statement (struct die_info *die, struct dwarf2_cu *);
 
+static int read_namespace_alias (struct die_info *die, struct dwarf2_cu *cu);
+
 static struct type *read_module_type (struct die_info *die,
 				      struct dwarf2_cu *cu);
 
@@ -6244,6 +6246,9 @@ scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
 			       cu->per_cu->imported_symtabs, per_cu);
 	      }
 	      break;
+	    case DW_TAG_imported_declaration:
+	      add_partial_symbol (pdi, cu);
+	      break;
 	    default:
 	      break;
 	    }
@@ -6515,6 +6520,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
 			   &objfile->static_psymbols,
 			   0, (CORE_ADDR) 0, cu->language, objfile);
       break;
+    case DW_TAG_imported_declaration:
     case DW_TAG_namespace:
       add_psymbol_to_list (actual_name, strlen (actual_name),
 			   built_actual_name != NULL,
@@ -7732,6 +7738,10 @@ process_die (struct die_info *die, struct dwarf2_cu *cu)
       read_module (die, cu);
       break;
     case DW_TAG_imported_declaration:
+      cu->processing_has_namespace_info = 1;
+      if (read_namespace_alias (die, cu))
+	break;
+      /* The declaration is not a global namespace alias: fall through.  */
     case DW_TAG_imported_module:
       cu->processing_has_namespace_info = 1;
       if (die->child != NULL && (die->tag == DW_TAG_imported_declaration
@@ -7774,6 +7784,7 @@ die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu)
     case DW_TAG_enumerator:
     case DW_TAG_subprogram:
     case DW_TAG_member:
+    case DW_TAG_imported_declaration:
       return 1;
 
     case DW_TAG_variable:
@@ -8192,6 +8203,56 @@ dwarf2_physname (const char *name, struct die_info *die, struct dwarf2_cu *cu)
   return retval;
 }
 
+/* Inspect DIE in CU for a namespace alias.  If one exists, record
+   a new symbol for it.
+
+   Returns 1 if a namespace alias was recorded, 0 otherwise.  */
+
+static int
+read_namespace_alias (struct die_info *die, struct dwarf2_cu *cu)
+{
+  struct attribute *attr;
+
+  /* If the die does not have a name, this is not a namespace
+     alias.  */
+  attr = dwarf2_attr (die, DW_AT_name, cu);
+  if (attr != NULL)
+    {
+      struct die_info *d = die;
+      struct dwarf2_cu *imported_cu = cu;
+
+      /* If the compiler has nested DW_AT_imported_declaration DIEs,
+	 keep inspecting DIEs until we hit the underlying import.  */
+      while (1)
+	{
+	  attr = dwarf2_attr (d, DW_AT_import, cu);
+	  if (attr == NULL)
+	    break;
+
+	  d = follow_die_ref (d, attr, &imported_cu);
+	  if (d->tag != DW_TAG_imported_declaration)
+	    break;
+	}
+
+      if (attr != NULL)
+	{
+	  struct type *type;
+	  sect_offset offset = dwarf2_get_ref_die_offset (attr);
+
+	  type = get_die_type_at_offset (offset, cu->per_cu);
+	  if (type != NULL && TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
+	    {
+	      /* This declaration is a global namespace alias.  Add
+		 a symbol for it whose type is the aliased namespace.  */
+	      new_symbol (die, type, cu);
+	      return 1;
+	    }
+	}
+    }
+
+  return 0;
+}
+
 /* Read the import statement specified by the given die and record it.  */
 
 static void
@@ -14013,7 +14074,8 @@ load_partial_dies (const struct die_reader_specs *reader,
 	  && abbrev->tag != DW_TAG_namespace
 	  && abbrev->tag != DW_TAG_module
 	  && abbrev->tag != DW_TAG_member
-	  && abbrev->tag != DW_TAG_imported_unit)
+	  && abbrev->tag != DW_TAG_imported_unit
+	  && abbrev->tag != DW_TAG_imported_declaration)
 	{
 	  /* Otherwise we skip to the next sibling, if any.  */
 	  info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev);
@@ -16731,6 +16793,7 @@ new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
 			   ? &global_symbols : cu->list_in_scope);
 	  }
 	  break;
+	case DW_TAG_imported_declaration:
 	case DW_TAG_namespace:
 	  SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
 	  list_to_add = &global_symbols;
diff --git a/gdb/testsuite/gdb.cp/nsalias.cc b/gdb/testsuite/gdb.cp/nsalias.cc
new file mode 100644
index 0000000..be2dfbe
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/nsalias.cc
@@ -0,0 +1,23 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2013 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 <http://www.gnu.org/licenses/>.  */
+
+int
+main ()
+{
+  return 0;
+}
+
diff --git a/gdb/testsuite/gdb.cp/nsalias.exp b/gdb/testsuite/gdb.cp/nsalias.exp
new file mode 100644
index 0000000..18f32b2
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/nsalias.exp
@@ -0,0 +1,254 @@
+# Copyright 2013 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 <http://www.gnu.org/licenses/>.
+
+# Test namespace aliases.
+# PRs c++/7935, c++/10541
+
+load_lib dwarf.exp
+
+if {![dwarf2_support]} {
+    return 0
+}
+
+if {[skip_cplus_tests]} {
+    continue
+}
+
+standard_testfile .cc nsalias-dw.S
+
+# Make the DWARF used for the test.  This is necessary to work
+# around compiler issues.  Not all versions of gcc output the
+# correct debuginfo we need.
+#
+# This should create the equivalent DWARF to:
+#
+# namespace outer
+# {
+#   namespace inner
+#   {
+#     namespace innermost
+#     {
+#       const int x = 2;
+#       int foo (void) { return x; }
+#     }
+#
+#     namespace Innermost = innermost;
+#
+#     const int x = 1;
+#     int foo (void) { return x + Innermost::foo (); }
+#   }
+#
+#   namespace Inner = inner;
+#
+#   const int x = 0;
+#   int foo (void) { return x + Inner::foo (); }
+# }
+#
+# namespace Outer = outer;
+# namespace oi = Outer::Inner;
+
+set asm_file [standard_output_file $srcfile2]
+Dwarf::assemble $asm_file {
+    cu {} {
+	compile_unit {{language @DW_LANG_C_plus_plus}} {
+	    declare_labels int_label outer_label inner_label innermost_label
+	    declare_labels im_foo_label i_foo_label o_foo_label
+	    declare_labels OuterInner_label oi1_label oi2_label
+
+	    int_label: base_type {
+		{name int}
+		{encoding @DW_ATE_signed}
+		{byte_size 4 DW_FORM_sdata}
+	    }
+
+	    outer_label: DW_TAG_namespace {
+		{name outer}
+	    } {
+		inner_label: DW_TAG_namespace {
+		    {name inner}
+		} {
+		    innermost_label: DW_TAG_namespace {
+			{name innermost}
+		    } {
+			DW_TAG_variable {
+			    {name x}
+			    {type :$int_label}
+			    {const_value 2 DW_FORM_data1}
+			}
+
+			im_foo_label: DW_TAG_subprogram {
+			    {name foo}
+			    {external 1}
+			    {declaration 1}
+			}
+		    }
+
+		    imported_declaration {
+			{name Innermost}
+			{import :$innermost_label}
+		    }
+
+		    DW_TAG_variable {
+			{name x}
+			{type :$int_label}
+			{const_value 1 DW_FORM_data1}
+		    }
+
+		    i_foo_label: subprogram {
+			{name foo}
+			{external 1}
+			{declaration 1}
+		    }
+		}
+
+		OuterInner_label: imported_declaration {
+		    {name Inner}
+		    {import :$inner_label}
+		}
+
+		DW_TAG_variable {
+		    {name x}
+		    {type :$int_label}
+		    {const_value 0 DW_FORM_data1}
+		}
+
+		o_foo_label: subprogram {
+		    {name foo}
+		    {external 1}
+		    {declaration 1}
+		}
+	    }
+
+	    imported_declaration {
+		{name Outer}
+		{import :$outer_label}
+	    }
+
+	    oi1_label: imported_declaration {
+		{name oi1}
+		{import :$OuterInner_label}
+	    }
+
+	    oi2_label: imported_declaration {
+		{name oi2}
+		{import :$oi1_label}
+	    }
+
+	    imported_declaration {
+		{name oi3}
+		{import :$oi2_label}
+	    }
+
+	    subprogram {
+		{specification :$im_foo_label}
+		{low_pc 0x0}
+		{high_pc 0x1}
+	    }
+
+	    subprogram {
+		{specification :$i_foo_label}
+		{low_pc 0x2}
+		{high_pc 0x3}
+	    }
+
+	    subprogram {
+		{specification :$o_foo_label}
+		{low_pc 0x4}
+		{high_pc 0x5}
+	    }
+	}
+    }
+}
+
+if {[gdb_compile $srcdir/$subdir/$srcfile ${binfile}1.o \
+	 object {c++ debug}] != ""} {
+    return -1
+}
+
+if {[gdb_compile $asm_file ${binfile}2.o object {nodebug}] != ""} {
+    return -1
+}
+
+if {[gdb_compile [list ${binfile}1.o ${binfile}2.o] \
+	 $binfile executable {c++}] != ""} {
+    return -1
+}
+
+clean_restart $testfile
+
+# A procedure to run various tests on aliased namespaces.
+proc do_alias_tests {ns {real ""} {x ""}} {
+
+    # The "real" namespace is simply NS in all lowercase.
+    if {$real == ""} {
+	set real [string tolower $ns]
+    }
+
+    # The value of `x' is the number of '::' in NS.
+    if {$x == ""} {
+	set x [expr {[llength [split $ns ":"]] / 2}]
+    }
+
+    # Test "whatis"
+    gdb_test "whatis $ns" "type = $real"
+
+    # Test "ptype"
+    gdb_test "ptype $ns" "type = namespace $real"
+
+    # Print 'x'
+    send_log "expecting x = $x\n"
+    gdb_test "print ${ns}::x" " = $x"
+
+    # Attempt to list the function.
+    gdb_test_no_output "list ${ns}::foo"
+
+    # Attempt to break on the start of the function.
+    gdb_breakpoint "*${ns}::foo"
+
+    # And then erase it
+    with_test_prefix "($ns)" {
+	gdb_test_no_output "delete \$bpnum"
+    }
+}
+
+# This is a list of all the permutations to be tested.  For troubleshooting
+# purposes, this list is explicitly enumerated.
+
+set permutations {}
+lappend permutations "outer"
+lappend permutations "Outer"
+lappend permutations "outer::inner"
+lappend permutations "Outer::inner"
+lappend permutations "outer::Inner"
+lappend permutations "Outer::Inner"
+lappend permutations "outer::inner::innermost"
+lappend permutations "outer::inner::Innermost"
+lappend permutations "outer::Inner::innermost"
+lappend permutations "outer::Inner::Innermost"
+lappend permutations "Outer::inner::innermost"
+lappend permutations "Outer::inner::Innermost"
+lappend permutations "Outer::Inner::innermost"
+lappend permutations "Outer::Inner::Innermost"
+
+foreach p $permutations {
+    do_alias_tests $p
+}
+
+# Test recursively imported aliases.
+foreach ns {"oi1" "oi2" "oi3"} {
+    do_alias_tests $ns "outer::inner" 1
+    do_alias_tests "${ns}::innermost" "outer::inner::innermost" 2
+    do_alias_tests "${ns}::Innermost" "outer::inner::innermost" 2
+}
diff --git a/gdb/testsuite/gdb.cp/nsrecurs.exp b/gdb/testsuite/gdb.cp/nsrecurs.exp
index 0537e89..9cf4331 100644
--- a/gdb/testsuite/gdb.cp/nsrecurs.exp
+++ b/gdb/testsuite/gdb.cp/nsrecurs.exp
@@ -52,8 +52,10 @@ gdb_test "print xx" "= 999"
 # Test printing using recursive namespace
 # aliases.
 
-setup_kfail "gdb/10541" "*-*-*"
-gdb_test "ptype G::GF" "= namespace F"
+if {![test_compiler_info {gcc-[0-3]-*}]} {
+    gdb_test "ptype G::GF" "= namespace F"
 
-setup_kfail "gdb/10541" "*-*-*"
-gdb_test "print G::GF::FE::ex" "= 9999"
+    if {![test_compiler_info {gcc-4-[0-3]-*}]} {
+	gdb_test "print G::GF::FE::ex" "= 9999"
+    }
+}

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFA] Fix namespace aliases (c++/7539, c++/10541)
  2013-07-30 22:44   ` Keith Seitz
@ 2013-07-31 18:46     ` Tom Tromey
  2013-09-17 23:03       ` Keith Seitz
  0 siblings, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2013-07-31 18:46 UTC (permalink / raw)
  To: Keith Seitz; +Cc: gdb-patches@sourceware.org ml

>>>>> "Keith" == Keith Seitz <keiths@redhat.com> writes:

Tom> Or, if the program is stopped in a function inside a namespace, can the
Tom> user use the "local" (not fully qualified) alias?

Keith> This particular feature is c++/13884. That is an entirely different
Keith> problem. I've updated the bug with some comments explaining what's
Keith> going on.

Ok, thanks.

Tom> I don't think either of these situations is tested.

Keith> I've added tests for the recursive alias. If/when I get around to
Keith> fixing 13384, I'll add tests for that.

Sounds good.

I was also curious why the new type is a TYPE_CODE_NAMESPACE and not a
TYPE_CODE_TYPEDEF.  Maybe that is too goofy though.

Keith> +      /* If the compiler has nested DW_AT_imported_declaration DIEs,
Keith> +	 keep inspecting DIEs until we hit the underlying import.  */
Keith> +      while (1)
Keith> +	{
Keith> +	  attr = dwarf2_attr (d, DW_AT_import, cu);
Keith> +	  if (attr == NULL)
Keith> +	    break;
Keith> +
Keith> +	  d = follow_die_ref (d, attr, &imported_cu);
Keith> +	  if (d->tag != DW_TAG_imported_declaration)
Keith> +	    break;
Keith> +	}

Now I'm concerned that bad DWARF can send gdb into an infinite loop
here.

Sorry about that.  If compilers don't emit chained imports like this,
then it is fine to just go back to the old code.

Otherwise I guess we'd need the tortoise-and-hare thing here.

Tom

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFA] Fix namespace aliases (c++/7539, c++/10541)
  2013-07-31 18:46     ` Tom Tromey
@ 2013-09-17 23:03       ` Keith Seitz
  2013-11-06 22:03         ` Tom Tromey
  0 siblings, 1 reply; 7+ messages in thread
From: Keith Seitz @ 2013-09-17 23:03 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches@sourceware.org ml

[-- Attachment #1: Type: text/plain, Size: 2172 bytes --]

On 07/31/2013 11:46 AM, Tom Tromey wrote:
    ^^^^^^^^^^
Wow, it has taken a bit longer to rotate this back onto my plate than 
I'd hoped. Sorry for the long delay.

>>>>>> "Keith" == Keith Seitz <keiths@redhat.com> writes:
>
> I was also curious why the new type is a TYPE_CODE_NAMESPACE and not a
> TYPE_CODE_TYPEDEF.  Maybe that is too goofy though.

That sounded goofy to me, too. I think neither choice is exactly what we 
(I?) want to describe. I happened to pick TYPE_CODE_NAMESPACE as the 
more appropriate choice.

> Now I'm concerned that bad DWARF can send gdb into an infinite loop
> here.

Ha, yeah. That's a little aggressive on my part.

> Sorry about that.  If compilers don't emit chained imports like this,
> then it is fine to just go back to the old code.

While there's no reason for a compiler to do this, there's also no 
reason one couldn't. So I've decided to play it safe and leave the code, 
fenceposting the maximum number of lookups that the code will do. Right 
now, I've randomly selected 200 imports as the limit.

When this limit is exceeded, it will issue a complaint (and stop 
attempting to read the import). This seems to be the norm in dwarf2read.c.

I've added an additional test case which generates arbitrary depth 
recursive imported declarations and checks for the complaint.

Keith

ChangeLog
2013-09-17  Keith Seitz  <keiths@redhat.com>

	PR c++/7539
	PR c++/10541
	* cp-support.c (insepct_type): Add support for substituting
	namespace aliases, too.
	* dwarf2read.c (scan_partial_symbols): Add a partial symbol
	for DW_TAG_imported_declaration.
	(add_partial_symbol): Likewise.
	(process_die): Handle namespace aliases with
	read_namespace_alias.
	(die_needs_namespace): Add DW_TAG_imported_declaration.
	(read_namespace_alias): New function.
	(load_partial_dies): Load DW_TAG_imported_declaration, too.
	(new_symbol_full): Handle DW_TAG_imported_declaration.

testsuite/ChangeLog
2013-09-17  Keith Seitz  <keiths@redhat.com>

	PR c++/7935
	PR c++/10541
	* gdb.cp/nsalias.exp: New file.
	* gdb.cp/nsalias.cc: New file.
	* gdb.cp/nsrecurs.exp: Remove kfails. Conditionally run
	tests only on known, working compiler versions.


[-- Attachment #2: namespace-aliases-2.patch --]
[-- Type: text/x-patch, Size: 14868 bytes --]

diff --git a/gdb/cp-support.c b/gdb/cp-support.c
index 86f19de..b91bcdc 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -198,8 +198,9 @@ inspect_type (struct demangle_parse_info *info,
 	  return 0;
 	}
 
-      /* If the type is a typedef, replace it.  */
-      if (TYPE_CODE (otype) == TYPE_CODE_TYPEDEF)
+      /* If the type is a typedef or namespace alias, replace it.  */
+      if (TYPE_CODE (otype) == TYPE_CODE_TYPEDEF
+	  || TYPE_CODE (otype) == TYPE_CODE_NAMESPACE)
 	{
 	  long len;
 	  int is_anon;
@@ -210,6 +211,13 @@ inspect_type (struct demangle_parse_info *info,
 	  /* Get the real type of the typedef.  */
 	  type = check_typedef (otype);
 
+	  /* If the symbol is a namespace and its type name is no different
+	     than the name we looked up, this symbol is not a namespace
+	     alias and does not need to be substituted.  */
+	  if (TYPE_CODE (otype) == TYPE_CODE_NAMESPACE
+	      && strcmp (TYPE_NAME (type), name) == 0)
+	    return 0;
+
 	  is_anon = (TYPE_TAG_NAME (type) == NULL
 		     && (TYPE_CODE (type) == TYPE_CODE_ENUM
 			 || TYPE_CODE (type) == TYPE_CODE_STRUCT
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 4b30e6e..cd954ee 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -1548,6 +1548,8 @@ static void read_module (struct die_info *die, struct dwarf2_cu *cu);
 
 static void read_import_statement (struct die_info *die, struct dwarf2_cu *);
 
+static int read_namespace_alias (struct die_info *die, struct dwarf2_cu *cu);
+
 static struct type *read_module_type (struct die_info *die,
 				      struct dwarf2_cu *cu);
 
@@ -6235,6 +6237,9 @@ scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
 			       cu->per_cu->imported_symtabs, per_cu);
 	      }
 	      break;
+	    case DW_TAG_imported_declaration:
+	      add_partial_symbol (pdi, cu);
+	      break;
 	    default:
 	      break;
 	    }
@@ -6506,6 +6511,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
 			   &objfile->static_psymbols,
 			   0, (CORE_ADDR) 0, cu->language, objfile);
       break;
+    case DW_TAG_imported_declaration:
     case DW_TAG_namespace:
       add_psymbol_to_list (actual_name, strlen (actual_name),
 			   built_actual_name != NULL,
@@ -7762,6 +7768,10 @@ process_die (struct die_info *die, struct dwarf2_cu *cu)
       read_module (die, cu);
       break;
     case DW_TAG_imported_declaration:
+      cu->processing_has_namespace_info = 1;
+      if (read_namespace_alias (die, cu))
+	break;
+      /* The declaration is not a global namespace alias: fall through.  */
     case DW_TAG_imported_module:
       cu->processing_has_namespace_info = 1;
       if (die->child != NULL && (die->tag == DW_TAG_imported_declaration
@@ -7804,6 +7814,7 @@ die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu)
     case DW_TAG_enumerator:
     case DW_TAG_subprogram:
     case DW_TAG_member:
+    case DW_TAG_imported_declaration:
       return 1;
 
     case DW_TAG_variable:
@@ -8222,6 +8233,66 @@ dwarf2_physname (const char *name, struct die_info *die, struct dwarf2_cu *cu)
   return retval;
 }
 
+/* Inspect DIE in CU for a namespace alias.  If one exists, record
+   a new symbol for it.
+
+   Returns 1 if a namespace alias was recorded, 0 otherwise.  */
+
+static int
+read_namespace_alias (struct die_info *die, struct dwarf2_cu *cu)
+{
+  struct attribute *attr;
+
+  /* If the die does not have a name, this is not a namespace
+     alias.  */
+  attr = dwarf2_attr (die, DW_AT_name, cu);
+  if (attr != NULL)
+    {
+      int num;
+      struct die_info *d = die;
+      struct dwarf2_cu *imported_cu = cu;
+
+      /* If the compiler has nested DW_AT_imported_declaration DIEs,
+	 keep inspecting DIEs until we hit the underlying import.  */
+#define MAX_NESTED_IMPORTED_DECLARATIONS 100
+      for (num = 0; num  < MAX_NESTED_IMPORTED_DECLARATIONS; ++num)
+	{
+	  attr = dwarf2_attr (d, DW_AT_import, cu);
+	  if (attr == NULL)
+	    break;
+
+	  d = follow_die_ref (d, attr, &imported_cu);
+	  if (d->tag != DW_TAG_imported_declaration)
+	    break;
+	}
+
+      if (num == MAX_NESTED_IMPORTED_DECLARATIONS)
+	{
+	  complaint (&symfile_complaints,
+		     _("DIE at 0x%x has too many recursively imported "
+		       "declarations"), d->offset.sect_off);
+	  return 0;
+	}
+
+      if (attr != NULL)
+	{
+	  struct type *type;
+	  sect_offset offset = dwarf2_get_ref_die_offset (attr);
+
+	  type = get_die_type_at_offset (offset, cu->per_cu);
+	  if (type != NULL && TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
+	    {
+	      /* This declaration is a global namespace alias.  Add
+		 a symbol for it whose type is the aliased namespace.  */
+	      new_symbol (die, type, cu);
+	      return 1;
+	    }
+	}
+    }
+
+  return 0;
+}
+
 /* Read the import statement specified by the given die and record it.  */
 
 static void
@@ -14092,7 +14163,8 @@ load_partial_dies (const struct die_reader_specs *reader,
 	  && abbrev->tag != DW_TAG_namespace
 	  && abbrev->tag != DW_TAG_module
 	  && abbrev->tag != DW_TAG_member
-	  && abbrev->tag != DW_TAG_imported_unit)
+	  && abbrev->tag != DW_TAG_imported_unit
+	  && abbrev->tag != DW_TAG_imported_declaration)
 	{
 	  /* Otherwise we skip to the next sibling, if any.  */
 	  info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev);
@@ -16810,6 +16882,7 @@ new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
 			   ? &global_symbols : cu->list_in_scope);
 	  }
 	  break;
+	case DW_TAG_imported_declaration:
 	case DW_TAG_namespace:
 	  SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
 	  list_to_add = &global_symbols;
diff --git a/gdb/testsuite/gdb.cp/nsalias.cc b/gdb/testsuite/gdb.cp/nsalias.cc
new file mode 100644
index 0000000..be2dfbe
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/nsalias.cc
@@ -0,0 +1,23 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2013 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 <http://www.gnu.org/licenses/>.  */
+
+int
+main ()
+{
+  return 0;
+}
+
diff --git a/gdb/testsuite/gdb.cp/nsalias.exp b/gdb/testsuite/gdb.cp/nsalias.exp
new file mode 100644
index 0000000..61bf72f
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/nsalias.exp
@@ -0,0 +1,322 @@
+# Copyright 2013 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 <http://www.gnu.org/licenses/>.
+
+# Test namespace aliases.
+# PRs c++/7935, c++/10541
+
+load_lib dwarf.exp
+
+if {![dwarf2_support]} {
+    return 0
+}
+
+if {[skip_cplus_tests]} {
+    continue
+}
+
+standard_testfile .cc nsalias-dw.S
+
+# Make the DWARF used for the test.  This is necessary to work
+# around compiler issues.  Not all versions of gcc output the
+# correct debuginfo we need.
+#
+# This should create the equivalent DWARF to:
+#
+# namespace outer
+# {
+#   namespace inner
+#   {
+#     namespace innermost
+#     {
+#       const int x = 2;
+#       int foo (void) { return x; }
+#     }
+#
+#     namespace Innermost = innermost;
+#
+#     const int x = 1;
+#     int foo (void) { return x + Innermost::foo (); }
+#   }
+#
+#   namespace Inner = inner;
+#
+#   const int x = 0;
+#   int foo (void) { return x + Inner::foo (); }
+# }
+#
+# namespace Outer = outer;
+# namespace oi = Outer::Inner;
+
+set asm_file [standard_output_file $srcfile2]
+Dwarf::assemble $asm_file {
+    cu {} {
+	compile_unit {{language @DW_LANG_C_plus_plus}} {
+	    declare_labels int_label outer_label inner_label innermost_label
+	    declare_labels im_foo_label i_foo_label o_foo_label
+	    declare_labels OuterInner_label oi1_label oi2_label
+
+	    int_label: base_type {
+		{name int}
+		{encoding @DW_ATE_signed}
+		{byte_size 4 DW_FORM_sdata}
+	    }
+
+	    outer_label: DW_TAG_namespace {
+		{name outer}
+	    } {
+		inner_label: DW_TAG_namespace {
+		    {name inner}
+		} {
+		    innermost_label: DW_TAG_namespace {
+			{name innermost}
+		    } {
+			DW_TAG_variable {
+			    {name x}
+			    {type :$int_label}
+			    {const_value 2 DW_FORM_data1}
+			}
+
+			im_foo_label: DW_TAG_subprogram {
+			    {name foo}
+			    {external 1}
+			    {declaration 1}
+			}
+		    }
+
+		    imported_declaration {
+			{name Innermost}
+			{import :$innermost_label}
+		    }
+
+		    DW_TAG_variable {
+			{name x}
+			{type :$int_label}
+			{const_value 1 DW_FORM_data1}
+		    }
+
+		    i_foo_label: subprogram {
+			{name foo}
+			{external 1}
+			{declaration 1}
+		    }
+		}
+
+		OuterInner_label: imported_declaration {
+		    {name Inner}
+		    {import :$inner_label}
+		}
+
+		DW_TAG_variable {
+		    {name x}
+		    {type :$int_label}
+		    {const_value 0 DW_FORM_data1}
+		}
+
+		o_foo_label: subprogram {
+		    {name foo}
+		    {external 1}
+		    {declaration 1}
+		}
+	    }
+
+	    imported_declaration {
+		{name Outer}
+		{import :$outer_label}
+	    }
+
+	    oi1_label: imported_declaration {
+		{name oi1}
+		{import :$OuterInner_label}
+	    }
+
+	    oi2_label: imported_declaration {
+		{name oi2}
+		{import :$oi1_label}
+	    }
+
+	    imported_declaration {
+		{name oi3}
+		{import :$oi2_label}
+	    }
+
+	    subprogram {
+		{specification :$im_foo_label}
+		{low_pc 0x0}
+		{high_pc 0x1}
+	    }
+
+	    subprogram {
+		{specification :$i_foo_label}
+		{low_pc 0x2}
+		{high_pc 0x3}
+	    }
+
+	    subprogram {
+		{specification :$o_foo_label}
+		{low_pc 0x4}
+		{high_pc 0x5}
+	    }
+	}
+    }
+}
+
+if {[gdb_compile $srcdir/$subdir/$srcfile ${binfile}1.o \
+	 object {c++ debug}] != ""} {
+    return -1
+}
+
+if {[gdb_compile $asm_file ${binfile}2.o object {nodebug}] != ""} {
+    return -1
+}
+
+if {[gdb_compile [list ${binfile}1.o ${binfile}2.o] \
+	 $binfile executable {c++}] != ""} {
+    return -1
+}
+
+clean_restart $testfile
+
+# A procedure to run various tests on aliased namespaces.
+proc do_alias_tests {ns {real ""} {x ""}} {
+
+    # The "real" namespace is simply NS in all lowercase.
+    if {$real == ""} {
+	set real [string tolower $ns]
+    }
+
+    # The value of `x' is the number of '::' in NS.
+    if {$x == ""} {
+	set x [expr {[llength [split $ns ":"]] / 2}]
+    }
+
+    # Test "whatis"
+    gdb_test "whatis $ns" "type = $real"
+
+    # Test "ptype"
+    gdb_test "ptype $ns" "type = namespace $real"
+
+    # Print 'x'
+    send_log "expecting x = $x\n"
+    gdb_test "print ${ns}::x" " = $x"
+
+    # Attempt to list the function.
+    gdb_test_no_output "list ${ns}::foo"
+
+    # Attempt to break on the start of the function.
+    gdb_breakpoint "*${ns}::foo"
+
+    # And then erase it
+    with_test_prefix "($ns)" {
+	gdb_test_no_output "delete \$bpnum"
+    }
+}
+
+# This is a list of all the permutations to be tested.  For troubleshooting
+# purposes, this list is explicitly enumerated.
+
+set permutations {}
+lappend permutations "outer"
+lappend permutations "Outer"
+lappend permutations "outer::inner"
+lappend permutations "Outer::inner"
+lappend permutations "outer::Inner"
+lappend permutations "Outer::Inner"
+lappend permutations "outer::inner::innermost"
+lappend permutations "outer::inner::Innermost"
+lappend permutations "outer::Inner::innermost"
+lappend permutations "outer::Inner::Innermost"
+lappend permutations "Outer::inner::innermost"
+lappend permutations "Outer::inner::Innermost"
+lappend permutations "Outer::Inner::innermost"
+lappend permutations "Outer::Inner::Innermost"
+
+foreach p $permutations {
+    do_alias_tests $p
+}
+
+# Test recursively imported aliases.
+foreach ns {"oi1" "oi2" "oi3"} {
+    do_alias_tests $ns "outer::inner" 1
+    do_alias_tests "${ns}::innermost" "outer::inner::innermost" 2
+    do_alias_tests "${ns}::Innermost" "outer::inner::innermost" 2
+}
+
+# Generate another objfile with nested imported declarations.
+
+set imports {
+    declare_labels n0_label
+
+    n0_label: DW_TAG_namespace {
+	{name n0}
+    } {
+	DW_TAG_variable {
+	    {name x}
+	    {type :$int_label}
+	    {const_value 3 DW_FORM_data1}
+	}
+    }
+
+    declare_labels n0_import
+    n0_import: imported_declaration {
+	{name N0}
+	{import :$n0_label}
+    }
+}
+
+for {set i 1} {$i <= 100} {incr i} {
+    append imports [format "
+	declare_labels n%d_import
+	n%d_import: imported_declaration {
+	    {name N%d}
+	    {import :\$n%d_import}
+	}" $i $i $i [expr {$i - 1}]]
+}
+
+standard_testfile .cc nsalias-r-dw.S
+
+set asm_file [standard_output_file $srcfile2]
+set the_dwarf [format {
+    cu {} {
+	compile_unit {{language @DW_LANG_C_plus_plus}} {
+	    declare_labels int_label n0_label
+
+	    int_label: base_type {
+		{name int}
+		{encoding @DW_ATE_signed}
+		{byte_size 4 DW_FORM_sdata}
+	    }
+
+%s
+	}
+    }
+} $imports]
+
+Dwarf::assemble $asm_file $the_dwarf
+
+if {[gdb_compile $asm_file ${binfile}3.o object {nodebug}] != ""} {
+    return -1
+}
+
+if {[gdb_compile [list ${binfile}1.o ${binfile}3.o] \
+	 ${binfile}-r executable {c++}] != ""} {
+    return -1
+}
+
+clean_restart ${testfile}-r
+
+gdb_test_no_output "set complaints 1"
+gdb_test "print N100::x" \
+    ".* has too many recursively imported declarations.*" \
+    "compaint for too many recursively imported declarations"
diff --git a/gdb/testsuite/gdb.cp/nsrecurs.exp b/gdb/testsuite/gdb.cp/nsrecurs.exp
index 0537e89..9cf4331 100644
--- a/gdb/testsuite/gdb.cp/nsrecurs.exp
+++ b/gdb/testsuite/gdb.cp/nsrecurs.exp
@@ -52,8 +52,10 @@ gdb_test "print xx" "= 999"
 # Test printing using recursive namespace
 # aliases.
 
-setup_kfail "gdb/10541" "*-*-*"
-gdb_test "ptype G::GF" "= namespace F"
+if {![test_compiler_info {gcc-[0-3]-*}]} {
+    gdb_test "ptype G::GF" "= namespace F"
 
-setup_kfail "gdb/10541" "*-*-*"
-gdb_test "print G::GF::FE::ex" "= 9999"
+    if {![test_compiler_info {gcc-4-[0-3]-*}]} {
+	gdb_test "print G::GF::FE::ex" "= 9999"
+    }
+}

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFA] Fix namespace aliases (c++/7539, c++/10541)
  2013-09-17 23:03       ` Keith Seitz
@ 2013-11-06 22:03         ` Tom Tromey
  2013-11-14  0:44           ` Keith Seitz
  0 siblings, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2013-11-06 22:03 UTC (permalink / raw)
  To: Keith Seitz; +Cc: gdb-patches@sourceware.org ml

>>>>> "Keith" == Keith Seitz <keiths@redhat.com> writes:

Keith> On 07/31/2013 11:46 AM, Tom Tromey wrote:
Keith>    ^^^^^^^^^^
Keith> Wow, it has taken a bit longer to rotate this back onto my plate than
Keith> I'd hoped. Sorry for the long delay.

Right back at you :-)

Keith> 2013-09-17  Keith Seitz  <keiths@redhat.com>

Keith> 	PR c++/7539
Keith> 	PR c++/10541
Keith> 	* cp-support.c (insepct_type): Add support for substituting
Keith> 	namespace aliases, too.
Keith> 	* dwarf2read.c (scan_partial_symbols): Add a partial symbol
Keith> 	for DW_TAG_imported_declaration.
Keith> 	(add_partial_symbol): Likewise.
Keith> 	(process_die): Handle namespace aliases with
Keith> 	read_namespace_alias.
Keith> 	(die_needs_namespace): Add DW_TAG_imported_declaration.
Keith> 	(read_namespace_alias): New function.
Keith> 	(load_partial_dies): Load DW_TAG_imported_declaration, too.
Keith> 	(new_symbol_full): Handle DW_TAG_imported_declaration.

Keith> testsuite/ChangeLog
Keith> 2013-09-17  Keith Seitz  <keiths@redhat.com>

Keith> 	PR c++/7935
Keith> 	PR c++/10541
Keith> 	* gdb.cp/nsalias.exp: New file.
Keith> 	* gdb.cp/nsalias.cc: New file.
Keith> 	* gdb.cp/nsrecurs.exp: Remove kfails. Conditionally run
Keith> 	tests only on known, working compiler versions.

This is ok.  Thanks, and sorry again for the delay.

Tom

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFA] Fix namespace aliases (c++/7539, c++/10541)
  2013-11-06 22:03         ` Tom Tromey
@ 2013-11-14  0:44           ` Keith Seitz
  0 siblings, 0 replies; 7+ messages in thread
From: Keith Seitz @ 2013-11-14  0:44 UTC (permalink / raw)
  To: gdb-patches@sourceware.org ml

On 11/06/2013 01:53 PM, Tom Tromey wrote:
> This is ok.  Thanks, and sorry again for the delay.

Not a problem. I've now committed this and closed the bugs.

Keith

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-11-14  0:36 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-26 19:15 [RFA] Fix namespace aliases (c++/7539, c++/10541) Keith Seitz
2013-07-29 20:28 ` Tom Tromey
2013-07-30 22:44   ` Keith Seitz
2013-07-31 18:46     ` Tom Tromey
2013-09-17 23:03       ` Keith Seitz
2013-11-06 22:03         ` Tom Tromey
2013-11-14  0:44           ` Keith Seitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).