#include "hpread.h"
#include "demangle.h"
#define QUICK_LOOK_UP 1
#define USE_PXDB 1
void hpread_symfile_init (struct objfile *);
void do_pxdb (bfd *);
void hpread_build_psymtabs (struct objfile *, int);
void hpread_symfile_finish (struct objfile *);
static union dnttentry *hpread_get_gntt (int, struct objfile *);
static unsigned long hpread_get_textlow (int, int, struct objfile *, int);
static struct partial_symtab *hpread_start_psymtab
(struct objfile *, char *, CORE_ADDR, int,
struct partial_symbol **, struct partial_symbol **);
static struct partial_symtab *hpread_end_psymtab
(struct partial_symtab *, char **, int, int, CORE_ADDR,
struct partial_symtab **, int);
#ifdef USE_PXDB
#define PXDB_SVR4 "/opt/langtools/bin/pxdb"
#define PXDB_BSD "/usr/bin/pxdb"
#include <stdlib.h>
#include "gdb_string.h"
int
file_exists (char *filename)
{
if (filename)
return (access (filename, F_OK) == 0);
return 0;
}
static enum language
trans_lang (enum hp_language in_lang)
{
if (in_lang == HP_LANGUAGE_C)
return language_c;
else if (in_lang == HP_LANGUAGE_CPLUSPLUS)
return language_cplus;
else if (in_lang == HP_LANGUAGE_FORTRAN)
return language_fortran;
else
return language_unknown;
}
static char main_string[] = "main";
int
hpread_call_pxdb (const char *file_name)
{
char *p;
int status;
int retval;
if (file_exists (PXDB_SVR4))
{
p = xmalloc (strlen (PXDB_SVR4) + strlen (file_name) + 2);
strcpy (p, PXDB_SVR4);
strcat (p, " ");
strcat (p, file_name);
warning ("File not processed by pxdb--about to process now.\n");
status = system (p);
retval = (status == 0);
}
else
{
warning ("pxdb not found at standard location: /opt/langtools/bin\ngdb will not be able to debug %s.\nPlease install pxdb at the above location and then restart gdb.\nYou can also run pxdb on %s with the command\n\"pxdb %s\" and then restart gdb.", file_name, file_name, file_name);
retval = 0;
}
return retval;
}
int
hpread_pxdb_needed (bfd *sym_bfd)
{
asection *pinfo_section, *debug_section, *header_section;
unsigned int do_pxdb;
char *buf;
bfd_size_type header_section_size;
unsigned long tmp;
unsigned int pxdbed;
header_section = bfd_get_section_by_name (sym_bfd, "$HEADER$");
if (!header_section)
{
return 0;
}
debug_section = bfd_get_section_by_name (sym_bfd, "$DEBUG$");
pinfo_section = bfd_get_section_by_name (sym_bfd, "$PINFO$");
if (pinfo_section && !debug_section)
{
header_section_size = bfd_section_size (objfile->obfd, header_section);
if (header_section_size == (bfd_size_type) sizeof (DOC_info_PXDB_header))
{
buf = alloca (sizeof (DOC_info_PXDB_header));
if (!bfd_get_section_contents (sym_bfd,
header_section,
buf, 0,
header_section_size))
error ("bfd_get_section_contents\n");
tmp = bfd_get_32 (sym_bfd, (bfd_byte *) (buf + sizeof (int) * 4));
pxdbed = (tmp >> 31) & 0x1;
if (!pxdbed)
error ("file debug header info invalid\n");
do_pxdb = 0;
}
else
error ("invalid $HEADER$ size in executable \n");
}
else
{
header_section_size = bfd_section_size (objfile->obfd, header_section);
if (header_section_size == (bfd_size_type) sizeof (PXDB_header))
{
buf = alloca (sizeof (PXDB_header));
if (!bfd_get_section_contents (sym_bfd,
header_section,
buf, 0,
header_section_size))
error ("bfd_get_section_contents\n");
tmp = bfd_get_32 (sym_bfd, (bfd_byte *) (buf + sizeof (int) * 3));
pxdbed = (tmp >> 31) & 0x1;
if (pxdbed)
do_pxdb = 0;
else
error ("file debug header invalid\n");
}
else
do_pxdb = 1;
}
if (do_pxdb)
{
return 1;
}
else
{
return 0;
}
}
#endif
void
do_pxdb (bfd *sym_bfd)
{
if (hpread_pxdb_needed (sym_bfd))
{
if (hpread_call_pxdb (sym_bfd->filename))
{
bfd_close (sym_bfd);
}
}
}
#ifdef QUICK_LOOK_UP
#define VALID_FILE(i) ((i) < pxdb_header_p->fd_entries)
#define VALID_MODULE(i) ((i) < pxdb_header_p->md_entries)
#define VALID_PROC(i) ((i) < pxdb_header_p->pd_entries)
#define VALID_CLASS(i) ((i) < pxdb_header_p->cd_entries)
#define FILE_START(i) (qFD[i].adrStart)
#define MODULE_START(i) (qMD[i].adrStart)
#define PROC_START(i) (qPD[i].adrStart)
#define FILE_END(i) (qFD[i].adrEnd)
#define MODULE_END(i) (qMD[i].adrEnd)
#define PROC_END(i) (qPD[i].adrEnd)
#define FILE_ISYM(i) (qFD[i].isym)
#define MODULE_ISYM(i) (qMD[i].isym)
#define PROC_ISYM(i) (qPD[i].isym)
#define VALID_CURR_FILE (curr_fd < pxdb_header_p->fd_entries)
#define VALID_CURR_MODULE (curr_md < pxdb_header_p->md_entries)
#define VALID_CURR_PROC (curr_pd < pxdb_header_p->pd_entries)
#define VALID_CURR_CLASS (curr_cd < pxdb_header_p->cd_entries)
#define CURR_FILE_START (qFD[curr_fd].adrStart)
#define CURR_MODULE_START (qMD[curr_md].adrStart)
#define CURR_PROC_START (qPD[curr_pd].adrStart)
#define CURR_FILE_END (qFD[curr_fd].adrEnd)
#define CURR_MODULE_END (qMD[curr_md].adrEnd)
#define CURR_PROC_END (qPD[curr_pd].adrEnd)
#define CURR_FILE_ISYM (qFD[curr_fd].isym)
#define CURR_MODULE_ISYM (qMD[curr_md].isym)
#define CURR_PROC_ISYM (qPD[curr_pd].isym)
#define TELL_OBJFILE \
do { \
if( !told_objfile ) { \
told_objfile = 1; \
warning ("\nIn object file \"%s\":\n", \
objfile->name); \
} \
} while (0)
typedef struct
{
int start;
int end;
}
pst_syms_struct;
static pst_syms_struct *pst_syms_array = 0;
static pst_syms_count = 0;
static pst_syms_size = 0;
static boolean told_objfile = 0;
static void
init_pst_syms (void)
{
pst_syms_count = 0;
pst_syms_size = 20;
pst_syms_array = (pst_syms_struct *) xmalloc (20 * sizeof (pst_syms_struct));
}
static void
clear_pst_syms (void)
{
pst_syms_count = 0;
pst_syms_size = 0;
xfree (pst_syms_array);
pst_syms_array = 0;
}
static void
record_pst_syms (int start_sym, int end_sym)
{
if (++pst_syms_count > pst_syms_size)
{
pst_syms_array = (pst_syms_struct *) xrealloc (pst_syms_array,
2 * pst_syms_size * sizeof (pst_syms_struct));
pst_syms_size *= 2;
}
pst_syms_array[pst_syms_count - 1].start = start_sym;
pst_syms_array[pst_syms_count - 1].end = end_sym;
}
static int
find_next_pst_start (int index)
{
int i;
for (i = pst_syms_count - 1; i >= 0; i--)
if (pst_syms_array[i].end <= index)
return (i == pst_syms_count - 1) ? 0 : pst_syms_array[i + 1].start - 1;
if (pst_syms_array[0].start > index)
return pst_syms_array[0].start - 1;
return 0;
}
static int
find_next_file_isym (int index, quick_file_entry *qFD, int curr_fd,
PXDB_header_ptr pxdb_header_p)
{
while (VALID_CURR_FILE)
{
if (CURR_FILE_ISYM >= index)
return CURR_FILE_ISYM - 1;
curr_fd++;
}
return 0;
}
static int
find_next_proc_isym (int index, quick_procedure_entry *qPD, int curr_pd,
PXDB_header_ptr pxdb_header_p)
{
while (VALID_CURR_PROC)
{
if (CURR_PROC_ISYM >= index)
return CURR_PROC_ISYM - 1;
curr_pd++;
}
return 0;
}
static int
find_next_module_isym (int index, quick_module_entry *qMD, int curr_md,
PXDB_header_ptr pxdb_header_p)
{
while (VALID_CURR_MODULE)
{
if (CURR_MODULE_ISYM >= index)
return CURR_MODULE_ISYM - 1;
curr_md++;
}
return 0;
}
static int
scan_procs (int *curr_pd_p, quick_procedure_entry *qPD, int max_procs,
CORE_ADDR start_adr, CORE_ADDR end_adr, struct partial_symtab *pst,
char *vt_bits, struct objfile *objfile)
{
union dnttentry *dn_bufp;
int symbol_count = 0;
int curr_pd = *curr_pd_p;
#ifdef DUMPING
static int dumping = 0;
#endif
#ifdef DUMPING
if (dumping)
{
printf ("Scan_procs called, addresses %x to %x, proc %x\n", start_adr, end_adr, curr_pd);
}
#endif
while ((CURR_PROC_START <= end_adr) && (curr_pd < max_procs))
{
char *rtn_name;
char *rtn_dem_name;
char *class_name;
int class;
if ((trans_lang ((enum hp_language) qPD[curr_pd].language) == language_cplus) &&
vt_bits[(long) qPD[curr_pd].sbAlias])
{
rtn_name = &vt_bits[(long) qPD[curr_pd].sbAlias];
rtn_dem_name = cplus_demangle (rtn_name, DMGL_ANSI | DMGL_PARAMS);
}
else
{
rtn_name = &vt_bits[(long) qPD[curr_pd].sbProc];
rtn_dem_name = NULL;
}
if ((strcmp (rtn_name, "_MAIN_") == 0) &&
(strcmp (&vt_bits[(long) qPD[curr_pd].sbProc], "main") == 0))
rtn_dem_name = rtn_name = main_string;
#ifdef DUMPING
if (dumping)
{
printf ("..add %s (demangled %s), index %x to this psymtab\n", rtn_name, rtn_dem_name, curr_pd);
}
#endif
if (CURR_PROC_END > end_adr)
{
TELL_OBJFILE;
warning ("Procedure \"%s\" [0x%x] spans file or module boundaries.", rtn_name, curr_pd);
}
dn_bufp = hpread_get_lntt (qPD[curr_pd].isym, objfile);
if (dn_bufp->dfunc.global)
add_psymbol_with_dem_name_to_list (rtn_name,
strlen (rtn_name),
rtn_dem_name,
strlen (rtn_dem_name),
VAR_NAMESPACE,
LOC_BLOCK,
&objfile->global_psymbols,
(qPD[curr_pd].adrStart +
ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile))),
0,
trans_lang ((enum hp_language) qPD[curr_pd].language),
objfile);
else
add_psymbol_with_dem_name_to_list (rtn_name,
strlen (rtn_name),
rtn_dem_name,
strlen (rtn_dem_name),
VAR_NAMESPACE,
LOC_BLOCK,
&objfile->static_psymbols,
(qPD[curr_pd].adrStart +
ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile))),
0,
trans_lang ((enum hp_language) qPD[curr_pd].language),
objfile);
symbol_count++;
*curr_pd_p = ++curr_pd;
}
#ifdef DUMPING
if (dumping)
{
if (symbol_count == 0)
printf ("Scan_procs: no symbols found!\n");
}
#endif
return symbol_count;
}
int
hpread_quick_traverse (struct objfile *objfile, char *gntt_bits,
char *vt_bits, PXDB_header_ptr pxdb_header_p)
{
struct partial_symtab *pst;
char *addr;
quick_procedure_entry *qPD;
quick_file_entry *qFD;
quick_module_entry *qMD;
quick_class_entry *qCD;
int idx;
int i;
CORE_ADDR start_adr;
CORE_ADDR end_adr;
CORE_ADDR next_mod_adr;
int curr_pd;
int curr_fd;
int curr_md;
int start_sym;
int end_sym;
int max_LNTT_sym_index;
int syms_in_pst;
B_TYPE *class_entered;
struct partial_symbol **global_syms;
struct partial_symbol **static_syms;
#ifdef DUMPING
static int dumping = 0;
#endif
pst = (struct partial_symtab *) 0;
init_pst_syms ();
told_objfile = 0;
if (current_demangling_style != edg_demangling)
{
set_demangling_style (HP_DEMANGLING_STYLE_STRING);
}
addr = gntt_bits;
qPD = (quick_procedure_entry_ptr) addr;
addr += pxdb_header_p->pd_entries * sizeof (quick_procedure_entry);
#ifdef DUMPING
if (dumping)
{
printf ("\n Printing routines as we see them\n");
for (i = 0; VALID_PROC (i); i++)
{
idx = (long) qPD[i].sbProc;
printf ("%s %x..%x\n", &vt_bits[idx],
(int) PROC_START (i),
(int) PROC_END (i));
}
}
#endif
qFD = (quick_file_entry_ptr) addr;
addr += pxdb_header_p->fd_entries * sizeof (quick_file_entry);
#ifdef DUMPING
if (dumping)
{
printf ("\n Printing files as we see them\n");
for (i = 0; VALID_FILE (i); i++)
{
idx = (long) qFD[i].sbFile;
printf ("%s %x..%x\n", &vt_bits[idx],
(int) FILE_START (i),
(int) FILE_END (i));
}
}
#endif
qMD = (quick_module_entry_ptr) addr;
addr += pxdb_header_p->md_entries * sizeof (quick_module_entry);
#ifdef DUMPING
if (dumping)
{
printf ("\n Printing modules as we see them\n");
for (i = 0; i < pxdb_header_p->md_entries; i++)
{
idx = (long) qMD[i].sbMod;
printf ("%s\n", &vt_bits[idx]);
}
}
#endif
qCD = (quick_class_entry_ptr) addr;
addr += pxdb_header_p->cd_entries * sizeof (quick_class_entry);
#ifdef DUMPING
if (dumping)
{
printf ("\n Printing classes as we see them\n");
for (i = 0; VALID_CLASS (i); i++)
{
idx = (long) qCD[i].sbClass;
printf ("%s\n", &vt_bits[idx]);
}
printf ("\n Done with dump, on to build!\n");
}
#endif
max_LNTT_sym_index = LNTT_SYMCOUNT (objfile);
curr_pd = 0;
curr_fd = 0;
curr_md = 0;
start_adr = 0;
end_adr = 0;
start_sym = 0;
end_sym = 0;
syms_in_pst = 0;
global_syms = objfile->global_psymbols.list;
static_syms = objfile->static_psymbols.list;
while (VALID_CURR_PROC && (CURR_PROC_START == 0))
curr_pd++;
while (VALID_CURR_FILE || VALID_CURR_MODULE)
{
char *mod_name_string;
char *full_name_string;
if (VALID_CURR_MODULE && (CURR_MODULE_START == -1) && (CURR_MODULE_END == 0))
{
mod_name_string = &vt_bits[(long) qMD[curr_md].sbMod];
#ifdef DUMPING
if (dumping)
printf ("Module with data only %s\n", mod_name_string);
#endif
pst = hpread_start_psymtab (objfile,
mod_name_string,
CURR_MODULE_START,
(CURR_MODULE_ISYM * sizeof (struct dntt_type_block)),
global_syms,
static_syms);
pst = hpread_end_psymtab (pst,
NULL,
0,
end_sym * sizeof (struct dntt_type_block),
0,
NULL,
0);
global_syms = objfile->global_psymbols.next;
static_syms = objfile->static_psymbols.next;
curr_md++;
}
else if (VALID_CURR_MODULE &&
((CURR_MODULE_START == 0) || (CURR_MODULE_START == -1) ||
(CURR_MODULE_END == 0) || (CURR_MODULE_END == -1)))
{
TELL_OBJFILE;
warning ("Module \"%s\" [0x%s] has non-standard addresses. It starts at 0x%s, ends at 0x%s, and will be skipped.",
mod_name_string, paddr_nz (curr_md), paddr_nz (start_adr), paddr_nz (end_adr));
curr_md++;
}
else
{
if (VALID_CURR_FILE ? (VALID_CURR_MODULE ? (CURR_FILE_END < CURR_MODULE_START) : 1) : 0)
{
full_name_string = &vt_bits[(long) qFD[curr_fd].sbFile];
start_adr = CURR_FILE_START;
end_adr = CURR_FILE_END;
start_sym = CURR_FILE_ISYM;
if (CURR_PROC_START < start_adr)
{
TELL_OBJFILE;
warning ("Found procedure \"%s\" [0x%x] that is not in any file or module.",
&vt_bits[(long) qPD[curr_pd].sbProc], curr_pd);
start_adr = CURR_PROC_START;
if (CURR_PROC_ISYM < start_sym)
start_sym = CURR_PROC_ISYM;
}
if (VALID_FILE (curr_fd + 1) && (FILE_START (curr_fd + 1) <= end_adr))
{
TELL_OBJFILE;
warning ("File \"%s\" [0x%x] has ending address after starting address of next file; adjusting ending address down.",
full_name_string, curr_fd);
end_adr = FILE_START (curr_fd + 1) - 1;
}
if (VALID_MODULE (curr_md) && (CURR_MODULE_START <= end_adr))
{
TELL_OBJFILE;
warning ("File \"%s\" [0x%x] has ending address after starting address of next module; adjusting ending address down.",
full_name_string, curr_fd);
end_adr = CURR_MODULE_START - 1;
}
#ifdef DUMPING
if (dumping)
{
printf ("Make new psymtab for file %s (%x to %x).\n",
full_name_string, start_adr, end_adr);
}
#endif
pst = hpread_start_psymtab (objfile,
full_name_string,
start_adr,
(start_sym * sizeof (struct dntt_type_block)),
global_syms,
static_syms);
class_entered = xmalloc (B_BYTES (pxdb_header_p->cd_entries));
B_CLRALL (class_entered, pxdb_header_p->cd_entries);
syms_in_pst = scan_procs (&curr_pd, qPD, pxdb_header_p->pd_entries,
start_adr, end_adr, pst, vt_bits, objfile);
end_sym = 0;
if (pst_syms_count && start_sym < pst_syms_array[pst_syms_count - 1].end)
{
end_sym = find_next_pst_start (start_sym);
}
if (!end_sym)
{
int next_file_isym = find_next_file_isym (start_sym, qFD, curr_fd + 1, pxdb_header_p);
int next_module_isym = find_next_module_isym (start_sym, qMD, curr_md, pxdb_header_p);
int next_proc_isym = find_next_proc_isym (start_sym, qPD, curr_pd, pxdb_header_p);
if (next_file_isym && next_module_isym)
{
end_sym = min (next_file_isym, next_module_isym);
}
else
{
end_sym = max (next_file_isym, next_module_isym);
}
if (!end_sym)
end_sym = next_proc_isym;
else
end_sym = min (end_sym, next_proc_isym);
}
if (!end_sym)
end_sym = pxdb_header_p->globals;
#ifdef DUMPING
if (dumping)
{
printf ("File psymtab indices: %x to %x\n", start_sym, end_sym);
}
#endif
pst = hpread_end_psymtab (pst,
NULL,
0,
end_sym * sizeof (struct dntt_type_block),
end_adr,
NULL,
0);
record_pst_syms (start_sym, end_sym);
if (NULL == pst)
warning ("No symbols in psymtab for file \"%s\" [0x%x].", full_name_string, curr_fd);
#ifdef DUMPING
if (dumping)
{
printf ("Made new psymtab for file %s (%x to %x), sym %x to %x.\n",
full_name_string, start_adr, end_adr, CURR_FILE_ISYM, end_sym);
}
#endif
global_syms = objfile->global_psymbols.next;
static_syms = objfile->static_psymbols.next;
xfree (class_entered);
curr_fd++;
}
else
{
mod_name_string = &vt_bits[(long) qMD[curr_md].sbMod];
start_adr = CURR_MODULE_START;
if (VALID_CURR_FILE)
{
if (CURR_FILE_START < CURR_MODULE_START)
{
TELL_OBJFILE;
warning ("File \"%s\" [0x%x] crosses beginning of module \"%s\".",
&vt_bits[(long) qFD[curr_fd].sbFile],
curr_fd, mod_name_string);
start_adr = CURR_FILE_START;
}
}
start_sym = CURR_MODULE_ISYM;
if (VALID_CURR_FILE && (CURR_FILE_ISYM < CURR_MODULE_ISYM))
start_sym = CURR_FILE_ISYM;
end_adr = CURR_MODULE_END;
if (VALID_CURR_FILE)
{
while (VALID_CURR_FILE && (CURR_FILE_START < end_adr))
{
#ifdef DUMPING
if (dumping)
printf ("Maybe skipping file %s which overlaps with module %s\n",
&vt_bits[(long) qFD[curr_fd].sbFile], mod_name_string);
#endif
if (CURR_FILE_END > end_adr)
{
TELL_OBJFILE;
warning ("File \"%s\" [0x%x] crosses end of module \"%s\".",
&vt_bits[(long) qFD[curr_fd].sbFile],
curr_fd, mod_name_string);
end_adr = CURR_FILE_END;
}
curr_fd++;
}
curr_fd--;
}
if (VALID_MODULE (curr_md + 1) && (MODULE_START (curr_md + 1) <= end_adr))
{
TELL_OBJFILE;
warning ("Module \"%s\" [0x%x] has ending address after starting address of next module; adjusting ending address down.",
mod_name_string, curr_md);
end_adr = MODULE_START (curr_md + 1) - 1;
}
if (VALID_FILE (curr_fd + 1) && (FILE_START (curr_fd + 1) <= end_adr))
{
TELL_OBJFILE;
warning ("Module \"%s\" [0x%x] has ending address after starting address of next file; adjusting ending address down.",
mod_name_string, curr_md);
end_adr = FILE_START (curr_fd + 1) - 1;
}
if (VALID_CURR_FILE)
full_name_string = &vt_bits[(long) qFD[curr_fd].sbFile];
else
full_name_string = mod_name_string;
if (CURR_PROC_START < start_adr)
{
TELL_OBJFILE;
warning ("Found procedure \"%s\" [0x%x] that is not in any file or module.",
&vt_bits[(long) qPD[curr_pd].sbProc], curr_pd);
start_adr = CURR_PROC_START;
if (CURR_PROC_ISYM < start_sym)
start_sym = CURR_PROC_ISYM;
}
#ifdef DUMPING
if (dumping)
{
printf ("Make new psymtab for module %s (%x to %x), using file %s\n",
mod_name_string, start_adr, end_adr, full_name_string);
}
#endif
pst = hpread_start_psymtab (objfile,
full_name_string,
start_adr,
(start_sym * sizeof (struct dntt_type_block)),
global_syms,
static_syms);
class_entered = xmalloc (B_BYTES (pxdb_header_p->cd_entries));
B_CLRALL (class_entered, pxdb_header_p->cd_entries);
syms_in_pst = scan_procs (&curr_pd, qPD, pxdb_header_p->pd_entries,
start_adr, end_adr, pst, vt_bits, objfile);
end_sym = 0;
if (pst_syms_count && start_sym < pst_syms_array[pst_syms_count - 1].end)
{
end_sym = find_next_pst_start (start_sym);
}
if (!end_sym)
{
int next_file_isym = find_next_file_isym (start_sym, qFD, curr_fd + 1, pxdb_header_p);
int next_module_isym = find_next_module_isym (start_sym, qMD, curr_md + 1, pxdb_header_p);
int next_proc_isym = find_next_proc_isym (start_sym, qPD, curr_pd, pxdb_header_p);
if (next_file_isym && next_module_isym)
{
end_sym = min (next_file_isym, next_module_isym);
}
else
{
end_sym = max (next_file_isym, next_module_isym);
}
if (!end_sym)
end_sym = next_proc_isym;
else
end_sym = min (end_sym, next_proc_isym);
}
if (!end_sym)
end_sym = pxdb_header_p->globals;
#ifdef DUMPING
if (dumping)
{
printf ("Module psymtab indices: %x to %x\n", start_sym, end_sym);
}
#endif
pst = hpread_end_psymtab (pst,
NULL,
0,
end_sym * sizeof (struct dntt_type_block),
end_adr,
NULL,
0);
record_pst_syms (start_sym, end_sym);
if (NULL == pst)
warning ("No symbols in psymtab for module \"%s\" [0x%x].", mod_name_string, curr_md);
#ifdef DUMPING
if (dumping)
{
printf ("Made new psymtab for module %s (%x to %x), sym %x to %x.\n",
mod_name_string, start_adr, end_adr, CURR_MODULE_ISYM, end_sym);
}
#endif
global_syms = objfile->global_psymbols.next;
static_syms = objfile->static_psymbols.next;
xfree (class_entered);
curr_md++;
curr_fd++;
}
}
}
if (VALID_CURR_PROC)
{
start_adr = CURR_PROC_START;
end_adr = qPD[pxdb_header_p->pd_entries - 1].adrEnd;
TELL_OBJFILE;
warning ("Found functions beyond end of all files and modules [0x%x].", curr_pd);
#ifdef DUMPING
if (dumping)
{
printf ("Orphan functions at end, PD %d and beyond (%x to %x)\n",
curr_pd, start_adr, end_adr);
}
#endif
pst = hpread_start_psymtab (objfile,
"orphans",
start_adr,
(CURR_PROC_ISYM * sizeof (struct dntt_type_block)),
global_syms,
static_syms);
scan_procs (&curr_pd, qPD, pxdb_header_p->pd_entries,
start_adr, end_adr, pst, vt_bits, objfile);
pst = hpread_end_psymtab (pst,
NULL,
0,
pxdb_header_p->globals * sizeof (struct dntt_type_block),
end_adr,
NULL,
0);
}
#ifdef NEVER_NEVER
pst = hpread_start_psymtab (objfile,
"globals",
0,
(pxdb_header_p->globals
* sizeof (struct dntt_type_block)),
objfile->global_psymbols.next,
objfile->static_psymbols.next);
hpread_end_psymtab (pst,
NULL, 0,
(max_LNTT_sym_index * sizeof (struct dntt_type_block)),
0,
NULL, 0);
#endif
clear_pst_syms ();
return 1;
}
int
hpread_get_header (struct objfile *objfile, PXDB_header_ptr pxdb_header_p)
{
asection *pinfo_section, *debug_section, *header_section;
#ifdef DUMPING
static int dumping = 0;
#endif
header_section = bfd_get_section_by_name (objfile->obfd, "$HEADER$");
if (!header_section)
{
#ifdef DUMPING
if (dumping)
printf ("==No debug info at all for %s.\n", objfile->name);
#endif
return 0;
}
debug_section = bfd_get_section_by_name (objfile->obfd, "$DEBUG$");
pinfo_section = bfd_get_section_by_name (objfile->obfd, "$PINFO$");
if (debug_section)
{
bfd_get_section_contents (objfile->obfd, header_section,
pxdb_header_p, 0, sizeof (PXDB_header));
if (!pxdb_header_p->pxdbed)
{
return 0;
}
}
else if (pinfo_section)
{
DOC_info_PXDB_header doc_header;
#ifdef DUMPING
if (dumping)
{
printf ("==OOps, PINFO, let's try to handle this, %s.\n", objfile->name);
}
#endif
bfd_get_section_contents (objfile->obfd,
header_section,
&doc_header, 0,
sizeof (DOC_info_PXDB_header));
if (!doc_header.pxdbed)
{
warning ("File \"%s\" not processed by pxdb!", objfile->name);
return 0;
}
pxdb_header_p->pd_entries = doc_header.pd_entries;
pxdb_header_p->fd_entries = doc_header.fd_entries;
pxdb_header_p->md_entries = doc_header.md_entries;
pxdb_header_p->pxdbed = doc_header.pxdbed;
pxdb_header_p->bighdr = doc_header.bighdr;
pxdb_header_p->sa_header = doc_header.sa_header;
pxdb_header_p->inlined = doc_header.inlined;
pxdb_header_p->globals = doc_header.globals;
pxdb_header_p->time = doc_header.time;
pxdb_header_p->pg_entries = doc_header.pg_entries;
pxdb_header_p->functions = doc_header.functions;
pxdb_header_p->files = doc_header.files;
pxdb_header_p->cd_entries = doc_header.cd_entries;
pxdb_header_p->aa_entries = doc_header.aa_entries;
pxdb_header_p->oi_entries = doc_header.oi_entries;
pxdb_header_p->version = doc_header.version;
}
else
{
#ifdef DUMPING
if (dumping)
printf ("==No debug info at all for %s.\n", objfile->name);
#endif
return 0;
}
return 1;
}
#endif
void
hpread_symfile_init (struct objfile *objfile)
{
asection *vt_section, *slt_section, *lntt_section, *gntt_section;
objfile->sym_private = (PTR)
xmmalloc (objfile->md, sizeof (struct hpread_symfile_info));
memset (objfile->sym_private, 0, sizeof (struct hpread_symfile_info));
TYPE_VECTOR (objfile) = 0;
gntt_section = bfd_get_section_by_name (objfile->obfd, "$GNTT$");
if (!gntt_section)
return;
GNTT (objfile)
= obstack_alloc (&objfile->symbol_obstack,
bfd_section_size (objfile->obfd, gntt_section));
bfd_get_section_contents (objfile->obfd, gntt_section, GNTT (objfile),
0, bfd_section_size (objfile->obfd, gntt_section));
GNTT_SYMCOUNT (objfile)
= bfd_section_size (objfile->obfd, gntt_section)
/ sizeof (struct dntt_type_block);
lntt_section = bfd_get_section_by_name (objfile->obfd, "$LNTT$");
if (!lntt_section)
return;
LNTT (objfile)
= obstack_alloc (&objfile->symbol_obstack,
bfd_section_size (objfile->obfd, lntt_section));
bfd_get_section_contents (objfile->obfd, lntt_section, LNTT (objfile),
0, bfd_section_size (objfile->obfd, lntt_section));
LNTT_SYMCOUNT (objfile)
= bfd_section_size (objfile->obfd, lntt_section)
/ sizeof (struct dntt_type_block);
slt_section = bfd_get_section_by_name (objfile->obfd, "$SLT$");
if (!slt_section)
return;
SLT (objfile) =
obstack_alloc (&objfile->symbol_obstack,
bfd_section_size (objfile->obfd, slt_section));
bfd_get_section_contents (objfile->obfd, slt_section, SLT (objfile),
0, bfd_section_size (objfile->obfd, slt_section));
vt_section = bfd_get_section_by_name (objfile->obfd, "$VT$");
if (!vt_section)
return;
VT_SIZE (objfile) = bfd_section_size (objfile->obfd, vt_section);
VT (objfile) =
(char *) obstack_alloc (&objfile->symbol_obstack,
VT_SIZE (objfile));
bfd_get_section_contents (objfile->obfd, vt_section, VT (objfile),
0, VT_SIZE (objfile));
}
void
hpread_build_psymtabs (struct objfile *objfile, int mainline)
{
#ifdef DUMPING
static int dumping = 0;
#endif
char *namestring;
int past_first_source_file = 0;
struct cleanup *old_chain;
int hp_symnum, symcount, i;
int scan_start = 0;
union dnttentry *dn_bufp;
unsigned long valu;
char *p;
int texthigh = 0;
int have_name = 0;
struct partial_symtab *pst;
char **psymtab_include_list;
int includes_allocated;
int includes_used;
struct partial_symtab **dependency_list;
int dependencies_used, dependencies_allocated;
free_pending_blocks ();
make_cleanup (really_free_pendings, 0);
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 *));
old_chain = make_cleanup_free_objfile (objfile);
last_source_file = 0;
#ifdef QUICK_LOOK_UP
{
PXDB_header pxdb_header;
int found_modules_in_program;
if (hpread_get_header (objfile, &pxdb_header))
{
#ifdef DUMPING
if (dumping)
printf ("\nNew method for %s\n", objfile->name);
#endif
found_modules_in_program = hpread_quick_traverse (objfile,
GNTT (objfile),
VT (objfile),
&pxdb_header);
discard_cleanups (old_chain);
if (found_modules_in_program)
scan_start = pxdb_header.globals;
}
#ifdef DUMPING
else
{
if (dumping)
printf ("\nGoing on to old method for %s\n", objfile->name);
}
#endif
}
#endif
for (i = 0; i < 1; i++)
{
int within_function = 0;
if (i)
symcount = GNTT_SYMCOUNT (objfile);
else
symcount = LNTT_SYMCOUNT (objfile);
for (hp_symnum = scan_start; hp_symnum < symcount; hp_symnum++)
{
QUIT;
if (i)
dn_bufp = hpread_get_gntt (hp_symnum, objfile);
else
dn_bufp = hpread_get_lntt (hp_symnum, objfile);
if (dn_bufp->dblock.extension)
continue;
switch (dn_bufp->dblock.kind)
{
case DNTT_TYPE_SRCFILE:
{
#ifdef QUICK_LOOK_UP
if (scan_start == hp_symnum
&& symcount == hp_symnum + 1)
{
continue;
}
#endif
SET_NAMESTRING (dn_bufp, &namestring, objfile);
if (pst && !strcmp (namestring, pst->filename))
continue;
p = strrchr (namestring, '.');
if (!strcmp (p, ".h"))
{
int j, found;
found = 0;
for (j = 0; j < includes_used; j++)
if (!strcmp (namestring, psymtab_include_list[j]))
{
found = 1;
break;
}
if (found)
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 ((PTR) psymtab_include_list, (PTR) orig,
includes_used * sizeof (char *));
}
continue;
}
if (pst)
{
if (!have_name)
{
pst->filename = (char *)
obstack_alloc (&pst->objfile->psymbol_obstack,
strlen (namestring) + 1);
strcpy (pst->filename, namestring);
have_name = 1;
continue;
}
continue;
}
if (pst && past_first_source_file)
{
hpread_end_psymtab (pst, psymtab_include_list,
includes_used,
(hp_symnum
* sizeof (struct dntt_type_block)),
texthigh,
dependency_list, dependencies_used);
pst = (struct partial_symtab *) 0;
includes_used = 0;
dependencies_used = 0;
}
else
past_first_source_file = 1;
valu = hpread_get_textlow (i, hp_symnum, objfile, symcount);
valu += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
pst = hpread_start_psymtab (objfile,
namestring, valu,
(hp_symnum
* sizeof (struct dntt_type_block)),
objfile->global_psymbols.next,
objfile->static_psymbols.next);
texthigh = valu;
have_name = 1;
continue;
}
case DNTT_TYPE_MODULE:
if (pst)
{
hpread_end_psymtab (pst, psymtab_include_list, includes_used,
((hp_symnum - 1)
* sizeof (struct dntt_type_block)),
texthigh,
dependency_list, dependencies_used);
pst = (struct partial_symtab *) 0;
includes_used = 0;
dependencies_used = 0;
have_name = 0;
}
SET_NAMESTRING (dn_bufp, &namestring, objfile);
valu = hpread_get_textlow (i, hp_symnum, objfile, symcount);
valu += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
if (!pst)
{
pst = hpread_start_psymtab (objfile,
namestring, valu,
(hp_symnum
* sizeof (struct dntt_type_block)),
objfile->global_psymbols.next,
objfile->static_psymbols.next);
texthigh = valu;
have_name = 0;
}
continue;
case DNTT_TYPE_FUNCTION:
case DNTT_TYPE_ENTRY:
valu = dn_bufp->dfunc.hiaddr + ANOFFSET (objfile->section_offsets,
SECT_OFF_TEXT (objfile));
if (valu > texthigh)
texthigh = valu;
valu = dn_bufp->dfunc.lowaddr +
ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
SET_NAMESTRING (dn_bufp, &namestring, objfile);
if (dn_bufp->dfunc.global)
add_psymbol_to_list (namestring, strlen (namestring),
VAR_NAMESPACE, LOC_BLOCK,
&objfile->global_psymbols, valu,
0, language_unknown, objfile);
else
add_psymbol_to_list (namestring, strlen (namestring),
VAR_NAMESPACE, LOC_BLOCK,
&objfile->static_psymbols, valu,
0, language_unknown, objfile);
within_function = 1;
continue;
case DNTT_TYPE_DOC_FUNCTION:
valu = dn_bufp->ddocfunc.hiaddr + ANOFFSET (objfile->section_offsets,
SECT_OFF_TEXT (objfile));
if (valu > texthigh)
texthigh = valu;
valu = dn_bufp->ddocfunc.lowaddr +
ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
SET_NAMESTRING (dn_bufp, &namestring, objfile);
if (dn_bufp->ddocfunc.global)
add_psymbol_to_list (namestring, strlen (namestring),
VAR_NAMESPACE, LOC_BLOCK,
&objfile->global_psymbols, valu,
0, language_unknown, objfile);
else
add_psymbol_to_list (namestring, strlen (namestring),
VAR_NAMESPACE, LOC_BLOCK,
&objfile->static_psymbols, valu,
0, language_unknown, objfile);
within_function = 1;
continue;
case DNTT_TYPE_BEGIN:
case DNTT_TYPE_END:
#ifdef QUICK_LOOK_UP
if (scan_start == hp_symnum
&& symcount == hp_symnum + 1)
{
continue;
}
#endif
if ((dn_bufp->dend.endkind == DNTT_TYPE_FUNCTION) ||
(dn_bufp->dend.endkind == DNTT_TYPE_DOC_FUNCTION))
within_function = 0;
continue;
case DNTT_TYPE_SVAR:
case DNTT_TYPE_DVAR:
case DNTT_TYPE_TYPEDEF:
case DNTT_TYPE_TAGDEF:
{
enum address_class storage;
namespace_enum namespace;
if (within_function
&& (dn_bufp->dblock.kind == DNTT_TYPE_SVAR
|| dn_bufp->dblock.kind == DNTT_TYPE_DVAR))
continue;
if (dn_bufp->dblock.kind == DNTT_TYPE_TAGDEF)
namespace = STRUCT_NAMESPACE;
else
namespace = VAR_NAMESPACE;
if (dn_bufp->dblock.kind == DNTT_TYPE_SVAR)
storage = LOC_STATIC;
else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR
&& dn_bufp->ddvar.regvar)
storage = LOC_REGISTER;
else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR)
storage = LOC_LOCAL;
else
storage = LOC_UNDEF;
SET_NAMESTRING (dn_bufp, &namestring, objfile);
if (!pst)
{
pst = hpread_start_psymtab (objfile,
"globals", 0,
(hp_symnum
* sizeof (struct dntt_type_block)),
objfile->global_psymbols.next,
objfile->static_psymbols.next);
}
valu = dn_bufp->dsvar.location;
if (storage == LOC_STATIC)
valu += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
if (dn_bufp->dsvar.global)
{
add_psymbol_to_list (namestring, strlen (namestring),
namespace, storage,
&objfile->global_psymbols,
valu,
0, language_unknown, objfile);
}
else
{
add_psymbol_to_list (namestring, strlen (namestring),
namespace, storage,
&objfile->static_psymbols,
valu,
0, language_unknown, objfile);
}
if (dn_bufp->dblock.kind == DNTT_TYPE_TAGDEF &&
dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile))
{
int global = dn_bufp->dtag.global;
dn_bufp = hpread_get_lntt (dn_bufp->dtype.type.dnttp.index, objfile);
if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS ||
dn_bufp->dblock.kind == DNTT_TYPE_ENUM ||
dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE)
{
if (global)
{
add_psymbol_to_list (namestring, strlen (namestring),
VAR_NAMESPACE, storage,
&objfile->global_psymbols,
dn_bufp->dsvar.location,
0, language_unknown, objfile);
}
else
{
add_psymbol_to_list (namestring, strlen (namestring),
VAR_NAMESPACE, storage,
&objfile->static_psymbols,
dn_bufp->dsvar.location,
0, language_unknown, objfile);
}
}
}
}
continue;
case DNTT_TYPE_MEMENUM:
case DNTT_TYPE_CONST:
SET_NAMESTRING (dn_bufp, &namestring, objfile);
if (!pst)
{
pst = hpread_start_psymtab (objfile,
"globals", 0,
(hp_symnum
* sizeof (struct dntt_type_block)),
objfile->global_psymbols.next,
objfile->static_psymbols.next);
}
if (dn_bufp->dconst.global)
add_psymbol_to_list (namestring, strlen (namestring),
VAR_NAMESPACE, LOC_CONST,
&objfile->global_psymbols, 0,
0, language_unknown, objfile);
else
add_psymbol_to_list (namestring, strlen (namestring),
VAR_NAMESPACE, LOC_CONST,
&objfile->static_psymbols, 0,
0, language_unknown, objfile);
continue;
default:
continue;
}
}
}
if (pst)
{
hpread_end_psymtab (pst, psymtab_include_list, includes_used,
hp_symnum * sizeof (struct dntt_type_block),
0, dependency_list, dependencies_used);
}
discard_cleanups (old_chain);
}
void
hpread_symfile_finish (struct objfile *objfile)
{
if (objfile->sym_private != NULL)
{
xmfree (objfile->md, objfile->sym_private);
}
}
union dnttentry *
hpread_get_lntt (int index, struct objfile *objfile)
{
return (union dnttentry *)
&(LNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
}
static union dnttentry *
hpread_get_gntt (int index, struct objfile *objfile)
{
return (union dnttentry *)
&(GNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
}
union sltentry *
hpread_get_slt (int index, struct objfile *objfile)
{
return (union sltentry *) &(SLT (objfile)[index * sizeof (union sltentry)]);
}
static unsigned long
hpread_get_textlow (int global, int index, struct objfile *objfile,
int symcount)
{
union dnttentry *dn_bufp;
struct minimal_symbol *msymbol;
if (index < symcount)
{
do
{
if (global)
dn_bufp = hpread_get_gntt (index++, objfile);
else
dn_bufp = hpread_get_lntt (index++, objfile);
}
while (dn_bufp->dblock.kind != DNTT_TYPE_FUNCTION
&& dn_bufp->dblock.kind != DNTT_TYPE_DOC_FUNCTION
&& dn_bufp->dblock.kind != DNTT_TYPE_END
&& index < symcount);
}
if (dn_bufp->dblock.kind == DNTT_TYPE_END)
return 0;
if (index == symcount)
return 0;
if (dn_bufp->dblock.kind == DNTT_TYPE_FUNCTION)
msymbol = lookup_minimal_symbol (dn_bufp->dfunc.name + VT (objfile), NULL,
objfile);
else
msymbol = lookup_minimal_symbol (dn_bufp->ddocfunc.name + VT (objfile), NULL,
objfile);
if (msymbol)
return SYMBOL_VALUE_ADDRESS (msymbol);
else
return dn_bufp->dfunc.lowaddr;
}
static struct partial_symtab *
hpread_start_psymtab (struct objfile *objfile, char *filename,
CORE_ADDR textlow, int ldsymoff,
struct partial_symbol **global_syms,
struct partial_symbol **static_syms)
{
int offset = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
extern void hpread_psymtab_to_symtab ();
struct partial_symtab *result =
start_psymtab_common (objfile, objfile->section_offsets,
filename, textlow, global_syms, static_syms);
result->textlow += offset;
result->read_symtab_private = (char *)
obstack_alloc (&objfile->psymbol_obstack, sizeof (struct symloc));
LDSYMOFF (result) = ldsymoff;
result->read_symtab = hpread_psymtab_to_symtab;
return result;
}
static struct partial_symtab *
hpread_end_psymtab (struct partial_symtab *pst, char **include_list,
int num_includes, int capping_symbol_offset,
CORE_ADDR capping_text,
struct partial_symtab **dependency_list,
int number_dependencies)
{
int i;
struct objfile *objfile = pst->objfile;
int offset = ANOFFSET (pst->section_offsets, SECT_OFF_TEXT (objfile));
#ifdef DUMPING
static int dumping = 0;
#endif
if (capping_symbol_offset != -1)
LDSYMLEN (pst) = capping_symbol_offset - LDSYMOFF (pst);
else
LDSYMLEN (pst) = 0;
pst->texthigh = capping_text + offset;
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);
#ifdef DUMPING
if (dumping)
{
printf ("\nPst %s, LDSYMOFF %x (%x), LDSYMLEN %x (%x), globals %d, statics %d\n",
pst->filename,
LDSYMOFF (pst),
LDSYMOFF (pst) / sizeof (struct dntt_type_block),
LDSYMLEN (pst),
LDSYMLEN (pst) / sizeof (struct dntt_type_block),
pst->n_global_syms, pst->n_static_syms);
}
#endif
pst->number_of_dependencies = number_dependencies;
if (number_dependencies)
{
pst->dependencies = (struct partial_symtab **)
obstack_alloc (&objfile->psymbol_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->psymbol_obstack,
sizeof (struct symloc));
LDSYMOFF (subpst) =
LDSYMLEN (subpst) =
subpst->textlow =
subpst->texthigh = 0;
subpst->dependencies = (struct partial_symtab **)
obstack_alloc (&objfile->psymbol_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;
}
#if 0
***Local Variables:
***c - basic - offset:4
*** End:
#endif