#endif
#ifndef LCC_PRODUCER
-#define LCC_PRODUCER "LUCID C++ "
+#define LCC_PRODUCER "NCR C/C++"
#endif
#ifndef CFRONT_PRODUCER
unsigned long at_member;
unsigned long at_discr;
BLOCK * at_discr_value;
- unsigned short at_visibility;
- unsigned long at_import;
BLOCK * at_string_length;
char * at_comp_dir;
char * at_producer;
- unsigned long at_frame_base;
unsigned long at_start_scope;
unsigned long at_stride_size;
unsigned long at_src_info;
char * at_prototyped;
unsigned int has_at_low_pc:1;
unsigned int has_at_stmt_list:1;
+ unsigned int has_at_byte_size:1;
unsigned int short_element_list:1;
};
static struct type **utypes; /* Pointer to array of user type pointers */
static int numutypes; /* Max number of user type pointers */
+/* Record the language for the compilation unit which is currently being
+ processed. We know it once we have seen the TAG_compile_unit DIE,
+ and we need it while processing the DIE's for that compilation unit.
+ It is eventually saved in the symtab structure, but we don't finalize
+ the symtab struct until we have processed all the DIE's for the
+ compilation unit. */
+
+static enum language cu_language;
+
/* Forward declarations of static functions so we don't have to worry
about ordering within this file. */
static struct symbol *
new_symbol PARAMS ((struct dieinfo *, struct objfile *));
+static void
+synthesize_typedef PARAMS ((struct dieinfo *, struct objfile *,
+ struct type *));
+
static int
locval PARAMS ((char *));
record_minimal_symbol PARAMS ((char *, CORE_ADDR, enum minimal_symbol_type,
struct objfile *));
+static void
+set_cu_language PARAMS ((struct dieinfo *));
+
+/*
+
+LOCAL FUNCTION
+
+ set_cu_language -- set local copy of language for compilation unit
+
+SYNOPSIS
+
+ void
+ set_cu_language (struct dieinfo *dip)
+
+DESCRIPTION
+
+ Decode the language attribute for a compilation unit DIE and
+ remember what the language was. We use this at various times
+ when processing DIE's for a given compilation unit.
+
+RETURNS
+
+ No return value.
+
+ */
+
+static void
+set_cu_language (dip)
+ struct dieinfo *dip;
+{
+ switch (dip -> at_language)
+ {
+ case LANG_C89:
+ case LANG_C:
+ cu_language = language_c;
+ break;
+ case LANG_C_PLUS_PLUS:
+ cu_language = language_cplus;
+ break;
+ case LANG_ADA83:
+ case LANG_COBOL74:
+ case LANG_COBOL85:
+ case LANG_FORTRAN77:
+ case LANG_FORTRAN90:
+ case LANG_PASCAL83:
+ case LANG_MODULA2:
+ default:
+ cu_language = language_unknown;
+ break;
+ }
+}
+
/*
GLOBAL FUNCTION
char *tpart1;
struct dieinfo mbr;
char *nextdie;
+ int anonymous_size;
if ((type = lookup_utype (dip -> die_ref)) == NULL)
{
INIT_CPLUS_SPECIFIC(type);
switch (dip -> die_tag)
{
+ case TAG_class_type:
+ TYPE_CODE (type) = TYPE_CODE_CLASS;
+ tpart1 = "class";
+ break;
case TAG_structure_type:
TYPE_CODE (type) = TYPE_CODE_STRUCT;
tpart1 = "struct";
/* Should never happen */
TYPE_CODE (type) = TYPE_CODE_UNDEF;
tpart1 = "???";
- SQUAWK (("missing structure or union tag"));
+ SQUAWK (("missing class, structure, or union tag"));
break;
}
/* Some compilers try to be helpful by inventing "fake" names for
TYPE_NAME (type) = obconcat (&objfile -> type_obstack,
tpart1, " ", dip -> at_name);
}
- if (dip -> at_byte_size != 0)
- {
- TYPE_LENGTH (type) = dip -> at_byte_size;
- }
+ /* Use whatever size is known. Zero is a valid size. We might however
+ wish to check has_at_byte_size to make sure that some byte size was
+ given explicitly, but DWARF doesn't specify that explicit sizes of
+ zero have to present, so complaining about missing sizes should
+ probably not be the default. */
+ TYPE_LENGTH (type) = dip -> at_byte_size;
thisdie += dip -> die_length;
while (thisdie < enddie)
{
itself. The result is the bit offset of the LSB of the field. */
if (mbr.at_bit_size > 0)
{
+ if (mbr.has_at_byte_size)
+ {
+ /* The size of the anonymous object containing the bit field
+ is explicit, so use the indicated size (in bytes). */
+ anonymous_size = mbr.at_byte_size;
+ }
+ else
+ {
+ /* The size of the anonymous object containing the bit field
+ matches the size of an object of the bit field's type.
+ DWARF allows at_byte_size to be left out in such cases,
+ as a debug information size optimization. */
+ anonymous_size = TYPE_LENGTH (list -> field.type);
+ }
list -> field.bitpos +=
- mbr.at_byte_size * 8 - mbr.at_bit_offset - mbr.at_bit_size;
+ anonymous_size * 8 - mbr.at_bit_offset - mbr.at_bit_size;
}
#endif
nfields++;
{
TYPE_NFIELDS (type) = nfields;
TYPE_FIELDS (type) = (struct field *)
- obstack_alloc (&objfile -> type_obstack,
- sizeof (struct field) * nfields);
+ TYPE_ALLOC (type, sizeof (struct field) * nfields);
/* Copy the saved-up fields into the field vector. */
for (n = nfields; list; list = list -> next)
{
type = struct_type (dip, thisdie, enddie, objfile);
if (!(TYPE_FLAGS (type) & TYPE_FLAG_STUB))
{
- if ((sym = new_symbol (dip, objfile)) != NULL)
+ sym = new_symbol (dip, objfile);
+ if (sym != NULL)
{
SYMBOL_TYPE (sym) = type;
+ if (cu_language == language_cplus)
+ {
+ synthesize_typedef (dip, objfile, type);
+ }
}
}
}
struct symbol *sym;
type = enum_type (dip, objfile);
- if ((sym = new_symbol (dip, objfile)) != NULL)
+ sym = new_symbol (dip, objfile);
+ if (sym != NULL)
{
SYMBOL_TYPE (sym) = type;
+ if (cu_language == language_cplus)
+ {
+ synthesize_typedef (dip, objfile, type);
+ }
}
}
is not auto. We also leave the demangling style alone if we find a
gcc (cc1) producer, as opposed to a g++ (cc1plus) producer. */
-#if 0 /* Works, but is disabled for now. -fnf */
- if (current_demangling_style == auto_demangling)
+#if 1 /* Works, but is experimental. -fnf */
+ if (AUTO_DEMANGLING)
{
if (STREQN (producer, GPLUS_PRODUCER, strlen (GPLUS_PRODUCER)))
{
objfile -> ei.entry_file_lowpc = dip -> at_low_pc;
objfile -> ei.entry_file_highpc = dip -> at_high_pc;
}
+ set_cu_language (dip);
if (dip -> at_producer != NULL)
{
handle_producer (dip -> at_producer);
utypes = (struct type **) xmalloc (numutypes * sizeof (struct type *));
back_to = make_cleanup (free, utypes);
memset (utypes, 0, numutypes * sizeof (struct type *));
- start_symtab (dip -> at_name, NULL, dip -> at_low_pc);
+ start_symtab (dip -> at_name, dip -> at_comp_dir, dip -> at_low_pc);
decode_line_numbers (lnbase);
process_dies (thisdie + dip -> die_length, enddie, objfile);
symtab = end_symtab (dip -> at_high_pc, 0, 0, objfile);
- /* FIXME: The following may need to be expanded for other languages */
- switch (dip -> at_language)
+ if (symtab != NULL)
{
- case LANG_C89:
- case LANG_C:
- symtab -> language = language_c;
- break;
- case LANG_C_PLUS_PLUS:
- symtab -> language = language_cplus;
- break;
- default:
- ;
- }
+ symtab -> language = cu_language;
+ }
do_cleanups (back_to);
utypes = NULL;
numutypes = 0;
case TAG_lexical_block:
read_lexical_block_scope (&di, thisdie, nextdie, objfile);
break;
+ case TAG_class_type:
case TAG_structure_type:
case TAG_union_type:
read_structure_scope (&di, thisdie, nextdie, objfile);
struct partial_symtab *pst;
{
int i;
+ struct cleanup *old_chain;
if (pst != NULL)
{
}
if (DBLENGTH (pst)) /* Otherwise it's a dummy */
{
+ buildsym_init ();
+ old_chain = make_cleanup (really_free_pendings, 0);
pst -> symtab = read_ofile_symtab (pst);
if (info_verbose)
{
fflush (stdout);
}
sort_symtab_syms (pst -> symtab);
+ do_cleanups (old_chain);
}
pst -> readin = 1;
}
add to a partial symbol table, finish filling in the die info
and then add a partial symbol table entry for it.
+NOTES
+
+ The caller must ensure that the DIE has a valid name attribute.
*/
static void
objfile -> static_psymbols,
0);
break;
+ case TAG_class_type:
case TAG_structure_type:
case TAG_union_type:
+ case TAG_enumeration_type:
ADD_PSYMBOL_TO_LIST (dip -> at_name, strlen (dip -> at_name),
STRUCT_NAMESPACE, LOC_TYPEDEF,
objfile -> static_psymbols,
0);
- break;
- case TAG_enumeration_type:
- if (dip -> at_name)
+ if (cu_language == language_cplus)
{
+ /* For C++, these implicitly act as typedefs as well. */
ADD_PSYMBOL_TO_LIST (dip -> at_name, strlen (dip -> at_name),
- STRUCT_NAMESPACE, LOC_TYPEDEF,
+ VAR_NAMESPACE, LOC_TYPEDEF,
objfile -> static_psymbols,
0);
}
- add_enum_psymbol (dip, objfile);
break;
}
}
Process the DIE's within a single compilation unit, looking for
interesting DIE's that contribute to the partial symbol table entry
- for this compilation unit. Since we cannot follow any sibling
- chains without reading the complete DIE info for every DIE,
- it is probably faster to just sequentially check each one to
- see if it is one of the types we are interested in, and if so,
- then extract all the attributes info and generate a partial
- symbol table entry.
+ for this compilation unit.
NOTES
+ There are some DIE's that may appear both at file scope and within
+ the scope of a function. We are only interested in the ones at file
+ scope, and the only way to tell them apart is to keep track of the
+ scope. For example, consider the test case:
+
+ static int i;
+ main () { int j; }
+
+ for which the relevant DWARF segment has the structure:
+
+ 0x51:
+ 0x23 global subrtn sibling 0x9b
+ name main
+ fund_type FT_integer
+ low_pc 0x800004cc
+ high_pc 0x800004d4
+
+ 0x74:
+ 0x23 local var sibling 0x97
+ name j
+ fund_type FT_integer
+ location OP_BASEREG 0xe
+ OP_CONST 0xfffffffc
+ OP_ADD
+ 0x97:
+ 0x4
+
+ 0x9b:
+ 0x1d local var sibling 0xb8
+ name i
+ fund_type FT_integer
+ location OP_ADDR 0x800025dc
+
+ 0xb8:
+ 0x4
+
+ We want to include the symbol 'i' in the partial symbol table, but
+ not the symbol 'j'. In essence, we want to skip all the dies within
+ the scope of a TAG_global_subroutine DIE.
+
Don't attempt to add anonymous structures or unions since they have
no name. Anonymous enumerations however are processed, because we
want to extract their member names (the check for a tag name is
struct objfile *objfile;
{
char *nextdie;
+ char *temp;
struct dieinfo di;
while (thisdie < enddie)
{
case TAG_global_subroutine:
case TAG_subroutine:
+ completedieinfo (&di, objfile);
+ if (di.at_name && (di.has_at_low_pc || di.at_location))
+ {
+ add_partial_symbol (&di, objfile);
+ /* If there is a sibling attribute, adjust the nextdie
+ pointer to skip the entire scope of the subroutine.
+ Apply some sanity checking to make sure we don't
+ overrun or underrun the range of remaining DIE's */
+ if (di.at_sibling != 0)
+ {
+ temp = dbbase + di.at_sibling - dbroff;
+ if ((temp < thisdie) || (temp >= enddie))
+ {
+ dwarfwarn ("reference to DIE (0x%x) outside compilation unit", di.at_sibling);
+ }
+ else
+ {
+ nextdie = temp;
+ }
+ }
+ }
+ break;
case TAG_global_variable:
case TAG_local_variable:
completedieinfo (&di, objfile);
}
break;
case TAG_typedef:
+ case TAG_class_type:
case TAG_structure_type:
case TAG_union_type:
completedieinfo (&di, objfile);
break;
case TAG_enumeration_type:
completedieinfo (&di, objfile);
- add_partial_symbol (&di, objfile);
+ if (di.at_name)
+ {
+ add_partial_symbol (&di, objfile);
+ }
+ add_enum_psymbol (&di, objfile);
break;
}
}
else
{
completedieinfo (&di, objfile);
+ set_cu_language (&di);
if (di.at_sibling != 0)
{
nextdie = dbbase + di.at_sibling - dbroff;
/* First allocate a new partial symbol table structure */
- pst = start_psymtab_common (objfile, base_section_offsets, di.at_name,
- di.at_low_pc,
+ pst = start_psymtab_common (objfile, base_section_offsets,
+ di.at_name, di.at_low_pc,
objfile -> global_psymbols.next,
objfile -> static_psymbols.next);
sym = (struct symbol *) obstack_alloc (&objfile -> symbol_obstack,
sizeof (struct symbol));
memset (sym, 0, sizeof (struct symbol));
- SYMBOL_NAME (sym) = create_name (dip -> at_name, &objfile->symbol_obstack);
+ SYMBOL_NAME (sym) = create_name (dip -> at_name,
+ &objfile->symbol_obstack);
/* default assumptions */
SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
SYMBOL_CLASS (sym) = LOC_STATIC;
/* From varargs functions; gdb doesn't seem to have any interest in
this information, so just ignore it for now. (FIXME?) */
break;
+ case TAG_class_type:
case TAG_structure_type:
case TAG_union_type:
case TAG_enumeration_type:
/*
+LOCAL FUNCTION
+
+ synthesize_typedef -- make a symbol table entry for a "fake" typedef
+
+SYNOPSIS
+
+ static void synthesize_typedef (struct dieinfo *dip,
+ struct objfile *objfile,
+ struct type *type);
+
+DESCRIPTION
+
+ Given a pointer to a DWARF information entry, synthesize a typedef
+ for the name in the DIE, using the specified type.
+
+ This is used for C++ class, structs, unions, and enumerations to
+ set up the tag name as a type.
+
+ */
+
+static void
+synthesize_typedef (dip, objfile, type)
+ struct dieinfo *dip;
+ struct objfile *objfile;
+ struct type *type;
+{
+ struct symbol *sym = NULL;
+
+ if (dip -> at_name != NULL)
+ {
+ sym = (struct symbol *)
+ obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
+ memset (sym, 0, sizeof (struct symbol));
+ SYMBOL_NAME (sym) = create_name (dip -> at_name,
+ &objfile->symbol_obstack);
+ SYMBOL_TYPE (sym) = type;
+ SYMBOL_CLASS (sym) = LOC_TYPEDEF;
+ SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
+ add_symbol_to_list (sym, list_in_scope);
+ }
+}
+
+/*
+
LOCAL FUNCTION
decode_mod_fund_type -- decode a modified fundamental type
dip -> at_bit_offset = target_to_host (diep, nbytes, GET_UNSIGNED,
objfile);
break;
- case AT_visibility:
- dip -> at_visibility = target_to_host (diep, nbytes, GET_UNSIGNED,
- objfile);
- break;
case AT_sibling:
dip -> at_sibling = target_to_host (diep, nbytes, GET_UNSIGNED,
objfile);
case AT_byte_size:
dip -> at_byte_size = target_to_host (diep, nbytes, GET_UNSIGNED,
objfile);
+ dip -> has_at_byte_size = 1;
break;
case AT_bit_size:
dip -> at_bit_size = target_to_host (diep, nbytes, GET_UNSIGNED,
dip -> at_discr = target_to_host (diep, nbytes, GET_UNSIGNED,
objfile);
break;
- case AT_import:
- dip -> at_import = target_to_host (diep, nbytes, GET_UNSIGNED,
- objfile);
- break;
case AT_location:
dip -> at_location = diep;
break;
dip -> at_name = diep;
break;
case AT_comp_dir:
- dip -> at_comp_dir = diep;
+ /* For now, ignore any "hostname:" portion, since gdb doesn't
+ know how to deal with it. (FIXME). */
+ dip -> at_comp_dir = strrchr (diep, ':');
+ if (dip -> at_comp_dir != NULL)
+ {
+ dip -> at_comp_dir++;
+ }
+ else
+ {
+ dip -> at_comp_dir = diep;
+ }
break;
case AT_producer:
dip -> at_producer = diep;
break;
- case AT_frame_base:
- dip -> at_frame_base = target_to_host (diep, nbytes, GET_UNSIGNED,
- objfile);
- break;
case AT_start_scope:
dip -> at_start_scope = target_to_host (diep, nbytes, GET_UNSIGNED,
objfile);