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