Home | History | Annotate | Line # | Download | only in gdb
psymtab.h revision 1.12
      1   1.1  christos /* Public partial symbol table definitions.
      2   1.1  christos 
      3  1.11  christos    Copyright (C) 2009-2024 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.12  christos #ifndef GDB_PSYMTAB_H
     21  1.12  christos #define GDB_PSYMTAB_H
     22   1.1  christos 
     23  1.11  christos #include "objfiles.h"
     24  1.11  christos #include <string_view>
     25  1.10  christos #include "gdbsupport/gdb_obstack.h"
     26   1.1  christos #include "symfile.h"
     27   1.9  christos #include "gdbsupport/next-iterator.h"
     28   1.9  christos #include "bcache.h"
     29   1.8  christos 
     30  1.10  christos /* Specialization of bcache to store partial symbols.  */
     31  1.10  christos 
     32  1.10  christos struct psymbol_bcache : public gdb::bcache
     33  1.10  christos {
     34  1.10  christos   /* Calculate a hash code for the given partial symbol.  The hash is
     35  1.10  christos      calculated using the symbol's value, language, domain, class
     36  1.10  christos      and name.  These are the values which are set by
     37  1.10  christos      add_psymbol_to_bcache.  */
     38  1.10  christos   unsigned long hash (const void *addr, int length) override;
     39  1.10  christos 
     40  1.10  christos   /* Returns true if the symbol LEFT equals the symbol RIGHT.
     41  1.10  christos      For the comparison this function uses a symbols value,
     42  1.10  christos      language, domain, class and name.  */
     43  1.10  christos   int compare (const void *left, const void *right, int length) override;
     44  1.10  christos };
     45  1.10  christos 
     46   1.8  christos /* An instance of this class manages the partial symbol tables and
     47   1.8  christos    partial symbols for a given objfile.
     48   1.8  christos 
     49   1.8  christos    The core psymtab functions -- those in psymtab.c -- arrange for
     50   1.8  christos    nearly all psymtab- and psymbol-related allocations to happen
     51   1.8  christos    either in the psymtab_storage object (either on its obstack or in
     52   1.8  christos    other memory managed by this class), or on the per-BFD object.  The
     53   1.8  christos    only link from the psymtab storage object back to the objfile (or
     54   1.8  christos    objfile_obstack) that is made by the core psymtab code is the
     55   1.9  christos    compunit_symtab member in the standard_psymtab -- and a given
     56   1.9  christos    symbol reader can avoid this by implementing its own subclasses of
     57   1.9  christos    partial_symtab.
     58   1.8  christos 
     59   1.8  christos    However, it is up to each symbol reader to maintain this invariant
     60   1.8  christos    in other ways, if it wants to reuse psymtabs across multiple
     61   1.8  christos    objfiles.  The main issue here is ensuring that read_symtab_private
     62   1.8  christos    does not point into objfile_obstack.  */
     63   1.8  christos 
     64   1.8  christos class psymtab_storage
     65   1.8  christos {
     66   1.8  christos public:
     67  1.10  christos   psymtab_storage () = default;
     68   1.8  christos   ~psymtab_storage ();
     69   1.8  christos 
     70   1.8  christos   DISABLE_COPY_AND_ASSIGN (psymtab_storage);
     71   1.8  christos 
     72   1.8  christos   /* Discard all partial symbol tables starting with "psymtabs" and
     73   1.8  christos      proceeding until "to" has been discarded.  */
     74   1.8  christos 
     75   1.8  christos   void discard_psymtabs_to (struct partial_symtab *to)
     76   1.8  christos   {
     77   1.8  christos     while (psymtabs != to)
     78   1.8  christos       discard_psymtab (psymtabs);
     79   1.8  christos   }
     80   1.8  christos 
     81   1.8  christos   /* Discard the partial symbol table.  */
     82   1.8  christos 
     83   1.8  christos   void discard_psymtab (struct partial_symtab *pst);
     84   1.8  christos 
     85   1.8  christos   /* Return the obstack that is used for storage by this object.  */
     86   1.8  christos 
     87   1.8  christos   struct obstack *obstack ()
     88   1.8  christos   {
     89   1.8  christos     if (!m_obstack.has_value ())
     90   1.8  christos       m_obstack.emplace ();
     91   1.8  christos     return &*m_obstack;
     92   1.8  christos   }
     93   1.8  christos 
     94   1.8  christos   /* Allocate storage for the "dependencies" field of a psymtab.
     95   1.8  christos      NUMBER says how many dependencies there are.  */
     96   1.8  christos 
     97   1.8  christos   struct partial_symtab **allocate_dependencies (int number)
     98   1.8  christos   {
     99   1.8  christos     return OBSTACK_CALLOC (obstack (), number, struct partial_symtab *);
    100   1.8  christos   }
    101   1.8  christos 
    102   1.9  christos   /* Install a psymtab on the psymtab list.  This transfers ownership
    103   1.9  christos      of PST to this object.  */
    104   1.8  christos 
    105   1.9  christos   void install_psymtab (partial_symtab *pst);
    106   1.8  christos 
    107  1.10  christos   using partial_symtab_range = next_range<partial_symtab>;
    108   1.8  christos 
    109   1.8  christos   /* A range adapter that makes it possible to iterate over all
    110   1.8  christos      psymtabs in one objfile.  */
    111   1.8  christos 
    112   1.8  christos   partial_symtab_range range ()
    113   1.8  christos   {
    114   1.8  christos     return partial_symtab_range (psymtabs);
    115   1.8  christos   }
    116   1.8  christos 
    117   1.8  christos 
    118   1.8  christos   /* Each objfile points to a linked list of partial symtabs derived from
    119   1.8  christos      this file, one partial symtab structure for each compilation unit
    120   1.8  christos      (source file).  */
    121   1.8  christos 
    122   1.8  christos   struct partial_symtab *psymtabs = nullptr;
    123   1.8  christos 
    124   1.8  christos   /* A byte cache where we can stash arbitrary "chunks" of bytes that
    125   1.8  christos      will not change.  */
    126   1.8  christos 
    127  1.10  christos   psymbol_bcache psymbol_cache;
    128   1.8  christos 
    129   1.9  christos private:
    130   1.8  christos 
    131   1.8  christos   /* The obstack where allocations are made.  This is lazily allocated
    132   1.8  christos      so that we don't waste memory when there are no psymtabs.  */
    133   1.8  christos 
    134  1.11  christos   std::optional<auto_obstack> m_obstack;
    135  1.11  christos };
    136  1.11  christos 
    137  1.11  christos /* A partial_symbol records the name, domain, and address class of
    138  1.11  christos    symbols whose types we have not parsed yet.  For functions, it also
    139  1.11  christos    contains their memory address, so we can find them from a PC value.
    140  1.11  christos    Each partial_symbol sits in a partial_symtab, all of which are chained
    141  1.11  christos    on a  partial symtab list and which points to the corresponding
    142  1.11  christos    normal symtab once the partial_symtab has been referenced.  */
    143  1.11  christos 
    144  1.11  christos /* This structure is space critical.  See space comments at the top of
    145  1.11  christos    symtab.h.  */
    146  1.11  christos 
    147  1.11  christos struct partial_symbol
    148  1.11  christos {
    149  1.11  christos   /* Return the section for this partial symbol, or nullptr if no
    150  1.11  christos      section has been set.  */
    151  1.11  christos   struct obj_section *obj_section (struct objfile *objfile) const
    152  1.11  christos   {
    153  1.11  christos     return ginfo.obj_section (objfile);
    154  1.11  christos   }
    155  1.11  christos 
    156  1.11  christos   /* Return the unrelocated address of this partial symbol.  */
    157  1.11  christos   unrelocated_addr unrelocated_address () const
    158  1.11  christos   {
    159  1.11  christos     return ginfo.unrelocated_address ();
    160  1.11  christos   }
    161  1.11  christos 
    162  1.11  christos   /* Return the address of this partial symbol, relocated according to
    163  1.11  christos      the offsets provided in OBJFILE.  */
    164  1.11  christos   CORE_ADDR address (const struct objfile *objfile) const
    165  1.11  christos   {
    166  1.11  christos     return (CORE_ADDR (ginfo.unrelocated_address ())
    167  1.11  christos 	    + objfile->section_offsets[ginfo.section_index ()]);
    168  1.11  christos   }
    169  1.11  christos 
    170  1.11  christos   /* Set the address of this partial symbol.  The address must be
    171  1.11  christos      unrelocated.  */
    172  1.11  christos   void set_unrelocated_address (unrelocated_addr addr)
    173  1.11  christos   {
    174  1.11  christos     ginfo.set_unrelocated_address (addr);
    175  1.11  christos   }
    176  1.11  christos 
    177  1.11  christos   /* Note that partial_symbol does not derive from general_symbol_info
    178  1.11  christos      due to the bcache.  See add_psymbol_to_bcache.  */
    179  1.11  christos 
    180  1.11  christos   struct general_symbol_info ginfo;
    181  1.11  christos 
    182  1.11  christos   /* Name space code.  */
    183  1.11  christos 
    184  1.11  christos   ENUM_BITFIELD(domain_enum) domain : SYMBOL_DOMAIN_BITS;
    185  1.11  christos 
    186  1.11  christos   /* Address class (for info_symbols).  Note that we don't allow
    187  1.11  christos      synthetic "aclass" values here at present, simply because there's
    188  1.11  christos      no need.  */
    189  1.11  christos 
    190  1.11  christos   ENUM_BITFIELD(address_class) aclass : SYMBOL_ACLASS_BITS;
    191  1.11  christos };
    192  1.11  christos 
    193  1.11  christos /* A convenience enum to give names to some constants used when
    194  1.11  christos    searching psymtabs.  This is internal to psymtab and should not be
    195  1.11  christos    used elsewhere.  */
    196  1.11  christos 
    197  1.11  christos enum psymtab_search_status
    198  1.11  christos   {
    199  1.11  christos     PST_NOT_SEARCHED,
    200  1.11  christos     PST_SEARCHED_AND_FOUND,
    201  1.11  christos     PST_SEARCHED_AND_NOT_FOUND
    202  1.11  christos   };
    203  1.11  christos 
    204  1.11  christos /* Specify whether a partial psymbol should be allocated on the global
    205  1.11  christos    list or the static list.  */
    206  1.11  christos 
    207  1.11  christos enum class psymbol_placement
    208  1.11  christos {
    209  1.11  christos   STATIC,
    210  1.11  christos   GLOBAL
    211  1.11  christos };
    212  1.11  christos 
    213  1.11  christos /* Each source file that has not been fully read in is represented by
    214  1.11  christos    a partial_symtab.  This contains the information on where in the
    215  1.11  christos    executable the debugging symbols for a specific file are, and a
    216  1.11  christos    list of names of global symbols which are located in this file.
    217  1.11  christos    They are all chained on partial symtab lists.
    218  1.11  christos 
    219  1.11  christos    Even after the source file has been read into a symtab, the
    220  1.11  christos    partial_symtab remains around.  */
    221  1.11  christos 
    222  1.11  christos struct partial_symtab
    223  1.11  christos {
    224  1.11  christos   /* Allocate a new partial symbol table.
    225  1.11  christos 
    226  1.11  christos      FILENAME (which must be non-NULL) is the filename of this partial
    227  1.11  christos      symbol table; it is copied into the appropriate storage.  The
    228  1.11  christos      partial symtab will also be installed using
    229  1.11  christos      psymtab_storage::install.  */
    230  1.11  christos 
    231  1.11  christos   partial_symtab (const char *filename,
    232  1.11  christos 		  psymtab_storage *partial_symtabs,
    233  1.11  christos 		  objfile_per_bfd_storage *objfile_per_bfd)
    234  1.11  christos     ATTRIBUTE_NONNULL (2) ATTRIBUTE_NONNULL (3);
    235  1.11  christos 
    236  1.11  christos   /* Like the above, but also sets the initial text low and text high
    237  1.11  christos      from the ADDR argument, and sets the global- and
    238  1.11  christos      static-offsets.  */
    239  1.11  christos 
    240  1.11  christos   partial_symtab (const char *filename,
    241  1.11  christos 		  psymtab_storage *partial_symtabs,
    242  1.11  christos 		  objfile_per_bfd_storage *objfile_per_bfd,
    243  1.11  christos 		  unrelocated_addr addr)
    244  1.11  christos     ATTRIBUTE_NONNULL (2) ATTRIBUTE_NONNULL (3);
    245  1.11  christos 
    246  1.11  christos   virtual ~partial_symtab ()
    247  1.11  christos   {
    248  1.11  christos   }
    249  1.11  christos 
    250  1.11  christos   /* Psymtab expansion is done in two steps:
    251  1.11  christos      - a call to read_symtab
    252  1.11  christos      - while that call is in progress, calls to expand_psymtab can be made,
    253  1.11  christos        both for this psymtab, and its dependencies.
    254  1.11  christos      This makes a distinction between a toplevel psymtab (for which both
    255  1.11  christos      read_symtab and expand_psymtab will be called) and a non-toplevel
    256  1.11  christos      psymtab (for which only expand_psymtab will be called). The
    257  1.11  christos      distinction can be used f.i. to do things before and after all
    258  1.11  christos      dependencies of a top-level psymtab have been expanded.
    259  1.11  christos 
    260  1.11  christos      Read the full symbol table corresponding to this partial symbol
    261  1.11  christos      table.  Typically calls expand_psymtab.  */
    262  1.11  christos   virtual void read_symtab (struct objfile *) = 0;
    263  1.11  christos 
    264  1.11  christos   /* Expand the full symbol table for this partial symbol table.  Typically
    265  1.11  christos      calls expand_dependencies.  */
    266  1.11  christos   virtual void expand_psymtab (struct objfile *) = 0;
    267  1.11  christos 
    268  1.11  christos   /* Ensure that all the dependencies are read in.  Calls
    269  1.11  christos      expand_psymtab for each non-shared dependency.  */
    270  1.11  christos   void expand_dependencies (struct objfile *);
    271  1.11  christos 
    272  1.11  christos   /* Return true if the symtab corresponding to this psymtab has been
    273  1.11  christos      read in in the context of this objfile.  */
    274  1.11  christos   virtual bool readin_p (struct objfile *) const = 0;
    275  1.11  christos 
    276  1.11  christos   /* Return a pointer to the compunit allocated for this source file
    277  1.11  christos      in the context of this objfile.
    278  1.11  christos 
    279  1.11  christos      Return nullptr if the compunit was not read in or if there was no
    280  1.11  christos      symtab.  */
    281  1.11  christos   virtual struct compunit_symtab *get_compunit_symtab
    282  1.11  christos     (struct objfile *) const = 0;
    283  1.11  christos 
    284  1.11  christos   /* Return the unrelocated low text address of this
    285  1.11  christos      partial_symtab.  */
    286  1.11  christos   unrelocated_addr unrelocated_text_low () const
    287  1.11  christos   {
    288  1.11  christos     return m_text_low;
    289  1.11  christos   }
    290  1.11  christos 
    291  1.11  christos   /* Return the unrelocated_addr high text address of this
    292  1.11  christos      partial_symtab.  */
    293  1.11  christos   unrelocated_addr unrelocated_text_high () const
    294  1.11  christos   {
    295  1.11  christos     return m_text_high;
    296  1.11  christos   }
    297  1.11  christos 
    298  1.11  christos   /* Return the relocated low text address of this partial_symtab.  */
    299  1.11  christos   CORE_ADDR text_low (struct objfile *objfile) const
    300  1.11  christos   {
    301  1.11  christos     return CORE_ADDR (m_text_low) + objfile->text_section_offset ();
    302  1.11  christos   }
    303  1.11  christos 
    304  1.11  christos   /* Return the relocated high text address of this partial_symtab.  */
    305  1.11  christos   CORE_ADDR text_high (struct objfile *objfile) const
    306  1.11  christos   {
    307  1.11  christos     return CORE_ADDR (m_text_high) + objfile->text_section_offset ();
    308  1.11  christos   }
    309  1.11  christos 
    310  1.11  christos   /* Set the low text address of this partial_symtab.  */
    311  1.11  christos   void set_text_low (unrelocated_addr addr)
    312  1.11  christos   {
    313  1.11  christos     m_text_low = addr;
    314  1.11  christos     text_low_valid = 1;
    315  1.11  christos   }
    316  1.11  christos 
    317  1.11  christos   /* Set the high text address of this partial_symtab.  */
    318  1.11  christos   void set_text_high (unrelocated_addr addr)
    319  1.11  christos   {
    320  1.11  christos     m_text_high = addr;
    321  1.11  christos     text_high_valid = 1;
    322  1.11  christos   }
    323  1.11  christos 
    324  1.11  christos   /* Return true if this symtab is empty -- meaning that it contains
    325  1.11  christos      no symbols.  It may still have dependencies.  */
    326  1.11  christos   bool empty () const
    327  1.11  christos   {
    328  1.11  christos     return global_psymbols.empty () && static_psymbols.empty ();
    329  1.11  christos   }
    330  1.11  christos 
    331  1.11  christos   /* Add a symbol to this partial symbol table of OBJFILE.
    332  1.11  christos 
    333  1.11  christos      If COPY_NAME is true, make a copy of NAME, otherwise use the passed
    334  1.11  christos      reference.
    335  1.11  christos 
    336  1.11  christos      THECLASS is the type of symbol.
    337  1.11  christos 
    338  1.11  christos      SECTION is the index of the section of OBJFILE in which the symbol is found.
    339  1.11  christos 
    340  1.11  christos      WHERE determines whether the symbol goes in the list of static or global
    341  1.11  christos      partial symbols.
    342  1.11  christos 
    343  1.11  christos      COREADDR is the address of the symbol.  For partial symbols that don't have
    344  1.11  christos      an address, zero is passed.
    345  1.11  christos 
    346  1.11  christos      LANGUAGE is the language from which the symbol originates.  This will
    347  1.11  christos      influence, amongst other things, how the symbol name is demangled. */
    348  1.11  christos 
    349  1.11  christos   void add_psymbol (std::string_view name,
    350  1.11  christos 		    bool copy_name, domain_enum domain,
    351  1.11  christos 		    enum address_class theclass,
    352  1.12  christos 		    int section,
    353  1.11  christos 		    psymbol_placement where,
    354  1.11  christos 		    unrelocated_addr coreaddr,
    355  1.11  christos 		    enum language language,
    356  1.11  christos 		    psymtab_storage *partial_symtabs,
    357  1.11  christos 		    struct objfile *objfile);
    358  1.11  christos 
    359  1.11  christos   /* Add a symbol to this partial symbol table of OBJFILE.  The psymbol
    360  1.11  christos      must be fully constructed, and the names must be set and intern'd
    361  1.11  christos      as appropriate.  */
    362  1.11  christos 
    363  1.11  christos   void add_psymbol (const partial_symbol &psym,
    364  1.11  christos 		    psymbol_placement where,
    365  1.11  christos 		    psymtab_storage *partial_symtabs,
    366  1.11  christos 		    struct objfile *objfile);
    367  1.11  christos 
    368  1.11  christos 
    369  1.11  christos   /* Indicate that this partial symtab is complete.  */
    370  1.11  christos 
    371  1.11  christos   void end ();
    372  1.11  christos 
    373  1.11  christos   /* Chain of all existing partial symtabs.  */
    374  1.11  christos 
    375  1.11  christos   struct partial_symtab *next = nullptr;
    376  1.11  christos 
    377  1.11  christos   /* Name of the source file which this partial_symtab defines,
    378  1.11  christos      or if the psymtab is anonymous then a descriptive name for
    379  1.11  christos      debugging purposes, or "".  It must not be NULL.  */
    380  1.11  christos 
    381  1.11  christos   const char *filename = nullptr;
    382  1.11  christos 
    383  1.11  christos   /* Full path of the source file.  NULL if not known.  */
    384  1.11  christos 
    385  1.11  christos   char *fullname = nullptr;
    386  1.11  christos 
    387  1.11  christos   /* Directory in which it was compiled, or NULL if we don't know.  */
    388  1.11  christos 
    389  1.11  christos   const char *dirname = nullptr;
    390  1.11  christos 
    391  1.11  christos   /* Range of text addresses covered by this file; texthigh is the
    392  1.11  christos      beginning of the next section.  Do not refer directly to these
    393  1.11  christos      fields.  Instead, use the accessors.  The validity of these
    394  1.11  christos      fields is determined by the text_low_valid and text_high_valid
    395  1.11  christos      fields; these are located later in this structure for better
    396  1.11  christos      packing.  */
    397  1.11  christos 
    398  1.11  christos   unrelocated_addr m_text_low {};
    399  1.11  christos   unrelocated_addr m_text_high {};
    400  1.11  christos 
    401  1.11  christos   /* If NULL, this is an ordinary partial symbol table.
    402  1.11  christos 
    403  1.11  christos      If non-NULL, this holds a single includer of this partial symbol
    404  1.11  christos      table, and this partial symbol table is a shared one.
    405  1.11  christos 
    406  1.11  christos      A shared psymtab is one that is referenced by multiple other
    407  1.11  christos      psymtabs, and which conceptually has its contents directly
    408  1.11  christos      included in those.
    409  1.11  christos 
    410  1.11  christos      Shared psymtabs have special semantics.  When a search finds a
    411  1.11  christos      symbol in a shared table, we instead return one of the non-shared
    412  1.11  christos      tables that include this one.
    413  1.11  christos 
    414  1.11  christos      A shared psymtabs can be referred to by other shared ones.
    415  1.11  christos 
    416  1.11  christos      The psymtabs that refer to a shared psymtab will list the shared
    417  1.11  christos      psymtab in their 'dependencies' array.
    418  1.11  christos 
    419  1.11  christos      In DWARF terms, a shared psymtab is a DW_TAG_partial_unit; but
    420  1.11  christos      of course using a name based on that would be too confusing, so
    421  1.11  christos      "shared" was chosen instead.
    422  1.11  christos 
    423  1.11  christos      Only a single user is needed because, when expanding a shared
    424  1.11  christos      psymtab, we only need to expand its "canonical" non-shared user.
    425  1.11  christos      The choice of which one should be canonical is left to the
    426  1.11  christos      debuginfo reader; it can be arbitrary.  */
    427  1.11  christos 
    428  1.11  christos   struct partial_symtab *user = nullptr;
    429  1.11  christos 
    430  1.11  christos   /* Array of pointers to all of the partial_symtab's which this one
    431  1.11  christos      depends on.  Since this array can only be set to previous or
    432  1.11  christos      the current (?) psymtab, this dependency tree is guaranteed not
    433  1.11  christos      to have any loops.  "depends on" means that symbols must be read
    434  1.11  christos      for the dependencies before being read for this psymtab; this is
    435  1.11  christos      for type references in stabs, where if foo.c includes foo.h, declarations
    436  1.11  christos      in foo.h may use type numbers defined in foo.c.  For other debugging
    437  1.11  christos      formats there may be no need to use dependencies.  */
    438  1.11  christos 
    439  1.11  christos   struct partial_symtab **dependencies = nullptr;
    440  1.11  christos 
    441  1.11  christos   int number_of_dependencies = 0;
    442  1.11  christos 
    443  1.11  christos   /* Global symbol list.  This list will be sorted after readin to
    444  1.11  christos      improve access.  Binary search will be the usual method of
    445  1.11  christos      finding a symbol within it.  */
    446  1.11  christos 
    447  1.12  christos   std::vector<const partial_symbol *> global_psymbols;
    448  1.11  christos 
    449  1.11  christos   /* Static symbol list.  This list will *not* be sorted after readin;
    450  1.11  christos      to find a symbol in it, exhaustive search must be used.  This is
    451  1.11  christos      reasonable because searches through this list will eventually
    452  1.11  christos      lead to either the read in of a files symbols for real (assumed
    453  1.11  christos      to take a *lot* of time; check) or an error (and we don't care
    454  1.11  christos      how long errors take).  */
    455  1.11  christos 
    456  1.12  christos   std::vector<const partial_symbol *> static_psymbols;
    457  1.11  christos 
    458  1.11  christos   /* True if the name of this partial symtab is not a source file name.  */
    459  1.11  christos 
    460  1.11  christos   bool anonymous = false;
    461  1.11  christos 
    462  1.11  christos   /* A flag that is temporarily used when searching psymtabs.  */
    463  1.11  christos 
    464  1.11  christos   ENUM_BITFIELD (psymtab_search_status) searched_flag : 2;
    465  1.11  christos 
    466  1.11  christos   /* Validity of the m_text_low and m_text_high fields.  */
    467  1.11  christos 
    468  1.11  christos   unsigned int text_low_valid : 1;
    469  1.11  christos   unsigned int text_high_valid : 1;
    470  1.11  christos };
    471  1.11  christos 
    472  1.11  christos /* A partial symtab that tracks the "readin" and "compunit_symtab"
    473  1.11  christos    information in the ordinary way -- by storing it directly in this
    474  1.11  christos    object.  */
    475  1.11  christos struct standard_psymtab : public partial_symtab
    476  1.11  christos {
    477  1.11  christos   standard_psymtab (const char *filename,
    478  1.11  christos 		    psymtab_storage *partial_symtabs,
    479  1.11  christos 		    objfile_per_bfd_storage *objfile_per_bfd)
    480  1.11  christos     : partial_symtab (filename, partial_symtabs, objfile_per_bfd)
    481  1.11  christos   {
    482  1.11  christos   }
    483  1.11  christos 
    484  1.11  christos   standard_psymtab (const char *filename,
    485  1.11  christos 		    psymtab_storage *partial_symtabs,
    486  1.11  christos 		    objfile_per_bfd_storage *objfile_per_bfd,
    487  1.11  christos 		    unrelocated_addr addr)
    488  1.11  christos     : partial_symtab (filename, partial_symtabs, objfile_per_bfd, addr)
    489  1.11  christos   {
    490  1.11  christos   }
    491  1.11  christos 
    492  1.11  christos   bool readin_p (struct objfile *) const override
    493  1.11  christos   {
    494  1.11  christos     return readin;
    495  1.11  christos   }
    496  1.11  christos 
    497  1.11  christos   struct compunit_symtab *get_compunit_symtab (struct objfile *) const override
    498  1.11  christos   {
    499  1.11  christos     return compunit_symtab;
    500  1.11  christos   }
    501  1.11  christos 
    502  1.11  christos   /* True if the symtab corresponding to this psymtab has been
    503  1.11  christos      readin.  */
    504  1.11  christos 
    505  1.11  christos   bool readin = false;
    506  1.11  christos 
    507  1.11  christos   /* Pointer to compunit eventually allocated for this source file, 0 if
    508  1.11  christos      !readin or if we haven't looked for the symtab after it was readin.  */
    509  1.11  christos 
    510  1.11  christos   struct compunit_symtab *compunit_symtab = nullptr;
    511  1.11  christos };
    512  1.11  christos 
    513  1.11  christos /* A partial_symtab that works in the historical db way.  This should
    514  1.11  christos    not be used in new code, but exists to transition the somewhat
    515  1.11  christos    unmaintained "legacy" debug formats.  */
    516  1.11  christos 
    517  1.11  christos struct legacy_psymtab : public standard_psymtab
    518  1.11  christos {
    519  1.11  christos   legacy_psymtab (const char *filename,
    520  1.11  christos 		  psymtab_storage *partial_symtabs,
    521  1.11  christos 		  objfile_per_bfd_storage *objfile_per_bfd)
    522  1.11  christos     : standard_psymtab (filename, partial_symtabs, objfile_per_bfd)
    523  1.11  christos   {
    524  1.11  christos   }
    525  1.11  christos 
    526  1.11  christos   legacy_psymtab (const char *filename,
    527  1.11  christos 		  psymtab_storage *partial_symtabs,
    528  1.11  christos 		  objfile_per_bfd_storage *objfile_per_bfd,
    529  1.11  christos 		  unrelocated_addr addr)
    530  1.11  christos     : standard_psymtab (filename, partial_symtabs, objfile_per_bfd, addr)
    531  1.11  christos   {
    532  1.11  christos   }
    533  1.11  christos 
    534  1.11  christos   void read_symtab (struct objfile *objf) override
    535  1.11  christos   {
    536  1.11  christos     if (legacy_read_symtab)
    537  1.11  christos       (*legacy_read_symtab) (this, objf);
    538  1.11  christos   }
    539  1.11  christos 
    540  1.11  christos   void expand_psymtab (struct objfile *objf) override
    541  1.11  christos   {
    542  1.11  christos     (*legacy_expand_psymtab) (this, objf);
    543  1.11  christos   }
    544  1.11  christos 
    545  1.11  christos   /* Pointer to function which will read in the symtab corresponding to
    546  1.11  christos      this psymtab.  */
    547  1.11  christos 
    548  1.11  christos   void (*legacy_read_symtab) (legacy_psymtab *, struct objfile *) = nullptr;
    549  1.11  christos 
    550  1.11  christos   /* Pointer to function which will actually expand this psymtab into
    551  1.11  christos      a full symtab.  */
    552  1.11  christos 
    553  1.11  christos   void (*legacy_expand_psymtab) (legacy_psymtab *, struct objfile *) = nullptr;
    554  1.11  christos 
    555  1.11  christos   /* Information that lets read_symtab() locate the part of the symbol table
    556  1.11  christos      that this psymtab corresponds to.  This information is private to the
    557  1.11  christos      format-dependent symbol reading routines.  For further detail examine
    558  1.11  christos      the various symbol reading modules.  */
    559  1.11  christos 
    560  1.11  christos   void *read_symtab_private = nullptr;
    561  1.11  christos };
    562  1.11  christos 
    563  1.11  christos /* Used when recording partial symbol tables.  On destruction,
    564  1.11  christos    discards any partial symbol tables that have been built.  However,
    565  1.11  christos    the tables can be kept by calling the "keep" method.  */
    566  1.11  christos class psymtab_discarder
    567  1.11  christos {
    568  1.11  christos  public:
    569  1.11  christos 
    570  1.11  christos   psymtab_discarder (psymtab_storage *partial_symtabs)
    571  1.11  christos     : m_partial_symtabs (partial_symtabs),
    572  1.11  christos       m_psymtab (partial_symtabs->psymtabs)
    573  1.11  christos   {
    574  1.11  christos   }
    575  1.11  christos 
    576  1.11  christos   ~psymtab_discarder ()
    577  1.11  christos   {
    578  1.11  christos     if (m_partial_symtabs != nullptr)
    579  1.11  christos       m_partial_symtabs->discard_psymtabs_to (m_psymtab);
    580  1.11  christos   }
    581  1.11  christos 
    582  1.11  christos   /* Keep any partial symbol tables that were built.  */
    583  1.11  christos   void keep ()
    584  1.11  christos   {
    585  1.11  christos     m_partial_symtabs = nullptr;
    586  1.11  christos   }
    587  1.11  christos 
    588  1.11  christos  private:
    589  1.11  christos 
    590  1.11  christos   /* The partial symbol storage object.  */
    591  1.11  christos   psymtab_storage *m_partial_symtabs;
    592  1.11  christos   /* How far back to free.  */
    593  1.11  christos   struct partial_symtab *m_psymtab;
    594  1.11  christos };
    595  1.11  christos 
    596  1.11  christos /* An implementation of quick_symbol_functions, specialized for
    597  1.11  christos    partial symbols.  */
    598  1.11  christos struct psymbol_functions : public quick_symbol_functions
    599  1.11  christos {
    600  1.11  christos   explicit psymbol_functions (const std::shared_ptr<psymtab_storage> &storage)
    601  1.11  christos     : m_partial_symtabs (storage)
    602  1.11  christos   {
    603  1.11  christos   }
    604  1.11  christos 
    605  1.11  christos   psymbol_functions ()
    606  1.11  christos     : m_partial_symtabs (new psymtab_storage)
    607  1.11  christos   {
    608  1.11  christos   }
    609  1.11  christos 
    610  1.11  christos   bool has_symbols (struct objfile *objfile) override;
    611  1.11  christos 
    612  1.11  christos   bool has_unexpanded_symtabs (struct objfile *objfile) override;
    613  1.11  christos 
    614  1.11  christos   struct symtab *find_last_source_symtab (struct objfile *objfile) override;
    615  1.11  christos 
    616  1.11  christos   void forget_cached_source_info (struct objfile *objfile) override;
    617  1.11  christos 
    618  1.11  christos   enum language lookup_global_symbol_language (struct objfile *objfile,
    619  1.11  christos 					       const char *name,
    620  1.11  christos 					       domain_search_flags domain,
    621  1.11  christos 					       bool *symbol_found_p) override;
    622  1.11  christos 
    623  1.11  christos   void print_stats (struct objfile *objfile, bool print_bcache) override;
    624  1.11  christos 
    625  1.11  christos   void dump (struct objfile *objfile) override;
    626  1.11  christos 
    627  1.11  christos   void expand_all_symtabs (struct objfile *objfile) override;
    628  1.11  christos 
    629  1.11  christos   bool expand_symtabs_matching
    630  1.11  christos     (struct objfile *objfile,
    631  1.11  christos      gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
    632  1.11  christos      const lookup_name_info *lookup_name,
    633  1.11  christos      gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
    634  1.11  christos      gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
    635  1.11  christos      block_search_flags search_flags,
    636  1.12  christos      domain_search_flags kind,
    637  1.12  christos      gdb::function_view<expand_symtabs_lang_matcher_ftype> lang_matcher)
    638  1.12  christos        override;
    639  1.11  christos 
    640  1.11  christos   struct compunit_symtab *find_pc_sect_compunit_symtab
    641  1.12  christos     (struct objfile *objfile, bound_minimal_symbol msymbol, CORE_ADDR pc,
    642  1.12  christos      struct obj_section *section, int warn_if_readin) override;
    643  1.11  christos 
    644  1.11  christos   struct compunit_symtab *find_compunit_symtab_by_address
    645  1.11  christos     (struct objfile *objfile, CORE_ADDR address) override
    646  1.11  christos   {
    647  1.11  christos     return nullptr;
    648  1.11  christos   }
    649  1.11  christos 
    650  1.11  christos   void map_symbol_filenames (struct objfile *objfile,
    651  1.11  christos 			     gdb::function_view<symbol_filename_ftype> fun,
    652  1.11  christos 			     bool need_fullname) override;
    653  1.11  christos 
    654  1.11  christos   /* Return a range adapter for the psymtabs.  */
    655  1.11  christos   psymtab_storage::partial_symtab_range partial_symbols
    656  1.11  christos        (struct objfile *objfile);
    657  1.11  christos 
    658  1.11  christos   /* Return the partial symbol storage associated with this
    659  1.11  christos      object.  */
    660  1.11  christos   const std::shared_ptr<psymtab_storage> &get_partial_symtabs () const
    661  1.11  christos   {
    662  1.11  christos     return m_partial_symtabs;
    663  1.11  christos   }
    664  1.11  christos 
    665  1.11  christos   /* Replace the partial symbol table storage in this object with
    666  1.11  christos      SYMS.  */
    667  1.11  christos   void set_partial_symtabs (const std::shared_ptr<psymtab_storage> &syms)
    668  1.11  christos   {
    669  1.11  christos     m_partial_symtabs = syms;
    670  1.11  christos   }
    671  1.11  christos 
    672  1.11  christos   /* Find which partial symtab contains PC and SECTION.  Return NULL if
    673  1.11  christos      none.  We return the psymtab that contains a symbol whose address
    674  1.11  christos      exactly matches PC, or, if we cannot find an exact match, the
    675  1.11  christos      psymtab that contains a symbol whose address is closest to PC.  */
    676  1.11  christos 
    677  1.12  christos   struct partial_symtab *find_pc_sect_psymtab (struct objfile *objfile,
    678  1.12  christos 					       CORE_ADDR pc,
    679  1.12  christos 					       struct obj_section *section,
    680  1.12  christos 					       bound_minimal_symbol msymbol);
    681  1.11  christos 
    682  1.11  christos private:
    683  1.11  christos 
    684  1.11  christos   /* Count the number of partial symbols in *THIS.  */
    685  1.11  christos   int count_psyms ();
    686  1.11  christos 
    687  1.11  christos   /* Storage for the partial symbols.  */
    688  1.11  christos   std::shared_ptr<psymtab_storage> m_partial_symtabs;
    689   1.8  christos };
    690   1.8  christos 
    691  1.12  christos #endif /* GDB_PSYMTAB_H */
    692