New Georgian translation for the ld sub-directory
[binutils-gdb.git] / gdb / symtab.h
blob8dfc873b1c9400ac7948583b7234634c0d32617a
1 /* Symbol table definitions for GDB.
3 Copyright (C) 1986-2023 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
20 #if !defined (SYMTAB_H)
21 #define SYMTAB_H 1
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 #include "split-name.h"
40 #include "frame.h"
42 /* Opaque declarations. */
43 struct ui_file;
44 class frame_info_ptr;
45 struct symbol;
46 struct obstack;
47 struct objfile;
48 struct block;
49 struct blockvector;
50 struct axs_value;
51 struct agent_expr;
52 struct program_space;
53 struct language_defn;
54 struct common_block;
55 struct obj_section;
56 struct cmd_list_element;
57 class probe;
58 struct lookup_name_info;
59 struct code_breakpoint;
61 /* How to match a lookup name against a symbol search name. */
62 enum class symbol_name_match_type
64 /* Wild matching. Matches unqualified symbol names in all
65 namespace/module/packages, etc. */
66 WILD,
68 /* Full matching. The lookup name indicates a fully-qualified name,
69 and only matches symbol search names in the specified
70 namespace/module/package. */
71 FULL,
73 /* Search name matching. This is like FULL, but the search name did
74 not come from the user; instead it is already a search name
75 retrieved from a search_name () call.
76 For Ada, this avoids re-encoding an already-encoded search name
77 (which would potentially incorrectly lowercase letters in the
78 linkage/search name that should remain uppercase). For C++, it
79 avoids trying to demangle a name we already know is
80 demangled. */
81 SEARCH_NAME,
83 /* Expression matching. The same as FULL matching in most
84 languages. The same as WILD matching in Ada. */
85 EXPRESSION,
88 /* Hash the given symbol search name according to LANGUAGE's
89 rules. */
90 extern unsigned int search_name_hash (enum language language,
91 const char *search_name);
93 /* Ada-specific bits of a lookup_name_info object. This is lazily
94 constructed on demand. */
96 class ada_lookup_name_info final
98 public:
99 /* Construct. */
100 explicit ada_lookup_name_info (const lookup_name_info &lookup_name);
102 /* Compare SYMBOL_SEARCH_NAME with our lookup name, using MATCH_TYPE
103 as name match type. Returns true if there's a match, false
104 otherwise. If non-NULL, store the matching results in MATCH. */
105 bool matches (const char *symbol_search_name,
106 symbol_name_match_type match_type,
107 completion_match_result *comp_match_res) const;
109 /* The Ada-encoded lookup name. */
110 const std::string &lookup_name () const
111 { return m_encoded_name; }
113 /* Return true if we're supposed to be doing a wild match look
114 up. */
115 bool wild_match_p () const
116 { return m_wild_match_p; }
118 /* Return true if we're looking up a name inside package
119 Standard. */
120 bool standard_p () const
121 { return m_standard_p; }
123 /* Return true if doing a verbatim match. */
124 bool verbatim_p () const
125 { return m_verbatim_p; }
127 /* A wrapper for ::split_name that handles some Ada-specific
128 peculiarities. */
129 std::vector<gdb::string_view> split_name () const
131 if (m_verbatim_p || m_standard_p)
133 std::vector<gdb::string_view> result;
134 if (m_standard_p)
135 result.emplace_back ("standard");
136 result.emplace_back (m_encoded_name);
137 return result;
139 return ::split_name (m_encoded_name.c_str (), split_style::UNDERSCORE);
142 private:
143 /* The Ada-encoded lookup name. */
144 std::string m_encoded_name;
146 /* Whether the user-provided lookup name was Ada encoded. If so,
147 then return encoded names in the 'matches' method's 'completion
148 match result' output. */
149 bool m_encoded_p : 1;
151 /* True if really doing wild matching. Even if the user requests
152 wild matching, some cases require full matching. */
153 bool m_wild_match_p : 1;
155 /* True if doing a verbatim match. This is true if the decoded
156 version of the symbol name is wrapped in '<'/'>'. This is an
157 escape hatch users can use to look up symbols the Ada encoding
158 does not understand. */
159 bool m_verbatim_p : 1;
161 /* True if the user specified a symbol name that is inside package
162 Standard. Symbol names inside package Standard are handled
163 specially. We always do a non-wild match of the symbol name
164 without the "standard__" prefix, and only search static and
165 global symbols. This was primarily introduced in order to allow
166 the user to specifically access the standard exceptions using,
167 for instance, Standard.Constraint_Error when Constraint_Error is
168 ambiguous (due to the user defining its own Constraint_Error
169 entity inside its program). */
170 bool m_standard_p : 1;
173 /* Language-specific bits of a lookup_name_info object, for languages
174 that do name searching using demangled names (C++/D/Go). This is
175 lazily constructed on demand. */
177 struct demangle_for_lookup_info final
179 public:
180 demangle_for_lookup_info (const lookup_name_info &lookup_name,
181 language lang);
183 /* The demangled lookup name. */
184 const std::string &lookup_name () const
185 { return m_demangled_name; }
187 private:
188 /* The demangled lookup name. */
189 std::string m_demangled_name;
192 /* Object that aggregates all information related to a symbol lookup
193 name. I.e., the name that is matched against the symbol's search
194 name. Caches per-language information so that it doesn't require
195 recomputing it for every symbol comparison, like for example the
196 Ada encoded name and the symbol's name hash for a given language.
197 The object is conceptually immutable once constructed, and thus has
198 no setters. This is to prevent some code path from tweaking some
199 property of the lookup name for some local reason and accidentally
200 altering the results of any continuing search(es).
201 lookup_name_info objects are generally passed around as a const
202 reference to reinforce that. (They're not passed around by value
203 because they're not small.) */
204 class lookup_name_info final
206 public:
207 /* We delete this overload so that the callers are required to
208 explicitly handle the lifetime of the name. */
209 lookup_name_info (std::string &&name,
210 symbol_name_match_type match_type,
211 bool completion_mode = false,
212 bool ignore_parameters = false) = delete;
214 /* This overload requires that NAME have a lifetime at least as long
215 as the lifetime of this object. */
216 lookup_name_info (const std::string &name,
217 symbol_name_match_type match_type,
218 bool completion_mode = false,
219 bool ignore_parameters = false)
220 : m_match_type (match_type),
221 m_completion_mode (completion_mode),
222 m_ignore_parameters (ignore_parameters),
223 m_name (name)
226 /* This overload requires that NAME have a lifetime at least as long
227 as the lifetime of this object. */
228 lookup_name_info (const char *name,
229 symbol_name_match_type match_type,
230 bool completion_mode = false,
231 bool ignore_parameters = false)
232 : m_match_type (match_type),
233 m_completion_mode (completion_mode),
234 m_ignore_parameters (ignore_parameters),
235 m_name (name)
238 /* Getters. See description of each corresponding field. */
239 symbol_name_match_type match_type () const { return m_match_type; }
240 bool completion_mode () const { return m_completion_mode; }
241 gdb::string_view name () const { return m_name; }
242 const bool ignore_parameters () const { return m_ignore_parameters; }
244 /* Like the "name" method but guarantees that the returned string is
245 \0-terminated. */
246 const char *c_str () const
248 /* Actually this is always guaranteed due to how the class is
249 constructed. */
250 return m_name.data ();
253 /* Return a version of this lookup name that is usable with
254 comparisons against symbols have no parameter info, such as
255 psymbols and GDB index symbols. */
256 lookup_name_info make_ignore_params () const
258 return lookup_name_info (c_str (), m_match_type, m_completion_mode,
259 true /* ignore params */);
262 /* Get the search name hash for searches in language LANG. */
263 unsigned int search_name_hash (language lang) const
265 /* Only compute each language's hash once. */
266 if (!m_demangled_hashes_p[lang])
268 m_demangled_hashes[lang]
269 = ::search_name_hash (lang, language_lookup_name (lang));
270 m_demangled_hashes_p[lang] = true;
272 return m_demangled_hashes[lang];
275 /* Get the search name for searches in language LANG. */
276 const char *language_lookup_name (language lang) const
278 switch (lang)
280 case language_ada:
281 return ada ().lookup_name ().c_str ();
282 case language_cplus:
283 return cplus ().lookup_name ().c_str ();
284 case language_d:
285 return d ().lookup_name ().c_str ();
286 case language_go:
287 return go ().lookup_name ().c_str ();
288 default:
289 return m_name.data ();
293 /* A wrapper for ::split_name (see split-name.h) that splits this
294 name, and that handles any language-specific peculiarities. */
295 std::vector<gdb::string_view> split_name (language lang) const
297 if (lang == language_ada)
298 return ada ().split_name ();
299 split_style style = split_style::NONE;
300 switch (lang)
302 case language_cplus:
303 case language_rust:
304 style = split_style::CXX;
305 break;
306 case language_d:
307 case language_go:
308 style = split_style::DOT_STYLE;
309 break;
311 return ::split_name (language_lookup_name (lang), style);
314 /* Get the Ada-specific lookup info. */
315 const ada_lookup_name_info &ada () const
317 maybe_init (m_ada);
318 return *m_ada;
321 /* Get the C++-specific lookup info. */
322 const demangle_for_lookup_info &cplus () const
324 maybe_init (m_cplus, language_cplus);
325 return *m_cplus;
328 /* Get the D-specific lookup info. */
329 const demangle_for_lookup_info &d () const
331 maybe_init (m_d, language_d);
332 return *m_d;
335 /* Get the Go-specific lookup info. */
336 const demangle_for_lookup_info &go () const
338 maybe_init (m_go, language_go);
339 return *m_go;
342 /* Get a reference to a lookup_name_info object that matches any
343 symbol name. */
344 static const lookup_name_info &match_any ();
346 private:
347 /* Initialize FIELD, if not initialized yet. */
348 template<typename Field, typename... Args>
349 void maybe_init (Field &field, Args&&... args) const
351 if (!field)
352 field.emplace (*this, std::forward<Args> (args)...);
355 /* The lookup info as passed to the ctor. */
356 symbol_name_match_type m_match_type;
357 bool m_completion_mode;
358 bool m_ignore_parameters;
359 gdb::string_view m_name;
361 /* Language-specific info. These fields are filled lazily the first
362 time a lookup is done in the corresponding language. They're
363 mutable because lookup_name_info objects are typically passed
364 around by const reference (see intro), and they're conceptually
365 "cache" that can always be reconstructed from the non-mutable
366 fields. */
367 mutable gdb::optional<ada_lookup_name_info> m_ada;
368 mutable gdb::optional<demangle_for_lookup_info> m_cplus;
369 mutable gdb::optional<demangle_for_lookup_info> m_d;
370 mutable gdb::optional<demangle_for_lookup_info> m_go;
372 /* The demangled hashes. Stored in an array with one entry for each
373 possible language. The second array records whether we've
374 already computed the each language's hash. (These are separate
375 arrays instead of a single array of optional<unsigned> to avoid
376 alignment padding). */
377 mutable std::array<unsigned int, nr_languages> m_demangled_hashes;
378 mutable std::array<bool, nr_languages> m_demangled_hashes_p {};
381 /* Comparison function for completion symbol lookup.
383 Returns true if the symbol name matches against LOOKUP_NAME.
385 SYMBOL_SEARCH_NAME should be a symbol's "search" name.
387 On success and if non-NULL, COMP_MATCH_RES->match is set to point
388 to the symbol name as should be presented to the user as a
389 completion match list element. In most languages, this is the same
390 as the symbol's search name, but in some, like Ada, the display
391 name is dynamically computed within the comparison routine.
393 Also, on success and if non-NULL, COMP_MATCH_RES->match_for_lcd
394 points the part of SYMBOL_SEARCH_NAME that was considered to match
395 LOOKUP_NAME. E.g., in C++, in linespec/wild mode, if the symbol is
396 "foo::function()" and LOOKUP_NAME is "function(", MATCH_FOR_LCD
397 points to "function()" inside SYMBOL_SEARCH_NAME. */
398 typedef bool (symbol_name_matcher_ftype)
399 (const char *symbol_search_name,
400 const lookup_name_info &lookup_name,
401 completion_match_result *comp_match_res);
403 /* Some of the structures in this file are space critical.
404 The space-critical structures are:
406 struct general_symbol_info
407 struct symbol
408 struct partial_symbol
410 These structures are laid out to encourage good packing.
411 They use ENUM_BITFIELD and short int fields, and they order the
412 structure members so that fields less than a word are next
413 to each other so they can be packed together. */
415 /* Rearranged: used ENUM_BITFIELD and rearranged field order in
416 all the space critical structures (plus struct minimal_symbol).
417 Memory usage dropped from 99360768 bytes to 90001408 bytes.
418 I measured this with before-and-after tests of
419 "HEAD-old-gdb -readnow HEAD-old-gdb" and
420 "HEAD-new-gdb -readnow HEAD-old-gdb" on native i686-pc-linux-gnu,
421 red hat linux 8, with LD_LIBRARY_PATH=/usr/lib/debug,
422 typing "maint space 1" at the first command prompt.
424 Here is another measurement (from andrew c):
425 # no /usr/lib/debug, just plain glibc, like a normal user
426 gdb HEAD-old-gdb
427 (gdb) break internal_error
428 (gdb) run
429 (gdb) maint internal-error
430 (gdb) backtrace
431 (gdb) maint space 1
433 gdb gdb_6_0_branch 2003-08-19 space used: 8896512
434 gdb HEAD 2003-08-19 space used: 8904704
435 gdb HEAD 2003-08-21 space used: 8396800 (+symtab.h)
436 gdb HEAD 2003-08-21 space used: 8265728 (+gdbtypes.h)
438 The third line shows the savings from the optimizations in symtab.h.
439 The fourth line shows the savings from the optimizations in
440 gdbtypes.h. Both optimizations are in gdb HEAD now.
442 --chastain 2003-08-21 */
444 /* Define a structure for the information that is common to all symbol types,
445 including minimal symbols, partial symbols, and full symbols. In a
446 multilanguage environment, some language specific information may need to
447 be recorded along with each symbol. */
449 /* This structure is space critical. See space comments at the top. */
451 struct general_symbol_info
453 /* Short version as to when to use which name accessor:
454 Use natural_name () to refer to the name of the symbol in the original
455 source code. Use linkage_name () if you want to know what the linker
456 thinks the symbol's name is. Use print_name () for output. Use
457 demangled_name () if you specifically need to know whether natural_name ()
458 and linkage_name () are different. */
460 const char *linkage_name () const
461 { return m_name; }
463 /* Return SYMBOL's "natural" name, i.e. the name that it was called in
464 the original source code. In languages like C++ where symbols may
465 be mangled for ease of manipulation by the linker, this is the
466 demangled name. */
467 const char *natural_name () const;
469 /* Returns a version of the name of a symbol that is
470 suitable for output. In C++ this is the "demangled" form of the
471 name if demangle is on and the "mangled" form of the name if
472 demangle is off. In other languages this is just the symbol name.
473 The result should never be NULL. Don't use this for internal
474 purposes (e.g. storing in a hashtable): it's only suitable for output. */
475 const char *print_name () const
476 { return demangle ? natural_name () : linkage_name (); }
478 /* Return the demangled name for a symbol based on the language for
479 that symbol. If no demangled name exists, return NULL. */
480 const char *demangled_name () const;
482 /* Returns the name to be used when sorting and searching symbols.
483 In C++, we search for the demangled form of a name,
484 and so sort symbols accordingly. In Ada, however, we search by mangled
485 name. If there is no distinct demangled name, then this
486 returns the same value (same pointer) as linkage_name (). */
487 const char *search_name () const;
489 /* Set just the linkage name of a symbol; do not try to demangle
490 it. Used for constructs which do not have a mangled name,
491 e.g. struct tags. Unlike compute_and_set_names, linkage_name must
492 be terminated and either already on the objfile's obstack or
493 permanently allocated. */
494 void set_linkage_name (const char *linkage_name)
495 { m_name = linkage_name; }
497 /* Set the demangled name of this symbol to NAME. NAME must be
498 already correctly allocated. If the symbol's language is Ada,
499 then the name is ignored and the obstack is set. */
500 void set_demangled_name (const char *name, struct obstack *obstack);
502 enum language language () const
503 { return m_language; }
505 /* Initializes the language dependent portion of a symbol
506 depending upon the language for the symbol. */
507 void set_language (enum language language, struct obstack *obstack);
509 /* Set the linkage and natural names of a symbol, by demangling
510 the linkage name. If linkage_name may not be nullterminated,
511 copy_name must be set to true. */
512 void compute_and_set_names (gdb::string_view linkage_name, bool copy_name,
513 struct objfile_per_bfd_storage *per_bfd,
514 gdb::optional<hashval_t> hash
515 = gdb::optional<hashval_t> ());
517 CORE_ADDR value_address () const
519 return m_value.address;
522 void set_value_address (CORE_ADDR address)
524 m_value.address = address;
527 /* Return the unrelocated address of this symbol. */
528 unrelocated_addr unrelocated_address () const
530 return m_value.unrel_addr;
533 /* Set the unrelocated address of this symbol. */
534 void set_unrelocated_address (unrelocated_addr addr)
536 m_value.unrel_addr = addr;
539 /* Name of the symbol. This is a required field. Storage for the
540 name is allocated on the objfile_obstack for the associated
541 objfile. For languages like C++ that make a distinction between
542 the mangled name and demangled name, this is the mangled
543 name. */
545 const char *m_name;
547 /* Value of the symbol. Which member of this union to use, and what
548 it means, depends on what kind of symbol this is and its
549 SYMBOL_CLASS. See comments there for more details. All of these
550 are in host byte order (though what they point to might be in
551 target byte order, e.g. LOC_CONST_BYTES). */
553 union
555 LONGEST ivalue;
557 const struct block *block;
559 const gdb_byte *bytes;
561 CORE_ADDR address;
563 /* The address, if unrelocated. An unrelocated symbol does not
564 have the runtime section offset applied. */
565 unrelocated_addr unrel_addr;
567 /* A common block. Used with LOC_COMMON_BLOCK. */
569 const struct common_block *common_block;
571 /* For opaque typedef struct chain. */
573 struct symbol *chain;
575 m_value;
577 /* Since one and only one language can apply, wrap the language specific
578 information inside a union. */
580 union
582 /* A pointer to an obstack that can be used for storage associated
583 with this symbol. This is only used by Ada, and only when the
584 'ada_mangled' field is zero. */
585 struct obstack *obstack;
587 /* This is used by languages which wish to store a demangled name.
588 currently used by Ada, C++, and Objective C. */
589 const char *demangled_name;
591 language_specific;
593 /* Record the source code language that applies to this symbol.
594 This is used to select one of the fields from the language specific
595 union above. */
597 ENUM_BITFIELD(language) m_language : LANGUAGE_BITS;
599 /* This is only used by Ada. If set, then the 'demangled_name' field
600 of language_specific is valid. Otherwise, the 'obstack' field is
601 valid. */
602 unsigned int ada_mangled : 1;
604 /* Which section is this symbol in? This is an index into
605 section_offsets for this objfile. Negative means that the symbol
606 does not get relocated relative to a section. */
608 short m_section;
610 /* Set the index into the obj_section list (within the containing
611 objfile) for the section that contains this symbol. See M_SECTION
612 for more details. */
614 void set_section_index (short idx)
615 { m_section = idx; }
617 /* Return the index into the obj_section list (within the containing
618 objfile) for the section that contains this symbol. See M_SECTION
619 for more details. */
621 short section_index () const
622 { return m_section; }
624 /* Return the obj_section from OBJFILE for this symbol. The symbol
625 returned is based on the SECTION member variable, and can be nullptr
626 if SECTION is negative. */
628 struct obj_section *obj_section (const struct objfile *objfile) const;
631 extern CORE_ADDR symbol_overlayed_address (CORE_ADDR, struct obj_section *);
633 /* Try to determine the demangled name for a symbol, based on the
634 language of that symbol. If the language is set to language_auto,
635 it will attempt to find any demangling algorithm that works and
636 then set the language appropriately. The returned name is allocated
637 by the demangler and should be xfree'd. */
639 extern gdb::unique_xmalloc_ptr<char> symbol_find_demangled_name
640 (struct general_symbol_info *gsymbol, const char *mangled);
642 /* Return true if NAME matches the "search" name of GSYMBOL, according
643 to the symbol's language. */
644 extern bool symbol_matches_search_name
645 (const struct general_symbol_info *gsymbol,
646 const lookup_name_info &name);
648 /* Compute the hash of the given symbol search name of a symbol of
649 language LANGUAGE. */
650 extern unsigned int search_name_hash (enum language language,
651 const char *search_name);
653 /* Classification types for a minimal symbol. These should be taken as
654 "advisory only", since if gdb can't easily figure out a
655 classification it simply selects mst_unknown. It may also have to
656 guess when it can't figure out which is a better match between two
657 types (mst_data versus mst_bss) for example. Since the minimal
658 symbol info is sometimes derived from the BFD library's view of a
659 file, we need to live with what information bfd supplies. */
661 enum minimal_symbol_type
663 mst_unknown = 0, /* Unknown type, the default */
664 mst_text, /* Generally executable instructions */
666 /* A GNU ifunc symbol, in the .text section. GDB uses to know
667 whether the user is setting a breakpoint on a GNU ifunc function,
668 and thus GDB needs to actually set the breakpoint on the target
669 function. It is also used to know whether the program stepped
670 into an ifunc resolver -- the resolver may get a separate
671 symbol/alias under a different name, but it'll have the same
672 address as the ifunc symbol. */
673 mst_text_gnu_ifunc, /* Executable code returning address
674 of executable code */
676 /* A GNU ifunc function descriptor symbol, in a data section
677 (typically ".opd"). Seen on architectures that use function
678 descriptors, like PPC64/ELFv1. In this case, this symbol's value
679 is the address of the descriptor. There'll be a corresponding
680 mst_text_gnu_ifunc synthetic symbol for the text/entry
681 address. */
682 mst_data_gnu_ifunc, /* Executable code returning address
683 of executable code */
685 mst_slot_got_plt, /* GOT entries for .plt sections */
686 mst_data, /* Generally initialized data */
687 mst_bss, /* Generally uninitialized data */
688 mst_abs, /* Generally absolute (nonrelocatable) */
689 /* GDB uses mst_solib_trampoline for the start address of a shared
690 library trampoline entry. Breakpoints for shared library functions
691 are put there if the shared library is not yet loaded.
692 After the shared library is loaded, lookup_minimal_symbol will
693 prefer the minimal symbol from the shared library (usually
694 a mst_text symbol) over the mst_solib_trampoline symbol, and the
695 breakpoints will be moved to their true address in the shared
696 library via breakpoint_re_set. */
697 mst_solib_trampoline, /* Shared library trampoline code */
698 /* For the mst_file* types, the names are only guaranteed to be unique
699 within a given .o file. */
700 mst_file_text, /* Static version of mst_text */
701 mst_file_data, /* Static version of mst_data */
702 mst_file_bss, /* Static version of mst_bss */
703 nr_minsym_types
706 /* The number of enum minimal_symbol_type values, with some padding for
707 reasonable growth. */
708 #define MINSYM_TYPE_BITS 4
709 gdb_static_assert (nr_minsym_types <= (1 << MINSYM_TYPE_BITS));
711 /* Define a simple structure used to hold some very basic information about
712 all defined global symbols (text, data, bss, abs, etc). The only required
713 information is the general_symbol_info.
715 In many cases, even if a file was compiled with no special options for
716 debugging at all, as long as was not stripped it will contain sufficient
717 information to build a useful minimal symbol table using this structure.
718 Even when a file contains enough debugging information to build a full
719 symbol table, these minimal symbols are still useful for quickly mapping
720 between names and addresses, and vice versa. They are also sometimes
721 used to figure out what full symbol table entries need to be read in. */
723 struct minimal_symbol : public general_symbol_info
725 LONGEST value_longest () const
727 return m_value.ivalue;
730 /* The relocated address of the minimal symbol, using the section
731 offsets from OBJFILE. */
732 CORE_ADDR value_address (objfile *objfile) const;
734 /* It does not make sense to call this for minimal symbols, as they
735 are stored unrelocated. */
736 CORE_ADDR value_address () const = delete;
738 /* The unrelocated address of the minimal symbol. */
739 unrelocated_addr unrelocated_address () const
741 return m_value.unrel_addr;
744 /* The unrelocated address just after the end of the the minimal
745 symbol. */
746 unrelocated_addr unrelocated_end_address () const
748 return unrelocated_addr (CORE_ADDR (unrelocated_address ()) + size ());
751 /* Return this minimal symbol's type. */
753 minimal_symbol_type type () const
755 return m_type;
758 /* Set this minimal symbol's type. */
760 void set_type (minimal_symbol_type type)
762 m_type = type;
765 /* Return this minimal symbol's size. */
767 unsigned long size () const
769 return m_size;
772 /* Set this minimal symbol's size. */
774 void set_size (unsigned long size)
776 m_size = size;
777 m_has_size = 1;
780 /* Return true if this minimal symbol's size is known. */
782 bool has_size () const
784 return m_has_size;
787 /* Return this minimal symbol's first target-specific flag. */
789 bool target_flag_1 () const
791 return m_target_flag_1;
794 /* Set this minimal symbol's first target-specific flag. */
796 void set_target_flag_1 (bool target_flag_1)
798 m_target_flag_1 = target_flag_1;
801 /* Return this minimal symbol's second target-specific flag. */
803 bool target_flag_2 () const
805 return m_target_flag_2;
808 /* Set this minimal symbol's second target-specific flag. */
810 void set_target_flag_2 (bool target_flag_2)
812 m_target_flag_2 = target_flag_2;
815 /* Size of this symbol. dbx_end_psymtab in dbxread.c uses this
816 information to calculate the end of the partial symtab based on the
817 address of the last symbol plus the size of the last symbol. */
819 unsigned long m_size;
821 /* Which source file is this symbol in? Only relevant for mst_file_*. */
822 const char *filename;
824 /* Classification type for this minimal symbol. */
826 ENUM_BITFIELD(minimal_symbol_type) m_type : MINSYM_TYPE_BITS;
828 /* Non-zero if this symbol was created by gdb.
829 Such symbols do not appear in the output of "info var|fun". */
830 unsigned int created_by_gdb : 1;
832 /* Two flag bits provided for the use of the target. */
833 unsigned int m_target_flag_1 : 1;
834 unsigned int m_target_flag_2 : 1;
836 /* Nonzero iff the size of the minimal symbol has been set.
837 Symbol size information can sometimes not be determined, because
838 the object file format may not carry that piece of information. */
839 unsigned int m_has_size : 1;
841 /* Non-zero if this symbol ever had its demangled name set (even if
842 it was set to NULL). */
843 unsigned int name_set : 1;
845 /* Minimal symbols with the same hash key are kept on a linked
846 list. This is the link. */
848 struct minimal_symbol *hash_next;
850 /* Minimal symbols are stored in two different hash tables. This is
851 the `next' pointer for the demangled hash table. */
853 struct minimal_symbol *demangled_hash_next;
855 /* True if this symbol is of some data type. */
857 bool data_p () const;
859 /* True if MSYMBOL is of some text type. */
861 bool text_p () const;
863 /* For data symbols only, given an objfile, if 'maybe_copied'
864 evaluates to 'true' for that objfile, then the symbol might be
865 subject to copy relocation. In this case, a minimal symbol
866 matching the symbol's linkage name is first looked for in the
867 main objfile. If found, then that address is used; otherwise the
868 address in this symbol is used. */
870 bool maybe_copied (objfile *objfile) const;
872 private:
873 /* Return the address of this minimal symbol, in the context of OBJF. The
874 MAYBE_COPIED flag must be set. If the minimal symbol appears in the
875 main program's minimal symbols, then that minsym's address is
876 returned; otherwise, this minimal symbol's address is returned. */
877 CORE_ADDR get_maybe_copied_address (objfile *objf) const;
880 #include "minsyms.h"
884 /* Represent one symbol name; a variable, constant, function or typedef. */
886 /* Different name domains for symbols. Looking up a symbol specifies a
887 domain and ignores symbol definitions in other name domains. */
889 enum domain_enum
891 /* UNDEF_DOMAIN is used when a domain has not been discovered or
892 none of the following apply. This usually indicates an error either
893 in the symbol information or in gdb's handling of symbols. */
895 UNDEF_DOMAIN,
897 /* VAR_DOMAIN is the usual domain. In C, this contains variables,
898 function names, typedef names and enum type values. */
900 VAR_DOMAIN,
902 /* STRUCT_DOMAIN is used in C to hold struct, union and enum type names.
903 Thus, if `struct foo' is used in a C program, it produces a symbol named
904 `foo' in the STRUCT_DOMAIN. */
906 STRUCT_DOMAIN,
908 /* MODULE_DOMAIN is used in Fortran to hold module type names. */
910 MODULE_DOMAIN,
912 /* LABEL_DOMAIN may be used for names of labels (for gotos). */
914 LABEL_DOMAIN,
916 /* Fortran common blocks. Their naming must be separate from VAR_DOMAIN.
917 They also always use LOC_COMMON_BLOCK. */
918 COMMON_BLOCK_DOMAIN,
920 /* This must remain last. */
921 NR_DOMAINS
924 /* The number of bits in a symbol used to represent the domain. */
926 #define SYMBOL_DOMAIN_BITS 3
927 gdb_static_assert (NR_DOMAINS <= (1 << SYMBOL_DOMAIN_BITS));
929 extern const char *domain_name (domain_enum);
931 /* Searching domains, used when searching for symbols. Element numbers are
932 hardcoded in GDB, check all enum uses before changing it. */
934 enum search_domain
936 /* Everything in VAR_DOMAIN minus FUNCTIONS_DOMAIN and
937 TYPES_DOMAIN. */
938 VARIABLES_DOMAIN = 0,
940 /* All functions -- for some reason not methods, though. */
941 FUNCTIONS_DOMAIN = 1,
943 /* All defined types */
944 TYPES_DOMAIN = 2,
946 /* All modules. */
947 MODULES_DOMAIN = 3,
949 /* Any type. */
950 ALL_DOMAIN = 4
953 extern const char *search_domain_name (enum search_domain);
955 /* An address-class says where to find the value of a symbol. */
957 enum address_class
959 /* Not used; catches errors. */
961 LOC_UNDEF,
963 /* Value is constant int SYMBOL_VALUE, host byteorder. */
965 LOC_CONST,
967 /* Value is at fixed address SYMBOL_VALUE_ADDRESS. */
969 LOC_STATIC,
971 /* Value is in register. SYMBOL_VALUE is the register number
972 in the original debug format. SYMBOL_REGISTER_OPS holds a
973 function that can be called to transform this into the
974 actual register number this represents in a specific target
975 architecture (gdbarch).
977 For some symbol formats (stabs, for some compilers at least),
978 the compiler generates two symbols, an argument and a register.
979 In some cases we combine them to a single LOC_REGISTER in symbol
980 reading, but currently not for all cases (e.g. it's passed on the
981 stack and then loaded into a register). */
983 LOC_REGISTER,
985 /* It's an argument; the value is at SYMBOL_VALUE offset in arglist. */
987 LOC_ARG,
989 /* Value address is at SYMBOL_VALUE offset in arglist. */
991 LOC_REF_ARG,
993 /* Value is in specified register. Just like LOC_REGISTER except the
994 register holds the address of the argument instead of the argument
995 itself. This is currently used for the passing of structs and unions
996 on sparc and hppa. It is also used for call by reference where the
997 address is in a register, at least by mipsread.c. */
999 LOC_REGPARM_ADDR,
1001 /* Value is a local variable at SYMBOL_VALUE offset in stack frame. */
1003 LOC_LOCAL,
1005 /* Value not used; definition in SYMBOL_TYPE. Symbols in the domain
1006 STRUCT_DOMAIN all have this class. */
1008 LOC_TYPEDEF,
1010 /* Value is address SYMBOL_VALUE_ADDRESS in the code. */
1012 LOC_LABEL,
1014 /* In a symbol table, value is SYMBOL_BLOCK_VALUE of a `struct block'.
1015 In a partial symbol table, SYMBOL_VALUE_ADDRESS is the start address
1016 of the block. Function names have this class. */
1018 LOC_BLOCK,
1020 /* Value is a constant byte-sequence pointed to by SYMBOL_VALUE_BYTES, in
1021 target byte order. */
1023 LOC_CONST_BYTES,
1025 /* Value is at fixed address, but the address of the variable has
1026 to be determined from the minimal symbol table whenever the
1027 variable is referenced.
1028 This happens if debugging information for a global symbol is
1029 emitted and the corresponding minimal symbol is defined
1030 in another object file or runtime common storage.
1031 The linker might even remove the minimal symbol if the global
1032 symbol is never referenced, in which case the symbol remains
1033 unresolved.
1035 GDB would normally find the symbol in the minimal symbol table if it will
1036 not find it in the full symbol table. But a reference to an external
1037 symbol in a local block shadowing other definition requires full symbol
1038 without possibly having its address available for LOC_STATIC. Testcase
1039 is provided as `gdb.dwarf2/dw2-unresolved.exp'.
1041 This is also used for thread local storage (TLS) variables. In
1042 this case, the address of the TLS variable must be determined
1043 when the variable is referenced, from the msymbol's address,
1044 which is the offset of the TLS variable in the thread local
1045 storage of the shared library/object. */
1047 LOC_UNRESOLVED,
1049 /* The variable does not actually exist in the program.
1050 The value is ignored. */
1052 LOC_OPTIMIZED_OUT,
1054 /* The variable's address is computed by a set of location
1055 functions (see "struct symbol_computed_ops" below). */
1056 LOC_COMPUTED,
1058 /* The variable uses general_symbol_info->value->common_block field.
1059 It also always uses COMMON_BLOCK_DOMAIN. */
1060 LOC_COMMON_BLOCK,
1062 /* Not used, just notes the boundary of the enum. */
1063 LOC_FINAL_VALUE
1066 /* The number of bits needed for values in enum address_class, with some
1067 padding for reasonable growth, and room for run-time registered address
1068 classes. See symtab.c:MAX_SYMBOL_IMPLS.
1069 This is a #define so that we can have a assertion elsewhere to
1070 verify that we have reserved enough space for synthetic address
1071 classes. */
1072 #define SYMBOL_ACLASS_BITS 5
1073 gdb_static_assert (LOC_FINAL_VALUE <= (1 << SYMBOL_ACLASS_BITS));
1075 /* The methods needed to implement LOC_COMPUTED. These methods can
1076 use the symbol's .aux_value for additional per-symbol information.
1078 At present this is only used to implement location expressions. */
1080 struct symbol_computed_ops
1083 /* Return the value of the variable SYMBOL, relative to the stack
1084 frame FRAME. If the variable has been optimized out, return
1085 zero.
1087 Iff `read_needs_frame (SYMBOL)' is not SYMBOL_NEEDS_FRAME, then
1088 FRAME may be zero. */
1090 struct value *(*read_variable) (struct symbol * symbol,
1091 frame_info_ptr frame);
1093 /* Read variable SYMBOL like read_variable at (callee) FRAME's function
1094 entry. SYMBOL should be a function parameter, otherwise
1095 NO_ENTRY_VALUE_ERROR will be thrown. */
1096 struct value *(*read_variable_at_entry) (struct symbol *symbol,
1097 frame_info_ptr frame);
1099 /* Find the "symbol_needs_kind" value for the given symbol. This
1100 value determines whether reading the symbol needs memory (e.g., a
1101 global variable), just registers (a thread-local), or a frame (a
1102 local variable). */
1103 enum symbol_needs_kind (*get_symbol_read_needs) (struct symbol * symbol);
1105 /* Write to STREAM a natural-language description of the location of
1106 SYMBOL, in the context of ADDR. */
1107 void (*describe_location) (struct symbol * symbol, CORE_ADDR addr,
1108 struct ui_file * stream);
1110 /* Non-zero if this symbol's address computation is dependent on PC. */
1111 unsigned char location_has_loclist;
1113 /* Tracepoint support. Append bytecodes to the tracepoint agent
1114 expression AX that push the address of the object SYMBOL. Set
1115 VALUE appropriately. Note --- for objects in registers, this
1116 needn't emit any code; as long as it sets VALUE properly, then
1117 the caller will generate the right code in the process of
1118 treating this as an lvalue or rvalue. */
1120 void (*tracepoint_var_ref) (struct symbol *symbol, struct agent_expr *ax,
1121 struct axs_value *value);
1123 /* Generate C code to compute the location of SYMBOL. The C code is
1124 emitted to STREAM. GDBARCH is the current architecture and PC is
1125 the PC at which SYMBOL's location should be evaluated.
1126 REGISTERS_USED is a vector indexed by register number; the
1127 generator function should set an element in this vector if the
1128 corresponding register is needed by the location computation.
1129 The generated C code must assign the location to a local
1130 variable; this variable's name is RESULT_NAME. */
1132 void (*generate_c_location) (struct symbol *symbol, string_file *stream,
1133 struct gdbarch *gdbarch,
1134 std::vector<bool> &registers_used,
1135 CORE_ADDR pc, const char *result_name);
1139 /* The methods needed to implement LOC_BLOCK for inferior functions.
1140 These methods can use the symbol's .aux_value for additional
1141 per-symbol information. */
1143 struct symbol_block_ops
1145 /* Fill in *START and *LENGTH with DWARF block data of function
1146 FRAMEFUNC valid for inferior context address PC. Set *LENGTH to
1147 zero if such location is not valid for PC; *START is left
1148 uninitialized in such case. */
1149 void (*find_frame_base_location) (struct symbol *framefunc, CORE_ADDR pc,
1150 const gdb_byte **start, size_t *length);
1152 /* Return the frame base address. FRAME is the frame for which we want to
1153 compute the base address while FRAMEFUNC is the symbol for the
1154 corresponding function. Return 0 on failure (FRAMEFUNC may not hold the
1155 information we need).
1157 This method is designed to work with static links (nested functions
1158 handling). Static links are function properties whose evaluation returns
1159 the frame base address for the enclosing frame. However, there are
1160 multiple definitions for "frame base": the content of the frame base
1161 register, the CFA as defined by DWARF unwinding information, ...
1163 So this specific method is supposed to compute the frame base address such
1164 as for nested functions, the static link computes the same address. For
1165 instance, considering DWARF debugging information, the static link is
1166 computed with DW_AT_static_link and this method must be used to compute
1167 the corresponding DW_AT_frame_base attribute. */
1168 CORE_ADDR (*get_frame_base) (struct symbol *framefunc,
1169 frame_info_ptr frame);
1171 /* Return the block for this function. So far, this is used to
1172 implement function aliases. So, if this is set, then it's not
1173 necessary to set the other functions in this structure; and vice
1174 versa. */
1175 const block *(*get_block_value) (const struct symbol *sym);
1178 /* Functions used with LOC_REGISTER and LOC_REGPARM_ADDR. */
1180 struct symbol_register_ops
1182 int (*register_number) (struct symbol *symbol, struct gdbarch *gdbarch);
1185 /* Objects of this type are used to find the address class and the
1186 various computed ops vectors of a symbol. */
1188 struct symbol_impl
1190 enum address_class aclass;
1192 /* Used with LOC_COMPUTED. */
1193 const struct symbol_computed_ops *ops_computed;
1195 /* Used with LOC_BLOCK. */
1196 const struct symbol_block_ops *ops_block;
1198 /* Used with LOC_REGISTER and LOC_REGPARM_ADDR. */
1199 const struct symbol_register_ops *ops_register;
1202 /* struct symbol has some subclasses. This enum is used to
1203 differentiate between them. */
1205 enum symbol_subclass_kind
1207 /* Plain struct symbol. */
1208 SYMBOL_NONE,
1210 /* struct template_symbol. */
1211 SYMBOL_TEMPLATE,
1213 /* struct rust_vtable_symbol. */
1214 SYMBOL_RUST_VTABLE
1217 extern gdb::array_view<const struct symbol_impl> symbol_impls;
1219 bool symbol_matches_domain (enum language symbol_language,
1220 domain_enum symbol_domain,
1221 domain_enum domain);
1223 /* This structure is space critical. See space comments at the top. */
1225 struct symbol : public general_symbol_info, public allocate_on_obstack
1227 symbol ()
1228 /* Class-initialization of bitfields is only allowed in C++20. */
1229 : m_domain (UNDEF_DOMAIN),
1230 m_aclass_index (0),
1231 m_is_objfile_owned (1),
1232 m_is_argument (0),
1233 m_is_inlined (0),
1234 maybe_copied (0),
1235 subclass (SYMBOL_NONE),
1236 m_artificial (false)
1238 /* We can't use an initializer list for members of a base class, and
1239 general_symbol_info needs to stay a POD type. */
1240 m_name = nullptr;
1241 m_value.ivalue = 0;
1242 language_specific.obstack = nullptr;
1243 m_language = language_unknown;
1244 ada_mangled = 0;
1245 m_section = -1;
1246 /* GCC 4.8.5 (on CentOS 7) does not correctly compile class-
1247 initialization of unions, so we initialize it manually here. */
1248 owner.symtab = nullptr;
1251 symbol (const symbol &) = default;
1252 symbol &operator= (const symbol &) = default;
1254 void set_aclass_index (unsigned int aclass_index)
1256 m_aclass_index = aclass_index;
1259 const symbol_impl &impl () const
1261 return symbol_impls[this->m_aclass_index];
1264 address_class aclass () const
1266 return this->impl ().aclass;
1269 /* Call symbol_matches_domain on this symbol, using the symbol's
1270 domain. */
1271 bool matches (domain_enum d) const
1273 return symbol_matches_domain (language (), domain (), d);
1276 domain_enum domain () const
1278 return m_domain;
1281 void set_domain (domain_enum domain)
1283 m_domain = domain;
1286 bool is_objfile_owned () const
1288 return m_is_objfile_owned;
1291 void set_is_objfile_owned (bool is_objfile_owned)
1293 m_is_objfile_owned = is_objfile_owned;
1296 bool is_argument () const
1298 return m_is_argument;
1301 void set_is_argument (bool is_argument)
1303 m_is_argument = is_argument;
1306 bool is_inlined () const
1308 return m_is_inlined;
1311 void set_is_inlined (bool is_inlined)
1313 m_is_inlined = is_inlined;
1316 bool is_cplus_template_function () const
1318 return this->subclass == SYMBOL_TEMPLATE;
1321 struct type *type () const
1323 return m_type;
1326 void set_type (struct type *type)
1328 m_type = type;
1331 unsigned int line () const
1333 return m_line;
1336 void set_line (unsigned int line)
1338 m_line = line;
1341 LONGEST value_longest () const
1343 return m_value.ivalue;
1346 void set_value_longest (LONGEST value)
1348 m_value.ivalue = value;
1351 CORE_ADDR value_address () const
1353 if (this->maybe_copied)
1354 return this->get_maybe_copied_address ();
1355 else
1356 return m_value.address;
1359 void set_value_address (CORE_ADDR address)
1361 m_value.address = address;
1364 const gdb_byte *value_bytes () const
1366 return m_value.bytes;
1369 void set_value_bytes (const gdb_byte *bytes)
1371 m_value.bytes = bytes;
1374 const common_block *value_common_block () const
1376 return m_value.common_block;
1379 void set_value_common_block (const common_block *common_block)
1381 m_value.common_block = common_block;
1384 const block *value_block () const;
1386 void set_value_block (const block *block)
1388 m_value.block = block;
1391 symbol *value_chain () const
1393 return m_value.chain;
1396 void set_value_chain (symbol *sym)
1398 m_value.chain = sym;
1401 /* Return true if this symbol was marked as artificial. */
1402 bool is_artificial () const
1404 return m_artificial;
1407 /* Set the 'artificial' flag on this symbol. */
1408 void set_is_artificial (bool artificial)
1410 m_artificial = artificial;
1413 /* Return the OBJFILE of this symbol. It is an error to call this
1414 if is_objfile_owned is false, which only happens for
1415 architecture-provided types. */
1417 struct objfile *objfile () const;
1419 /* Return the ARCH of this symbol. */
1421 struct gdbarch *arch () const;
1423 /* Return the symtab of this symbol. It is an error to call this if
1424 is_objfile_owned is false, which only happens for
1425 architecture-provided types. */
1427 struct symtab *symtab () const;
1429 /* Set the symtab of this symbol to SYMTAB. It is an error to call
1430 this if is_objfile_owned is false, which only happens for
1431 architecture-provided types. */
1433 void set_symtab (struct symtab *symtab);
1435 /* Data type of value */
1437 struct type *m_type = nullptr;
1439 /* The owner of this symbol.
1440 Which one to use is defined by symbol.is_objfile_owned. */
1442 union
1444 /* The symbol table containing this symbol. This is the file associated
1445 with LINE. It can be NULL during symbols read-in but it is never NULL
1446 during normal operation. */
1447 struct symtab *symtab;
1449 /* For types defined by the architecture. */
1450 struct gdbarch *arch;
1451 } owner;
1453 /* Domain code. */
1455 ENUM_BITFIELD(domain_enum) m_domain : SYMBOL_DOMAIN_BITS;
1457 /* Address class. This holds an index into the 'symbol_impls'
1458 table. The actual enum address_class value is stored there,
1459 alongside any per-class ops vectors. */
1461 unsigned int m_aclass_index : SYMBOL_ACLASS_BITS;
1463 /* If non-zero then symbol is objfile-owned, use owner.symtab.
1464 Otherwise symbol is arch-owned, use owner.arch. */
1466 unsigned int m_is_objfile_owned : 1;
1468 /* Whether this is an argument. */
1470 unsigned m_is_argument : 1;
1472 /* Whether this is an inlined function (class LOC_BLOCK only). */
1473 unsigned m_is_inlined : 1;
1475 /* For LOC_STATIC only, if this is set, then the symbol might be
1476 subject to copy relocation. In this case, a minimal symbol
1477 matching the symbol's linkage name is first looked for in the
1478 main objfile. If found, then that address is used; otherwise the
1479 address in this symbol is used. */
1481 unsigned maybe_copied : 1;
1483 /* The concrete type of this symbol. */
1485 ENUM_BITFIELD (symbol_subclass_kind) subclass : 2;
1487 /* Whether this symbol is artificial. */
1489 bool m_artificial : 1;
1491 /* Line number of this symbol's definition, except for inlined
1492 functions. For an inlined function (class LOC_BLOCK and
1493 SYMBOL_INLINED set) this is the line number of the function's call
1494 site. Inlined function symbols are not definitions, and they are
1495 never found by symbol table lookup.
1496 If this symbol is arch-owned, LINE shall be zero. */
1498 unsigned int m_line = 0;
1500 /* An arbitrary data pointer, allowing symbol readers to record
1501 additional information on a per-symbol basis. Note that this data
1502 must be allocated using the same obstack as the symbol itself. */
1503 /* So far it is only used by:
1504 LOC_COMPUTED: to find the location information
1505 LOC_BLOCK (DWARF2 function): information used internally by the
1506 DWARF 2 code --- specifically, the location expression for the frame
1507 base for this function. */
1508 /* FIXME drow/2003-02-21: For the LOC_BLOCK case, it might be better
1509 to add a magic symbol to the block containing this information,
1510 or to have a generic debug info annotation slot for symbols. */
1512 void *aux_value = nullptr;
1514 struct symbol *hash_next = nullptr;
1516 private:
1517 /* Return the address of this symbol. The MAYBE_COPIED flag must be set.
1518 If the symbol appears in the main program's minimal symbols, then
1519 that minsym's address is returned; otherwise, this symbol's address is
1520 returned. */
1521 CORE_ADDR get_maybe_copied_address () const;
1524 /* Several lookup functions return both a symbol and the block in which the
1525 symbol is found. This structure is used in these cases. */
1527 struct block_symbol
1529 /* The symbol that was found, or NULL if no symbol was found. */
1530 struct symbol *symbol;
1532 /* If SYMBOL is not NULL, then this is the block in which the symbol is
1533 defined. */
1534 const struct block *block;
1537 /* Note: There is no accessor macro for symbol.owner because it is
1538 "private". */
1540 #define SYMBOL_COMPUTED_OPS(symbol) ((symbol)->impl ().ops_computed)
1541 #define SYMBOL_BLOCK_OPS(symbol) ((symbol)->impl ().ops_block)
1542 #define SYMBOL_REGISTER_OPS(symbol) ((symbol)->impl ().ops_register)
1543 #define SYMBOL_LOCATION_BATON(symbol) (symbol)->aux_value
1545 inline const block *
1546 symbol::value_block () const
1548 if (SYMBOL_BLOCK_OPS (this) != nullptr
1549 && SYMBOL_BLOCK_OPS (this)->get_block_value != nullptr)
1550 return SYMBOL_BLOCK_OPS (this)->get_block_value (this);
1551 return m_value.block;
1554 extern int register_symbol_computed_impl (enum address_class,
1555 const struct symbol_computed_ops *);
1557 extern int register_symbol_block_impl (enum address_class aclass,
1558 const struct symbol_block_ops *ops);
1560 extern int register_symbol_register_impl (enum address_class,
1561 const struct symbol_register_ops *);
1563 /* An instance of this type is used to represent a C++ template
1564 function. A symbol is really of this type iff
1565 symbol::is_cplus_template_function is true. */
1567 struct template_symbol : public symbol
1569 /* The number of template arguments. */
1570 int n_template_arguments = 0;
1572 /* The template arguments. This is an array with
1573 N_TEMPLATE_ARGUMENTS elements. */
1574 struct symbol **template_arguments = nullptr;
1577 /* A symbol that represents a Rust virtual table object. */
1579 struct rust_vtable_symbol : public symbol
1581 /* The concrete type for which this vtable was created; that is, in
1582 "impl Trait for Type", this is "Type". */
1583 struct type *concrete_type = nullptr;
1587 /* Each item represents a line-->pc (or the reverse) mapping. This is
1588 somewhat more wasteful of space than one might wish, but since only
1589 the files which are actually debugged are read in to core, we don't
1590 waste much space. */
1592 struct linetable_entry
1594 /* Set the (unrelocated) PC for this entry. */
1595 void set_unrelocated_pc (unrelocated_addr pc)
1596 { m_pc = pc; }
1598 /* Return the unrelocated PC for this entry. */
1599 unrelocated_addr unrelocated_pc () const
1600 { return m_pc; }
1602 /* Return the relocated PC for this entry. */
1603 CORE_ADDR pc (const struct objfile *objfile) const;
1605 bool operator< (const linetable_entry &other) const
1607 if (m_pc == other.m_pc
1608 && (line != 0) != (other.line != 0))
1609 return line == 0;
1610 return m_pc < other.m_pc;
1613 /* Two entries are equal if they have the same line and PC. The
1614 other members are ignored. */
1615 bool operator== (const linetable_entry &other) const
1616 { return line == other.line && m_pc == other.m_pc; }
1618 /* The line number for this entry. */
1619 int line;
1621 /* True if this PC is a good location to place a breakpoint for LINE. */
1622 bool is_stmt : 1;
1624 /* True if this location is a good location to place a breakpoint after a
1625 function prologue. */
1626 bool prologue_end : 1;
1628 private:
1630 /* The address for this entry. */
1631 unrelocated_addr m_pc;
1634 /* The order of entries in the linetable is significant. They should
1635 be sorted by increasing values of the pc field. If there is more than
1636 one entry for a given pc, then I'm not sure what should happen (and
1637 I not sure whether we currently handle it the best way).
1639 Example: a C for statement generally looks like this
1641 10 0x100 - for the init/test part of a for stmt.
1642 20 0x200
1643 30 0x300
1644 10 0x400 - for the increment part of a for stmt.
1646 If an entry has a line number of zero, it marks the start of a PC
1647 range for which no line number information is available. It is
1648 acceptable, though wasteful of table space, for such a range to be
1649 zero length. */
1651 struct linetable
1653 int nitems;
1655 /* Actually NITEMS elements. If you don't like this use of the
1656 `struct hack', you can shove it up your ANSI (seriously, if the
1657 committee tells us how to do it, we can probably go along). */
1658 struct linetable_entry item[1];
1661 /* How to relocate the symbols from each section in a symbol file.
1662 The ordering and meaning of the offsets is file-type-dependent;
1663 typically it is indexed by section numbers or symbol types or
1664 something like that. */
1666 typedef std::vector<CORE_ADDR> section_offsets;
1668 /* Each source file or header is represented by a struct symtab.
1669 The name "symtab" is historical, another name for it is "filetab".
1670 These objects are chained through the `next' field. */
1672 struct symtab
1674 struct compunit_symtab *compunit () const
1676 return m_compunit;
1679 void set_compunit (struct compunit_symtab *compunit)
1681 m_compunit = compunit;
1684 const struct linetable *linetable () const
1686 return m_linetable;
1689 void set_linetable (const struct linetable *linetable)
1691 m_linetable = linetable;
1694 enum language language () const
1696 return m_language;
1699 void set_language (enum language language)
1701 m_language = language;
1704 /* Unordered chain of all filetabs in the compunit, with the exception
1705 that the "main" source file is the first entry in the list. */
1707 struct symtab *next;
1709 /* Backlink to containing compunit symtab. */
1711 struct compunit_symtab *m_compunit;
1713 /* Table mapping core addresses to line numbers for this file.
1714 Can be NULL if none. Never shared between different symtabs. */
1716 const struct linetable *m_linetable;
1718 /* Name of this source file, in a form appropriate to print to the user.
1720 This pointer is never nullptr. */
1722 const char *filename;
1724 /* Filename for this source file, used as an identifier to link with
1725 related objects such as associated macro_source_file objects. It must
1726 therefore match the name of any macro_source_file object created for this
1727 source file. The value can be the same as FILENAME if it is known to
1728 follow that rule, or another form of the same file name, this is up to
1729 the specific debug info reader.
1731 This pointer is never nullptr.*/
1732 const char *filename_for_id;
1734 /* Language of this source file. */
1736 enum language m_language;
1738 /* Full name of file as found by searching the source path.
1739 NULL if not yet known. */
1741 char *fullname;
1744 /* A range adapter to allowing iterating over all the file tables in a list. */
1746 using symtab_range = next_range<symtab>;
1748 /* Compunit symtabs contain the actual "symbol table", aka blockvector, as well
1749 as the list of all source files (what gdb has historically associated with
1750 the term "symtab").
1751 Additional information is recorded here that is common to all symtabs in a
1752 compilation unit (DWARF or otherwise).
1754 Example:
1755 For the case of a program built out of these files:
1757 foo.c
1758 foo1.h
1759 foo2.h
1760 bar.c
1761 foo1.h
1762 bar.h
1764 This is recorded as:
1766 objfile -> foo.c(cu) -> bar.c(cu) -> NULL
1769 foo.c bar.c
1772 foo1.h foo1.h
1775 foo2.h bar.h
1778 NULL NULL
1780 where "foo.c(cu)" and "bar.c(cu)" are struct compunit_symtab objects,
1781 and the files foo.c, etc. are struct symtab objects. */
1783 struct compunit_symtab
1785 struct objfile *objfile () const
1787 return m_objfile;
1790 void set_objfile (struct objfile *objfile)
1792 m_objfile = objfile;
1795 symtab_range filetabs () const
1797 return symtab_range (m_filetabs);
1800 void add_filetab (symtab *filetab)
1802 if (m_filetabs == nullptr)
1804 m_filetabs = filetab;
1805 m_last_filetab = filetab;
1807 else
1809 m_last_filetab->next = filetab;
1810 m_last_filetab = filetab;
1814 const char *debugformat () const
1816 return m_debugformat;
1819 void set_debugformat (const char *debugformat)
1821 m_debugformat = debugformat;
1824 const char *producer () const
1826 return m_producer;
1829 void set_producer (const char *producer)
1831 m_producer = producer;
1834 const char *dirname () const
1836 return m_dirname;
1839 void set_dirname (const char *dirname)
1841 m_dirname = dirname;
1844 struct blockvector *blockvector ()
1846 return m_blockvector;
1849 const struct blockvector *blockvector () const
1851 return m_blockvector;
1854 void set_blockvector (struct blockvector *blockvector)
1856 m_blockvector = blockvector;
1859 bool locations_valid () const
1861 return m_locations_valid;
1864 void set_locations_valid (bool locations_valid)
1866 m_locations_valid = locations_valid;
1869 bool epilogue_unwind_valid () const
1871 return m_epilogue_unwind_valid;
1874 void set_epilogue_unwind_valid (bool epilogue_unwind_valid)
1876 m_epilogue_unwind_valid = epilogue_unwind_valid;
1879 struct macro_table *macro_table () const
1881 return m_macro_table;
1884 void set_macro_table (struct macro_table *macro_table)
1886 m_macro_table = macro_table;
1889 /* Make PRIMARY_FILETAB the primary filetab of this compunit symtab.
1891 PRIMARY_FILETAB must already be a filetab of this compunit symtab. */
1893 void set_primary_filetab (symtab *primary_filetab);
1895 /* Return the primary filetab of the compunit. */
1896 symtab *primary_filetab () const;
1898 /* Set m_call_site_htab. */
1899 void set_call_site_htab (htab_t call_site_htab);
1901 /* Find call_site info for PC. */
1902 call_site *find_call_site (CORE_ADDR pc) const;
1904 /* Return the language of this compunit_symtab. */
1905 enum language language () const;
1907 /* Unordered chain of all compunit symtabs of this objfile. */
1908 struct compunit_symtab *next;
1910 /* Object file from which this symtab information was read. */
1911 struct objfile *m_objfile;
1913 /* Name of the symtab.
1914 This is *not* intended to be a usable filename, and is
1915 for debugging purposes only. */
1916 const char *name;
1918 /* Unordered list of file symtabs, except that by convention the "main"
1919 source file (e.g., .c, .cc) is guaranteed to be first.
1920 Each symtab is a file, either the "main" source file (e.g., .c, .cc)
1921 or header (e.g., .h). */
1922 symtab *m_filetabs;
1924 /* Last entry in FILETABS list.
1925 Subfiles are added to the end of the list so they accumulate in order,
1926 with the main source subfile living at the front.
1927 The main reason is so that the main source file symtab is at the head
1928 of the list, and the rest appear in order for debugging convenience. */
1929 symtab *m_last_filetab;
1931 /* Non-NULL string that identifies the format of the debugging information,
1932 such as "stabs", "dwarf 1", "dwarf 2", "coff", etc. This is mostly useful
1933 for automated testing of gdb but may also be information that is
1934 useful to the user. */
1935 const char *m_debugformat;
1937 /* String of producer version information, or NULL if we don't know. */
1938 const char *m_producer;
1940 /* Directory in which it was compiled, or NULL if we don't know. */
1941 const char *m_dirname;
1943 /* List of all symbol scope blocks for this symtab. It is shared among
1944 all symtabs in a given compilation unit. */
1945 struct blockvector *m_blockvector;
1947 /* Symtab has been compiled with both optimizations and debug info so that
1948 GDB may stop skipping prologues as variables locations are valid already
1949 at function entry points. */
1950 unsigned int m_locations_valid : 1;
1952 /* DWARF unwinder for this CU is valid even for epilogues (PC at the return
1953 instruction). This is supported by GCC since 4.5.0. */
1954 unsigned int m_epilogue_unwind_valid : 1;
1956 /* struct call_site entries for this compilation unit or NULL. */
1957 htab_t m_call_site_htab;
1959 /* The macro table for this symtab. Like the blockvector, this
1960 is shared between different symtabs in a given compilation unit.
1961 It's debatable whether it *should* be shared among all the symtabs in
1962 the given compilation unit, but it currently is. */
1963 struct macro_table *m_macro_table;
1965 /* If non-NULL, then this points to a NULL-terminated vector of
1966 included compunits. When searching the static or global
1967 block of this compunit, the corresponding block of all
1968 included compunits will also be searched. Note that this
1969 list must be flattened -- the symbol reader is responsible for
1970 ensuring that this vector contains the transitive closure of all
1971 included compunits. */
1972 struct compunit_symtab **includes;
1974 /* If this is an included compunit, this points to one includer
1975 of the table. This user is considered the canonical compunit
1976 containing this one. An included compunit may itself be
1977 included by another. */
1978 struct compunit_symtab *user;
1981 using compunit_symtab_range = next_range<compunit_symtab>;
1983 /* Return true if this symtab is the "main" symtab of its compunit_symtab. */
1985 static inline bool
1986 is_main_symtab_of_compunit_symtab (struct symtab *symtab)
1988 return symtab == symtab->compunit ()->primary_filetab ();
1991 /* Return true if epilogue unwind info of CUST is valid. */
1993 static inline bool
1994 compunit_epilogue_unwind_valid (struct compunit_symtab *cust)
1996 /* In absence of producer information, assume epilogue unwind info is
1997 valid. */
1998 if (cust == nullptr)
1999 return true;
2001 return cust->epilogue_unwind_valid ();
2005 /* The virtual function table is now an array of structures which have the
2006 form { int16 offset, delta; void *pfn; }.
2008 In normal virtual function tables, OFFSET is unused.
2009 DELTA is the amount which is added to the apparent object's base
2010 address in order to point to the actual object to which the
2011 virtual function should be applied.
2012 PFN is a pointer to the virtual function.
2014 Note that this macro is g++ specific (FIXME). */
2016 #define VTBL_FNADDR_OFFSET 2
2018 /* External variables and functions for the objects described above. */
2020 /* True if we are nested inside psymtab_to_symtab. */
2022 extern int currently_reading_symtab;
2024 /* symtab.c lookup functions */
2026 extern const char multiple_symbols_ask[];
2027 extern const char multiple_symbols_all[];
2028 extern const char multiple_symbols_cancel[];
2030 const char *multiple_symbols_select_mode (void);
2032 /* lookup a symbol table by source file name. */
2034 extern struct symtab *lookup_symtab (const char *);
2036 /* An object of this type is passed as the 'is_a_field_of_this'
2037 argument to lookup_symbol and lookup_symbol_in_language. */
2039 struct field_of_this_result
2041 /* The type in which the field was found. If this is NULL then the
2042 symbol was not found in 'this'. If non-NULL, then one of the
2043 other fields will be non-NULL as well. */
2045 struct type *type;
2047 /* If the symbol was found as an ordinary field of 'this', then this
2048 is non-NULL and points to the particular field. */
2050 struct field *field;
2052 /* If the symbol was found as a function field of 'this', then this
2053 is non-NULL and points to the particular field. */
2055 struct fn_fieldlist *fn_field;
2058 /* Find the definition for a specified symbol name NAME
2059 in domain DOMAIN in language LANGUAGE, visible from lexical block BLOCK
2060 if non-NULL or from global/static blocks if BLOCK is NULL.
2061 Returns the struct symbol pointer, or NULL if no symbol is found.
2062 C++: if IS_A_FIELD_OF_THIS is non-NULL on entry, check to see if
2063 NAME is a field of the current implied argument `this'. If so fill in the
2064 fields of IS_A_FIELD_OF_THIS, otherwise the fields are set to NULL.
2065 The symbol's section is fixed up if necessary. */
2067 extern struct block_symbol
2068 lookup_symbol_in_language (const char *,
2069 const struct block *,
2070 const domain_enum,
2071 enum language,
2072 struct field_of_this_result *);
2074 /* Same as lookup_symbol_in_language, but using the current language. */
2076 extern struct block_symbol lookup_symbol (const char *,
2077 const struct block *,
2078 const domain_enum,
2079 struct field_of_this_result *);
2081 /* Find the definition for a specified symbol search name in domain
2082 DOMAIN, visible from lexical block BLOCK if non-NULL or from
2083 global/static blocks if BLOCK is NULL. The passed-in search name
2084 should not come from the user; instead it should already be a
2085 search name as retrieved from a search_name () call. See definition of
2086 symbol_name_match_type::SEARCH_NAME. Returns the struct symbol
2087 pointer, or NULL if no symbol is found. The symbol's section is
2088 fixed up if necessary. */
2090 extern struct block_symbol lookup_symbol_search_name (const char *search_name,
2091 const struct block *block,
2092 domain_enum domain);
2094 /* Some helper functions for languages that need to write their own
2095 lookup_symbol_nonlocal functions. */
2097 /* Lookup a symbol in the static block associated to BLOCK, if there
2098 is one; do nothing if BLOCK is NULL or a global block.
2099 Upon success fixes up the symbol's section if necessary. */
2101 extern struct block_symbol
2102 lookup_symbol_in_static_block (const char *name,
2103 const struct block *block,
2104 const domain_enum domain);
2106 /* Search all static file-level symbols for NAME from DOMAIN.
2107 Upon success fixes up the symbol's section if necessary. */
2109 extern struct block_symbol lookup_static_symbol (const char *name,
2110 const domain_enum domain);
2112 /* Lookup a symbol in all files' global blocks.
2114 If BLOCK is non-NULL then it is used for two things:
2115 1) If a target-specific lookup routine for libraries exists, then use the
2116 routine for the objfile of BLOCK, and
2117 2) The objfile of BLOCK is used to assist in determining the search order
2118 if the target requires it.
2119 See gdbarch_iterate_over_objfiles_in_search_order.
2121 Upon success fixes up the symbol's section if necessary. */
2123 extern struct block_symbol
2124 lookup_global_symbol (const char *name,
2125 const struct block *block,
2126 const domain_enum domain);
2128 /* Lookup a symbol in block BLOCK.
2129 Upon success fixes up the symbol's section if necessary. */
2131 extern struct symbol *
2132 lookup_symbol_in_block (const char *name,
2133 symbol_name_match_type match_type,
2134 const struct block *block,
2135 const domain_enum domain);
2137 /* Look up the `this' symbol for LANG in BLOCK. Return the symbol if
2138 found, or NULL if not found. */
2140 extern struct block_symbol
2141 lookup_language_this (const struct language_defn *lang,
2142 const struct block *block);
2144 /* Lookup a [struct, union, enum] by name, within a specified block. */
2146 extern struct type *lookup_struct (const char *, const struct block *);
2148 extern struct type *lookup_union (const char *, const struct block *);
2150 extern struct type *lookup_enum (const char *, const struct block *);
2152 /* from blockframe.c: */
2154 /* lookup the function symbol corresponding to the address. The
2155 return value will not be an inlined function; the containing
2156 function will be returned instead. */
2158 extern struct symbol *find_pc_function (CORE_ADDR);
2160 /* lookup the function corresponding to the address and section. The
2161 return value will not be an inlined function; the containing
2162 function will be returned instead. */
2164 extern struct symbol *find_pc_sect_function (CORE_ADDR, struct obj_section *);
2166 /* lookup the function symbol corresponding to the address and
2167 section. The return value will be the closest enclosing function,
2168 which might be an inline function. */
2170 extern struct symbol *find_pc_sect_containing_function
2171 (CORE_ADDR pc, struct obj_section *section);
2173 /* Find the symbol at the given address. Returns NULL if no symbol
2174 found. Only exact matches for ADDRESS are considered. */
2176 extern struct symbol *find_symbol_at_address (CORE_ADDR);
2178 /* Finds the "function" (text symbol) that is smaller than PC but
2179 greatest of all of the potential text symbols in SECTION. Sets
2180 *NAME and/or *ADDRESS conditionally if that pointer is non-null.
2181 If ENDADDR is non-null, then set *ENDADDR to be the end of the
2182 function (exclusive). If the optional parameter BLOCK is non-null,
2183 then set *BLOCK to the address of the block corresponding to the
2184 function symbol, if such a symbol could be found during the lookup;
2185 nullptr is used as a return value for *BLOCK if no block is found.
2186 This function either succeeds or fails (not halfway succeeds). If
2187 it succeeds, it sets *NAME, *ADDRESS, and *ENDADDR to real
2188 information and returns true. If it fails, it sets *NAME, *ADDRESS
2189 and *ENDADDR to zero and returns false.
2191 If the function in question occupies non-contiguous ranges,
2192 *ADDRESS and *ENDADDR are (subject to the conditions noted above) set
2193 to the start and end of the range in which PC is found. Thus
2194 *ADDRESS <= PC < *ENDADDR with no intervening gaps (in which ranges
2195 from other functions might be found).
2197 This property allows find_pc_partial_function to be used (as it had
2198 been prior to the introduction of non-contiguous range support) by
2199 various tdep files for finding a start address and limit address
2200 for prologue analysis. This still isn't ideal, however, because we
2201 probably shouldn't be doing prologue analysis (in which
2202 instructions are scanned to determine frame size and stack layout)
2203 for any range that doesn't contain the entry pc. Moreover, a good
2204 argument can be made that prologue analysis ought to be performed
2205 starting from the entry pc even when PC is within some other range.
2206 This might suggest that *ADDRESS and *ENDADDR ought to be set to the
2207 limits of the entry pc range, but that will cause the
2208 *ADDRESS <= PC < *ENDADDR condition to be violated; many of the
2209 callers of find_pc_partial_function expect this condition to hold.
2211 Callers which require the start and/or end addresses for the range
2212 containing the entry pc should instead call
2213 find_function_entry_range_from_pc. */
2215 extern bool find_pc_partial_function (CORE_ADDR pc, const char **name,
2216 CORE_ADDR *address, CORE_ADDR *endaddr,
2217 const struct block **block = nullptr);
2219 /* Like find_pc_partial_function, above, but returns the underlying
2220 general_symbol_info (rather than the name) as an out parameter. */
2222 extern bool find_pc_partial_function_sym
2223 (CORE_ADDR pc, const general_symbol_info **sym,
2224 CORE_ADDR *address, CORE_ADDR *endaddr,
2225 const struct block **block = nullptr);
2227 /* Like find_pc_partial_function, above, but *ADDRESS and *ENDADDR are
2228 set to start and end addresses of the range containing the entry pc.
2230 Note that it is not necessarily the case that (for non-NULL ADDRESS
2231 and ENDADDR arguments) the *ADDRESS <= PC < *ENDADDR condition will
2232 hold.
2234 See comment for find_pc_partial_function, above, for further
2235 explanation. */
2237 extern bool find_function_entry_range_from_pc (CORE_ADDR pc,
2238 const char **name,
2239 CORE_ADDR *address,
2240 CORE_ADDR *endaddr);
2242 /* Return the type of a function with its first instruction exactly at
2243 the PC address. Return NULL otherwise. */
2245 extern struct type *find_function_type (CORE_ADDR pc);
2247 /* See if we can figure out the function's actual type from the type
2248 that the resolver returns. RESOLVER_FUNADDR is the address of the
2249 ifunc resolver. */
2251 extern struct type *find_gnu_ifunc_target_type (CORE_ADDR resolver_funaddr);
2253 /* Find the GNU ifunc minimal symbol that matches SYM. */
2254 extern bound_minimal_symbol find_gnu_ifunc (const symbol *sym);
2256 extern void clear_pc_function_cache (void);
2258 /* lookup full symbol table by address. */
2260 extern struct compunit_symtab *find_pc_compunit_symtab (CORE_ADDR);
2262 /* lookup full symbol table by address and section. */
2264 extern struct compunit_symtab *
2265 find_pc_sect_compunit_symtab (CORE_ADDR, struct obj_section *);
2267 extern bool find_pc_line_pc_range (CORE_ADDR, CORE_ADDR *, CORE_ADDR *);
2269 extern void reread_symbols (int from_tty);
2271 /* Look up a type named NAME in STRUCT_DOMAIN in the current language.
2272 The type returned must not be opaque -- i.e., must have at least one field
2273 defined. */
2275 extern struct type *lookup_transparent_type (const char *);
2277 extern struct type *basic_lookup_transparent_type (const char *);
2279 /* Macro for name of symbol to indicate a file compiled with gcc. */
2280 #ifndef GCC_COMPILED_FLAG_SYMBOL
2281 #define GCC_COMPILED_FLAG_SYMBOL "gcc_compiled."
2282 #endif
2284 /* Macro for name of symbol to indicate a file compiled with gcc2. */
2285 #ifndef GCC2_COMPILED_FLAG_SYMBOL
2286 #define GCC2_COMPILED_FLAG_SYMBOL "gcc2_compiled."
2287 #endif
2289 extern bool in_gnu_ifunc_stub (CORE_ADDR pc);
2291 /* Functions for resolving STT_GNU_IFUNC symbols which are implemented only
2292 for ELF symbol files. */
2294 struct gnu_ifunc_fns
2296 /* See elf_gnu_ifunc_resolve_addr for its real implementation. */
2297 CORE_ADDR (*gnu_ifunc_resolve_addr) (struct gdbarch *gdbarch, CORE_ADDR pc);
2299 /* See elf_gnu_ifunc_resolve_name for its real implementation. */
2300 bool (*gnu_ifunc_resolve_name) (const char *function_name,
2301 CORE_ADDR *function_address_p);
2303 /* See elf_gnu_ifunc_resolver_stop for its real implementation. */
2304 void (*gnu_ifunc_resolver_stop) (code_breakpoint *b);
2306 /* See elf_gnu_ifunc_resolver_return_stop for its real implementation. */
2307 void (*gnu_ifunc_resolver_return_stop) (code_breakpoint *b);
2310 #define gnu_ifunc_resolve_addr gnu_ifunc_fns_p->gnu_ifunc_resolve_addr
2311 #define gnu_ifunc_resolve_name gnu_ifunc_fns_p->gnu_ifunc_resolve_name
2312 #define gnu_ifunc_resolver_stop gnu_ifunc_fns_p->gnu_ifunc_resolver_stop
2313 #define gnu_ifunc_resolver_return_stop \
2314 gnu_ifunc_fns_p->gnu_ifunc_resolver_return_stop
2316 extern const struct gnu_ifunc_fns *gnu_ifunc_fns_p;
2318 extern CORE_ADDR find_solib_trampoline_target (frame_info_ptr, CORE_ADDR);
2320 struct symtab_and_line
2322 /* The program space of this sal. */
2323 struct program_space *pspace = NULL;
2325 struct symtab *symtab = NULL;
2326 struct symbol *symbol = NULL;
2327 struct obj_section *section = NULL;
2328 struct minimal_symbol *msymbol = NULL;
2329 /* Line number. Line numbers start at 1 and proceed through symtab->nlines.
2330 0 is never a valid line number; it is used to indicate that line number
2331 information is not available. */
2332 int line = 0;
2334 CORE_ADDR pc = 0;
2335 CORE_ADDR end = 0;
2336 bool explicit_pc = false;
2337 bool explicit_line = false;
2339 /* If the line number information is valid, then this indicates if this
2340 line table entry had the is-stmt flag set or not. */
2341 bool is_stmt = false;
2343 /* The probe associated with this symtab_and_line. */
2344 probe *prob = NULL;
2345 /* If PROBE is not NULL, then this is the objfile in which the probe
2346 originated. */
2347 struct objfile *objfile = NULL;
2352 /* Given a pc value, return line number it is in. Second arg nonzero means
2353 if pc is on the boundary use the previous statement's line number. */
2355 extern struct symtab_and_line find_pc_line (CORE_ADDR, int);
2357 /* Same function, but specify a section as well as an address. */
2359 extern struct symtab_and_line find_pc_sect_line (CORE_ADDR,
2360 struct obj_section *, int);
2362 /* Wrapper around find_pc_line to just return the symtab. */
2364 extern struct symtab *find_pc_line_symtab (CORE_ADDR);
2366 /* Given a symtab and line number, return the pc there. */
2368 extern bool find_line_pc (struct symtab *, int, CORE_ADDR *);
2370 extern bool find_line_pc_range (struct symtab_and_line, CORE_ADDR *,
2371 CORE_ADDR *);
2373 extern void resolve_sal_pc (struct symtab_and_line *);
2375 /* solib.c */
2377 extern void clear_solib (void);
2379 /* The reason we're calling into a completion match list collector
2380 function. */
2381 enum class complete_symbol_mode
2383 /* Completing an expression. */
2384 EXPRESSION,
2386 /* Completing a linespec. */
2387 LINESPEC,
2390 extern void default_collect_symbol_completion_matches_break_on
2391 (completion_tracker &tracker,
2392 complete_symbol_mode mode,
2393 symbol_name_match_type name_match_type,
2394 const char *text, const char *word, const char *break_on,
2395 enum type_code code);
2396 extern void collect_symbol_completion_matches
2397 (completion_tracker &tracker,
2398 complete_symbol_mode mode,
2399 symbol_name_match_type name_match_type,
2400 const char *, const char *);
2401 extern void collect_symbol_completion_matches_type (completion_tracker &tracker,
2402 const char *, const char *,
2403 enum type_code);
2405 extern void collect_file_symbol_completion_matches
2406 (completion_tracker &tracker,
2407 complete_symbol_mode,
2408 symbol_name_match_type name_match_type,
2409 const char *, const char *, const char *);
2411 extern completion_list
2412 make_source_files_completion_list (const char *, const char *);
2414 /* Return whether SYM is a function/method, as opposed to a data symbol. */
2416 extern bool symbol_is_function_or_method (symbol *sym);
2418 /* Return whether MSYMBOL is a function/method, as opposed to a data
2419 symbol */
2421 extern bool symbol_is_function_or_method (minimal_symbol *msymbol);
2423 /* Return whether SYM should be skipped in completion mode MODE. In
2424 linespec mode, we're only interested in functions/methods. */
2426 template<typename Symbol>
2427 static bool
2428 completion_skip_symbol (complete_symbol_mode mode, Symbol *sym)
2430 return (mode == complete_symbol_mode::LINESPEC
2431 && !symbol_is_function_or_method (sym));
2434 /* symtab.c */
2436 bool matching_obj_sections (struct obj_section *, struct obj_section *);
2438 extern struct symtab *find_line_symtab (struct symtab *, int, int *, bool *);
2440 /* Given a function symbol SYM, find the symtab and line for the start
2441 of the function. If FUNFIRSTLINE is true, we want the first line
2442 of real code inside the function. */
2443 extern symtab_and_line find_function_start_sal (symbol *sym, bool
2444 funfirstline);
2446 /* Same, but start with a function address/section instead of a
2447 symbol. */
2448 extern symtab_and_line find_function_start_sal (CORE_ADDR func_addr,
2449 obj_section *section,
2450 bool funfirstline);
2452 extern void skip_prologue_sal (struct symtab_and_line *);
2454 /* symtab.c */
2456 extern CORE_ADDR skip_prologue_using_sal (struct gdbarch *gdbarch,
2457 CORE_ADDR func_addr);
2459 /* If SYM requires a section index, find it either via minimal symbols
2460 or examining OBJFILE's sections. Note that SYM's current address
2461 must not have any runtime offsets applied. */
2463 extern void fixup_symbol_section (struct symbol *sym,
2464 struct objfile *objfile);
2466 /* If MSYMBOL is an text symbol, look for a function debug symbol with
2467 the same address. Returns NULL if not found. This is necessary in
2468 case a function is an alias to some other function, because debug
2469 information is only emitted for the alias target function's
2470 definition, not for the alias. */
2471 extern symbol *find_function_alias_target (bound_minimal_symbol msymbol);
2473 /* Symbol searching */
2475 /* When using the symbol_searcher struct to search for symbols, a vector of
2476 the following structs is returned. */
2477 struct symbol_search
2479 symbol_search (block_enum block_, struct symbol *symbol_)
2480 : block (block_),
2481 symbol (symbol_)
2483 msymbol.minsym = nullptr;
2484 msymbol.objfile = nullptr;
2487 symbol_search (block_enum block_, struct minimal_symbol *minsym,
2488 struct objfile *objfile)
2489 : block (block_),
2490 symbol (nullptr)
2492 msymbol.minsym = minsym;
2493 msymbol.objfile = objfile;
2496 bool operator< (const symbol_search &other) const
2498 return compare_search_syms (*this, other) < 0;
2501 bool operator== (const symbol_search &other) const
2503 return compare_search_syms (*this, other) == 0;
2506 /* The block in which the match was found. Either STATIC_BLOCK or
2507 GLOBAL_BLOCK. */
2508 block_enum block;
2510 /* Information describing what was found.
2512 If symbol is NOT NULL, then information was found for this match. */
2513 struct symbol *symbol;
2515 /* If msymbol is non-null, then a match was made on something for
2516 which only minimal_symbols exist. */
2517 struct bound_minimal_symbol msymbol;
2519 private:
2521 static int compare_search_syms (const symbol_search &sym_a,
2522 const symbol_search &sym_b);
2525 /* In order to search for global symbols of a particular kind matching
2526 particular regular expressions, create an instance of this structure and
2527 call the SEARCH member function. */
2528 class global_symbol_searcher
2530 public:
2532 /* Constructor. */
2533 global_symbol_searcher (enum search_domain kind,
2534 const char *symbol_name_regexp)
2535 : m_kind (kind),
2536 m_symbol_name_regexp (symbol_name_regexp)
2538 /* The symbol searching is designed to only find one kind of thing. */
2539 gdb_assert (m_kind != ALL_DOMAIN);
2542 /* Set the optional regexp that matches against the symbol type. */
2543 void set_symbol_type_regexp (const char *regexp)
2545 m_symbol_type_regexp = regexp;
2548 /* Set the flag to exclude minsyms from the search results. */
2549 void set_exclude_minsyms (bool exclude_minsyms)
2551 m_exclude_minsyms = exclude_minsyms;
2554 /* Set the maximum number of search results to be returned. */
2555 void set_max_search_results (size_t max_search_results)
2557 m_max_search_results = max_search_results;
2560 /* Search the symbols from all objfiles in the current program space
2561 looking for matches as defined by the current state of this object.
2563 Within each file the results are sorted locally; each symtab's global
2564 and static blocks are separately alphabetized. Duplicate entries are
2565 removed. */
2566 std::vector<symbol_search> search () const;
2568 /* The set of source files to search in for matching symbols. This is
2569 currently public so that it can be populated after this object has
2570 been constructed. */
2571 std::vector<const char *> filenames;
2573 private:
2574 /* The kind of symbols are we searching for.
2575 VARIABLES_DOMAIN - Search all symbols, excluding functions, type
2576 names, and constants (enums).
2577 FUNCTIONS_DOMAIN - Search all functions..
2578 TYPES_DOMAIN - Search all type names.
2579 MODULES_DOMAIN - Search all Fortran modules.
2580 ALL_DOMAIN - Not valid for this function. */
2581 enum search_domain m_kind;
2583 /* Regular expression to match against the symbol name. */
2584 const char *m_symbol_name_regexp = nullptr;
2586 /* Regular expression to match against the symbol type. */
2587 const char *m_symbol_type_regexp = nullptr;
2589 /* When this flag is false then minsyms that match M_SYMBOL_REGEXP will
2590 be included in the results, otherwise they are excluded. */
2591 bool m_exclude_minsyms = false;
2593 /* Maximum number of search results. We currently impose a hard limit
2594 of SIZE_MAX, there is no "unlimited". */
2595 size_t m_max_search_results = SIZE_MAX;
2597 /* Expand symtabs in OBJFILE that match PREG, are of type M_KIND. Return
2598 true if any msymbols were seen that we should later consider adding to
2599 the results list. */
2600 bool expand_symtabs (objfile *objfile,
2601 const gdb::optional<compiled_regex> &preg) const;
2603 /* Add symbols from symtabs in OBJFILE that match PREG, and TREG, and are
2604 of type M_KIND, to the results set RESULTS_SET. Return false if we
2605 stop adding results early due to having already found too many results
2606 (based on M_MAX_SEARCH_RESULTS limit), otherwise return true.
2607 Returning true does not indicate that any results were added, just
2608 that we didn't _not_ add a result due to reaching MAX_SEARCH_RESULTS. */
2609 bool add_matching_symbols (objfile *objfile,
2610 const gdb::optional<compiled_regex> &preg,
2611 const gdb::optional<compiled_regex> &treg,
2612 std::set<symbol_search> *result_set) const;
2614 /* Add msymbols from OBJFILE that match PREG and M_KIND, to the results
2615 vector RESULTS. Return false if we stop adding results early due to
2616 having already found too many results (based on max search results
2617 limit M_MAX_SEARCH_RESULTS), otherwise return true. Returning true
2618 does not indicate that any results were added, just that we didn't
2619 _not_ add a result due to reaching MAX_SEARCH_RESULTS. */
2620 bool add_matching_msymbols (objfile *objfile,
2621 const gdb::optional<compiled_regex> &preg,
2622 std::vector<symbol_search> *results) const;
2624 /* Return true if MSYMBOL is of type KIND. */
2625 static bool is_suitable_msymbol (const enum search_domain kind,
2626 const minimal_symbol *msymbol);
2629 /* When searching for Fortran symbols within modules (functions/variables)
2630 we return a vector of this type. The first item in the pair is the
2631 module symbol, and the second item is the symbol for the function or
2632 variable we found. */
2633 typedef std::pair<symbol_search, symbol_search> module_symbol_search;
2635 /* Searches the symbols to find function and variables symbols (depending
2636 on KIND) within Fortran modules. The MODULE_REGEXP matches against the
2637 name of the module, REGEXP matches against the name of the symbol within
2638 the module, and TYPE_REGEXP matches against the type of the symbol
2639 within the module. */
2640 extern std::vector<module_symbol_search> search_module_symbols
2641 (const char *module_regexp, const char *regexp,
2642 const char *type_regexp, search_domain kind);
2644 /* Convert a global or static symbol SYM (based on BLOCK, which should be
2645 either GLOBAL_BLOCK or STATIC_BLOCK) into a string for use in 'info'
2646 type commands (e.g. 'info variables', 'info functions', etc). KIND is
2647 the type of symbol that was searched for which gave us SYM. */
2649 extern std::string symbol_to_info_string (struct symbol *sym, int block,
2650 enum search_domain kind);
2652 extern bool treg_matches_sym_type_name (const compiled_regex &treg,
2653 const struct symbol *sym);
2655 /* The name of the ``main'' function. */
2656 extern const char *main_name ();
2657 extern enum language main_language (void);
2659 /* Lookup symbol NAME from DOMAIN in MAIN_OBJFILE's global or static blocks,
2660 as specified by BLOCK_INDEX.
2661 This searches MAIN_OBJFILE as well as any associated separate debug info
2662 objfiles of MAIN_OBJFILE.
2663 BLOCK_INDEX can be GLOBAL_BLOCK or STATIC_BLOCK.
2664 Upon success fixes up the symbol's section if necessary. */
2666 extern struct block_symbol
2667 lookup_global_symbol_from_objfile (struct objfile *main_objfile,
2668 enum block_enum block_index,
2669 const char *name,
2670 const domain_enum domain);
2672 /* Return 1 if the supplied producer string matches the ARM RealView
2673 compiler (armcc). */
2674 bool producer_is_realview (const char *producer);
2676 extern unsigned int symtab_create_debug;
2678 /* Print a "symtab-create" debug statement. */
2680 #define symtab_create_debug_printf(fmt, ...) \
2681 debug_prefixed_printf_cond (symtab_create_debug >= 1, "symtab-create", fmt, ##__VA_ARGS__)
2683 /* Print a verbose "symtab-create" debug statement, only if
2684 "set debug symtab-create" is set to 2 or higher. */
2686 #define symtab_create_debug_printf_v(fmt, ...) \
2687 debug_prefixed_printf_cond (symtab_create_debug >= 2, "symtab-create", fmt, ##__VA_ARGS__)
2689 extern unsigned int symbol_lookup_debug;
2691 /* Return true if symbol-lookup debug is turned on at all. */
2693 static inline bool
2694 symbol_lookup_debug_enabled ()
2696 return symbol_lookup_debug > 0;
2699 /* Return true if symbol-lookup debug is turned to verbose mode. */
2701 static inline bool
2702 symbol_lookup_debug_enabled_v ()
2704 return symbol_lookup_debug > 1;
2707 /* Print a "symbol-lookup" debug statement if symbol_lookup_debug is >= 1. */
2709 #define symbol_lookup_debug_printf(fmt, ...) \
2710 debug_prefixed_printf_cond (symbol_lookup_debug_enabled (), \
2711 "symbol-lookup", fmt, ##__VA_ARGS__)
2713 /* Print a "symbol-lookup" debug statement if symbol_lookup_debug is >= 2. */
2715 #define symbol_lookup_debug_printf_v(fmt, ...) \
2716 debug_prefixed_printf_cond (symbol_lookup_debug_enabled_v (), \
2717 "symbol-lookup", fmt, ##__VA_ARGS__)
2719 /* Print "symbol-lookup" enter/exit debug statements. */
2721 #define SYMBOL_LOOKUP_SCOPED_DEBUG_ENTER_EXIT \
2722 scoped_debug_enter_exit (symbol_lookup_debug_enabled, "symbol-lookup")
2724 extern bool basenames_may_differ;
2726 bool compare_filenames_for_search (const char *filename,
2727 const char *search_name);
2729 bool compare_glob_filenames_for_search (const char *filename,
2730 const char *search_name);
2732 bool iterate_over_some_symtabs (const char *name,
2733 const char *real_path,
2734 struct compunit_symtab *first,
2735 struct compunit_symtab *after_last,
2736 gdb::function_view<bool (symtab *)> callback);
2738 void iterate_over_symtabs (const char *name,
2739 gdb::function_view<bool (symtab *)> callback);
2742 std::vector<CORE_ADDR> find_pcs_for_symtab_line
2743 (struct symtab *symtab, int line, const linetable_entry **best_entry);
2745 /* Prototype for callbacks for LA_ITERATE_OVER_SYMBOLS. The callback
2746 is called once per matching symbol SYM. The callback should return
2747 true to indicate that LA_ITERATE_OVER_SYMBOLS should continue
2748 iterating, or false to indicate that the iteration should end. */
2750 typedef bool (symbol_found_callback_ftype) (struct block_symbol *bsym);
2752 /* Iterate over the symbols named NAME, matching DOMAIN, in BLOCK.
2754 For each symbol that matches, CALLBACK is called. The symbol is
2755 passed to the callback.
2757 If CALLBACK returns false, the iteration ends and this function
2758 returns false. Otherwise, the search continues, and the function
2759 eventually returns true. */
2761 bool iterate_over_symbols (const struct block *block,
2762 const lookup_name_info &name,
2763 const domain_enum domain,
2764 gdb::function_view<symbol_found_callback_ftype> callback);
2766 /* Like iterate_over_symbols, but if all calls to CALLBACK return
2767 true, then calls CALLBACK one additional time with a block_symbol
2768 that has a valid block but a NULL symbol. */
2770 bool iterate_over_symbols_terminated
2771 (const struct block *block,
2772 const lookup_name_info &name,
2773 const domain_enum domain,
2774 gdb::function_view<symbol_found_callback_ftype> callback);
2776 /* Storage type used by demangle_for_lookup. demangle_for_lookup
2777 either returns a const char * pointer that points to either of the
2778 fields of this type, or a pointer to the input NAME. This is done
2779 this way to avoid depending on the precise details of the storage
2780 for the string. */
2781 class demangle_result_storage
2783 public:
2785 /* Swap the malloc storage to STR, and return a pointer to the
2786 beginning of the new string. */
2787 const char *set_malloc_ptr (gdb::unique_xmalloc_ptr<char> &&str)
2789 m_malloc = std::move (str);
2790 return m_malloc.get ();
2793 /* Set the malloc storage to now point at PTR. Any previous malloc
2794 storage is released. */
2795 const char *set_malloc_ptr (char *ptr)
2797 m_malloc.reset (ptr);
2798 return ptr;
2801 private:
2803 /* The storage. */
2804 gdb::unique_xmalloc_ptr<char> m_malloc;
2807 const char *
2808 demangle_for_lookup (const char *name, enum language lang,
2809 demangle_result_storage &storage);
2811 /* Test to see if the symbol of language SYMBOL_LANGUAGE specified by
2812 SYMNAME (which is already demangled for C++ symbols) matches
2813 SYM_TEXT in the first SYM_TEXT_LEN characters. If so, add it to
2814 the current completion list and return true. Otherwise, return
2815 false. */
2816 bool completion_list_add_name (completion_tracker &tracker,
2817 language symbol_language,
2818 const char *symname,
2819 const lookup_name_info &lookup_name,
2820 const char *text, const char *word);
2822 /* A simple symbol searching class. */
2824 class symbol_searcher
2826 public:
2827 /* Returns the symbols found for the search. */
2828 const std::vector<block_symbol> &
2829 matching_symbols () const
2831 return m_symbols;
2834 /* Returns the minimal symbols found for the search. */
2835 const std::vector<bound_minimal_symbol> &
2836 matching_msymbols () const
2838 return m_minimal_symbols;
2841 /* Search for all symbols named NAME in LANGUAGE with DOMAIN, restricting
2842 search to FILE_SYMTABS and SEARCH_PSPACE, both of which may be NULL
2843 to search all symtabs and program spaces. */
2844 void find_all_symbols (const std::string &name,
2845 const struct language_defn *language,
2846 enum search_domain search_domain,
2847 std::vector<symtab *> *search_symtabs,
2848 struct program_space *search_pspace);
2850 /* Reset this object to perform another search. */
2851 void reset ()
2853 m_symbols.clear ();
2854 m_minimal_symbols.clear ();
2857 private:
2858 /* Matching debug symbols. */
2859 std::vector<block_symbol> m_symbols;
2861 /* Matching non-debug symbols. */
2862 std::vector<bound_minimal_symbol> m_minimal_symbols;
2865 /* Class used to encapsulate the filename filtering for the "info sources"
2866 command. */
2868 struct info_sources_filter
2870 /* If filename filtering is being used (see M_C_REGEXP) then which part
2871 of the filename is being filtered against? */
2872 enum class match_on
2874 /* Match against the full filename. */
2875 FULLNAME,
2877 /* Match only against the directory part of the full filename. */
2878 DIRNAME,
2880 /* Match only against the basename part of the full filename. */
2881 BASENAME
2884 /* Create a filter of MATCH_TYPE using regular expression REGEXP. If
2885 REGEXP is nullptr then all files will match the filter and MATCH_TYPE
2886 is ignored.
2888 The string pointed too by REGEXP must remain live and unchanged for
2889 this lifetime of this object as the object only retains a copy of the
2890 pointer. */
2891 info_sources_filter (match_on match_type, const char *regexp);
2893 DISABLE_COPY_AND_ASSIGN (info_sources_filter);
2895 /* Does FULLNAME match the filter defined by this object, return true if
2896 it does, otherwise, return false. If there is no filtering defined
2897 then this function will always return true. */
2898 bool matches (const char *fullname) const;
2900 private:
2902 /* The type of filtering in place. */
2903 match_on m_match_type;
2905 /* Points to the original regexp used to create this filter. */
2906 const char *m_regexp;
2908 /* A compiled version of M_REGEXP. This object is only given a value if
2909 M_REGEXP is not nullptr and is not the empty string. */
2910 gdb::optional<compiled_regex> m_c_regexp;
2913 /* Perform the core of the 'info sources' command.
2915 FILTER is used to perform regular expression based filtering on the
2916 source files that will be displayed.
2918 Output is written to UIOUT in CLI or MI style as appropriate. */
2920 extern void info_sources_worker (struct ui_out *uiout,
2921 bool group_by_objfile,
2922 const info_sources_filter &filter);
2924 #endif /* !defined(SYMTAB_H) */