Home | History | Annotate | Line # | Download | only in gdb
psymtab.h revision 1.9
      1  1.1  christos /* Public partial symbol table definitions.
      2  1.1  christos 
      3  1.9  christos    Copyright (C) 2009-2020 Free Software Foundation, Inc.
      4  1.1  christos 
      5  1.1  christos    This file is part of GDB.
      6  1.1  christos 
      7  1.1  christos    This program is free software; you can redistribute it and/or modify
      8  1.1  christos    it under the terms of the GNU General Public License as published by
      9  1.1  christos    the Free Software Foundation; either version 3 of the License, or
     10  1.1  christos    (at your option) any later version.
     11  1.1  christos 
     12  1.1  christos    This program is distributed in the hope that it will be useful,
     13  1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15  1.1  christos    GNU General Public License for more details.
     16  1.1  christos 
     17  1.1  christos    You should have received a copy of the GNU General Public License
     18  1.1  christos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     19  1.1  christos 
     20  1.1  christos #ifndef PSYMTAB_H
     21  1.1  christos #define PSYMTAB_H
     22  1.1  christos 
     23  1.8  christos #include "gdb_obstack.h"
     24  1.1  christos #include "symfile.h"
     25  1.9  christos #include "gdbsupport/next-iterator.h"
     26  1.9  christos #include "bcache.h"
     27  1.8  christos 
     28  1.8  christos struct partial_symbol;
     29  1.1  christos 
     30  1.8  christos /* An instance of this class manages the partial symbol tables and
     31  1.8  christos    partial symbols for a given objfile.
     32  1.8  christos 
     33  1.8  christos    The core psymtab functions -- those in psymtab.c -- arrange for
     34  1.8  christos    nearly all psymtab- and psymbol-related allocations to happen
     35  1.8  christos    either in the psymtab_storage object (either on its obstack or in
     36  1.8  christos    other memory managed by this class), or on the per-BFD object.  The
     37  1.8  christos    only link from the psymtab storage object back to the objfile (or
     38  1.8  christos    objfile_obstack) that is made by the core psymtab code is the
     39  1.9  christos    compunit_symtab member in the standard_psymtab -- and a given
     40  1.9  christos    symbol reader can avoid this by implementing its own subclasses of
     41  1.9  christos    partial_symtab.
     42  1.8  christos 
     43  1.8  christos    However, it is up to each symbol reader to maintain this invariant
     44  1.8  christos    in other ways, if it wants to reuse psymtabs across multiple
     45  1.8  christos    objfiles.  The main issue here is ensuring that read_symtab_private
     46  1.8  christos    does not point into objfile_obstack.  */
     47  1.8  christos 
     48  1.8  christos class psymtab_storage
     49  1.8  christos {
     50  1.8  christos public:
     51  1.8  christos 
     52  1.8  christos   psymtab_storage ();
     53  1.8  christos 
     54  1.8  christos   ~psymtab_storage ();
     55  1.8  christos 
     56  1.8  christos   DISABLE_COPY_AND_ASSIGN (psymtab_storage);
     57  1.8  christos 
     58  1.8  christos   /* Discard all partial symbol tables starting with "psymtabs" and
     59  1.8  christos      proceeding until "to" has been discarded.  */
     60  1.8  christos 
     61  1.8  christos   void discard_psymtabs_to (struct partial_symtab *to)
     62  1.8  christos   {
     63  1.8  christos     while (psymtabs != to)
     64  1.8  christos       discard_psymtab (psymtabs);
     65  1.8  christos   }
     66  1.8  christos 
     67  1.8  christos   /* Discard the partial symbol table.  */
     68  1.8  christos 
     69  1.8  christos   void discard_psymtab (struct partial_symtab *pst);
     70  1.8  christos 
     71  1.8  christos   /* Return the obstack that is used for storage by this object.  */
     72  1.8  christos 
     73  1.8  christos   struct obstack *obstack ()
     74  1.8  christos   {
     75  1.8  christos     if (!m_obstack.has_value ())
     76  1.8  christos       m_obstack.emplace ();
     77  1.8  christos     return &*m_obstack;
     78  1.8  christos   }
     79  1.8  christos 
     80  1.8  christos   /* Allocate storage for the "dependencies" field of a psymtab.
     81  1.8  christos      NUMBER says how many dependencies there are.  */
     82  1.8  christos 
     83  1.8  christos   struct partial_symtab **allocate_dependencies (int number)
     84  1.8  christos   {
     85  1.8  christos     return OBSTACK_CALLOC (obstack (), number, struct partial_symtab *);
     86  1.8  christos   }
     87  1.8  christos 
     88  1.9  christos   /* Install a psymtab on the psymtab list.  This transfers ownership
     89  1.9  christos      of PST to this object.  */
     90  1.8  christos 
     91  1.9  christos   void install_psymtab (partial_symtab *pst);
     92  1.8  christos 
     93  1.8  christos   typedef next_adapter<struct partial_symtab> partial_symtab_range;
     94  1.8  christos 
     95  1.8  christos   /* A range adapter that makes it possible to iterate over all
     96  1.8  christos      psymtabs in one objfile.  */
     97  1.8  christos 
     98  1.8  christos   partial_symtab_range range ()
     99  1.8  christos   {
    100  1.8  christos     return partial_symtab_range (psymtabs);
    101  1.8  christos   }
    102  1.8  christos 
    103  1.8  christos 
    104  1.8  christos   /* Each objfile points to a linked list of partial symtabs derived from
    105  1.8  christos      this file, one partial symtab structure for each compilation unit
    106  1.8  christos      (source file).  */
    107  1.8  christos 
    108  1.8  christos   struct partial_symtab *psymtabs = nullptr;
    109  1.8  christos 
    110  1.8  christos   /* Map addresses to the entries of PSYMTABS.  It would be more efficient to
    111  1.8  christos      have a map per the whole process but ADDRMAP cannot selectively remove
    112  1.8  christos      its items during FREE_OBJFILE.  This mapping is already present even for
    113  1.9  christos      PARTIAL_SYMTABs which still have no corresponding full SYMTABs read.
    114  1.9  christos 
    115  1.9  christos      The DWARF parser reuses this addrmap to store things other than
    116  1.9  christos      psymtabs in the cases where debug information is being read from, for
    117  1.9  christos      example, the .debug-names section.  */
    118  1.8  christos 
    119  1.8  christos   struct addrmap *psymtabs_addrmap = nullptr;
    120  1.8  christos 
    121  1.8  christos   /* A byte cache where we can stash arbitrary "chunks" of bytes that
    122  1.8  christos      will not change.  */
    123  1.8  christos 
    124  1.9  christos   gdb::bcache psymbol_cache;
    125  1.8  christos 
    126  1.8  christos   /* Vectors of all partial symbols read in from file.  The actual data
    127  1.8  christos      is stored in the objfile_obstack.  */
    128  1.8  christos 
    129  1.8  christos   std::vector<partial_symbol *> global_psymbols;
    130  1.8  christos   std::vector<partial_symbol *> static_psymbols;
    131  1.8  christos 
    132  1.9  christos   /* Stack of vectors of partial symbols, using during psymtab
    133  1.9  christos      initialization.  */
    134  1.8  christos 
    135  1.9  christos   std::vector<std::vector<partial_symbol *>*> current_global_psymbols;
    136  1.9  christos   std::vector<std::vector<partial_symbol *>*> current_static_psymbols;
    137  1.8  christos 
    138  1.9  christos private:
    139  1.8  christos 
    140  1.8  christos   /* The obstack where allocations are made.  This is lazily allocated
    141  1.8  christos      so that we don't waste memory when there are no psymtabs.  */
    142  1.8  christos 
    143  1.8  christos   gdb::optional<auto_obstack> m_obstack;
    144  1.8  christos };
    145  1.8  christos 
    146  1.8  christos 
    147  1.1  christos extern const struct quick_symbol_functions psym_functions;
    148  1.1  christos 
    149  1.1  christos extern const struct quick_symbol_functions dwarf2_gdb_index_functions;
    150  1.8  christos extern const struct quick_symbol_functions dwarf2_debug_names_functions;
    151  1.1  christos 
    152  1.1  christos /* Ensure that the partial symbols for OBJFILE have been loaded.  If
    153  1.9  christos    VERBOSE is true, then this will print a message when symbols
    154  1.8  christos    are loaded.  This function returns a range adapter suitable for
    155  1.8  christos    iterating over the psymtabs of OBJFILE.  */
    156  1.1  christos 
    157  1.8  christos extern psymtab_storage::partial_symtab_range require_partial_symbols
    158  1.9  christos     (struct objfile *objfile, bool verbose);
    159  1.1  christos 
    160  1.1  christos #endif /* PSYMTAB_H */
    161