#include "defs.h"
#include "bfd.h"
#include <sys/types.h>
#include <fcntl.h>
#include <ctype.h>
#include "gdb_string.h"
#include <sys/param.h>
#ifdef HAVE_SYS_FILE_H
#include <sys/file.h>
#endif
#include "gdb_stat.h"
#include "coff/internal.h"
#include "libcoff.h"
#include "coff/xcoff.h"
#include "libxcoff.h"
#include "coff/rs6000.h"
#include "symtab.h"
#include "gdbtypes.h"
#include "symfile.h"
#include "objfiles.h"
#include "buildsym.h"
#include "stabsread.h"
#include "expression.h"
#include "complaints.h"
#include "gdb-stabs.h"
#include "aout/stab_gnu.h"
struct symloc
{
int first_symnum;
int numsyms;
unsigned int lineno_off;
};
static enum language psymtab_language = language_unknown;
struct coff_symbol
{
char *c_name;
int c_symnum;
int c_naux;
long c_value;
unsigned char c_sclass;
int c_secnum;
unsigned int c_type;
};
static struct coff_symbol fcn_cs_saved;
static bfd *symfile_bfd;
static CORE_ADDR cur_src_end_addr;
static CORE_ADDR first_object_file_end;
#define INITIAL_STABVECTOR_LENGTH 40
int within_function;
static unsigned local_symesz;
struct coff_symfile_info
{
file_ptr min_lineno_offset;
file_ptr max_lineno_offset;
char *strtbl;
char *debugsec;
char *symtbl;
int symtbl_num_syms;
CORE_ADDR toc_offset;
};
static void
bf_notfound_complaint (void)
{
complaint (&symfile_complaints, _("line numbers off, `.bf' symbol not found"));
}
static void
ef_complaint (int arg1)
{
complaint (&symfile_complaints,
_("Mismatched .ef symbol ignored starting at symnum %d"), arg1);
}
static void
eb_complaint (int arg1)
{
complaint (&symfile_complaints,
_("Mismatched .eb symbol ignored starting at symnum %d"), arg1);
}
static void xcoff_initial_scan (struct objfile *, int);
static void scan_xcoff_symtab (struct objfile *);
static char *xcoff_next_symbol_text (struct objfile *);
static void record_include_begin (struct coff_symbol *);
static void
enter_line_range (struct subfile *, unsigned, unsigned,
CORE_ADDR, CORE_ADDR, unsigned *);
static void init_stringtab (bfd *, file_ptr, struct objfile *);
static void xcoff_symfile_init (struct objfile *);
static void xcoff_new_init (struct objfile *);
static void xcoff_symfile_finish (struct objfile *);
static void xcoff_symfile_offsets (struct objfile *,
struct section_addr_info *addrs);
static char *coff_getfilename (union internal_auxent *, struct objfile *);
static void read_symbol (struct internal_syment *, int);
static int read_symbol_lineno (int);
static CORE_ADDR read_symbol_nvalue (int);
static struct symbol *process_xcoff_symbol (struct coff_symbol *,
struct objfile *);
static void read_xcoff_symtab (struct partial_symtab *);
#if 0
static void add_stab_to_list (char *, struct pending_stabs **);
#endif
static int compare_lte (const void *, const void *);
static struct linetable *arrange_linetable (struct linetable *);
static void record_include_end (struct coff_symbol *);
static void process_linenos (CORE_ADDR, CORE_ADDR);
static int secnum_to_section (int, struct objfile *);
static asection *secnum_to_bfd_section (int, struct objfile *);
struct find_targ_sec_arg
{
int targ_index;
int *resultp;
asection **bfd_sect;
struct objfile *objfile;
};
static void find_targ_sec (bfd *, asection *, void *);
static void
find_targ_sec (bfd *abfd, asection *sect, void *obj)
{
struct find_targ_sec_arg *args = (struct find_targ_sec_arg *) obj;
struct objfile *objfile = args->objfile;
if (sect->target_index == args->targ_index)
{
if (bfd_get_section_flags (abfd, sect) & SEC_CODE)
*args->resultp = SECT_OFF_TEXT (objfile);
else if (bfd_get_section_flags (abfd, sect) & SEC_LOAD)
*args->resultp = SECT_OFF_DATA (objfile);
else
*args->resultp = sect->index;
*args->bfd_sect = sect;
}
}
static int
secnum_to_section (int secnum, struct objfile *objfile)
{
int off = SECT_OFF_TEXT (objfile);
asection *sect = NULL;
struct find_targ_sec_arg args;
args.targ_index = secnum;
args.resultp = &off;
args.bfd_sect = §
args.objfile = objfile;
bfd_map_over_sections (objfile->obfd, find_targ_sec, &args);
return off;
}
static asection *
secnum_to_bfd_section (int secnum, struct objfile *objfile)
{
int off = SECT_OFF_TEXT (objfile);
asection *sect = NULL;
struct find_targ_sec_arg args;
args.targ_index = secnum;
args.resultp = &off;
args.bfd_sect = §
args.objfile = objfile;
bfd_map_over_sections (objfile->obfd, find_targ_sec, &args);
return sect;
}
#if 0
static void
add_stab_to_list (char *stabname, struct pending_stabs **stabvector)
{
if (*stabvector == NULL)
{
*stabvector = (struct pending_stabs *)
xmalloc (sizeof (struct pending_stabs) +
INITIAL_STABVECTOR_LENGTH * sizeof (char *));
(*stabvector)->count = 0;
(*stabvector)->length = INITIAL_STABVECTOR_LENGTH;
}
else if ((*stabvector)->count >= (*stabvector)->length)
{
(*stabvector)->length += INITIAL_STABVECTOR_LENGTH;
*stabvector = (struct pending_stabs *)
xrealloc ((char *) *stabvector, sizeof (struct pending_stabs) +
(*stabvector)->length * sizeof (char *));
}
(*stabvector)->stab[(*stabvector)->count++] = stabname;
}
#endif
static int
compare_lte (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;
}
static struct linetable *
arrange_linetable (struct linetable *oldLineTb)
{
int ii, jj, newline,
function_count;
struct linetable_entry *fentry;
int fentry_size;
struct linetable *newLineTb;
#define NUM_OF_FUNCTIONS 20
fentry_size = NUM_OF_FUNCTIONS;
fentry = (struct linetable_entry *)
xmalloc (fentry_size * sizeof (struct linetable_entry));
for (function_count = 0, ii = 0; ii < oldLineTb->nitems; ++ii)
{
if (oldLineTb->item[ii].line == 0)
{
if (function_count >= fentry_size)
{
fentry_size *= 2;
fentry = (struct linetable_entry *)
xrealloc (fentry, fentry_size * sizeof (struct linetable_entry));
}
fentry[function_count].line = ii;
fentry[function_count].pc = oldLineTb->item[ii].pc;
++function_count;
}
}
if (function_count == 0)
{
xfree (fentry);
return oldLineTb;
}
else if (function_count > 1)
qsort (fentry, function_count, sizeof (struct linetable_entry), compare_lte);
newLineTb = (struct linetable *)
xmalloc
(sizeof (struct linetable) +
(oldLineTb->nitems - function_count) * sizeof (struct linetable_entry));
newline = 0;
if (oldLineTb->item[0].line != 0)
for (newline = 0;
newline < oldLineTb->nitems && oldLineTb->item[newline].line; ++newline)
newLineTb->item[newline] = oldLineTb->item[newline];
for (ii = 0; ii < function_count; ++ii)
{
for (jj = fentry[ii].line + 1;
jj < oldLineTb->nitems && oldLineTb->item[jj].line != 0;
++jj, ++newline)
newLineTb->item[newline] = oldLineTb->item[jj];
}
xfree (fentry);
newLineTb->nitems = oldLineTb->nitems - function_count;
return newLineTb;
}
typedef struct _inclTable
{
char *name;
int begin, end;
struct subfile *subfile;
unsigned funStartLine;
}
InclTable;
#define INITIAL_INCLUDE_TABLE_LENGTH 20
static InclTable *inclTable;
static int inclIndx;
static int inclLength;
static int inclDepth;
static void allocate_include_entry (void);
static void
record_include_begin (struct coff_symbol *cs)
{
if (inclDepth)
{
complaint (&symfile_complaints, _("Nested C_BINCL symbols"));
}
++inclDepth;
allocate_include_entry ();
inclTable[inclIndx].name = cs->c_name;
inclTable[inclIndx].begin = cs->c_value;
}
static void
record_include_end (struct coff_symbol *cs)
{
InclTable *pTbl;
if (inclDepth == 0)
{
complaint (&symfile_complaints, _("Mismatched C_BINCL/C_EINCL pair"));
}
allocate_include_entry ();
pTbl = &inclTable[inclIndx];
pTbl->end = cs->c_value;
--inclDepth;
++inclIndx;
}
static void
allocate_include_entry (void)
{
if (inclTable == NULL)
{
inclTable = (InclTable *)
xmalloc (sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
memset (inclTable,
'\0', sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
inclLength = INITIAL_INCLUDE_TABLE_LENGTH;
inclIndx = 0;
}
else if (inclIndx >= inclLength)
{
inclLength += INITIAL_INCLUDE_TABLE_LENGTH;
inclTable = (InclTable *)
xrealloc (inclTable, sizeof (InclTable) * inclLength);
memset (inclTable + inclLength - INITIAL_INCLUDE_TABLE_LENGTH,
'\0', sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
}
}
static struct partial_symtab *this_symtab_psymtab;
static void
process_linenos (CORE_ADDR start, CORE_ADDR end)
{
int offset, ii;
file_ptr max_offset =
((struct coff_symfile_info *) this_symtab_psymtab->objfile->deprecated_sym_private)
->max_lineno_offset;
struct subfile main_subfile;
unsigned int main_source_baseline = 0;
unsigned *firstLine;
offset =
((struct symloc *) this_symtab_psymtab->read_symtab_private)->lineno_off;
if (offset == 0)
goto return_after_cleanup;
memset (&main_subfile, '\0', sizeof (main_subfile));
if (inclIndx == 0)
enter_line_range (&main_subfile, offset, 0, start, end,
&main_source_baseline);
else
{
int linesz =
coff_data (this_symtab_psymtab->objfile->obfd)->local_linesz;
main_source_baseline = 0;
for (ii = 0; ii < inclIndx; ++ii)
{
struct subfile *tmpSubfile;
if (offset < inclTable[ii].begin)
{
enter_line_range
(&main_subfile, offset, inclTable[ii].begin - linesz,
start, 0, &main_source_baseline);
}
tmpSubfile = inclTable[ii].subfile =
(struct subfile *) xmalloc (sizeof (struct subfile));
memset (tmpSubfile, '\0', sizeof (struct subfile));
firstLine = &(inclTable[ii].funStartLine);
enter_line_range (tmpSubfile, inclTable[ii].begin,
inclTable[ii].end, start, 0, firstLine);
if (offset <= inclTable[ii].end)
offset = inclTable[ii].end + linesz;
}
if (offset < max_offset + 1 - linesz)
{
enter_line_range (&main_subfile, offset, 0, start, end,
&main_source_baseline);
}
}
if (main_subfile.line_vector)
{
struct linetable *lineTb, *lv;
lv = main_subfile.line_vector;
lineTb = arrange_linetable (lv);
if (lv == lineTb)
{
current_subfile->line_vector = (struct linetable *)
xrealloc (lv, (sizeof (struct linetable)
+ lv->nitems * sizeof (struct linetable_entry)));
}
else
{
xfree (lv);
current_subfile->line_vector = lineTb;
}
current_subfile->line_vector_length =
current_subfile->line_vector->nitems;
}
for (ii = 0; ii < inclIndx; ++ii)
{
if ((inclTable[ii].subfile)->line_vector)
{
struct linetable *lineTb, *lv;
lv = (inclTable[ii].subfile)->line_vector;
lineTb = arrange_linetable (lv);
push_subfile ();
#if 0
start_subfile (inclTable[ii].name, (char *) 0);
#else
{
char *fakename = strrchr (inclTable[ii].name, '.');
if (fakename == NULL)
fakename = " ?";
start_subfile (fakename, (char *) 0);
xfree (current_subfile->name);
}
current_subfile->name = xstrdup (inclTable[ii].name);
#endif
if (lv == lineTb)
{
current_subfile->line_vector =
(struct linetable *) xrealloc
(lv, (sizeof (struct linetable)
+ lv->nitems * sizeof (struct linetable_entry)));
}
else
{
xfree (lv);
current_subfile->line_vector = lineTb;
}
current_subfile->line_vector_length =
current_subfile->line_vector->nitems;
start_subfile (pop_subfile (), (char *) 0);
}
}
return_after_cleanup:
inclIndx = 0;
memset (&main_subfile, '\0', sizeof (struct subfile));
}
void
aix_process_linenos (void)
{
process_linenos (last_source_start_addr, cur_src_end_addr);
}
static void
enter_line_range (struct subfile *subfile, unsigned beginoffset, unsigned endoffset,
CORE_ADDR startaddr,
CORE_ADDR endaddr, unsigned *firstLine)
{
unsigned int curoffset;
CORE_ADDR addr;
void *ext_lnno;
struct internal_lineno int_lnno;
unsigned int limit_offset;
bfd *abfd;
int linesz;
if (endoffset == 0 && startaddr == 0 && endaddr == 0)
return;
curoffset = beginoffset;
limit_offset =
((struct coff_symfile_info *) this_symtab_psymtab->objfile->deprecated_sym_private)
->max_lineno_offset;
if (endoffset != 0)
{
if (endoffset >= limit_offset)
{
complaint (&symfile_complaints,
_("Bad line table offset in C_EINCL directive"));
return;
}
limit_offset = endoffset;
}
else
limit_offset -= 1;
abfd = this_symtab_psymtab->objfile->obfd;
linesz = coff_data (abfd)->local_linesz;
ext_lnno = alloca (linesz);
while (curoffset <= limit_offset)
{
bfd_seek (abfd, curoffset, SEEK_SET);
bfd_bread (ext_lnno, linesz, abfd);
bfd_coff_swap_lineno_in (abfd, ext_lnno, &int_lnno);
addr = (int_lnno.l_lnno
? int_lnno.l_addr.l_paddr
: read_symbol_nvalue (int_lnno.l_addr.l_symndx));
addr += ANOFFSET (this_symtab_psymtab->objfile->section_offsets,
SECT_OFF_TEXT (this_symtab_psymtab->objfile));
if (addr < startaddr || (endaddr && addr >= endaddr))
return;
if (int_lnno.l_lnno == 0)
{
*firstLine = read_symbol_lineno (int_lnno.l_addr.l_symndx);
record_line (subfile, 0, addr, 0, NORMAL_LT_ENTRY);
--(*firstLine);
}
else
record_line (subfile, *firstLine + int_lnno.l_lnno, addr, 0,
NORMAL_LT_ENTRY);
curoffset += linesz;
}
}
#define complete_symtab(name, start_addr) { \
last_source_file = savestring (name, strlen (name)); \
last_source_start_addr = start_addr; \
}
#define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, SECTION, OBJFILE) \
{ \
char *namestr; \
namestr = (NAME); \
if (namestr[0] == '.') ++namestr; \
prim_record_minimal_symbol_and_info (namestr, (ADDR), (TYPE), \
(char *)NULL, (SECTION), (asection *)NULL, (OBJFILE)); \
misc_func_recorded = 1; \
}
static int static_block_base = 0;
static int static_block_section = -1;
static int symname_alloced = 0;
static char *raw_symbol;
static char *
xcoff_next_symbol_text (struct objfile *objfile)
{
struct internal_syment symbol;
char *retval;
objfile = this_symtab_psymtab->objfile;
bfd_coff_swap_sym_in (objfile->obfd, raw_symbol, &symbol);
if (symbol.n_zeroes)
{
complaint (&symfile_complaints, _("Unexpected symbol continuation"));
retval = "";
}
else if (symbol.n_sclass & 0x80)
{
retval =
((struct coff_symfile_info *) objfile->deprecated_sym_private)->debugsec
+ symbol.n_offset;
raw_symbol +=
coff_data (objfile->obfd)->local_symesz;
++symnum;
}
else
{
complaint (&symfile_complaints, _("Unexpected symbol continuation"));
retval = "";
}
return retval;
}
static void
read_xcoff_symtab (struct partial_symtab *pst)
{
struct objfile *objfile = pst->objfile;
bfd *abfd = objfile->obfd;
char *raw_auxptr;
char *strtbl = ((struct coff_symfile_info *) objfile->deprecated_sym_private)->strtbl;
char *debugsec =
((struct coff_symfile_info *) objfile->deprecated_sym_private)->debugsec;
char *debugfmt = bfd_xcoff_is_xcoff64 (abfd) ? "XCOFF64" : "XCOFF";
struct internal_syment symbol[1];
union internal_auxent main_aux;
struct coff_symbol cs[1];
CORE_ADDR file_start_addr = 0;
CORE_ADDR file_end_addr = 0;
int next_file_symnum = -1;
unsigned int max_symnum;
int just_started = 1;
int depth = 0;
int fcn_start_addr = 0;
struct coff_symbol fcn_stab_saved;
union internal_auxent fcn_aux_saved;
struct context_stack *new;
char *filestring = " _start_ ";
char *last_csect_name;
CORE_ADDR last_csect_val;
int last_csect_sec;
this_symtab_psymtab = pst;
local_symesz = coff_data (abfd)->local_symesz;
last_source_file = NULL;
last_csect_name = 0;
last_csect_val = 0;
start_stabs ();
start_symtab (filestring, (char *) NULL, file_start_addr);
record_debugformat (debugfmt);
symnum = ((struct symloc *) pst->read_symtab_private)->first_symnum;
max_symnum =
symnum + ((struct symloc *) pst->read_symtab_private)->numsyms;
first_object_file_end = 0;
raw_symbol =
((struct coff_symfile_info *) objfile->deprecated_sym_private)->symtbl
+ symnum * local_symesz;
while (symnum < max_symnum)
{
QUIT;
{
int ii;
bfd_coff_swap_sym_in (abfd, raw_symbol, symbol);
cs->c_symnum = symnum;
cs->c_naux = symbol->n_numaux;
if (symbol->n_zeroes)
{
symname_alloced = 0;
cs->c_name = ((struct external_syment *) raw_symbol)->e.e_name;
if (cs->c_name[E_SYMNMLEN - 1] != '\0')
{
char *p;
p = obstack_alloc (&objfile->objfile_obstack, E_SYMNMLEN + 1);
strncpy (p, cs->c_name, E_SYMNMLEN);
p[E_SYMNMLEN] = '\0';
cs->c_name = p;
symname_alloced = 1;
}
}
else if (symbol->n_sclass & 0x80)
{
cs->c_name = debugsec + symbol->n_offset;
symname_alloced = 0;
}
else
{
cs->c_name = strtbl + (int) symbol->n_offset;
symname_alloced = 1;
}
cs->c_value = symbol->n_value;
cs->c_sclass = symbol->n_sclass;
cs->c_secnum = symbol->n_scnum;
cs->c_type = (unsigned) symbol->n_type;
raw_symbol += local_symesz;
++symnum;
raw_auxptr = raw_symbol;
for (ii = symbol->n_numaux; ii; --ii)
{
raw_symbol += coff_data (abfd)->local_auxesz;
++symnum;
}
}
if (cs->c_name[0] == '$'
|| (cs->c_name[1] == '$' && cs->c_name[0] == '.'))
continue;
if (cs->c_symnum == next_file_symnum && cs->c_sclass != C_FILE)
{
if (last_source_file)
{
pst->symtab =
end_symtab (cur_src_end_addr, objfile, SECT_OFF_TEXT (objfile));
end_stabs ();
}
start_stabs ();
start_symtab ("_globals_", (char *) NULL, (CORE_ADDR) 0);
record_debugformat (debugfmt);
cur_src_end_addr = first_object_file_end;
}
if ((cs->c_sclass == C_EXT || cs->c_sclass == C_HIDEXT)
&& cs->c_naux == 1)
{
#define CSECT(PP) ((PP)->x_csect)
#define CSECT_LEN(PP) (CSECT(PP).x_scnlen.l)
#define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
#define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
#define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
0, cs->c_naux, &main_aux);
switch (CSECT_SMTYP (&main_aux))
{
case XTY_ER:
continue;
case XTY_SD:
{
switch (CSECT_SCLAS (&main_aux))
{
case XMC_PR:
{
if (last_csect_name)
{
complete_symtab (filestring, file_start_addr);
cur_src_end_addr = file_end_addr;
end_symtab (file_end_addr, objfile, SECT_OFF_TEXT (objfile));
end_stabs ();
start_stabs ();
start_symtab (filestring, NULL, (CORE_ADDR) 0);
record_debugformat (debugfmt);
}
if (just_started)
{
first_object_file_end
= cs->c_value + CSECT_LEN (&main_aux);
just_started = 0;
}
file_start_addr =
cs->c_value + ANOFFSET (objfile->section_offsets,
SECT_OFF_TEXT (objfile));
file_end_addr = file_start_addr + CSECT_LEN (&main_aux);
if (cs->c_name && (cs->c_name[0] == '.'
|| cs->c_name[0] == '@'))
{
last_csect_name = cs->c_name;
last_csect_val = cs->c_value;
last_csect_sec = secnum_to_section (cs->c_secnum, objfile);
}
}
continue;
case XMC_RW:
continue;
case XMC_TC0:
continue;
case XMC_TC:
continue;
default:
continue;
}
}
break;
case XTY_LD:
switch (CSECT_SCLAS (&main_aux))
{
case XMC_PR:
function_entry_point:
fcn_start_addr = cs->c_value;
fcn_cs_saved = *cs;
fcn_aux_saved = main_aux;
continue;
case XMC_GL:
continue;
case XMC_DS:
continue;
default:
continue;
}
break;
case XTY_CM:
continue;
default:
break;
}
}
if (ISFCN (cs->c_type) && cs->c_sclass != C_TPDEF)
{
bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
0, cs->c_naux, &main_aux);
goto function_entry_point;
}
switch (cs->c_sclass)
{
case C_FILE:
next_file_symnum = cs->c_value;
complete_symtab (filestring, file_start_addr);
cur_src_end_addr = file_end_addr;
end_symtab (file_end_addr, objfile, SECT_OFF_TEXT (objfile));
end_stabs ();
if (!strcmp (cs->c_name, ".file") && cs->c_naux > 0)
{
bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
0, cs->c_naux, &main_aux);
filestring = coff_getfilename (&main_aux, objfile);
}
else
filestring = cs->c_name;
start_stabs ();
start_symtab (filestring, (char *) NULL, (CORE_ADDR) 0);
record_debugformat (debugfmt);
last_csect_name = 0;
file_start_addr = file_end_addr = 0;
break;
case C_FUN:
fcn_stab_saved = *cs;
break;
case C_FCN:
if (DEPRECATED_STREQ (cs->c_name, ".bf"))
{
CORE_ADDR off = ANOFFSET (objfile->section_offsets,
SECT_OFF_TEXT (objfile));
bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
0, cs->c_naux, &main_aux);
within_function = 1;
new = push_context (0, fcn_start_addr + off);
new->name = define_symbol
(fcn_cs_saved.c_value + off,
fcn_stab_saved.c_name, NULL, 0, 0, objfile);
if (new->name != NULL)
SYMBOL_SECTION (new->name) = SECT_OFF_TEXT (objfile);
}
else if (DEPRECATED_STREQ (cs->c_name, ".ef"))
{
bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
0, cs->c_naux, &main_aux);
if (context_stack_depth <= 0)
{
ef_complaint (cs->c_symnum);
within_function = 0;
break;
}
new = pop_context ();
if (context_stack_depth > 0 || new == NULL)
{
ef_complaint (cs->c_symnum);
within_function = 0;
break;
}
finish_block (new->name, &local_symbols, new->old_blocks,
new->start_addr,
(fcn_cs_saved.c_value
+ fcn_aux_saved.x_sym.x_misc.x_fsize
+ ANOFFSET (objfile->section_offsets,
SECT_OFF_TEXT (objfile))),
NULL, objfile);
within_function = 0;
}
break;
case C_BSTAT:
{
struct internal_syment symbol;
read_symbol (&symbol, cs->c_value);
static_block_base = symbol.n_value;
static_block_section =
secnum_to_section (symbol.n_scnum, objfile);
}
break;
case C_ESTAT:
static_block_base = 0;
static_block_section = -1;
break;
case C_ARG:
case C_REGPARM:
case C_REG:
case C_TPDEF:
case C_STRTAG:
case C_UNTAG:
case C_ENTAG:
{
complaint (&symfile_complaints, _("Unrecognized storage class %d."),
cs->c_sclass);
}
break;
case C_LABEL:
case C_NULL:
break;
case C_HIDEXT:
case C_STAT:
break;
case C_BINCL:
record_include_begin (cs);
break;
case C_EINCL:
record_include_end (cs);
break;
case C_BLOCK:
if (DEPRECATED_STREQ (cs->c_name, ".bb"))
{
depth++;
new = push_context (depth,
(cs->c_value
+ ANOFFSET (objfile->section_offsets,
SECT_OFF_TEXT (objfile))));
}
else if (DEPRECATED_STREQ (cs->c_name, ".eb"))
{
if (context_stack_depth <= 0)
{
eb_complaint (cs->c_symnum);
break;
}
new = pop_context ();
if (depth-- != new->depth)
{
eb_complaint (cs->c_symnum);
break;
}
if (local_symbols && context_stack_depth > 0)
{
finish_block (new->name, &local_symbols, new->old_blocks,
new->start_addr,
(cs->c_value
+ ANOFFSET (objfile->section_offsets,
SECT_OFF_TEXT (objfile))),
NULL, objfile);
}
local_symbols = new->locals;
}
break;
default:
process_xcoff_symbol (cs, objfile);
break;
}
}
if (last_source_file)
{
struct symtab *s;
complete_symtab (filestring, file_start_addr);
cur_src_end_addr = file_end_addr;
s = end_symtab (file_end_addr, objfile, SECT_OFF_TEXT (objfile));
if (pst->symtab == NULL)
pst->symtab = s;
end_stabs ();
}
}
#define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
(SYMBOL2) = (struct symbol *) \
obstack_alloc (&objfile->objfile_obstack, sizeof (struct symbol)); \
*(SYMBOL2) = *(SYMBOL1);
#define SYMNAME_ALLOC(NAME, ALLOCED) \
(ALLOCED) ? (NAME) : obsavestring ((NAME), strlen (NAME), &objfile->objfile_obstack);
static struct type *func_symbol_type;
static struct type *var_symbol_type;
static struct symbol *
process_xcoff_symbol (struct coff_symbol *cs, struct objfile *objfile)
{
struct symbol onesymbol;
struct symbol *sym = &onesymbol;
struct symbol *sym2 = NULL;
char *name, *pp;
int sec;
CORE_ADDR off;
if (cs->c_secnum < 0)
{
off = 0;
sec = -1;
}
else
{
sec = secnum_to_section (cs->c_secnum, objfile);
off = ANOFFSET (objfile->section_offsets, sec);
}
name = cs->c_name;
if (name[0] == '.')
++name;
memset (sym, '\0', sizeof (struct symbol));
SYMBOL_VALUE_ADDRESS (sym) = cs->c_value + off;
SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
SYMBOL_SECTION (sym) = secnum_to_section (cs->c_secnum, objfile);
if (ISFCN (cs->c_type))
{
DEPRECATED_SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
SYMBOL_TYPE (sym) = func_symbol_type;
SYMBOL_CLASS (sym) = LOC_BLOCK;
SYMBOL_DUP (sym, sym2);
if (cs->c_sclass == C_EXT)
add_symbol_to_list (sym2, &global_symbols);
else if (cs->c_sclass == C_HIDEXT || cs->c_sclass == C_STAT)
add_symbol_to_list (sym2, &file_symbols);
}
else
{
SYMBOL_TYPE (sym) = var_symbol_type;
switch (cs->c_sclass)
{
#if 0
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;
case C_GSYM:
add_stab_to_list (name, &global_stabs);
break;
#endif
case C_BCOMM:
common_block_start (cs->c_name, objfile);
break;
case C_ECOMM:
common_block_end (objfile);
break;
default:
complaint (&symfile_complaints, _("Unexpected storage class: %d"),
cs->c_sclass);
case C_DECL:
case C_PSYM:
case C_RPSYM:
case C_ECOML:
case C_LSYM:
case C_RSYM:
case C_GSYM:
{
sym = define_symbol (cs->c_value + off, cs->c_name, NULL, 0, 0, objfile);
if (sym != NULL)
{
SYMBOL_SECTION (sym) = sec;
}
return sym;
}
case C_STSYM:
if (*name == ':' || (pp = (char *) strchr (name, ':')) == NULL)
return NULL;
++pp;
if (*pp == 'V' && !within_function)
*pp = 'S';
sym = define_symbol ((cs->c_value
+ ANOFFSET (objfile->section_offsets,
static_block_section)),
cs->c_name, NULL, 0, 0, objfile);
if (sym != NULL)
{
SYMBOL_VALUE_ADDRESS (sym) += static_block_base;
SYMBOL_SECTION (sym) = static_block_section;
}
return sym;
}
}
return sym2;
}
static char *
coff_getfilename (union internal_auxent *aux_entry, struct objfile *objfile)
{
static char buffer[BUFSIZ];
if (aux_entry->x_file.x_n.x_zeroes == 0)
strcpy (buffer,
((struct coff_symfile_info *) objfile->deprecated_sym_private)->strtbl
+ aux_entry->x_file.x_n.x_offset);
else
{
strncpy (buffer, aux_entry->x_file.x_fname, FILNMLEN);
buffer[FILNMLEN] = '\0';
}
return (buffer);
}
static void
read_symbol (struct internal_syment *symbol, int symno)
{
int nsyms =
((struct coff_symfile_info *) this_symtab_psymtab->objfile->deprecated_sym_private)->symtbl_num_syms;
char *stbl =
((struct coff_symfile_info *) this_symtab_psymtab->objfile->deprecated_sym_private)->symtbl;
if (symno < 0 || symno >= nsyms)
{
complaint (&symfile_complaints, _("Invalid symbol offset"));
symbol->n_value = 0;
symbol->n_scnum = -1;
return;
}
bfd_coff_swap_sym_in (this_symtab_psymtab->objfile->obfd,
stbl + (symno * local_symesz),
symbol);
}
static CORE_ADDR
read_symbol_nvalue (int symno)
{
struct internal_syment symbol[1];
read_symbol (symbol, symno);
return symbol->n_value;
}
static int
read_symbol_lineno (int symno)
{
struct objfile *objfile = this_symtab_psymtab->objfile;
int xcoff64 = bfd_xcoff_is_xcoff64 (objfile->obfd);
struct coff_symfile_info *info =
(struct coff_symfile_info *)objfile->deprecated_sym_private;
int nsyms = info->symtbl_num_syms;
char *stbl = info->symtbl;
char *strtbl = info->strtbl;
struct internal_syment symbol[1];
union internal_auxent main_aux[1];
if (symno < 0)
{
bf_notfound_complaint ();
return 0;
}
while (symno < nsyms)
{
bfd_coff_swap_sym_in (symfile_bfd,
stbl + (symno * local_symesz), symbol);
if (symbol->n_sclass == C_FCN)
{
char *name = xcoff64 ? strtbl + symbol->n_offset : symbol->n_name;
if (DEPRECATED_STREQ (name, ".bf"))
goto gotit;
}
symno += symbol->n_numaux + 1;
}
bf_notfound_complaint ();
return 0;
gotit:
symno++;
bfd_coff_swap_aux_in (objfile->obfd, stbl + symno * local_symesz,
symbol->n_type, symbol->n_sclass,
0, symbol->n_numaux, main_aux);
return main_aux->x_sym.x_misc.x_lnsz.x_lnno;
}
static void
find_linenos (struct bfd *abfd, struct bfd_section *asect, void *vpinfo)
{
struct coff_symfile_info *info;
int size, count;
file_ptr offset, maxoff;
count = asect->lineno_count;
if (!DEPRECATED_STREQ (asect->name, ".text") || count == 0)
return;
size = count * coff_data (abfd)->local_linesz;
info = (struct coff_symfile_info *) vpinfo;
offset = asect->line_filepos;
maxoff = offset + size;
if (offset < info->min_lineno_offset || info->min_lineno_offset == 0)
info->min_lineno_offset = offset;
if (maxoff > info->max_lineno_offset)
info->max_lineno_offset = maxoff;
}
static void xcoff_psymtab_to_symtab_1 (struct partial_symtab *);
static void
xcoff_psymtab_to_symtab_1 (struct partial_symtab *pst)
{
struct cleanup *old_chain;
int i;
if (!pst)
return;
if (pst->readin)
{
fprintf_unfiltered
(gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
pst->filename);
return;
}
for (i = 0; i < pst->number_of_dependencies; i++)
if (!pst->dependencies[i]->readin)
{
if (info_verbose)
{
fputs_filtered (" ", gdb_stdout);
wrap_here ("");
fputs_filtered ("and ", gdb_stdout);
wrap_here ("");
printf_filtered ("%s...", pst->dependencies[i]->filename);
wrap_here ("");
gdb_flush (gdb_stdout);
}
xcoff_psymtab_to_symtab_1 (pst->dependencies[i]);
}
if (((struct symloc *) pst->read_symtab_private)->numsyms != 0)
{
stabsread_init ();
buildsym_init ();
old_chain = make_cleanup (really_free_pendings, 0);
read_xcoff_symtab (pst);
do_cleanups (old_chain);
}
pst->readin = 1;
}
static void xcoff_psymtab_to_symtab (struct partial_symtab *);
static void
xcoff_psymtab_to_symtab (struct partial_symtab *pst)
{
bfd *sym_bfd;
if (!pst)
return;
if (pst->readin)
{
fprintf_unfiltered
(gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
pst->filename);
return;
}
if (((struct symloc *) pst->read_symtab_private)->numsyms != 0
|| pst->number_of_dependencies)
{
if (info_verbose)
{
printf_filtered ("Reading in symbols for %s...", pst->filename);
gdb_flush (gdb_stdout);
}
sym_bfd = pst->objfile->obfd;
next_symbol_text_func = xcoff_next_symbol_text;
xcoff_psymtab_to_symtab_1 (pst);
scan_file_globals (pst->objfile);
if (info_verbose)
printf_filtered ("done.\n");
}
}
static void
xcoff_new_init (struct objfile *objfile)
{
stabsread_new_init ();
buildsym_new_init ();
}
static void
xcoff_symfile_init (struct objfile *objfile)
{
objfile->deprecated_sym_private = xmalloc (sizeof (struct coff_symfile_info));
objfile->flags |= OBJF_REORDERED;
init_entry_point_info (objfile);
}
static void
xcoff_symfile_finish (struct objfile *objfile)
{
if (objfile->deprecated_sym_private != NULL)
{
xfree (objfile->deprecated_sym_private);
}
if (inclTable)
{
xfree (inclTable);
inclTable = NULL;
}
inclIndx = inclLength = inclDepth = 0;
}
static void
init_stringtab (bfd *abfd, file_ptr offset, struct objfile *objfile)
{
long length;
int val;
unsigned char lengthbuf[4];
char *strtbl;
((struct coff_symfile_info *) objfile->deprecated_sym_private)->strtbl = NULL;
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 ()));
val = bfd_bread ((char *) lengthbuf, sizeof lengthbuf, abfd);
length = bfd_h_get_32 (abfd, lengthbuf);
if (val != sizeof lengthbuf || length < sizeof lengthbuf)
return;
strtbl = (char *) obstack_alloc (&objfile->objfile_obstack, length);
((struct coff_symfile_info *) objfile->deprecated_sym_private)->strtbl = strtbl;
memcpy (strtbl, lengthbuf, sizeof lengthbuf);
if (length == sizeof lengthbuf)
return;
val = bfd_bread (strtbl + sizeof lengthbuf, length - sizeof lengthbuf, abfd);
if (val != length - sizeof lengthbuf)
error (_("cannot read string table from %s: %s"),
bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
if (strtbl[length - 1] != '\0')
error (_("bad symbol file: string table does not end with null character"));
return;
}
static unsigned int first_fun_line_offset;
static struct partial_symtab *xcoff_start_psymtab
(struct objfile *, char *, int,
struct partial_symbol **, struct partial_symbol **);
static struct partial_symtab *
xcoff_start_psymtab (struct objfile *objfile, char *filename, int first_symnum,
struct partial_symbol **global_syms,
struct partial_symbol **static_syms)
{
struct partial_symtab *result =
start_psymtab_common (objfile, objfile->section_offsets,
filename,
0,
global_syms, static_syms);
result->read_symtab_private = (char *)
obstack_alloc (&objfile->objfile_obstack, sizeof (struct symloc));
((struct symloc *) result->read_symtab_private)->first_symnum = first_symnum;
result->read_symtab = xcoff_psymtab_to_symtab;
psymtab_language = deduce_language_from_filename (filename);
return result;
}
static struct partial_symtab *xcoff_end_psymtab
(struct partial_symtab *, char **, int, int,
struct partial_symtab **, int, int);
static struct partial_symtab *
xcoff_end_psymtab (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;
if (capping_symbol_number != -1)
((struct symloc *) pst->read_symtab_private)->numsyms =
capping_symbol_number
- ((struct symloc *) pst->read_symtab_private)->first_symnum;
((struct symloc *) pst->read_symtab_private)->lineno_off =
first_fun_line_offset;
first_fun_line_offset = 0;
pst->n_global_syms =
objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
pst->n_static_syms =
objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
pst->number_of_dependencies = number_dependencies;
if (number_dependencies)
{
pst->dependencies = (struct partial_symtab **)
obstack_alloc (&objfile->objfile_obstack,
number_dependencies * sizeof (struct partial_symtab *));
memcpy (pst->dependencies, dependency_list,
number_dependencies * sizeof (struct partial_symtab *));
}
else
pst->dependencies = 0;
for (i = 0; i < num_includes; i++)
{
struct partial_symtab *subpst =
allocate_psymtab (include_list[i], objfile);
subpst->section_offsets = pst->section_offsets;
subpst->read_symtab_private =
(char *) obstack_alloc (&objfile->objfile_obstack,
sizeof (struct symloc));
((struct symloc *) subpst->read_symtab_private)->first_symnum = 0;
((struct symloc *) subpst->read_symtab_private)->numsyms = 0;
subpst->textlow = 0;
subpst->texthigh = 0;
subpst->dependencies = (struct partial_symtab **)
obstack_alloc (&objfile->objfile_obstack,
sizeof (struct partial_symtab *));
subpst->dependencies[0] = pst;
subpst->number_of_dependencies = 1;
subpst->globals_offset =
subpst->n_global_syms =
subpst->statics_offset =
subpst->n_static_syms = 0;
subpst->readin = 0;
subpst->symtab = 0;
subpst->read_symtab = pst->read_symtab;
}
sort_pst_symbols (pst);
free_named_symtabs (pst->filename);
if (num_includes == 0
&& number_dependencies == 0
&& pst->n_global_syms == 0
&& pst->n_static_syms == 0)
{
discard_psymtab (pst);
pst = (struct partial_symtab *) NULL;
}
return pst;
}
static void swap_sym (struct internal_syment *,
union internal_auxent *, char **, char **,
unsigned int *, struct objfile *);
static void
swap_sym (struct internal_syment *symbol, union internal_auxent *aux,
char **name, char **raw, unsigned int *symnump,
struct objfile *objfile)
{
bfd_coff_swap_sym_in (objfile->obfd, *raw, symbol);
if (symbol->n_zeroes)
{
if (symbol->n_name[E_SYMNMLEN - 1] != '\0')
{
char *p;
p = obstack_alloc (&objfile->objfile_obstack, E_SYMNMLEN + 1);
strncpy (p, symbol->n_name, E_SYMNMLEN);
p[E_SYMNMLEN] = '\0';
*name = p;
}
else
*name = ((struct external_syment *) *raw)->e.e_name;
}
else if (symbol->n_sclass & 0x80)
{
*name = ((struct coff_symfile_info *) objfile->deprecated_sym_private)->debugsec
+ symbol->n_offset;
}
else
{
*name = ((struct coff_symfile_info *) objfile->deprecated_sym_private)->strtbl
+ symbol->n_offset;
}
++*symnump;
*raw += coff_data (objfile->obfd)->local_symesz;
if (symbol->n_numaux > 0)
{
bfd_coff_swap_aux_in (objfile->obfd, *raw, symbol->n_type,
symbol->n_sclass, 0, symbol->n_numaux, aux);
*symnump += symbol->n_numaux;
*raw += coff_data (objfile->obfd)->local_symesz * symbol->n_numaux;
}
}
static void
function_outside_compilation_unit_complaint (const char *arg1)
{
complaint (&symfile_complaints,
_("function `%s' appears to be defined outside of all compilation units"),
arg1);
}
static void
scan_xcoff_symtab (struct objfile *objfile)
{
CORE_ADDR toc_offset = 0;
char *filestring = NULL;
char *namestring;
int past_first_source_file = 0;
bfd *abfd;
asection *bfd_sect;
unsigned int nsyms;
struct partial_symtab *pst;
char **psymtab_include_list;
int includes_allocated;
int includes_used;
struct partial_symtab **dependency_list;
int dependencies_used, dependencies_allocated;
char *sraw_symbol;
struct internal_syment symbol;
union internal_auxent main_aux[5];
unsigned int ssymnum;
char *last_csect_name = NULL;
CORE_ADDR last_csect_val = 0;
int last_csect_sec = 0;
int misc_func_recorded = 0;
int textlow_not_set = 1;
pst = (struct partial_symtab *) 0;
includes_allocated = 30;
includes_used = 0;
psymtab_include_list = (char **) alloca (includes_allocated *
sizeof (char *));
dependencies_allocated = 30;
dependencies_used = 0;
dependency_list =
(struct partial_symtab **) alloca (dependencies_allocated *
sizeof (struct partial_symtab *));
last_source_file = NULL;
abfd = objfile->obfd;
sraw_symbol = ((struct coff_symfile_info *) objfile->deprecated_sym_private)->symtbl;
nsyms = ((struct coff_symfile_info *) objfile->deprecated_sym_private)->symtbl_num_syms;
ssymnum = 0;
while (ssymnum < nsyms)
{
int sclass;
QUIT;
bfd_coff_swap_sym_in (abfd, sraw_symbol, &symbol);
sclass = symbol.n_sclass;
switch (sclass)
{
case C_EXT:
case C_HIDEXT:
{
union internal_auxent csect_aux;
unsigned int symnum_before = ssymnum;
swap_sym (&symbol, &main_aux[0], &namestring, &sraw_symbol,
&ssymnum, objfile);
if (symbol.n_numaux > 1)
{
bfd_coff_swap_aux_in
(objfile->obfd,
sraw_symbol - coff_data (abfd)->local_symesz,
symbol.n_type,
symbol.n_sclass,
symbol.n_numaux - 1,
symbol.n_numaux,
&csect_aux);
}
else
csect_aux = main_aux[0];
if (namestring[0] == '$'
|| (namestring[0] == '.' && namestring[1] == '$'))
break;
switch (csect_aux.x_csect.x_smtyp & 0x7)
{
case XTY_SD:
switch (csect_aux.x_csect.x_smclas)
{
case XMC_PR:
if (last_csect_name)
{
if (!misc_func_recorded)
{
RECORD_MINIMAL_SYMBOL
(last_csect_name, last_csect_val,
mst_text, last_csect_sec,
objfile);
}
if (pst != NULL)
{
xcoff_end_psymtab
(pst, psymtab_include_list, includes_used,
symnum_before, dependency_list,
dependencies_used, textlow_not_set);
includes_used = 0;
dependencies_used = 0;
pst = xcoff_start_psymtab
(objfile,
filestring,
symnum_before,
objfile->global_psymbols.next,
objfile->static_psymbols.next);
}
}
if (namestring && (namestring[0] == '.'
|| namestring[0] == '@'))
{
last_csect_name = namestring;
last_csect_val = symbol.n_value;
last_csect_sec =
secnum_to_section (symbol.n_scnum, objfile);
}
if (pst != NULL)
{
CORE_ADDR highval =
symbol.n_value + csect_aux.x_csect.x_scnlen.l;
if (highval > pst->texthigh)
pst->texthigh = highval;
if (pst->textlow == 0 || symbol.n_value < pst->textlow)
pst->textlow = symbol.n_value;
}
misc_func_recorded = 0;
break;
case XMC_RW:
case XMC_TD:
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;
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:
break;
default:
break;
}
break;
case XTY_LD:
switch (csect_aux.x_csect.x_smclas)
{
case XMC_PR:
if (first_fun_line_offset == 0 && symbol.n_numaux > 1)
first_fun_line_offset =
main_aux[0].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:
RECORD_MINIMAL_SYMBOL
(namestring, symbol.n_value,
mst_solib_trampoline,
secnum_to_section (symbol.n_scnum, objfile),
objfile);
break;
case XMC_DS:
break;
default:
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;
case XTY_CM:
switch (csect_aux.x_csect.x_smclas)
{
case XMC_RW:
case XMC_BS:
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;
}
}
break;
case C_FILE:
{
unsigned int symnum_before;
symnum_before = ssymnum;
swap_sym (&symbol, &main_aux[0], &namestring, &sraw_symbol,
&ssymnum, objfile);
if (last_csect_name && !misc_func_recorded)
{
RECORD_MINIMAL_SYMBOL
(last_csect_name, last_csect_val,
mst_text, last_csect_sec, objfile);
}
if (pst)
{
xcoff_end_psymtab (pst, psymtab_include_list, includes_used,
symnum_before, dependency_list,
dependencies_used, textlow_not_set);
includes_used = 0;
dependencies_used = 0;
}
first_fun_line_offset = 0;
if (!strcmp (namestring, ".file") && symbol.n_numaux > 0)
{
filestring = coff_getfilename (&main_aux[0], objfile);
}
else
filestring = namestring;
pst = xcoff_start_psymtab (objfile,
filestring,
symnum_before,
objfile->global_psymbols.next,
objfile->static_psymbols.next);
last_csect_name = NULL;
}
break;
default:
{
complaint (&symfile_complaints,
_("Storage class %d not recognized during scan"), sclass);
}
case C_FCN:
case C_BSTAT:
case C_ESTAT:
case C_ARG:
case C_REGPARM:
case C_REG:
case C_TPDEF:
case C_STRTAG:
case C_UNTAG:
case C_ENTAG:
case C_LABEL:
case C_NULL:
case C_EINCL:
case C_BLOCK:
case C_STAT:
case C_BCOMM:
case C_ECOMM:
case C_PSYM:
case C_RPSYM:
case C_LSYM:
case C_AUTO:
case C_RSYM:
{
int naux1 = symbol.n_numaux + 1;
ssymnum += naux1;
sraw_symbol += bfd_coff_symesz (abfd) * naux1;
}
break;
case C_BINCL:
{
enum language tmp_language;
swap_sym (&symbol, &main_aux[0], &namestring, &sraw_symbol,
&ssymnum, objfile);
tmp_language = deduce_language_from_filename (namestring);
if (tmp_language != language_unknown
&& (tmp_language != language_c
|| psymtab_language != language_cplus))
psymtab_language = tmp_language;
if (pst && DEPRECATED_STREQ (namestring, pst->filename))
continue;
{
int i;
for (i = 0; i < includes_used; i++)
if (DEPRECATED_STREQ (namestring, psymtab_include_list[i]))
{
i = -1;
break;
}
if (i == -1)
continue;
}
psymtab_include_list[includes_used++] = namestring;
if (includes_used >= includes_allocated)
{
char **orig = psymtab_include_list;
psymtab_include_list = (char **)
alloca ((includes_allocated *= 2) *
sizeof (char *));
memcpy (psymtab_include_list, orig,
includes_used * sizeof (char *));
}
continue;
}
case C_FUN:
case C_GSYM:
case C_ECOML:
case C_DECL:
case C_STSYM:
{
char *p;
swap_sym (&symbol, &main_aux[0], &namestring, &sraw_symbol,
&ssymnum, objfile);
p = (char *) strchr (namestring, ':');
if (!p)
continue;
switch (p[1])
{
case 'S':
symbol.n_value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
#ifdef STATIC_TRANSFORM_NAME
namestring = STATIC_TRANSFORM_NAME (namestring);
#endif
add_psymbol_to_list (namestring, p - namestring,
VAR_DOMAIN, LOC_STATIC,
&objfile->static_psymbols,
0, symbol.n_value,
psymtab_language, objfile);
continue;
case 'G':
symbol.n_value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
add_psymbol_to_list (namestring, p - namestring,
VAR_DOMAIN, LOC_STATIC,
&objfile->global_psymbols,
0, symbol.n_value,
psymtab_language, objfile);
continue;
case 'T':
if (p >= namestring + 2
|| (p == namestring + 1
&& namestring[0] != ' '))
{
add_psymbol_to_list (namestring, p - namestring,
STRUCT_DOMAIN, LOC_TYPEDEF,
&objfile->static_psymbols,
symbol.n_value, 0,
psymtab_language, objfile);
if (p[2] == 't')
{
add_psymbol_to_list (namestring, p - namestring,
VAR_DOMAIN, LOC_TYPEDEF,
&objfile->static_psymbols,
symbol.n_value, 0,
psymtab_language, objfile);
p += 1;
}
}
goto check_enum;
case 't':
if (p != namestring)
{
add_psymbol_to_list (namestring, p - namestring,
VAR_DOMAIN, LOC_TYPEDEF,
&objfile->static_psymbols,
symbol.n_value, 0,
psymtab_language, objfile);
}
check_enum:
p += 2;
while ((*p >= '0' && *p <= '9')
|| *p == '(' || *p == ',' || *p == ')'
|| *p == '=')
p++;
if (*p++ == 'e')
{
if (*p == '-')
{
while (*p != ':')
p++;
p++;
}
while (*p && *p != ';' && *p != ',')
{
char *q;
if (*p == '\\' || (*p == '?' && p[1] == '\0'))
p = next_symbol_text (objfile);
for (q = p; *q && *q != ':'; q++)
;
add_psymbol_to_list (p, q - p,
VAR_DOMAIN, LOC_CONST,
&objfile->static_psymbols, 0,
0, psymtab_language, objfile);
p = q;
while (*p && *p != ',')
p++;
if (*p)
p++;
}
}
continue;
case 'c':
add_psymbol_to_list (namestring, p - namestring,
VAR_DOMAIN, LOC_CONST,
&objfile->static_psymbols, symbol.n_value,
0, psymtab_language, objfile);
continue;
case 'f':
if (! pst)
{
int name_len = p - namestring;
char *name = xmalloc (name_len + 1);
memcpy (name, namestring, name_len);
name[name_len] = '\0';
function_outside_compilation_unit_complaint (name);
xfree (name);
}
symbol.n_value += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
add_psymbol_to_list (namestring, p - namestring,
VAR_DOMAIN, LOC_BLOCK,
&objfile->static_psymbols,
0, symbol.n_value,
psymtab_language, objfile);
continue;
case 'F':
if (! pst)
{
int name_len = p - namestring;
char *name = xmalloc (name_len + 1);
memcpy (name, namestring, name_len);
name[name_len] = '\0';
function_outside_compilation_unit_complaint (name);
xfree (name);
}
symbol.n_value += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
add_psymbol_to_list (namestring, p - namestring,
VAR_DOMAIN, LOC_BLOCK,
&objfile->global_psymbols,
0, symbol.n_value,
psymtab_language, objfile);
continue;
case 'V':
case '(':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '-':
case '#':
continue;
case ':':
continue;
default:
complaint (&symfile_complaints,
_("unknown symbol descriptor `%c'"), p[1]);
continue;
}
}
}
}
if (pst)
{
xcoff_end_psymtab (pst, psymtab_include_list, includes_used,
ssymnum, dependency_list,
dependencies_used, textlow_not_set);
}
((struct coff_symfile_info *) objfile->deprecated_sym_private)->toc_offset = toc_offset;
}
CORE_ADDR
get_toc_offset (struct objfile *objfile)
{
if (objfile)
return ((struct coff_symfile_info *) objfile->deprecated_sym_private)->toc_offset;
return 0;
}
static void
xcoff_initial_scan (struct objfile *objfile, int mainline)
{
bfd *abfd;
int val;
struct cleanup *back_to;
int num_symbols;
file_ptr symtab_offset;
file_ptr stringtab_offset;
struct coff_symfile_info *info;
char *name;
unsigned int size;
info = (struct coff_symfile_info *) objfile->deprecated_sym_private;
symfile_bfd = abfd = objfile->obfd;
name = objfile->name;
num_symbols = bfd_get_symcount (abfd);
symtab_offset = obj_sym_filepos (abfd);
stringtab_offset = symtab_offset +
num_symbols * coff_data (abfd)->local_symesz;
info->min_lineno_offset = 0;
info->max_lineno_offset = 0;
bfd_map_over_sections (abfd, find_linenos, info);
if (num_symbols > 0)
{
init_stringtab (abfd, stringtab_offset, objfile);
{
struct bfd_section *secp;
bfd_size_type length;
char *debugsec = NULL;
secp = bfd_get_section_by_name (abfd, ".debug");
if (secp)
{
length = bfd_section_size (abfd, secp);
if (length)
{
debugsec =
(char *) obstack_alloc (&objfile->objfile_obstack, length);
if (!bfd_get_section_contents (abfd, secp, debugsec,
(file_ptr) 0, length))
{
error (_("Error reading .debug section of `%s': %s"),
name, bfd_errmsg (bfd_get_error ()));
}
}
}
((struct coff_symfile_info *) objfile->deprecated_sym_private)->debugsec =
debugsec;
}
}
val = bfd_seek (abfd, symtab_offset, SEEK_SET);
if (val < 0)
error (_("Error reading symbols from %s: %s"),
name, bfd_errmsg (bfd_get_error ()));
size = coff_data (abfd)->local_symesz * num_symbols;
((struct coff_symfile_info *) objfile->deprecated_sym_private)->symtbl =
obstack_alloc (&objfile->objfile_obstack, size);
((struct coff_symfile_info *) objfile->deprecated_sym_private)->symtbl_num_syms =
num_symbols;
val = bfd_bread (((struct coff_symfile_info *) objfile->deprecated_sym_private)->symtbl,
size, abfd);
if (val != size)
perror_with_name (_("reading symbol table"));
if (mainline
|| (objfile->global_psymbols.size == 0
&& objfile->static_psymbols.size == 0))
init_psymbol_list (objfile, num_symbols);
free_pending_blocks ();
back_to = make_cleanup (really_free_pendings, 0);
init_minimal_symbol_collection ();
make_cleanup_discard_minimal_symbols ();
scan_xcoff_symtab (objfile);
install_minimal_symbols (objfile);
do_cleanups (back_to);
}
static void
xcoff_symfile_offsets (struct objfile *objfile, struct section_addr_info *addrs)
{
asection *sect = NULL;
int i;
objfile->num_sections = bfd_count_sections (objfile->obfd);
objfile->section_offsets = (struct section_offsets *)
obstack_alloc (&objfile->objfile_obstack,
SIZEOF_N_SECTION_OFFSETS (objfile->num_sections));
sect = bfd_get_section_by_name (objfile->obfd, ".text");
if (sect)
objfile->sect_index_text = sect->index;
sect = bfd_get_section_by_name (objfile->obfd, ".data");
if (sect)
objfile->sect_index_data = sect->index;
sect = bfd_get_section_by_name (objfile->obfd, ".bss");
if (sect)
objfile->sect_index_bss = sect->index;
sect = bfd_get_section_by_name (objfile->obfd, ".rodata");
if (sect)
objfile->sect_index_rodata = sect->index;
for (i = 0; i < objfile->num_sections; ++i)
{
(objfile->section_offsets)->offsets[i] = 0;
}
}
static struct sym_fns xcoff_sym_fns =
{
bfd_target_xcoff_flavour,
xcoff_new_init,
xcoff_symfile_init,
xcoff_initial_scan,
xcoff_symfile_finish,
xcoff_symfile_offsets,
NULL
};
void
_initialize_xcoffread (void)
{
add_symtab_fns (&xcoff_sym_fns);
func_symbol_type = init_type (TYPE_CODE_FUNC, 1, 0,
"<function, no debug info>", NULL);
TYPE_TARGET_TYPE (func_symbol_type) = builtin_type_int;
var_symbol_type =
init_type (TYPE_CODE_INT, TARGET_INT_BIT / HOST_CHAR_BIT, 0,
"<variable, no debug info>", NULL);
}