15796c8dcSSimon Schubert /* Build symbol tables in GDB's internal format. 2*ef5ccd6cSJohn Marino Copyright (C) 1986-2013 Free Software Foundation, Inc. 35796c8dcSSimon Schubert 45796c8dcSSimon Schubert This file is part of GDB. 55796c8dcSSimon Schubert 65796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 75796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 85796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 95796c8dcSSimon Schubert (at your option) any later version. 105796c8dcSSimon Schubert 115796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 125796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 135796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 145796c8dcSSimon Schubert GNU General Public License for more details. 155796c8dcSSimon Schubert 165796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 175796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 185796c8dcSSimon Schubert 195796c8dcSSimon Schubert #if !defined (BUILDSYM_H) 205796c8dcSSimon Schubert #define BUILDSYM_H 1 215796c8dcSSimon Schubert 225796c8dcSSimon Schubert struct objfile; 235796c8dcSSimon Schubert struct symbol; 245796c8dcSSimon Schubert struct addrmap; 255796c8dcSSimon Schubert 265796c8dcSSimon Schubert /* This module provides definitions used for creating and adding to 275796c8dcSSimon Schubert the symbol table. These routines are called from various symbol- 285796c8dcSSimon Schubert file-reading routines. 295796c8dcSSimon Schubert 305796c8dcSSimon Schubert They originated in dbxread.c of gdb-4.2, and were split out to 315796c8dcSSimon Schubert make xcoffread.c more maintainable by sharing code. 325796c8dcSSimon Schubert 335796c8dcSSimon Schubert Variables declared in this file can be defined by #define-ing the 345796c8dcSSimon Schubert name EXTERN to null. It is used to declare variables that are 355796c8dcSSimon Schubert normally extern, but which get defined in a single module using 365796c8dcSSimon Schubert this technique. */ 375796c8dcSSimon Schubert 385796c8dcSSimon Schubert struct block; 39*ef5ccd6cSJohn Marino struct pending_block; 405796c8dcSSimon Schubert 415796c8dcSSimon Schubert #ifndef EXTERN 425796c8dcSSimon Schubert #define EXTERN extern 435796c8dcSSimon Schubert #endif 445796c8dcSSimon Schubert 455796c8dcSSimon Schubert #define HASHSIZE 127 /* Size of things hashed via 46c50c785cSJohn Marino hashname(). */ 475796c8dcSSimon Schubert 485796c8dcSSimon Schubert /* Core address of start of text of current source file. This too 495796c8dcSSimon Schubert comes from the N_SO symbol. For Dwarf it typically comes from the 505796c8dcSSimon Schubert DW_AT_low_pc attribute of a DW_TAG_compile_unit DIE. */ 515796c8dcSSimon Schubert 525796c8dcSSimon Schubert EXTERN CORE_ADDR last_source_start_addr; 535796c8dcSSimon Schubert 545796c8dcSSimon Schubert /* The list of sub-source-files within the current individual 555796c8dcSSimon Schubert compilation. Each file gets its own symtab with its own linetable 565796c8dcSSimon Schubert and associated info, but they all share one blockvector. */ 575796c8dcSSimon Schubert 585796c8dcSSimon Schubert struct subfile 595796c8dcSSimon Schubert { 605796c8dcSSimon Schubert struct subfile *next; 615796c8dcSSimon Schubert char *name; 625796c8dcSSimon Schubert char *dirname; 635796c8dcSSimon Schubert struct linetable *line_vector; 645796c8dcSSimon Schubert int line_vector_length; 655796c8dcSSimon Schubert enum language language; 66a45ae5f8SJohn Marino const char *producer; 67a45ae5f8SJohn Marino const char *debugformat; 685796c8dcSSimon Schubert struct symtab *symtab; 695796c8dcSSimon Schubert }; 705796c8dcSSimon Schubert 715796c8dcSSimon Schubert EXTERN struct subfile *current_subfile; 725796c8dcSSimon Schubert 735796c8dcSSimon Schubert /* Global variable which, when set, indicates that we are processing a 745796c8dcSSimon Schubert .o file compiled with gcc */ 755796c8dcSSimon Schubert 765796c8dcSSimon Schubert EXTERN unsigned char processing_gcc_compilation; 775796c8dcSSimon Schubert 785796c8dcSSimon Schubert /* When set, we are processing a .o file compiled by sun acc. This is 795796c8dcSSimon Schubert misnamed; it refers to all stabs-in-elf implementations which use 805796c8dcSSimon Schubert N_UNDF the way Sun does, including Solaris gcc. Hopefully all 815796c8dcSSimon Schubert stabs-in-elf implementations ever invented will choose to be 825796c8dcSSimon Schubert compatible. */ 835796c8dcSSimon Schubert 845796c8dcSSimon Schubert EXTERN unsigned char processing_acc_compilation; 855796c8dcSSimon Schubert 865796c8dcSSimon Schubert /* Count symbols as they are processed, for error messages. */ 875796c8dcSSimon Schubert 885796c8dcSSimon Schubert EXTERN unsigned int symnum; 895796c8dcSSimon Schubert 905796c8dcSSimon Schubert /* Record the symbols defined for each context in a list. We don't 915796c8dcSSimon Schubert create a struct block for the context until we know how long to 925796c8dcSSimon Schubert make it. */ 935796c8dcSSimon Schubert 945796c8dcSSimon Schubert #define PENDINGSIZE 100 955796c8dcSSimon Schubert 965796c8dcSSimon Schubert struct pending 975796c8dcSSimon Schubert { 985796c8dcSSimon Schubert struct pending *next; 995796c8dcSSimon Schubert int nsyms; 1005796c8dcSSimon Schubert struct symbol *symbol[PENDINGSIZE]; 1015796c8dcSSimon Schubert }; 1025796c8dcSSimon Schubert 1035796c8dcSSimon Schubert /* Here are the three lists that symbols are put on. */ 1045796c8dcSSimon Schubert 1055796c8dcSSimon Schubert /* static at top level, and types */ 1065796c8dcSSimon Schubert 1075796c8dcSSimon Schubert EXTERN struct pending *file_symbols; 1085796c8dcSSimon Schubert 1095796c8dcSSimon Schubert /* global functions and variables */ 1105796c8dcSSimon Schubert 1115796c8dcSSimon Schubert EXTERN struct pending *global_symbols; 1125796c8dcSSimon Schubert 1135796c8dcSSimon Schubert /* everything local to lexical context */ 1145796c8dcSSimon Schubert 1155796c8dcSSimon Schubert EXTERN struct pending *local_symbols; 1165796c8dcSSimon Schubert 1175796c8dcSSimon Schubert /* "using" directives local to lexical context. */ 1185796c8dcSSimon Schubert 1195796c8dcSSimon Schubert EXTERN struct using_direct *using_directives; 1205796c8dcSSimon Schubert 1215796c8dcSSimon Schubert /* Stack representing unclosed lexical contexts (that will become 1225796c8dcSSimon Schubert blocks, eventually). */ 1235796c8dcSSimon Schubert 1245796c8dcSSimon Schubert struct context_stack 1255796c8dcSSimon Schubert { 1265796c8dcSSimon Schubert /* Outer locals at the time we entered */ 1275796c8dcSSimon Schubert 1285796c8dcSSimon Schubert struct pending *locals; 1295796c8dcSSimon Schubert 1305796c8dcSSimon Schubert /* Pending using directives at the time we entered. */ 1315796c8dcSSimon Schubert 1325796c8dcSSimon Schubert struct using_direct *using_directives; 1335796c8dcSSimon Schubert 1345796c8dcSSimon Schubert /* Pointer into blocklist as of entry */ 1355796c8dcSSimon Schubert 1365796c8dcSSimon Schubert struct pending_block *old_blocks; 1375796c8dcSSimon Schubert 1385796c8dcSSimon Schubert /* Name of function, if any, defining context */ 1395796c8dcSSimon Schubert 1405796c8dcSSimon Schubert struct symbol *name; 1415796c8dcSSimon Schubert 1425796c8dcSSimon Schubert /* PC where this context starts */ 1435796c8dcSSimon Schubert 1445796c8dcSSimon Schubert CORE_ADDR start_addr; 1455796c8dcSSimon Schubert 1465796c8dcSSimon Schubert /* Temp slot for exception handling. */ 1475796c8dcSSimon Schubert 1485796c8dcSSimon Schubert CORE_ADDR end_addr; 1495796c8dcSSimon Schubert 1505796c8dcSSimon Schubert /* For error-checking matching push/pop */ 1515796c8dcSSimon Schubert 1525796c8dcSSimon Schubert int depth; 1535796c8dcSSimon Schubert 1545796c8dcSSimon Schubert }; 1555796c8dcSSimon Schubert 1565796c8dcSSimon Schubert EXTERN struct context_stack *context_stack; 1575796c8dcSSimon Schubert 1585796c8dcSSimon Schubert /* Index of first unused entry in context stack. */ 1595796c8dcSSimon Schubert 1605796c8dcSSimon Schubert EXTERN int context_stack_depth; 1615796c8dcSSimon Schubert 1625796c8dcSSimon Schubert /* Currently allocated size of context stack. */ 1635796c8dcSSimon Schubert 1645796c8dcSSimon Schubert EXTERN int context_stack_size; 1655796c8dcSSimon Schubert 1665796c8dcSSimon Schubert /* Non-zero if the context stack is empty. */ 1675796c8dcSSimon Schubert #define outermost_context_p() (context_stack_depth == 0) 1685796c8dcSSimon Schubert 1695796c8dcSSimon Schubert /* Nonzero if within a function (so symbols should be local, if 1705796c8dcSSimon Schubert nothing says specifically). */ 1715796c8dcSSimon Schubert 1725796c8dcSSimon Schubert EXTERN int within_function; 1735796c8dcSSimon Schubert 1745796c8dcSSimon Schubert 1755796c8dcSSimon Schubert 1765796c8dcSSimon Schubert struct subfile_stack 1775796c8dcSSimon Schubert { 1785796c8dcSSimon Schubert struct subfile_stack *next; 1795796c8dcSSimon Schubert char *name; 1805796c8dcSSimon Schubert }; 1815796c8dcSSimon Schubert 1825796c8dcSSimon Schubert EXTERN struct subfile_stack *subfile_stack; 1835796c8dcSSimon Schubert 1845796c8dcSSimon Schubert #define next_symbol_text(objfile) (*next_symbol_text_func)(objfile) 1855796c8dcSSimon Schubert 1865796c8dcSSimon Schubert /* Function to invoke get the next symbol. Return the symbol name. */ 1875796c8dcSSimon Schubert 1885796c8dcSSimon Schubert EXTERN char *(*next_symbol_text_func) (struct objfile *); 1895796c8dcSSimon Schubert 1905796c8dcSSimon Schubert /* Vector of types defined so far, indexed by their type numbers. 1915796c8dcSSimon Schubert Used for both stabs and coff. (In newer sun systems, dbx uses a 1925796c8dcSSimon Schubert pair of numbers in parens, as in "(SUBFILENUM,NUMWITHINSUBFILE)". 1935796c8dcSSimon Schubert Then these numbers must be translated through the type_translations 1945796c8dcSSimon Schubert hash table to get the index into the type vector.) */ 1955796c8dcSSimon Schubert 1965796c8dcSSimon Schubert EXTERN struct type **type_vector; 1975796c8dcSSimon Schubert 1985796c8dcSSimon Schubert /* Number of elements allocated for type_vector currently. */ 1995796c8dcSSimon Schubert 2005796c8dcSSimon Schubert EXTERN int type_vector_length; 2015796c8dcSSimon Schubert 2025796c8dcSSimon Schubert /* Initial size of type vector. Is realloc'd larger if needed, and 2035796c8dcSSimon Schubert realloc'd down to the size actually used, when completed. */ 2045796c8dcSSimon Schubert 2055796c8dcSSimon Schubert #define INITIAL_TYPE_VECTOR_LENGTH 160 2065796c8dcSSimon Schubert 2075796c8dcSSimon Schubert extern void add_symbol_to_list (struct symbol *symbol, 2085796c8dcSSimon Schubert struct pending **listhead); 2095796c8dcSSimon Schubert 2105796c8dcSSimon Schubert extern struct symbol *find_symbol_in_list (struct pending *list, 2115796c8dcSSimon Schubert char *name, int length); 2125796c8dcSSimon Schubert 2135796c8dcSSimon Schubert extern struct block *finish_block (struct symbol *symbol, 2145796c8dcSSimon Schubert struct pending **listhead, 2155796c8dcSSimon Schubert struct pending_block *old_blocks, 2165796c8dcSSimon Schubert CORE_ADDR start, CORE_ADDR end, 2175796c8dcSSimon Schubert struct objfile *objfile); 2185796c8dcSSimon Schubert 2195796c8dcSSimon Schubert extern void record_block_range (struct block *, 2205796c8dcSSimon Schubert CORE_ADDR start, CORE_ADDR end_inclusive); 2215796c8dcSSimon Schubert 2225796c8dcSSimon Schubert extern void really_free_pendings (void *dummy); 2235796c8dcSSimon Schubert 224c50c785cSJohn Marino extern void start_subfile (const char *name, const char *dirname); 2255796c8dcSSimon Schubert 2265796c8dcSSimon Schubert extern void patch_subfile_names (struct subfile *subfile, char *name); 2275796c8dcSSimon Schubert 2285796c8dcSSimon Schubert extern void push_subfile (void); 2295796c8dcSSimon Schubert 2305796c8dcSSimon Schubert extern char *pop_subfile (void); 2315796c8dcSSimon Schubert 232*ef5ccd6cSJohn Marino extern struct block *end_symtab_get_static_block (CORE_ADDR end_addr, 233*ef5ccd6cSJohn Marino struct objfile *objfile, 234*ef5ccd6cSJohn Marino int expandable, 235*ef5ccd6cSJohn Marino int required); 236*ef5ccd6cSJohn Marino 237*ef5ccd6cSJohn Marino extern struct symtab *end_symtab_from_static_block (struct block *static_block, 238*ef5ccd6cSJohn Marino struct objfile *objfile, 239*ef5ccd6cSJohn Marino int section, 240*ef5ccd6cSJohn Marino int expandable); 241*ef5ccd6cSJohn Marino 2425796c8dcSSimon Schubert extern struct symtab *end_symtab (CORE_ADDR end_addr, 2435796c8dcSSimon Schubert struct objfile *objfile, int section); 2445796c8dcSSimon Schubert 245*ef5ccd6cSJohn Marino extern struct symtab *end_expandable_symtab (CORE_ADDR end_addr, 246*ef5ccd6cSJohn Marino struct objfile *objfile, 247*ef5ccd6cSJohn Marino int section); 248*ef5ccd6cSJohn Marino 249*ef5ccd6cSJohn Marino extern void augment_type_symtab (struct objfile *objfile, 250*ef5ccd6cSJohn Marino struct symtab *primary_symtab); 251*ef5ccd6cSJohn Marino 2525796c8dcSSimon Schubert /* Defined in stabsread.c. */ 2535796c8dcSSimon Schubert 2545796c8dcSSimon Schubert extern void scan_file_globals (struct objfile *objfile); 2555796c8dcSSimon Schubert 2565796c8dcSSimon Schubert extern void buildsym_new_init (void); 2575796c8dcSSimon Schubert 2585796c8dcSSimon Schubert extern void buildsym_init (void); 2595796c8dcSSimon Schubert 2605796c8dcSSimon Schubert extern struct context_stack *push_context (int desc, CORE_ADDR valu); 2615796c8dcSSimon Schubert 2625796c8dcSSimon Schubert extern struct context_stack *pop_context (void); 2635796c8dcSSimon Schubert 2645796c8dcSSimon Schubert extern void record_line (struct subfile *subfile, int line, CORE_ADDR pc); 2655796c8dcSSimon Schubert 266*ef5ccd6cSJohn Marino extern void start_symtab (const char *name, const char *dirname, 267*ef5ccd6cSJohn Marino CORE_ADDR start_addr); 2685796c8dcSSimon Schubert 269*ef5ccd6cSJohn Marino extern void restart_symtab (CORE_ADDR start_addr); 270*ef5ccd6cSJohn Marino 271*ef5ccd6cSJohn Marino extern int hashname (const char *name); 2725796c8dcSSimon Schubert 2735796c8dcSSimon Schubert extern void free_pending_blocks (void); 2745796c8dcSSimon Schubert 275a45ae5f8SJohn Marino /* Record the name of the debug format in the current pending symbol 276a45ae5f8SJohn Marino table. FORMAT must be a string with a lifetime at least as long as 277a45ae5f8SJohn Marino the symtab's objfile. */ 278a45ae5f8SJohn Marino 279a45ae5f8SJohn Marino extern void record_debugformat (const char *format); 280a45ae5f8SJohn Marino 281a45ae5f8SJohn Marino /* Record the name of the debuginfo producer (usually the compiler) in 282a45ae5f8SJohn Marino the current pending symbol table. PRODUCER must be a string with a 283a45ae5f8SJohn Marino lifetime at least as long as the symtab's objfile. */ 2845796c8dcSSimon Schubert 2855796c8dcSSimon Schubert extern void record_producer (const char *producer); 2865796c8dcSSimon Schubert 2875796c8dcSSimon Schubert extern void merge_symbol_lists (struct pending **srclist, 2885796c8dcSSimon Schubert struct pending **targetlist); 2895796c8dcSSimon Schubert 290*ef5ccd6cSJohn Marino /* Set the name of the last source file. NAME is copied by this 291*ef5ccd6cSJohn Marino function. */ 292*ef5ccd6cSJohn Marino 293*ef5ccd6cSJohn Marino extern void set_last_source_file (const char *name); 294*ef5ccd6cSJohn Marino 295*ef5ccd6cSJohn Marino /* Fetch the name of the last source file. */ 296*ef5ccd6cSJohn Marino 297*ef5ccd6cSJohn Marino extern const char *get_last_source_file (void); 298*ef5ccd6cSJohn Marino 2995796c8dcSSimon Schubert /* The macro table for the compilation unit whose symbols we're 300c50c785cSJohn Marino currently reading. All the symtabs for this CU will point to 301c50c785cSJohn Marino this. */ 3025796c8dcSSimon Schubert EXTERN struct macro_table *pending_macros; 3035796c8dcSSimon Schubert 3045796c8dcSSimon Schubert #undef EXTERN 3055796c8dcSSimon Schubert 3065796c8dcSSimon Schubert #endif /* defined (BUILDSYM_H) */ 307