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