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