Home | History | Annotate | Line # | Download | only in gdb
psymtab.h revision 1.10
      1   1.1  christos /* Public partial symbol table definitions.
      2   1.1  christos 
      3  1.10  christos    Copyright (C) 2009-2023 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.10  christos #include "gdbsupport/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.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.8  christos   gdb::optional<auto_obstack> m_obstack;
    135   1.8  christos };
    136   1.8  christos 
    137   1.1  christos #endif /* PSYMTAB_H */
    138