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