Fix issues with multiple inferiors
[deliverable/binutils-gdb.git] / gdb / buildsym.h
index e9d33a81df21f6c48ec48b2c80232778ae68a40c..1e57fe471120a57ed10657a4d0c93ddc2f460a49 100644 (file)
 /* Build symbol tables in GDB's internal format.
-   Copyright (C) 1986-1991 Free Software Foundation, Inc.
+   Copyright (C) 1986-2020 Free Software Foundation, Inc.
+   Copyright (C) 2019-2020 Advanced Micro Devices, Inc. All rights reserved.
 
-This file is part of GDB.
+   This file is part of GDB.
 
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
 
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#if !defined (BUILDSYM_H)
+#define BUILDSYM_H 1
+
+#include "gdb_obstack.h"
+
+struct objfile;
+struct symbol;
+struct addrmap;
+struct compunit_symtab;
+enum language;
 
 /* This module provides definitions used for creating and adding to
    the symbol table.  These routines are called from various symbol-
-   file-reading routines.  
+   file-reading routines.
 
    They originated in dbxread.c of gdb-4.2, and were split out to
-   make xcoffread.c more maintainable by sharing code.
-
-   Variables declared in this file can be defined by #define-ing
-   the name EXTERN to null.  It is used to declare variables that
-   are normally extern, but which get defined in a single module
-   using this technique.  */
-
-#ifndef EXTERN
-#define        EXTERN  extern
-#endif
-
-extern void add_symbol_to_list ();
-struct symbol *find_symbol_in_list ();
-extern void read_type_number ();
-extern struct type *read_type ();
-extern struct type *read_range_type ();
-extern struct type *read_enum_type ();
-extern struct type *read_struct_type ();
-extern struct type *read_array_type ();
-extern struct type **read_args ();
-extern struct type **dbx_lookup_type ();
-extern long read_number ();
-extern void finish_block ();
-extern struct blockvector *make_blockvector ();
-extern void add_undefined_type ();
-extern void really_free_pendings ();
-extern void start_subfile ();
-extern void push_subfile ();
-extern char *pop_subfile ();
-extern struct symtab *end_symtab ();
-extern void scan_file_globals ();
-extern void buildsym_new_init ();
-extern void buildsym_init ();
-extern struct context_stack *push_context ();
-extern void record_line ();
-extern void start_symtab ();
-extern struct symbol *define_symbol ();
-extern struct partial_symtab *start_psymtab ();
-extern void end_psymtab();
-
-
-/* Convert stab register number (from `r' declaration) to a gdb REGNUM.  */
-
-#ifndef STAB_REG_TO_REGNUM
-#define STAB_REG_TO_REGNUM(VALUE) (VALUE)
-#endif
-\f
-/* Name of source file whose symbol data we are now processing.
-   This comes from a symbol of type N_SO.  */
-
-EXTERN char *last_source_file;
+   make xcoffread.c more maintainable by sharing code.  */
 
-/* Core address of start of text of current source file.
-   This too comes from the N_SO symbol.  */
+struct block;
+struct pending_block;
 
-EXTERN CORE_ADDR last_source_start_addr;
+struct dynamic_prop;
 
-/* The list of sub-source-files within the current individual compilation.
-   Each file gets its own symtab with its own linetable and associated info,
-   but they all share one blockvector.  */
+/* The list of sub-source-files within the current individual
+   compilation.  Each file gets its own symtab with its own linetable
+   and associated info, but they all share one blockvector.  */
 
 struct subfile
 {
   struct subfile *next;
+  /* Space for this is malloc'd.  */
   char *name;
-  char *dirname;
+  /* Space for this is malloc'd.  */
   struct linetable *line_vector;
   int line_vector_length;
+  /* The "containing" compunit.  */
+  struct buildsym_compunit *buildsym_compunit;
+  enum language language;
+  struct symtab *symtab;
 };
 
-EXTERN struct subfile *subfiles;
+/* Record the symbols defined for each context in a list.  We don't
+   create a struct block for the context until we know how long to
+   make it.  */
+
+#define PENDINGSIZE 100
+
+struct pending
+  {
+    struct pending *next;
+    int nsyms;
+    struct symbol *symbol[PENDINGSIZE];
+  };
 
-EXTERN struct subfile *current_subfile;
+/* Stack representing unclosed lexical contexts (that will become
+   blocks, eventually).  */
 
-/* Global variable which, when set, indicates that we are processing a
-   .o file compiled with gcc */
+struct context_stack
+  {
+    /* Outer locals at the time we entered */
 
-EXTERN unsigned char processing_gcc_compilation;
+    struct pending *locals;
 
-/* Count symbols as they are processed, for error messages.  */
+    /* Pending using directives at the time we entered.  */
 
-EXTERN unsigned int symnum;
+    struct using_direct *local_using_directives;
 
-/* Vector of types defined so far, indexed by their dbx type numbers.
-   (In newer sun systems, dbx uses a pair of numbers in parens,
-    as in "(SUBFILENUM,NUMWITHINSUBFILE)".  Then these numbers must be
-    translated through the type_translations hash table to get
-    the index into the type vector.)  */
+    /* Pointer into blocklist as of entry */
 
-EXTERN struct type **type_vector;
+    struct pending_block *old_blocks;
 
-/* Number of elements allocated for type_vector currently.  */
+    /* Name of function, if any, defining context */
 
-EXTERN int type_vector_length;
+    struct symbol *name;
 
-/* Hash table of global symbols whose values are not known yet.
-   They are chained thru the SYMBOL_VALUE_CHAIN, since we don't
-   have the correct data for that slot yet.  */
-/* The use of the LOC_BLOCK code in this chain is nonstandard--
-   it refers to a FORTRAN common block rather than the usual meaning.  */
+    /* Expression that computes the frame base of the lexically enclosing
+       function, if any.  NULL otherwise.  */
 
-#define HASHSIZE 127
-EXTERN struct symbol *global_sym_chain[HASHSIZE];
+    struct dynamic_prop *static_link;
 
-/* Record the symbols defined for each context in a list.
-   We don't create a struct block for the context until we
-   know how long to make it.  */
+    /* PC where this context starts */
 
-#define PENDINGSIZE 100
+    CORE_ADDR start_addr;
 
-struct pending
+    /* Temp slot for exception handling.  */
+
+    CORE_ADDR end_addr;
+
+    /* For error-checking matching push/pop */
+
+    int depth;
+
+  };
+
+/* Buildsym's counterpart to struct compunit_symtab.  */
+
+struct buildsym_compunit
 {
-  struct pending *next;
-  int nsyms;
-  struct symbol *symbol[PENDINGSIZE];
-};
+  /* Start recording information about a primary source file (IOW, not an
+     included source file).
+     COMP_DIR is the directory in which the compilation unit was compiled
+     (or NULL if not known).  */
+
+  buildsym_compunit (struct objfile *objfile_, const char *name,
+                    const char *comp_dir_, enum language language_,
+                    CORE_ADDR last_addr);
+
+  /* Reopen an existing compunit_symtab so that additional symbols can
+     be added to it.  Arguments are as for the main constructor.  CUST
+     is the expandable compunit_symtab to be reopened.  */
+
+  buildsym_compunit (struct objfile *objfile_, const char *name,
+                    const char *comp_dir_, enum language language_,
+                    CORE_ADDR last_addr, struct compunit_symtab *cust)
+    : m_objfile (objfile_),
+      m_last_source_file (name == nullptr ? nullptr : xstrdup (name)),
+      m_comp_dir (comp_dir_ == nullptr ? nullptr : xstrdup (comp_dir_)),
+      m_compunit_symtab (cust),
+      m_language (language_),
+      m_last_source_start_addr (last_addr)
+  {
+  }
+
+  ~buildsym_compunit ();
+
+  DISABLE_COPY_AND_ASSIGN (buildsym_compunit);
+
+  void set_last_source_file (const char *name)
+  {
+    char *new_name = name == NULL ? NULL : xstrdup (name);
+    m_last_source_file.reset (new_name);
+  }
+
+  const char *get_last_source_file ()
+  {
+    return m_last_source_file.get ();
+  }
+
+  struct macro_table *get_macro_table ();
+
+  struct macro_table *release_macros ()
+  {
+    struct macro_table *result = m_pending_macros;
+    m_pending_macros = nullptr;
+    return result;
+  }
+
+  /* This function is called to discard any pending blocks.  */
+
+  void free_pending_blocks ()
+  {
+    m_pending_block_obstack.clear ();
+    m_pending_blocks = nullptr;
+  }
+
+  struct block *finish_block (struct symbol *symbol,
+                             struct pending_block *old_blocks,
+                             const struct dynamic_prop *static_link,
+                             CORE_ADDR start, CORE_ADDR end);
+
+  void record_block_range (struct block *block,
+                          CORE_ADDR start, CORE_ADDR end_inclusive);
+
+  void start_subfile (const char *name);
+
+  void patch_subfile_names (struct subfile *subfile, const char *name);
+
+  void push_subfile ();
 
-/* List of free `struct pending' structures for reuse.  */
-EXTERN struct pending *free_pendings;
+  const char *pop_subfile ();
 
-/* Here are the three lists that symbols are put on.  */
+  void record_line (struct subfile *subfile, int line, CORE_ADDR pc);
 
-EXTERN struct pending *file_symbols;   /* static at top level, and types */
+  struct compunit_symtab *get_compunit_symtab ()
+  {
+    return m_compunit_symtab;
+  }
+
+  void set_last_source_start_addr (CORE_ADDR addr)
+  {
+    m_last_source_start_addr = addr;
+  }
 
-EXTERN struct pending *global_symbols; /* global functions and variables */
+  CORE_ADDR get_last_source_start_addr ()
+  {
+    return m_last_source_start_addr;
+  }
 
-EXTERN struct pending *local_symbols;  /* everything local to lexic context */
+  struct using_direct **get_local_using_directives ()
+  {
+    return &m_local_using_directives;
+  }
 
-/* Kludge for xcoffread.c */
-struct pending_stabs {
-  int  count, length;
-  char *stab[1];
-};
+  void set_local_using_directives (struct using_direct *new_local)
+  {
+    m_local_using_directives = new_local;
+  }
 
-EXTERN struct pending_stabs *global_stabs;
-EXTERN struct pending_stabs *file_stabs;
+  struct using_direct **get_global_using_directives ()
+  {
+    return &m_global_using_directives;
+  }
 
-/* List of symbols declared since the last BCOMM.  This list is a tail
-   of local_symbols.  When ECOMM is seen, the symbols on the list
-   are noted so their proper addresses can be filled in later,
-   using the common block base address gotten from the assembler
-   stabs.  */
+  bool outermost_context_p () const
+  {
+    return m_context_stack.empty ();
+  }
 
-EXTERN struct pending *common_block;
-EXTERN int common_block_i;
+  struct context_stack *get_current_context_stack ()
+  {
+    if (m_context_stack.empty ())
+      return nullptr;
+    return &m_context_stack.back ();
+  }
 
-/* Stack representing unclosed lexical contexts
-   (that will become blocks, eventually).  */
+  int get_context_stack_depth () const
+  {
+    return m_context_stack.size ();
+  }
 
-struct context_stack
-{
-  struct pending *locals;      /* Outer locals at the time we entered */
-  struct pending_block *old_blocks; /* Pointer into blocklist as of entry */
-  struct symbol *name;         /* Name of function, if any, defining context*/
-  CORE_ADDR start_addr;                /* PC where this context starts */
-  CORE_ADDR end_addr;          /* Temp slot for exception handling. */
-  int depth;                   /* For error-checking matching push/pop */
-};
+  struct subfile *get_current_subfile ()
+  {
+    return m_current_subfile;
+  }
 
-EXTERN struct context_stack *context_stack;
+  struct pending **get_local_symbols ()
+  {
+    return &m_local_symbols;
+  }
 
-/* Index of first unused entry in context stack.  */
-EXTERN int context_stack_depth;
+  struct pending **get_file_symbols ()
+  {
+    return &m_file_symbols;
+  }
 
-/* Currently allocated size of context stack.  */
+  struct pending **get_global_symbols ()
+  {
+    return &m_global_symbols;
+  }
 
-EXTERN int context_stack_size;
+  void record_debugformat (const char *format)
+  {
+    m_debugformat = make_unique_xstrdup (format);
+  }
 
-/* Macro "function" for popping contexts from the stack.  Pushing is done
-   by a real function, push_context.  This returns a pointer to a struct
-   context_stack.  */
+  void record_producer (const char *producer)
+  {
+    m_producer = producer;
+  }
 
-#define        pop_context()   \
-      (&context_stack[--context_stack_depth]);
+  struct context_stack *push_context (int desc, CORE_ADDR valu);
 
-/* Nonzero if within a function (so symbols should be local,
-   if nothing says specifically).  */
+  struct context_stack pop_context ();
 
-EXTERN int within_function;
+  struct block *end_symtab_get_static_block (CORE_ADDR end_addr,
+                                            int expandable, int required);
 
-/* List of blocks already made (lexical contexts already closed).
-   This is used at the end to make the blockvector.  */
+  struct compunit_symtab *end_symtab_from_static_block
+      (struct block *static_block, int section, int expandable);
 
-struct pending_block
-{
-  struct pending_block *next;
-  struct block *block;
-};
+  struct compunit_symtab *end_symtab (CORE_ADDR end_addr, int section);
 
-EXTERN struct pending_block *pending_blocks;
+  struct compunit_symtab *end_expandable_symtab (CORE_ADDR end_addr,
+                                                int section);
 
-extern CORE_ADDR startup_file_start;   /* From blockframe.c */
-extern CORE_ADDR startup_file_end;     /* From blockframe.c */
+  void augment_type_symtab ();
 
-/* Global variable which, when set, indicates that we are processing a
-   .o file compiled with gcc */
+private:
 
-EXTERN unsigned char processing_gcc_compilation;
+  void record_pending_block (struct block *block, struct pending_block *opblock);
 
-/* The type code that process_one_symbol saw on its previous invocation.
-   Used to detect pairs of N_SO symbols. */
+  struct block *finish_block_internal (struct symbol *symbol,
+                                      struct pending **listhead,
+                                      struct pending_block *old_blocks,
+                                      const struct dynamic_prop *static_link,
+                                      CORE_ADDR start, CORE_ADDR end,
+                                      int is_global, int expandable);
 
-EXTERN int previous_stab_code;
+  struct blockvector *make_blockvector ();
 
-/* Setup a define to deal cleanly with the underscore problem */
+  void watch_main_source_file_lossage ();
 
-#ifdef NAMES_HAVE_UNDERSCORE
-#define HASH_OFFSET 1
-#else
-#define HASH_OFFSET 0
-#endif
-\f
-/* Support for Sun changes to dbx symbol format */
-
-/* For each identified header file, we have a table of types defined
-   in that header file.
-
-   header_files maps header file names to their type tables.
-   It is a vector of n_header_files elements.
-   Each element describes one header file.
-   It contains a vector of types.
-
-   Sometimes it can happen that the same header file produces
-   different results when included in different places.
-   This can result from conditionals or from different
-   things done before including the file.
-   When this happens, there are multiple entries for the file in this table,
-   one entry for each distinct set of results.
-   The entries are distinguished by the INSTANCE field.
-   The INSTANCE field appears in the N_BINCL and N_EXCL symbol table and is
-   used to match header-file references to their corresponding data.  */
-
-struct header_file
-{
-  char *name;                  /* Name of header file */
-  int instance;                        /* Numeric code distinguishing instances
-                                  of one header file that produced
-                                  different results when included.
-                                  It comes from the N_BINCL or N_EXCL.  */
-  struct type **vector;                /* Pointer to vector of types */
-  int length;                  /* Allocated length (# elts) of that vector */
-};
+  struct compunit_symtab *end_symtab_with_blockvector
+      (struct block *static_block, int section, int expandable);
 
-EXTERN struct header_file *header_files;
+  /* The objfile we're reading debug info from.  */
+  struct objfile *m_objfile;
 
-EXTERN int n_header_files;
+  /* List of subfiles (source files).
+     Files are added to the front of the list.
+     This is important mostly for the language determination hacks we use,
+     which iterate over previously added files.  */
+  struct subfile *m_subfiles = nullptr;
 
-EXTERN int n_allocated_header_files;
+  /* The subfile of the main source file.  */
+  struct subfile *m_main_subfile = nullptr;
 
-/* Within each object file, various header files are assigned numbers.
-   A type is defined or referred to with a pair of numbers
-   (FILENUM,TYPENUM) where FILENUM is the number of the header file
-   and TYPENUM is the number within that header file.
-   TYPENUM is the index within the vector of types for that header file.
+  /* Name of source file whose symbol data we are now processing.  This
+     comes from a symbol of type N_SO for stabs.  For DWARF it comes
+     from the DW_AT_name attribute of a DW_TAG_compile_unit DIE.  */
+  gdb::unique_xmalloc_ptr<char> m_last_source_file;
 
-   FILENUM == 1 is special; it refers to the main source of the object file,
-   and not to any header file.  FILENUM != 1 is interpreted by looking it up
-   in the following table, which contains indices in header_files.  */
+  /* E.g., DW_AT_comp_dir if DWARF.  Space for this is malloc'd.  */
+  gdb::unique_xmalloc_ptr<char> m_comp_dir;
 
-EXTERN int *this_object_header_files;
+  /* Space for this is not malloc'd, and is assumed to have at least
+     the same lifetime as objfile.  */
+  const char *m_producer = nullptr;
 
-EXTERN int n_this_object_header_files;
+  /* Space for this is malloc'd.  */
+  gdb::unique_xmalloc_ptr<char> m_debugformat;
 
-EXTERN int n_allocated_this_object_header_files;
+  /* The compunit we are building.  */
+  struct compunit_symtab *m_compunit_symtab = nullptr;
 
-/* When a header file is getting special overriding definitions
-   for one source file, record here the header_files index
-   of its normal definition vector.
-   At other times, this is -1.  */
+  /* Language of this compunit_symtab.  */
+  enum language m_language;
 
-EXTERN int header_file_prev_index;
+  /* The macro table for the compilation unit whose symbols we're
+     currently reading.  */
+  struct macro_table *m_pending_macros = nullptr;
 
-struct subfile_stack
-{
-  struct subfile_stack *next;
-  char *name;
-  int prev_index;
-};
+  /* True if symtab has line number info.  This prevents an otherwise
+     empty symtab from being tossed.  */
+  bool m_have_line_numbers = false;
+
+  /* Core address of start of text of current source file.  This too
+     comes from the N_SO symbol.  For Dwarf it typically comes from the
+     DW_AT_low_pc attribute of a DW_TAG_compile_unit DIE.  */
+  CORE_ADDR m_last_source_start_addr;
+
+  /* Stack of subfile names.  */
+  std::vector<const char *> m_subfile_stack;
+
+  /* The "using" directives local to lexical context.  */
+  struct using_direct *m_local_using_directives = nullptr;
+
+  /* Global "using" directives.  */
+  struct using_direct *m_global_using_directives = nullptr;
 
-EXTERN struct subfile_stack *subfile_stack;
+  /* The stack of contexts that are pushed by push_context and popped
+     by pop_context.  */
+  std::vector<struct context_stack> m_context_stack;
 
-extern struct complaint unknown_symtype_complaint;
+  struct subfile *m_current_subfile = nullptr;
+
+  /* The mutable address map for the compilation unit whose symbols
+     we're currently reading.  The symtabs' shared blockvector will
+     point to a fixed copy of this.  */
+  struct addrmap *m_pending_addrmap = nullptr;
+
+  /* The obstack on which we allocate pending_addrmap.
+     If pending_addrmap is NULL, this is uninitialized; otherwise, it is
+     initialized (and holds pending_addrmap).  */
+  auto_obstack m_pending_addrmap_obstack;
+
+  /* True if we recorded any ranges in the addrmap that are different
+     from those in the blockvector already.  We set this to false when
+     we start processing a symfile, and if it's still false at the
+     end, then we just toss the addrmap.  */
+  bool m_pending_addrmap_interesting = false;
+
+  /* An obstack used for allocating pending blocks.  */
+  auto_obstack m_pending_block_obstack;
+
+  /* Pointer to the head of a linked list of symbol blocks which have
+     already been finalized (lexical contexts already closed) and which
+     are just waiting to be built into a blockvector when finalizing the
+     associated symtab.  */
+  struct pending_block *m_pending_blocks = nullptr;
+
+  /* Pending static symbols and types at the top level.  */
+  struct pending *m_file_symbols = nullptr;
+
+  /* Pending global functions and variables.  */
+  struct pending *m_global_symbols = nullptr;
+
+  /* Pending symbols that are local to the lexical context.  */
+  struct pending *m_local_symbols = nullptr;
+};
+
+\f
 
-#define next_symbol_text() (*next_symbol_text_func)()
+extern void add_symbol_to_list (struct symbol *symbol,
+                               struct pending **listhead);
 
-/* Function to invoke get the next symbol.  Return the symbol name. */
+extern struct symbol *find_symbol_in_list (struct pending *list,
+                                          char *name, int length);
 
-EXTERN char * (*next_symbol_text_func)();
+#endif /* defined (BUILDSYM_H) */
This page took 0.029835 seconds and 4 git commands to generate.