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