+/* See if we can figure out if the class lives in a namespace. We do
+ this by looking for a member function; its demangled name will
+ contain namespace info, if there is any.
+ Return the computed name or NULL.
+ Space for the result is allocated on the objfile's obstack.
+ This is the full-die version of guess_partial_die_structure_name.
+ In this case we know DIE has no useful parent. */
+
+static char *
+guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu)
+{
+ struct die_info *spec_die;
+ struct dwarf2_cu *spec_cu;
+ struct die_info *child;
+
+ spec_cu = cu;
+ spec_die = die_specification (die, &spec_cu);
+ if (spec_die != NULL)
+ {
+ die = spec_die;
+ cu = spec_cu;
+ }
+
+ for (child = die->child;
+ child != NULL;
+ child = child->sibling)
+ {
+ if (child->tag == DW_TAG_subprogram)
+ {
+ struct attribute *attr;
+
+ attr = dwarf2_attr (child, DW_AT_linkage_name, cu);
+ if (attr == NULL)
+ attr = dwarf2_attr (child, DW_AT_MIPS_linkage_name, cu);
+ if (attr != NULL)
+ {
+ char *actual_name
+ = language_class_name_from_physname (cu->language_defn,
+ DW_STRING (attr));
+ char *name = NULL;
+
+ if (actual_name != NULL)
+ {
+ char *die_name = dwarf2_name (die, cu);
+
+ if (die_name != NULL
+ && strcmp (die_name, actual_name) != 0)
+ {
+ /* Strip off the class name from the full name.
+ We want the prefix. */
+ int die_name_len = strlen (die_name);
+ int actual_name_len = strlen (actual_name);
+
+ /* Test for '::' as a sanity check. */
+ if (actual_name_len > die_name_len + 2
+ && actual_name[actual_name_len - die_name_len - 1] == ':')
+ name =
+ obsavestring (actual_name,
+ actual_name_len - die_name_len - 2,
+ &cu->objfile->objfile_obstack);
+ }
+ }
+ xfree (actual_name);
+ return name;
+ }
+ }
+ }
+
+ return NULL;
+}
+