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