1*5796c8dcSSimon Schubert /* Build symbol tables in GDB's internal format. 2*5796c8dcSSimon Schubert Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1995, 1996, 3*5796c8dcSSimon Schubert 1997, 1998, 1999, 2000, 2002, 2003, 2007, 2008, 2009 4*5796c8dcSSimon Schubert Free Software Foundation, Inc. 5*5796c8dcSSimon Schubert 6*5796c8dcSSimon Schubert This file is part of GDB. 7*5796c8dcSSimon Schubert 8*5796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 9*5796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 10*5796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 11*5796c8dcSSimon Schubert (at your option) any later version. 12*5796c8dcSSimon Schubert 13*5796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 14*5796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 15*5796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16*5796c8dcSSimon Schubert GNU General Public License for more details. 17*5796c8dcSSimon Schubert 18*5796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 19*5796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 20*5796c8dcSSimon Schubert 21*5796c8dcSSimon Schubert #if !defined (BUILDSYM_H) 22*5796c8dcSSimon Schubert #define BUILDSYM_H 1 23*5796c8dcSSimon Schubert 24*5796c8dcSSimon Schubert struct objfile; 25*5796c8dcSSimon Schubert struct symbol; 26*5796c8dcSSimon Schubert struct addrmap; 27*5796c8dcSSimon Schubert 28*5796c8dcSSimon Schubert /* This module provides definitions used for creating and adding to 29*5796c8dcSSimon Schubert the symbol table. These routines are called from various symbol- 30*5796c8dcSSimon Schubert file-reading routines. 31*5796c8dcSSimon Schubert 32*5796c8dcSSimon Schubert They originated in dbxread.c of gdb-4.2, and were split out to 33*5796c8dcSSimon Schubert make xcoffread.c more maintainable by sharing code. 34*5796c8dcSSimon Schubert 35*5796c8dcSSimon Schubert Variables declared in this file can be defined by #define-ing the 36*5796c8dcSSimon Schubert name EXTERN to null. It is used to declare variables that are 37*5796c8dcSSimon Schubert normally extern, but which get defined in a single module using 38*5796c8dcSSimon Schubert this technique. */ 39*5796c8dcSSimon Schubert 40*5796c8dcSSimon Schubert struct block; 41*5796c8dcSSimon Schubert 42*5796c8dcSSimon Schubert #ifndef EXTERN 43*5796c8dcSSimon Schubert #define EXTERN extern 44*5796c8dcSSimon Schubert #endif 45*5796c8dcSSimon Schubert 46*5796c8dcSSimon Schubert #define HASHSIZE 127 /* Size of things hashed via 47*5796c8dcSSimon Schubert hashname() */ 48*5796c8dcSSimon Schubert 49*5796c8dcSSimon Schubert /* Name of source file whose symbol data we are now processing. This 50*5796c8dcSSimon Schubert comes from a symbol of type N_SO for stabs. For Dwarf it comes from the 51*5796c8dcSSimon Schubert DW_AT_name attribute of a DW_TAG_compile_unit DIE. */ 52*5796c8dcSSimon Schubert 53*5796c8dcSSimon Schubert EXTERN char *last_source_file; 54*5796c8dcSSimon Schubert 55*5796c8dcSSimon Schubert /* Core address of start of text of current source file. This too 56*5796c8dcSSimon Schubert comes from the N_SO symbol. For Dwarf it typically comes from the 57*5796c8dcSSimon Schubert DW_AT_low_pc attribute of a DW_TAG_compile_unit DIE. */ 58*5796c8dcSSimon Schubert 59*5796c8dcSSimon Schubert EXTERN CORE_ADDR last_source_start_addr; 60*5796c8dcSSimon Schubert 61*5796c8dcSSimon Schubert /* The list of sub-source-files within the current individual 62*5796c8dcSSimon Schubert compilation. Each file gets its own symtab with its own linetable 63*5796c8dcSSimon Schubert and associated info, but they all share one blockvector. */ 64*5796c8dcSSimon Schubert 65*5796c8dcSSimon Schubert struct subfile 66*5796c8dcSSimon Schubert { 67*5796c8dcSSimon Schubert struct subfile *next; 68*5796c8dcSSimon Schubert char *name; 69*5796c8dcSSimon Schubert char *dirname; 70*5796c8dcSSimon Schubert struct linetable *line_vector; 71*5796c8dcSSimon Schubert int line_vector_length; 72*5796c8dcSSimon Schubert enum language language; 73*5796c8dcSSimon Schubert char *producer; 74*5796c8dcSSimon Schubert char *debugformat; 75*5796c8dcSSimon Schubert struct symtab *symtab; 76*5796c8dcSSimon Schubert }; 77*5796c8dcSSimon Schubert 78*5796c8dcSSimon Schubert EXTERN struct subfile *current_subfile; 79*5796c8dcSSimon Schubert 80*5796c8dcSSimon Schubert /* Global variable which, when set, indicates that we are processing a 81*5796c8dcSSimon Schubert .o file compiled with gcc */ 82*5796c8dcSSimon Schubert 83*5796c8dcSSimon Schubert EXTERN unsigned char processing_gcc_compilation; 84*5796c8dcSSimon Schubert 85*5796c8dcSSimon Schubert /* When set, we are processing a .o file compiled by sun acc. This is 86*5796c8dcSSimon Schubert misnamed; it refers to all stabs-in-elf implementations which use 87*5796c8dcSSimon Schubert N_UNDF the way Sun does, including Solaris gcc. Hopefully all 88*5796c8dcSSimon Schubert stabs-in-elf implementations ever invented will choose to be 89*5796c8dcSSimon Schubert compatible. */ 90*5796c8dcSSimon Schubert 91*5796c8dcSSimon Schubert EXTERN unsigned char processing_acc_compilation; 92*5796c8dcSSimon Schubert 93*5796c8dcSSimon Schubert /* Count symbols as they are processed, for error messages. */ 94*5796c8dcSSimon Schubert 95*5796c8dcSSimon Schubert EXTERN unsigned int symnum; 96*5796c8dcSSimon Schubert 97*5796c8dcSSimon Schubert /* Record the symbols defined for each context in a list. We don't 98*5796c8dcSSimon Schubert create a struct block for the context until we know how long to 99*5796c8dcSSimon Schubert make it. */ 100*5796c8dcSSimon Schubert 101*5796c8dcSSimon Schubert #define PENDINGSIZE 100 102*5796c8dcSSimon Schubert 103*5796c8dcSSimon Schubert struct pending 104*5796c8dcSSimon Schubert { 105*5796c8dcSSimon Schubert struct pending *next; 106*5796c8dcSSimon Schubert int nsyms; 107*5796c8dcSSimon Schubert struct symbol *symbol[PENDINGSIZE]; 108*5796c8dcSSimon Schubert }; 109*5796c8dcSSimon Schubert 110*5796c8dcSSimon Schubert /* Here are the three lists that symbols are put on. */ 111*5796c8dcSSimon Schubert 112*5796c8dcSSimon Schubert /* static at top level, and types */ 113*5796c8dcSSimon Schubert 114*5796c8dcSSimon Schubert EXTERN struct pending *file_symbols; 115*5796c8dcSSimon Schubert 116*5796c8dcSSimon Schubert /* global functions and variables */ 117*5796c8dcSSimon Schubert 118*5796c8dcSSimon Schubert EXTERN struct pending *global_symbols; 119*5796c8dcSSimon Schubert 120*5796c8dcSSimon Schubert /* everything local to lexical context */ 121*5796c8dcSSimon Schubert 122*5796c8dcSSimon Schubert EXTERN struct pending *local_symbols; 123*5796c8dcSSimon Schubert 124*5796c8dcSSimon Schubert /* func params local to lexical context */ 125*5796c8dcSSimon Schubert 126*5796c8dcSSimon Schubert EXTERN struct pending *param_symbols; 127*5796c8dcSSimon Schubert 128*5796c8dcSSimon Schubert /* "using" directives local to lexical context. */ 129*5796c8dcSSimon Schubert 130*5796c8dcSSimon Schubert EXTERN struct using_direct *using_directives; 131*5796c8dcSSimon Schubert 132*5796c8dcSSimon Schubert /* Stack representing unclosed lexical contexts (that will become 133*5796c8dcSSimon Schubert blocks, eventually). */ 134*5796c8dcSSimon Schubert 135*5796c8dcSSimon Schubert struct context_stack 136*5796c8dcSSimon Schubert { 137*5796c8dcSSimon Schubert /* Outer locals at the time we entered */ 138*5796c8dcSSimon Schubert 139*5796c8dcSSimon Schubert struct pending *locals; 140*5796c8dcSSimon Schubert 141*5796c8dcSSimon Schubert /* Pending func params at the time we entered */ 142*5796c8dcSSimon Schubert 143*5796c8dcSSimon Schubert struct pending *params; 144*5796c8dcSSimon Schubert 145*5796c8dcSSimon Schubert /* Pending using directives at the time we entered. */ 146*5796c8dcSSimon Schubert 147*5796c8dcSSimon Schubert struct using_direct *using_directives; 148*5796c8dcSSimon Schubert 149*5796c8dcSSimon Schubert /* Pointer into blocklist as of entry */ 150*5796c8dcSSimon Schubert 151*5796c8dcSSimon Schubert struct pending_block *old_blocks; 152*5796c8dcSSimon Schubert 153*5796c8dcSSimon Schubert /* Name of function, if any, defining context */ 154*5796c8dcSSimon Schubert 155*5796c8dcSSimon Schubert struct symbol *name; 156*5796c8dcSSimon Schubert 157*5796c8dcSSimon Schubert /* PC where this context starts */ 158*5796c8dcSSimon Schubert 159*5796c8dcSSimon Schubert CORE_ADDR start_addr; 160*5796c8dcSSimon Schubert 161*5796c8dcSSimon Schubert /* Temp slot for exception handling. */ 162*5796c8dcSSimon Schubert 163*5796c8dcSSimon Schubert CORE_ADDR end_addr; 164*5796c8dcSSimon Schubert 165*5796c8dcSSimon Schubert /* For error-checking matching push/pop */ 166*5796c8dcSSimon Schubert 167*5796c8dcSSimon Schubert int depth; 168*5796c8dcSSimon Schubert 169*5796c8dcSSimon Schubert }; 170*5796c8dcSSimon Schubert 171*5796c8dcSSimon Schubert EXTERN struct context_stack *context_stack; 172*5796c8dcSSimon Schubert 173*5796c8dcSSimon Schubert /* Index of first unused entry in context stack. */ 174*5796c8dcSSimon Schubert 175*5796c8dcSSimon Schubert EXTERN int context_stack_depth; 176*5796c8dcSSimon Schubert 177*5796c8dcSSimon Schubert /* Currently allocated size of context stack. */ 178*5796c8dcSSimon Schubert 179*5796c8dcSSimon Schubert EXTERN int context_stack_size; 180*5796c8dcSSimon Schubert 181*5796c8dcSSimon Schubert /* Non-zero if the context stack is empty. */ 182*5796c8dcSSimon Schubert #define outermost_context_p() (context_stack_depth == 0) 183*5796c8dcSSimon Schubert 184*5796c8dcSSimon Schubert /* Nonzero if within a function (so symbols should be local, if 185*5796c8dcSSimon Schubert nothing says specifically). */ 186*5796c8dcSSimon Schubert 187*5796c8dcSSimon Schubert EXTERN int within_function; 188*5796c8dcSSimon Schubert 189*5796c8dcSSimon Schubert /* List of blocks already made (lexical contexts already closed). 190*5796c8dcSSimon Schubert This is used at the end to make the blockvector. */ 191*5796c8dcSSimon Schubert 192*5796c8dcSSimon Schubert struct pending_block 193*5796c8dcSSimon Schubert { 194*5796c8dcSSimon Schubert struct pending_block *next; 195*5796c8dcSSimon Schubert struct block *block; 196*5796c8dcSSimon Schubert }; 197*5796c8dcSSimon Schubert 198*5796c8dcSSimon Schubert /* Pointer to the head of a linked list of symbol blocks which have 199*5796c8dcSSimon Schubert already been finalized (lexical contexts already closed) and which 200*5796c8dcSSimon Schubert are just waiting to be built into a blockvector when finalizing the 201*5796c8dcSSimon Schubert associated symtab. */ 202*5796c8dcSSimon Schubert 203*5796c8dcSSimon Schubert EXTERN struct pending_block *pending_blocks; 204*5796c8dcSSimon Schubert 205*5796c8dcSSimon Schubert 206*5796c8dcSSimon Schubert struct subfile_stack 207*5796c8dcSSimon Schubert { 208*5796c8dcSSimon Schubert struct subfile_stack *next; 209*5796c8dcSSimon Schubert char *name; 210*5796c8dcSSimon Schubert }; 211*5796c8dcSSimon Schubert 212*5796c8dcSSimon Schubert EXTERN struct subfile_stack *subfile_stack; 213*5796c8dcSSimon Schubert 214*5796c8dcSSimon Schubert #define next_symbol_text(objfile) (*next_symbol_text_func)(objfile) 215*5796c8dcSSimon Schubert 216*5796c8dcSSimon Schubert /* Function to invoke get the next symbol. Return the symbol name. */ 217*5796c8dcSSimon Schubert 218*5796c8dcSSimon Schubert EXTERN char *(*next_symbol_text_func) (struct objfile *); 219*5796c8dcSSimon Schubert 220*5796c8dcSSimon Schubert /* Vector of types defined so far, indexed by their type numbers. 221*5796c8dcSSimon Schubert Used for both stabs and coff. (In newer sun systems, dbx uses a 222*5796c8dcSSimon Schubert pair of numbers in parens, as in "(SUBFILENUM,NUMWITHINSUBFILE)". 223*5796c8dcSSimon Schubert Then these numbers must be translated through the type_translations 224*5796c8dcSSimon Schubert hash table to get the index into the type vector.) */ 225*5796c8dcSSimon Schubert 226*5796c8dcSSimon Schubert EXTERN struct type **type_vector; 227*5796c8dcSSimon Schubert 228*5796c8dcSSimon Schubert /* Number of elements allocated for type_vector currently. */ 229*5796c8dcSSimon Schubert 230*5796c8dcSSimon Schubert EXTERN int type_vector_length; 231*5796c8dcSSimon Schubert 232*5796c8dcSSimon Schubert /* Initial size of type vector. Is realloc'd larger if needed, and 233*5796c8dcSSimon Schubert realloc'd down to the size actually used, when completed. */ 234*5796c8dcSSimon Schubert 235*5796c8dcSSimon Schubert #define INITIAL_TYPE_VECTOR_LENGTH 160 236*5796c8dcSSimon Schubert 237*5796c8dcSSimon Schubert extern void add_free_pendings (struct pending *list); 238*5796c8dcSSimon Schubert 239*5796c8dcSSimon Schubert extern void add_symbol_to_list (struct symbol *symbol, 240*5796c8dcSSimon Schubert struct pending **listhead); 241*5796c8dcSSimon Schubert 242*5796c8dcSSimon Schubert extern struct symbol *find_symbol_in_list (struct pending *list, 243*5796c8dcSSimon Schubert char *name, int length); 244*5796c8dcSSimon Schubert 245*5796c8dcSSimon Schubert extern struct block *finish_block (struct symbol *symbol, 246*5796c8dcSSimon Schubert struct pending **listhead, 247*5796c8dcSSimon Schubert struct pending_block *old_blocks, 248*5796c8dcSSimon Schubert CORE_ADDR start, CORE_ADDR end, 249*5796c8dcSSimon Schubert struct objfile *objfile); 250*5796c8dcSSimon Schubert 251*5796c8dcSSimon Schubert extern void record_block_range (struct block *, 252*5796c8dcSSimon Schubert CORE_ADDR start, CORE_ADDR end_inclusive); 253*5796c8dcSSimon Schubert 254*5796c8dcSSimon Schubert extern void really_free_pendings (void *dummy); 255*5796c8dcSSimon Schubert 256*5796c8dcSSimon Schubert extern void start_subfile (char *name, char *dirname); 257*5796c8dcSSimon Schubert 258*5796c8dcSSimon Schubert extern void patch_subfile_names (struct subfile *subfile, char *name); 259*5796c8dcSSimon Schubert 260*5796c8dcSSimon Schubert extern void push_subfile (void); 261*5796c8dcSSimon Schubert 262*5796c8dcSSimon Schubert extern char *pop_subfile (void); 263*5796c8dcSSimon Schubert 264*5796c8dcSSimon Schubert extern struct symtab *end_symtab (CORE_ADDR end_addr, 265*5796c8dcSSimon Schubert struct objfile *objfile, int section); 266*5796c8dcSSimon Schubert 267*5796c8dcSSimon Schubert /* Defined in stabsread.c. */ 268*5796c8dcSSimon Schubert 269*5796c8dcSSimon Schubert extern void scan_file_globals (struct objfile *objfile); 270*5796c8dcSSimon Schubert 271*5796c8dcSSimon Schubert extern void buildsym_new_init (void); 272*5796c8dcSSimon Schubert 273*5796c8dcSSimon Schubert extern void buildsym_init (void); 274*5796c8dcSSimon Schubert 275*5796c8dcSSimon Schubert extern struct context_stack *push_context (int desc, CORE_ADDR valu); 276*5796c8dcSSimon Schubert 277*5796c8dcSSimon Schubert extern struct context_stack *pop_context (void); 278*5796c8dcSSimon Schubert 279*5796c8dcSSimon Schubert extern void record_line (struct subfile *subfile, int line, CORE_ADDR pc); 280*5796c8dcSSimon Schubert 281*5796c8dcSSimon Schubert extern void start_symtab (char *name, char *dirname, CORE_ADDR start_addr); 282*5796c8dcSSimon Schubert 283*5796c8dcSSimon Schubert extern int hashname (char *name); 284*5796c8dcSSimon Schubert 285*5796c8dcSSimon Schubert extern void free_pending_blocks (void); 286*5796c8dcSSimon Schubert 287*5796c8dcSSimon Schubert /* FIXME: Note that this is used only in buildsym.c and dstread.c, 288*5796c8dcSSimon Schubert which should be fixed to not need direct access to 289*5796c8dcSSimon Schubert record_pending_block. */ 290*5796c8dcSSimon Schubert 291*5796c8dcSSimon Schubert extern void record_pending_block (struct objfile *objfile, 292*5796c8dcSSimon Schubert struct block *block, 293*5796c8dcSSimon Schubert struct pending_block *opblock); 294*5796c8dcSSimon Schubert 295*5796c8dcSSimon Schubert extern void record_debugformat (char *format); 296*5796c8dcSSimon Schubert 297*5796c8dcSSimon Schubert extern void record_producer (const char *producer); 298*5796c8dcSSimon Schubert 299*5796c8dcSSimon Schubert extern void merge_symbol_lists (struct pending **srclist, 300*5796c8dcSSimon Schubert struct pending **targetlist); 301*5796c8dcSSimon Schubert 302*5796c8dcSSimon Schubert /* The macro table for the compilation unit whose symbols we're 303*5796c8dcSSimon Schubert currently reading. All the symtabs for this CU will point to this. */ 304*5796c8dcSSimon Schubert EXTERN struct macro_table *pending_macros; 305*5796c8dcSSimon Schubert 306*5796c8dcSSimon Schubert #undef EXTERN 307*5796c8dcSSimon Schubert 308*5796c8dcSSimon Schubert #endif /* defined (BUILDSYM_H) */ 309