(gdbint.info)Symbol Reading


Next: Cleanups Prev: BFD support for GDB Up: Top

Symbol Reading
**************

   GDB reads symbols from "symbol files".  The usual symbol file is the
file containing the program which gdb is debugging.  GDB can be directed
to use a different file for symbols (with the "symbol-file" command),
and it can also read more symbols via the "add-file" and "load"
commands, or while reading symbols from shared libraries.

   Symbol files are initially opened by `symfile.c' using the BFD
library.  BFD identifies the type of the file by examining its header.
`symfile_init' then uses this identification to locate a set of
symbol-reading functions.

   Symbol reading modules identify themselves to GDB by calling
`add_symtab_fns' during their module initialization.  The argument to
`add_symtab_fns' is a `struct sym_fns' which contains the name (or name
prefix) of the symbol format, the length of the prefix, and pointers to
four functions.  These functions are called at various times to process
symbol-files whose identification matches the specified prefix.

   The functions supplied by each module are:

`XXX_symfile_init(struct sym_fns *sf)'
     Called from `symbol_file_add' when we are about to read a new
     symbol file.  This function should clean up any internal state
     (possibly resulting from half-read previous files, for example)
     and prepare to read a new symbol file. Note that the symbol file
     which we are reading might be a new "main" symbol file, or might
     be a secondary symbol file whose symbols are being added to the
     existing symbol table.

     The argument to `XXX_symfile_init' is a newly allocated `struct
     sym_fns' whose `bfd' field contains the BFD for the new symbol
     file being read.  Its `private' field has been zeroed, and can be
     modified as desired.  Typically, a struct of private information
     will be `malloc''d, and a pointer to it will be placed in the
     `private' field.

     There is no result from `XXX_symfile_init', but it can call
     `error' if it detects an unavoidable problem.

`XXX_new_init()'
     Called from `symbol_file_add' when discarding existing symbols.
     This function need only handle the symbol-reading module's
     internal state; the symbol table data structures visible to the
     rest of GDB will be discarded by `symbol_file_add'.  It has no
     arguments and no result.  It may be called after
     `XXX_symfile_init', if a new symbol table is being read, or may be
     called alone if all symbols are simply being discarded.

`XXX_symfile_read(struct sym_fns *sf, CORE_ADDR addr, int mainline)'
     Called from `symbol_file_add' to actually read the symbols from a
     symbol-file into a set of psymtabs or symtabs.

     `sf' points to the struct sym_fns originally passed to
     `XXX_sym_init' for possible initialization.  `addr' is the offset
     between the file's specified start address and its true address in
     memory.  `mainline' is 1 if this is the main symbol table being
     read, and 0 if a secondary symbol file (e.g. shared library or
     dynamically loaded file) is being read.

   In addition, if a symbol-reading module creates psymtabs when
XXX_symfile_read is called, these psymtabs will contain a pointer to a
function `XXX_psymtab_to_symtab', which can be called from any point in
the GDB symbol-handling code.

`XXX_psymtab_to_symtab (struct partial_symtab *pst)'
     Called from `psymtab_to_symtab' (or the PSYMTAB_TO_SYMTAB macro)
     if the psymtab has not already been read in and had its
     `pst->symtab' pointer set.  The argument is the psymtab to be
     fleshed-out into a symtab.  Upon return, pst->readin should have
     been set to 1, and pst->symtab should contain a pointer to the new
     corresponding symtab, or zero if there were no symbols in that
     part of the symbol file.


automatically generated by info2www