Home | History | Annotate | Line # | Download | only in gdb
symtab.h revision 1.11
      1 /* Symbol table definitions for GDB.
      2 
      3    Copyright (C) 1986-2024 Free Software Foundation, Inc.
      4 
      5    This file is part of GDB.
      6 
      7    This program is free software; you can redistribute it and/or modify
      8    it under the terms of the GNU General Public License as published by
      9    the Free Software Foundation; either version 3 of the License, or
     10    (at your option) any later version.
     11 
     12    This program is distributed in the hope that it will be useful,
     13    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15    GNU General Public License for more details.
     16 
     17    You should have received a copy of the GNU General Public License
     18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     19 
     20 #if !defined (SYMTAB_H)
     21 #define SYMTAB_H 1
     22 
     23 #include <array>
     24 #include <vector>
     25 #include <string>
     26 #include <set>
     27 #include "gdbsupport/gdb_vecs.h"
     28 #include "gdbtypes.h"
     29 #include "gdbsupport/gdb_obstack.h"
     30 #include "gdbsupport/gdb_regex.h"
     31 #include "gdbsupport/enum-flags.h"
     32 #include "gdbsupport/function-view.h"
     33 #include <optional>
     34 #include <string_view>
     35 #include "gdbsupport/next-iterator.h"
     36 #include "gdbsupport/iterator-range.h"
     37 #include "completer.h"
     38 #include "gdb-demangle.h"
     39 #include "split-name.h"
     40 #include "frame.h"
     41 #include <optional>
     42 
     43 /* Opaque declarations.  */
     44 struct ui_file;
     45 class frame_info_ptr;
     46 struct symbol;
     47 struct obstack;
     48 struct objfile;
     49 struct block;
     50 struct blockvector;
     51 struct axs_value;
     52 struct agent_expr;
     53 struct program_space;
     54 struct language_defn;
     55 struct common_block;
     56 struct obj_section;
     57 struct cmd_list_element;
     58 class probe;
     59 struct lookup_name_info;
     60 struct code_breakpoint;
     61 
     62 /* How to match a lookup name against a symbol search name.  */
     63 enum class symbol_name_match_type
     64 {
     65   /* Wild matching.  Matches unqualified symbol names in all
     66      namespace/module/packages, etc.  */
     67   WILD,
     68 
     69   /* Full matching.  The lookup name indicates a fully-qualified name,
     70      and only matches symbol search names in the specified
     71      namespace/module/package.  */
     72   FULL,
     73 
     74   /* Search name matching.  This is like FULL, but the search name did
     75      not come from the user; instead it is already a search name
     76      retrieved from a search_name () call.
     77      For Ada, this avoids re-encoding an already-encoded search name
     78      (which would potentially incorrectly lowercase letters in the
     79      linkage/search name that should remain uppercase).  For C++, it
     80      avoids trying to demangle a name we already know is
     81      demangled.  */
     82   SEARCH_NAME,
     83 
     84   /* Expression matching.  The same as FULL matching in most
     85      languages.  The same as WILD matching in Ada.  */
     86   EXPRESSION,
     87 };
     88 
     89 /* Hash the given symbol search name according to LANGUAGE's
     90    rules.  */
     91 extern unsigned int search_name_hash (enum language language,
     92 				      const char *search_name);
     93 
     94 /* Ada-specific bits of a lookup_name_info object.  This is lazily
     95    constructed on demand.  */
     96 
     97 class ada_lookup_name_info final
     98 {
     99  public:
    100   /* Construct.  */
    101   explicit ada_lookup_name_info (const lookup_name_info &lookup_name);
    102 
    103   /* Compare SYMBOL_SEARCH_NAME with our lookup name, using MATCH_TYPE
    104      as name match type.  Returns true if there's a match, false
    105      otherwise.  If non-NULL, store the matching results in MATCH.  */
    106   bool matches (const char *symbol_search_name,
    107 		symbol_name_match_type match_type,
    108 		completion_match_result *comp_match_res) const;
    109 
    110   /* The Ada-encoded lookup name.  */
    111   const std::string &lookup_name () const
    112   { return m_encoded_name; }
    113 
    114   /* Return true if we're supposed to be doing a wild match look
    115      up.  */
    116   bool wild_match_p () const
    117   { return m_wild_match_p; }
    118 
    119   /* Return true if we're looking up a name inside package
    120      Standard.  */
    121   bool standard_p () const
    122   { return m_standard_p; }
    123 
    124   /* Return true if doing a verbatim match.  */
    125   bool verbatim_p () const
    126   { return m_verbatim_p; }
    127 
    128   /* A wrapper for ::split_name that handles some Ada-specific
    129      peculiarities.  */
    130   std::vector<std::string_view> split_name () const
    131   {
    132     if (m_verbatim_p)
    133       {
    134 	/* For verbatim matches, just return the encoded name
    135 	   as-is.  */
    136 	std::vector<std::string_view> result;
    137 	result.emplace_back (m_encoded_name);
    138 	return result;
    139       }
    140     /* Otherwise, split the decoded name for matching.  */
    141     return ::split_name (m_decoded_name.c_str (), split_style::DOT_STYLE);
    142   }
    143 
    144 private:
    145   /* The Ada-encoded lookup name.  */
    146   std::string m_encoded_name;
    147 
    148   /* The decoded lookup name.  This is formed by calling ada_decode
    149      with both 'operators' and 'wide' set to false.  */
    150   std::string m_decoded_name;
    151 
    152   /* Whether the user-provided lookup name was Ada encoded.  If so,
    153      then return encoded names in the 'matches' method's 'completion
    154      match result' output.  */
    155   bool m_encoded_p : 1;
    156 
    157   /* True if really doing wild matching.  Even if the user requests
    158      wild matching, some cases require full matching.  */
    159   bool m_wild_match_p : 1;
    160 
    161   /* True if doing a verbatim match.  This is true if the decoded
    162      version of the symbol name is wrapped in '<'/'>'.  This is an
    163      escape hatch users can use to look up symbols the Ada encoding
    164      does not understand.  */
    165   bool m_verbatim_p : 1;
    166 
    167    /* True if the user specified a symbol name that is inside package
    168       Standard.  Symbol names inside package Standard are handled
    169       specially.  We always do a non-wild match of the symbol name
    170       without the "standard__" prefix, and only search static and
    171       global symbols.  This was primarily introduced in order to allow
    172       the user to specifically access the standard exceptions using,
    173       for instance, Standard.Constraint_Error when Constraint_Error is
    174       ambiguous (due to the user defining its own Constraint_Error
    175       entity inside its program).  */
    176   bool m_standard_p : 1;
    177 };
    178 
    179 /* Language-specific bits of a lookup_name_info object, for languages
    180    that do name searching using demangled names (C++/D/Go).  This is
    181    lazily constructed on demand.  */
    182 
    183 struct demangle_for_lookup_info final
    184 {
    185 public:
    186   demangle_for_lookup_info (const lookup_name_info &lookup_name,
    187 			    language lang);
    188 
    189   /* The demangled lookup name.  */
    190   const std::string &lookup_name () const
    191   { return m_demangled_name; }
    192 
    193 private:
    194   /* The demangled lookup name.  */
    195   std::string m_demangled_name;
    196 };
    197 
    198 /* Object that aggregates all information related to a symbol lookup
    199    name.  I.e., the name that is matched against the symbol's search
    200    name.  Caches per-language information so that it doesn't require
    201    recomputing it for every symbol comparison, like for example the
    202    Ada encoded name and the symbol's name hash for a given language.
    203    The object is conceptually immutable once constructed, and thus has
    204    no setters.  This is to prevent some code path from tweaking some
    205    property of the lookup name for some local reason and accidentally
    206    altering the results of any continuing search(es).
    207    lookup_name_info objects are generally passed around as a const
    208    reference to reinforce that.  (They're not passed around by value
    209    because they're not small.)  */
    210 class lookup_name_info final
    211 {
    212  public:
    213   /* We delete this overload so that the callers are required to
    214      explicitly handle the lifetime of the name.  */
    215   lookup_name_info (std::string &&name,
    216 		    symbol_name_match_type match_type,
    217 		    bool completion_mode = false,
    218 		    bool ignore_parameters = false) = delete;
    219 
    220   /* This overload requires that NAME have a lifetime at least as long
    221      as the lifetime of this object.  */
    222   lookup_name_info (const std::string &name,
    223 		    symbol_name_match_type match_type,
    224 		    bool completion_mode = false,
    225 		    bool ignore_parameters = false)
    226     : m_match_type (match_type),
    227       m_completion_mode (completion_mode),
    228       m_ignore_parameters (ignore_parameters),
    229       m_name (name)
    230   {}
    231 
    232   /* This overload requires that NAME have a lifetime at least as long
    233      as the lifetime of this object.  */
    234   lookup_name_info (const char *name,
    235 		    symbol_name_match_type match_type,
    236 		    bool completion_mode = false,
    237 		    bool ignore_parameters = false)
    238     : m_match_type (match_type),
    239       m_completion_mode (completion_mode),
    240       m_ignore_parameters (ignore_parameters),
    241       m_name (name)
    242   {}
    243 
    244   /* Getters.  See description of each corresponding field.  */
    245   symbol_name_match_type match_type () const { return m_match_type; }
    246   bool completion_mode () const { return m_completion_mode; }
    247   std::string_view name () const { return m_name; }
    248   const bool ignore_parameters () const { return m_ignore_parameters; }
    249 
    250   /* Like the "name" method but guarantees that the returned string is
    251      \0-terminated.  */
    252   const char *c_str () const
    253   {
    254     /* Actually this is always guaranteed due to how the class is
    255        constructed.  */
    256     return m_name.data ();
    257   }
    258 
    259   /* Return a version of this lookup name that is usable with
    260      comparisons against symbols have no parameter info, such as
    261      psymbols and GDB index symbols.  */
    262   lookup_name_info make_ignore_params () const
    263   {
    264     return lookup_name_info (c_str (), m_match_type, m_completion_mode,
    265 			     true /* ignore params */);
    266   }
    267 
    268   /* Get the search name hash for searches in language LANG.  */
    269   unsigned int search_name_hash (language lang) const
    270   {
    271     /* Only compute each language's hash once.  */
    272     if (!m_demangled_hashes_p[lang])
    273       {
    274 	m_demangled_hashes[lang]
    275 	  = ::search_name_hash (lang, language_lookup_name (lang));
    276 	m_demangled_hashes_p[lang] = true;
    277       }
    278     return m_demangled_hashes[lang];
    279   }
    280 
    281   /* Get the search name for searches in language LANG.  */
    282   const char *language_lookup_name (language lang) const
    283   {
    284     switch (lang)
    285       {
    286       case language_ada:
    287 	return ada ().lookup_name ().c_str ();
    288       case language_cplus:
    289 	return cplus ().lookup_name ().c_str ();
    290       case language_d:
    291 	return d ().lookup_name ().c_str ();
    292       case language_go:
    293 	return go ().lookup_name ().c_str ();
    294       default:
    295 	return m_name.data ();
    296       }
    297   }
    298 
    299   /* A wrapper for ::split_name (see split-name.h) that splits this
    300      name, and that handles any language-specific peculiarities.  */
    301   std::vector<std::string_view> split_name (language lang) const
    302   {
    303     if (lang == language_ada)
    304       return ada ().split_name ();
    305     split_style style = split_style::NONE;
    306     switch (lang)
    307       {
    308       case language_cplus:
    309       case language_rust:
    310 	style = split_style::CXX;
    311 	break;
    312       case language_d:
    313       case language_go:
    314 	style = split_style::DOT_STYLE;
    315 	break;
    316       }
    317     return ::split_name (language_lookup_name (lang), style);
    318   }
    319 
    320   /* Get the Ada-specific lookup info.  */
    321   const ada_lookup_name_info &ada () const
    322   {
    323     maybe_init (m_ada);
    324     return *m_ada;
    325   }
    326 
    327   /* Get the C++-specific lookup info.  */
    328   const demangle_for_lookup_info &cplus () const
    329   {
    330     maybe_init (m_cplus, language_cplus);
    331     return *m_cplus;
    332   }
    333 
    334   /* Get the D-specific lookup info.  */
    335   const demangle_for_lookup_info &d () const
    336   {
    337     maybe_init (m_d, language_d);
    338     return *m_d;
    339   }
    340 
    341   /* Get the Go-specific lookup info.  */
    342   const demangle_for_lookup_info &go () const
    343   {
    344     maybe_init (m_go, language_go);
    345     return *m_go;
    346   }
    347 
    348   /* Get a reference to a lookup_name_info object that matches any
    349      symbol name.  */
    350   static const lookup_name_info &match_any ();
    351 
    352 private:
    353   /* Initialize FIELD, if not initialized yet.  */
    354   template<typename Field, typename... Args>
    355   void maybe_init (Field &field, Args&&... args) const
    356   {
    357     if (!field)
    358       field.emplace (*this, std::forward<Args> (args)...);
    359   }
    360 
    361   /* The lookup info as passed to the ctor.  */
    362   symbol_name_match_type m_match_type;
    363   bool m_completion_mode;
    364   bool m_ignore_parameters;
    365   std::string_view m_name;
    366 
    367   /* Language-specific info.  These fields are filled lazily the first
    368      time a lookup is done in the corresponding language.  They're
    369      mutable because lookup_name_info objects are typically passed
    370      around by const reference (see intro), and they're conceptually
    371      "cache" that can always be reconstructed from the non-mutable
    372      fields.  */
    373   mutable std::optional<ada_lookup_name_info> m_ada;
    374   mutable std::optional<demangle_for_lookup_info> m_cplus;
    375   mutable std::optional<demangle_for_lookup_info> m_d;
    376   mutable std::optional<demangle_for_lookup_info> m_go;
    377 
    378   /* The demangled hashes.  Stored in an array with one entry for each
    379      possible language.  The second array records whether we've
    380      already computed the each language's hash.  (These are separate
    381      arrays instead of a single array of optional<unsigned> to avoid
    382      alignment padding).  */
    383   mutable std::array<unsigned int, nr_languages> m_demangled_hashes;
    384   mutable std::array<bool, nr_languages> m_demangled_hashes_p {};
    385 };
    386 
    387 /* Comparison function for completion symbol lookup.
    388 
    389    Returns true if the symbol name matches against LOOKUP_NAME.
    390 
    391    SYMBOL_SEARCH_NAME should be a symbol's "search" name.
    392 
    393    On success and if non-NULL, COMP_MATCH_RES->match is set to point
    394    to the symbol name as should be presented to the user as a
    395    completion match list element.  In most languages, this is the same
    396    as the symbol's search name, but in some, like Ada, the display
    397    name is dynamically computed within the comparison routine.
    398 
    399    Also, on success and if non-NULL, COMP_MATCH_RES->match_for_lcd
    400    points the part of SYMBOL_SEARCH_NAME that was considered to match
    401    LOOKUP_NAME.  E.g., in C++, in linespec/wild mode, if the symbol is
    402    "foo::function()" and LOOKUP_NAME is "function(", MATCH_FOR_LCD
    403    points to "function()" inside SYMBOL_SEARCH_NAME.  */
    404 typedef bool (symbol_name_matcher_ftype)
    405   (const char *symbol_search_name,
    406    const lookup_name_info &lookup_name,
    407    completion_match_result *comp_match_res);
    408 
    409 /* Some of the structures in this file are space critical.
    410    The space-critical structures are:
    411 
    412      struct general_symbol_info
    413      struct symbol
    414      struct partial_symbol
    415 
    416    These structures are laid out to encourage good packing.
    417    They use ENUM_BITFIELD and short int fields, and they order the
    418    structure members so that fields less than a word are next
    419    to each other so they can be packed together.  */
    420 
    421 /* Rearranged: used ENUM_BITFIELD and rearranged field order in
    422    all the space critical structures (plus struct minimal_symbol).
    423    Memory usage dropped from 99360768 bytes to 90001408 bytes.
    424    I measured this with before-and-after tests of
    425    "HEAD-old-gdb -readnow HEAD-old-gdb" and
    426    "HEAD-new-gdb -readnow HEAD-old-gdb" on native i686-pc-linux-gnu,
    427    red hat linux 8, with LD_LIBRARY_PATH=/usr/lib/debug,
    428    typing "maint space 1" at the first command prompt.
    429 
    430    Here is another measurement (from andrew c):
    431      # no /usr/lib/debug, just plain glibc, like a normal user
    432      gdb HEAD-old-gdb
    433      (gdb) break internal_error
    434      (gdb) run
    435      (gdb) maint internal-error
    436      (gdb) backtrace
    437      (gdb) maint space 1
    438 
    439    gdb gdb_6_0_branch  2003-08-19  space used: 8896512
    440    gdb HEAD            2003-08-19  space used: 8904704
    441    gdb HEAD            2003-08-21  space used: 8396800 (+symtab.h)
    442    gdb HEAD            2003-08-21  space used: 8265728 (+gdbtypes.h)
    443 
    444    The third line shows the savings from the optimizations in symtab.h.
    445    The fourth line shows the savings from the optimizations in
    446    gdbtypes.h.  Both optimizations are in gdb HEAD now.
    447 
    448    --chastain 2003-08-21  */
    449 
    450 /* Define a structure for the information that is common to all symbol types,
    451    including minimal symbols, partial symbols, and full symbols.  In a
    452    multilanguage environment, some language specific information may need to
    453    be recorded along with each symbol.  */
    454 
    455 /* This structure is space critical.  See space comments at the top.  */
    456 
    457 struct general_symbol_info
    458 {
    459   /* Short version as to when to use which name accessor:
    460      Use natural_name () to refer to the name of the symbol in the original
    461      source code.  Use linkage_name () if you want to know what the linker
    462      thinks the symbol's name is.  Use print_name () for output.  Use
    463      demangled_name () if you specifically need to know whether natural_name ()
    464      and linkage_name () are different.  */
    465 
    466   const char *linkage_name () const
    467   { return m_name; }
    468 
    469   /* Return SYMBOL's "natural" name, i.e. the name that it was called in
    470      the original source code.  In languages like C++ where symbols may
    471      be mangled for ease of manipulation by the linker, this is the
    472      demangled name.  */
    473   const char *natural_name () const;
    474 
    475   /* Returns a version of the name of a symbol that is
    476      suitable for output.  In C++ this is the "demangled" form of the
    477      name if demangle is on and the "mangled" form of the name if
    478      demangle is off.  In other languages this is just the symbol name.
    479      The result should never be NULL.  Don't use this for internal
    480      purposes (e.g. storing in a hashtable): it's only suitable for output.  */
    481   const char *print_name () const
    482   { return demangle ? natural_name () : linkage_name (); }
    483 
    484   /* Return the demangled name for a symbol based on the language for
    485      that symbol.  If no demangled name exists, return NULL.  */
    486   const char *demangled_name () const;
    487 
    488   /* Returns the name to be used when sorting and searching symbols.
    489      In C++, we search for the demangled form of a name,
    490      and so sort symbols accordingly.  In Ada, however, we search by mangled
    491      name.  If there is no distinct demangled name, then this
    492      returns the same value (same pointer) as linkage_name ().  */
    493   const char *search_name () const;
    494 
    495   /* Set just the linkage name of a symbol; do not try to demangle
    496      it.  Used for constructs which do not have a mangled name,
    497      e.g. struct tags.  Unlike compute_and_set_names, linkage_name must
    498      be terminated and either already on the objfile's obstack or
    499      permanently allocated.  */
    500   void set_linkage_name (const char *linkage_name)
    501   { m_name = linkage_name; }
    502 
    503   /* Set the demangled name of this symbol to NAME.  NAME must be
    504      already correctly allocated.  If the symbol's language is Ada,
    505      then the name is ignored and the obstack is set.  */
    506   void set_demangled_name (const char *name, struct obstack *obstack);
    507 
    508   enum language language () const
    509   { return m_language; }
    510 
    511   /* Initializes the language dependent portion of a symbol
    512      depending upon the language for the symbol.  */
    513   void set_language (enum language language, struct obstack *obstack);
    514 
    515   /* Set the linkage and natural names of a symbol, by demangling
    516      the linkage name.  If linkage_name may not be nullterminated,
    517      copy_name must be set to true.  */
    518   void compute_and_set_names (std::string_view linkage_name, bool copy_name,
    519 			      struct objfile_per_bfd_storage *per_bfd,
    520 			      std::optional<hashval_t> hash
    521 				= std::optional<hashval_t> ());
    522 
    523   CORE_ADDR value_address () const
    524   {
    525     return m_value.address;
    526   }
    527 
    528   void set_value_address (CORE_ADDR address)
    529   {
    530     m_value.address = address;
    531   }
    532 
    533   /* Return the unrelocated address of this symbol.  */
    534   unrelocated_addr unrelocated_address () const
    535   {
    536     return m_value.unrel_addr;
    537   }
    538 
    539   /* Set the unrelocated address of this symbol.  */
    540   void set_unrelocated_address (unrelocated_addr addr)
    541   {
    542     m_value.unrel_addr = addr;
    543   }
    544 
    545   /* Name of the symbol.  This is a required field.  Storage for the
    546      name is allocated on the objfile_obstack for the associated
    547      objfile.  For languages like C++ that make a distinction between
    548      the mangled name and demangled name, this is the mangled
    549      name.  */
    550 
    551   const char *m_name;
    552 
    553   /* Value of the symbol.  Which member of this union to use, and what
    554      it means, depends on what kind of symbol this is and its
    555      SYMBOL_CLASS.  See comments there for more details.  All of these
    556      are in host byte order (though what they point to might be in
    557      target byte order, e.g. LOC_CONST_BYTES).  */
    558 
    559   union
    560   {
    561     LONGEST ivalue;
    562 
    563     const struct block *block;
    564 
    565     const gdb_byte *bytes;
    566 
    567     CORE_ADDR address;
    568 
    569     /* The address, if unrelocated.  An unrelocated symbol does not
    570        have the runtime section offset applied.  */
    571     unrelocated_addr unrel_addr;
    572 
    573     /* A common block.  Used with LOC_COMMON_BLOCK.  */
    574 
    575     const struct common_block *common_block;
    576 
    577     /* For opaque typedef struct chain.  */
    578 
    579     struct symbol *chain;
    580   }
    581   m_value;
    582 
    583   /* Since one and only one language can apply, wrap the language specific
    584      information inside a union.  */
    585 
    586   union
    587   {
    588     /* A pointer to an obstack that can be used for storage associated
    589        with this symbol.  This is only used by Ada, and only when the
    590        'ada_mangled' field is zero.  */
    591     struct obstack *obstack;
    592 
    593     /* This is used by languages which wish to store a demangled name.
    594        currently used by Ada, C++, and Objective C.  */
    595     const char *demangled_name;
    596   }
    597   language_specific;
    598 
    599   /* Record the source code language that applies to this symbol.
    600      This is used to select one of the fields from the language specific
    601      union above.  */
    602 
    603   ENUM_BITFIELD(language) m_language : LANGUAGE_BITS;
    604 
    605   /* This is only used by Ada.  If set, then the 'demangled_name' field
    606      of language_specific is valid.  Otherwise, the 'obstack' field is
    607      valid.  */
    608   unsigned int ada_mangled : 1;
    609 
    610   /* Which section is this symbol in?  This is an index into
    611      section_offsets for this objfile.  Negative means that the symbol
    612      does not get relocated relative to a section.  */
    613 
    614   short m_section;
    615 
    616   /* Set the index into the obj_section list (within the containing
    617      objfile) for the section that contains this symbol.  See M_SECTION
    618      for more details.  */
    619 
    620   void set_section_index (short idx)
    621   { m_section = idx; }
    622 
    623   /* Return the index into the obj_section list (within the containing
    624      objfile) for the section that contains this symbol.  See M_SECTION
    625      for more details.  */
    626 
    627   short section_index () const
    628   { return m_section; }
    629 
    630   /* Return the obj_section from OBJFILE for this symbol.  The symbol
    631      returned is based on the SECTION member variable, and can be nullptr
    632      if SECTION is negative.  */
    633 
    634   struct obj_section *obj_section (const struct objfile *objfile) const;
    635 };
    636 
    637 extern CORE_ADDR symbol_overlayed_address (CORE_ADDR, struct obj_section *);
    638 
    639 /* Try to determine the demangled name for a symbol, based on the
    640    language of that symbol.  If the language is set to language_auto,
    641    it will attempt to find any demangling algorithm that works and
    642    then set the language appropriately.  The returned name is allocated
    643    by the demangler and should be xfree'd.  */
    644 
    645 extern gdb::unique_xmalloc_ptr<char> symbol_find_demangled_name
    646      (struct general_symbol_info *gsymbol, const char *mangled);
    647 
    648 /* Return true if NAME matches the "search" name of GSYMBOL, according
    649    to the symbol's language.  */
    650 extern bool symbol_matches_search_name
    651   (const struct general_symbol_info *gsymbol,
    652    const lookup_name_info &name);
    653 
    654 /* Compute the hash of the given symbol search name of a symbol of
    655    language LANGUAGE.  */
    656 extern unsigned int search_name_hash (enum language language,
    657 				      const char *search_name);
    658 
    659 /* Classification types for a minimal symbol.  These should be taken as
    660    "advisory only", since if gdb can't easily figure out a
    661    classification it simply selects mst_unknown.  It may also have to
    662    guess when it can't figure out which is a better match between two
    663    types (mst_data versus mst_bss) for example.  Since the minimal
    664    symbol info is sometimes derived from the BFD library's view of a
    665    file, we need to live with what information bfd supplies.  */
    666 
    667 enum minimal_symbol_type
    668 {
    669   mst_unknown = 0,		/* Unknown type, the default */
    670   mst_text,			/* Generally executable instructions */
    671 
    672   /* A GNU ifunc symbol, in the .text section.  GDB uses to know
    673      whether the user is setting a breakpoint on a GNU ifunc function,
    674      and thus GDB needs to actually set the breakpoint on the target
    675      function.  It is also used to know whether the program stepped
    676      into an ifunc resolver -- the resolver may get a separate
    677      symbol/alias under a different name, but it'll have the same
    678      address as the ifunc symbol.  */
    679   mst_text_gnu_ifunc,           /* Executable code returning address
    680 				   of executable code */
    681 
    682   /* A GNU ifunc function descriptor symbol, in a data section
    683      (typically ".opd").  Seen on architectures that use function
    684      descriptors, like PPC64/ELFv1.  In this case, this symbol's value
    685      is the address of the descriptor.  There'll be a corresponding
    686      mst_text_gnu_ifunc synthetic symbol for the text/entry
    687      address.  */
    688   mst_data_gnu_ifunc,		/* Executable code returning address
    689 				   of executable code */
    690 
    691   mst_slot_got_plt,		/* GOT entries for .plt sections */
    692   mst_data,			/* Generally initialized data */
    693   mst_bss,			/* Generally uninitialized data */
    694   mst_abs,			/* Generally absolute (nonrelocatable) */
    695   /* GDB uses mst_solib_trampoline for the start address of a shared
    696      library trampoline entry.  Breakpoints for shared library functions
    697      are put there if the shared library is not yet loaded.
    698      After the shared library is loaded, lookup_minimal_symbol will
    699      prefer the minimal symbol from the shared library (usually
    700      a mst_text symbol) over the mst_solib_trampoline symbol, and the
    701      breakpoints will be moved to their true address in the shared
    702      library via breakpoint_re_set.  */
    703   mst_solib_trampoline,		/* Shared library trampoline code */
    704   /* For the mst_file* types, the names are only guaranteed to be unique
    705      within a given .o file.  */
    706   mst_file_text,		/* Static version of mst_text */
    707   mst_file_data,		/* Static version of mst_data */
    708   mst_file_bss,			/* Static version of mst_bss */
    709   nr_minsym_types
    710 };
    711 
    712 /* The number of enum minimal_symbol_type values, with some padding for
    713    reasonable growth.  */
    714 #define MINSYM_TYPE_BITS 4
    715 static_assert (nr_minsym_types <= (1 << MINSYM_TYPE_BITS));
    716 
    717 /* Define a simple structure used to hold some very basic information about
    718    all defined global symbols (text, data, bss, abs, etc).  The only required
    719    information is the general_symbol_info.
    720 
    721    In many cases, even if a file was compiled with no special options for
    722    debugging at all, as long as was not stripped it will contain sufficient
    723    information to build a useful minimal symbol table using this structure.
    724    Even when a file contains enough debugging information to build a full
    725    symbol table, these minimal symbols are still useful for quickly mapping
    726    between names and addresses, and vice versa.  They are also sometimes
    727    used to figure out what full symbol table entries need to be read in.  */
    728 
    729 struct minimal_symbol : public general_symbol_info
    730 {
    731   LONGEST value_longest () const
    732   {
    733     return m_value.ivalue;
    734   }
    735 
    736   /* The relocated address of the minimal symbol, using the section
    737      offsets from OBJFILE.  */
    738   CORE_ADDR value_address (objfile *objfile) const;
    739 
    740   /* It does not make sense to call this for minimal symbols, as they
    741      are stored unrelocated.  */
    742   CORE_ADDR value_address () const = delete;
    743 
    744   /* The unrelocated address of the minimal symbol.  */
    745   unrelocated_addr unrelocated_address () const
    746   {
    747     return m_value.unrel_addr;
    748   }
    749 
    750   /* The unrelocated address just after the end of the the minimal
    751      symbol.  */
    752   unrelocated_addr unrelocated_end_address () const
    753   {
    754     return unrelocated_addr (CORE_ADDR (unrelocated_address ()) + size ());
    755   }
    756 
    757   /* Return this minimal symbol's type.  */
    758 
    759   minimal_symbol_type type () const
    760   {
    761     return m_type;
    762   }
    763 
    764   /* Set this minimal symbol's type.  */
    765 
    766   void set_type (minimal_symbol_type type)
    767   {
    768     m_type = type;
    769   }
    770 
    771   /* Return this minimal symbol's size.  */
    772 
    773   unsigned long size () const
    774   {
    775     return m_size;
    776   }
    777 
    778   /* Set this minimal symbol's size.  */
    779 
    780   void set_size (unsigned long size)
    781   {
    782     m_size = size;
    783     m_has_size = 1;
    784   }
    785 
    786   /* Return true if this minimal symbol's size is known.  */
    787 
    788   bool has_size () const
    789   {
    790     return m_has_size;
    791   }
    792 
    793   /* Return this minimal symbol's first target-specific flag.  */
    794 
    795   bool target_flag_1 () const
    796   {
    797     return m_target_flag_1;
    798   }
    799 
    800   /* Set this minimal symbol's first target-specific flag.  */
    801 
    802   void set_target_flag_1 (bool target_flag_1)
    803   {
    804     m_target_flag_1 = target_flag_1;
    805   }
    806 
    807   /* Return this minimal symbol's second target-specific flag.  */
    808 
    809   bool target_flag_2 () const
    810   {
    811     return m_target_flag_2;
    812   }
    813 
    814   /* Set this minimal symbol's second target-specific flag.  */
    815 
    816   void set_target_flag_2 (bool target_flag_2)
    817   {
    818     m_target_flag_2 = target_flag_2;
    819   }
    820 
    821   /* Size of this symbol.  dbx_end_psymtab in dbxread.c uses this
    822      information to calculate the end of the partial symtab based on the
    823      address of the last symbol plus the size of the last symbol.  */
    824 
    825   unsigned long m_size;
    826 
    827   /* Which source file is this symbol in?  Only relevant for mst_file_*.  */
    828   const char *filename;
    829 
    830   /* Classification type for this minimal symbol.  */
    831 
    832   ENUM_BITFIELD(minimal_symbol_type) m_type : MINSYM_TYPE_BITS;
    833 
    834   /* Non-zero if this symbol was created by gdb.
    835      Such symbols do not appear in the output of "info var|fun".  */
    836   unsigned int created_by_gdb : 1;
    837 
    838   /* Two flag bits provided for the use of the target.  */
    839   unsigned int m_target_flag_1 : 1;
    840   unsigned int m_target_flag_2 : 1;
    841 
    842   /* Nonzero iff the size of the minimal symbol has been set.
    843      Symbol size information can sometimes not be determined, because
    844      the object file format may not carry that piece of information.  */
    845   unsigned int m_has_size : 1;
    846 
    847   /* Non-zero if this symbol ever had its demangled name set (even if
    848      it was set to NULL).  */
    849   unsigned int name_set : 1;
    850 
    851   /* Minimal symbols with the same hash key are kept on a linked
    852      list.  This is the link.  */
    853 
    854   struct minimal_symbol *hash_next;
    855 
    856   /* Minimal symbols are stored in two different hash tables.  This is
    857      the `next' pointer for the demangled hash table.  */
    858 
    859   struct minimal_symbol *demangled_hash_next;
    860 
    861   /* True if this symbol is of some data type.  */
    862 
    863   bool data_p () const;
    864 
    865   /* True if MSYMBOL is of some text type.  */
    866 
    867   bool text_p () const;
    868 
    869   /* For data symbols only, given an objfile, if 'maybe_copied'
    870      evaluates to 'true' for that objfile, then the symbol might be
    871      subject to copy relocation.  In this case, a minimal symbol
    872      matching the symbol's linkage name is first looked for in the
    873      main objfile.  If found, then that address is used; otherwise the
    874      address in this symbol is used.  */
    875 
    876   bool maybe_copied (objfile *objfile) const;
    877 
    878 private:
    879   /* Return the address of this minimal symbol, in the context of OBJF.  The
    880      MAYBE_COPIED flag must be set.  If the minimal symbol appears in the
    881      main program's minimal symbols, then that minsym's address is
    882      returned; otherwise, this minimal symbol's address is returned.  */
    883   CORE_ADDR get_maybe_copied_address (objfile *objf) const;
    884 };
    885 
    886 #include "minsyms.h"
    887 
    888 
    889 
    891 /* Represent one symbol name; a variable, constant, function or typedef.  */
    892 
    893 /* Different name domains for symbols.  Looking up a symbol specifies a
    894    domain and ignores symbol definitions in other name domains.  */
    895 
    896 enum domain_enum
    897 {
    898 #define SYM_DOMAIN(X) X ## _DOMAIN,
    899 #include "sym-domains.def"
    900 #undef SYM_DOMAIN
    901 };
    902 
    903 /* The number of bits in a symbol used to represent the domain.  */
    904 
    905 #define SYMBOL_DOMAIN_BITS 3
    906 
    907 extern const char *domain_name (domain_enum);
    908 
    909 /* Flags used for searching symbol tables.  These can be combined to
    910    let the search match multiple kinds of symbol.  */
    911 enum domain_search_flag
    912 {
    913 #define SYM_DOMAIN(X) \
    914   SEARCH_ ## X ## _DOMAIN = (1 << X ## _DOMAIN),
    915 #include "sym-domains.def"
    916 #undef SYM_DOMAIN
    917 };
    918 DEF_ENUM_FLAGS_TYPE (enum domain_search_flag, domain_search_flags);
    919 
    920 /* A convenience constant to search for any symbol.  */
    921 constexpr domain_search_flags SEARCH_ALL_DOMAINS
    922     = ((domain_search_flags) 0
    923 #define SYM_DOMAIN(X) | SEARCH_ ## X ## _DOMAIN
    924 #include "sym-domains.def"
    925 #undef SYM_DOMAIN
    926        );
    927 
    928 /* A convenience define for "C-like" name lookups, matching variables,
    929    types, and functions.  */
    930 #define SEARCH_VFT \
    931   (SEARCH_VAR_DOMAIN | SEARCH_FUNCTION_DOMAIN | SEARCH_TYPE_DOMAIN)
    932 
    933 /* Return a string representing the given flags.  */
    934 extern std::string domain_name (domain_search_flags);
    935 
    936 /* Convert a symbol domain to search flags.  */
    937 static inline domain_search_flags
    938 to_search_flags (domain_enum domain)
    939 {
    940   return domain_search_flags (domain_search_flag (1 << domain));
    941 }
    942 
    943 /* Return true if the given domain matches the given flags, false
    944    otherwise.  */
    945 static inline bool
    946 search_flags_matches (domain_search_flags flags, domain_enum domain)
    947 {
    948   return (flags & to_search_flags (domain)) != 0;
    949 }
    950 
    951 /* Some helpers for Python and Guile to account for backward
    952    compatibility.  Those exposed the domains for lookup as well as
    953    checking attributes of a symbol, so special encoding and decoding
    954    is needed to continue to support both uses.  Domain constants must
    955    remain unchanged, so that comparing a symbol's domain against a
    956    constant yields the correct result, so search symbols are
    957    distinguished by adding a flag bit.  This way, either sort of
    958    constant can be used for lookup.  */
    959 
    960 /* The flag bit.  */
    961 constexpr int SCRIPTING_SEARCH_FLAG = 0x8000;
    962 static_assert (SCRIPTING_SEARCH_FLAG > SEARCH_ALL_DOMAINS);
    963 
    964 /* Convert a domain constant to a "scripting domain".  */
    965 static constexpr inline int
    966 to_scripting_domain (domain_enum val)
    967 {
    968   return val;
    969 }
    970 
    971 /* Convert a search constant to a "scripting domain".  */
    972 static constexpr inline int
    973 to_scripting_domain (domain_search_flags val)
    974 {
    975   return SCRIPTING_SEARCH_FLAG | (int) val;
    976 }
    977 
    978 /* Convert from a "scripting domain" constant back to search flags.
    979    Throws an exception if VAL is not one of the allowable values.  */
    980 extern domain_search_flags from_scripting_domain (int val);
    981 
    982 /* An address-class says where to find the value of a symbol.  */
    983 
    984 enum address_class
    985 {
    986   /* Not used; catches errors.  */
    987 
    988   LOC_UNDEF,
    989 
    990   /* Value is constant int SYMBOL_VALUE, host byteorder.  */
    991 
    992   LOC_CONST,
    993 
    994   /* Value is at fixed address SYMBOL_VALUE_ADDRESS.  */
    995 
    996   LOC_STATIC,
    997 
    998   /* Value is in register.  SYMBOL_VALUE is the register number
    999      in the original debug format.  SYMBOL_REGISTER_OPS holds a
   1000      function that can be called to transform this into the
   1001      actual register number this represents in a specific target
   1002      architecture (gdbarch).
   1003 
   1004      For some symbol formats (stabs, for some compilers at least),
   1005      the compiler generates two symbols, an argument and a register.
   1006      In some cases we combine them to a single LOC_REGISTER in symbol
   1007      reading, but currently not for all cases (e.g. it's passed on the
   1008      stack and then loaded into a register).  */
   1009 
   1010   LOC_REGISTER,
   1011 
   1012   /* It's an argument; the value is at SYMBOL_VALUE offset in arglist.  */
   1013 
   1014   LOC_ARG,
   1015 
   1016   /* Value address is at SYMBOL_VALUE offset in arglist.  */
   1017 
   1018   LOC_REF_ARG,
   1019 
   1020   /* Value is in specified register.  Just like LOC_REGISTER except the
   1021      register holds the address of the argument instead of the argument
   1022      itself.  This is currently used for the passing of structs and unions
   1023      on sparc and hppa.  It is also used for call by reference where the
   1024      address is in a register, at least by mipsread.c.  */
   1025 
   1026   LOC_REGPARM_ADDR,
   1027 
   1028   /* Value is a local variable at SYMBOL_VALUE offset in stack frame.  */
   1029 
   1030   LOC_LOCAL,
   1031 
   1032   /* Value not used; definition in SYMBOL_TYPE.  Symbols in the domain
   1033      STRUCT_DOMAIN all have this class.  */
   1034 
   1035   LOC_TYPEDEF,
   1036 
   1037   /* Value is address SYMBOL_VALUE_ADDRESS in the code.  */
   1038 
   1039   LOC_LABEL,
   1040 
   1041   /* In a symbol table, value is SYMBOL_BLOCK_VALUE of a `struct block'.
   1042      In a partial symbol table, SYMBOL_VALUE_ADDRESS is the start address
   1043      of the block.  Function names have this class.  */
   1044 
   1045   LOC_BLOCK,
   1046 
   1047   /* Value is a constant byte-sequence pointed to by SYMBOL_VALUE_BYTES, in
   1048      target byte order.  */
   1049 
   1050   LOC_CONST_BYTES,
   1051 
   1052   /* Value is at fixed address, but the address of the variable has
   1053      to be determined from the minimal symbol table whenever the
   1054      variable is referenced.
   1055      This happens if debugging information for a global symbol is
   1056      emitted and the corresponding minimal symbol is defined
   1057      in another object file or runtime common storage.
   1058      The linker might even remove the minimal symbol if the global
   1059      symbol is never referenced, in which case the symbol remains
   1060      unresolved.
   1061 
   1062      GDB would normally find the symbol in the minimal symbol table if it will
   1063      not find it in the full symbol table.  But a reference to an external
   1064      symbol in a local block shadowing other definition requires full symbol
   1065      without possibly having its address available for LOC_STATIC.  Testcase
   1066      is provided as `gdb.dwarf2/dw2-unresolved.exp'.
   1067 
   1068      This is also used for thread local storage (TLS) variables.  In
   1069      this case, the address of the TLS variable must be determined
   1070      when the variable is referenced, from the msymbol's address,
   1071      which is the offset of the TLS variable in the thread local
   1072      storage of the shared library/object.  */
   1073 
   1074   LOC_UNRESOLVED,
   1075 
   1076   /* The variable does not actually exist in the program.
   1077      The value is ignored.  */
   1078 
   1079   LOC_OPTIMIZED_OUT,
   1080 
   1081   /* The variable's address is computed by a set of location
   1082      functions (see "struct symbol_computed_ops" below).  */
   1083   LOC_COMPUTED,
   1084 
   1085   /* The variable uses general_symbol_info->value->common_block field.
   1086      It also always uses COMMON_BLOCK_DOMAIN.  */
   1087   LOC_COMMON_BLOCK,
   1088 
   1089   /* Not used, just notes the boundary of the enum.  */
   1090   LOC_FINAL_VALUE
   1091 };
   1092 
   1093 /* The number of bits needed for values in enum address_class, with some
   1094    padding for reasonable growth, and room for run-time registered address
   1095    classes. See symtab.c:MAX_SYMBOL_IMPLS.
   1096    This is a #define so that we can have a assertion elsewhere to
   1097    verify that we have reserved enough space for synthetic address
   1098    classes.  */
   1099 #define SYMBOL_ACLASS_BITS 5
   1100 static_assert (LOC_FINAL_VALUE <= (1 << SYMBOL_ACLASS_BITS));
   1101 
   1102 /* The methods needed to implement LOC_COMPUTED.  These methods can
   1103    use the symbol's .aux_value for additional per-symbol information.
   1104 
   1105    At present this is only used to implement location expressions.  */
   1106 
   1107 struct symbol_computed_ops
   1108 {
   1109 
   1110   /* Return the value of the variable SYMBOL, relative to the stack
   1111      frame FRAME.  If the variable has been optimized out, return
   1112      zero.
   1113 
   1114      Iff `read_needs_frame (SYMBOL)' is not SYMBOL_NEEDS_FRAME, then
   1115      FRAME may be zero.  */
   1116 
   1117   struct value *(*read_variable) (struct symbol * symbol,
   1118 				  const frame_info_ptr &frame);
   1119 
   1120   /* Read variable SYMBOL like read_variable at (callee) FRAME's function
   1121      entry.  SYMBOL should be a function parameter, otherwise
   1122      NO_ENTRY_VALUE_ERROR will be thrown.  */
   1123   struct value *(*read_variable_at_entry) (struct symbol *symbol,
   1124 					   const frame_info_ptr &frame);
   1125 
   1126   /* Find the "symbol_needs_kind" value for the given symbol.  This
   1127      value determines whether reading the symbol needs memory (e.g., a
   1128      global variable), just registers (a thread-local), or a frame (a
   1129      local variable).  */
   1130   enum symbol_needs_kind (*get_symbol_read_needs) (struct symbol * symbol);
   1131 
   1132   /* Write to STREAM a natural-language description of the location of
   1133      SYMBOL, in the context of ADDR.  */
   1134   void (*describe_location) (struct symbol * symbol, CORE_ADDR addr,
   1135 			     struct ui_file * stream);
   1136 
   1137   /* Non-zero if this symbol's address computation is dependent on PC.  */
   1138   unsigned char location_has_loclist;
   1139 
   1140   /* Tracepoint support.  Append bytecodes to the tracepoint agent
   1141      expression AX that push the address of the object SYMBOL.  Set
   1142      VALUE appropriately.  Note --- for objects in registers, this
   1143      needn't emit any code; as long as it sets VALUE properly, then
   1144      the caller will generate the right code in the process of
   1145      treating this as an lvalue or rvalue.  */
   1146 
   1147   void (*tracepoint_var_ref) (struct symbol *symbol, struct agent_expr *ax,
   1148 			      struct axs_value *value);
   1149 
   1150   /* Generate C code to compute the location of SYMBOL.  The C code is
   1151      emitted to STREAM.  GDBARCH is the current architecture and PC is
   1152      the PC at which SYMBOL's location should be evaluated.
   1153      REGISTERS_USED is a vector indexed by register number; the
   1154      generator function should set an element in this vector if the
   1155      corresponding register is needed by the location computation.
   1156      The generated C code must assign the location to a local
   1157      variable; this variable's name is RESULT_NAME.  */
   1158 
   1159   void (*generate_c_location) (struct symbol *symbol, string_file *stream,
   1160 			       struct gdbarch *gdbarch,
   1161 			       std::vector<bool> &registers_used,
   1162 			       CORE_ADDR pc, const char *result_name);
   1163 
   1164 };
   1165 
   1166 /* The methods needed to implement LOC_BLOCK for inferior functions.
   1167    These methods can use the symbol's .aux_value for additional
   1168    per-symbol information.  */
   1169 
   1170 struct symbol_block_ops
   1171 {
   1172   /* Fill in *START and *LENGTH with DWARF block data of function
   1173      FRAMEFUNC valid for inferior context address PC.  Set *LENGTH to
   1174      zero if such location is not valid for PC; *START is left
   1175      uninitialized in such case.  */
   1176   void (*find_frame_base_location) (struct symbol *framefunc, CORE_ADDR pc,
   1177 				    const gdb_byte **start, size_t *length);
   1178 
   1179   /* Return the frame base address.  FRAME is the frame for which we want to
   1180      compute the base address while FRAMEFUNC is the symbol for the
   1181      corresponding function.  Return 0 on failure (FRAMEFUNC may not hold the
   1182      information we need).
   1183 
   1184      This method is designed to work with static links (nested functions
   1185      handling).  Static links are function properties whose evaluation returns
   1186      the frame base address for the enclosing frame.  However, there are
   1187      multiple definitions for "frame base": the content of the frame base
   1188      register, the CFA as defined by DWARF unwinding information, ...
   1189 
   1190      So this specific method is supposed to compute the frame base address such
   1191      as for nested functions, the static link computes the same address.  For
   1192      instance, considering DWARF debugging information, the static link is
   1193      computed with DW_AT_static_link and this method must be used to compute
   1194      the corresponding DW_AT_frame_base attribute.  */
   1195   CORE_ADDR (*get_frame_base) (struct symbol *framefunc,
   1196 			       const frame_info_ptr &frame);
   1197 
   1198   /* Return the block for this function.  So far, this is used to
   1199      implement function aliases.  So, if this is set, then it's not
   1200      necessary to set the other functions in this structure; and vice
   1201      versa.  */
   1202   const block *(*get_block_value) (const struct symbol *sym);
   1203 };
   1204 
   1205 /* Functions used with LOC_REGISTER and LOC_REGPARM_ADDR.  */
   1206 
   1207 struct symbol_register_ops
   1208 {
   1209   int (*register_number) (struct symbol *symbol, struct gdbarch *gdbarch);
   1210 };
   1211 
   1212 /* Objects of this type are used to find the address class and the
   1213    various computed ops vectors of a symbol.  */
   1214 
   1215 struct symbol_impl
   1216 {
   1217   enum address_class aclass;
   1218 
   1219   /* Used with LOC_COMPUTED.  */
   1220   const struct symbol_computed_ops *ops_computed;
   1221 
   1222   /* Used with LOC_BLOCK.  */
   1223   const struct symbol_block_ops *ops_block;
   1224 
   1225   /* Used with LOC_REGISTER and LOC_REGPARM_ADDR.  */
   1226   const struct symbol_register_ops *ops_register;
   1227 };
   1228 
   1229 /* struct symbol has some subclasses.  This enum is used to
   1230    differentiate between them.  */
   1231 
   1232 enum symbol_subclass_kind
   1233 {
   1234   /* Plain struct symbol.  */
   1235   SYMBOL_NONE,
   1236 
   1237   /* struct template_symbol.  */
   1238   SYMBOL_TEMPLATE,
   1239 
   1240   /* struct rust_vtable_symbol.  */
   1241   SYMBOL_RUST_VTABLE
   1242 };
   1243 
   1244 extern gdb::array_view<const struct symbol_impl> symbol_impls;
   1245 
   1246 /* This structure is space critical.  See space comments at the top.  */
   1247 
   1248 struct symbol : public general_symbol_info, public allocate_on_obstack<symbol>
   1249 {
   1250   symbol ()
   1251     /* Class-initialization of bitfields is only allowed in C++20.  */
   1252     : m_domain (UNDEF_DOMAIN),
   1253       m_aclass_index (0),
   1254       m_is_objfile_owned (1),
   1255       m_is_argument (0),
   1256       m_is_inlined (0),
   1257       maybe_copied (0),
   1258       subclass (SYMBOL_NONE),
   1259       m_artificial (false)
   1260     {
   1261       /* We can't use an initializer list for members of a base class, and
   1262 	 general_symbol_info needs to stay a POD type.  */
   1263       m_name = nullptr;
   1264       m_value.ivalue = 0;
   1265       language_specific.obstack = nullptr;
   1266       m_language = language_unknown;
   1267       ada_mangled = 0;
   1268       m_section = -1;
   1269       /* GCC 4.8.5 (on CentOS 7) does not correctly compile class-
   1270 	 initialization of unions, so we initialize it manually here.  */
   1271       owner.symtab = nullptr;
   1272     }
   1273 
   1274   symbol (const symbol &) = default;
   1275   symbol &operator= (const symbol &) = default;
   1276 
   1277   void set_aclass_index (unsigned int aclass_index)
   1278   {
   1279     m_aclass_index = aclass_index;
   1280   }
   1281 
   1282   const symbol_impl &impl () const
   1283   {
   1284     return symbol_impls[this->m_aclass_index];
   1285   }
   1286 
   1287   const symbol_block_ops *block_ops () const
   1288   {
   1289     return this->impl ().ops_block;
   1290   }
   1291 
   1292   const symbol_computed_ops *computed_ops () const
   1293   {
   1294     return this->impl ().ops_computed;
   1295   }
   1296 
   1297   const symbol_register_ops *register_ops () const
   1298   {
   1299     return this->impl ().ops_register;
   1300   }
   1301 
   1302   address_class aclass () const
   1303   {
   1304     return this->impl ().aclass;
   1305   }
   1306 
   1307   /* Return true if this symbol's domain matches FLAGS.  */
   1308   bool matches (domain_search_flags flags) const;
   1309 
   1310   domain_enum domain () const
   1311   {
   1312     return m_domain;
   1313   }
   1314 
   1315   void set_domain (domain_enum domain)
   1316   {
   1317     m_domain = domain;
   1318   }
   1319 
   1320   bool is_objfile_owned () const
   1321   {
   1322     return m_is_objfile_owned;
   1323   }
   1324 
   1325   void set_is_objfile_owned (bool is_objfile_owned)
   1326   {
   1327     m_is_objfile_owned = is_objfile_owned;
   1328   }
   1329 
   1330   bool is_argument () const
   1331   {
   1332     return m_is_argument;
   1333   }
   1334 
   1335   void set_is_argument (bool is_argument)
   1336   {
   1337     m_is_argument = is_argument;
   1338   }
   1339 
   1340   bool is_inlined () const
   1341   {
   1342     return m_is_inlined;
   1343   }
   1344 
   1345   void set_is_inlined (bool is_inlined)
   1346   {
   1347     m_is_inlined = is_inlined;
   1348   }
   1349 
   1350   bool is_cplus_template_function () const
   1351   {
   1352     return this->subclass == SYMBOL_TEMPLATE;
   1353   }
   1354 
   1355   struct type *type () const
   1356   {
   1357     return m_type;
   1358   }
   1359 
   1360   void set_type (struct type *type)
   1361   {
   1362     m_type = type;
   1363   }
   1364 
   1365   unsigned int line () const
   1366   {
   1367     return m_line;
   1368   }
   1369 
   1370   void set_line (unsigned int line)
   1371   {
   1372     m_line = line;
   1373   }
   1374 
   1375   LONGEST value_longest () const
   1376   {
   1377     return m_value.ivalue;
   1378   }
   1379 
   1380   void set_value_longest (LONGEST value)
   1381   {
   1382     m_value.ivalue = value;
   1383   }
   1384 
   1385   CORE_ADDR value_address () const
   1386   {
   1387     if (this->maybe_copied)
   1388       return this->get_maybe_copied_address ();
   1389     else
   1390       return m_value.address;
   1391   }
   1392 
   1393   void set_value_address (CORE_ADDR address)
   1394   {
   1395     m_value.address = address;
   1396   }
   1397 
   1398   const gdb_byte *value_bytes () const
   1399   {
   1400     return m_value.bytes;
   1401   }
   1402 
   1403   void set_value_bytes (const gdb_byte *bytes)
   1404   {
   1405     m_value.bytes = bytes;
   1406   }
   1407 
   1408   const common_block *value_common_block () const
   1409   {
   1410     return m_value.common_block;
   1411   }
   1412 
   1413   void set_value_common_block (const common_block *common_block)
   1414   {
   1415     m_value.common_block = common_block;
   1416   }
   1417 
   1418   const block *value_block () const;
   1419 
   1420   void set_value_block (const block *block)
   1421   {
   1422     m_value.block = block;
   1423   }
   1424 
   1425   symbol *value_chain () const
   1426   {
   1427     return m_value.chain;
   1428   }
   1429 
   1430   void set_value_chain (symbol *sym)
   1431   {
   1432     m_value.chain = sym;
   1433   }
   1434 
   1435   /* Return true if this symbol was marked as artificial.  */
   1436   bool is_artificial () const
   1437   {
   1438     return m_artificial;
   1439   }
   1440 
   1441   /* Set the 'artificial' flag on this symbol.  */
   1442   void set_is_artificial (bool artificial)
   1443   {
   1444     m_artificial = artificial;
   1445   }
   1446 
   1447   /* Return the OBJFILE of this symbol.  It is an error to call this
   1448      if is_objfile_owned is false, which only happens for
   1449      architecture-provided types.  */
   1450 
   1451   struct objfile *objfile () const;
   1452 
   1453   /* Return the ARCH of this symbol.  */
   1454 
   1455   struct gdbarch *arch () const;
   1456 
   1457   /* Return the symtab of this symbol.  It is an error to call this if
   1458      is_objfile_owned is false, which only happens for
   1459      architecture-provided types.  */
   1460 
   1461   struct symtab *symtab () const;
   1462 
   1463   /* Set the symtab of this symbol to SYMTAB.  It is an error to call
   1464      this if is_objfile_owned is false, which only happens for
   1465      architecture-provided types.  */
   1466 
   1467   void set_symtab (struct symtab *symtab);
   1468 
   1469   /* Data type of value */
   1470 
   1471   struct type *m_type = nullptr;
   1472 
   1473   /* The owner of this symbol.
   1474      Which one to use is defined by symbol.is_objfile_owned.  */
   1475 
   1476   union
   1477   {
   1478     /* The symbol table containing this symbol.  This is the file associated
   1479        with LINE.  It can be NULL during symbols read-in but it is never NULL
   1480        during normal operation.  */
   1481     struct symtab *symtab;
   1482 
   1483     /* For types defined by the architecture.  */
   1484     struct gdbarch *arch;
   1485   } owner;
   1486 
   1487   /* Domain code.  */
   1488 
   1489   ENUM_BITFIELD(domain_enum) m_domain : SYMBOL_DOMAIN_BITS;
   1490 
   1491   /* Address class.  This holds an index into the 'symbol_impls'
   1492      table.  The actual enum address_class value is stored there,
   1493      alongside any per-class ops vectors.  */
   1494 
   1495   unsigned int m_aclass_index : SYMBOL_ACLASS_BITS;
   1496 
   1497   /* If non-zero then symbol is objfile-owned, use owner.symtab.
   1498        Otherwise symbol is arch-owned, use owner.arch.  */
   1499 
   1500   unsigned int m_is_objfile_owned : 1;
   1501 
   1502   /* Whether this is an argument.  */
   1503 
   1504   unsigned m_is_argument : 1;
   1505 
   1506   /* Whether this is an inlined function (class LOC_BLOCK only).  */
   1507   unsigned m_is_inlined : 1;
   1508 
   1509   /* For LOC_STATIC only, if this is set, then the symbol might be
   1510      subject to copy relocation.  In this case, a minimal symbol
   1511      matching the symbol's linkage name is first looked for in the
   1512      main objfile.  If found, then that address is used; otherwise the
   1513      address in this symbol is used.  */
   1514 
   1515   unsigned maybe_copied : 1;
   1516 
   1517   /* The concrete type of this symbol.  */
   1518 
   1519   ENUM_BITFIELD (symbol_subclass_kind) subclass : 2;
   1520 
   1521   /* Whether this symbol is artificial.  */
   1522 
   1523   bool m_artificial : 1;
   1524 
   1525   /* Line number of this symbol's definition, except for inlined
   1526      functions.  For an inlined function (class LOC_BLOCK and
   1527      SYMBOL_INLINED set) this is the line number of the function's call
   1528      site.  Inlined function symbols are not definitions, and they are
   1529      never found by symbol table lookup.
   1530      If this symbol is arch-owned, LINE shall be zero.  */
   1531 
   1532   unsigned int m_line = 0;
   1533 
   1534   /* An arbitrary data pointer, allowing symbol readers to record
   1535      additional information on a per-symbol basis.  Note that this data
   1536      must be allocated using the same obstack as the symbol itself.  */
   1537   /* So far it is only used by:
   1538      LOC_COMPUTED: to find the location information
   1539      LOC_BLOCK (DWARF2 function): information used internally by the
   1540      DWARF 2 code --- specifically, the location expression for the frame
   1541      base for this function.  */
   1542   /* FIXME drow/2003-02-21: For the LOC_BLOCK case, it might be better
   1543      to add a magic symbol to the block containing this information,
   1544      or to have a generic debug info annotation slot for symbols.  */
   1545 
   1546   void *aux_value = nullptr;
   1547 
   1548   struct symbol *hash_next = nullptr;
   1549 
   1550 private:
   1551   /* Return the address of this symbol.  The MAYBE_COPIED flag must be set.
   1552    If the symbol appears in the main program's minimal symbols, then
   1553    that minsym's address is returned; otherwise, this symbol's address is
   1554    returned.  */
   1555  CORE_ADDR get_maybe_copied_address () const;
   1556 };
   1557 
   1558 /* Several lookup functions return both a symbol and the block in which the
   1559    symbol is found.  This structure is used in these cases.  */
   1560 
   1561 struct block_symbol
   1562 {
   1563   /* The symbol that was found, or NULL if no symbol was found.  */
   1564   struct symbol *symbol;
   1565 
   1566   /* If SYMBOL is not NULL, then this is the block in which the symbol is
   1567      defined.  */
   1568   const struct block *block;
   1569 };
   1570 
   1571 /* Note: There is no accessor macro for symbol.owner because it is
   1572    "private".  */
   1573 
   1574 #define SYMBOL_LOCATION_BATON(symbol)   (symbol)->aux_value
   1575 
   1576 inline const block *
   1577 symbol::value_block () const
   1578 {
   1579   if (const symbol_block_ops *block_ops = this->block_ops ();
   1580       block_ops != nullptr && block_ops->get_block_value != nullptr)
   1581     return block_ops->get_block_value (this);
   1582 
   1583   return m_value.block;
   1584 }
   1585 
   1586 extern int register_symbol_computed_impl (enum address_class,
   1587 					  const struct symbol_computed_ops *);
   1588 
   1589 extern int register_symbol_block_impl (enum address_class aclass,
   1590 				       const struct symbol_block_ops *ops);
   1591 
   1592 extern int register_symbol_register_impl (enum address_class,
   1593 					  const struct symbol_register_ops *);
   1594 
   1595 /* An instance of this type is used to represent a C++ template
   1596    function.  A symbol is really of this type iff
   1597    symbol::is_cplus_template_function is true.  */
   1598 
   1599 struct template_symbol : public symbol
   1600 {
   1601   /* The number of template arguments.  */
   1602   int n_template_arguments = 0;
   1603 
   1604   /* The template arguments.  This is an array with
   1605      N_TEMPLATE_ARGUMENTS elements.  */
   1606   struct symbol **template_arguments = nullptr;
   1607 };
   1608 
   1609 /* A symbol that represents a Rust virtual table object.  */
   1610 
   1611 struct rust_vtable_symbol : public symbol
   1612 {
   1613   /* The concrete type for which this vtable was created; that is, in
   1614      "impl Trait for Type", this is "Type".  */
   1615   struct type *concrete_type = nullptr;
   1616 };
   1617 
   1618 
   1619 /* Each item represents a line-->pc (or the reverse) mapping.  This is
   1621    somewhat more wasteful of space than one might wish, but since only
   1622    the files which are actually debugged are read in to core, we don't
   1623    waste much space.  */
   1624 
   1625 struct linetable_entry
   1626 {
   1627   /* Set the (unrelocated) PC for this entry.  */
   1628   void set_unrelocated_pc (unrelocated_addr pc)
   1629   { m_pc = pc; }
   1630 
   1631   /* Return the unrelocated PC for this entry.  */
   1632   unrelocated_addr unrelocated_pc () const
   1633   { return m_pc; }
   1634 
   1635   /* Return the relocated PC for this entry.  */
   1636   CORE_ADDR pc (const struct objfile *objfile) const;
   1637 
   1638   bool operator< (const linetable_entry &other) const
   1639   {
   1640     if (m_pc == other.m_pc
   1641 	&& (line != 0) != (other.line != 0))
   1642       return line == 0;
   1643     return m_pc < other.m_pc;
   1644   }
   1645 
   1646   /* Two entries are equal if they have the same line and PC.  The
   1647      other members are ignored.  */
   1648   bool operator== (const linetable_entry &other) const
   1649   { return line == other.line && m_pc == other.m_pc; }
   1650 
   1651   /* The line number for this entry.  */
   1652   int line;
   1653 
   1654   /* True if this PC is a good location to place a breakpoint for LINE.  */
   1655   bool is_stmt : 1;
   1656 
   1657   /* True if this location is a good location to place a breakpoint after a
   1658      function prologue.  */
   1659   bool prologue_end : 1;
   1660 
   1661   /* True if this location marks the start of the epilogue.  */
   1662   bool epilogue_begin : 1;
   1663 
   1664 private:
   1665 
   1666   /* The address for this entry.  */
   1667   unrelocated_addr m_pc;
   1668 };
   1669 
   1670 /* The order of entries in the linetable is significant.  They should
   1671    be sorted by increasing values of the pc field.  If there is more than
   1672    one entry for a given pc, then I'm not sure what should happen (and
   1673    I not sure whether we currently handle it the best way).
   1674 
   1675    Example: a C for statement generally looks like this
   1676 
   1677    10   0x100   - for the init/test part of a for stmt.
   1678    20   0x200
   1679    30   0x300
   1680    10   0x400   - for the increment part of a for stmt.
   1681 
   1682    If an entry has a line number of zero, it marks the start of a PC
   1683    range for which no line number information is available.  It is
   1684    acceptable, though wasteful of table space, for such a range to be
   1685    zero length.  */
   1686 
   1687 struct linetable
   1688 {
   1689   int nitems;
   1690 
   1691   /* Actually NITEMS elements.  If you don't like this use of the
   1692      `struct hack', you can shove it up your ANSI (seriously, if the
   1693      committee tells us how to do it, we can probably go along).  */
   1694   struct linetable_entry item[1];
   1695 };
   1696 
   1697 /* How to relocate the symbols from each section in a symbol file.
   1698    The ordering and meaning of the offsets is file-type-dependent;
   1699    typically it is indexed by section numbers or symbol types or
   1700    something like that.  */
   1701 
   1702 typedef std::vector<CORE_ADDR> section_offsets;
   1703 
   1704 /* Each source file or header is represented by a struct symtab.
   1705    The name "symtab" is historical, another name for it is "filetab".
   1706    These objects are chained through the `next' field.  */
   1707 
   1708 struct symtab
   1709 {
   1710   struct compunit_symtab *compunit () const
   1711   {
   1712     return m_compunit;
   1713   }
   1714 
   1715   void set_compunit (struct compunit_symtab *compunit)
   1716   {
   1717     m_compunit = compunit;
   1718   }
   1719 
   1720   const struct linetable *linetable () const
   1721   {
   1722     return m_linetable;
   1723   }
   1724 
   1725   void set_linetable (const struct linetable *linetable)
   1726   {
   1727     m_linetable = linetable;
   1728   }
   1729 
   1730   enum language language () const
   1731   {
   1732     return m_language;
   1733   }
   1734 
   1735   void set_language (enum language language)
   1736   {
   1737     m_language = language;
   1738   }
   1739 
   1740   /* Unordered chain of all filetabs in the compunit,  with the exception
   1741      that the "main" source file is the first entry in the list.  */
   1742 
   1743   struct symtab *next;
   1744 
   1745   /* Backlink to containing compunit symtab.  */
   1746 
   1747   struct compunit_symtab *m_compunit;
   1748 
   1749   /* Table mapping core addresses to line numbers for this file.
   1750      Can be NULL if none.  Never shared between different symtabs.  */
   1751 
   1752   const struct linetable *m_linetable;
   1753 
   1754   /* Name of this source file, in a form appropriate to print to the user.
   1755 
   1756      This pointer is never nullptr.  */
   1757 
   1758   const char *filename;
   1759 
   1760   /* Filename for this source file, used as an identifier to link with
   1761      related objects such as associated macro_source_file objects.  It must
   1762      therefore match the name of any macro_source_file object created for this
   1763      source file.  The value can be the same as FILENAME if it is known to
   1764      follow that rule, or another form of the same file name, this is up to
   1765      the specific debug info reader.
   1766 
   1767      This pointer is never nullptr.*/
   1768   const char *filename_for_id;
   1769 
   1770   /* Language of this source file.  */
   1771 
   1772   enum language m_language;
   1773 
   1774   /* Full name of file as found by searching the source path.
   1775      NULL if not yet known.  */
   1776 
   1777   char *fullname;
   1778 };
   1779 
   1780 /* A range adapter to allowing iterating over all the file tables in a list.  */
   1781 
   1782 using symtab_range = next_range<symtab>;
   1783 
   1784 /* Compunit symtabs contain the actual "symbol table", aka blockvector, as well
   1785    as the list of all source files (what gdb has historically associated with
   1786    the term "symtab").
   1787    Additional information is recorded here that is common to all symtabs in a
   1788    compilation unit (DWARF or otherwise).
   1789 
   1790    Example:
   1791    For the case of a program built out of these files:
   1792 
   1793    foo.c
   1794      foo1.h
   1795      foo2.h
   1796    bar.c
   1797      foo1.h
   1798      bar.h
   1799 
   1800    This is recorded as:
   1801 
   1802    objfile -> foo.c(cu) -> bar.c(cu) -> NULL
   1803 		|            |
   1804 		v            v
   1805 	      foo.c        bar.c
   1806 		|            |
   1807 		v            v
   1808 	      foo1.h       foo1.h
   1809 		|            |
   1810 		v            v
   1811 	      foo2.h       bar.h
   1812 		|            |
   1813 		v            v
   1814 	       NULL         NULL
   1815 
   1816    where "foo.c(cu)" and "bar.c(cu)" are struct compunit_symtab objects,
   1817    and the files foo.c, etc. are struct symtab objects.  */
   1818 
   1819 struct compunit_symtab
   1820 {
   1821   struct objfile *objfile () const
   1822   {
   1823     return m_objfile;
   1824   }
   1825 
   1826   void set_objfile (struct objfile *objfile)
   1827   {
   1828     m_objfile = objfile;
   1829   }
   1830 
   1831   symtab_range filetabs () const
   1832   {
   1833     return symtab_range (m_filetabs);
   1834   }
   1835 
   1836   void add_filetab (symtab *filetab)
   1837   {
   1838     if (m_filetabs == nullptr)
   1839       {
   1840 	m_filetabs = filetab;
   1841 	m_last_filetab = filetab;
   1842       }
   1843     else
   1844       {
   1845 	m_last_filetab->next = filetab;
   1846 	m_last_filetab = filetab;
   1847       }
   1848   }
   1849 
   1850   const char *debugformat () const
   1851   {
   1852     return m_debugformat;
   1853   }
   1854 
   1855   void set_debugformat (const char *debugformat)
   1856   {
   1857     m_debugformat = debugformat;
   1858   }
   1859 
   1860   const char *producer () const
   1861   {
   1862     return m_producer;
   1863   }
   1864 
   1865   void set_producer (const char *producer)
   1866   {
   1867     m_producer = producer;
   1868   }
   1869 
   1870   const char *dirname () const
   1871   {
   1872     return m_dirname;
   1873   }
   1874 
   1875   void set_dirname (const char *dirname)
   1876   {
   1877     m_dirname = dirname;
   1878   }
   1879 
   1880   struct blockvector *blockvector ()
   1881   {
   1882     return m_blockvector;
   1883   }
   1884 
   1885   const struct blockvector *blockvector () const
   1886   {
   1887     return m_blockvector;
   1888   }
   1889 
   1890   void set_blockvector (struct blockvector *blockvector)
   1891   {
   1892     m_blockvector = blockvector;
   1893   }
   1894 
   1895   bool locations_valid () const
   1896   {
   1897     return m_locations_valid;
   1898   }
   1899 
   1900   void set_locations_valid (bool locations_valid)
   1901   {
   1902     m_locations_valid = locations_valid;
   1903   }
   1904 
   1905   bool epilogue_unwind_valid () const
   1906   {
   1907     return m_epilogue_unwind_valid;
   1908   }
   1909 
   1910   void set_epilogue_unwind_valid (bool epilogue_unwind_valid)
   1911   {
   1912     m_epilogue_unwind_valid = epilogue_unwind_valid;
   1913   }
   1914 
   1915   struct macro_table *macro_table () const
   1916   {
   1917     return m_macro_table;
   1918   }
   1919 
   1920   void set_macro_table (struct macro_table *macro_table)
   1921   {
   1922     m_macro_table = macro_table;
   1923   }
   1924 
   1925   /* Make PRIMARY_FILETAB the primary filetab of this compunit symtab.
   1926 
   1927      PRIMARY_FILETAB must already be a filetab of this compunit symtab.  */
   1928 
   1929   void set_primary_filetab (symtab *primary_filetab);
   1930 
   1931   /* Return the primary filetab of the compunit.  */
   1932   symtab *primary_filetab () const;
   1933 
   1934   /* Set m_call_site_htab.  */
   1935   void set_call_site_htab (htab_t call_site_htab);
   1936 
   1937   /* Find call_site info for PC.  */
   1938   call_site *find_call_site (CORE_ADDR pc) const;
   1939 
   1940   /* Return the language of this compunit_symtab.  */
   1941   enum language language () const;
   1942 
   1943   /* Unordered chain of all compunit symtabs of this objfile.  */
   1944   struct compunit_symtab *next;
   1945 
   1946   /* Object file from which this symtab information was read.  */
   1947   struct objfile *m_objfile;
   1948 
   1949   /* Name of the symtab.
   1950      This is *not* intended to be a usable filename, and is
   1951      for debugging purposes only.  */
   1952   const char *name;
   1953 
   1954   /* Unordered list of file symtabs, except that by convention the "main"
   1955      source file (e.g., .c, .cc) is guaranteed to be first.
   1956      Each symtab is a file, either the "main" source file (e.g., .c, .cc)
   1957      or header (e.g., .h).  */
   1958   symtab *m_filetabs;
   1959 
   1960   /* Last entry in FILETABS list.
   1961      Subfiles are added to the end of the list so they accumulate in order,
   1962      with the main source subfile living at the front.
   1963      The main reason is so that the main source file symtab is at the head
   1964      of the list, and the rest appear in order for debugging convenience.  */
   1965   symtab *m_last_filetab;
   1966 
   1967   /* Non-NULL string that identifies the format of the debugging information,
   1968      such as "stabs", "dwarf 1", "dwarf 2", "coff", etc.  This is mostly useful
   1969      for automated testing of gdb but may also be information that is
   1970      useful to the user.  */
   1971   const char *m_debugformat;
   1972 
   1973   /* String of producer version information, or NULL if we don't know.  */
   1974   const char *m_producer;
   1975 
   1976   /* Directory in which it was compiled, or NULL if we don't know.  */
   1977   const char *m_dirname;
   1978 
   1979   /* List of all symbol scope blocks for this symtab.  It is shared among
   1980      all symtabs in a given compilation unit.  */
   1981   struct blockvector *m_blockvector;
   1982 
   1983   /* Symtab has been compiled with both optimizations and debug info so that
   1984      GDB may stop skipping prologues as variables locations are valid already
   1985      at function entry points.  */
   1986   unsigned int m_locations_valid : 1;
   1987 
   1988   /* DWARF unwinder for this CU is valid even for epilogues (PC at the return
   1989      instruction).  This is supported by GCC since 4.5.0.  */
   1990   unsigned int m_epilogue_unwind_valid : 1;
   1991 
   1992   /* struct call_site entries for this compilation unit or NULL.  */
   1993   htab_t m_call_site_htab;
   1994 
   1995   /* The macro table for this symtab.  Like the blockvector, this
   1996      is shared between different symtabs in a given compilation unit.
   1997      It's debatable whether it *should* be shared among all the symtabs in
   1998      the given compilation unit, but it currently is.  */
   1999   struct macro_table *m_macro_table;
   2000 
   2001   /* If non-NULL, then this points to a NULL-terminated vector of
   2002      included compunits.  When searching the static or global
   2003      block of this compunit, the corresponding block of all
   2004      included compunits will also be searched.  Note that this
   2005      list must be flattened -- the symbol reader is responsible for
   2006      ensuring that this vector contains the transitive closure of all
   2007      included compunits.  */
   2008   struct compunit_symtab **includes;
   2009 
   2010   /* If this is an included compunit, this points to one includer
   2011      of the table.  This user is considered the canonical compunit
   2012      containing this one.  An included compunit may itself be
   2013      included by another.  */
   2014   struct compunit_symtab *user;
   2015 };
   2016 
   2017 using compunit_symtab_range = next_range<compunit_symtab>;
   2018 
   2019 /* Return true if this symtab is the "main" symtab of its compunit_symtab.  */
   2020 
   2021 static inline bool
   2022 is_main_symtab_of_compunit_symtab (struct symtab *symtab)
   2023 {
   2024   return symtab == symtab->compunit ()->primary_filetab ();
   2025 }
   2026 
   2027 /* Return true if epilogue unwind info of CUST is valid.  */
   2028 
   2029 static inline bool
   2030 compunit_epilogue_unwind_valid (struct compunit_symtab *cust)
   2031 {
   2032   /* In absence of producer information, assume epilogue unwind info is
   2033      valid.  */
   2034   if (cust == nullptr)
   2035     return true;
   2036 
   2037   return cust->epilogue_unwind_valid ();
   2038 }
   2039 
   2040 
   2042 /* The virtual function table is now an array of structures which have the
   2043    form { int16 offset, delta; void *pfn; }.
   2044 
   2045    In normal virtual function tables, OFFSET is unused.
   2046    DELTA is the amount which is added to the apparent object's base
   2047    address in order to point to the actual object to which the
   2048    virtual function should be applied.
   2049    PFN is a pointer to the virtual function.
   2050 
   2051    Note that this macro is g++ specific (FIXME).  */
   2052 
   2053 #define VTBL_FNADDR_OFFSET 2
   2054 
   2055 /* External variables and functions for the objects described above.  */
   2056 
   2057 /* True if we are nested inside psymtab_to_symtab.  */
   2058 
   2059 extern int currently_reading_symtab;
   2060 
   2061 /* symtab.c lookup functions */
   2062 
   2063 extern const char multiple_symbols_ask[];
   2064 extern const char multiple_symbols_all[];
   2065 extern const char multiple_symbols_cancel[];
   2066 
   2067 const char *multiple_symbols_select_mode (void);
   2068 
   2069 /* lookup a symbol table by source file name.  */
   2070 
   2071 extern struct symtab *lookup_symtab (const char *);
   2072 
   2073 /* An object of this type is passed as the 'is_a_field_of_this'
   2074    argument to lookup_symbol and lookup_symbol_in_language.  */
   2075 
   2076 struct field_of_this_result
   2077 {
   2078   /* The type in which the field was found.  If this is NULL then the
   2079      symbol was not found in 'this'.  If non-NULL, then one of the
   2080      other fields will be non-NULL as well.  */
   2081 
   2082   struct type *type;
   2083 
   2084   /* If the symbol was found as an ordinary field of 'this', then this
   2085      is non-NULL and points to the particular field.  */
   2086 
   2087   struct field *field;
   2088 
   2089   /* If the symbol was found as a function field of 'this', then this
   2090      is non-NULL and points to the particular field.  */
   2091 
   2092   struct fn_fieldlist *fn_field;
   2093 };
   2094 
   2095 /* Find the definition for a specified symbol name NAME
   2096    in domain DOMAIN in language LANGUAGE, visible from lexical block BLOCK
   2097    if non-NULL or from global/static blocks if BLOCK is NULL.
   2098    Returns the struct symbol pointer, or NULL if no symbol is found.
   2099    C++: if IS_A_FIELD_OF_THIS is non-NULL on entry, check to see if
   2100    NAME is a field of the current implied argument `this'.  If so fill in the
   2101    fields of IS_A_FIELD_OF_THIS, otherwise the fields are set to NULL.
   2102    The symbol's section is fixed up if necessary.  */
   2103 
   2104 extern struct block_symbol
   2105   lookup_symbol_in_language (const char *,
   2106 			     const struct block *,
   2107 			     const domain_search_flags,
   2108 			     enum language,
   2109 			     struct field_of_this_result *);
   2110 
   2111 /* Same as lookup_symbol_in_language, but using the current language.  */
   2112 
   2113 extern struct block_symbol lookup_symbol (const char *,
   2114 					  const struct block *,
   2115 					  const domain_search_flags,
   2116 					  struct field_of_this_result *);
   2117 
   2118 /* Find the definition for a specified symbol search name in domain
   2119    DOMAIN, visible from lexical block BLOCK if non-NULL or from
   2120    global/static blocks if BLOCK is NULL.  The passed-in search name
   2121    should not come from the user; instead it should already be a
   2122    search name as retrieved from a search_name () call.  See definition of
   2123    symbol_name_match_type::SEARCH_NAME.  Returns the struct symbol
   2124    pointer, or NULL if no symbol is found.  The symbol's section is
   2125    fixed up if necessary.  */
   2126 
   2127 extern struct block_symbol lookup_symbol_search_name
   2128      (const char *search_name,
   2129       const struct block *block,
   2130       domain_search_flags domain);
   2131 
   2132 /* Some helper functions for languages that need to write their own
   2133    lookup_symbol_nonlocal functions.  */
   2134 
   2135 /* Lookup a symbol in the static block associated to BLOCK, if there
   2136    is one; do nothing if BLOCK is NULL or a global block.
   2137    Upon success fixes up the symbol's section if necessary.  */
   2138 
   2139 extern struct block_symbol
   2140   lookup_symbol_in_static_block (const char *name,
   2141 				 const struct block *block,
   2142 				 const domain_search_flags domain);
   2143 
   2144 /* Search all static file-level symbols for NAME from DOMAIN.
   2145    Upon success fixes up the symbol's section if necessary.  */
   2146 
   2147 extern struct block_symbol lookup_static_symbol
   2148      (const char *name, const domain_search_flags domain);
   2149 
   2150 /* Lookup a symbol in all files' global blocks.
   2151 
   2152    If BLOCK is non-NULL then it is used for two things:
   2153    1) If a target-specific lookup routine for libraries exists, then use the
   2154       routine for the objfile of BLOCK, and
   2155    2) The objfile of BLOCK is used to assist in determining the search order
   2156       if the target requires it.
   2157       See gdbarch_iterate_over_objfiles_in_search_order.
   2158 
   2159    Upon success fixes up the symbol's section if necessary.  */
   2160 
   2161 extern struct block_symbol
   2162   lookup_global_symbol (const char *name,
   2163 			const struct block *block,
   2164 			const domain_search_flags domain);
   2165 
   2166 /* Lookup a symbol in block BLOCK.
   2167    Upon success fixes up the symbol's section if necessary.  */
   2168 
   2169 extern struct symbol *
   2170   lookup_symbol_in_block (const char *name,
   2171 			  symbol_name_match_type match_type,
   2172 			  const struct block *block,
   2173 			  const domain_search_flags domain);
   2174 
   2175 /* Look up the `this' symbol for LANG in BLOCK.  Return the symbol if
   2176    found, or NULL if not found.  */
   2177 
   2178 extern struct block_symbol
   2179   lookup_language_this (const struct language_defn *lang,
   2180 			const struct block *block);
   2181 
   2182 /* Lookup a [struct, union, enum] by name, within a specified block.  */
   2183 
   2184 extern struct type *lookup_struct (const char *, const struct block *);
   2185 
   2186 extern struct type *lookup_union (const char *, const struct block *);
   2187 
   2188 extern struct type *lookup_enum (const char *, const struct block *);
   2189 
   2190 /* from blockframe.c: */
   2191 
   2192 /* lookup the function symbol corresponding to the address.  The
   2193    return value will not be an inlined function; the containing
   2194    function will be returned instead.  */
   2195 
   2196 extern struct symbol *find_pc_function (CORE_ADDR);
   2197 
   2198 /* lookup the function corresponding to the address and section.  The
   2199    return value will not be an inlined function; the containing
   2200    function will be returned instead.  */
   2201 
   2202 extern struct symbol *find_pc_sect_function (CORE_ADDR, struct obj_section *);
   2203 
   2204 /* lookup the function symbol corresponding to the address and
   2205    section.  The return value will be the closest enclosing function,
   2206    which might be an inline function.  */
   2207 
   2208 extern struct symbol *find_pc_sect_containing_function
   2209   (CORE_ADDR pc, struct obj_section *section);
   2210 
   2211 /* Find the symbol at the given address.  Returns NULL if no symbol
   2212    found.  Only exact matches for ADDRESS are considered.  */
   2213 
   2214 extern struct symbol *find_symbol_at_address (CORE_ADDR);
   2215 
   2216 /* Finds the "function" (text symbol) that is smaller than PC but
   2217    greatest of all of the potential text symbols in SECTION.  Sets
   2218    *NAME and/or *ADDRESS conditionally if that pointer is non-null.
   2219    If ENDADDR is non-null, then set *ENDADDR to be the end of the
   2220    function (exclusive).  If the optional parameter BLOCK is non-null,
   2221    then set *BLOCK to the address of the block corresponding to the
   2222    function symbol, if such a symbol could be found during the lookup;
   2223    nullptr is used as a return value for *BLOCK if no block is found.
   2224    This function either succeeds or fails (not halfway succeeds).  If
   2225    it succeeds, it sets *NAME, *ADDRESS, and *ENDADDR to real
   2226    information and returns true.  If it fails, it sets *NAME, *ADDRESS
   2227    and *ENDADDR to zero and returns false.
   2228 
   2229    If the function in question occupies non-contiguous ranges,
   2230    *ADDRESS and *ENDADDR are (subject to the conditions noted above) set
   2231    to the start and end of the range in which PC is found.  Thus
   2232    *ADDRESS <= PC < *ENDADDR with no intervening gaps (in which ranges
   2233    from other functions might be found).
   2234 
   2235    This property allows find_pc_partial_function to be used (as it had
   2236    been prior to the introduction of non-contiguous range support) by
   2237    various tdep files for finding a start address and limit address
   2238    for prologue analysis.  This still isn't ideal, however, because we
   2239    probably shouldn't be doing prologue analysis (in which
   2240    instructions are scanned to determine frame size and stack layout)
   2241    for any range that doesn't contain the entry pc.  Moreover, a good
   2242    argument can be made that prologue analysis ought to be performed
   2243    starting from the entry pc even when PC is within some other range.
   2244    This might suggest that *ADDRESS and *ENDADDR ought to be set to the
   2245    limits of the entry pc range, but that will cause the
   2246    *ADDRESS <= PC < *ENDADDR condition to be violated; many of the
   2247    callers of find_pc_partial_function expect this condition to hold.
   2248 
   2249    Callers which require the start and/or end addresses for the range
   2250    containing the entry pc should instead call
   2251    find_function_entry_range_from_pc.  */
   2252 
   2253 extern bool find_pc_partial_function (CORE_ADDR pc, const char **name,
   2254 				      CORE_ADDR *address, CORE_ADDR *endaddr,
   2255 				      const struct block **block = nullptr);
   2256 
   2257 /* Like find_pc_partial_function, above, but returns the underlying
   2258    general_symbol_info (rather than the name) as an out parameter.  */
   2259 
   2260 extern bool find_pc_partial_function_sym
   2261   (CORE_ADDR pc, const general_symbol_info **sym,
   2262    CORE_ADDR *address, CORE_ADDR *endaddr,
   2263    const struct block **block = nullptr);
   2264 
   2265 /* Like find_pc_partial_function, above, but *ADDRESS and *ENDADDR are
   2266    set to start and end addresses of the range containing the entry pc.
   2267 
   2268    Note that it is not necessarily the case that (for non-NULL ADDRESS
   2269    and ENDADDR arguments) the *ADDRESS <= PC < *ENDADDR condition will
   2270    hold.
   2271 
   2272    See comment for find_pc_partial_function, above, for further
   2273    explanation.  */
   2274 
   2275 extern bool find_function_entry_range_from_pc (CORE_ADDR pc,
   2276 					       const char **name,
   2277 					       CORE_ADDR *address,
   2278 					       CORE_ADDR *endaddr);
   2279 
   2280 /* Return the type of a function with its first instruction exactly at
   2281    the PC address.  Return NULL otherwise.  */
   2282 
   2283 extern struct type *find_function_type (CORE_ADDR pc);
   2284 
   2285 /* See if we can figure out the function's actual type from the type
   2286    that the resolver returns.  RESOLVER_FUNADDR is the address of the
   2287    ifunc resolver.  */
   2288 
   2289 extern struct type *find_gnu_ifunc_target_type (CORE_ADDR resolver_funaddr);
   2290 
   2291 /* Find the GNU ifunc minimal symbol that matches SYM.  */
   2292 extern bound_minimal_symbol find_gnu_ifunc (const symbol *sym);
   2293 
   2294 extern void clear_pc_function_cache (void);
   2295 
   2296 /* lookup full symbol table by address.  */
   2297 
   2298 extern struct compunit_symtab *find_pc_compunit_symtab (CORE_ADDR);
   2299 
   2300 /* lookup full symbol table by address and section.  */
   2301 
   2302 extern struct compunit_symtab *
   2303   find_pc_sect_compunit_symtab (CORE_ADDR, struct obj_section *);
   2304 
   2305 extern bool find_pc_line_pc_range (CORE_ADDR, CORE_ADDR *, CORE_ADDR *);
   2306 
   2307 extern void reread_symbols (int from_tty);
   2308 
   2309 /* Look up a type named NAME in STRUCT_DOMAIN in the current language.
   2310    The type returned must not be opaque -- i.e., must have at least one field
   2311    defined.  */
   2312 
   2313 extern struct type *lookup_transparent_type
   2314     (const char *name, domain_search_flags flags = SEARCH_STRUCT_DOMAIN);
   2315 
   2316 extern struct type *basic_lookup_transparent_type
   2317      (const char *name, domain_search_flags flags = SEARCH_STRUCT_DOMAIN);
   2318 
   2319 /* Macro for name of symbol to indicate a file compiled with gcc.  */
   2320 #ifndef GCC_COMPILED_FLAG_SYMBOL
   2321 #define GCC_COMPILED_FLAG_SYMBOL "gcc_compiled."
   2322 #endif
   2323 
   2324 /* Macro for name of symbol to indicate a file compiled with gcc2.  */
   2325 #ifndef GCC2_COMPILED_FLAG_SYMBOL
   2326 #define GCC2_COMPILED_FLAG_SYMBOL "gcc2_compiled."
   2327 #endif
   2328 
   2329 extern bool in_gnu_ifunc_stub (CORE_ADDR pc);
   2330 
   2331 /* Functions for resolving STT_GNU_IFUNC symbols which are implemented only
   2332    for ELF symbol files.  */
   2333 
   2334 struct gnu_ifunc_fns
   2335 {
   2336   /* See elf_gnu_ifunc_resolve_addr for its real implementation.  */
   2337   CORE_ADDR (*gnu_ifunc_resolve_addr) (struct gdbarch *gdbarch, CORE_ADDR pc);
   2338 
   2339   /* See elf_gnu_ifunc_resolve_name for its real implementation.  */
   2340   bool (*gnu_ifunc_resolve_name) (const char *function_name,
   2341 				 CORE_ADDR *function_address_p);
   2342 
   2343   /* See elf_gnu_ifunc_resolver_stop for its real implementation.  */
   2344   void (*gnu_ifunc_resolver_stop) (code_breakpoint *b);
   2345 
   2346   /* See elf_gnu_ifunc_resolver_return_stop for its real implementation.  */
   2347   void (*gnu_ifunc_resolver_return_stop) (code_breakpoint *b);
   2348 };
   2349 
   2350 #define gnu_ifunc_resolve_addr gnu_ifunc_fns_p->gnu_ifunc_resolve_addr
   2351 #define gnu_ifunc_resolve_name gnu_ifunc_fns_p->gnu_ifunc_resolve_name
   2352 #define gnu_ifunc_resolver_stop gnu_ifunc_fns_p->gnu_ifunc_resolver_stop
   2353 #define gnu_ifunc_resolver_return_stop \
   2354   gnu_ifunc_fns_p->gnu_ifunc_resolver_return_stop
   2355 
   2356 extern const struct gnu_ifunc_fns *gnu_ifunc_fns_p;
   2357 
   2358 extern CORE_ADDR find_solib_trampoline_target (const frame_info_ptr &, CORE_ADDR);
   2359 
   2360 struct symtab_and_line
   2361 {
   2362   /* The program space of this sal.  */
   2363   struct program_space *pspace = NULL;
   2364 
   2365   struct symtab *symtab = NULL;
   2366   struct symbol *symbol = NULL;
   2367   struct obj_section *section = NULL;
   2368   struct minimal_symbol *msymbol = NULL;
   2369   /* Line number.  Line numbers start at 1 and proceed through symtab->nlines.
   2370      0 is never a valid line number; it is used to indicate that line number
   2371      information is not available.  */
   2372   int line = 0;
   2373 
   2374   CORE_ADDR pc = 0;
   2375   CORE_ADDR end = 0;
   2376   bool explicit_pc = false;
   2377   bool explicit_line = false;
   2378 
   2379   /* If the line number information is valid, then this indicates if this
   2380      line table entry had the is-stmt flag set or not.  */
   2381   bool is_stmt = false;
   2382 
   2383   /* The probe associated with this symtab_and_line.  */
   2384   probe *prob = NULL;
   2385   /* If PROBE is not NULL, then this is the objfile in which the probe
   2386      originated.  */
   2387   struct objfile *objfile = NULL;
   2388 };
   2389 
   2390 
   2391 
   2393 /* Given a pc value, return line number it is in.  Second arg nonzero means
   2394    if pc is on the boundary use the previous statement's line number.  */
   2395 
   2396 extern struct symtab_and_line find_pc_line (CORE_ADDR, int);
   2397 
   2398 /* Same function, but specify a section as well as an address.  */
   2399 
   2400 extern struct symtab_and_line find_pc_sect_line (CORE_ADDR,
   2401 						 struct obj_section *, int);
   2402 
   2403 /* Given PC, and assuming it is part of a range of addresses that is part of
   2404    a line, go back through the linetable and find the starting PC of that
   2405    line.
   2406 
   2407    For example, suppose we have 3 PC ranges for line X:
   2408 
   2409    Line X - [0x0 - 0x8]
   2410    Line X - [0x8 - 0x10]
   2411    Line X - [0x10 - 0x18]
   2412 
   2413    If we call the function with PC == 0x14, we want to return 0x0, as that is
   2414    the starting PC of line X, and the ranges are contiguous.
   2415 */
   2416 
   2417 extern std::optional<CORE_ADDR> find_line_range_start (CORE_ADDR pc);
   2418 
   2419 /* Wrapper around find_pc_line to just return the symtab.  */
   2420 
   2421 extern struct symtab *find_pc_line_symtab (CORE_ADDR);
   2422 
   2423 /* Given a symtab and line number, return the pc there.  */
   2424 
   2425 extern bool find_line_pc (struct symtab *, int, CORE_ADDR *);
   2426 
   2427 extern bool find_line_pc_range (struct symtab_and_line, CORE_ADDR *,
   2428 				CORE_ADDR *);
   2429 
   2430 extern void resolve_sal_pc (struct symtab_and_line *);
   2431 
   2432 /* The reason we're calling into a completion match list collector
   2433    function.  */
   2434 enum class complete_symbol_mode
   2435   {
   2436     /* Completing an expression.  */
   2437     EXPRESSION,
   2438 
   2439     /* Completing a linespec.  */
   2440     LINESPEC,
   2441   };
   2442 
   2443 extern void default_collect_symbol_completion_matches_break_on
   2444   (completion_tracker &tracker,
   2445    complete_symbol_mode mode,
   2446    symbol_name_match_type name_match_type,
   2447    const char *text, const char *word, const char *break_on,
   2448    enum type_code code);
   2449 extern void collect_symbol_completion_matches
   2450   (completion_tracker &tracker,
   2451    complete_symbol_mode mode,
   2452    symbol_name_match_type name_match_type,
   2453    const char *, const char *);
   2454 extern void collect_symbol_completion_matches_type (completion_tracker &tracker,
   2455 						    const char *, const char *,
   2456 						    enum type_code);
   2457 
   2458 extern void collect_file_symbol_completion_matches
   2459   (completion_tracker &tracker,
   2460    complete_symbol_mode,
   2461    symbol_name_match_type name_match_type,
   2462    const char *, const char *, const char *);
   2463 
   2464 extern completion_list
   2465   make_source_files_completion_list (const char *, const char *);
   2466 
   2467 /* Return whether SYM is a function/method, as opposed to a data symbol.  */
   2468 
   2469 extern bool symbol_is_function_or_method (symbol *sym);
   2470 
   2471 /* Return whether MSYMBOL is a function/method, as opposed to a data
   2472    symbol */
   2473 
   2474 extern bool symbol_is_function_or_method (minimal_symbol *msymbol);
   2475 
   2476 /* Return whether SYM should be skipped in completion mode MODE.  In
   2477    linespec mode, we're only interested in functions/methods.  */
   2478 
   2479 template<typename Symbol>
   2480 static bool
   2481 completion_skip_symbol (complete_symbol_mode mode, Symbol *sym)
   2482 {
   2483   return (mode == complete_symbol_mode::LINESPEC
   2484 	  && !symbol_is_function_or_method (sym));
   2485 }
   2486 
   2487 /* symtab.c */
   2488 
   2489 bool matching_obj_sections (struct obj_section *, struct obj_section *);
   2490 
   2491 extern struct symtab *find_line_symtab (struct symtab *, int, int *, bool *);
   2492 
   2493 /* Given a function symbol SYM, find the symtab and line for the start
   2494    of the function.  If FUNFIRSTLINE is true, we want the first line
   2495    of real code inside the function.  */
   2496 extern symtab_and_line find_function_start_sal (symbol *sym, bool
   2497 						funfirstline);
   2498 
   2499 /* Same, but start with a function address/section instead of a
   2500    symbol.  */
   2501 extern symtab_and_line find_function_start_sal (CORE_ADDR func_addr,
   2502 						obj_section *section,
   2503 						bool funfirstline);
   2504 
   2505 extern void skip_prologue_sal (struct symtab_and_line *);
   2506 
   2507 /* symtab.c */
   2508 
   2509 extern CORE_ADDR skip_prologue_using_sal (struct gdbarch *gdbarch,
   2510 					  CORE_ADDR func_addr);
   2511 
   2512 /* If SYM requires a section index, find it either via minimal symbols
   2513    or examining OBJFILE's sections.  Note that SYM's current address
   2514    must not have any runtime offsets applied.  */
   2515 
   2516 extern void fixup_symbol_section (struct symbol *sym,
   2517 				  struct objfile *objfile);
   2518 
   2519 /* If MSYMBOL is an text symbol, look for a function debug symbol with
   2520    the same address.  Returns NULL if not found.  This is necessary in
   2521    case a function is an alias to some other function, because debug
   2522    information is only emitted for the alias target function's
   2523    definition, not for the alias.  */
   2524 extern symbol *find_function_alias_target (bound_minimal_symbol msymbol);
   2525 
   2526 /* Symbol searching */
   2527 
   2528 /* When using the symbol_searcher struct to search for symbols, a vector of
   2529    the following structs is returned.  */
   2530 struct symbol_search
   2531 {
   2532   symbol_search (block_enum block_, struct symbol *symbol_)
   2533     : block (block_),
   2534       symbol (symbol_)
   2535   {
   2536     msymbol.minsym = nullptr;
   2537     msymbol.objfile = nullptr;
   2538   }
   2539 
   2540   symbol_search (block_enum block_, struct minimal_symbol *minsym,
   2541 		 struct objfile *objfile)
   2542     : block (block_),
   2543       symbol (nullptr)
   2544   {
   2545     msymbol.minsym = minsym;
   2546     msymbol.objfile = objfile;
   2547   }
   2548 
   2549   bool operator< (const symbol_search &other) const
   2550   {
   2551     return compare_search_syms (*this, other) < 0;
   2552   }
   2553 
   2554   bool operator== (const symbol_search &other) const
   2555   {
   2556     return compare_search_syms (*this, other) == 0;
   2557   }
   2558 
   2559   /* The block in which the match was found.  Either STATIC_BLOCK or
   2560      GLOBAL_BLOCK.  */
   2561   block_enum block;
   2562 
   2563   /* Information describing what was found.
   2564 
   2565      If symbol is NOT NULL, then information was found for this match.  */
   2566   struct symbol *symbol;
   2567 
   2568   /* If msymbol is non-null, then a match was made on something for
   2569      which only minimal_symbols exist.  */
   2570   struct bound_minimal_symbol msymbol;
   2571 
   2572 private:
   2573 
   2574   static int compare_search_syms (const symbol_search &sym_a,
   2575 				  const symbol_search &sym_b);
   2576 };
   2577 
   2578 /* In order to search for global symbols of a particular kind matching
   2579    particular regular expressions, create an instance of this structure and
   2580    call the SEARCH member function.  */
   2581 class global_symbol_searcher
   2582 {
   2583 public:
   2584 
   2585   /* Constructor.  */
   2586   global_symbol_searcher (domain_search_flags kind,
   2587 			  const char *symbol_name_regexp)
   2588     : m_kind (kind),
   2589       m_symbol_name_regexp (symbol_name_regexp)
   2590   {
   2591   }
   2592 
   2593   /* Set the optional regexp that matches against the symbol type.  */
   2594   void set_symbol_type_regexp (const char *regexp)
   2595   {
   2596     m_symbol_type_regexp = regexp;
   2597   }
   2598 
   2599   /* Set the flag to exclude minsyms from the search results.  */
   2600   void set_exclude_minsyms (bool exclude_minsyms)
   2601   {
   2602     m_exclude_minsyms = exclude_minsyms;
   2603   }
   2604 
   2605   /* Set the maximum number of search results to be returned.  */
   2606   void set_max_search_results (size_t max_search_results)
   2607   {
   2608     m_max_search_results = max_search_results;
   2609   }
   2610 
   2611   /* Search the symbols from all objfiles in the current program space
   2612      looking for matches as defined by the current state of this object.
   2613 
   2614      Within each file the results are sorted locally; each symtab's global
   2615      and static blocks are separately alphabetized.  Duplicate entries are
   2616      removed.  */
   2617   std::vector<symbol_search> search () const;
   2618 
   2619   /* The set of source files to search in for matching symbols.  This is
   2620      currently public so that it can be populated after this object has
   2621      been constructed.  */
   2622   std::vector<const char *> filenames;
   2623 
   2624 private:
   2625   /* The kind of symbols are we searching for.
   2626      VARIABLES_DOMAIN - Search all symbols, excluding functions, type
   2627 			names, and constants (enums).
   2628      FUNCTIONS_DOMAIN - Search all functions..
   2629      TYPES_DOMAIN     - Search all type names.
   2630      MODULES_DOMAIN   - Search all Fortran modules.
   2631      ALL_DOMAIN       - Not valid for this function.  */
   2632   domain_search_flags m_kind;
   2633 
   2634   /* Regular expression to match against the symbol name.  */
   2635   const char *m_symbol_name_regexp = nullptr;
   2636 
   2637   /* Regular expression to match against the symbol type.  */
   2638   const char *m_symbol_type_regexp = nullptr;
   2639 
   2640   /* When this flag is false then minsyms that match M_SYMBOL_REGEXP will
   2641      be included in the results, otherwise they are excluded.  */
   2642   bool m_exclude_minsyms = false;
   2643 
   2644   /* Maximum number of search results.  We currently impose a hard limit
   2645      of SIZE_MAX, there is no "unlimited".  */
   2646   size_t m_max_search_results = SIZE_MAX;
   2647 
   2648   /* Expand symtabs in OBJFILE that match PREG, are of type M_KIND.  Return
   2649      true if any msymbols were seen that we should later consider adding to
   2650      the results list.  */
   2651   bool expand_symtabs (objfile *objfile,
   2652 		       const std::optional<compiled_regex> &preg) const;
   2653 
   2654   /* Add symbols from symtabs in OBJFILE that match PREG, and TREG, and are
   2655      of type M_KIND, to the results set RESULTS_SET.  Return false if we
   2656      stop adding results early due to having already found too many results
   2657      (based on M_MAX_SEARCH_RESULTS limit), otherwise return true.
   2658      Returning true does not indicate that any results were added, just
   2659      that we didn't _not_ add a result due to reaching MAX_SEARCH_RESULTS.  */
   2660   bool add_matching_symbols (objfile *objfile,
   2661 			     const std::optional<compiled_regex> &preg,
   2662 			     const std::optional<compiled_regex> &treg,
   2663 			     std::set<symbol_search> *result_set) const;
   2664 
   2665   /* Add msymbols from OBJFILE that match PREG and M_KIND, to the results
   2666      vector RESULTS.  Return false if we stop adding results early due to
   2667      having already found too many results (based on max search results
   2668      limit M_MAX_SEARCH_RESULTS), otherwise return true.  Returning true
   2669      does not indicate that any results were added, just that we didn't
   2670      _not_ add a result due to reaching MAX_SEARCH_RESULTS.  */
   2671   bool add_matching_msymbols (objfile *objfile,
   2672 			      const std::optional<compiled_regex> &preg,
   2673 			      std::vector<symbol_search> *results) const;
   2674 
   2675   /* Return true if MSYMBOL is of type KIND.  */
   2676   static bool is_suitable_msymbol (const domain_search_flags kind,
   2677 				   const minimal_symbol *msymbol);
   2678 };
   2679 
   2680 /* When searching for Fortran symbols within modules (functions/variables)
   2681    we return a vector of this type.  The first item in the pair is the
   2682    module symbol, and the second item is the symbol for the function or
   2683    variable we found.  */
   2684 typedef std::pair<symbol_search, symbol_search> module_symbol_search;
   2685 
   2686 /* Searches the symbols to find function and variables symbols (depending
   2687    on KIND) within Fortran modules.  The MODULE_REGEXP matches against the
   2688    name of the module, REGEXP matches against the name of the symbol within
   2689    the module, and TYPE_REGEXP matches against the type of the symbol
   2690    within the module.  */
   2691 extern std::vector<module_symbol_search> search_module_symbols
   2692 	(const char *module_regexp, const char *regexp,
   2693 	 const char *type_regexp, domain_search_flags kind);
   2694 
   2695 /* Convert a global or static symbol SYM (based on BLOCK, which should be
   2696    either GLOBAL_BLOCK or STATIC_BLOCK) into a string for use in 'info'
   2697    type commands (e.g. 'info variables', 'info functions', etc).  */
   2698 
   2699 extern std::string symbol_to_info_string (struct symbol *sym, int block);
   2700 
   2701 extern bool treg_matches_sym_type_name (const compiled_regex &treg,
   2702 					const struct symbol *sym);
   2703 
   2704 /* The name of the ``main'' function.  */
   2705 extern const char *main_name ();
   2706 extern enum language main_language (void);
   2707 
   2708 /* Lookup symbol NAME from DOMAIN in MAIN_OBJFILE's global or static blocks,
   2709    as specified by BLOCK_INDEX.
   2710    This searches MAIN_OBJFILE as well as any associated separate debug info
   2711    objfiles of MAIN_OBJFILE.
   2712    BLOCK_INDEX can be GLOBAL_BLOCK or STATIC_BLOCK.
   2713    Upon success fixes up the symbol's section if necessary.  */
   2714 
   2715 extern struct block_symbol
   2716   lookup_global_symbol_from_objfile (struct objfile *main_objfile,
   2717 				     enum block_enum block_index,
   2718 				     const char *name,
   2719 				     const domain_search_flags domain);
   2720 
   2721 /* Return 1 if the supplied producer string matches the ARM RealView
   2722    compiler (armcc).  */
   2723 bool producer_is_realview (const char *producer);
   2724 
   2725 extern unsigned int symtab_create_debug;
   2726 
   2727 /* Print a "symtab-create" debug statement.  */
   2728 
   2729 #define symtab_create_debug_printf(fmt, ...) \
   2730   debug_prefixed_printf_cond (symtab_create_debug >= 1, "symtab-create", fmt, ##__VA_ARGS__)
   2731 
   2732 /* Print a verbose "symtab-create" debug statement, only if
   2733    "set debug symtab-create" is set to 2 or higher.  */
   2734 
   2735 #define symtab_create_debug_printf_v(fmt, ...) \
   2736   debug_prefixed_printf_cond (symtab_create_debug >= 2, "symtab-create", fmt, ##__VA_ARGS__)
   2737 
   2738 extern unsigned int symbol_lookup_debug;
   2739 
   2740 /* Return true if symbol-lookup debug is turned on at all.  */
   2741 
   2742 static inline bool
   2743 symbol_lookup_debug_enabled ()
   2744 {
   2745   return symbol_lookup_debug > 0;
   2746 }
   2747 
   2748 /* Return true if symbol-lookup debug is turned to verbose mode.  */
   2749 
   2750 static inline bool
   2751 symbol_lookup_debug_enabled_v ()
   2752 {
   2753   return symbol_lookup_debug > 1;
   2754 }
   2755 
   2756 /* Print a "symbol-lookup" debug statement if symbol_lookup_debug is >= 1.  */
   2757 
   2758 #define symbol_lookup_debug_printf(fmt, ...) \
   2759   debug_prefixed_printf_cond (symbol_lookup_debug_enabled (),	\
   2760 			      "symbol-lookup", fmt, ##__VA_ARGS__)
   2761 
   2762 /* Print a "symbol-lookup" debug statement if symbol_lookup_debug is >= 2.  */
   2763 
   2764 #define symbol_lookup_debug_printf_v(fmt, ...) \
   2765   debug_prefixed_printf_cond (symbol_lookup_debug_enabled_v (), \
   2766 			      "symbol-lookup", fmt, ##__VA_ARGS__)
   2767 
   2768 /* Print "symbol-lookup" enter/exit debug statements.  */
   2769 
   2770 #define SYMBOL_LOOKUP_SCOPED_DEBUG_ENTER_EXIT \
   2771   scoped_debug_enter_exit (symbol_lookup_debug_enabled, "symbol-lookup")
   2772 
   2773 extern bool basenames_may_differ;
   2774 
   2775 bool compare_filenames_for_search (const char *filename,
   2776 				   const char *search_name);
   2777 
   2778 bool compare_glob_filenames_for_search (const char *filename,
   2779 					const char *search_name);
   2780 
   2781 bool iterate_over_some_symtabs (const char *name,
   2782 				const char *real_path,
   2783 				struct compunit_symtab *first,
   2784 				struct compunit_symtab *after_last,
   2785 				gdb::function_view<bool (symtab *)> callback);
   2786 
   2787 void iterate_over_symtabs (const char *name,
   2788 			   gdb::function_view<bool (symtab *)> callback);
   2789 
   2790 
   2791 std::vector<CORE_ADDR> find_pcs_for_symtab_line
   2792     (struct symtab *symtab, int line, const linetable_entry **best_entry);
   2793 
   2794 /* Prototype for callbacks for LA_ITERATE_OVER_SYMBOLS.  The callback
   2795    is called once per matching symbol SYM.  The callback should return
   2796    true to indicate that LA_ITERATE_OVER_SYMBOLS should continue
   2797    iterating, or false to indicate that the iteration should end.  */
   2798 
   2799 typedef bool (symbol_found_callback_ftype) (struct block_symbol *bsym);
   2800 
   2801 /* Iterate over the symbols named NAME, matching DOMAIN, in BLOCK.
   2802 
   2803    For each symbol that matches, CALLBACK is called.  The symbol is
   2804    passed to the callback.
   2805 
   2806    If CALLBACK returns false, the iteration ends and this function
   2807    returns false.  Otherwise, the search continues, and the function
   2808    eventually returns true.  */
   2809 
   2810 bool iterate_over_symbols (const struct block *block,
   2811 			   const lookup_name_info &name,
   2812 			   const domain_search_flags domain,
   2813 			   gdb::function_view<symbol_found_callback_ftype> callback);
   2814 
   2815 /* Like iterate_over_symbols, but if all calls to CALLBACK return
   2816    true, then calls CALLBACK one additional time with a block_symbol
   2817    that has a valid block but a NULL symbol.  */
   2818 
   2819 bool iterate_over_symbols_terminated
   2820   (const struct block *block,
   2821    const lookup_name_info &name,
   2822    const domain_search_flags domain,
   2823    gdb::function_view<symbol_found_callback_ftype> callback);
   2824 
   2825 /* Storage type used by demangle_for_lookup.  demangle_for_lookup
   2826    either returns a const char * pointer that points to either of the
   2827    fields of this type, or a pointer to the input NAME.  This is done
   2828    this way to avoid depending on the precise details of the storage
   2829    for the string.  */
   2830 class demangle_result_storage
   2831 {
   2832 public:
   2833 
   2834   /* Swap the malloc storage to STR, and return a pointer to the
   2835      beginning of the new string.  */
   2836   const char *set_malloc_ptr (gdb::unique_xmalloc_ptr<char> &&str)
   2837   {
   2838     m_malloc = std::move (str);
   2839     return m_malloc.get ();
   2840   }
   2841 
   2842   /* Set the malloc storage to now point at PTR.  Any previous malloc
   2843      storage is released.  */
   2844   const char *set_malloc_ptr (char *ptr)
   2845   {
   2846     m_malloc.reset (ptr);
   2847     return ptr;
   2848   }
   2849 
   2850 private:
   2851 
   2852   /* The storage.  */
   2853   gdb::unique_xmalloc_ptr<char> m_malloc;
   2854 };
   2855 
   2856 const char *
   2857   demangle_for_lookup (const char *name, enum language lang,
   2858 		       demangle_result_storage &storage);
   2859 
   2860 /* Test to see if the symbol of language SYMBOL_LANGUAGE specified by
   2861    SYMNAME (which is already demangled for C++ symbols) matches
   2862    SYM_TEXT in the first SYM_TEXT_LEN characters.  If so, add it to
   2863    the current completion list and return true.  Otherwise, return
   2864    false.  */
   2865 bool completion_list_add_name (completion_tracker &tracker,
   2866 			       language symbol_language,
   2867 			       const char *symname,
   2868 			       const lookup_name_info &lookup_name,
   2869 			       const char *text, const char *word);
   2870 
   2871 /* A simple symbol searching class.  */
   2872 
   2873 class symbol_searcher
   2874 {
   2875 public:
   2876   /* Returns the symbols found for the search.  */
   2877   const std::vector<block_symbol> &
   2878   matching_symbols () const
   2879   {
   2880     return m_symbols;
   2881   }
   2882 
   2883   /* Returns the minimal symbols found for the search.  */
   2884   const std::vector<bound_minimal_symbol> &
   2885   matching_msymbols () const
   2886   {
   2887     return m_minimal_symbols;
   2888   }
   2889 
   2890   /* Search for all symbols named NAME in LANGUAGE with DOMAIN, restricting
   2891      search to FILE_SYMTABS and SEARCH_PSPACE, both of which may be NULL
   2892      to search all symtabs and program spaces.  */
   2893   void find_all_symbols (const std::string &name,
   2894 			 const struct language_defn *language,
   2895 			 domain_search_flags domain_search_flags,
   2896 			 std::vector<symtab *> *search_symtabs,
   2897 			 struct program_space *search_pspace);
   2898 
   2899   /* Reset this object to perform another search.  */
   2900   void reset ()
   2901   {
   2902     m_symbols.clear ();
   2903     m_minimal_symbols.clear ();
   2904   }
   2905 
   2906 private:
   2907   /* Matching debug symbols.  */
   2908   std::vector<block_symbol>  m_symbols;
   2909 
   2910   /* Matching non-debug symbols.  */
   2911   std::vector<bound_minimal_symbol> m_minimal_symbols;
   2912 };
   2913 
   2914 /* Class used to encapsulate the filename filtering for the "info sources"
   2915    command.  */
   2916 
   2917 struct info_sources_filter
   2918 {
   2919   /* If filename filtering is being used (see M_C_REGEXP) then which part
   2920      of the filename is being filtered against?  */
   2921   enum class match_on
   2922   {
   2923     /* Match against the full filename.  */
   2924     FULLNAME,
   2925 
   2926     /* Match only against the directory part of the full filename.  */
   2927     DIRNAME,
   2928 
   2929     /* Match only against the basename part of the full filename.  */
   2930     BASENAME
   2931   };
   2932 
   2933   /* Create a filter of MATCH_TYPE using regular expression REGEXP.  If
   2934      REGEXP is nullptr then all files will match the filter and MATCH_TYPE
   2935      is ignored.
   2936 
   2937      The string pointed too by REGEXP must remain live and unchanged for
   2938      this lifetime of this object as the object only retains a copy of the
   2939      pointer.  */
   2940   info_sources_filter (match_on match_type, const char *regexp);
   2941 
   2942   DISABLE_COPY_AND_ASSIGN (info_sources_filter);
   2943 
   2944   /* Does FULLNAME match the filter defined by this object, return true if
   2945      it does, otherwise, return false.  If there is no filtering defined
   2946      then this function will always return true.  */
   2947   bool matches (const char *fullname) const;
   2948 
   2949 private:
   2950 
   2951   /* The type of filtering in place.  */
   2952   match_on m_match_type;
   2953 
   2954   /* Points to the original regexp used to create this filter.  */
   2955   const char *m_regexp;
   2956 
   2957   /* A compiled version of M_REGEXP.  This object is only given a value if
   2958      M_REGEXP is not nullptr and is not the empty string.  */
   2959   std::optional<compiled_regex> m_c_regexp;
   2960 };
   2961 
   2962 /* Perform the core of the 'info sources' command.
   2963 
   2964    FILTER is used to perform regular expression based filtering on the
   2965    source files that will be displayed.
   2966 
   2967    Output is written to UIOUT in CLI or MI style as appropriate.  */
   2968 
   2969 extern void info_sources_worker (struct ui_out *uiout,
   2970 				 bool group_by_objfile,
   2971 				 const info_sources_filter &filter);
   2972 
   2973 /* This function returns the address at which the function epilogue begins,
   2974    according to the linetable.
   2975 
   2976    Returns an empty optional if EPILOGUE_BEGIN is never set in the
   2977    linetable.  */
   2978 
   2979 std::optional<CORE_ADDR> find_epilogue_using_linetable (CORE_ADDR func_addr);
   2980 
   2981 #endif /* !defined(SYMTAB_H) */
   2982