public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [patch 1/2] Search typedefs in namespaces also in other files
@ 2010-06-14 15:59 Jan Kratochvil
  2010-06-16 21:30 ` Tom Tromey
  0 siblings, 1 reply; 8+ messages in thread
From: Jan Kratochvil @ 2010-06-14 15:59 UTC (permalink / raw)
  To: gdb-patches; +Cc: Sami Wagiaalla

Hi,

currently you can access static symbols from not-current CUs (Compilation
Units).  In some cases you cannot if it is a name contained in namespace.

==> ns.C <==
int
main ()
{
  extern int f ();
  return f ();
}

==> ns2.C <==
typedef short i_t;
static i_t i = 1;
namespace N
  {
    typedef long j_t;
    j_t j = 2;
  }
int
f ()
{
  return i + N::j;
}

(gdb) start
(gdb) ptype i_t
type = short
(gdb) ptype N::j_t
No symbol "j_t" in namespace "N".
	-> with the patch: type = long
(gdb) ptype ::N::j_t
No symbol "j_t" in current context.
	-> with the patch: type = long
(gdb) ptype j_t
No symbol "j_t" in current context.
(gdb) adv f
f () at ns2.C:11
(gdb) ptype N::j_t
type = long
(gdb) _

That is type gets resolvable only if we are currently in its CU.

It is questionable how it should behave.  Such access is already not
compliant with the C++ standard.  The implementation tries only to search for
the fully qualified names - without any attempts for imported namespaces.

New types are always local to its CU.  You cannot use type from some .o file
without having its types defined for each new compiled CU from a .h file.
Therefore all the types get normally duplicated by each new CU.  While one can
use cross-CU references those are AFAIK (seen it only at Portland Group
compiled output) only de-duplicated after the compilation is done.  That means
DW_TAG_typedef has never DW_AT_external (is it really true?) and C++ standard
non-compliant other-file lookup makes sense.


While I tried I have not found any proper coding scheme so I just patched some
functions to make it working.  I may have missed some design points.  Already
the C++ parser calls various functions in not so correct way IMHO and there
also now exists at least the archer-cpparser effort to make it more sane.

Filed two KFAILed GDB Bugs for it, they are not regressions but rather the
unfixed parts:
	[Bug c++/11702] New: static const member is not printed
	 - it is unrelated to the issue this(ese) patch(es) try to solve.
	[Bug c++/11703] New: root namespace sometimes not working
	 - Leading :: works only for types, not other objects.
	 - IMHO a fix requires patching the C++ parser: -> archer-cpparser

No regressions on {x86_64,x86_64-m32,i686}-fedora13-linux-gnu (gcc-4.4-rh).
For proper testing avoiding some XFAILs one needs at least gcc-4.5.


Thanks,
Jan


gdb/
2010-06-14  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* cp-namespace.c (cp_lookup_symbol_namespace): Call also
	lookup_static_symbol_aux if we failed otherwise.
	(cp_lookup_nested_type): New variable concatenated_name.  Turn the
	current return condition into a reverse one.  Call also
	lookup_static_symbol_aux on the constructed qualified name.
	* symtab.c (lookup_symbol_aux): Move variable objfile and searching in
	other files into a called ...
	(lookup_static_symbol_aux): ... new function here.
	* symtab.h (lookup_static_symbol_aux): New prototype.

gdb/testsuite/
2010-06-14  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.cp/namespace.exp (whatis C::cOtherFileType)
	(whatis ::C::cOtherFileType, whatis C::cOtherFileVar)
	(whatis ::C::cOtherFileVar, print C::cOtherFileVar)
	(print ::C::cOtherFileVar)
	(whatis C::OtherFileClass::cOtherFileClassType)
	(whatis ::C::OtherFileClass::cOtherFileClassType)
	(print C::OtherFileClass::cOtherFileClassVar)
	(print ::C::OtherFileClass::cOtherFileClassVar): New tests.
	(ptype OtherFileClass, ptype ::C::OtherFileClass): Permit arbitrary
	trailing content.
	* gdb.cp/namespace1.cc (C::OtherFileClass::cOtherFileClassType)
	(C::OtherFileClass::cOtherFileClassVar)
	(C::OtherFileClass::cOtherFileClassVar_use, C::cOtherFileType)
	(C::cOtherFileVar, C::cOtherFileVar_use): New.

--- a/gdb/cp-namespace.c
+++ b/gdb/cp-namespace.c
@@ -440,6 +440,27 @@ cp_lookup_symbol_namespace (const char *scope,
       block = BLOCK_SUPERBLOCK (block);
     }
 
+  /* Now search all static file-level symbols.  Not strictly correct,
+     but more useful than an error.  We do not try to guess any imported
+     namespace as even the fully specified namespace seach is is already not
+     C++ compliant and more assumptions could make it too magic.  */
+
+  if (scope[0] == '\0')
+    {
+      sym = lookup_static_symbol_aux (name, domain);
+      if (sym != NULL)
+	return sym;
+    }
+  else
+    {
+      char *concatenated_name = alloca (strlen (scope) + 2 + strlen (name) + 1);
+
+      sprintf (concatenated_name, "%s::%s", scope, name);
+      sym = lookup_static_symbol_aux (concatenated_name, domain);
+      if (sym != NULL)
+	return sym;
+    }
+
   return NULL;
 }
 
@@ -578,11 +599,24 @@ cp_lookup_nested_type (struct type *parent_type,
 	                                                    nested_name,
 	                                                    block,
 	                                                    VAR_DOMAIN);
+	char *concatenated_name;
 
-	if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
-	  return NULL;
-	else
+	if (sym != NULL && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
 	  return SYMBOL_TYPE (sym);
+
+	/* Now search all static file-level symbols.  Not strictly correct,
+	   but more useful than an error.  We do not try to guess any imported
+	   namespace as even the fully specified namespace seach is is already
+	   not C++ compliant and more assumptions could make it too magic.  */
+
+	concatenated_name = alloca (strlen (parent_name) + 2
+				    + strlen (nested_name) + 1);
+	sprintf (concatenated_name, "%s::%s", parent_name, nested_name);
+	sym = lookup_static_symbol_aux (concatenated_name, VAR_DOMAIN);
+	if (sym != NULL && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
+	  return SYMBOL_TYPE (sym);
+
+	return NULL;
       }
     default:
       internal_error (__FILE__, __LINE__,
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -1054,7 +1054,6 @@ lookup_symbol_aux (const char *name, const struct block *block,
 {
   struct symbol *sym;
   const struct language_defn *langdef;
-  struct objfile *objfile;
 
   /* Make sure we do something sensible with is_a_field_of_this, since
      the callers that set this parameter to some non-null value will
@@ -1121,11 +1120,20 @@ lookup_symbol_aux (const char *name, const struct block *block,
   if (sym != NULL)
     return sym;
 
-  /* Now search all static file-level symbols.  Not strictly correct,
-     but more useful than an error.  Do the symtabs first, then check
-     the psymtabs.  If a psymtab indicates the existence of the
-     desired name as a file-level static, then do psymtab-to-symtab
-     conversion on the fly and return the found symbol. */
+  return lookup_static_symbol_aux (name, domain);
+}
+
+/* Now search all static file-level symbols.  Not strictly correct,
+   but more useful than an error.  Do the symtabs first, then check
+   the psymtabs.  If a psymtab indicates the existence of the
+   desired name as a file-level static, then do psymtab-to-symtab
+   conversion on the fly and return the found symbol. */
+
+struct symbol *
+lookup_static_symbol_aux (const char *name, const domain_enum domain)
+{
+  struct objfile *objfile;
+  struct symbol *sym;
 
   sym = lookup_symbol_aux_symtabs (STATIC_BLOCK, name, domain);
   if (sym != NULL)
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -886,6 +886,12 @@ extern struct symbol *lookup_symbol_aux_block (const char *name,
 					       const struct block *block,
 					       const domain_enum domain);
 
+/* Lookup a symbol only in the file static scope of all the objfiles.  */
+
+struct symbol *lookup_static_symbol_aux (const char *name,
+					 const domain_enum domain);
+
+
 /* lookup a symbol by name, within a specified block */
 
 extern struct symbol *lookup_block_symbol (const struct block *, const char *,
--- a/gdb/testsuite/gdb.cp/namespace.exp
+++ b/gdb/testsuite/gdb.cp/namespace.exp
@@ -165,6 +165,66 @@ gdb_test "print BBB::Class::xyzq" \
 gdb_test "break BBB::Class::xyzq" \
     "Breakpoint.*at $hex: file.*namespace.cc, line 68\\."
 
+# Tests accessing static elements in namespace of other file.
+
+gdb_test "whatis C::cOtherFileType" "type = short"
+gdb_test "whatis ::C::cOtherFileType" "type = short"
+gdb_test "whatis C::cOtherFileVar" "type = const C::cOtherFileType"
+setup_kfail "c++/11703" "*-*-*"
+gdb_test "whatis ::C::cOtherFileVar" "type = const C::cOtherFileType"
+gdb_test "print C::cOtherFileVar" "\\$\[0-9\].* = 319"
+setup_kfail "c++/11703" "*-*-*"
+gdb_test "print ::C::cOtherFileVar" "\\$\[0-9\].* = 319"
+
+if {[test_compiler_info {gcc-[0-3]-*}]
+    || [test_compiler_info {gcc-4-[0-4]-*}]} {
+    # The type in class is missing in older GCCs.
+    setup_xfail *-*-* 
+}
+gdb_test "whatis C::OtherFileClass::cOtherFileClassType" "type = short"
+if {[test_compiler_info {gcc-[0-3]-*}]
+    || [test_compiler_info {gcc-4-[0-4]-*}]} {
+    # The type in class is missing in older GCCs.
+    setup_xfail *-*-* 
+}
+gdb_test "whatis ::C::OtherFileClass::cOtherFileClassType" "type = short"
+
+set test "print C::OtherFileClass::cOtherFileClassVar"
+gdb_test_multiple $test $test {
+    -re "\\$\[0-9\].* = 318\r\n$gdb_prompt $" {
+	pass $test
+    }
+    -re "static field cOtherFileClassVar has been optimized out\r\n$gdb_prompt $" {
+	setup_kfail "c++/11702" "*-*-*"
+	fail $test
+    }
+}
+if {[test_compiler_info {gcc-[0-3]-*}]
+    || [test_compiler_info {gcc-4-[0-4]-*}]} {
+    # Older GCCs create unqualified DIE "cOtherFileClassVar" ignoring the
+    # namespace the same way GDB does.
+    setup_xfail *-*-* 
+} else {
+    setup_kfail "c++/11703" "*-*-*"
+}
+set test "print ::C::OtherFileClass::cOtherFileClassVar"
+gdb_test_multiple $test $test {
+    -re "\\$\[0-9\].* = 318\r\n$gdb_prompt $" {
+	if {[test_compiler_info {gcc-[0-3]-*}]
+	    || [test_compiler_info {gcc-4-[0-4]-*}]} {
+	    # Older GCCs create unqualified DIE "cOtherFileClassVar" ignoring the
+	    # namespace the same way GDB does.
+	    xfail $test
+	} else {
+	    pass $test
+	}
+    }
+    -re "$gdb_prompt $" {
+	setup_kfail "c++/11703" "*-*-*"
+	fail $test
+    }
+}
+
 # Test to see if the appropriate namespaces are in scope when trying
 # to print out stuff from within a function defined within a
 # namespace.
@@ -201,8 +261,8 @@ gdb_test "ptype C::NestedClass" "No symbol \"NestedClass\" in namespace \"C::C\"
 # Tests involving multiple files
 
 gdb_test "print cOtherFile" "\\$\[0-9\].* = 316"
-gdb_test "ptype OtherFileClass" "type = (class C::OtherFileClass \{\r\n  public:|struct C::OtherFileClass \{)\r\n    int z;\r\n\}"
-gdb_test "ptype ::C::OtherFileClass" "type = class C::OtherFileClass \{\r\n  public:\r\n    int z;\r\n\}"
+gdb_test "ptype OtherFileClass" "type = (class C::OtherFileClass \{\r\n  public:|struct C::OtherFileClass \{)\r\n    int z;\r\n.*\}"
+gdb_test "ptype ::C::OtherFileClass" "type = class C::OtherFileClass \{\r\n  public:\r\n    int z;\r\n.*\}"
 gdb_test "ptype C::OtherFileClass" "No symbol \"OtherFileClass\" in namespace \"C::C\"."
 
 # Some anonymous namespace tests.
--- a/gdb/testsuite/gdb.cp/namespace1.cc
+++ b/gdb/testsuite/gdb.cp/namespace1.cc
@@ -21,7 +21,15 @@ namespace C
   class OtherFileClass {
   public:
     int z;
+
+    typedef short cOtherFileClassType;
+    static const cOtherFileClassType cOtherFileClassVar = 318;
+    cOtherFileClassType cOtherFileClassVar_use ();
   };
+  OtherFileClass::cOtherFileClassType OtherFileClass::cOtherFileClassVar_use ()
+  {
+    return cOtherFileClassVar;
+  }
 
   namespace {
     int cXOtherFile = 29;
@@ -35,6 +43,13 @@ namespace C
     static OtherFileClass *c = new OtherFileClass();
     c->z = cOtherFile + cXOtherFile;
   }
+
+  typedef short cOtherFileType;
+  static const cOtherFileType cOtherFileVar = 319;
+  cOtherFileType cOtherFileVar_use ()
+  {
+    return cOtherFileVar;
+  }
 }
 
 namespace {

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

* Re: [patch 1/2] Search typedefs in namespaces also in other files
  2010-06-14 15:59 [patch 1/2] Search typedefs in namespaces also in other files Jan Kratochvil
@ 2010-06-16 21:30 ` Tom Tromey
  2010-06-25 21:29   ` Jan Kratochvil
  0 siblings, 1 reply; 8+ messages in thread
From: Tom Tromey @ 2010-06-16 21:30 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches, Sami Wagiaalla

>>>>> "Jan" == Jan Kratochvil <jan.kratochvil@redhat.com> writes:

Jan> currently you can access static symbols from not-current CUs
Jan> (Compilation Units).  In some cases you cannot if it is a name
Jan> contained in namespace.

Jan> It is questionable how it should behave.  Such access is already
Jan> not compliant with the C++ standard.  The implementation tries only
Jan> to search for the fully qualified names - without any attempts for
Jan> imported namespaces.

Well... AFAIK, types don't have linkage.  And, in C++, due to the ODR,
presumably anything like this must have a single meaning (though of
course in reality we probably have fun cases with hidden symbols in .sos
and whatnot).  Finally, GCC may omit some debuginfo that it thinks is
not useful in the current CU... so in some cases this patch may actually
improve conformance; and anyway it is similar to what gdb already does,
and also helpful.

So I am inclined to think it is ok.

It is true that it can yield confusing results, just as gdb already can
in some cases.  I think that must be reasonably rare, because I haven't
seen any bug reports about it.  In any case I think the way forward is
to fix those cases somehow, not limit new ones.

Jan> Already the C++ parser calls various functions in not so correct
Jan> way IMHO

I'm curious to know what.

Jan> 	[Bug c++/11703] New: root namespace sometimes not working
Jan> 	 - Leading :: works only for types, not other objects.
Jan> 	 - IMHO a fix requires patching the C++ parser: -> archer-cpparser

I think it could probably be solved, but that isn't too important.
We'll fix it one way or another.  Thanks for filing that.

Jan> +  /* Now search all static file-level symbols.  Not strictly correct,
Jan> +     but more useful than an error.  We do not try to guess any imported
Jan> +     namespace as even the fully specified namespace seach is is already not
Jan> +     C++ compliant and more assumptions could make it too magic.  */
Jan> +
Jan> +  if (scope[0] == '\0')
Jan> +    {
Jan> +      sym = lookup_static_symbol_aux (name, domain);

I'm having trouble following all the logic.

I think lookup_symbol_aux calls la_lookup_symbol_nonlocal,
which for C++ calls cp_lookup_symbol_nonlocal, which calls
cp_lookup_symbol_namespace.

But maybe this call is needed here for other callers of
cp_lookup_symbol_namespace?

The symbol lookup stuff is starting to feel spaghetti-ish to me.

Jan> @@ -1121,11 +1120,20 @@ lookup_symbol_aux (const char *name, const struct block *block,
Jan>    if (sym != NULL)
Jan>      return sym;
 
Jan> -  /* Now search all static file-level symbols.  Not strictly correct,
Jan> -     but more useful than an error.  Do the symtabs first, then check
Jan> -     the psymtabs.  If a psymtab indicates the existence of the
Jan> -     desired name as a file-level static, then do psymtab-to-symtab
Jan> -     conversion on the fly and return the found symbol. */
Jan> +  return lookup_static_symbol_aux (name, domain);
Jan> +}
Jan> +
Jan> +/* Now search all static file-level symbols.  Not strictly correct,
Jan> +   but more useful than an error.  Do the symtabs first, then check
Jan> +   the psymtabs.  If a psymtab indicates the existence of the
Jan> +   desired name as a file-level static, then do psymtab-to-symtab
Jan> +   conversion on the fly and return the found symbol. */
Jan> +
Jan> +struct symbol *
Jan> +lookup_static_symbol_aux (const char *name, const domain_enum domain)
Jan> +{
Jan> +  struct objfile *objfile;
Jan> +  struct symbol *sym;

I think you should leave that comment in the previous function and write
a new comment for lookup_static_symbol_aux.

Tom

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

* Re: [patch 1/2] Search typedefs in namespaces also in other files
  2010-06-16 21:30 ` Tom Tromey
@ 2010-06-25 21:29   ` Jan Kratochvil
  2010-06-25 21:53     ` Jan Kratochvil
                       ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Jan Kratochvil @ 2010-06-25 21:29 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches, Sami Wagiaalla

On Wed, 16 Jun 2010 23:30:07 +0200, Tom Tromey wrote:
> >>>>> "Jan" == Jan Kratochvil <jan.kratochvil@redhat.com> writes:
> Jan> Already the C++ parser calls various functions in not so correct
> Jan> way IMHO
> 
> I'm curious to know what.

I am withdrawing that claim.  After I found a simple fix for PR 11703 (which
is PR 1448) it started working.


> Jan> 	[Bug c++/11703] New: root namespace sometimes not working
> Jan> 	 - Leading :: works only for types, not other objects.
> Jan> 	 - IMHO a fix requires patching the C++ parser: -> archer-cpparser
> 
> I think it could probably be solved, but that isn't too important.
> We'll fix it one way or another.  Thanks for filing that.

It may be fixed by:
-      if (first_was_coloncolon)
+      if (first_was_coloncolon && first_iter)

but that I am going to post+investigate it in a different patch.


cp_lookup_symbol_namespace:
> Jan> +  /* Now search all static file-level symbols.  Not strictly correct,
> Jan> +     but more useful than an error.  We do not try to guess any imported
> Jan> +     namespace as even the fully specified namespace seach is is already not
> Jan> +     C++ compliant and more assumptions could make it too magic.  */
> Jan> +
> Jan> +  if (scope[0] == '\0')
> Jan> +    {
> Jan> +      sym = lookup_static_symbol_aux (name, domain);
> 
> I'm having trouble following all the logic.
> 
> I think lookup_symbol_aux calls la_lookup_symbol_nonlocal,
> which for C++ calls cp_lookup_symbol_nonlocal, which calls
> cp_lookup_symbol_namespace.
> 
> But maybe this call is needed here for other callers of
> cp_lookup_symbol_namespace?

Yes, also value_maybe_namespace_elt calls it.  OK, made two changes: Inlined
the logic into the caller value_maybe_namespace_elt.
This way the (scope[0] == '\0') branch lost its meaning.


> I think you should leave that comment in the previous function and write
> a new comment for lookup_static_symbol_aux.

Made some change.  I find "comment in the previous function" describes
internals (="Do the symtabs first, then check the psymtabs.") of the function
being called.  Such comment should not be at the caller, should be?

No regressions on {x86_64,x86_64-m32,i686}-fedora13-linux-gnu.

The XFAIL GCC version checks are for FSF GCC (<=4.4).  Therefore for recent
Fedora GCCs (gcc-c++-4.4.4-8.fc13) it XPASSes as they behave like FSF GCC-4.5+.


Thanks,
Jan


gdb/
2010-06-25  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* cp-namespace.c (cp_lookup_nested_type): New variable
	concatenated_name.  Turn the current return condition into a reverse
	one.  Call also lookup_static_symbol_aux on the constructed qualified
	name.
        * symtab.c (lookup_symbol_aux): Move variable objfile and searching in
        other files into a called ...
        (lookup_static_symbol_aux): ... new function here.
        * symtab.h (lookup_static_symbol_aux): New prototype.
	* valops.c (value_maybe_namespace_elt): Call also
	lookup_static_symbol_aux if we failed otherwise.

gdb/testsuite/
2010-06-25  Jan Kratochvil  <jan.kratochvil@redhat.com>

        * gdb.cp/namespace.exp (whatis C::cOtherFileType)
        (whatis ::C::cOtherFileType, whatis C::cOtherFileVar)
        (whatis ::C::cOtherFileVar, print C::cOtherFileVar)
        (print ::C::cOtherFileVar)
        (whatis C::OtherFileClass::cOtherFileClassType)
        (whatis ::C::OtherFileClass::cOtherFileClassType)
        (print C::OtherFileClass::cOtherFileClassVar)
        (print ::C::OtherFileClass::cOtherFileClassVar): New tests.
        (ptype OtherFileClass, ptype ::C::OtherFileClass): Permit arbitrary
        trailing content.
        * gdb.cp/namespace1.cc (C::OtherFileClass::cOtherFileClassType)
        (C::OtherFileClass::cOtherFileClassVar)
        (C::OtherFileClass::cOtherFileClassVar_use, C::cOtherFileType)
        (C::cOtherFileVar, C::cOtherFileVar_use): New.

--- a/gdb/cp-namespace.c
+++ b/gdb/cp-namespace.c
@@ -578,11 +578,24 @@ cp_lookup_nested_type (struct type *parent_type,
 	                                                    nested_name,
 	                                                    block,
 	                                                    VAR_DOMAIN);
+	char *concatenated_name;
 
-	if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
-	  return NULL;
-	else
+	if (sym != NULL && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
 	  return SYMBOL_TYPE (sym);
+
+	/* Now search all static file-level symbols.  Not strictly correct,
+	   but more useful than an error.  We do not try to guess any imported
+	   namespace as even the fully specified namespace seach is is already
+	   not C++ compliant and more assumptions could make it too magic.  */
+
+	concatenated_name = alloca (strlen (parent_name) + 2
+				    + strlen (nested_name) + 1);
+	sprintf (concatenated_name, "%s::%s", parent_name, nested_name);
+	sym = lookup_static_symbol_aux (concatenated_name, VAR_DOMAIN);
+	if (sym != NULL && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
+	  return SYMBOL_TYPE (sym);
+
+	return NULL;
       }
     default:
       internal_error (__FILE__, __LINE__,
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -1054,7 +1054,6 @@ lookup_symbol_aux (const char *name, const struct block *block,
 {
   struct symbol *sym;
   const struct language_defn *langdef;
-  struct objfile *objfile;
 
   /* Make sure we do something sensible with is_a_field_of_this, since
      the callers that set this parameter to some non-null value will
@@ -1122,10 +1121,21 @@ lookup_symbol_aux (const char *name, const struct block *block,
     return sym;
 
   /* Now search all static file-level symbols.  Not strictly correct,
-     but more useful than an error.  Do the symtabs first, then check
-     the psymtabs.  If a psymtab indicates the existence of the
-     desired name as a file-level static, then do psymtab-to-symtab
-     conversion on the fly and return the found symbol. */
+     but more useful than an error.  */
+
+  return lookup_static_symbol_aux (name, domain);
+}
+
+/* Search all static file-level symbols for NAME from DOMAIN.  Do the symtabs
+   first, then check the psymtabs.  If a psymtab indicates the existence of the
+   desired name as a file-level static, then do psymtab-to-symtab conversion on
+   the fly and return the found symbol. */
+
+struct symbol *
+lookup_static_symbol_aux (const char *name, const domain_enum domain)
+{
+  struct objfile *objfile;
+  struct symbol *sym;
 
   sym = lookup_symbol_aux_symtabs (STATIC_BLOCK, name, domain);
   if (sym != NULL)
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -886,6 +886,12 @@ extern struct symbol *lookup_symbol_aux_block (const char *name,
 					       const struct block *block,
 					       const domain_enum domain);
 
+/* Lookup a symbol only in the file static scope of all the objfiles.  */
+
+struct symbol *lookup_static_symbol_aux (const char *name,
+					 const domain_enum domain);
+
+
 /* lookup a symbol by name, within a specified block */
 
 extern struct symbol *lookup_block_symbol (const struct block *, const char *,
--- a/gdb/testsuite/gdb.cp/namespace.exp
+++ b/gdb/testsuite/gdb.cp/namespace.exp
@@ -165,6 +165,66 @@ gdb_test "print BBB::Class::xyzq" \
 gdb_test "break BBB::Class::xyzq" \
     "Breakpoint.*at $hex: file.*namespace.cc, line 68\\."
 
+# Tests accessing static elements in namespace of other file.
+
+gdb_test "whatis C::cOtherFileType" "type = short"
+gdb_test "whatis ::C::cOtherFileType" "type = short"
+gdb_test "whatis C::cOtherFileVar" "type = const C::cOtherFileType"
+setup_kfail "c++/11703" "*-*-*"
+gdb_test "whatis ::C::cOtherFileVar" "type = const C::cOtherFileType"
+gdb_test "print C::cOtherFileVar" "\\$\[0-9\].* = 319"
+setup_kfail "c++/11703" "*-*-*"
+gdb_test "print ::C::cOtherFileVar" "\\$\[0-9\].* = 319"
+
+if {[test_compiler_info {gcc-[0-3]-*}]
+    || [test_compiler_info {gcc-4-[0-4]-*}]} {
+    # The type in class is missing in older GCCs.
+    setup_xfail *-*-* 
+}
+gdb_test "whatis C::OtherFileClass::cOtherFileClassType" "type = short"
+if {[test_compiler_info {gcc-[0-3]-*}]
+    || [test_compiler_info {gcc-4-[0-4]-*}]} {
+    # The type in class is missing in older GCCs.
+    setup_xfail *-*-* 
+}
+gdb_test "whatis ::C::OtherFileClass::cOtherFileClassType" "type = short"
+
+set test "print C::OtherFileClass::cOtherFileClassVar"
+gdb_test_multiple $test $test {
+    -re "\\$\[0-9\].* = 318\r\n$gdb_prompt $" {
+	pass $test
+    }
+    -re "static field cOtherFileClassVar has been optimized out\r\n$gdb_prompt $" {
+	setup_kfail "c++/11702" "*-*-*"
+	fail $test
+    }
+}
+if {[test_compiler_info {gcc-[0-3]-*}]
+    || [test_compiler_info {gcc-4-[0-4]-*}]} {
+    # Older GCCs create unqualified DIE "cOtherFileClassVar" ignoring the
+    # namespace the same way GDB does.
+    setup_xfail *-*-* 
+} else {
+    setup_kfail "c++/11703" "*-*-*"
+}
+set test "print ::C::OtherFileClass::cOtherFileClassVar"
+gdb_test_multiple $test $test {
+    -re "\\$\[0-9\].* = 318\r\n$gdb_prompt $" {
+	if {[test_compiler_info {gcc-[0-3]-*}]
+	    || [test_compiler_info {gcc-4-[0-4]-*}]} {
+	    # Older GCCs create unqualified DIE "cOtherFileClassVar" ignoring the
+	    # namespace the same way GDB does.
+	    xfail $test
+	} else {
+	    pass $test
+	}
+    }
+    -re "$gdb_prompt $" {
+	setup_kfail "c++/11703" "*-*-*"
+	fail $test
+    }
+}
+
 # Test to see if the appropriate namespaces are in scope when trying
 # to print out stuff from within a function defined within a
 # namespace.
@@ -201,8 +261,8 @@ gdb_test "ptype C::NestedClass" "No symbol \"NestedClass\" in namespace \"C::C\"
 # Tests involving multiple files
 
 gdb_test "print cOtherFile" "\\$\[0-9\].* = 316"
-gdb_test "ptype OtherFileClass" "type = (class C::OtherFileClass \{\r\n  public:|struct C::OtherFileClass \{)\r\n    int z;\r\n\}"
-gdb_test "ptype ::C::OtherFileClass" "type = class C::OtherFileClass \{\r\n  public:\r\n    int z;\r\n\}"
+gdb_test "ptype OtherFileClass" "type = (class C::OtherFileClass \{\r\n  public:|struct C::OtherFileClass \{)\r\n    int z;\r\n.*\}"
+gdb_test "ptype ::C::OtherFileClass" "type = class C::OtherFileClass \{\r\n  public:\r\n    int z;\r\n.*\}"
 gdb_test "ptype C::OtherFileClass" "No symbol \"OtherFileClass\" in namespace \"C::C\"."
 
 # Some anonymous namespace tests.
--- a/gdb/testsuite/gdb.cp/namespace1.cc
+++ b/gdb/testsuite/gdb.cp/namespace1.cc
@@ -21,7 +21,15 @@ namespace C
   class OtherFileClass {
   public:
     int z;
+
+    typedef short cOtherFileClassType;
+    static const cOtherFileClassType cOtherFileClassVar = 318;
+    cOtherFileClassType cOtherFileClassVar_use ();
   };
+  OtherFileClass::cOtherFileClassType OtherFileClass::cOtherFileClassVar_use ()
+  {
+    return cOtherFileClassVar;
+  }
 
   namespace {
     int cXOtherFile = 29;
@@ -35,6 +43,13 @@ namespace C
     static OtherFileClass *c = new OtherFileClass();
     c->z = cOtherFile + cXOtherFile;
   }
+
+  typedef short cOtherFileType;
+  static const cOtherFileType cOtherFileVar = 319;
+  cOtherFileType cOtherFileVar_use ()
+  {
+    return cOtherFileVar;
+  }
 }
 
 namespace {
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -3284,8 +3284,16 @@ value_maybe_namespace_elt (const struct type *curtype,
   struct value *result;
 
   sym = cp_lookup_symbol_namespace (namespace_name, name,
-				    get_selected_block (0), 
-				    VAR_DOMAIN);
+				    get_selected_block (0), VAR_DOMAIN);
+
+  if (sym == NULL)
+    {
+      char *concatenated_name = alloca (strlen (namespace_name) + 2
+					+ strlen (name) + 1);
+
+      sprintf (concatenated_name, "%s::%s", namespace_name, name);
+      sym = lookup_static_symbol_aux (concatenated_name, VAR_DOMAIN);
+    }
 
   if (sym == NULL)
     return NULL;

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

* Re: [patch 1/2] Search typedefs in namespaces also in other files
  2010-06-25 21:29   ` Jan Kratochvil
@ 2010-06-25 21:53     ` Jan Kratochvil
  2010-06-26  8:06     ` Jan Kratochvil
  2010-06-28 17:52     ` Tom Tromey
  2 siblings, 0 replies; 8+ messages in thread
From: Jan Kratochvil @ 2010-06-25 21:53 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches, Sami Wagiaalla

On Fri, 25 Jun 2010 23:28:59 +0200, Jan Kratochvil wrote:
> No regressions on {x86_64,x86_64-m32,i686}-fedora13-linux-gnu.

For both patches - I would lie - this time i686 host is untested:
No regressions on {x86_64,x86_64-m32}-fedora13-linux-gnu.

Regards,
Jan

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

* Re: [patch 1/2] Search typedefs in namespaces also in other files
  2010-06-25 21:29   ` Jan Kratochvil
  2010-06-25 21:53     ` Jan Kratochvil
@ 2010-06-26  8:06     ` Jan Kratochvil
  2010-06-28 17:53       ` Tom Tromey
  2010-06-28 17:52     ` Tom Tromey
  2 siblings, 1 reply; 8+ messages in thread
From: Jan Kratochvil @ 2010-06-26  8:06 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches, Sami Wagiaalla

On Fri, 25 Jun 2010 23:28:59 +0200, Jan Kratochvil wrote:
> The XFAIL GCC version checks are for FSF GCC (<=4.4).  Therefore for recent
> Fedora GCCs (gcc-c++-4.4.4-8.fc13) it XPASSes as they behave like FSF GCC-4.5+.

I fixed up a bit this part to no longer XFAIL on fixed gcc-4.4 (so that the
functionality instead of gcc version is tested now).


Thanks,
Jan


gdb/
2010-06-25  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* cp-namespace.c (cp_lookup_nested_type): New variable
	concatenated_name.  Turn the current return condition into a reverse
	one.  Call also lookup_static_symbol_aux on the constructed qualified
	name.
	* symtab.c (lookup_symbol_aux): Move variable objfile and searching in
	other files into a called ...
	(lookup_static_symbol_aux): ... new function here.
	* symtab.h (lookup_static_symbol_aux): New prototype.
	* valops.c (value_maybe_namespace_elt): Call also
	lookup_static_symbol_aux if we failed otherwise.

gdb/testsuite/
2010-06-26  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.cp/namespace.exp (whatis C::cOtherFileType)
	(whatis ::C::cOtherFileType, whatis C::cOtherFileVar)
	(whatis ::C::cOtherFileVar, print C::cOtherFileVar)
	(print ::C::cOtherFileVar)
	(whatis C::OtherFileClass::cOtherFileClassType)
	(whatis ::C::OtherFileClass::cOtherFileClassType)
	(print C::OtherFileClass::cOtherFileClassVar)
	(print ::cOtherFileClassVar)
	(print ::C::OtherFileClass::cOtherFileClassVar): New tests.
	(ptype OtherFileClass, ptype ::C::OtherFileClass): Permit arbitrary
	trailing content.
	* gdb.cp/namespace1.cc (C::OtherFileClass::cOtherFileClassType)
	(C::OtherFileClass::cOtherFileClassVar)
	(C::OtherFileClass::cOtherFileClassVar_use, C::cOtherFileType)
	(C::cOtherFileVar, C::cOtherFileVar_use): New.

diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c
index 0daf732..d0fdcbe 100644
--- a/gdb/cp-namespace.c
+++ b/gdb/cp-namespace.c
@@ -578,11 +578,24 @@ cp_lookup_nested_type (struct type *parent_type,
 	                                                    nested_name,
 	                                                    block,
 	                                                    VAR_DOMAIN);
+	char *concatenated_name;
 
-	if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
-	  return NULL;
-	else
+	if (sym != NULL && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
 	  return SYMBOL_TYPE (sym);
+
+	/* Now search all static file-level symbols.  Not strictly correct,
+	   but more useful than an error.  We do not try to guess any imported
+	   namespace as even the fully specified namespace seach is is already
+	   not C++ compliant and more assumptions could make it too magic.  */
+
+	concatenated_name = alloca (strlen (parent_name) + 2
+				    + strlen (nested_name) + 1);
+	sprintf (concatenated_name, "%s::%s", parent_name, nested_name);
+	sym = lookup_static_symbol_aux (concatenated_name, VAR_DOMAIN);
+	if (sym != NULL && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
+	  return SYMBOL_TYPE (sym);
+
+	return NULL;
       }
     default:
       internal_error (__FILE__, __LINE__,
diff --git a/gdb/symtab.c b/gdb/symtab.c
index cada00e..feb986f 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -1054,7 +1054,6 @@ lookup_symbol_aux (const char *name, const struct block *block,
 {
   struct symbol *sym;
   const struct language_defn *langdef;
-  struct objfile *objfile;
 
   /* Make sure we do something sensible with is_a_field_of_this, since
      the callers that set this parameter to some non-null value will
@@ -1122,10 +1121,21 @@ lookup_symbol_aux (const char *name, const struct block *block,
     return sym;
 
   /* Now search all static file-level symbols.  Not strictly correct,
-     but more useful than an error.  Do the symtabs first, then check
-     the psymtabs.  If a psymtab indicates the existence of the
-     desired name as a file-level static, then do psymtab-to-symtab
-     conversion on the fly and return the found symbol. */
+     but more useful than an error.  */
+
+  return lookup_static_symbol_aux (name, domain);
+}
+
+/* Search all static file-level symbols for NAME from DOMAIN.  Do the symtabs
+   first, then check the psymtabs.  If a psymtab indicates the existence of the
+   desired name as a file-level static, then do psymtab-to-symtab conversion on
+   the fly and return the found symbol. */
+
+struct symbol *
+lookup_static_symbol_aux (const char *name, const domain_enum domain)
+{
+  struct objfile *objfile;
+  struct symbol *sym;
 
   sym = lookup_symbol_aux_symtabs (STATIC_BLOCK, name, domain);
   if (sym != NULL)
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 5b109ce..bedc10a 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -886,6 +886,12 @@ extern struct symbol *lookup_symbol_aux_block (const char *name,
 					       const struct block *block,
 					       const domain_enum domain);
 
+/* Lookup a symbol only in the file static scope of all the objfiles.  */
+
+struct symbol *lookup_static_symbol_aux (const char *name,
+					 const domain_enum domain);
+
+
 /* lookup a symbol by name, within a specified block */
 
 extern struct symbol *lookup_block_symbol (const struct block *, const char *,
diff --git a/gdb/testsuite/gdb.cp/namespace.exp b/gdb/testsuite/gdb.cp/namespace.exp
index 97521a1..bc24fa5 100644
--- a/gdb/testsuite/gdb.cp/namespace.exp
+++ b/gdb/testsuite/gdb.cp/namespace.exp
@@ -165,6 +165,76 @@ gdb_test "print BBB::Class::xyzq" \
 gdb_test "break BBB::Class::xyzq" \
     "Breakpoint.*at $hex: file.*namespace.cc, line 68\\."
 
+# Tests accessing static elements in namespace of other file.
+
+gdb_test "whatis C::cOtherFileType" "type = short"
+gdb_test "whatis ::C::cOtherFileType" "type = short"
+gdb_test "whatis C::cOtherFileVar" "type = const C::cOtherFileType"
+setup_kfail "c++/11703" "*-*-*"
+gdb_test "whatis ::C::cOtherFileVar" "type = const C::cOtherFileType"
+gdb_test "print C::cOtherFileVar" "\\$\[0-9\].* = 319"
+setup_kfail "c++/11703" "*-*-*"
+gdb_test "print ::C::cOtherFileVar" "\\$\[0-9\].* = 319"
+
+if {[test_compiler_info {gcc-[0-3]-*}]
+    || [test_compiler_info {gcc-4-[0-4]-*}]} {
+    # The type in class is missing in older GCCs.
+    setup_xfail *-*-* 
+}
+gdb_test "whatis C::OtherFileClass::cOtherFileClassType" "type = short"
+if {[test_compiler_info {gcc-[0-3]-*}]
+    || [test_compiler_info {gcc-4-[0-4]-*}]} {
+    # The type in class is missing in older GCCs.
+    setup_xfail *-*-* 
+}
+gdb_test "whatis ::C::OtherFileClass::cOtherFileClassType" "type = short"
+
+set test "print C::OtherFileClass::cOtherFileClassVar"
+gdb_test_multiple $test $test {
+    -re "\\$\[0-9\].* = 318\r\n$gdb_prompt $" {
+	pass $test
+    }
+    -re "static field cOtherFileClassVar has been optimized out\r\n$gdb_prompt $" {
+	setup_kfail "c++/11702" "*-*-*"
+	fail $test
+    }
+}
+
+# FSF GCC <=4.4 creates unqualified DIE "cOtherFileClassVar" ignoring the
+# namespace the same way older GDB did.
+set test "print ::cOtherFileClassVar"
+set test2 "print ::C::OtherFileClass::cOtherFileClassVar"
+gdb_test_multiple $test $test {
+    -re "No symbol \"cOtherFileClassVar\" in current context\\.\r\n$gdb_prompt $" {
+	pass $test
+
+	gdb_test_multiple $test2 $test2 {
+	    -re "\\$\[0-9\].* = 318\r\n$gdb_prompt $" {
+		pass $test2
+	    }
+	    -re "No symbol \"cOtherFileClassVar\" in current context\\.\r\n$gdb_prompt $" {
+		setup_kfail "c++/11703" "*-*-*"
+		fail $test2
+	    }
+	    -re "static field cOtherFileClassVar has been optimized out\r\n$gdb_prompt $" {
+		setup_kfail "c++/11702" "*-*-*"
+		fail $test2
+	    }
+	}
+
+    }
+    -re "\\$\[0-9\].* = 318\r\n$gdb_prompt $" {
+	if {[test_compiler_info {gcc-[0-3]-*}]
+	    || [test_compiler_info {gcc-4-[0-4]-*}]} {
+	    # Do not permit to XFAIL on recent GCCs.
+	    setup_xfail *-*-* 
+	}
+	fail $test
+
+	unresolved $test2
+    }
+}
+
 # Test to see if the appropriate namespaces are in scope when trying
 # to print out stuff from within a function defined within a
 # namespace.
@@ -201,8 +271,8 @@ gdb_test "ptype C::NestedClass" "No symbol \"NestedClass\" in namespace \"C::C\"
 # Tests involving multiple files
 
 gdb_test "print cOtherFile" "\\$\[0-9\].* = 316"
-gdb_test "ptype OtherFileClass" "type = (class C::OtherFileClass \{\r\n  public:|struct C::OtherFileClass \{)\r\n    int z;\r\n\}"
-gdb_test "ptype ::C::OtherFileClass" "type = class C::OtherFileClass \{\r\n  public:\r\n    int z;\r\n\}"
+gdb_test "ptype OtherFileClass" "type = (class C::OtherFileClass \{\r\n  public:|struct C::OtherFileClass \{)\r\n    int z;\r\n.*\}"
+gdb_test "ptype ::C::OtherFileClass" "type = class C::OtherFileClass \{\r\n  public:\r\n    int z;\r\n.*\}"
 gdb_test "ptype C::OtherFileClass" "No symbol \"OtherFileClass\" in namespace \"C::C\"."
 
 # Some anonymous namespace tests.
diff --git a/gdb/testsuite/gdb.cp/namespace1.cc b/gdb/testsuite/gdb.cp/namespace1.cc
index af0ec29..928e357 100644
--- a/gdb/testsuite/gdb.cp/namespace1.cc
+++ b/gdb/testsuite/gdb.cp/namespace1.cc
@@ -21,7 +21,15 @@ namespace C
   class OtherFileClass {
   public:
     int z;
+
+    typedef short cOtherFileClassType;
+    static const cOtherFileClassType cOtherFileClassVar = 318;
+    cOtherFileClassType cOtherFileClassVar_use ();
   };
+  OtherFileClass::cOtherFileClassType OtherFileClass::cOtherFileClassVar_use ()
+  {
+    return cOtherFileClassVar;
+  }
 
   namespace {
     int cXOtherFile = 29;
@@ -35,6 +43,13 @@ namespace C
     static OtherFileClass *c = new OtherFileClass();
     c->z = cOtherFile + cXOtherFile;
   }
+
+  typedef short cOtherFileType;
+  static const cOtherFileType cOtherFileVar = 319;
+  cOtherFileType cOtherFileVar_use ()
+  {
+    return cOtherFileVar;
+  }
 }
 
 namespace {
diff --git a/gdb/valops.c b/gdb/valops.c
index 506d40e..19b88b7 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -3284,8 +3284,16 @@ value_maybe_namespace_elt (const struct type *curtype,
   struct value *result;
 
   sym = cp_lookup_symbol_namespace (namespace_name, name,
-				    get_selected_block (0), 
-				    VAR_DOMAIN);
+				    get_selected_block (0), VAR_DOMAIN);
+
+  if (sym == NULL)
+    {
+      char *concatenated_name = alloca (strlen (namespace_name) + 2
+					+ strlen (name) + 1);
+
+      sprintf (concatenated_name, "%s::%s", namespace_name, name);
+      sym = lookup_static_symbol_aux (concatenated_name, VAR_DOMAIN);
+    }
 
   if (sym == NULL)
     return NULL;

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

* Re: [patch 1/2] Search typedefs in namespaces also in other files
  2010-06-25 21:29   ` Jan Kratochvil
  2010-06-25 21:53     ` Jan Kratochvil
  2010-06-26  8:06     ` Jan Kratochvil
@ 2010-06-28 17:52     ` Tom Tromey
  2010-06-28 20:41       ` Jan Kratochvil
  2 siblings, 1 reply; 8+ messages in thread
From: Tom Tromey @ 2010-06-28 17:52 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches, Sami Wagiaalla

>>>>> "Jan" == Jan Kratochvil <jan.kratochvil@redhat.com> writes:

Tom> I think you should leave that comment in the previous function and write
Tom> a new comment for lookup_static_symbol_aux.

Jan> Made some change.  I find "comment in the previous function"
Jan> describes internals (="Do the symtabs first, then check the
Jan> psymtabs.") of the function being called.  Such comment should not
Jan> be at the caller, should be?

I don't totally follow, but I suppose the ideal is for a comment to
describe what the function does and also relevant info about its
arguments and returns; and not describe exactly how the function may do
its job.

I think what you did here is fine.

Tom

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

* Re: [patch 1/2] Search typedefs in namespaces also in other files
  2010-06-26  8:06     ` Jan Kratochvil
@ 2010-06-28 17:53       ` Tom Tromey
  0 siblings, 0 replies; 8+ messages in thread
From: Tom Tromey @ 2010-06-28 17:53 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches, Sami Wagiaalla

>>>>> "Jan" == Jan Kratochvil <jan.kratochvil@redhat.com> writes:

Jan> 2010-06-25  Jan Kratochvil  <jan.kratochvil@redhat.com>
Jan> 	* cp-namespace.c (cp_lookup_nested_type): New variable
Jan> 	concatenated_name.  Turn the current return condition into a reverse
Jan> 	one.  Call also lookup_static_symbol_aux on the constructed qualified
Jan> 	name.
Jan> 	* symtab.c (lookup_symbol_aux): Move variable objfile and searching in
Jan> 	other files into a called ...
Jan> 	(lookup_static_symbol_aux): ... new function here.
Jan> 	* symtab.h (lookup_static_symbol_aux): New prototype.
Jan> 	* valops.c (value_maybe_namespace_elt): Call also
Jan> 	lookup_static_symbol_aux if we failed otherwise.

Jan> 2010-06-26  Jan Kratochvil  <jan.kratochvil@redhat.com>
Jan> 	* gdb.cp/namespace.exp (whatis C::cOtherFileType)
Jan> 	(whatis ::C::cOtherFileType, whatis C::cOtherFileVar)
Jan> 	(whatis ::C::cOtherFileVar, print C::cOtherFileVar)
Jan> 	(print ::C::cOtherFileVar)
Jan> 	(whatis C::OtherFileClass::cOtherFileClassType)
Jan> 	(whatis ::C::OtherFileClass::cOtherFileClassType)
Jan> 	(print C::OtherFileClass::cOtherFileClassVar)
Jan> 	(print ::cOtherFileClassVar)
Jan> 	(print ::C::OtherFileClass::cOtherFileClassVar): New tests.
Jan> 	(ptype OtherFileClass, ptype ::C::OtherFileClass): Permit arbitrary
Jan> 	trailing content.
Jan> 	* gdb.cp/namespace1.cc (C::OtherFileClass::cOtherFileClassType)
Jan> 	(C::OtherFileClass::cOtherFileClassVar)
Jan> 	(C::OtherFileClass::cOtherFileClassVar_use, C::cOtherFileType)
Jan> 	(C::cOtherFileVar, C::cOtherFileVar_use): New.

This is ok.  Thanks.

Tom

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

* Re: [patch 1/2] Search typedefs in namespaces also in other files
  2010-06-28 17:52     ` Tom Tromey
@ 2010-06-28 20:41       ` Jan Kratochvil
  0 siblings, 0 replies; 8+ messages in thread
From: Jan Kratochvil @ 2010-06-28 20:41 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches, Sami Wagiaalla

On Mon, 28 Jun 2010 19:52:43 +0200, Tom Tromey wrote:
> >>>>> "Jan" == Jan Kratochvil <jan.kratochvil@redhat.com> writes:
> 
> I don't totally follow, but I suppose the ideal is for a comment to
> describe what the function does and also relevant info about its
> arguments and returns; and not describe exactly how the function may do
> its job.

Yes, I agree, sorry for my wording.


On Mon, 28 Jun 2010 19:53:02 +0200, Tom Tromey wrote:
> >>>>> "Jan" == Jan Kratochvil <jan.kratochvil@redhat.com> writes:
> 
> Jan> 2010-06-25  Jan Kratochvil  <jan.kratochvil@redhat.com>
> Jan> 	* cp-namespace.c (cp_lookup_nested_type): New variable
> Jan> 	concatenated_name.  Turn the current return condition into a reverse
> Jan> 	one.  Call also lookup_static_symbol_aux on the constructed qualified
> Jan> 	name.
> Jan> 	* symtab.c (lookup_symbol_aux): Move variable objfile and searching in
> Jan> 	other files into a called ...
> Jan> 	(lookup_static_symbol_aux): ... new function here.
> Jan> 	* symtab.h (lookup_static_symbol_aux): New prototype.
> Jan> 	* valops.c (value_maybe_namespace_elt): Call also
> Jan> 	lookup_static_symbol_aux if we failed otherwise.
> 
> Jan> 2010-06-26  Jan Kratochvil  <jan.kratochvil@redhat.com>
> Jan> 	* gdb.cp/namespace.exp (whatis C::cOtherFileType)
> Jan> 	(whatis ::C::cOtherFileType, whatis C::cOtherFileVar)
> Jan> 	(whatis ::C::cOtherFileVar, print C::cOtherFileVar)
> Jan> 	(print ::C::cOtherFileVar)
> Jan> 	(whatis C::OtherFileClass::cOtherFileClassType)
> Jan> 	(whatis ::C::OtherFileClass::cOtherFileClassType)
> Jan> 	(print C::OtherFileClass::cOtherFileClassVar)
> Jan> 	(print ::cOtherFileClassVar)
> Jan> 	(print ::C::OtherFileClass::cOtherFileClassVar): New tests.
> Jan> 	(ptype OtherFileClass, ptype ::C::OtherFileClass): Permit arbitrary
> Jan> 	trailing content.
> Jan> 	* gdb.cp/namespace1.cc (C::OtherFileClass::cOtherFileClassType)
> Jan> 	(C::OtherFileClass::cOtherFileClassVar)
> Jan> 	(C::OtherFileClass::cOtherFileClassVar_use, C::cOtherFileType)
> Jan> 	(C::cOtherFileVar, C::cOtherFileVar_use): New.
> 
> This is ok.  Thanks.

Checked-in.  Removed KFAILs for already fixed PR c++/11703.


Thanks,
Jan


http://sourceware.org/ml/gdb-cvs/2010-06/msg00198.html

--- src/gdb/ChangeLog	2010/06/28 20:18:26	1.11943
+++ src/gdb/ChangeLog	2010/06/28 20:35:51	1.11944
@@ -1,5 +1,18 @@
 2010-06-28  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
+	* cp-namespace.c (cp_lookup_nested_type): New variable
+	concatenated_name.  Turn the current return condition into a reverse
+	one.  Call also lookup_static_symbol_aux on the constructed qualified
+	name.
+	* symtab.c (lookup_symbol_aux): Move variable objfile and searching in
+	other files into a called ...
+	(lookup_static_symbol_aux): ... new function here.
+	* symtab.h (lookup_static_symbol_aux): New prototype.
+	* valops.c (value_maybe_namespace_elt): Call also
+	lookup_static_symbol_aux if we failed otherwise.
+
+2010-06-28  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
 	Fix PR c++/11703 and PR gdb/1448.
 	* c-exp.y (yylex) <last_was_coloncolon && first_was_coloncolon>: Add
 	FIRST_ITER check.
--- src/gdb/cp-namespace.c	2010/05/13 23:53:32	1.42
+++ src/gdb/cp-namespace.c	2010/06/28 20:35:52	1.43
@@ -578,11 +578,24 @@
 	                                                    nested_name,
 	                                                    block,
 	                                                    VAR_DOMAIN);
+	char *concatenated_name;
 
-	if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
-	  return NULL;
-	else
+	if (sym != NULL && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
 	  return SYMBOL_TYPE (sym);
+
+	/* Now search all static file-level symbols.  Not strictly correct,
+	   but more useful than an error.  We do not try to guess any imported
+	   namespace as even the fully specified namespace seach is is already
+	   not C++ compliant and more assumptions could make it too magic.  */
+
+	concatenated_name = alloca (strlen (parent_name) + 2
+				    + strlen (nested_name) + 1);
+	sprintf (concatenated_name, "%s::%s", parent_name, nested_name);
+	sym = lookup_static_symbol_aux (concatenated_name, VAR_DOMAIN);
+	if (sym != NULL && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
+	  return SYMBOL_TYPE (sym);
+
+	return NULL;
       }
     default:
       internal_error (__FILE__, __LINE__,
--- src/gdb/symtab.c	2010/06/02 22:41:55	1.238
+++ src/gdb/symtab.c	2010/06/28 20:35:52	1.239
@@ -1054,7 +1054,6 @@
 {
   struct symbol *sym;
   const struct language_defn *langdef;
-  struct objfile *objfile;
 
   /* Make sure we do something sensible with is_a_field_of_this, since
      the callers that set this parameter to some non-null value will
@@ -1122,10 +1121,21 @@
     return sym;
 
   /* Now search all static file-level symbols.  Not strictly correct,
-     but more useful than an error.  Do the symtabs first, then check
-     the psymtabs.  If a psymtab indicates the existence of the
-     desired name as a file-level static, then do psymtab-to-symtab
-     conversion on the fly and return the found symbol. */
+     but more useful than an error.  */
+
+  return lookup_static_symbol_aux (name, domain);
+}
+
+/* Search all static file-level symbols for NAME from DOMAIN.  Do the symtabs
+   first, then check the psymtabs.  If a psymtab indicates the existence of the
+   desired name as a file-level static, then do psymtab-to-symtab conversion on
+   the fly and return the found symbol. */
+
+struct symbol *
+lookup_static_symbol_aux (const char *name, const domain_enum domain)
+{
+  struct objfile *objfile;
+  struct symbol *sym;
 
   sym = lookup_symbol_aux_symtabs (STATIC_BLOCK, name, domain);
   if (sym != NULL)
--- src/gdb/symtab.h	2010/06/02 22:41:55	1.153
+++ src/gdb/symtab.h	2010/06/28 20:35:52	1.154
@@ -886,6 +886,12 @@
 					       const struct block *block,
 					       const domain_enum domain);
 
+/* Lookup a symbol only in the file static scope of all the objfiles.  */
+
+struct symbol *lookup_static_symbol_aux (const char *name,
+					 const domain_enum domain);
+
+
 /* lookup a symbol by name, within a specified block */
 
 extern struct symbol *lookup_block_symbol (const struct block *, const char *,
--- src/gdb/valops.c	2010/06/27 16:26:41	1.247
+++ src/gdb/valops.c	2010/06/28 20:35:52	1.248
@@ -3284,8 +3284,16 @@
   struct value *result;
 
   sym = cp_lookup_symbol_namespace (namespace_name, name,
-				    get_selected_block (0), 
-				    VAR_DOMAIN);
+				    get_selected_block (0), VAR_DOMAIN);
+
+  if (sym == NULL)
+    {
+      char *concatenated_name = alloca (strlen (namespace_name) + 2
+					+ strlen (name) + 1);
+
+      sprintf (concatenated_name, "%s::%s", namespace_name, name);
+      sym = lookup_static_symbol_aux (concatenated_name, VAR_DOMAIN);
+    }
 
   if (sym == NULL)
     return NULL;
--- src/gdb/testsuite/ChangeLog	2010/06/28 20:18:26	1.2360
+++ src/gdb/testsuite/ChangeLog	2010/06/28 20:35:52	1.2361
@@ -1,5 +1,23 @@
 2010-06-28  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
+	* gdb.cp/namespace.exp (whatis C::cOtherFileType)
+	(whatis ::C::cOtherFileType, whatis C::cOtherFileVar)
+	(whatis ::C::cOtherFileVar, print C::cOtherFileVar)
+	(print ::C::cOtherFileVar)
+	(whatis C::OtherFileClass::cOtherFileClassType)
+	(whatis ::C::OtherFileClass::cOtherFileClassType)
+	(print C::OtherFileClass::cOtherFileClassVar)
+	(print ::cOtherFileClassVar)
+	(print ::C::OtherFileClass::cOtherFileClassVar): New tests.
+	(ptype OtherFileClass, ptype ::C::OtherFileClass): Permit arbitrary
+	trailing content.
+	* gdb.cp/namespace1.cc (C::OtherFileClass::cOtherFileClassType)
+	(C::OtherFileClass::cOtherFileClassVar)
+	(C::OtherFileClass::cOtherFileClassVar_use, C::cOtherFileType)
+	(C::cOtherFileVar, C::cOtherFileVar_use): New.
+
+2010-06-28  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
 	Test PR c++/11703 and PR gdb/1448.
 	* gdb.cp/namespace.exp (ptype ::C::NestedClass): Remove KFAIL for
 	gdb/1448.
--- src/gdb/testsuite/gdb.cp/namespace.exp	2010/06/28 20:18:27	1.20
+++ src/gdb/testsuite/gdb.cp/namespace.exp	2010/06/28 20:35:52	1.21
@@ -165,6 +165,70 @@
 gdb_test "break BBB::Class::xyzq" \
     "Breakpoint.*at $hex: file.*namespace.cc, line 68\\."
 
+# Tests accessing static elements in namespace of other file.
+
+gdb_test "whatis C::cOtherFileType" "type = short"
+gdb_test "whatis ::C::cOtherFileType" "type = short"
+gdb_test "whatis C::cOtherFileVar" "type = const C::cOtherFileType"
+gdb_test "whatis ::C::cOtherFileVar" "type = const C::cOtherFileType"
+gdb_test "print C::cOtherFileVar" "\\$\[0-9\].* = 319"
+gdb_test "print ::C::cOtherFileVar" "\\$\[0-9\].* = 319"
+
+if {[test_compiler_info {gcc-[0-3]-*}]
+    || [test_compiler_info {gcc-4-[0-4]-*}]} {
+    # The type in class is missing in older GCCs.
+    setup_xfail *-*-* 
+}
+gdb_test "whatis C::OtherFileClass::cOtherFileClassType" "type = short"
+if {[test_compiler_info {gcc-[0-3]-*}]
+    || [test_compiler_info {gcc-4-[0-4]-*}]} {
+    # The type in class is missing in older GCCs.
+    setup_xfail *-*-* 
+}
+gdb_test "whatis ::C::OtherFileClass::cOtherFileClassType" "type = short"
+
+set test "print C::OtherFileClass::cOtherFileClassVar"
+gdb_test_multiple $test $test {
+    -re "\\$\[0-9\].* = 318\r\n$gdb_prompt $" {
+	pass $test
+    }
+    -re "static field cOtherFileClassVar has been optimized out\r\n$gdb_prompt $" {
+	setup_kfail "c++/11702" "*-*-*"
+	fail $test
+    }
+}
+
+# FSF GCC <=4.4 creates unqualified DIE "cOtherFileClassVar" ignoring the
+# namespace the same way older GDB did.
+set test "print ::cOtherFileClassVar"
+set test2 "print ::C::OtherFileClass::cOtherFileClassVar"
+gdb_test_multiple $test $test {
+    -re "No symbol \"cOtherFileClassVar\" in current context\\.\r\n$gdb_prompt $" {
+	pass $test
+
+	gdb_test_multiple $test2 $test2 {
+	    -re "\\$\[0-9\].* = 318\r\n$gdb_prompt $" {
+		pass $test2
+	    }
+	    -re "static field cOtherFileClassVar has been optimized out\r\n$gdb_prompt $" {
+		setup_kfail "c++/11702" "*-*-*"
+		fail $test2
+	    }
+	}
+
+    }
+    -re "\\$\[0-9\].* = 318\r\n$gdb_prompt $" {
+	if {[test_compiler_info {gcc-[0-3]-*}]
+	    || [test_compiler_info {gcc-4-[0-4]-*}]} {
+	    # Do not permit to XFAIL on recent GCCs.
+	    setup_xfail *-*-* 
+	}
+	fail $test
+
+	unresolved $test2
+    }
+}
+
 # Test to see if the appropriate namespaces are in scope when trying
 # to print out stuff from within a function defined within a
 # namespace.
@@ -200,8 +264,8 @@
 # Tests involving multiple files
 
 gdb_test "print cOtherFile" "\\$\[0-9\].* = 316"
-gdb_test "ptype OtherFileClass" "type = (class C::OtherFileClass \{\r\n  public:|struct C::OtherFileClass \{)\r\n    int z;\r\n\}"
-gdb_test "ptype ::C::OtherFileClass" "type = class C::OtherFileClass \{\r\n  public:\r\n    int z;\r\n\}"
+gdb_test "ptype OtherFileClass" "type = (class C::OtherFileClass \{\r\n  public:|struct C::OtherFileClass \{)\r\n    int z;\r\n.*\}"
+gdb_test "ptype ::C::OtherFileClass" "type = class C::OtherFileClass \{\r\n  public:\r\n    int z;\r\n.*\}"
 gdb_test "ptype C::OtherFileClass" "No symbol \"OtherFileClass\" in namespace \"C::C\"."
 
 # Some anonymous namespace tests.
--- src/gdb/testsuite/gdb.cp/namespace1.cc	2010/01/01 07:32:01	1.10
+++ src/gdb/testsuite/gdb.cp/namespace1.cc	2010/06/28 20:35:52	1.11
@@ -21,7 +21,15 @@
   class OtherFileClass {
   public:
     int z;
+
+    typedef short cOtherFileClassType;
+    static const cOtherFileClassType cOtherFileClassVar = 318;
+    cOtherFileClassType cOtherFileClassVar_use ();
   };
+  OtherFileClass::cOtherFileClassType OtherFileClass::cOtherFileClassVar_use ()
+  {
+    return cOtherFileClassVar;
+  }
 
   namespace {
     int cXOtherFile = 29;
@@ -35,6 +43,13 @@
     static OtherFileClass *c = new OtherFileClass();
     c->z = cOtherFile + cXOtherFile;
   }
+
+  typedef short cOtherFileType;
+  static const cOtherFileType cOtherFileVar = 319;
+  cOtherFileType cOtherFileVar_use ()
+  {
+    return cOtherFileVar;
+  }
 }
 
 namespace {

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

end of thread, other threads:[~2010-06-28 20:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-14 15:59 [patch 1/2] Search typedefs in namespaces also in other files Jan Kratochvil
2010-06-16 21:30 ` Tom Tromey
2010-06-25 21:29   ` Jan Kratochvil
2010-06-25 21:53     ` Jan Kratochvil
2010-06-26  8:06     ` Jan Kratochvil
2010-06-28 17:53       ` Tom Tromey
2010-06-28 17:52     ` Tom Tromey
2010-06-28 20:41       ` Jan Kratochvil

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).