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