/* Read AIX xcoff symbol tables and convert to internal format, for GDB.
- Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995
+ Copyright 1986, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 1997
Free Software Foundation, Inc.
Derived from coffread.c, dbxread.c, and a lot of hacking.
Contributed by IBM Corporation.
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. */
-
-/* Native only: Need struct tbtable in <sys/debug.h> from host, and
- need xcoff_add_toc_to_loadinfo in rs6000-tdep.c from target.
- need xcoff_init_loadinfo ditto.
- However, if you grab <sys/debug.h> and make it available on your
- host, and define FAKING_RS6000, then this code will compile. */
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "defs.h"
#include "bfd.h"
#include <sys/types.h>
#include <fcntl.h>
#include <ctype.h>
-#include <string.h>
+#include "gdb_string.h"
-#include "obstack.h"
#include <sys/param.h>
#ifndef NO_SYS_FILE
#include <sys/file.h>
#endif
-#include <sys/stat.h>
-#include <sys/debug.h>
+#include "gdb_stat.h"
#include "coff/internal.h"
#include "libcoff.h" /* FIXME, internal data from BFD */
#include "objfiles.h"
#include "buildsym.h"
#include "stabsread.h"
+#include "expression.h"
+#include "language.h" /* Needed inside partial-stab.h */
#include "complaints.h"
#include "gdb-stabs.h"
/* This is output from LD. */
#define N_SETV 0x1C /* Pointer to set vector in data area. */
\f
-/* Each partial symbol table entry contains a pointer to private data for the
- sym_read function to use when expanding a partial symbol table entry
- to a full symbol table entry. */
+/* We put a pointer to this structure in the read_symtab_private field
+ of the psymtab. */
struct symloc {
unsigned int c_type;
};
-/* The COFF line table, in raw form. */
-static char *linetab = NULL; /* Its actual contents */
-static long linetab_offset; /* Its offset in the file */
-static unsigned long linetab_size; /* Its size */
-
/* last function's saved coff symbol `cs' */
static struct coff_symbol fcn_cs_saved;
/* Number of symbols in symtbl. */
int symtbl_num_syms;
-};
-static struct complaint rsym_complaint =
- {"Non-stab C_RSYM `%s' needs special handling", 0, 0};
+ /* Offset in data section to TOC anchor. */
+ CORE_ADDR toc_offset;
+};
static struct complaint storclass_complaint =
{"Unexpected storage class: %d", 0, 0};
static struct complaint bf_notfound_complaint =
{"line numbers off, `.bf' symbol not found", 0, 0};
-extern struct complaint ef_complaint;
-extern struct complaint eb_complaint;
+static struct complaint ef_complaint =
+ {"Mismatched .ef symbol ignored starting at symnum %d", 0, 0};
+
+static struct complaint eb_complaint =
+ {"Mismatched .eb symbol ignored starting at symnum %d", 0, 0};
+
+static void
+xcoff_initial_scan PARAMS ((struct objfile *, struct section_offsets *, int));
+
+static void
+scan_xcoff_symtab PARAMS ((struct section_offsets *, struct objfile *));
+
+static char *
+xcoff_next_symbol_text PARAMS ((struct objfile *));
+
+static void
+record_include_begin PARAMS ((struct coff_symbol *));
static void
enter_line_range PARAMS ((struct subfile *, unsigned, unsigned,
static void
read_xcoff_symtab PARAMS ((struct partial_symtab *));
+#if 0
static void
add_stab_to_list PARAMS ((char *, struct pending_stabs **));
+#endif
+
+static int
+compare_lte PARAMS ((const void *, const void *));
+
+static struct linetable *
+arrange_linetable PARAMS ((struct linetable *));
+
+static void
+record_include_end PARAMS ((struct coff_symbol *));
+
+static void
+process_linenos PARAMS ((CORE_ADDR, CORE_ADDR));
\f
/* Translate from a COFF section number (target_index) to a SECT_OFF_*
code. */
static int secnum_to_section PARAMS ((int, struct objfile *));
+static asection * secnum_to_bfd_section PARAMS ((int, struct objfile *));
struct find_targ_sec_arg {
int targ_index;
int *resultp;
+ asection **bfd_sect;
};
static void find_targ_sec PARAMS ((bfd *, asection *, void *));
*args->resultp = SECT_OFF_DATA;
else
*args->resultp = SECT_OFF_BSS;
+ *args->bfd_sect = sect;
}
}
struct objfile *objfile;
{
int off = SECT_OFF_TEXT;
+ asection *sect = NULL;
struct find_targ_sec_arg args;
args.targ_index = secnum;
args.resultp = &off;
+ args.bfd_sect = §
bfd_map_over_sections (objfile->obfd, find_targ_sec, &args);
return off;
}
+
+/* Return the BFD section that CS points to. */
+static asection *
+secnum_to_bfd_section (secnum, objfile)
+ int secnum;
+ struct objfile *objfile;
+{
+ int off = SECT_OFF_TEXT;
+ asection *sect = NULL;
+ struct find_targ_sec_arg args;
+ args.targ_index = secnum;
+ args.resultp = &off;
+ args.bfd_sect = §
+ bfd_map_over_sections (objfile->obfd, find_targ_sec, &args);
+ return sect;
+}
\f
/* add a given stab string into given stab vector. */
+#if 0
+
static void
add_stab_to_list (stabname, stabvector)
char *stabname;
}
(*stabvector)->stab [(*stabvector)->count++] = stabname;
}
+
+#endif
+
\f
/* Linenos are processed on a file-by-file basis.
/* compare line table entry addresses. */
static int
-compare_lte (lte1, lte2)
- struct linetable_entry *lte1, *lte2;
+compare_lte (lte1p, lte2p)
+ const void *lte1p;
+ const void *lte2p;
{
+ struct linetable_entry *lte1 = (struct linetable_entry *) lte1p;
+ struct linetable_entry *lte2 = (struct linetable_entry *) lte2p;
return lte1->pc - lte2->pc;
}
-/* Give a line table with function entries are marked, arrange its functions
- in assending order and strip off function entry markers and return it in
+/* Given a line table with function entries are marked, arrange its functions
+ in ascending order and strip off function entry markers and return it in
a newly created table. If the old one is good enough, return the old one. */
/* FIXME: I think all this stuff can be replaced by just passing
sort_linevec = 1 to end_symtab. */
process_linenos (start, end)
CORE_ADDR start, end;
{
- char *pp;
int offset, ii;
file_ptr max_offset =
((struct coff_symfile_info *)this_symtab_psymtab->objfile->sym_private)
All the following line numbers in the function are relative to
this, and we record absolute line numbers in record_line(). */
- int main_source_baseline = 0;
+ unsigned int main_source_baseline = 0;
unsigned *firstLine;
- CORE_ADDR addr;
offset =
((struct symloc *)this_symtab_psymtab->read_symtab_private)->lineno_off;
enter_line_range (tmpSubfile, inclTable[ii].begin,
inclTable[ii].end, start, 0, firstLine);
- offset = inclTable[ii].end + LINESZ;
+ if (offset <= inclTable[ii].end)
+ offset = inclTable[ii].end + LINESZ;
}
/* All the include files' line have been processed at this point. Now,
}
}
-typedef struct {
- int fsize; /* file size */
- int fixedparms; /* number of fixed parms */
- int floatparms; /* number of float parms */
- unsigned int parminfo; /* parameter info.
- See /usr/include/sys/debug.h
- tbtable_ext.parminfo */
- int framesize; /* function frame size */
-} TracebackInfo;
-
-static TracebackInfo *retrieve_tracebackinfo
- PARAMS ((bfd *, struct coff_symbol *));
-
-/* Given a function symbol, return its traceback information. */
-
-static TracebackInfo *
-retrieve_tracebackinfo (abfd, cs)
- bfd *abfd;
- struct coff_symbol *cs;
-{
-#define TBTABLE_BUFSIZ 2000
-
- static TracebackInfo tbInfo;
- struct tbtable *ptb;
-
- static char buffer [TBTABLE_BUFSIZ];
-
- int *pinsn;
- int bytesread=0; /* total # of bytes read so far */
- int bufferbytes; /* number of bytes in the buffer */
- int functionstart;
-
- asection *textsec;
-
- /* FIXME: Should be looking through all sections, based on the
- address we are considering. Just using ".text" loses if more
- than one section has code in it. */
- textsec = bfd_get_section_by_name (abfd, ".text");
- if (!textsec)
- {
-#if 0
- /* If there is only data, no text, that is OK. */
- printf_unfiltered ("Unable to locate text section!\n");
-#endif
- return;
- }
-
- functionstart = cs->c_value - textsec->vma;
-
- memset (&tbInfo, '\0', sizeof (tbInfo));
-
- /* keep reading blocks of data from the text section, until finding a zero
- word and a traceback table. */
-
- /* Note: The logical thing way to write this code would be to assign
- to bufferbytes within the while condition. But that triggers a
- compiler (xlc in AIX 3.2) bug, so simplify it... */
- bufferbytes =
- (TBTABLE_BUFSIZ < (textsec->_raw_size - functionstart - bytesread) ?
- TBTABLE_BUFSIZ : (textsec->_raw_size - functionstart - bytesread));
- while (bufferbytes
- && (bfd_get_section_contents
- (abfd, textsec, buffer,
- (file_ptr)(functionstart + bytesread), bufferbytes)))
- {
- bytesread += bufferbytes;
- pinsn = (int*) buffer;
-
- /* If this is the first time we filled the buffer, retrieve function
- framesize info. */
-
- if (bytesread == bufferbytes) {
-
- /* skip over unrelated instructions */
-
- if (*pinsn == 0x7c0802a6) /* mflr r0 */
- ++pinsn;
- if ((*pinsn & 0xfc00003e) == 0x7c000026) /* mfcr Rx */
- ++pinsn;
- if ((*pinsn & 0xfc000000) == 0x48000000) /* bl foo, save fprs */
- ++pinsn;
- if ((*pinsn & 0xfc1f0000) == 0xbc010000) /* stm Rx, NUM(r1) */
- ++pinsn;
-
- do {
- int tmp = (*pinsn >> 16) & 0xffff;
-
- if (tmp == 0x9421) { /* stu r1, NUM(r1) */
- tbInfo.framesize = 0x10000 - (*pinsn & 0xffff);
- break;
- }
- else if ((*pinsn == 0x93e1fffc) || /* st r31,-4(r1) */
- (tmp == 0x9001)) /* st r0, NUM(r1) */
- ;
- /* else, could not find a frame size. */
- else
- return NULL;
-
- } while (++pinsn && *pinsn);
-
- if (!tbInfo.framesize)
- return NULL;
-
- }
-
- /* look for a zero word. */
-
- while (*pinsn && (pinsn < (int*)(buffer + bufferbytes - sizeof(int))))
- ++pinsn;
-
- if (pinsn >= (int*)(buffer + bufferbytes))
- continue;
-
- if (*pinsn == 0) {
-
- /* function size is the amount of bytes we have skipped so far. */
- tbInfo.fsize = bytesread - (buffer + bufferbytes - (char*)pinsn);
-
- ++pinsn;
-
- /* if we don't have the whole traceback table in the buffer, re-read
- the whole thing. */
-
- /* This is how much to read to get the traceback table.
- 8 bytes of the traceback table are always present, plus we
- look at parminfo. */
-#define MIN_TBTABSIZ 12
-
- if ((char*)pinsn > (buffer + bufferbytes - MIN_TBTABSIZ)) {
-
- /* In case if we are *very* close to the end of the text section
- and cannot read properly from that point on, abort by returning
- NULL.
-
- This could happen if the traceback table is only 8 bytes,
- but we try to read 12 bytes of it.
- Handle this case more graciously -- FIXME */
-
- if (!bfd_get_section_contents (
- abfd, textsec, buffer,
- (file_ptr)(functionstart +
- bytesread - (buffer + bufferbytes - (char*)pinsn)),MIN_TBTABSIZ))
- { printf_unfiltered ("Abnormal return!..\n"); return NULL; }
-
- ptb = (struct tbtable *)buffer;
- }
- else
- ptb = (struct tbtable *)pinsn;
-
- tbInfo.fixedparms = ptb->tb.fixedparms;
- tbInfo.floatparms = ptb->tb.floatparms;
- tbInfo.parminfo = ptb->tb_ext.parminfo;
- return &tbInfo;
- }
- bufferbytes =
- (TBTABLE_BUFSIZ < (textsec->_raw_size - functionstart - bytesread) ?
- TBTABLE_BUFSIZ : (textsec->_raw_size - functionstart - bytesread));
- }
- return NULL;
-}
/* Save the vital information for use when closing off the current file.
NAME is the file name the symbols came from, START_ADDR is the first
namestr = (NAME); \
if (namestr[0] == '.') ++namestr; \
prim_record_minimal_symbol_and_info (namestr, (ADDR), (TYPE), \
- (char *)NULL, (SECTION), (OBJFILE)); \
+ (char *)NULL, (SECTION), (asection *)NULL, (OBJFILE)); \
misc_func_recorded = 1; \
}
-/* A parameter template, used by ADD_PARM_TO_PENDING. It is initialized
- in our initializer function at the bottom of the file, to avoid
- dependencies on the exact "struct symbol" format. */
-
-static struct symbol parmsym;
-
-/* Add a parameter to a given pending symbol list. */
-
-#define ADD_PARM_TO_PENDING(PARM, VALUE, PTYPE, PENDING_SYMBOLS) \
-{ \
- PARM = (struct symbol *) \
- obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
- *(PARM) = parmsym; \
- SYMBOL_TYPE (PARM) = PTYPE; \
- SYMBOL_VALUE (PARM) = VALUE; \
- add_symbol_to_list (PARM, &PENDING_SYMBOLS); \
-}
-
-
/* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
nested. At any given time, a symbol can only be in one static block.
This is the base address of current static block, zero if non exists. */
/* This is the function which stabsread.c calls to get symbol
continuations. */
+
static char *
-xcoff_next_symbol_text ()
+xcoff_next_symbol_text (objfile)
+ struct objfile *objfile;
{
struct internal_syment symbol;
static struct complaint msg =
{"Unexpected symbol continuation", 0, 0};
char *retval;
- struct objfile *objfile = this_symtab_psymtab->objfile;
+ /* FIXME: is this the same as the passed arg? */
+ objfile = this_symtab_psymtab->objfile;
bfd_coff_swap_sym_in (objfile->obfd, raw_symbol, &symbol);
if (symbol.n_zeroes)
struct objfile *objfile = pst->objfile;
bfd *abfd = objfile->obfd;
char *raw_auxptr; /* Pointer to first raw aux entry for sym */
- TracebackInfo *ptb; /* Pointer to traceback table */
char *strtbl = ((struct coff_symfile_info *)objfile->sym_private)->strtbl;
char *debugsec =
((struct coff_symfile_info *)objfile->sym_private)->debugsec;
unsigned int max_symnum;
int just_started = 1;
int depth = 0;
- int val;
- int fcn_start_addr;
- size_t size;
+ int fcn_start_addr = 0;
struct coff_symbol fcn_stab_saved;
/* fcn_cs_saved is global because process_xcoff_symbol needs it. */
union internal_auxent fcn_aux_saved;
- struct type *fcn_type_saved = NULL;
struct context_stack *new;
char *filestring = " _start_ "; /* Name of the current file. */
char *last_csect_name; /* last seen csect's name and value */
CORE_ADDR last_csect_val;
int last_csect_sec;
- int misc_func_recorded; /* true if any misc. function */
this_symtab_psymtab = pst;
last_source_file = NULL;
last_csect_name = 0;
last_csect_val = 0;
- misc_func_recorded = 0;
start_stabs ();
start_symtab (filestring, (char *)NULL, file_start_addr);
+ record_debugformat ("XCOFF");
symnum = ((struct symloc *)pst->read_symtab_private)->first_symnum;
max_symnum =
symnum + ((struct symloc *)pst->read_symtab_private)->numsyms;
if (last_source_file)
{
pst->symtab =
- end_symtab (cur_src_end_addr, 1, 0, objfile, SECT_OFF_TEXT);
+ end_symtab (cur_src_end_addr, objfile, SECT_OFF_TEXT);
end_stabs ();
}
start_stabs ();
start_symtab ("_globals_", (char *)NULL, (CORE_ADDR)0);
+ record_debugformat ("XCOFF");
cur_src_end_addr = first_object_file_end;
/* done with all files, everything from here on is globals */
}
{
complete_symtab (filestring, file_start_addr);
cur_src_end_addr = file_end_addr;
- end_symtab (file_end_addr, 1, 0, objfile,
- SECT_OFF_TEXT);
+ end_symtab (file_end_addr, objfile, SECT_OFF_TEXT);
end_stabs ();
start_stabs ();
/* Give all csects for this source file the same
name. */
start_symtab (filestring, NULL, (CORE_ADDR)0);
+ record_debugformat ("XCOFF");
}
/* If this is the very first csect seen,
last_csect_sec = secnum_to_section (cs->c_secnum, objfile);
}
}
- misc_func_recorded = 0;
continue;
- case XMC_RW :
- break;
+ /* All other symbols are put into the minimal symbol
+ table only. */
- /* If the section is not a data description,
- ignore it. Note that uninitialized data will
- show up as XTY_CM/XMC_RW pair. */
+ case XMC_RW:
+ continue;
case XMC_TC0:
continue;
when `.bf' is seen. */
fcn_cs_saved = *cs;
fcn_aux_saved = main_aux;
-
- ptb = NULL;
-
- /* If function has two auxent, then debugging information is
- already available for it. Process traceback table for
- functions with only one auxent. */
-
- if (cs->c_naux == 1)
- ptb = retrieve_tracebackinfo (abfd, cs);
-
- else if (cs->c_naux != 2)
- {
- static struct complaint msg =
- {"Expected one or two auxents for function", 0, 0};
- complain (&msg);
- }
-
- /* If there is traceback info, create and add parameters
- for it. */
-
- if (ptb && (ptb->fixedparms || ptb->floatparms))
- {
-
- int parmcnt = ptb->fixedparms + ptb->floatparms;
- char *parmcode = (char*) &ptb->parminfo;
-
- /* The link area is 0x18 bytes. */
- int parmvalue = ptb->framesize + 0x18;
- unsigned int ii, mask;
-
- for (ii=0, mask = 0x80000000; ii <parmcnt; ++ii)
- {
- struct symbol *parm;
-
- if (ptb->parminfo & mask)
- {
- /* float or double */
- mask = mask >> 1;
- if (ptb->parminfo & mask)
- {
- /* double parm */
- ADD_PARM_TO_PENDING
- (parm, parmvalue, builtin_type_double,
- local_symbols);
- parmvalue += sizeof (double);
- }
- else
- {
- /* float parm */
- ADD_PARM_TO_PENDING
- (parm, parmvalue, builtin_type_float,
- local_symbols);
- parmvalue += sizeof (float);
- }
- }
- else
- {
- static struct type *intparm_type;
- if (intparm_type == NULL)
- {
-
- /* Create a type, which is a pointer
- type (a kludge to make it print
- in hex), but which has a name
- indicating we don't know the real
- type. */
-
- intparm_type =
- init_type
- (TYPE_CODE_PTR,
- TARGET_PTR_BIT / HOST_CHAR_BIT,
- 0,
- "<non-float parameter>",
- NULL);
- TYPE_TARGET_TYPE (intparm_type) =
- builtin_type_void;
- }
- ADD_PARM_TO_PENDING
- (parm, parmvalue,
- intparm_type,
- local_symbols);
- parmvalue += sizeof (int);
- }
- mask = mask >> 1;
- }
-
- /* Fake this as a function. Needed in
- process_xcoff_symbol(). */
- cs->c_type = 32;
-
- finish_block
- (process_xcoff_symbol (cs, objfile), &local_symbols,
- pending_blocks, cs->c_value,
- cs->c_value + ptb->fsize, objfile);
- }
continue;
case XMC_GL:
/* xlc puts each variable in a separate csect, so we get
an XTY_SD for each variable. But gcc puts several
variables in a csect, so that each variable only gets
- an XTY_LD. We still need to record them. This will
- typically be XMC_RW; I suspect XMC_RO and XMC_BS might
- be possible too. */
- break;
+ an XTY_LD. This will typically be XMC_RW; I suspect
+ XMC_RO and XMC_BS might be possible too.
+ These variables are put in the minimal symbol table
+ only. */
+ continue;
}
+ break;
+
+ case XTY_CM:
+ /* Common symbols are put into the minimal symbol table only. */
+ continue;
default:
break;
complete_symtab (filestring, file_start_addr);
cur_src_end_addr = file_end_addr;
- end_symtab (file_end_addr, 1, 0, objfile, SECT_OFF_TEXT);
+ end_symtab (file_end_addr, objfile, SECT_OFF_TEXT);
end_stabs ();
/* XCOFF, according to the AIX 3.2 documentation, puts the filename
start_stabs ();
start_symtab (filestring, (char *)NULL, (CORE_ADDR)0);
+ record_debugformat ("XCOFF");
last_csect_name = 0;
/* reset file start and end addresses. A compilation unit with no text
/* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
contains number of lines to '}' */
+ if (context_stack_depth <= 0)
+ { /* We attempted to pop an empty context stack */
+ complain (&ef_complaint, cs->c_symnum);
+ within_function = 0;
+ break;
+ }
new = pop_context ();
/* Stack must be empty now. */
if (context_stack_depth > 0 || new == NULL)
break;
case C_HIDEXT:
+ case C_STAT:
break;
case C_BINCL:
}
else if (STREQ (cs->c_name, ".eb"))
{
+ if (context_stack_depth <= 0)
+ { /* We attempted to pop an empty context stack */
+ complain (&eb_complaint, cs->c_symnum);
+ break;
+ }
new = pop_context ();
if (depth-- != new->depth)
{
- complain (&eb_complaint, symnum);
+ complain (&eb_complaint, cs->c_symnum);
break;
}
if (local_symbols && context_stack_depth > 0)
complete_symtab (filestring, file_start_addr);
cur_src_end_addr = file_end_addr;
- s = end_symtab (file_end_addr, 1, 0, objfile, SECT_OFF_TEXT);
+ s = end_symtab (file_end_addr, objfile, SECT_OFF_TEXT);
/* When reading symbols for the last C_FILE of the objfile, try
to make sure that we set pst->symtab to the symtab for the
file, not to the _globals_ symtab. I'm not sure whether this
#define SYMNAME_ALLOC(NAME, ALLOCED) \
- (ALLOCED) ? (NAME) : obstack_copy0 (&objfile->symbol_obstack, (NAME), strlen (NAME));
+ (ALLOCED) ? (NAME) : obsavestring ((NAME), strlen (NAME), &objfile->symbol_obstack);
static struct type *func_symbol_type;
struct symbol onesymbol;
register struct symbol *sym = &onesymbol;
struct symbol *sym2 = NULL;
- struct type *ttype;
- char *name, *pp, *qq;
- int struct_and_type_combined;
- int nameless;
+ char *name, *pp;
int sec;
CORE_ADDR off;
switch (cs->c_sclass)
{
#if 0
+ /* The values of functions and global symbols are now resolved
+ via the global_sym_chain in stabsread.c. */
case C_FUN:
if (fcn_cs_saved.c_sclass == C_EXT)
add_stab_to_list (name, &global_stabs);
else
add_stab_to_list (name, &file_stabs);
break;
-#endif
case C_GSYM:
add_stab_to_list (name, &global_stabs);
break;
+#endif
case C_BCOMM:
common_block_start (cs->c_name, objfile);
case C_ECOML:
case C_LSYM:
case C_RSYM:
+ case C_GSYM:
{
sym = define_symbol (cs->c_value + off, cs->c_name, 0, 0, objfile);
}
return sym;
-#if 0
- /* These appear to be vestigial remnants of coffread.c; I don't
- think any of them are used for xcoff. */
-
- case C_AUTO:
- SYMBOL_CLASS (sym) = LOC_LOCAL;
- SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
- SYMBOL_SECTION (sym) = secnum_to_section (cs->c_secnum, objfile);
- SYMBOL_DUP (sym, sym2);
- add_symbol_to_list (sym2, &local_symbols);
- break;
-
- case C_STAT:
- SYMBOL_CLASS (sym) = LOC_STATIC;
- SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
- SYMBOL_SECTION (sym) = secnum_to_section (cs->c_secnum, objfile);
- SYMBOL_DUP (sym, sym2);
- add_symbol_to_list
- (sym2, within_function ? &local_symbols : &file_symbols);
- break;
-
- case C_RSYM:
- pp = (char*) strchr (name, ':');
- if (pp)
- {
- sym = define_symbol (cs->c_value, cs->c_name, 0, 0, objfile);
- if (sym != NULL)
- SYMBOL_SECTION (sym) = secnum_to_section (cs->c_secnum, objfile);
- return sym;
- }
- else
- {
- complain (&rsym_complaint, name);
- return NULL;
- }
-#endif /* 0 */
-
- /* I think this one is used (dubious, I think, shouldn't
- it go into the msyms only?). */
- case C_EXT:
- SYMBOL_CLASS (sym) = LOC_STATIC;
- SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
- SYMBOL_SECTION (sym) = secnum_to_section (cs->c_secnum, objfile);
- SYMBOL_DUP (sym, sym2);
- add_symbol_to_list (sym2, &global_symbols);
- break;
-
}
}
return sym2;
}
-/* Extract the file name from the aux entry of a C_FILE symbol. Return
- only the last component of the name. Result is in static storage and
- is only good for temporary use. */
+/* Extract the file name from the aux entry of a C_FILE symbol.
+ Result is in static storage and is only good for temporary use. */
static char *
coff_getfilename (aux_entry, objfile)
struct objfile *objfile;
{
static char buffer[BUFSIZ];
- register char *temp;
- char *result;
if (aux_entry->x_file.x_n.x_zeroes == 0)
strcpy (buffer,
strncpy (buffer, aux_entry->x_file.x_fname, FILNMLEN);
buffer[FILNMLEN] = '\0';
}
- result = buffer;
-
- /* FIXME: We should not be throwing away the information about what
- directory. It should go into dirname of the symtab, or some such
- place. */
- if ((temp = strrchr (result, '/')) != NULL)
- result = temp + 1;
- return (result);
+ return (buffer);
}
/* Set *SYMBOL to symbol number symno in symtbl. */
/* Init stuff necessary for reading in symbols. */
stabsread_init ();
buildsym_init ();
- old_chain = make_cleanup (really_free_pendings, 0);
+ old_chain = make_cleanup ((make_cleanup_func) really_free_pendings, 0);
read_xcoff_symtab (pst);
sort_symtab_syms (pst->symtab);
xcoff_new_init (objfile)
struct objfile *objfile;
{
+ stabsread_new_init ();
+ buildsym_new_init ();
}
/* Do initialization in preparation for reading symbols from OBJFILE.
/* Allocate struct to keep track of the symfile */
objfile -> sym_private = xmmalloc (objfile -> md,
sizeof (struct coff_symfile_info));
+
+ /* XCOFF objects may be reordered, so set OBJF_REORDERED. If we
+ find this causes a significant slowdown in gdb then we could
+ set it in the debug symbol readers only when necessary. */
+ objfile->flags |= OBJF_REORDERED;
+
init_entry_point_info (objfile);
}
((struct coff_symfile_info *)objfile->sym_private)->strtbl = NULL;
- if (bfd_seek (abfd, offset, L_SET) < 0)
+ if (bfd_seek (abfd, offset, SEEK_SET) < 0)
error ("cannot seek to string table in %s: %s",
bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
strtbl = (char *) obstack_alloc (&objfile->symbol_obstack, length);
((struct coff_symfile_info *)objfile->sym_private)->strtbl = strtbl;
+ /* Copy length buffer, the first byte is usually zero and is
+ used for stabs with a name length of zero. */
+ memcpy (strtbl, lengthbuf, sizeof lengthbuf);
if (length == sizeof lengthbuf)
return;
static struct partial_symtab *xcoff_start_psymtab
PARAMS ((struct objfile *, struct section_offsets *, char *, int,
- struct partial_symbol *, struct partial_symbol *));
+ struct partial_symbol **, struct partial_symbol **));
/* Allocate and partially fill a partial symtab. It will be
completely filled at the end of the symbol list.
struct section_offsets *section_offsets;
char *filename;
int first_symnum;
- struct partial_symbol *global_syms;
- struct partial_symbol *static_syms;
+ struct partial_symbol **global_syms;
+ struct partial_symbol **static_syms;
{
struct partial_symtab *result =
start_psymtab_common (objfile, section_offsets,
static struct partial_symtab *xcoff_end_psymtab
PARAMS ((struct partial_symtab *, char **, int, int,
- struct partial_symtab **, int));
+ struct partial_symtab **, int, int));
/* Close off the current usage of PST.
Returns PST, or NULL if the partial symtab was empty and thrown away.
static struct partial_symtab *
xcoff_end_psymtab (pst, include_list, num_includes, capping_symbol_number,
- dependency_list, number_dependencies)
+ dependency_list, number_dependencies, textlow_not_set)
struct partial_symtab *pst;
char **include_list;
int num_includes;
int capping_symbol_number;
struct partial_symtab **dependency_list;
int number_dependencies;
+ int textlow_not_set;
{
int i;
struct objfile *objfile = pst -> objfile;
/* Throw away this psymtab, it's empty. We can't deallocate it, since
it is on the obstack, but we can forget to chain it on the list. */
/* Empty psymtabs happen as a result of header files which don't have
- any symbols in them. There can be a lot of them. But this check
- is wrong, in that a psymtab with N_SLINE entries but nothing else
- is not empty, but we don't realize that. Fixing that without slowing
- things down might be tricky. (FIXME: For XCOFF, it shouldn't be
- tricky at all). */
- struct partial_symtab *prev_pst;
-
- /* First, snip it out of the psymtab chain */
-
- if (pst->objfile->psymtabs == pst)
- pst->objfile->psymtabs = pst->next;
- else
- for (prev_pst = pst->objfile->psymtabs; prev_pst; prev_pst = pst->next)
- if (prev_pst->next == pst)
- prev_pst->next = pst->next;
+ any symbols in them. There can be a lot of them. */
- /* Next, put it on a free list for recycling */
-
- pst->next = pst->objfile->free_psymtabs;
- pst->objfile->free_psymtabs = pst;
+ discard_psymtab (pst);
/* Indicate that psymtab was thrown away. */
pst = (struct partial_symtab *)NULL;
struct section_offsets *section_offsets;
struct objfile *objfile;
{
- int toc_offset = 0; /* toc offset value in data section. */
- char *filestring;
+ CORE_ADDR toc_offset = 0; /* toc offset value in data section. */
+ char *filestring = NULL;
char *namestring;
- int nsl;
int past_first_source_file = 0;
- CORE_ADDR last_o_file_start = 0;
- struct cleanup *back_to;
bfd *abfd;
+ asection *bfd_sect;
unsigned int nsyms;
/* Current partial symtab */
unsigned int ssymnum;
char *last_csect_name = NULL; /* last seen csect's name and value */
- CORE_ADDR last_csect_val;
- int last_csect_sec;
- int misc_func_recorded; /* true if any misc. function */
+ CORE_ADDR last_csect_val = 0;
+ int last_csect_sec = 0;
+ int misc_func_recorded = 0; /* true if any misc. function */
+ int textlow_not_set = 1;
pst = (struct partial_symtab *) 0;
ssymnum = 0;
while (ssymnum < nsyms)
{
- int sclass = ((struct external_syment *)sraw_symbol)->e_sclass[0];
+ int sclass = ((struct external_syment *)sraw_symbol)->e_sclass[0] & 0xff;
/* This is the type we pass to partial-stab.h. A less kludgy solution
would be to break out partial-stab.h into its various parts--shuffle
off the DBXREAD_ONLY stuff to dbxread.c, and make separate
else
csect_aux = main_aux;
+ /* If symbol name starts with ".$" or "$", ignore it. */
+ if (namestring[0] == '$'
+ || (namestring[0] == '.' && namestring[1] == '$'))
+ break;
+
switch (csect_aux.x_csect.x_smtyp & 0x7)
{
case XTY_SD:
each program csect, because their text
sections need not be adjacent. */
xcoff_end_psymtab
- (pst, psymtab_include_list,
- includes_used,
- symnum_before,
- dependency_list, dependencies_used);
+ (pst, psymtab_include_list, includes_used,
+ symnum_before, dependency_list,
+ dependencies_used, textlow_not_set);
includes_used = 0;
dependencies_used = 0;
/* Give all psymtabs for this source file the same
}
misc_func_recorded = 0;
break;
+
case XMC_RW:
+ /* Data variables are recorded in the minimal symbol
+ table, except for section symbols. */
+ if (*namestring != '.')
+ prim_record_minimal_symbol_and_info
+ (namestring, symbol.n_value,
+ sclass == C_HIDEXT ? mst_file_data : mst_data,
+ NULL, secnum_to_section (symbol.n_scnum, objfile),
+ NULL, objfile);
break;
+
case XMC_TC0:
if (toc_offset)
warning ("More than one XMC_TC0 symbol found.");
toc_offset = symbol.n_value;
+
+ /* Make TOC offset relative to start address of section. */
+ bfd_sect = secnum_to_bfd_section (symbol.n_scnum, objfile);
+ if (bfd_sect)
+ toc_offset -= bfd_section_vma (objfile->obfd, bfd_sect);
break;
+
case XMC_TC:
/* These symbols tell us where the TOC entry for a
variable is, not the variable itself. */
break;
+
default:
break;
}
switch (csect_aux.x_csect.x_smclas)
{
case XMC_PR:
- {
- /* A function entry point. */
- char *namestr = namestring;
-
- if (first_fun_line_offset == 0)
- first_fun_line_offset =
- main_aux.x_sym.x_fcnary.x_fcn.x_lnnoptr;
- if (namestr[0] == '.')
- ++namestr;
- prim_record_minimal_symbol_and_info
- (namestr, symbol.n_value, mst_text,
- NULL, secnum_to_section (symbol.n_scnum, objfile),
- objfile);
- misc_func_recorded = 1;
-
- /* We also create full symbols for these, so
- better make a partial symbol. This seems bogus
- to me, but I'm not going to try to fix it now.
- (Note that allocate_space_in_inferior can't
- yet deal with a minimal symbol for malloc on xcoff
- because it doesn't understand the fact that
- function pointers don't just contain the address of
- the function). */
- ADD_PSYMBOL_ADDR_TO_LIST (namestr, strlen (namestr),
- VAR_NAMESPACE, LOC_BLOCK,
- objfile->global_psymbols,
- symbol.n_value,
- psymtab_language, objfile);
- }
+ /* A function entry point. */
+
+ if (first_fun_line_offset == 0 && symbol.n_numaux > 1)
+ first_fun_line_offset =
+ main_aux.x_sym.x_fcnary.x_fcn.x_lnnoptr;
+ RECORD_MINIMAL_SYMBOL
+ (namestring, symbol.n_value,
+ sclass == C_HIDEXT ? mst_file_text : mst_text,
+ secnum_to_section (symbol.n_scnum, objfile),
+ objfile);
break;
+
case XMC_GL:
/* shared library function trampoline code entry
point. */
still need to record them. This will
typically be XMC_RW; I suspect XMC_RO and
XMC_BS might be possible too. */
+ if (*namestring != '.')
+ prim_record_minimal_symbol_and_info
+ (namestring, symbol.n_value,
+ sclass == C_HIDEXT ? mst_file_data : mst_data,
+ NULL, secnum_to_section (symbol.n_scnum, objfile),
+ NULL, objfile);
+ break;
+ }
+ break;
- /* FIXME: Shouldn't these be going into the minimal
- symbols instead of partial/full symbols? */
-
- ADD_PSYMBOL_ADDR_TO_LIST (namestring, strlen (namestring),
- VAR_NAMESPACE, LOC_STATIC,
- objfile->global_psymbols,
- symbol.n_value,
- psymtab_language, objfile);
+ case XTY_CM:
+ switch (csect_aux.x_csect.x_smclas)
+ {
+ case XMC_RW:
+ case XMC_BS:
+ /* Common variables are recorded in the minimal symbol
+ table, except for section symbols. */
+ if (*namestring != '.')
+ prim_record_minimal_symbol_and_info
+ (namestring, symbol.n_value,
+ sclass == C_HIDEXT ? mst_file_bss : mst_bss,
+ NULL, secnum_to_section (symbol.n_scnum, objfile),
+ NULL, objfile);
break;
}
+ break;
+
default:
break;
}
if (pst)
{
xcoff_end_psymtab (pst, psymtab_include_list, includes_used,
- symnum_before,
- dependency_list, dependencies_used);
+ symnum_before, dependency_list,
+ dependencies_used, textlow_not_set);
includes_used = 0;
dependencies_used = 0;
}
called from DBXREAD_ONLY or N_SO code. Likewise for the symnum
variable. */
#define START_PSYMTAB(ofile,secoff,fname,low,symoff,global_syms,static_syms) 0
-#define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps)\
+#define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps,textlow_not_set)\
do {} while (0)
/* We have already set the namestring. */
-#define SET_NAMESTRING() 0
+#define SET_NAMESTRING() /* */
#include "partial-stab.h"
}
}
-#if 0
- /* What is this? */
- /* If there's stuff to be cleaned up, clean it up. */
- if (DBX_SYMCOUNT (objfile) > 0 /* We have some syms */
-/*FIXME, does this have a bug at start address 0? */
- && last_o_file_start
- && objfile -> ei.entry_point < bufp->n_value
- && objfile -> ei.entry_point >= last_o_file_start)
- {
- objfile -> ei.entry_file_lowpc = last_o_file_start;
- objfile -> ei.entry_file_highpc = bufp->n_value;
- }
-#endif
if (pst)
{
xcoff_end_psymtab (pst, psymtab_include_list, includes_used,
- ssymnum,
- dependency_list, dependencies_used);
+ ssymnum, dependency_list,
+ dependencies_used, textlow_not_set);
}
- /* Record the toc offset value of this symbol table into ldinfo structure.
+ /* Record the toc offset value of this symbol table into objfile structure.
If no XMC_TC0 is found, toc_offset should be zero. Another place to obtain
this information would be file auxiliary header. */
-#ifndef FAKING_RS6000
- xcoff_add_toc_to_loadinfo (toc_offset);
-#endif
+ ((struct coff_symfile_info *) objfile->sym_private)->toc_offset = toc_offset;
+}
+
+/* Return the toc offset value for a given objfile. */
+
+CORE_ADDR
+get_toc_offset (objfile)
+ struct objfile *objfile;
+{
+ if (objfile)
+ return ((struct coff_symfile_info *) objfile->sym_private)->toc_offset;
+ return 0;
}
/* Scan and build partial symbols for a symbol file.
char *name;
unsigned int size;
-#ifndef FAKING_RS6000
- /* Initialize load info structure. */
- if (mainline)
- xcoff_init_loadinfo ();
-#endif
-
info = (struct coff_symfile_info *) objfile -> sym_private;
symfile_bfd = abfd = objfile->obfd;
name = objfile->name;
/* Read the symbols. We keep them in core because we will want to
access them randomly in read_symbol*. */
- val = bfd_seek (abfd, symtab_offset, L_SET);
+ val = bfd_seek (abfd, symtab_offset, SEEK_SET);
if (val < 0)
error ("Error reading symbols from %s: %s",
name, bfd_errmsg (bfd_get_error ()));
include N_SLINE. */
init_psymbol_list (objfile, num_symbols);
- pending_blocks = 0;
- back_to = make_cleanup (really_free_pendings, 0);
+ free_pending_blocks ();
+ back_to = make_cleanup ((make_cleanup_func) really_free_pendings, 0);
init_minimal_symbol_collection ();
- make_cleanup (discard_minimal_symbols, 0);
+ make_cleanup ((make_cleanup_func) discard_minimal_symbols, 0);
/* Now that the symbol table data of the executable file are all in core,
process them and define symbols accordingly. */
{
add_symtab_fns(&xcoff_sym_fns);
- /* Initialize symbol template later used for arguments. Its other
- fields are zero, or are filled in later. */
- SYMBOL_NAME (&parmsym) = "";
- SYMBOL_INIT_LANGUAGE_SPECIFIC (&parmsym, language_c);
- SYMBOL_NAMESPACE (&parmsym) = VAR_NAMESPACE;
- SYMBOL_CLASS (&parmsym) = LOC_ARG;
-
func_symbol_type = init_type (TYPE_CODE_FUNC, 1, 0,
"<function, no debug info>", NULL);
TYPE_TARGET_TYPE (func_symbol_type) = builtin_type_int;