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]

[intercu] Handle DW_AT_specification for partial DIEs


This patch is not very nice.  I need to at the least fix up the interface of
pdi_needs_namespace so that I don't need to pass it "foo".  I'd also like to
think a little longer about the implementation of partial_determine_prefix.
However, it does work, and produce the correct partial symbol names.

Committed to the intercu branch (for now).

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer

2004-02-21  Daniel Jacobowitz  <drow@mvista.com>

	* dwarf2read.c (partial_determine_prefix)
	(partial_determine_prefix_aux): New functions.
	(add_partial_symbol): Call partial_determine_prefix.
	(add_partial_structure): Remove workaround for DW_AT_specification.
	(load_partial_die): Save DW_AT_extension.
	(determine_prefix_aux): Reuse the return value of dwarf2_name.

Index: dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.135.2.9
diff -u -p -r1.135.2.9 dwarf2read.c
--- dwarf2read.c	21 Feb 2004 21:08:33 -0000	1.135.2.9
+++ dwarf2read.c	21 Feb 2004 21:11:42 -0000
@@ -788,6 +788,10 @@ static char *determine_prefix (struct di
 
 static char *determine_prefix_aux (struct die_info *die, struct dwarf2_cu *);
 
+static char *partial_determine_prefix (struct partial_die_info *die, struct dwarf2_cu *);
+
+static char *partial_determine_prefix_aux (struct partial_die_info *die, struct dwarf2_cu *);
+
 static char *typename_concat (const char *prefix, const char *suffix);
 
 static char *class_name (struct die_info *die, struct dwarf2_cu *);
@@ -1519,6 +1523,7 @@ add_partial_symbol (struct partial_die_i
   struct objfile *objfile = cu->objfile;
   CORE_ADDR addr = 0;
   char *actual_name = pdi->name;
+  const char *my_prefix;
   const struct partial_symbol *psym = NULL;
   CORE_ADDR baseaddr;
 
@@ -1526,15 +1531,24 @@ add_partial_symbol (struct partial_die_i
 
   /* If we're not in the global namespace and if the namespace name
      isn't encoded in a mangled actual_name, add it.  */
-  
-  if (pdi_needs_namespace (pdi->tag, namespace))
+
+  if (pdi->spec_offset
+      && pdi_needs_namespace (pdi->tag, "foo"))
+    my_prefix = partial_determine_prefix (pdi, cu);
+  else
+    my_prefix = namespace;
+
+  if (pdi_needs_namespace (pdi->tag, my_prefix))
     {
-      actual_name = alloca (strlen (pdi->name) + 2 + strlen (namespace) + 1);
-      strcpy (actual_name, namespace);
+      actual_name = alloca (strlen (pdi->name) + 2 + strlen (my_prefix) + 1);
+      strcpy (actual_name, my_prefix);
       strcat (actual_name, "::");
       strcat (actual_name, pdi->name);
     }
 
+  if (my_prefix)
+    free (my_prefix);
+
   switch (pdi->tag)
     {
     case DW_TAG_subprogram:
@@ -1719,7 +1733,8 @@ add_partial_namespace (struct partial_di
   /* Now scan partial symbols in that namespace.  */
 
   if (pdi->has_children)
-    info_ptr = scan_partial_symbols (info_ptr, lowpc, highpc, cu, full_name);
+    info_ptr = scan_partial_symbols (pdi->die_child->offset + dwarf_info_buffer,
+				     lowpc, highpc, cu, full_name);
 
   return info_ptr;
 }
@@ -1735,7 +1750,7 @@ add_partial_structure (struct partial_di
   char *actual_class_name = NULL;
 
   if (cu->language == language_cplus
-      && (namespace == NULL || namespace[0] == '\0')
+      && namespace == NULL
       && struct_pdi->name != NULL
       && struct_pdi->has_children)
     {
@@ -1750,21 +1765,6 @@ add_partial_structure (struct partial_di
 	 could fix this by only using the demangled name to get the
 	 prefix (but see comment in read_structure_scope).  */
 
-      /* FIXME: carlton/2004-01-23: If NAMESPACE equals "", we have
-	 the appropriate debug information, so it would be nice to be
-	 able to avoid this hack.  But NAMESPACE may not be the
-	 namespace where this class was defined: NAMESPACE reflects
-	 where STRUCT_PDI occurs in the tree of dies, but because of
-	 DW_AT_specification, that may not actually tell us where the
-	 class is defined.  (See the comment in read_func_scope for an
-	 example of how this could occur.)
-
-         Unfortunately, our current partial symtab data structures are
-         completely unable to deal with DW_AT_specification.  So, for
-         now, the best thing to do is to get nesting information from
-         places other than the tree structure of dies if there's any
-         chance that a DW_AT_specification is involved. :-( */
-
       struct partial_die_info *child_pdi = struct_pdi->die_child;
 
       while (child_pdi != NULL)
@@ -4710,6 +4710,7 @@ load_partial_die (struct partial_die_inf
 	  break;
 	case DW_AT_abstract_origin:
 	case DW_AT_specification:
+	case DW_AT_extension:
 	  part_die->has_specification = 1;
 	  part_die->spec_offset = dwarf2_get_ref_die_offset (&attr, cu);
 	  break;
@@ -6490,7 +6491,7 @@ determine_prefix_aux (struct die_info *d
 	      const char *parent_name = dwarf2_name (parent, cu);
 
 	      if (parent_name != NULL)
-		retval = typename_concat (parent_prefix, dwarf2_name (parent, cu));
+		retval = typename_concat (parent_prefix, parent_name);
 	      else
 		/* FIXME: carlton/2003-11-10: I'm not sure what the
 		   best thing to do here is.  */
@@ -6500,6 +6501,70 @@ determine_prefix_aux (struct die_info *d
 	  else
 	    retval = class_name (parent, cu);
 	}
+	break;
+      default:
+	retval = parent_prefix;
+	break;
+      }
+
+      if (retval != parent_prefix)
+	xfree (parent_prefix);
+      return retval;
+    }
+}
+
+/* Likewise for partial DIEs.  */
+
+static char *
+partial_determine_prefix (struct partial_die_info *die, struct dwarf2_cu *cu)
+{
+  char *prefix = partial_determine_prefix_aux (die, cu);
+
+  return prefix ? prefix : xstrdup ("");
+}
+
+/* Return the name of the namespace/class that DIE is defined
+   within, or NULL if we can't tell.  The caller should xfree the
+   result.  */
+
+static char *
+partial_determine_prefix_aux (struct partial_die_info *die, struct dwarf2_cu *cu)
+{
+  struct partial_die_info *parent;
+
+  if (cu->language != language_cplus)
+    return NULL;
+
+  if (die->spec_offset)
+    die = find_partial_die (die->spec_offset, cu);
+
+  parent = die->die_parent;
+
+  if (parent == NULL)
+    {
+      return (processing_has_namespace_info ? xstrdup ("") : NULL);
+    }
+  else
+    {
+      char *parent_prefix = partial_determine_prefix_aux (parent, cu);
+      char *retval;
+
+      fixup_partial_die (parent, cu);
+
+      switch (parent->tag) {
+      case DW_TAG_namespace:
+	if (parent->name != NULL)
+	  retval = typename_concat (parent_prefix, parent->name);
+	else
+	  retval = typename_concat (parent_prefix, "(anonymous namespace)");
+	break;
+      case DW_TAG_class_type:
+      case DW_TAG_structure_type:
+	if (parent->name != NULL)
+	  retval = typename_concat (parent_prefix, parent->name);
+	else
+	  retval = typename_concat (parent_prefix,
+				    "<<anonymous class>>");
 	break;
       default:
 	retval = parent_prefix;


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