27#include "gdbsupport/gdb_obstack.h"
30#include "coff/internal.h"
66#define EXTERNAL_NAME(string, abfd) \
67 (*string != '\0' && *string == bfd_get_symbol_leading_char (abfd) \
68 ? string + 1 : string)
75#define SDB_TYPE(type) (BTYPE(type) | (type & N_TMASK))
107#define N_BTMASK local_n_btmask
108#define N_BTSHFT local_n_btshft
109#define N_TMASK local_n_tmask
110#define N_TSHIFT local_n_tshift
155#define INITIAL_TYPE_VECTOR_LENGTH 160
171 union internal_auxent *,
175 union internal_auxent *,
180 union internal_auxent *,
187 union internal_auxent *,
194static int init_lineno (bfd *, file_ptr, file_ptr, gdb::unique_xmalloc_ptr<char> *);
196static char *
getsymname (
struct internal_syment *);
200static int init_stringtab (bfd *, file_ptr, gdb::unique_xmalloc_ptr<char> *);
203 struct internal_syment *,
204 union internal_auxent *);
207 file_ptr,
unsigned int,
struct objfile *);
226 name = bfd_section_name (sectp);
227 if (strcmp (
name,
".text") == 0)
229 csi->
textaddr = bfd_section_vma (sectp);
230 csi->
textsize += bfd_section_size (sectp);
232 else if (startswith (
name,
".text"))
234 csi->
textsize += bfd_section_size (sectp);
236 else if (strcmp (
name,
".stabstr") == 0)
240 else if (startswith (
name,
".stab"))
246 for (s =
name +
sizeof ".stab" - 1; *s !=
'\0'; s++)
268 if (sect->target_index == args->targ_index)
269 *args->resultp = sect;
273static struct bfd_section*
276 asection *sect = NULL;
280 args.resultp = §
303 asection *sect = NULL;
308 args.resultp = §
311 addr = bfd_section_vma (sect);
434 if (!startswith (cs->
c_name,
"__fu"))
436 if (! isdigit (cs->
c_name[4]))
438 for (i = 5; cs->
c_name[i] !=
'\0' && isdigit (cs->
c_name[i]); i++)
499 file_ptr offset, maxoff;
502 count = asect->lineno_count;
511 offset = asect->line_filepos;
515 info->min_lineno_offset = offset;
517 maxoff = offset +
size;
518 if (maxoff > info->max_lineno_offset)
519 info->max_lineno_offset = maxoff;
561 const char *
name = msym->linkage_name ();
569 const char *name1 = NULL;
571 if (startswith (
name,
"_imp_"))
573 else if (startswith (
name,
"__imp_"))
578 = bfd_get_symbol_leading_char (
objfile->
obfd.get ());
581 if (lead !=
'\0' && *name1 == lead)
610 coff_data_type *cdata = coff_data (abfd);
611 const char *filename = bfd_get_filename (abfd);
613 unsigned int num_symbols;
614 file_ptr symtab_offset;
615 file_ptr stringtab_offset;
616 unsigned int stabstrsize;
622 scoped_restore restore_stabsects
623 = make_scoped_restore (&info->stabsects, &
stabsects);
626 num_symbols = bfd_get_symcount (abfd);
627 symtab_offset = cdata->sym_filepos;
628 stringtab_offset = symtab_offset +
629 num_symbols * cdata->local_symesz;
643 gdb::def_vector<char> temp_storage (cdata->local_symesz
644 + cdata->local_auxesz);
654 startswith (bfd_get_target (
objfile->
obfd.get ()),
"pe")
655 || startswith (bfd_get_target (
objfile->
obfd.get ()),
"epoc-pe");
659 info->min_lineno_offset = 0;
660 info->max_lineno_offset = 0;
676 scoped_restore restore_linetab = make_scoped_restore (&
linetab);
677 gdb::unique_xmalloc_ptr<char> linetab_storage;
681 bfd_map_over_sections (abfd,
find_linenos, (
void *) info);
684 info->max_lineno_offset - info->min_lineno_offset,
687 error (_(
"\"%s\": error reading line numbers."), filename);
692 scoped_restore restore_stringtab = make_scoped_restore (&
stringtab);
693 gdb::unique_xmalloc_ptr<char> stringtab_storage;
694 val =
init_stringtab (abfd, stringtab_offset, &stringtab_storage);
696 error (_(
"\"%s\": can't get string table"), filename);
703 if (!info->stabsects->empty())
705 if (!info->stabstrsect)
707 error (_(
"The debugging information in `%s' is corrupted.\nThe "
708 "file has a `.stabs' section, but no `.stabstr' section."),
714 stabstrsize = bfd_section_size (info->stabstrsect);
717 info->textaddr, info->textsize,
719 info->stabstrsect->filepos, stabstrsize);
731 std::string debugfile
734 if (debugfile.empty ())
738 if (!debugfile.empty ())
748 if (debugfile.empty ())
779 file_ptr symtab_offset,
unsigned int nsyms,
786 static struct internal_syment main_sym;
787 static union internal_auxent main_aux;
789 static struct internal_syment fcn_sym_saved;
790 static union internal_auxent fcn_aux_saved;
792 int in_source_file = 0;
793 int next_file_symnum = -1;
795 const char *filestring =
"";
797 int fcn_first_line = 0;
798 CORE_ADDR fcn_first_line_addr = 0;
799 int fcn_last_line = 0;
800 int fcn_start_addr = 0;
801 long fcn_line_ptr = 0;
809 val = bfd_seek (
objfile->
obfd.get (), symtab_offset, 0);
866 unrelocated_addr (tmpaddr),
869 fcn_line_ptr = main_aux.x_sym.x_fcnary.x_fcn.x_lnnoptr;
870 fcn_start_addr = tmpaddr;
872 fcn_sym_saved = main_sym;
873 fcn_aux_saved = main_aux;
886 complaint (_(
"Bad n_sclass for symbol %s"),
893 next_file_symnum = cs->
c_value;
921 case C_THUMBSTATFUNC:
924 if (strcmp (cs->
c_name,
".text") == 0)
935 main_aux.x_scn.x_scnlen);
943 && (startswith (cs->
c_name,
"LI%")
944 || startswith (cs->
c_name,
"LF%")
945 || startswith (cs->
c_name,
"LC%")
946 || startswith (cs->
c_name,
"LP%")
947 || startswith (cs->
c_name,
"LPB%")
948 || startswith (cs->
c_name,
"LBB%")
949 || startswith (cs->
c_name,
"LBE%")
950 || startswith (cs->
c_name,
"LPBX%")))
968 CORE_ADDR offset = 0;
1002 if (bfd_section->flags & SEC_CODE)
1010 else if (bfd_section->flags & SEC_ALLOC
1011 && bfd_section->flags & SEC_LOAD)
1017 else if (bfd_section->flags & SEC_ALLOC)
1028 unrelocated_addr (tmpaddr),
1047 if (strcmp (cs->
c_name,
".bf") == 0)
1056 complaint (_(
"`.bf' symbol %d has no aux entry"),
1058 fcn_first_line = main_aux.x_sym.x_misc.x_lnsz.x_lnno;
1059 fcn_first_line_addr = cs->
c_value;
1071 else if (strcmp (cs->
c_name,
".ef") == 0)
1074 error (_(
"Bad coff function information."));
1082 complaint (_(
"`.ef' symbol without matching `.bf' "
1083 "symbol ignored starting at symnum %d"),
1093 complaint (_(
"Unmatched .ef symbol(s) ignored "
1094 "starting at symnum %d"),
1101 complaint (_(
"`.ef' symbol %d has no aux entry"),
1103 fcn_last_line = 0x7FFFFFFF;
1107 fcn_last_line = main_aux.x_sym.x_misc.x_lnsz.x_lnno;
1116 if (fcn_last_line == 1)
1120 fcn_first_line_addr)));
1128 + fcn_aux_saved.x_sym.x_misc.x_fsize
1135 if (strcmp (cs->
c_name,
".bb") == 0)
1141 else if (strcmp (cs->
c_name,
".eb") == 0)
1145 complaint (_(
"`.eb' symbol without matching `.bb' "
1146 "symbol ignored starting at symnum %d"),
1154 complaint (_(
"Mismatched .eb symbol ignored "
1155 "starting at symnum %d"),
1185 for (
symtab *s : cu->filetabs ())
1202 struct internal_syment *sym,
1203 union internal_auxent *aux)
1206 bfd_size_type bytes;
1213 cs->
c_naux = sym->n_numaux & 0xff;
1220 sym->n_type, sym->n_sclass,
1221 0, cs->
c_naux, (
char *) aux);
1224 for (i = 1; i < cs->
c_naux; i++)
1228 error (_(
"%s: error reading symbols"),
1234 cs->
c_sclass = (sym->n_sclass & 0xff);
1236 cs->
c_type = (unsigned) sym->n_type;
1242 printf (_(
"thumb symbol %s, class 0x%x\n"), cs->
c_name, cs->
c_sclass);
1258 case C_THUMBEXTFUNC:
1263 case C_THUMBSTATFUNC:
1283 unsigned char lengthbuf[4];
1290 if (bfd_seek (abfd, offset, 0) < 0)
1293 val = bfd_read (lengthbuf,
sizeof lengthbuf, abfd);
1296 if (val !=
sizeof lengthbuf)
1299 if (length <
sizeof lengthbuf)
1302 storage->reset ((
char *)
xmalloc (length));
1306 memcpy (
stringtab, lengthbuf,
sizeof lengthbuf);
1308 if (length ==
sizeof length)
1311 val = bfd_read (
stringtab +
sizeof lengthbuf,
1312 length -
sizeof lengthbuf, abfd);
1313 if (val != length -
sizeof lengthbuf ||
stringtab[length - 1] !=
'\0')
1322 static char buffer[SYMNMLEN + 1];
1325 if (symbol_entry->_n._n_n._n_zeroes == 0)
1328 error (_(
"COFF Error: string table offset (%s) outside string table (length %ld)"),
1330 result =
stringtab + symbol_entry->_n._n_n._n_offset;
1334 strncpy (buffer, symbol_entry->_n._n_name, SYMNMLEN);
1335 buffer[SYMNMLEN] =
'\0';
1348 static char buffer[BUFSIZ];
1351 if (aux_entry->x_file.x_n.x_n.x_zeroes == 0)
1353 if (strlen (
stringtab + aux_entry->x_file.x_n.x_n.x_offset) >= BUFSIZ)
1354 internal_error (_(
"coff file name too long"));
1355 strcpy (buffer,
stringtab + aux_entry->x_file.x_n.x_n.x_offset);
1359 size_t x_fname_len =
sizeof (aux_entry->x_file.x_n.x_fname);
1360 strncpy (buffer, aux_entry->x_file.x_n.x_fname, x_fname_len);
1361 buffer[x_fname_len] =
'\0';
1368 result = lbasename (result);
1380 gdb::unique_xmalloc_ptr<char> *storage)
1390 if (bfd_seek (abfd, offset, 0) < 0)
1397 val = bfd_read (storage->get (),
size, abfd);
1407#if !defined (L_LNNO32)
1408#define L_LNNO32(lp) ((lp)->l_lnno)
1417 struct internal_lineno lptr;
1423 complaint (_(
"Line number pointer %s lower than start of line numbers"),
1424 plongest (file_offset));
1443 bfd_coff_swap_lineno_in (
symfile_bfd, rawptr, &lptr);
1449 CORE_ADDR addr = lptr.l_addr.l_paddr;
1469 if (real_target->
name ())
1495 && real_sym->type ()->code () == TYPE_CODE_PTR
1496 && real_sym->type ()->target_type ()->length () != 0)
1498 const char *
name = real_sym->linkage_name ();
1500 struct symbol *sym, *prev;
1546 union internal_auxent *aux,
1573 || cs->
c_sclass == C_THUMBSTATFUNC)
1593 case C_THUMBEXTFUNC:
1602 case C_THUMBSTATFUNC:
1652 if (sym->
type ()->
code () == TYPE_CODE_PTR
1653 || sym->
type ()->
code () == TYPE_CODE_FUNC)
1685 if (sym->
type ()->
code () == TYPE_CODE_PTR
1730 unsigned int new_c_type;
1734 new_c_type = DECREF (c_type);
1740 else if (ISFCN (c_type))
1745 else if (ISARY (c_type))
1748 unsigned short *dim;
1753 if (aux->x_sym.x_tagndx.u32 == 0)
1757 dim = &aux->x_sym.x_fcnary.x_ary.x_dimen[0];
1760 for (i = 0; *dim && i < DIMNUM - 1; i++, dim++)
1780 if (cs->
c_naux > 0 && aux->x_sym.x_tagndx.u32 != 0)
1785 && (int32_t) aux->x_sym.x_tagndx.u32 >= 0)
1792 complaint (_(
"Symbol table entry for %s has bad tagndx value"),
1806 unsigned int c_type,
1807 union internal_auxent *aux,
1810 if (aux->x_sym.x_tagndx.u32 == 0)
1821 unsigned int c_type,
1822 union internal_auxent *aux,
1851 && aux->x_sym.x_misc.x_lnsz.x_size
1881 aux->x_sym.x_misc.x_lnsz.x_size,
1882 aux->x_sym.x_fcnary.x_fcn.x_endndx.u32,
1901 aux->x_sym.x_misc.x_lnsz.x_size,
1902 aux->x_sym.x_fcnary.x_fcn.x_endndx.u32,
1922 aux->x_sym.x_misc.x_lnsz.x_size,
1923 aux->x_sym.x_fcnary.x_fcn.x_endndx.u32,
1943 && aux->x_sym.x_misc.x_lnsz.x_size
1976 struct internal_syment sub_sym;
1977 union internal_auxent sub_aux;
1998 newobj->next = list;
2007 list->
field.set_bitsize (0);
2015 newobj->next = list;
2024 list->
field.set_bitsize (sub_aux.x_sym.x_misc.x_lnsz.x_size);
2039 for (n = nfields; list; list = list->next)
2061 struct internal_syment sub_sym;
2062 union internal_auxent sub_aux;
2067 int unsigned_enum = 1;
2075 o_nsyms = osyms ? osyms->
nsyms : 0;
2123 for (syms = *symlist, n = 0; syms; syms = syms->
next)
2129 for (; j < syms->
nsyms; j++, n++)
void * xrealloc(void *ptr, size_t size)
iterator_range< block_iterator_wrapper > block_iterator_range
std::string find_separate_debug_file_by_buildid(struct objfile *objfile, deferred_warnings *warnings)
void set_last_source_start_addr(CORE_ADDR addr)
struct context_stack * push_context(int desc, CORE_ADDR valu)
struct block * finish_block(struct symbol *symbol, struct pending_block *old_blocks, const struct dynamic_prop *static_link, CORE_ADDR start, CORE_ADDR end)
struct compunit_symtab * start_compunit_symtab(struct objfile *objfile, const char *name, const char *comp_dir, CORE_ADDR start_addr, enum language language)
struct context_stack pop_context()
struct pending ** get_file_symbols()
bool outermost_context_p()
struct subfile * get_current_subfile()
void record_debugformat(const char *format)
void set_last_source_file(const char *name)
struct compunit_symtab * end_compunit_symtab(CORE_ADDR end_addr)
struct pending ** get_global_symbols()
void record_line(struct subfile *subfile, int line, unrelocated_addr pc)
const char * get_last_source_file()
struct pending ** get_local_symbols()
void add_symbol_to_list(struct symbol *symbol, struct pending **listhead)
struct minimal_symbol * record_full(gdb::string_view name, bool copy_name, unrelocated_addr address, enum minimal_symbol_type ms_type, int section)
void read_pe_exported_syms(minimal_symbol_reader &reader, struct objfile *objfile)
static struct objfile * coffread_objfile
static void find_linenos(bfd *abfd, struct bfd_section *asect, void *vpinfo)
static int coff_register_index
static file_ptr linetab_offset
static void coff_start_compunit_symtab(struct objfile *objfile, const char *name)
static void coff_read_minsyms(file_ptr symtab_offset, unsigned int nsyms, struct objfile *objfile)
static const char * coff_getfilename(union internal_auxent *)
static const struct sym_fns coff_sym_fns
static unsigned local_symesz
static void coff_end_compunit_symtab(struct objfile *objfile)
static int is_import_fixup_symbol(struct coff_symbol *cs, enum minimal_symbol_type type)
static int init_stringtab(bfd *, file_ptr, gdb::unique_xmalloc_ptr< char > *)
static CORE_ADDR cs_section_address(struct coff_symbol *, bfd *)
static unsigned local_linesz
static unsigned local_n_tshift
static int init_lineno(bfd *, file_ptr, file_ptr, gdb::unique_xmalloc_ptr< char > *)
static file_ptr linetab_size
static int type_vector_length
static CORE_ADDR current_source_end_addr
static void read_one_sym(struct coff_symbol *, struct internal_syment *, union internal_auxent *)
static struct type ** coff_lookup_type(int index)
static const registry< objfile >::key< coff_symfile_info > coff_objfile_data_key
static int coff_reg_to_regnum(struct symbol *sym, struct gdbarch *gdbarch)
static void coff_new_init(struct objfile *ignore)
static struct type * coff_read_struct_type(int, int, int, struct objfile *)
static void coff_symfile_finish(struct objfile *objfile)
static void coff_symtab_read(minimal_symbol_reader &, file_ptr, unsigned int, struct objfile *)
static long stringtab_length
static CORE_ADDR current_source_start_addr
#define INITIAL_TYPE_VECTOR_LENGTH
static void patch_type(struct type *type, struct type *real_type)
static unsigned local_auxesz
static struct type * decode_type(struct coff_symbol *, unsigned int, union internal_auxent *, struct objfile *)
static const struct symbol_register_ops coff_register_funcs
static struct symbol * process_coff_symbol(struct coff_symbol *, union internal_auxent *, struct objfile *)
static void enter_linenos(file_ptr, int, int, struct objfile *)
static void coff_symfile_init(struct objfile *objfile)
static bfd * nlist_bfd_global
void stabsread_clear_cache(void)
static struct type * coff_read_enum_type(int, int, int, struct objfile *)
static struct type * coff_alloc_type(int index)
static struct type * decode_function_type(struct coff_symbol *, unsigned int, union internal_auxent *, struct objfile *)
static struct minimal_symbol * record_minimal_symbol(minimal_symbol_reader &reader, struct coff_symbol *cs, unrelocated_addr address, enum minimal_symbol_type type, int section, struct objfile *objfile)
static struct type ** type_vector
static char * getsymname(struct internal_syment *)
static void coff_symfile_read(struct objfile *objfile, symfile_add_flags symfile_flags)
void _initialize_coffread()
static struct bfd_section * cs_to_bfd_section(struct coff_symbol *cs, struct objfile *objfile)
static unsigned local_n_btmask
static unsigned local_n_tmask
#define EXTERNAL_NAME(string, abfd)
static void find_targ_sec(bfd *abfd, asection *sect, void *obj)
static int nlist_nsyms_global
static struct type * decode_base_type(struct coff_symbol *, unsigned int, union internal_auxent *, struct objfile *)
static void coff_locate_sections(bfd *abfd, asection *sectp, void *csip)
static int cs_to_section(struct coff_symbol *, struct objfile *)
static struct symbol * opaque_type_chain[HASHSIZE]
static unsigned local_n_btshft
static void patch_opaque_types(struct symtab *)
#define complaint(FMT,...)
void coffstab_build_psymtabs(struct objfile *objfile, CORE_ADDR textaddr, unsigned int textsize, const std::vector< asection * > &stabsects, file_ptr stabstroffset, unsigned int stabstrsize)
int gdb_bfd_section_index(bfd *abfd, asection *section)
gdb::ref_ptr< struct bfd, gdb_bfd_ref_policy > gdb_bfd_ref_ptr
void gdbarch_coff_make_msymbol_special(struct gdbarch *gdbarch, int val, struct minimal_symbol *msym)
int gdbarch_sdb_reg_to_regnum(struct gdbarch *gdbarch, int sdb_regnr)
int gdbarch_int_bit(struct gdbarch *gdbarch)
CORE_ADDR gdbarch_addr_bits_remove(struct gdbarch *gdbarch, CORE_ADDR addr)
int gdbarch_long_bit(struct gdbarch *gdbarch)
struct type * lookup_pointer_type(struct type *type)
struct type * create_static_range_type(type_allocator &alloc, struct type *index_type, LONGEST low_bound, LONGEST high_bound)
struct type * lookup_function_type(struct type *type)
const struct builtin_type * builtin_type(struct gdbarch *gdbarch)
struct type * create_array_type(type_allocator &alloc, struct type *element_type, struct type *range_type)
#define INIT_CPLUS_SPECIFIC(type)
struct bound_minimal_symbol lookup_minimal_symbol(const char *name, const char *sfile, struct objfile *objf)
const char * objfile_name(const struct objfile *objfile)
#define SECT_OFF_TEXT(objfile)
bool dwarf2_has_info(struct objfile *, const struct dwarf2_debug_sections *, bool=false)
void dwarf2_initialize_objfile(struct objfile *objfile)
int hashname(const char *name)
struct block * static_block()
struct minimal_symbol * minsym
struct type * builtin_long_long
struct type * builtin_double
struct type * builtin_long
struct type * builtin_unsigned_char
struct type * builtin_long_double
struct type * builtin_unsigned_long_long
struct type * builtin_short
struct type * builtin_char
struct type * builtin_int
struct type * builtin_unsigned_short
struct type * builtin_unsigned_int
struct type * builtin_unsigned_long
struct type * builtin_void
struct type * builtin_float
std::vector< asection * > * stabsects
file_ptr max_lineno_offset
file_ptr min_lineno_offset
struct blockvector * blockvector()
struct pending_block * old_blocks
void set_bitsize(unsigned int bitsize)
void set_loc_enumval(LONGEST enumval)
void set_name(const char *name)
void set_section_index(short idx)
void compute_and_set_names(gdb::string_view linkage_name, bool copy_name, struct objfile_per_bfd_storage *per_bfd, gdb::optional< hashval_t > hash=gdb::optional< hashval_t >())
void set_language(enum language language, struct obstack *obstack)
const char * linkage_name() const
void set_linkage_name(const char *linkage_name)
void set_type(minimal_symbol_type type)
minimal_symbol_type type() const
struct gdbarch * arch() const
struct objfile_per_bfd_storage * per_bfd
CORE_ADDR text_section_offset() const
compunit_symtab_range compunits()
auto_obstack objfile_obstack
::section_offsets section_offsets
bool has_partial_symbols()
msymbols_range msymbols()
struct symbol * symbol[PENDINGSIZE]
symbol * value_chain() const
struct type * type() const
void set_aclass_index(unsigned int aclass_index)
LONGEST value_longest() const
void set_type(struct type *type)
void set_is_argument(bool is_argument)
void set_value_address(CORE_ADDR address)
void set_value_longest(LONGEST value)
void set_value_chain(symbol *sym)
void set_domain(domain_enum domain)
struct compunit_symtab * compunit() const
struct type * target_type() const
void copy_fields(struct type *src)
void set_code(type_code code)
struct field & field(int idx) const
void set_is_unsigned(bool is_unsigned)
void set_num_fields(unsigned int num_fields)
void set_name(const char *name)
void alloc_fields(unsigned int nfields, bool init=true)
void set_length(ULONGEST length)
const char * name() const
type * index_type() const
void set_fields(struct field *fields)
gdb_bfd_ref_ptr symfile_bfd_open(const char *name)
void add_symtab_fns(enum bfd_flavour flavour, const struct sym_fns *sf)
std::string find_separate_debug_file_by_debuglink(struct objfile *objfile, deferred_warnings *warnings)
void default_symfile_offsets(struct objfile *objfile, const section_addr_info &addrs)
symfile_segment_data_up default_symfile_segments(bfd *abfd)
void symbol_file_add_separate(const gdb_bfd_ref_ptr &bfd, const char *name, symfile_add_flags symfile_flags, struct objfile *objfile)
bfd_byte * default_symfile_relocate(struct objfile *objfile, asection *sectp, bfd_byte *buf)
int register_symbol_register_impl(enum address_class aclass, const struct symbol_register_ops *ops)
static struct xcoff_symbol fcn_cs_saved
#define complete_symtab(name, start_addr)