This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[dictionary] commit for 2003-03-10


Michael was kind enough to run my branch through his testbed.
Unfortunately, it didn't fare as well as I'd expected in situations
other than recent GCC, DWARF 2.  (I knew there was some work left to
do for stabs, but I'd expected more stuff to work.)

So I investigated that today.  GCC 2.95.3, DWARF 2 has problems for a
few reasons: some of my nested types detection code wasn't working as
well as it should, and anonymous namespaces weren't working.  I
haven't investigated the former; for the latter, it turns out that
there are two problems.  One of them is that the v2 demangler uses
"{anonymous}" instead of "(anonymous namespace)" for anonymous
namespaces.  Today's patch fixes that; but then, once I applied that,
it turns out that the v2 demangler can't demangle lots of names.
Sigh.  Given this, and given how badly 2.95.3 is for programming with
namespaces, I'm not sure if we should handle that form of the name, or
just only look for "(anonymous namespace)".  (Probably the best
approach would be to fix both problems with the demangler.)  This
demangling problem might or might not also be what's causing problems
with my nested types detection stuff; I haven't looked into that at
all.

The other problem is with stabs.  (With recent GCC's but perhaps not
with old GCC's: I haven't checked the details, but Michael's tables do
suggest that 2.95.3 works better here.)  It turns out that GDB doesn't
know about the mangled names of variables, with dire results.  Sigh.
I don't know to what extent this is a bug in GCC, but it doesn't make
me happy.  (Well, I don't mind _too_ much: the worse stabs gets, the
more people switch to DWARF 2...)

David Carlton
carlton at math dot stanford dot edu

2003-03-10  David Carlton  <carlton at math dot stanford dot edu>

	* buildsym.c (scan_for_anonymous_namespaces): Allow
	"{anonymous}".
	* cp-support.c (cp_is_anonymous): Scan for "{anonymous}".

Index: buildsym.c
===================================================================
RCS file: /cvs/src/src/gdb/buildsym.c,v
retrieving revision 1.20.2.23
diff -u -p -r1.20.2.23 buildsym.c
--- buildsym.c	6 Mar 2003 00:56:24 -0000	1.20.2.23
+++ buildsym.c	11 Mar 2003 01:00:08 -0000
@@ -148,10 +148,6 @@ add_symbol_to_list (struct symbol *symbo
 /* Check to see if a symbol is contained within an anonymous
    namespace; if so, add an appropriate using directive.  */
 
-/* Optimize away strlen ("(anonymous namespace)").  */
-
-#define ANONYMOUS_NAMESPACE_LEN 21
-
 static void
 scan_for_anonymous_namespaces (struct symbol *symbol)
 {
@@ -159,22 +155,40 @@ scan_for_anonymous_namespaces (struct sy
   unsigned int previous_component;
   unsigned int next_component;
   const char *len;
+  const char *anonymous_name;
+  int anonymous_len;
 
-  /* Start with a quick-and-dirty check for mention of "(anonymous
-     namespace)".  */
+  /* Start with a quick-and-dirty check for mentions of anonymous
+     namespaces.  */
+
+  switch (cp_is_anonymous (name))
+    {
+    case 1:
+      anonymous_name = "(anonymous namespace)";
+      break;
+    case 2:
+      /* FIXME: carlton/2003-03-10: This corresponds to GCCv2, and
+	 urrently, the demangler actually can't demangle all anonymous
+	 namespace mentions correctly.  (See PR gdb/1134.) Given
+	 GCCv2's lack of namespace support, I'm tempted to skip this
+	 case entirely.  */
+      anonymous_name = "{anonymous}";
+      break;
+    default:
+      return;
+    }
 
-  if (!cp_is_anonymous (name))
-    return;
+  anonymous_len = strlen (anonymous_name);
 
   previous_component = 0;
   next_component = cp_find_first_component (name + previous_component);
 
   while (name[next_component] == ':')
     {
-      if ((next_component - previous_component) == ANONYMOUS_NAMESPACE_LEN
-	  && strncmp (name + previous_component,
-		      "(anonymous namespace)",
-		      ANONYMOUS_NAMESPACE_LEN) == 0)
+      if ((next_component - previous_component) == anonymous_len
+	  && (strncmp (name + previous_component, anonymous_name,
+		       anonymous_len)
+	      == 0))
 	{
 	  /* We've found a component of the name that's an anonymous
 	     namespace.  So add symbols in it to the namespace given
Index: cp-support.c
===================================================================
RCS file: /cvs/src/src/gdb/cp-support.c,v
retrieving revision 1.1.2.16
diff -u -p -r1.1.2.16 cp-support.c
--- cp-support.c	6 Mar 2003 00:56:26 -0000	1.1.2.16
+++ cp-support.c	11 Mar 2003 01:00:08 -0000
@@ -647,13 +647,18 @@ maintenance_print_namespace (char *args,
 }
 
 /* Test whether or not NAMESPACE looks like it mentions an anonymous
-   namespace; return nonzero if so.  */
+   namespace; return 1 if it mentions "(anonymous namespace)", 2 if it
+   mentions "{anonymous}", and 0 otherwise.  */
 
 int
 cp_is_anonymous (const char *namespace)
 {
-  return (strstr (namespace, "(anonymous namespace)")
-	  != NULL);
+  if (strstr (namespace, "(anonymous namespace)") != NULL)
+    return 1;
+  else if (strstr (namespace, "{anonymous}") != NULL)
+    return 2;
+  else
+    return 0;
 }
 
 /* Create a copy of the initial substring of STRING of length LEN.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]