119370Spst/* Build symbol tables in GDB's internal format.
298944Sobrien   Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1995, 1996,
3130803Smarcel   1997, 1998, 1999, 2000, 2002, 2003 Free Software Foundation, Inc.
419370Spst
598944Sobrien   This file is part of GDB.
619370Spst
798944Sobrien   This program is free software; you can redistribute it and/or modify
898944Sobrien   it under the terms of the GNU General Public License as published by
998944Sobrien   the Free Software Foundation; either version 2 of the License, or
1098944Sobrien   (at your option) any later version.
1119370Spst
1298944Sobrien   This program is distributed in the hope that it will be useful,
1398944Sobrien   but WITHOUT ANY WARRANTY; without even the implied warranty of
1498944Sobrien   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1598944Sobrien   GNU General Public License for more details.
1619370Spst
1798944Sobrien   You should have received a copy of the GNU General Public License
1898944Sobrien   along with this program; if not, write to the Free Software
1998944Sobrien   Foundation, Inc., 59 Temple Place - Suite 330,
2098944Sobrien   Boston, MA 02111-1307, USA.  */
2119370Spst
2219370Spst#if !defined (BUILDSYM_H)
2319370Spst#define BUILDSYM_H 1
2419370Spst
25130803Smarcelstruct objfile;
26130803Smarcelstruct symbol;
27130803Smarcel
2819370Spst/* This module provides definitions used for creating and adding to
2919370Spst   the symbol table.  These routines are called from various symbol-
3046283Sdfr   file-reading routines.
3119370Spst
3219370Spst   They originated in dbxread.c of gdb-4.2, and were split out to
3319370Spst   make xcoffread.c more maintainable by sharing code.
3419370Spst
3546283Sdfr   Variables declared in this file can be defined by #define-ing the
3646283Sdfr   name EXTERN to null.  It is used to declare variables that are
3746283Sdfr   normally extern, but which get defined in a single module using
3846283Sdfr   this technique.  */
3919370Spst
40130803Smarcelstruct block;
41130803Smarcel
4219370Spst#ifndef EXTERN
4319370Spst#define	EXTERN extern
4419370Spst#endif
4519370Spst
4646283Sdfr#define HASHSIZE 127		/* Size of things hashed via
4746283Sdfr				   hashname() */
4819370Spst
4946283Sdfr/* Name of source file whose symbol data we are now processing.  This
5046283Sdfr   comes from a symbol of type N_SO. */
5119370Spst
5219370SpstEXTERN char *last_source_file;
5319370Spst
5446283Sdfr/* Core address of start of text of current source file.  This too
5546283Sdfr   comes from the N_SO symbol. */
5619370Spst
5719370SpstEXTERN CORE_ADDR last_source_start_addr;
5819370Spst
5946283Sdfr/* The list of sub-source-files within the current individual
6046283Sdfr   compilation.  Each file gets its own symtab with its own linetable
6146283Sdfr   and associated info, but they all share one blockvector.  */
6219370Spst
6319370Spststruct subfile
6446283Sdfr  {
6546283Sdfr    struct subfile *next;
6646283Sdfr    char *name;
6746283Sdfr    char *dirname;
6846283Sdfr    struct linetable *line_vector;
6946283Sdfr    int line_vector_length;
7046283Sdfr    enum language language;
7146283Sdfr    char *debugformat;
7246283Sdfr  };
7319370Spst
7419370SpstEXTERN struct subfile *subfiles;
7519370Spst
7619370SpstEXTERN struct subfile *current_subfile;
7719370Spst
7819370Spst/* Global variable which, when set, indicates that we are processing a
7919370Spst   .o file compiled with gcc */
8019370Spst
8119370SpstEXTERN unsigned char processing_gcc_compilation;
8219370Spst
8319370Spst/* When set, we are processing a .o file compiled by sun acc.  This is
8419370Spst   misnamed; it refers to all stabs-in-elf implementations which use
8519370Spst   N_UNDF the way Sun does, including Solaris gcc.  Hopefully all
8619370Spst   stabs-in-elf implementations ever invented will choose to be
8719370Spst   compatible.  */
8819370Spst
8919370SpstEXTERN unsigned char processing_acc_compilation;
9019370Spst
9119370Spst/* Count symbols as they are processed, for error messages.  */
9219370Spst
9319370SpstEXTERN unsigned int symnum;
9419370Spst
9546283Sdfr/* Record the symbols defined for each context in a list.  We don't
9646283Sdfr   create a struct block for the context until we know how long to
9746283Sdfr   make it.  */
9819370Spst
9919370Spst#define PENDINGSIZE 100
10019370Spst
10119370Spststruct pending
10246283Sdfr  {
10346283Sdfr    struct pending *next;
10446283Sdfr    int nsyms;
10546283Sdfr    struct symbol *symbol[PENDINGSIZE];
10646283Sdfr  };
10719370Spst
10846283Sdfr/* Here are the three lists that symbols are put on.  */
10919370Spst
11046283Sdfr/* static at top level, and types */
11119370Spst
11246283SdfrEXTERN struct pending *file_symbols;
11319370Spst
11446283Sdfr/* global functions and variables */
11519370Spst
11646283SdfrEXTERN struct pending *global_symbols;
11719370Spst
11846283Sdfr/* everything local to lexical context */
11919370Spst
12046283SdfrEXTERN struct pending *local_symbols;
12119370Spst
12246283Sdfr/* func params local to lexical  context */
12346283Sdfr
12446283SdfrEXTERN struct pending *param_symbols;
12546283Sdfr
12646283Sdfr/* Stack representing unclosed lexical contexts (that will become
12746283Sdfr   blocks, eventually).  */
12846283Sdfr
12919370Spststruct context_stack
13046283Sdfr  {
13146283Sdfr    /* Outer locals at the time we entered */
13219370Spst
13346283Sdfr    struct pending *locals;
13419370Spst
13546283Sdfr    /* Pending func params at the time we entered */
13619370Spst
13746283Sdfr    struct pending *params;
13819370Spst
13946283Sdfr    /* Pointer into blocklist as of entry */
14019370Spst
14146283Sdfr    struct pending_block *old_blocks;
14219370Spst
14346283Sdfr    /* Name of function, if any, defining context */
14419370Spst
14546283Sdfr    struct symbol *name;
14619370Spst
14746283Sdfr    /* PC where this context starts */
14819370Spst
14946283Sdfr    CORE_ADDR start_addr;
15019370Spst
15146283Sdfr    /* Temp slot for exception handling. */
15219370Spst
15346283Sdfr    CORE_ADDR end_addr;
15419370Spst
15546283Sdfr    /* For error-checking matching push/pop */
15619370Spst
15746283Sdfr    int depth;
15846283Sdfr
15946283Sdfr  };
16046283Sdfr
16119370SpstEXTERN struct context_stack *context_stack;
16219370Spst
16319370Spst/* Index of first unused entry in context stack.  */
16419370Spst
16519370SpstEXTERN int context_stack_depth;
16619370Spst
16719370Spst/* Currently allocated size of context stack.  */
16819370Spst
16919370SpstEXTERN int context_stack_size;
17019370Spst
171130803Smarcel/* Non-zero if the context stack is empty.  */
172130803Smarcel#define outermost_context_p() (context_stack_depth == 0)
17319370Spst
17446283Sdfr/* Nonzero if within a function (so symbols should be local, if
17546283Sdfr   nothing says specifically).  */
17619370Spst
17719370SpstEXTERN int within_function;
17819370Spst
17919370Spst/* List of blocks already made (lexical contexts already closed).
18019370Spst   This is used at the end to make the blockvector.  */
18119370Spst
18219370Spststruct pending_block
18346283Sdfr  {
18446283Sdfr    struct pending_block *next;
18546283Sdfr    struct block *block;
18646283Sdfr  };
18719370Spst
18846283Sdfr/* Pointer to the head of a linked list of symbol blocks which have
18946283Sdfr   already been finalized (lexical contexts already closed) and which
19046283Sdfr   are just waiting to be built into a blockvector when finalizing the
19146283Sdfr   associated symtab. */
19246283Sdfr
19319370SpstEXTERN struct pending_block *pending_blocks;
19446283Sdfr
19519370Spst
19619370Spststruct subfile_stack
19746283Sdfr  {
19846283Sdfr    struct subfile_stack *next;
19946283Sdfr    char *name;
20046283Sdfr  };
20119370Spst
20219370SpstEXTERN struct subfile_stack *subfile_stack;
20319370Spst
20419370Spst#define next_symbol_text(objfile) (*next_symbol_text_func)(objfile)
20519370Spst
20619370Spst/* Function to invoke get the next symbol.  Return the symbol name. */
20719370Spst
20846283SdfrEXTERN char *(*next_symbol_text_func) (struct objfile *);
20919370Spst
21019370Spst/* Vector of types defined so far, indexed by their type numbers.
21146283Sdfr   Used for both stabs and coff.  (In newer sun systems, dbx uses a
21246283Sdfr   pair of numbers in parens, as in "(SUBFILENUM,NUMWITHINSUBFILE)".
21346283Sdfr   Then these numbers must be translated through the type_translations
21446283Sdfr   hash table to get the index into the type vector.)  */
21519370Spst
21619370SpstEXTERN struct type **type_vector;
21719370Spst
21819370Spst/* Number of elements allocated for type_vector currently.  */
21919370Spst
22019370SpstEXTERN int type_vector_length;
22119370Spst
22246283Sdfr/* Initial size of type vector.  Is realloc'd larger if needed, and
22346283Sdfr   realloc'd down to the size actually used, when completed.  */
22419370Spst
22519370Spst#define	INITIAL_TYPE_VECTOR_LENGTH	160
22619370Spst
22798944Sobrienextern void add_free_pendings (struct pending *list);
22898944Sobrien
22946283Sdfrextern void add_symbol_to_list (struct symbol *symbol,
23046283Sdfr				struct pending **listhead);
23119370Spst
23246283Sdfrextern struct symbol *find_symbol_in_list (struct pending *list,
23346283Sdfr					   char *name, int length);
23419370Spst
23546283Sdfrextern void finish_block (struct symbol *symbol,
23646283Sdfr			  struct pending **listhead,
23746283Sdfr			  struct pending_block *old_blocks,
23846283Sdfr			  CORE_ADDR start, CORE_ADDR end,
23946283Sdfr			  struct objfile *objfile);
24019370Spst
241130803Smarcelextern void really_free_pendings (void *dummy);
24219370Spst
24346283Sdfrextern void start_subfile (char *name, char *dirname);
24419370Spst
24546283Sdfrextern void patch_subfile_names (struct subfile *subfile, char *name);
24619370Spst
24746283Sdfrextern void push_subfile (void);
24819370Spst
24946283Sdfrextern char *pop_subfile (void);
25019370Spst
25146283Sdfrextern struct symtab *end_symtab (CORE_ADDR end_addr,
25246283Sdfr				  struct objfile *objfile, int section);
25319370Spst
25446283Sdfr/* Defined in stabsread.c.  */
25519370Spst
25646283Sdfrextern void scan_file_globals (struct objfile *objfile);
25719370Spst
25846283Sdfrextern void buildsym_new_init (void);
25919370Spst
26046283Sdfrextern void buildsym_init (void);
26119370Spst
26246283Sdfrextern struct context_stack *push_context (int desc, CORE_ADDR valu);
26319370Spst
264130803Smarcelextern struct context_stack *pop_context (void);
265130803Smarcel
26646283Sdfrextern void record_line (struct subfile *subfile, int line, CORE_ADDR pc);
26719370Spst
26846283Sdfrextern void start_symtab (char *name, char *dirname, CORE_ADDR start_addr);
26919370Spst
27046283Sdfrextern int hashname (char *name);
27146283Sdfr
27246283Sdfrextern void free_pending_blocks (void);
27346283Sdfr
27446283Sdfr/* FIXME: Note that this is used only in buildsym.c and dstread.c,
27546283Sdfr   which should be fixed to not need direct access to
27646283Sdfr   record_pending_block. */
27746283Sdfr
27846283Sdfrextern void record_pending_block (struct objfile *objfile,
27946283Sdfr				  struct block *block,
28046283Sdfr				  struct pending_block *opblock);
28146283Sdfr
28246283Sdfrextern void record_debugformat (char *format);
28346283Sdfr
28446283Sdfrextern void merge_symbol_lists (struct pending **srclist,
28546283Sdfr				struct pending **targetlist);
28646283Sdfr
287130803Smarcel/* The macro table for the compilation unit whose symbols we're
288130803Smarcel   currently reading.  All the symtabs for this CU will point to this.  */
289130803SmarcelEXTERN struct macro_table *pending_macros;
290130803Smarcel
29119370Spst#undef EXTERN
29219370Spst
29346283Sdfr#endif /* defined (BUILDSYM_H) */
294