ENUM_BITFIELD(dwarf_form) form : 16;
};
+/* Additional GDB-specific attribute forms. */
+enum
+ {
+ /* A string which has been updated to GDB's internal
+ representation (e.g. converted to canonical form) and does not
+ need to be updated again. */
+ GDB_FORM_cached_string = 0xff
+ };
+
/* Attributes have a name and a value */
struct attribute
{
CORE_ADDR *lowpc, CORE_ADDR *highpc,
int need_pc, struct dwarf2_cu *cu);
+static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
+ CORE_ADDR *highpc, int need_pc,
+ struct dwarf2_cu *cu);
+
static void add_partial_enumeration (struct partial_die_info *enum_pdi,
struct dwarf2_cu *cu);
static void read_namespace (struct die_info *die, struct dwarf2_cu *);
+static void read_module (struct die_info *die, struct dwarf2_cu *cu);
+
static const char *namespace_name (struct die_info *die,
int *is_anonymous, struct dwarf2_cu *);
static char *dwarf2_linkage_name (struct die_info *, struct dwarf2_cu *);
+static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *,
+ struct obstack *);
+
static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *);
static struct die_info *dwarf2_extension (struct die_info *die,
case DW_TAG_namespace:
add_partial_namespace (pdi, lowpc, highpc, need_pc, cu);
break;
+ case DW_TAG_module:
+ add_partial_module (pdi, lowpc, highpc, need_pc, cu);
+ break;
default:
break;
}
scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
}
+/* Read a partial die corresponding to a Fortran module. */
+
+static void
+add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
+ CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
+{
+ /* Now scan partial symbols in that module.
+
+ FIXME: Support the separate Fortran module namespaces. */
+
+ if (pdi->has_children)
+ scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
+}
+
/* Read a partial die corresponding to a subprogram and create a partial
symbol for that subprogram. When the CU language allows it, this
routine also defines a partial symbol for each nested subprogram
case DW_TAG_base_type:
case DW_TAG_subrange_type:
+ case DW_TAG_typedef:
/* Add a typedef symbol for the type definition, if it has a
DW_AT_name. */
new_symbol (die, read_type_die (die, cu), cu);
processing_has_namespace_info = 1;
read_namespace (die, cu);
break;
+ case DW_TAG_module:
+ read_module (die, cu);
+ break;
case DW_TAG_imported_declaration:
case DW_TAG_imported_module:
/* FIXME: carlton/2002-10-16: Eventually, we should use the
cu->last_fn = thisfn;
}
+/* qsort helper for inherit_abstract_dies. */
+
+static int
+unsigned_int_compar (const void *ap, const void *bp)
+{
+ unsigned int a = *(unsigned int *) ap;
+ unsigned int b = *(unsigned int *) bp;
+
+ return (a > b) - (b > a);
+}
+
+/* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
+ Inherit only the children of the DW_AT_abstract_origin DIE not being already
+ referenced by DW_AT_abstract_origin from the children of the current DIE. */
+
+static void
+inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
+{
+ struct die_info *child_die;
+ unsigned die_children_count;
+ /* CU offsets which were referenced by children of the current DIE. */
+ unsigned *offsets;
+ unsigned *offsets_end, *offsetp;
+ /* Parent of DIE - referenced by DW_AT_abstract_origin. */
+ struct die_info *origin_die;
+ /* Iterator of the ORIGIN_DIE children. */
+ struct die_info *origin_child_die;
+ struct cleanup *cleanups;
+ struct attribute *attr;
+
+ attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
+ if (!attr)
+ return;
+
+ origin_die = follow_die_ref (die, attr, &cu);
+ if (die->tag != origin_die->tag)
+ complaint (&symfile_complaints,
+ _("DIE 0x%x and its abstract origin 0x%x have different tags"),
+ die->offset, origin_die->offset);
+
+ child_die = die->child;
+ die_children_count = 0;
+ while (child_die && child_die->tag)
+ {
+ child_die = sibling_die (child_die);
+ die_children_count++;
+ }
+ offsets = xmalloc (sizeof (*offsets) * die_children_count);
+ cleanups = make_cleanup (xfree, offsets);
+
+ offsets_end = offsets;
+ child_die = die->child;
+ while (child_die && child_die->tag)
+ {
+ attr = dwarf2_attr (child_die, DW_AT_abstract_origin, cu);
+ /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
+ counterpart may exist. */
+ if (attr)
+ {
+ struct die_info *child_origin_die;
+
+ child_origin_die = follow_die_ref (child_die, attr, &cu);
+ if (child_die->tag != child_origin_die->tag)
+ complaint (&symfile_complaints,
+ _("Child DIE 0x%x and its abstract origin 0x%x have "
+ "different tags"), child_die->offset,
+ child_origin_die->offset);
+ *offsets_end++ = child_origin_die->offset;
+ }
+ child_die = sibling_die (child_die);
+ }
+ qsort (offsets, offsets_end - offsets, sizeof (*offsets),
+ unsigned_int_compar);
+ for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++)
+ if (offsetp[-1] == *offsetp)
+ complaint (&symfile_complaints, _("Multiple children of DIE 0x%x refer "
+ "to DIE 0x%x as their abstract origin"),
+ die->offset, *offsetp);
+
+ offsetp = offsets;
+ origin_child_die = origin_die->child;
+ while (origin_child_die && origin_child_die->tag)
+ {
+ /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
+ while (offsetp < offsets_end && *offsetp < origin_child_die->offset)
+ offsetp++;
+ if (offsetp >= offsets_end || *offsetp > origin_child_die->offset)
+ {
+ /* Found that ORIGIN_CHILD_DIE is really not referenced. */
+ process_die (origin_child_die, cu);
+ }
+ origin_child_die = sibling_die (origin_child_die);
+ }
+
+ do_cleanups (cleanups);
+}
+
static void
read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
{
}
}
+ inherit_abstract_dies (die, cu);
+
new = pop_context ();
/* Make a block for the local symbols within. */
block = finish_block (new->name, &local_symbols, new->old_blocks,
}
}
+/* Read a Fortran module. */
+
+static void
+read_module (struct die_info *die, struct dwarf2_cu *cu)
+{
+ struct die_info *child_die = die->child;
+
+ /* FIXME: Support the separate Fortran module namespaces. */
+
+ while (child_die && child_die->tag)
+ {
+ process_die (child_die, cu);
+ child_die = sibling_die (child_die);
+ }
+}
+
/* Return the name of the namespace represented by DIE. Set
*IS_ANONYMOUS to tell whether or not the namespace is an anonymous
namespace. */
struct attribute *attr;
type = die_type (die, cu);
- ftype = make_function_type (type, (struct type **) 0);
+ ftype = make_function_type (type, (struct type **) 0, cu->objfile);
/* All functions in C++, Pascal and Java have prototypes. */
attr = dwarf2_attr (die, DW_AT_prototyped, cu);
type_flags |= TYPE_FLAG_UNSIGNED;
break;
case DW_ATE_signed_char:
- if (cu->language == language_ada || cu->language == language_m2)
+ if (cu->language == language_ada || cu->language == language_m2
+ || cu->language == language_pascal)
code = TYPE_CODE_CHAR;
break;
case DW_ATE_unsigned_char:
- if (cu->language == language_ada || cu->language == language_m2)
+ if (cu->language == language_ada || cu->language == language_m2
+ || cu->language == language_pascal)
code = TYPE_CODE_CHAR;
type_flags |= TYPE_FLAG_UNSIGNED;
break;
switch (attr.name)
{
case DW_AT_name:
-
- /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
- if (part_die->name == NULL)
- part_die->name = DW_STRING (&attr);
+ switch (part_die->tag)
+ {
+ case DW_TAG_compile_unit:
+ /* Compilation units have a DW_AT_name that is a filename, not
+ a source language identifier. */
+ case DW_TAG_enumeration_type:
+ case DW_TAG_enumerator:
+ /* These tags always have simple identifiers already; no need
+ to canonicalize them. */
+ part_die->name = DW_STRING (&attr);
+ break;
+ default:
+ part_die->name
+ = dwarf2_canonicalize_name (DW_STRING (&attr), cu,
+ &cu->comp_unit_obstack);
+ break;
+ }
break;
case DW_AT_comp_dir:
if (part_die->dirname == NULL)
switch (lang)
{
case DW_LANG_C89:
+ case DW_LANG_C99:
case DW_LANG_C:
cu->language = language_c;
break;
&& dwarf2_attr (die, DW_AT_type, cu) != NULL)
{
SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
- add_symbol_to_list (sym, &global_symbols);
+ add_symbol_to_list (sym, cu->list_in_scope);
+ }
+ else if (!die_is_declaration (die, cu))
+ {
+ /* Use the default LOC_OPTIMIZED_OUT class. */
+ gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT);
+ add_symbol_to_list (sym, cu->list_in_scope);
}
}
break;
DW_ADDR (attr));
SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
break;
+ case DW_FORM_string:
case DW_FORM_strp:
/* DW_STRING is already allocated on the obstack, point directly
to it. */
attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
if (attr && DW_STRING (attr))
return DW_STRING (attr);
- attr = dwarf2_attr (die, DW_AT_name, cu);
- if (attr && DW_STRING (attr))
- return DW_STRING (attr);
- return NULL;
+ return dwarf2_name (die, cu);
+}
+
+/* Get name of a die, return NULL if not found. */
+
+static char *
+dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu,
+ struct obstack *obstack)
+{
+ if (name && cu->language == language_cplus)
+ {
+ char *canon_name = cp_canonicalize_string (name);
+
+ if (canon_name != NULL)
+ {
+ if (strcmp (canon_name, name) != 0)
+ name = obsavestring (canon_name, strlen (canon_name),
+ obstack);
+ xfree (canon_name);
+ }
+ }
+
+ return name;
}
/* Get name of a die, return NULL if not found. */
struct attribute *attr;
attr = dwarf2_attr (die, DW_AT_name, cu);
- if (attr && DW_STRING (attr))
- return DW_STRING (attr);
- return NULL;
+ if (!attr || !DW_STRING (attr))
+ return NULL;
+
+ switch (die->tag)
+ {
+ case DW_TAG_compile_unit:
+ /* Compilation units have a DW_AT_name that is a filename, not
+ a source language identifier. */
+ case DW_TAG_enumeration_type:
+ case DW_TAG_enumerator:
+ /* These tags always have simple identifiers already; no need
+ to canonicalize them. */
+ return DW_STRING (attr);
+ default:
+ if (attr->form != GDB_FORM_cached_string)
+ {
+ DW_STRING (attr)
+ = dwarf2_canonicalize_name (DW_STRING (attr), cu,
+ &cu->objfile->objfile_obstack);
+ attr->form = GDB_FORM_cached_string;
+ }
+ return DW_STRING (attr);
+ }
}
/* Return the die that this die in an extension of, or NULL if there
return "DW_FORM_ref_udata";
case DW_FORM_indirect:
return "DW_FORM_indirect";
+ case GDB_FORM_cached_string:
+ return "GDB_FORM_cached_string";
default:
return "DW_FORM_<unknown>";
}
break;
case DW_FORM_string:
case DW_FORM_strp:
+ case GDB_FORM_cached_string:
fprintf_unfiltered (f, "string: \"%s\"",
DW_STRING (&die->attrs[i])
? DW_STRING (&die->attrs[i]) : "");
{
gdb_byte *mac_ptr, *mac_end;
struct macro_source_file *current_file = 0;
+ enum dwarf_macinfo_record_type macinfo_type;
+ int at_commandline;
if (dwarf2_per_objfile->macinfo_buffer == NULL)
{
return;
}
+ /* First pass: Find the name of the base filename.
+ This filename is needed in order to process all macros whose definition
+ (or undefinition) comes from the command line. These macros are defined
+ before the first DW_MACINFO_start_file entry, and yet still need to be
+ associated to the base file.
+
+ To determine the base file name, we scan the macro definitions until we
+ reach the first DW_MACINFO_start_file entry. We then initialize
+ CURRENT_FILE accordingly so that any macro definition found before the
+ first DW_MACINFO_start_file can still be associated to the base file. */
+
mac_ptr = dwarf2_per_objfile->macinfo_buffer + offset;
mac_end = dwarf2_per_objfile->macinfo_buffer
+ dwarf2_per_objfile->macinfo_size;
- for (;;)
+ do
{
- enum dwarf_macinfo_record_type macinfo_type;
-
/* Do we at least have room for a macinfo type byte? */
if (mac_ptr >= mac_end)
{
- dwarf2_macros_too_long_complaint ();
- return;
+ /* Complaint is printed during the second pass as GDB will probably
+ stop the first pass earlier upon finding DW_MACINFO_start_file. */
+ break;
}
macinfo_type = read_1_byte (abfd, mac_ptr);
/* A zero macinfo type indicates the end of the macro
information. */
case 0:
- return;
+ break;
+
+ case DW_MACINFO_define:
+ case DW_MACINFO_undef:
+ /* Only skip the data by MAC_PTR. */
+ {
+ unsigned int bytes_read;
+
+ read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
+ mac_ptr += bytes_read;
+ read_string (abfd, mac_ptr, &bytes_read);
+ mac_ptr += bytes_read;
+ }
+ break;
+
+ case DW_MACINFO_start_file:
+ {
+ unsigned int bytes_read;
+ int line, file;
+
+ line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
+ mac_ptr += bytes_read;
+ file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
+ mac_ptr += bytes_read;
+
+ current_file = macro_start_file (file, line, current_file, comp_dir,
+ lh, cu->objfile);
+ }
+ break;
+
+ case DW_MACINFO_end_file:
+ /* No data to skip by MAC_PTR. */
+ break;
+
+ case DW_MACINFO_vendor_ext:
+ /* Only skip the data by MAC_PTR. */
+ {
+ unsigned int bytes_read;
+
+ read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
+ mac_ptr += bytes_read;
+ read_string (abfd, mac_ptr, &bytes_read);
+ mac_ptr += bytes_read;
+ }
+ break;
+
+ default:
+ break;
+ }
+ } while (macinfo_type != 0 && current_file == NULL);
+
+ /* Second pass: Process all entries.
+
+ Use the AT_COMMAND_LINE flag to determine whether we are still processing
+ command-line macro definitions/undefinitions. This flag is unset when we
+ reach the first DW_MACINFO_start_file entry. */
+
+ mac_ptr = dwarf2_per_objfile->macinfo_buffer + offset;
+
+ /* Determines if GDB is still before first DW_MACINFO_start_file. If true
+ GDB is still reading the definitions from command line. First
+ DW_MACINFO_start_file will need to be ignored as it was already executed
+ to create CURRENT_FILE for the main source holding also the command line
+ definitions. On first met DW_MACINFO_start_file this flag is reset to
+ normally execute all the remaining DW_MACINFO_start_file macinfos. */
+
+ at_commandline = 1;
+
+ do
+ {
+ /* Do we at least have room for a macinfo type byte? */
+ if (mac_ptr >= mac_end)
+ {
+ dwarf2_macros_too_long_complaint ();
+ break;
+ }
+
+ macinfo_type = read_1_byte (abfd, mac_ptr);
+ mac_ptr++;
+
+ switch (macinfo_type)
+ {
+ /* A zero macinfo type indicates the end of the macro
+ information. */
+ case 0:
+ break;
case DW_MACINFO_define:
case DW_MACINFO_undef:
mac_ptr += bytes_read;
if (! current_file)
+ {
+ /* DWARF violation as no main source is present. */
+ complaint (&symfile_complaints,
+ _("debug info with no main source gives macro %s "
+ "on line %d: %s"),
+ macinfo_type ==
+ DW_MACINFO_define ? _("definition") : macinfo_type ==
+ DW_MACINFO_undef ? _("undefinition") :
+ "something-or-other", line, body);
+ break;
+ }
+ if ((line == 0 && !at_commandline) || (line != 0 && at_commandline))
complaint (&symfile_complaints,
- _("debug info gives macro %s outside of any file: %s"),
+ _("debug info gives %s macro %s with %s line %d: %s"),
+ at_commandline ? _("command-line") : _("in-file"),
macinfo_type ==
- DW_MACINFO_define ? "definition" : macinfo_type ==
- DW_MACINFO_undef ? "undefinition" :
- "something-or-other", body);
- else
- {
- if (macinfo_type == DW_MACINFO_define)
- parse_macro_definition (current_file, line, body);
- else if (macinfo_type == DW_MACINFO_undef)
- macro_undef (current_file, line, body);
- }
+ DW_MACINFO_define ? _("definition") : macinfo_type ==
+ DW_MACINFO_undef ? _("undefinition") :
+ "something-or-other",
+ line == 0 ? _("zero") : _("non-zero"), line, body);
+
+ if (macinfo_type == DW_MACINFO_define)
+ parse_macro_definition (current_file, line, body);
+ else if (macinfo_type == DW_MACINFO_undef)
+ macro_undef (current_file, line, body);
}
break;
file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
mac_ptr += bytes_read;
- current_file = macro_start_file (file, line,
- current_file, comp_dir,
- lh, cu->objfile);
+ if ((line == 0 && !at_commandline) || (line != 0 && at_commandline))
+ complaint (&symfile_complaints,
+ _("debug info gives source %d included "
+ "from %s at %s line %d"),
+ file, at_commandline ? _("command-line") : _("file"),
+ line == 0 ? _("zero") : _("non-zero"), line);
+
+ if (at_commandline)
+ {
+ /* This DW_MACINFO_start_file was executed in the pass one. */
+ at_commandline = 0;
+ }
+ else
+ current_file = macro_start_file (file, line,
+ current_file, comp_dir,
+ lh, cu->objfile);
}
break;
}
break;
}
- }
+ } while (macinfo_type != 0);
}
/* Check if the attribute's form is a DW_FORM_block*