You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-\f
-/* Symbol read-in occurs in two phases:
- 1. A scan (read_dbx_symtab()) of the entire executable, whose sole
- purpose is to make a list of symbols (partial symbol table)
- which will cause symbols
- to be read in if referenced. This scan happens when the
- "symbol-file" command is given (symbol_file_command()).
- 1a. The "add-file" command. Similar to #1.
- 2. Full read-in of symbols. (dbx_psymtab_to_symtab()). This happens
- when a symbol in a file for which symbols have not yet been
- read in is referenced. */
+
+/* This module provides three functions: dbx_symfile_init,
+ which initializes to read a symbol file; dbx_new_init, which
+ discards existing cached information when all symbols are being
+ discarded; and dbx_symfile_read, which reads a symbol table
+ from a file.
+
+ dbx_symfile_read only does the minimum work necessary for letting the
+ user "name" things symbolically; it does not read the entire symtab.
+ Instead, it reads the external and static symbols and puts them in partial
+ symbol tables. When more extensive information is requested of a
+ file, the corresponding partial symbol table is mutated into a full
+ fledged symbol table by going back and reading the symbols
+ for real. dbx_psymtab_to_symtab() is the function that does this */
#include <stdio.h>
#include <string.h>
static void add_undefined_type ();
static void cleanup_undefined_types ();
static void scan_file_globals ();
-static void read_ofile_symtab ();
+static struct symtab *read_ofile_symtab ();
static void dbx_psymtab_to_symtab ();
/* C++ */
static struct type **read_args ();
-static const char vptr_name[] = { '_','v','p','t','r',CPLUS_MARKER };
-static const char vb_name[] = { '_','v','b',CPLUS_MARKER };
+static const char vptr_name[] = { '_','v','p','t','r',CPLUS_MARKER,'\0' };
+static const char vb_name[] = { '_','v','b',CPLUS_MARKER,'\0' };
/* Macro to determine which symbols to ignore when reading the first symbol
of a file. Some machines override this definition. */
int within_function;
+#if 0
+/* The type of the function we are currently reading in. This is
+ used by define_symbol to record the type of arguments to a function. */
+
+static struct type *in_function_type;
+#endif
+
/* List of blocks already made (lexical contexts already closed).
This is used at the end to make the blockvector. */
{"bad string table offset in symbol %d", 0, 0};
struct complaint unknown_symtype_complaint =
- {"unknown symbol type 0x%x", 0, 0};
+ {"unknown symbol type %s", 0, 0};
struct complaint lbrac_rbrac_complaint =
{"block start larger than block end", 0, 0};
END_ADDR is the address of the end of the file's text. */
-static void
+static struct symtab *
end_symtab (end_addr)
CORE_ADDR end_addr;
{
current_subfile->line_vector_index = line_vector_index;
/* Now create the symtab objects proper, one for each subfile. */
- /* (The main file is one of them.) */
+ /* (The main file is the last one on the chain.) */
for (subfile = subfiles; subfile; subfile = nextsub)
{
- symtab = (struct symtab *) xmalloc (sizeof (struct symtab));
+ symtab = allocate_symtab (subfile->name);
/* Fill in its components. */
symtab->blockvector = blockvector;
type_vector->length = type_vector_length;
symtab->typevector = type_vector;
- symtab->filename = subfile->name;
symtab->dirname = subfile->dirname;
symtab->free_code = free_linetable;
if (subfile->next == 0)
symtab->free_ptr = (char *) type_vector;
- symtab->nlines = 0;
- symtab->line_charpos = 0;
-
- symtab->language = language_unknown;
- symtab->fullname = NULL;
-
/* There should never already be a symtab for this name, since
any prev dups have been removed when the psymtab was read in.
FIXME, there ought to be a way to check this here. */
line_vector = 0;
line_vector_length = -1;
last_source_file = 0;
+
+ return symtab;
}
\f
/* Handle the N_BINCL and N_EINCL symbol types
CORE_ADDR address;
int type;
{
- enum misc_function_type misc_type =
- (type == (N_TEXT | N_EXT) ? mf_text :
- (type == (N_DATA | N_EXT)
- || type == (N_DATA)
- || type == (N_SETV | N_EXT)
- ) ? mf_data :
- type == (N_BSS | N_EXT) ? mf_bss :
- type == (N_ABS | N_EXT) ? mf_abs : mf_unknown);
+ enum misc_function_type misc_type;
+
+ switch (type &~ N_EXT) {
+ case N_TEXT: misc_type = mf_text; break;
+ case N_DATA: misc_type = mf_data; break;
+ case N_BSS: misc_type = mf_bss; break;
+ case N_ABS: misc_type = mf_abs; break;
+#ifdef N_SETV
+ case N_SETV: misc_type = mf_data; break;
+#endif
+ default: misc_type = mf_unknown; break;
+ }
prim_record_misc_function (obsavestring (name, strlen (name)),
address, misc_type);
free (info);
sf->sym_private = 0; /* Zap pointer to our (now gone) info struct */
- if (!partial_symtab_list)
- printf_filtered ("\n(no debugging symbols found)...");
+ if (!partial_symtab_list) {
+ wrap_here ("");
+ printf_filtered ("(no debugging symbols found)...");
+ wrap_here ("");
+ }
}
-/* Discard any information we have cached during the reading of a
- single symbol file. This should not toss global information
- from previous symbol files that have been read. E.g. we might
- be discarding info from reading a shared library, and should not
- throw away the info from the main file. */
+/* Initialize anything that needs initializing when a completely new
+ symbol file is specified (not just adding some symbols from another
+ file, e.g. a shared library). */
void
-dbx_symfile_discard ()
+dbx_new_init ()
{
-
/* Empty the hash table of global syms looking for values. */
bzero (global_sym_chain, sizeof global_sym_chain);
free_pendings = 0;
file_symbols = 0;
global_symbols = 0;
-}
-/* Initialize anything that needs initializing when a completely new
- symbol file is specified (not just adding some symbols from another
- file, e.g. a shared library). */
-
-void
-dbx_new_init ()
-{
- dbx_symfile_discard ();
/* Don't put these on the cleanup chain; they need to stick around
- until the next call to symbol_file_command. *Then* we'll free
- them. */
+ until the next call to dbx_new_init. *Then* we'll free them. */
if (symfile_string_table)
{
free (symfile_string_table);
namestring, valu,
first_symnum * sizeof (struct nlist),
global_psymbols.next, static_psymbols.next);
-
continue;
}
case N_LBRAC:
case N_RBRAC:
case N_NSYMS: /* Ultrix 4.0: symbol count */
+ case N_DEFD: /* GNU Modula-2 */
/* These symbols aren't interesting; don't worry about them */
continue;
default:
/* If we haven't found it yet, ignore it. It's probably some
new type we don't know about yet. */
- complain (&unknown_symtype_complaint, bufp->n_type);
+ complain (&unknown_symtype_complaint, local_hex_string(bufp->n_type));
continue;
}
}
*st1 = SYMBOL_NAME (s1),
*st2 = SYMBOL_NAME (s2);
- return (st1[0] - st2[0] ? st1[0] - st2[0] :
- strcmp (st1 + 1, st2 + 1));
+ if (st1[0] - st2[0])
+ return st1[0] - st2[0];
+ if (st1[1] - st2[1])
+ return st1[1] - st2[1];
+ return strcmp (st1 + 1, st2 + 1);
}
/* Read in this files symbols */
lseek (desc, sym_offset, L_SET);
- read_ofile_symtab (desc, stringtab, stringtab_size,
- pst->ldsymoff,
- pst->ldsymlen, pst->textlow,
- pst->texthigh - pst->textlow, pst->addr);
- sort_symtab_syms (symtab_list); /* At beginning since just added */
+ pst->symtab =
+ read_ofile_symtab (desc, stringtab, stringtab_size,
+ pst->ldsymoff,
+ pst->ldsymlen, pst->textlow,
+ pst->texthigh - pst->textlow, pst->addr);
+ sort_symtab_syms (pst->symtab);
do_cleanups (old_chain);
}
}
/* Process a pair of symbols. Currently they must both be N_SO's. */
+/* ARGSUSED */
static void
process_symbol_pair (type1, desc1, value1, name1,
type2, desc2, value2, name2)
/* No need to check PCC_SOL_BROKEN, on the assumption that such
broken PCC's don't put out N_SO pairs. */
if (last_source_file)
- end_symtab (value2);
+ (void)end_symtab (value2);
start_symtab (name2, name1, value2);
}
* OFFSET is a relocation offset which gets added to each symbol
*/
-static void
+static struct symtab *
read_ofile_symtab (desc, stringtab, stringtab_size, sym_offset,
sym_size, text_offset, text_size, offset)
int desc;
processing_gcc_compilation = 1;
else if (type & N_EXT || type == (unsigned char)N_TEXT
|| type == (unsigned char)N_NBTEXT
- )
+ ) {
/* Global symbol: see if we came across a dbx defintion for
a corresponding symbol. If so, store the value. Remove
syms from the chain when their values are stored, but
be satisfied in each file as it appears. So we skip this
section. */
;
+ }
}
- end_symtab (text_offset + text_size);
+
+ return end_symtab (text_offset + text_size);
}
\f
static int
}
#endif
if (last_source_file)
- end_symtab (valu);
+ (void)end_symtab (valu);
start_symtab (name, NULL, valu);
break;
case N_ECOML:
case N_LENG:
+ case N_DEFD: /* GNU Modula-2 symbol */
break;
default:
get this name). */
static char *type_synonym_name;
+/* ARGSUSED */
static struct symbol *
define_symbol (valu, string, desc, type)
unsigned int valu;
if ((deftype == 'F' || deftype == 'f')
&& TYPE_CODE (type_read) != TYPE_CODE_FUNC)
+ {
+#if 0
+/* This code doesn't work -- it needs to realloc and can't. */
+ struct type *new = (struct type *)
+ obstack_alloc (symbol_obstack, sizeof (struct type));
+
+ /* Generate a template for the type of this function. The
+ types of the arguments will be added as we read the symbol
+ table. */
+ *new = *lookup_function_type (type_read);
+ SYMBOL_TYPE(sym) = new;
+ in_function_type = new;
+#else
SYMBOL_TYPE (sym) = lookup_function_type (type_read);
+#endif
+ }
else
SYMBOL_TYPE (sym) = type_read;
}
SYMBOL_CLASS (sym) = DBX_PARM_SYMBOL_CLASS (type);
SYMBOL_VALUE (sym) = valu;
SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
+#if 0
+ /* This doesn't work yet. */
+ add_param_to_type (&in_function_type, sym);
+#endif
add_symbol_to_list (sym, &local_symbols);
/* If it's gcc-compiled, if it says `short', believe it. */
|| TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
&& TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
{
- int i;
- for (i = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; i >= 0; i--)
- if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), i) == 0)
- TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), i) =
- type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), i));
+ int j;
+ for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--)
+ if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0)
+ TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) =
+ type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j));
}
add_symbol_to_list (sym, &file_symbols);
/* This field is unpacked. */
list->field.bitsize = 0;
}
+ /* GNU C++ anonymous type. */
+ else if (*p == '_')
+ break;
else
error ("invalid abbreviation at symtab pos %d.", symnum);
j = o_nsyms;
for (; j < syms->nsyms; j++,n++)
{
- struct symbol *sym = syms->symbol[j];
- SYMBOL_TYPE (sym) = type;
- TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (sym);
+ struct symbol *xsym = syms->symbol[j];
+ SYMBOL_TYPE (xsym) = type;
+ TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
TYPE_FIELD_VALUE (type, n) = 0;
- TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (sym);
+ TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
TYPE_FIELD_BITSIZE (type, n) = 0;
}
if (syms == osyms)
break;
}
+ /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
+ if(TYPE_NFIELDS(type) == 2 &&
+ ((!strcmp(TYPE_FIELD_NAME(type,0),"TRUE") &&
+ !strcmp(TYPE_FIELD_NAME(type,1),"FALSE")) ||
+ (!strcmp(TYPE_FIELD_NAME(type,1),"TRUE") &&
+ !strcmp(TYPE_FIELD_NAME(type,0),"FALSE"))))
+ TYPE_CODE(type) = TYPE_CODE_BOOL;
+
return type;
}
}
}
-#define MAX_OF_TYPE(t) ((1 << (sizeof (t)*8 - 1)) - 1)
-#define MIN_OF_TYPE(t) (-(1 << (sizeof (t)*8 - 1)))
+#define MAX_OF_C_TYPE(t) ((1 << (sizeof (t)*8 - 1)) - 1)
+#define MIN_OF_C_TYPE(t) (-(1 << (sizeof (t)*8 - 1)))
static struct type *
read_range_type (pp, typenums)
sizeof (struct type));
bzero (result_type, sizeof (struct type));
- TYPE_TARGET_TYPE (result_type) = (self_subrange ?
- builtin_type_int :
- *dbx_lookup_type(rangenums));
+ TYPE_CODE (result_type) = TYPE_CODE_RANGE;
+ TYPE_TARGET_TYPE (result_type) = *dbx_lookup_type(rangenums);
+
+ TYPE_NFIELDS (result_type) = 2;
+ TYPE_FIELDS (result_type) =
+ (struct field *) obstack_alloc (symbol_obstack,
+ 2 * sizeof (struct field));
+ bzero (TYPE_FIELDS (result_type), 2 * sizeof (struct field));
+ TYPE_FIELD_BITPOS (result_type, 0) = n2;
+ TYPE_FIELD_BITPOS (result_type, 1) = n3;
+
+#if 0
+/* Note that TYPE_LENGTH (result_type) is just overridden a few
+ statements down. What do we really need here? */
/* We have to figure out how many bytes it takes to hold this
range type. I'm going to assume that anything that is pushing
the bounds of a long was taken care of above. */
- if (n2 >= MIN_OF_TYPE(char) && n3 <= MAX_OF_TYPE(char))
+ if (n2 >= MIN_OF_C_TYPE(char) && n3 <= MAX_OF_C_TYPE(char))
TYPE_LENGTH (result_type) = 1;
- else if (n2 >= MIN_OF_TYPE(short) && n3 <= MAX_OF_TYPE(short))
+ else if (n2 >= MIN_OF_C_TYPE(short) && n3 <= MAX_OF_C_TYPE(short))
TYPE_LENGTH (result_type) = sizeof (short);
- else if (n2 >= MIN_OF_TYPE(int) && n3 <= MAX_OF_TYPE(int))
+ else if (n2 >= MIN_OF_C_TYPE(int) && n3 <= MAX_OF_C_TYPE(int))
TYPE_LENGTH (result_type) = sizeof (int);
- else if (n2 >= MIN_OF_TYPE(long) && n3 <= MAX_OF_TYPE(long))
+ else if (n2 >= MIN_OF_C_TYPE(long) && n3 <= MAX_OF_C_TYPE(long))
TYPE_LENGTH (result_type) = sizeof (long);
else
/* Ranged type doesn't fit within known sizes. */
+ /* FIXME -- use "long long" here. */
return error_type (pp);
+#endif
TYPE_LENGTH (result_type) = TYPE_LENGTH (TYPE_TARGET_TYPE (result_type));
- TYPE_CODE (result_type) = TYPE_CODE_RANGE;
- TYPE_NFIELDS (result_type) = 2;
- TYPE_FIELDS (result_type) =
- (struct field *) obstack_alloc (symbol_obstack,
- 2 * sizeof (struct field));
- bzero (TYPE_FIELDS (result_type), 2 * sizeof (struct field));
- TYPE_FIELD_BITPOS (result_type, 0) = n2;
- TYPE_FIELD_BITPOS (result_type, 1) = n3;
return result_type;
}
/* Register our willingness to decode symbols for SunOS and a.out and
b.out files handled by BFD... */
static struct sym_fns sunos_sym_fns = {"sunOs", 6,
- dbx_new_init, dbx_symfile_init,
- dbx_symfile_read, dbx_symfile_discard};
+ dbx_new_init, dbx_symfile_init, dbx_symfile_read};
static struct sym_fns aout_sym_fns = {"a.out", 5,
- dbx_new_init, dbx_symfile_init,
- dbx_symfile_read, dbx_symfile_discard};
+ dbx_new_init, dbx_symfile_init, dbx_symfile_read};
static struct sym_fns bout_sym_fns = {"b.out", 5,
- dbx_new_init, dbx_symfile_init,
- dbx_symfile_read, dbx_symfile_discard};
+ dbx_new_init, dbx_symfile_init, dbx_symfile_read};
void
_initialize_dbxread ()
undef_types_length = 0;
undef_types = (struct type **) xmalloc (undef_types_allocated *
sizeof (struct type *));
-
- dbx_new_init ();
}