📄 xcoffread.c
字号:
SYMBOL_VALUE (sym) += static_block_base; return sym;#endif case C_LSYM: if (*name == ':' || (pp = (char *) strchr (name, ':')) == NULL) return NULL; SYMBOL_NAME (sym) = obsavestring (name, pp-name, &objfile -> symbol_obstack); SYMBOL_CLASS (sym) = LOC_LOCAL; pp += 1; SYMBOL_TYPE (sym) = read_type (&pp, objfile); SYMBOL_DUP (sym, sym2); add_symbol_to_list (sym2, &local_symbols); break; case C_AUTO: SYMBOL_CLASS (sym) = LOC_LOCAL; SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced); SYMBOL_DUP (sym, sym2); add_symbol_to_list (sym2, &local_symbols); break; case C_EXT: SYMBOL_CLASS (sym) = LOC_STATIC; SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced); SYMBOL_DUP (sym, sym2); add_symbol_to_list (sym2, &global_symbols); break; case C_STAT: SYMBOL_CLASS (sym) = LOC_STATIC; SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced); SYMBOL_DUP (sym, sym2); add_symbol_to_list (sym2, within_function ? &local_symbols : &file_symbols); break; case C_REG: printf ("ERROR! C_REG is not fully implemented!\n"); SYMBOL_CLASS (sym) = LOC_REGISTER; SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced); SYMBOL_DUP (sym, sym2); add_symbol_to_list (sym2, &local_symbols); break; case C_RSYM:#ifdef NO_DEFINE_SYMBOL pp = (char*) strchr (name, ':'); SYMBOL_CLASS (sym) = LOC_REGISTER; SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (cs->c_value); if (pp) { SYMBOL_NAME (sym) = obsavestring (name, pp-name, &objfile -> symbol_obstack); pp += 2; if (*pp) SYMBOL_TYPE (sym) = read_type (&pp, objfile); } else /* else this is not a stab entry, suppose the type is either `int' or `float', depending on the register class. */ SYMBOL_TYPE (sym) = (SYMBOL_VALUE (sym) < 32) ? lookup_fundamental_type (objfile, FT_INTEGER) : lookup_fundamental_type (objfile, FT_FLOAT); SYMBOL_DUP (sym, sym2); add_symbol_to_list (sym2, &local_symbols); break;#else if (pp) { sym = define_symbol (cs->c_value, cs->c_name, 0, 0, objfile); return sym; } else { warning ("A non-stab C_RSYM needs special handling."); return NULL; }#endif default : warning ("Unexpected storage class: %d.", cs->c_sclass); return NULL; } } return sym2;}static intread_symbol_nvalue (symtable, symno) char *symtable; int symno;{ struct internal_syment symbol[1]; bfd_coff_swap_sym_in (symfile_bfd, symtable + (symno*local_symesz), symbol); return symbol->n_value; }static intread_symbol_lineno (symtable, symno) char *symtable; int symno;{ struct internal_syment symbol[1]; union internal_auxent main_aux[1]; int ii; for (ii = 0; ii < 50; ii++) { bfd_coff_swap_sym_in (symfile_bfd, symtable + (symno*local_symesz), symbol); if (symbol->n_sclass == C_FCN && 0 == strcmp (symbol->n_name, ".bf")) goto gotit; symno += symbol->n_numaux+1; } printf ("GDB Error: `.bf' not found.\n"); return 0;gotit: /* take aux entry and return its lineno */ symno++; bfd_coff_swap_aux_in (symfile_bfd, symtable+(symno*local_symesz), symbol->n_type, symbol->n_sclass, main_aux); return main_aux->x_sym.x_misc.x_lnsz.x_lnno;}/* Support for line number handling *//* This function is called for every section; it finds the outer limits * of the line table (minimum and maximum file offset) so that the * mainline code can read the whole thing for efficiency. */static voidfind_linenos(abfd, asect, vpinfo)bfd *abfd;sec_ptr asect;PTR vpinfo; { struct coff_symfile_info *info; int size, count; file_ptr offset, maxoff; count = asect->lineno_count; if (strcmp (asect->name, ".text") || count == 0) return; size = count * coff_data (symfile_bfd)->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;}/* Read in all the line numbers for fast lookups later. Leave them in external (unswapped) format in memory; we'll swap them as we enter them into GDB's data structures. */static intinit_lineno (abfd, offset, size) bfd *abfd; file_ptr offset; int size;{ int val; if (bfd_seek(abfd, offset, L_SET) < 0) return -1; linetab = (char *) xmalloc(size); val = bfd_read(linetab, 1, size, abfd); if (val != size) return -1; linetab_offset = offset; linetab_size = size; make_cleanup (free, linetab); /* Be sure it gets de-allocated. */ return 0;}/* dbx allows the text of a symbol name to be continued into the next symbol name! When such a continuation is encountered (a \ at the end of the text of a name) call this function to get the continuation. *//* So far, I haven't seen this happenning xlc output. I doubt we'll need this for xcoff. */#undef next_symbol_text#define next_symbol_text() \ printf ("Gdb Error: symbol names on multiple lines not implemented.\n")/* xlc/dbx combination uses a set of builtin types, starting from -1. return the proper type node fora given builtin type #. */struct type *builtin_type (pp)char **pp;{ int typenums[2]; if (**pp != '-') { printf ("ERROR!, unknown built-in type!\n"); return NULL; } *pp += 1; read_type_number (pp, typenums); /* default types are defined in dbxstclass.h. */ switch ( typenums[1] ) { case 1: return lookup_fundamental_type (current_objfile, FT_INTEGER); case 2: return lookup_fundamental_type (current_objfile, FT_CHAR); case 3: return lookup_fundamental_type (current_objfile, FT_SHORT); case 4: return lookup_fundamental_type (current_objfile, FT_LONG); case 5: return lookup_fundamental_type (current_objfile, FT_UNSIGNED_CHAR); case 6: return lookup_fundamental_type (current_objfile, FT_SIGNED_CHAR); case 7: return lookup_fundamental_type (current_objfile, FT_UNSIGNED_SHORT); case 8: return lookup_fundamental_type (current_objfile, FT_UNSIGNED_INTEGER); case 9: return lookup_fundamental_type (current_objfile, FT_UNSIGNED_INTEGER); case 10: return lookup_fundamental_type (current_objfile, FT_UNSIGNED_LONG); case 11: return lookup_fundamental_type (current_objfile, FT_VOID); case 12: return lookup_fundamental_type (current_objfile, FT_FLOAT); case 13: return lookup_fundamental_type (current_objfile, FT_DBL_PREC_FLOAT); case 14: return lookup_fundamental_type (current_objfile, FT_EXT_PREC_FLOAT); case 15: /* requires a builtin `integer' */ return lookup_fundamental_type (current_objfile, FT_INTEGER); case 16: return lookup_fundamental_type (current_objfile, FT_BOOLEAN); case 17: /* requires builtin `short real' */ return lookup_fundamental_type (current_objfile, FT_FLOAT); case 18: /* requires builtin `real' */ return lookup_fundamental_type (current_objfile, FT_FLOAT); default : printf ("ERROR! Unknown builtin type -%d\n", typenums[1]); return NULL; }}static voidxcoff_new_init (objfile) struct objfile *objfile;{}static voidxcoff_symfile_init (objfile) struct objfile *objfile;{ bfd *abfd = objfile->obfd; /* Allocate struct to keep track of the symfile */ objfile -> sym_private = xmmalloc (objfile -> md, sizeof (struct coff_symfile_info)); init_entry_point_info (objfile);}/* Perform any local cleanups required when we are done with a particular objfile. I.E, we are in the process of discarding all symbol information for an objfile, freeing up all memory held for it, and unlinking the objfile struct from the global list of known objfiles. */static voidxcoff_symfile_finish (objfile) struct objfile *objfile;{ if (objfile -> sym_private != NULL) { mfree (objfile -> md, objfile -> sym_private); } /* Start with a fresh include table for the next objfile. */ if (inclTable) { free (inclTable); inclTable = NULL; } inclIndx = inclLength = inclDepth = 0;}static intinit_stringtab(abfd, offset, objfile) bfd *abfd; file_ptr offset; struct objfile *objfile;{ long length; int val; unsigned char lengthbuf[4]; if (bfd_seek(abfd, offset, L_SET) < 0) return -1; val = bfd_read((char *)lengthbuf, 1, sizeof lengthbuf, abfd); length = bfd_h_get_32(abfd, lengthbuf); /* If no string table is needed, then the file may end immediately after the symbols. Just return with `strtbl' set to null. */ if (val != sizeof length || length < sizeof length) return 0; /* Allocate string table from symbol_obstack. We will need this table as long as we have its symbol table around. */ strtbl = (char*) obstack_alloc (&objfile->symbol_obstack, length); if (strtbl == NULL) return -1; bcopy(&length, strtbl, sizeof length); if (length == sizeof length) return 0; val = bfd_read(strtbl + sizeof length, 1, length - sizeof length, abfd); if (val != length - sizeof length || strtbl[length - 1] != '\0') return -1; return 0;}static intinit_debugsection(abfd) bfd *abfd;{ register sec_ptr secp; bfd_size_type length; if (debugsec) { free(debugsec); debugsec = NULL; } secp = bfd_get_section_by_name(abfd, ".debug"); if (!secp) return 0; if (!(length = bfd_section_size(abfd, secp))) return 0; debugsec = (char *) xmalloc ((unsigned)length); if (debugsec == NULL) return -1; if (!bfd_get_section_contents(abfd, secp, debugsec, (file_ptr) 0, length)) { printf ("Can't read .debug section from symbol file\n"); return -1; } return 0;}static voidfree_debugsection(){ if (debugsec) free(debugsec); debugsec = NULL;}/* xcoff version of symbol file read. */static voidxcoff_symfile_read (objfile, section_offset, mainline) struct objfile *objfile; struct section_offset *section_offset; int mainline;{ int num_symbols; /* # of symbols */ file_ptr symtab_offset; /* symbol table and */ file_ptr stringtab_offset; /* string table file offsets */ int val; bfd *abfd; struct coff_symfile_info *info; char *name; info = (struct coff_symfile_info *) objfile -> sym_private; symfile_bfd = abfd = objfile->obfd; name = objfile->name; num_symbols = bfd_get_symcount (abfd); /* # of symbols */ symtab_offset = obj_sym_filepos (abfd); /* symbol table file offset */ 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); /* FIXME! This stuff should move into symfile_init */ if (info->min_lineno_offset != 0 && info->max_lineno_offset > info->min_lineno_offset) { /* only read in the line # table if one exists */ val = init_lineno(abfd, info->min_lineno_offset, (int) (info->max_lineno_offset - info->min_lineno_offset)); if (val < 0) error("\"%s\": error reading line numbers\n", name); } val = init_stringtab(abfd, stringtab_offset, objfile); if (val < 0) { error ("\"%s\": can't get string table", name); } if (init_debugsection(abfd) < 0) { error ("Error reading .debug section of `%s'\n", name); } /* Position to read the symbol table. Do not read it all at once. */ val = bfd_seek(abfd, symtab_offset, L_SET); if (val < 0) perror_with_name(name); if (bfd_tell(abfd) != symtab_offset) fatal("bfd? BFD!"); init_minimal_symbol_collection (); make_cleanup (discard_minimal_symbols, 0); /* Initialize load info structure. */ if (mainline) xcoff_init_loadinfo (); /* Now that the executable file is positioned at symbol table, process it and define symbols accordingly. */ read_xcoff_symtab(obj
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -