f->length *= 2;
f->vector = (struct type **)
xrealloc (f->vector, f->length * sizeof (struct type *));
- bzero (&f->vector[f->length / 2],
- f->length * sizeof (struct type *) / 2);
+ memset (&f->vector[f->length / 2],
+ '\0', f->length * sizeof (struct type *) / 2);
}
return &f->vector[index];
}
{
enum minimal_symbol_type ms_type;
- switch (type &~ N_EXT) {
- case N_TEXT: ms_type = mst_text; break;
- case N_DATA: ms_type = mst_data; break;
- case N_BSS: ms_type = mst_bss; break;
- case N_ABS: ms_type = mst_abs; break;
+ switch (type)
+ {
+ case N_TEXT | N_EXT: ms_type = mst_text; break;
+ case N_DATA | N_EXT: ms_type = mst_data; break;
+ case N_BSS | N_EXT: ms_type = mst_bss; break;
+ case N_ABS | N_EXT: ms_type = mst_abs; break;
#ifdef N_SETV
- case N_SETV: ms_type = mst_data; break;
+ case N_SETV | N_EXT: ms_type = mst_data; break;
+ case N_SETV:
+ /* I don't think this type actually exists; since a N_SETV is the result
+ of going over many .o files, it doesn't make sense to have one
+ file local. */
+ ms_type = mst_file_data;
+ break;
#endif
+ case N_TEXT:
+ /* Don't put gcc_compiled, __gnu_compiled_cplus, and friends into
+ the minimal symbols, because if there is also another symbol
+ at the same address (e.g. the first function of the file),
+ lookup_minimal_symbol_by_pc would have no way of getting the
+ right one. */
+ if (name[0] == 'g'
+ && (strcmp (name, GCC_COMPILED_FLAG_SYMBOL) == 0
+ || strcmp (name, GCC2_COMPILED_FLAG_SYMBOL) == 0))
+ return;
+
+ {
+ char *tempstring = name;
+ if (tempstring[0] == bfd_get_symbol_leading_char (objfile->obfd))
+ ++tempstring;
+ if (STREQN (tempstring, "__gnu_compiled", 14))
+ return;
+ }
+
+ case N_NBTEXT:
+ case N_FN:
+ case N_FN_SEQ:
+ ms_type = mst_file_text;
+ break;
+
+ case N_DATA:
+ ms_type = mst_file_data;
+
+ /* Check for __DYNAMIC, which is used by Sun shared libraries.
+ Record it as global even if it's local, not global, so
+ lookup_minimal_symbol can find it. We don't check symbol_leading_char
+ because for SunOS4 it always is '_'. */
+ if (name[8] == 'C' && STREQ ("__DYNAMIC", name))
+ ms_type = mst_data;
+
+ /* Same with virtual function tables, both global and static. */
+ {
+ char *tempstring = name;
+ if (tempstring[0] == bfd_get_symbol_leading_char (objfile->obfd))
+ ++tempstring;
+ if (VTBL_PREFIX_P ((tempstring)))
+ ms_type = mst_data;
+ }
+ break;
+
+ case N_BSS:
+ ms_type = mst_file_bss;
+ break;
+
default: ms_type = mst_unknown; break;
}
- prim_record_minimal_symbol (obsavestring (name, strlen (name), &objfile -> symbol_obstack),
- address, ms_type);
+ prim_record_minimal_symbol
+ (obsavestring (name, strlen (name), &objfile -> symbol_obstack),
+ address,
+ ms_type);
}
\f
/* Scan and build partial symbols for a symbol file.
{
bfd *sym_bfd;
int val;
+ struct cleanup *back_to;
sym_bfd = objfile->obfd;
val = bfd_seek (objfile->obfd, DBX_SYMTAB_OFFSET (objfile), SEEK_SET);
symbol_table_offset = DBX_SYMTAB_OFFSET (objfile);
pending_blocks = 0;
- make_cleanup (really_free_pendings, 0);
+ back_to = make_cleanup (really_free_pendings, 0);
init_minimal_symbol_collection ();
make_cleanup (discard_minimal_symbols, 0);
printf_filtered ("(no debugging symbols found)...");
wrap_here ("");
}
+
+ do_cleanups (back_to);
}
/* Initialize anything that needs initializing when a completely new
int nsl;
int past_first_source_file = 0;
CORE_ADDR last_o_file_start = 0;
- struct cleanup *old_chain;
+ struct cleanup *back_to;
bfd *abfd;
/* End of the text segment of the executable file. */
(struct partial_symtab **) alloca (dependencies_allocated *
sizeof (struct partial_symtab *));
- old_chain = make_cleanup (free_objfile, objfile);
-
/* Init bincl list */
init_bincl_list (20, objfile);
- make_cleanup (free_bincl_list, objfile);
+ back_to = make_cleanup (free_bincl_list, objfile);
last_source_file = NULL;
dependency_list, dependencies_used);
}
- free_bincl_list (objfile);
- discard_cleanups (old_chain);
+ do_cleanups (back_to);
}
/* Allocate and partially fill a partial symtab. It will be
return result;
}
-/* Close off the current usage of a partial_symbol table entry. This
- involves setting the correct number of includes (with a realloc),
- setting the high text mark, setting the symbol length in the
- executable, and setting the length of the global and static lists
- of psymbols.
-
- The global symbols and static symbols are then seperately sorted.
+/* Close off the current usage of PST.
+ Returns PST or NULL if the partial symtab was empty and thrown away.
- Then the partial symtab is put on the global list.
- *** List variables and peculiarities of same. ***
- */
+ FIXME: List variables and peculiarities of same. */
-void
+struct partial_symtab *
end_psymtab (pst, include_list, num_includes, capping_symbol_offset,
capping_text, dependency_list, number_dependencies)
struct partial_symtab *pst;
pst->next = pst->objfile->free_psymtabs;
pst->objfile->free_psymtabs = pst;
+
+ /* Indicate that psymtab was thrown away. */
+ pst = (struct partial_symtab *)NULL;
}
+ return pst;
}
\f
static void
unsigned char type;
unsigned max_symnum;
register bfd *abfd;
- struct symtab *rtn;
struct objfile *objfile;
int sym_offset; /* Offset to start of symbols to read */
int sym_size; /* Size of symbols to read */
other than Solaris 2, this just holds the SECT_OFF_TEXT value, and is
used to relocate these symbol types rather than SECTION_OFFSETS. */
static CORE_ADDR function_start_offset;
- char *colon_pos;
/* If this is nonzero, N_LBRAC, N_RBRAC, and N_SLINE entries are relative
to the function start address. */
int block_address_function_relative;
/* If this is nonzero, we've seen a non-gcc N_OPT symbol for this source
- file. */
+ file. Used to detect the SunPRO solaris compiler. */
int n_opt_found;
+ /* The stab type used for the definition of the last function.
+ N_STSYM or N_GSYM for SunOS4 acc; N_FUN for other compilers. */
+ static int function_stab_type = 0;
+
/* This is true for Solaris (and all other stabs-in-elf systems, hopefully,
since it would be silly to do things differently from Solaris), and
false for SunOS4 and other a.out file formats. */
{
case N_FUN:
case N_FNAME:
-#if 0
-/* It seems that the Sun ANSI C compiler (acc) replaces N_FUN with N_GSYM and
- N_STSYM with a type code of f or F. Can't enable this until we get some
- stuff straightened out with psymtabs. FIXME. */
-
- case N_GSYM:
- case N_STSYM:
-#endif /* 0 */
-
/* Relocate for dynamic loading */
valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
-
- /* Either of these types of symbols indicates the start of
- a new function. We must process its "name" normally for dbx,
- but also record the start of a new lexical context, and possibly
- also the end of the lexical context for the previous function. */
- /* This is not always true. This type of symbol may indicate a
- text segment variable. */
-
- colon_pos = strchr (name, ':');
- if (!colon_pos++
- || (*colon_pos != 'f' && *colon_pos != 'F'))
- {
- define_symbol (valu, name, desc, type, objfile);
- break;
- }
-
-#ifdef SUN_FIXED_LBRAC_BUG
- last_pc_address = valu; /* Save for SunOS bug circumcision */
-#endif
-
- if (block_address_function_relative)
- /* On Solaris 2.0 compilers, the block addresses and N_SLINE's
- are relative to the start of the function. On normal systems,
- and when using gcc on Solaris 2.0, these addresses are just
- absolute, or relative to the N_SO, depending on
- BLOCK_ADDRESS_ABSOLUTE. */
- function_start_offset = valu;
-
- within_function = 1;
- if (context_stack_depth > 0)
- {
- new = pop_context ();
- /* Make a block for the local symbols within. */
- finish_block (new->name, &local_symbols, new->old_blocks,
- new->start_addr, valu, objfile);
- }
- /* Stack must be empty now. */
- if (context_stack_depth != 0)
- complain (&lbrac_unmatched_complaint, symnum);
-
- new = push_context (0, valu);
- new->name = define_symbol (valu, name, desc, type, objfile);
- break;
+ goto define_a_symbol;
case N_LBRAC:
/* This "symbol" just indicates the start of an inner lexical
.stab "foo:V...",N_STSYM is relative (section base subtracted).
This leaves us no choice but to search for the 'S' or 'V'...
(or pass the whole section_offsets stuff down ONE MORE function
- call level, which we really don't want to do). */
+ call level, which we really don't want to do).
+
+ The above is indeed true for Solaris 2.1. I'm not sure what
+ happens in Solaris 2.3, in which ld stops relocating stabs. */
{
char *p;
p = strchr (name, ':');
{
/* FIXME! We relocate it by the TEXT offset, in case the
whole module moved in memory. But this is wrong, since
- the sections can side around independently. */
+ the sections can side around independently. (I suspect that
+ the text offset is always zero anyway--elfread.c doesn't
+ process (and Sun cc doesn't produce) Ttext.text symbols). */
valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
goto define_a_symbol;
}
valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
goto define_a_symbol;
+ /* The following symbol types we don't know how to process. Handle
+ them in a "default" way, but complain to people who care. */
+ default:
+ case N_CATCH: /* Exception handler catcher */
+ case N_EHDECL: /* Exception handler name */
+ case N_PC: /* Global symbol in Pascal */
+ case N_M2C: /* Modula-2 compilation unit */
+ /* N_MOD2: overlaps with N_EHDECL */
+ case N_SCOPE: /* Modula-2 scope information */
+ case N_ECOML: /* End common (local name) */
+ case N_NBTEXT: /* Gould Non-Base-Register symbols??? */
+ case N_NBDATA:
+ case N_NBBSS:
+ case N_NBSTS:
+ case N_NBLCS:
+ complain (&unknown_symtype_complaint, local_hex_string(type));
+ /* FALLTHROUGH */
+
/* The following symbol types don't need the address field relocated,
since it is either unused, or is absolute. */
define_a_symbol:
case N_PSYM: /* Parameter variable */
case N_LENG: /* Length of preceding symbol type */
if (name)
- define_symbol (valu, name, desc, type, objfile);
+ {
+ int deftype;
+ char *colon_pos = strchr (name, ':');
+ if (colon_pos == NULL)
+ deftype = '\0';
+ else
+ deftype = colon_pos[1];
+
+ switch (deftype)
+ {
+ case 'f':
+ case 'F':
+ function_stab_type = type;
+
+#ifdef SUN_FIXED_LBRAC_BUG
+ /* The Sun acc compiler, under SunOS4, puts out
+ functions with N_GSYM or N_STSYM. The problem is
+ that the address of the symbol is no good (for N_GSYM
+ it doesn't even attept an address; for N_STSYM it
+ puts out an address but then it gets relocated
+ relative to the data segment, not the text segment).
+ Currently we can't fix this up later as we do for
+ some types of symbol in scan_file_globals.
+ Fortunately we do have a way of finding the address -
+ we know that the value in last_pc_address is either
+ the one we want (if we're dealing with the first
+ function in an object file), or somewhere in the
+ previous function. This means that we can use the
+ minimal symbol table to get the address. */
+
+ /* On solaris up to 2.2, the N_FUN stab gets relocated.
+ On Solaris 2.3, ld no longer relocates stabs (which
+ is good), and the N_FUN's value is now always zero.
+ We only provide this correction for functions, not for
+ all N_FUN symbols, because that is easiest and all
+ readonly variables seem to go in the .rodata on Solaris. */
+
+ if (type == N_GSYM || type == N_STSYM
+ || (type == N_FUN && valu == 0))
+ {
+ struct minimal_symbol *m;
+ int l = colon_pos - name;
+
+ m = lookup_minimal_symbol_by_pc (last_pc_address);
+ if (m && STREQN (SYMBOL_NAME (m), name, l))
+ /* last_pc_address was in this function */
+ valu = SYMBOL_VALUE (m);
+ else if (m && STREQN (SYMBOL_NAME (m+1), name, l))
+ /* last_pc_address was in last function */
+ valu = SYMBOL_VALUE (m+1);
+ else
+ /* Not found - use last_pc_address (for finish_block) */
+ valu = last_pc_address;
+ }
+
+ last_pc_address = valu; /* Save for SunOS bug circumcision */
+#endif
+
+ if (block_address_function_relative)
+ /* For Solaris 2.0 compilers, the block addresses and
+ N_SLINE's are relative to the start of the
+ function. On normal systems, and when using gcc on
+ Solaris 2.0, these addresses are just absolute, or
+ relative to the N_SO, depending on
+ BLOCK_ADDRESS_ABSOLUTE. */
+ function_start_offset = valu;
+
+ within_function = 1;
+ if (context_stack_depth > 0)
+ {
+ new = pop_context ();
+ /* Make a block for the local symbols within. */
+ finish_block (new->name, &local_symbols, new->old_blocks,
+ new->start_addr, valu, objfile);
+ }
+ /* Stack must be empty now. */
+ if (context_stack_depth != 0)
+ complain (&lbrac_unmatched_complaint, symnum);
+
+ new = push_context (0, valu);
+ new->name = define_symbol (valu, name, desc, type, objfile);
+ break;
+
+ default:
+ define_symbol (valu, name, desc, type, objfile);
+ break;
+ }
+ }
break;
/* We use N_OPT to carry the gcc2_compiled flag. Sun uses it
case N_ENDM: /* Solaris 2: End of module */
case N_MAIN: /* Name of main routine. */
break;
-
- /* The following symbol types we don't know how to process. Handle
- them in a "default" way, but complain to people who care. */
- default:
- case N_CATCH: /* Exception handler catcher */
- case N_EHDECL: /* Exception handler name */
- case N_PC: /* Global symbol in Pascal */
- case N_M2C: /* Modula-2 compilation unit */
- /* N_MOD2: overlaps with N_EHDECL */
- case N_SCOPE: /* Modula-2 scope information */
- case N_ECOML: /* End common (local name) */
- case N_NBTEXT: /* Gould Non-Base-Register symbols??? */
- case N_NBDATA:
- case N_NBBSS:
- case N_NBSTS:
- case N_NBLCS:
- complain (&unknown_symtype_complaint, local_hex_string(type));
- if (name)
- define_symbol (valu, name, desc, type, objfile);
}
previous_stab_code = type;
}
\f
/* Copy a pending list, used to record the contents of a common
- block for later fixup. */
+ block for later fixup. We copy the symbols starting with all
+ symbols in BEG, and ending with the symbols which are in
+ END at index ENDI. */
static struct pending *
-copy_pending (beg, begi, end)
+copy_pending (beg, endi, end)
struct pending *beg;
- int begi;
+ int endi;
struct pending *end;
{
struct pending *new = 0;
struct pending *next;
+ int j;
- for (next = beg; next != 0 && (next != end || begi < end->nsyms);
- next = next->next, begi = 0)
+ /* Copy all the struct pendings before end. */
+ for (next = beg; next != NULL && next != end; next = next->next)
{
- register int j;
- for (j = begi; j < next->nsyms; j++)
+ for (j = 0; j < next->nsyms; j++)
add_symbol_to_list (next->symbol[j], &new);
}
+
+ /* Copy however much of END we need. */
+ for (j = endi; j < end->nsyms; j++)
+ add_symbol_to_list (end->symbol[j], &new);
+
return new;
}
\f
DBX_STRINGTAB_SIZE (objfile) = stabstrsize;
DBX_SYMTAB_OFFSET (objfile) = staboffset;
- if (stabstrsize < 0 /* FIXME: stabstrsize is unsigned; never true! */
- || stabstrsize > bfd_get_size (sym_bfd))
+ if (stabstrsize > bfd_get_size (sym_bfd))
error ("ridiculous string table size: %d bytes", stabstrsize);
DBX_STRINGTAB (objfile) = (char *)
obstack_alloc (&objfile->psymbol_obstack, stabstrsize+1);
}
\f
/* Register our willingness to decode symbols for SunOS and a.out and
- b.out files handled by BFD... */
+ NetBSD and b.out files handled by BFD... */
static struct sym_fns sunos_sym_fns =
{
"sunOs", /* sym_name: name or name prefix of BFD target type */