Fix: Null pointer dereference in ldlex.l
[binutils-gdb.git] / gdb / symtab.h
blob365743384e175c46c1c764311c933ac46cb3ca77
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 /* Return the address of SYM. The MAYBE_COPIED flag must be set on
634 SYM. If SYM appears in the main program's minimal symbols, then
635 that minsym's address is returned; otherwise, SYM's address is
636 returned. This should generally only be used via the
637 SYMBOL_VALUE_ADDRESS macro. */
639 extern CORE_ADDR get_symbol_address (const struct symbol *sym);
641 /* Try to determine the demangled name for a symbol, based on the
642 language of that symbol. If the language is set to language_auto,
643 it will attempt to find any demangling algorithm that works and
644 then set the language appropriately. The returned name is allocated
645 by the demangler and should be xfree'd. */
647 extern gdb::unique_xmalloc_ptr<char> symbol_find_demangled_name
648 (struct general_symbol_info *gsymbol, const char *mangled);
650 /* Return true if NAME matches the "search" name of GSYMBOL, according
651 to the symbol's language. */
652 extern bool symbol_matches_search_name
653 (const struct general_symbol_info *gsymbol,
654 const lookup_name_info &name);
656 /* Compute the hash of the given symbol search name of a symbol of
657 language LANGUAGE. */
658 extern unsigned int search_name_hash (enum language language,
659 const char *search_name);
661 /* Classification types for a minimal symbol. These should be taken as
662 "advisory only", since if gdb can't easily figure out a
663 classification it simply selects mst_unknown. It may also have to
664 guess when it can't figure out which is a better match between two
665 types (mst_data versus mst_bss) for example. Since the minimal
666 symbol info is sometimes derived from the BFD library's view of a
667 file, we need to live with what information bfd supplies. */
669 enum minimal_symbol_type
671 mst_unknown = 0, /* Unknown type, the default */
672 mst_text, /* Generally executable instructions */
674 /* A GNU ifunc symbol, in the .text section. GDB uses to know
675 whether the user is setting a breakpoint on a GNU ifunc function,
676 and thus GDB needs to actually set the breakpoint on the target
677 function. It is also used to know whether the program stepped
678 into an ifunc resolver -- the resolver may get a separate
679 symbol/alias under a different name, but it'll have the same
680 address as the ifunc symbol. */
681 mst_text_gnu_ifunc, /* Executable code returning address
682 of executable code */
684 /* A GNU ifunc function descriptor symbol, in a data section
685 (typically ".opd"). Seen on architectures that use function
686 descriptors, like PPC64/ELFv1. In this case, this symbol's value
687 is the address of the descriptor. There'll be a corresponding
688 mst_text_gnu_ifunc synthetic symbol for the text/entry
689 address. */
690 mst_data_gnu_ifunc, /* Executable code returning address
691 of executable code */
693 mst_slot_got_plt, /* GOT entries for .plt sections */
694 mst_data, /* Generally initialized data */
695 mst_bss, /* Generally uninitialized data */
696 mst_abs, /* Generally absolute (nonrelocatable) */
697 /* GDB uses mst_solib_trampoline for the start address of a shared
698 library trampoline entry. Breakpoints for shared library functions
699 are put there if the shared library is not yet loaded.
700 After the shared library is loaded, lookup_minimal_symbol will
701 prefer the minimal symbol from the shared library (usually
702 a mst_text symbol) over the mst_solib_trampoline symbol, and the
703 breakpoints will be moved to their true address in the shared
704 library via breakpoint_re_set. */
705 mst_solib_trampoline, /* Shared library trampoline code */
706 /* For the mst_file* types, the names are only guaranteed to be unique
707 within a given .o file. */
708 mst_file_text, /* Static version of mst_text */
709 mst_file_data, /* Static version of mst_data */
710 mst_file_bss, /* Static version of mst_bss */
711 nr_minsym_types
714 /* The number of enum minimal_symbol_type values, with some padding for
715 reasonable growth. */
716 #define MINSYM_TYPE_BITS 4
717 gdb_static_assert (nr_minsym_types <= (1 << MINSYM_TYPE_BITS));
719 /* Return the address of MINSYM, which comes from OBJF. The
720 MAYBE_COPIED flag must be set on MINSYM. If MINSYM appears in the
721 main program's minimal symbols, then that minsym's address is
722 returned; otherwise, MINSYM's address is returned. This should
723 generally only be used via the MSYMBOL_VALUE_ADDRESS macro. */
725 extern CORE_ADDR get_msymbol_address (struct objfile *objf,
726 const struct minimal_symbol *minsym);
728 /* Define a simple structure used to hold some very basic information about
729 all defined global symbols (text, data, bss, abs, etc). The only required
730 information is the general_symbol_info.
732 In many cases, even if a file was compiled with no special options for
733 debugging at all, as long as was not stripped it will contain sufficient
734 information to build a useful minimal symbol table using this structure.
735 Even when a file contains enough debugging information to build a full
736 symbol table, these minimal symbols are still useful for quickly mapping
737 between names and addresses, and vice versa. They are also sometimes
738 used to figure out what full symbol table entries need to be read in. */
740 struct minimal_symbol : public general_symbol_info
742 LONGEST value_longest () const
744 return m_value.ivalue;
747 /* The relocated address of the minimal symbol, using the section
748 offsets from OBJFILE. */
749 CORE_ADDR value_address (objfile *objfile) const;
751 /* It does not make sense to call this for minimal symbols, as they
752 are stored unrelocated. */
753 CORE_ADDR value_address () const = delete;
755 /* The unrelocated address of the minimal symbol. */
756 unrelocated_addr unrelocated_address () const
758 return m_value.unrel_addr;
761 /* The unrelocated address just after the end of the the minimal
762 symbol. */
763 unrelocated_addr unrelocated_end_address () const
765 return unrelocated_addr (CORE_ADDR (unrelocated_address ()) + size ());
768 /* Return this minimal symbol's type. */
770 minimal_symbol_type type () const
772 return m_type;
775 /* Set this minimal symbol's type. */
777 void set_type (minimal_symbol_type type)
779 m_type = type;
782 /* Return this minimal symbol's size. */
784 unsigned long size () const
786 return m_size;
789 /* Set this minimal symbol's size. */
791 void set_size (unsigned long size)
793 m_size = size;
794 m_has_size = 1;
797 /* Return true if this minimal symbol's size is known. */
799 bool has_size () const
801 return m_has_size;
804 /* Return this minimal symbol's first target-specific flag. */
806 bool target_flag_1 () const
808 return m_target_flag_1;
811 /* Set this minimal symbol's first target-specific flag. */
813 void set_target_flag_1 (bool target_flag_1)
815 m_target_flag_1 = target_flag_1;
818 /* Return this minimal symbol's second target-specific flag. */
820 bool target_flag_2 () const
822 return m_target_flag_2;
825 /* Set this minimal symbol's second target-specific flag. */
827 void set_target_flag_2 (bool target_flag_2)
829 m_target_flag_2 = target_flag_2;
832 /* Size of this symbol. dbx_end_psymtab in dbxread.c uses this
833 information to calculate the end of the partial symtab based on the
834 address of the last symbol plus the size of the last symbol. */
836 unsigned long m_size;
838 /* Which source file is this symbol in? Only relevant for mst_file_*. */
839 const char *filename;
841 /* Classification type for this minimal symbol. */
843 ENUM_BITFIELD(minimal_symbol_type) m_type : MINSYM_TYPE_BITS;
845 /* Non-zero if this symbol was created by gdb.
846 Such symbols do not appear in the output of "info var|fun". */
847 unsigned int created_by_gdb : 1;
849 /* Two flag bits provided for the use of the target. */
850 unsigned int m_target_flag_1 : 1;
851 unsigned int m_target_flag_2 : 1;
853 /* Nonzero iff the size of the minimal symbol has been set.
854 Symbol size information can sometimes not be determined, because
855 the object file format may not carry that piece of information. */
856 unsigned int m_has_size : 1;
858 /* Non-zero if this symbol ever had its demangled name set (even if
859 it was set to NULL). */
860 unsigned int name_set : 1;
862 /* Minimal symbols with the same hash key are kept on a linked
863 list. This is the link. */
865 struct minimal_symbol *hash_next;
867 /* Minimal symbols are stored in two different hash tables. This is
868 the `next' pointer for the demangled hash table. */
870 struct minimal_symbol *demangled_hash_next;
872 /* True if this symbol is of some data type. */
874 bool data_p () const;
876 /* True if MSYMBOL is of some text type. */
878 bool text_p () const;
880 /* For data symbols only, given an objfile, if 'maybe_copied'
881 evaluates to 'true' for that objfile, then the symbol might be
882 subject to copy relocation. In this case, a minimal symbol
883 matching the symbol's linkage name is first looked for in the
884 main objfile. If found, then that address is used; otherwise the
885 address in this symbol is used. */
887 bool maybe_copied (objfile *objfile) const;
890 #include "minsyms.h"
894 /* Represent one symbol name; a variable, constant, function or typedef. */
896 /* Different name domains for symbols. Looking up a symbol specifies a
897 domain and ignores symbol definitions in other name domains. */
899 enum domain_enum
901 /* UNDEF_DOMAIN is used when a domain has not been discovered or
902 none of the following apply. This usually indicates an error either
903 in the symbol information or in gdb's handling of symbols. */
905 UNDEF_DOMAIN,
907 /* VAR_DOMAIN is the usual domain. In C, this contains variables,
908 function names, typedef names and enum type values. */
910 VAR_DOMAIN,
912 /* STRUCT_DOMAIN is used in C to hold struct, union and enum type names.
913 Thus, if `struct foo' is used in a C program, it produces a symbol named
914 `foo' in the STRUCT_DOMAIN. */
916 STRUCT_DOMAIN,
918 /* MODULE_DOMAIN is used in Fortran to hold module type names. */
920 MODULE_DOMAIN,
922 /* LABEL_DOMAIN may be used for names of labels (for gotos). */
924 LABEL_DOMAIN,
926 /* Fortran common blocks. Their naming must be separate from VAR_DOMAIN.
927 They also always use LOC_COMMON_BLOCK. */
928 COMMON_BLOCK_DOMAIN,
930 /* This must remain last. */
931 NR_DOMAINS
934 /* The number of bits in a symbol used to represent the domain. */
936 #define SYMBOL_DOMAIN_BITS 3
937 gdb_static_assert (NR_DOMAINS <= (1 << SYMBOL_DOMAIN_BITS));
939 extern const char *domain_name (domain_enum);
941 /* Searching domains, used when searching for symbols. Element numbers are
942 hardcoded in GDB, check all enum uses before changing it. */
944 enum search_domain
946 /* Everything in VAR_DOMAIN minus FUNCTIONS_DOMAIN and
947 TYPES_DOMAIN. */
948 VARIABLES_DOMAIN = 0,
950 /* All functions -- for some reason not methods, though. */
951 FUNCTIONS_DOMAIN = 1,
953 /* All defined types */
954 TYPES_DOMAIN = 2,
956 /* All modules. */
957 MODULES_DOMAIN = 3,
959 /* Any type. */
960 ALL_DOMAIN = 4
963 extern const char *search_domain_name (enum search_domain);
965 /* An address-class says where to find the value of a symbol. */
967 enum address_class
969 /* Not used; catches errors. */
971 LOC_UNDEF,
973 /* Value is constant int SYMBOL_VALUE, host byteorder. */
975 LOC_CONST,
977 /* Value is at fixed address SYMBOL_VALUE_ADDRESS. */
979 LOC_STATIC,
981 /* Value is in register. SYMBOL_VALUE is the register number
982 in the original debug format. SYMBOL_REGISTER_OPS holds a
983 function that can be called to transform this into the
984 actual register number this represents in a specific target
985 architecture (gdbarch).
987 For some symbol formats (stabs, for some compilers at least),
988 the compiler generates two symbols, an argument and a register.
989 In some cases we combine them to a single LOC_REGISTER in symbol
990 reading, but currently not for all cases (e.g. it's passed on the
991 stack and then loaded into a register). */
993 LOC_REGISTER,
995 /* It's an argument; the value is at SYMBOL_VALUE offset in arglist. */
997 LOC_ARG,
999 /* Value address is at SYMBOL_VALUE offset in arglist. */
1001 LOC_REF_ARG,
1003 /* Value is in specified register. Just like LOC_REGISTER except the
1004 register holds the address of the argument instead of the argument
1005 itself. This is currently used for the passing of structs and unions
1006 on sparc and hppa. It is also used for call by reference where the
1007 address is in a register, at least by mipsread.c. */
1009 LOC_REGPARM_ADDR,
1011 /* Value is a local variable at SYMBOL_VALUE offset in stack frame. */
1013 LOC_LOCAL,
1015 /* Value not used; definition in SYMBOL_TYPE. Symbols in the domain
1016 STRUCT_DOMAIN all have this class. */
1018 LOC_TYPEDEF,
1020 /* Value is address SYMBOL_VALUE_ADDRESS in the code. */
1022 LOC_LABEL,
1024 /* In a symbol table, value is SYMBOL_BLOCK_VALUE of a `struct block'.
1025 In a partial symbol table, SYMBOL_VALUE_ADDRESS is the start address
1026 of the block. Function names have this class. */
1028 LOC_BLOCK,
1030 /* Value is a constant byte-sequence pointed to by SYMBOL_VALUE_BYTES, in
1031 target byte order. */
1033 LOC_CONST_BYTES,
1035 /* Value is at fixed address, but the address of the variable has
1036 to be determined from the minimal symbol table whenever the
1037 variable is referenced.
1038 This happens if debugging information for a global symbol is
1039 emitted and the corresponding minimal symbol is defined
1040 in another object file or runtime common storage.
1041 The linker might even remove the minimal symbol if the global
1042 symbol is never referenced, in which case the symbol remains
1043 unresolved.
1045 GDB would normally find the symbol in the minimal symbol table if it will
1046 not find it in the full symbol table. But a reference to an external
1047 symbol in a local block shadowing other definition requires full symbol
1048 without possibly having its address available for LOC_STATIC. Testcase
1049 is provided as `gdb.dwarf2/dw2-unresolved.exp'.
1051 This is also used for thread local storage (TLS) variables. In
1052 this case, the address of the TLS variable must be determined
1053 when the variable is referenced, from the msymbol's address,
1054 which is the offset of the TLS variable in the thread local
1055 storage of the shared library/object. */
1057 LOC_UNRESOLVED,
1059 /* The variable does not actually exist in the program.
1060 The value is ignored. */
1062 LOC_OPTIMIZED_OUT,
1064 /* The variable's address is computed by a set of location
1065 functions (see "struct symbol_computed_ops" below). */
1066 LOC_COMPUTED,
1068 /* The variable uses general_symbol_info->value->common_block field.
1069 It also always uses COMMON_BLOCK_DOMAIN. */
1070 LOC_COMMON_BLOCK,
1072 /* Not used, just notes the boundary of the enum. */
1073 LOC_FINAL_VALUE
1076 /* The number of bits needed for values in enum address_class, with some
1077 padding for reasonable growth, and room for run-time registered address
1078 classes. See symtab.c:MAX_SYMBOL_IMPLS.
1079 This is a #define so that we can have a assertion elsewhere to
1080 verify that we have reserved enough space for synthetic address
1081 classes. */
1082 #define SYMBOL_ACLASS_BITS 5
1083 gdb_static_assert (LOC_FINAL_VALUE <= (1 << SYMBOL_ACLASS_BITS));
1085 /* The methods needed to implement LOC_COMPUTED. These methods can
1086 use the symbol's .aux_value for additional per-symbol information.
1088 At present this is only used to implement location expressions. */
1090 struct symbol_computed_ops
1093 /* Return the value of the variable SYMBOL, relative to the stack
1094 frame FRAME. If the variable has been optimized out, return
1095 zero.
1097 Iff `read_needs_frame (SYMBOL)' is not SYMBOL_NEEDS_FRAME, then
1098 FRAME may be zero. */
1100 struct value *(*read_variable) (struct symbol * symbol,
1101 frame_info_ptr frame);
1103 /* Read variable SYMBOL like read_variable at (callee) FRAME's function
1104 entry. SYMBOL should be a function parameter, otherwise
1105 NO_ENTRY_VALUE_ERROR will be thrown. */
1106 struct value *(*read_variable_at_entry) (struct symbol *symbol,
1107 frame_info_ptr frame);
1109 /* Find the "symbol_needs_kind" value for the given symbol. This
1110 value determines whether reading the symbol needs memory (e.g., a
1111 global variable), just registers (a thread-local), or a frame (a
1112 local variable). */
1113 enum symbol_needs_kind (*get_symbol_read_needs) (struct symbol * symbol);
1115 /* Write to STREAM a natural-language description of the location of
1116 SYMBOL, in the context of ADDR. */
1117 void (*describe_location) (struct symbol * symbol, CORE_ADDR addr,
1118 struct ui_file * stream);
1120 /* Non-zero if this symbol's address computation is dependent on PC. */
1121 unsigned char location_has_loclist;
1123 /* Tracepoint support. Append bytecodes to the tracepoint agent
1124 expression AX that push the address of the object SYMBOL. Set
1125 VALUE appropriately. Note --- for objects in registers, this
1126 needn't emit any code; as long as it sets VALUE properly, then
1127 the caller will generate the right code in the process of
1128 treating this as an lvalue or rvalue. */
1130 void (*tracepoint_var_ref) (struct symbol *symbol, struct agent_expr *ax,
1131 struct axs_value *value);
1133 /* Generate C code to compute the location of SYMBOL. The C code is
1134 emitted to STREAM. GDBARCH is the current architecture and PC is
1135 the PC at which SYMBOL's location should be evaluated.
1136 REGISTERS_USED is a vector indexed by register number; the
1137 generator function should set an element in this vector if the
1138 corresponding register is needed by the location computation.
1139 The generated C code must assign the location to a local
1140 variable; this variable's name is RESULT_NAME. */
1142 void (*generate_c_location) (struct symbol *symbol, string_file *stream,
1143 struct gdbarch *gdbarch,
1144 std::vector<bool> &registers_used,
1145 CORE_ADDR pc, const char *result_name);
1149 /* The methods needed to implement LOC_BLOCK for inferior functions.
1150 These methods can use the symbol's .aux_value for additional
1151 per-symbol information. */
1153 struct symbol_block_ops
1155 /* Fill in *START and *LENGTH with DWARF block data of function
1156 FRAMEFUNC valid for inferior context address PC. Set *LENGTH to
1157 zero if such location is not valid for PC; *START is left
1158 uninitialized in such case. */
1159 void (*find_frame_base_location) (struct symbol *framefunc, CORE_ADDR pc,
1160 const gdb_byte **start, size_t *length);
1162 /* Return the frame base address. FRAME is the frame for which we want to
1163 compute the base address while FRAMEFUNC is the symbol for the
1164 corresponding function. Return 0 on failure (FRAMEFUNC may not hold the
1165 information we need).
1167 This method is designed to work with static links (nested functions
1168 handling). Static links are function properties whose evaluation returns
1169 the frame base address for the enclosing frame. However, there are
1170 multiple definitions for "frame base": the content of the frame base
1171 register, the CFA as defined by DWARF unwinding information, ...
1173 So this specific method is supposed to compute the frame base address such
1174 as for nested functions, the static link computes the same address. For
1175 instance, considering DWARF debugging information, the static link is
1176 computed with DW_AT_static_link and this method must be used to compute
1177 the corresponding DW_AT_frame_base attribute. */
1178 CORE_ADDR (*get_frame_base) (struct symbol *framefunc,
1179 frame_info_ptr frame);
1181 /* Return the block for this function. So far, this is used to
1182 implement function aliases. So, if this is set, then it's not
1183 necessary to set the other functions in this structure; and vice
1184 versa. */
1185 const block *(*get_block_value) (const struct symbol *sym);
1188 /* Functions used with LOC_REGISTER and LOC_REGPARM_ADDR. */
1190 struct symbol_register_ops
1192 int (*register_number) (struct symbol *symbol, struct gdbarch *gdbarch);
1195 /* Objects of this type are used to find the address class and the
1196 various computed ops vectors of a symbol. */
1198 struct symbol_impl
1200 enum address_class aclass;
1202 /* Used with LOC_COMPUTED. */
1203 const struct symbol_computed_ops *ops_computed;
1205 /* Used with LOC_BLOCK. */
1206 const struct symbol_block_ops *ops_block;
1208 /* Used with LOC_REGISTER and LOC_REGPARM_ADDR. */
1209 const struct symbol_register_ops *ops_register;
1212 /* struct symbol has some subclasses. This enum is used to
1213 differentiate between them. */
1215 enum symbol_subclass_kind
1217 /* Plain struct symbol. */
1218 SYMBOL_NONE,
1220 /* struct template_symbol. */
1221 SYMBOL_TEMPLATE,
1223 /* struct rust_vtable_symbol. */
1224 SYMBOL_RUST_VTABLE
1227 extern gdb::array_view<const struct symbol_impl> symbol_impls;
1229 bool symbol_matches_domain (enum language symbol_language,
1230 domain_enum symbol_domain,
1231 domain_enum domain);
1233 /* This structure is space critical. See space comments at the top. */
1235 struct symbol : public general_symbol_info, public allocate_on_obstack
1237 symbol ()
1238 /* Class-initialization of bitfields is only allowed in C++20. */
1239 : m_domain (UNDEF_DOMAIN),
1240 m_aclass_index (0),
1241 m_is_objfile_owned (1),
1242 m_is_argument (0),
1243 m_is_inlined (0),
1244 maybe_copied (0),
1245 subclass (SYMBOL_NONE),
1246 m_artificial (false)
1248 /* We can't use an initializer list for members of a base class, and
1249 general_symbol_info needs to stay a POD type. */
1250 m_name = nullptr;
1251 m_value.ivalue = 0;
1252 language_specific.obstack = nullptr;
1253 m_language = language_unknown;
1254 ada_mangled = 0;
1255 m_section = -1;
1256 /* GCC 4.8.5 (on CentOS 7) does not correctly compile class-
1257 initialization of unions, so we initialize it manually here. */
1258 owner.symtab = nullptr;
1261 symbol (const symbol &) = default;
1262 symbol &operator= (const symbol &) = default;
1264 void set_aclass_index (unsigned int aclass_index)
1266 m_aclass_index = aclass_index;
1269 const symbol_impl &impl () const
1271 return symbol_impls[this->m_aclass_index];
1274 address_class aclass () const
1276 return this->impl ().aclass;
1279 /* Call symbol_matches_domain on this symbol, using the symbol's
1280 domain. */
1281 bool matches (domain_enum d) const
1283 return symbol_matches_domain (language (), domain (), d);
1286 domain_enum domain () const
1288 return m_domain;
1291 void set_domain (domain_enum domain)
1293 m_domain = domain;
1296 bool is_objfile_owned () const
1298 return m_is_objfile_owned;
1301 void set_is_objfile_owned (bool is_objfile_owned)
1303 m_is_objfile_owned = is_objfile_owned;
1306 bool is_argument () const
1308 return m_is_argument;
1311 void set_is_argument (bool is_argument)
1313 m_is_argument = is_argument;
1316 bool is_inlined () const
1318 return m_is_inlined;
1321 void set_is_inlined (bool is_inlined)
1323 m_is_inlined = is_inlined;
1326 bool is_cplus_template_function () const
1328 return this->subclass == SYMBOL_TEMPLATE;
1331 struct type *type () const
1333 return m_type;
1336 void set_type (struct type *type)
1338 m_type = type;
1341 unsigned int line () const
1343 return m_line;
1346 void set_line (unsigned int line)
1348 m_line = line;
1351 LONGEST value_longest () const
1353 return m_value.ivalue;
1356 void set_value_longest (LONGEST value)
1358 m_value.ivalue = value;
1361 CORE_ADDR value_address () const
1363 if (this->maybe_copied)
1364 return get_symbol_address (this);
1365 else
1366 return m_value.address;
1369 void set_value_address (CORE_ADDR address)
1371 m_value.address = address;
1374 const gdb_byte *value_bytes () const
1376 return m_value.bytes;
1379 void set_value_bytes (const gdb_byte *bytes)
1381 m_value.bytes = bytes;
1384 const common_block *value_common_block () const
1386 return m_value.common_block;
1389 void set_value_common_block (const common_block *common_block)
1391 m_value.common_block = common_block;
1394 const block *value_block () const;
1396 void set_value_block (const block *block)
1398 m_value.block = block;
1401 symbol *value_chain () const
1403 return m_value.chain;
1406 void set_value_chain (symbol *sym)
1408 m_value.chain = sym;
1411 /* Return true if this symbol was marked as artificial. */
1412 bool is_artificial () const
1414 return m_artificial;
1417 /* Set the 'artificial' flag on this symbol. */
1418 void set_is_artificial (bool artificial)
1420 m_artificial = artificial;
1423 /* Return the OBJFILE of this symbol. It is an error to call this
1424 if is_objfile_owned is false, which only happens for
1425 architecture-provided types. */
1427 struct objfile *objfile () const;
1429 /* Return the ARCH of this symbol. */
1431 struct gdbarch *arch () const;
1433 /* Return the symtab of this symbol. It is an error to call this if
1434 is_objfile_owned is false, which only happens for
1435 architecture-provided types. */
1437 struct symtab *symtab () const;
1439 /* Set the symtab of this symbol to SYMTAB. It is an error to call
1440 this if is_objfile_owned is false, which only happens for
1441 architecture-provided types. */
1443 void set_symtab (struct symtab *symtab);
1445 /* Data type of value */
1447 struct type *m_type = nullptr;
1449 /* The owner of this symbol.
1450 Which one to use is defined by symbol.is_objfile_owned. */
1452 union
1454 /* The symbol table containing this symbol. This is the file associated
1455 with LINE. It can be NULL during symbols read-in but it is never NULL
1456 during normal operation. */
1457 struct symtab *symtab;
1459 /* For types defined by the architecture. */
1460 struct gdbarch *arch;
1461 } owner;
1463 /* Domain code. */
1465 ENUM_BITFIELD(domain_enum) m_domain : SYMBOL_DOMAIN_BITS;
1467 /* Address class. This holds an index into the 'symbol_impls'
1468 table. The actual enum address_class value is stored there,
1469 alongside any per-class ops vectors. */
1471 unsigned int m_aclass_index : SYMBOL_ACLASS_BITS;
1473 /* If non-zero then symbol is objfile-owned, use owner.symtab.
1474 Otherwise symbol is arch-owned, use owner.arch. */
1476 unsigned int m_is_objfile_owned : 1;
1478 /* Whether this is an argument. */
1480 unsigned m_is_argument : 1;
1482 /* Whether this is an inlined function (class LOC_BLOCK only). */
1483 unsigned m_is_inlined : 1;
1485 /* For LOC_STATIC only, if this is set, then the symbol might be
1486 subject to copy relocation. In this case, a minimal symbol
1487 matching the symbol's linkage name is first looked for in the
1488 main objfile. If found, then that address is used; otherwise the
1489 address in this symbol is used. */
1491 unsigned maybe_copied : 1;
1493 /* The concrete type of this symbol. */
1495 ENUM_BITFIELD (symbol_subclass_kind) subclass : 2;
1497 /* Whether this symbol is artificial. */
1499 bool m_artificial : 1;
1501 /* Line number of this symbol's definition, except for inlined
1502 functions. For an inlined function (class LOC_BLOCK and
1503 SYMBOL_INLINED set) this is the line number of the function's call
1504 site. Inlined function symbols are not definitions, and they are
1505 never found by symbol table lookup.
1506 If this symbol is arch-owned, LINE shall be zero. */
1508 unsigned int m_line = 0;
1510 /* An arbitrary data pointer, allowing symbol readers to record
1511 additional information on a per-symbol basis. Note that this data
1512 must be allocated using the same obstack as the symbol itself. */
1513 /* So far it is only used by:
1514 LOC_COMPUTED: to find the location information
1515 LOC_BLOCK (DWARF2 function): information used internally by the
1516 DWARF 2 code --- specifically, the location expression for the frame
1517 base for this function. */
1518 /* FIXME drow/2003-02-21: For the LOC_BLOCK case, it might be better
1519 to add a magic symbol to the block containing this information,
1520 or to have a generic debug info annotation slot for symbols. */
1522 void *aux_value = nullptr;
1524 struct symbol *hash_next = nullptr;
1527 /* Several lookup functions return both a symbol and the block in which the
1528 symbol is found. This structure is used in these cases. */
1530 struct block_symbol
1532 /* The symbol that was found, or NULL if no symbol was found. */
1533 struct symbol *symbol;
1535 /* If SYMBOL is not NULL, then this is the block in which the symbol is
1536 defined. */
1537 const struct block *block;
1540 /* Note: There is no accessor macro for symbol.owner because it is
1541 "private". */
1543 #define SYMBOL_COMPUTED_OPS(symbol) ((symbol)->impl ().ops_computed)
1544 #define SYMBOL_BLOCK_OPS(symbol) ((symbol)->impl ().ops_block)
1545 #define SYMBOL_REGISTER_OPS(symbol) ((symbol)->impl ().ops_register)
1546 #define SYMBOL_LOCATION_BATON(symbol) (symbol)->aux_value
1548 inline const block *
1549 symbol::value_block () const
1551 if (SYMBOL_BLOCK_OPS (this) != nullptr
1552 && SYMBOL_BLOCK_OPS (this)->get_block_value != nullptr)
1553 return SYMBOL_BLOCK_OPS (this)->get_block_value (this);
1554 return m_value.block;
1557 extern int register_symbol_computed_impl (enum address_class,
1558 const struct symbol_computed_ops *);
1560 extern int register_symbol_block_impl (enum address_class aclass,
1561 const struct symbol_block_ops *ops);
1563 extern int register_symbol_register_impl (enum address_class,
1564 const struct symbol_register_ops *);
1566 /* An instance of this type is used to represent a C++ template
1567 function. A symbol is really of this type iff
1568 symbol::is_cplus_template_function is true. */
1570 struct template_symbol : public symbol
1572 /* The number of template arguments. */
1573 int n_template_arguments = 0;
1575 /* The template arguments. This is an array with
1576 N_TEMPLATE_ARGUMENTS elements. */
1577 struct symbol **template_arguments = nullptr;
1580 /* A symbol that represents a Rust virtual table object. */
1582 struct rust_vtable_symbol : public symbol
1584 /* The concrete type for which this vtable was created; that is, in
1585 "impl Trait for Type", this is "Type". */
1586 struct type *concrete_type = nullptr;
1590 /* Each item represents a line-->pc (or the reverse) mapping. This is
1591 somewhat more wasteful of space than one might wish, but since only
1592 the files which are actually debugged are read in to core, we don't
1593 waste much space. */
1595 struct linetable_entry
1597 /* Set the (unrelocated) PC for this entry. */
1598 void set_unrelocated_pc (unrelocated_addr pc)
1599 { m_pc = pc; }
1601 /* Return the unrelocated PC for this entry. */
1602 unrelocated_addr unrelocated_pc () const
1603 { return m_pc; }
1605 /* Return the relocated PC for this entry. */
1606 CORE_ADDR pc (const struct objfile *objfile) const;
1608 bool operator< (const linetable_entry &other) const
1610 if (m_pc == other.m_pc
1611 && (line != 0) != (other.line != 0))
1612 return line == 0;
1613 return m_pc < other.m_pc;
1616 /* Two entries are equal if they have the same line and PC. The
1617 other members are ignored. */
1618 bool operator== (const linetable_entry &other) const
1619 { return line == other.line && m_pc == other.m_pc; }
1621 /* The line number for this entry. */
1622 int line;
1624 /* True if this PC is a good location to place a breakpoint for LINE. */
1625 bool is_stmt : 1;
1627 /* True if this location is a good location to place a breakpoint after a
1628 function prologue. */
1629 bool prologue_end : 1;
1631 private:
1633 /* The address for this entry. */
1634 unrelocated_addr m_pc;
1637 /* The order of entries in the linetable is significant. They should
1638 be sorted by increasing values of the pc field. If there is more than
1639 one entry for a given pc, then I'm not sure what should happen (and
1640 I not sure whether we currently handle it the best way).
1642 Example: a C for statement generally looks like this
1644 10 0x100 - for the init/test part of a for stmt.
1645 20 0x200
1646 30 0x300
1647 10 0x400 - for the increment part of a for stmt.
1649 If an entry has a line number of zero, it marks the start of a PC
1650 range for which no line number information is available. It is
1651 acceptable, though wasteful of table space, for such a range to be
1652 zero length. */
1654 struct linetable
1656 int nitems;
1658 /* Actually NITEMS elements. If you don't like this use of the
1659 `struct hack', you can shove it up your ANSI (seriously, if the
1660 committee tells us how to do it, we can probably go along). */
1661 struct linetable_entry item[1];
1664 /* How to relocate the symbols from each section in a symbol file.
1665 The ordering and meaning of the offsets is file-type-dependent;
1666 typically it is indexed by section numbers or symbol types or
1667 something like that. */
1669 typedef std::vector<CORE_ADDR> section_offsets;
1671 /* Each source file or header is represented by a struct symtab.
1672 The name "symtab" is historical, another name for it is "filetab".
1673 These objects are chained through the `next' field. */
1675 struct symtab
1677 struct compunit_symtab *compunit () const
1679 return m_compunit;
1682 void set_compunit (struct compunit_symtab *compunit)
1684 m_compunit = compunit;
1687 const struct linetable *linetable () const
1689 return m_linetable;
1692 void set_linetable (const struct linetable *linetable)
1694 m_linetable = linetable;
1697 enum language language () const
1699 return m_language;
1702 void set_language (enum language language)
1704 m_language = language;
1707 /* Unordered chain of all filetabs in the compunit, with the exception
1708 that the "main" source file is the first entry in the list. */
1710 struct symtab *next;
1712 /* Backlink to containing compunit symtab. */
1714 struct compunit_symtab *m_compunit;
1716 /* Table mapping core addresses to line numbers for this file.
1717 Can be NULL if none. Never shared between different symtabs. */
1719 const struct linetable *m_linetable;
1721 /* Name of this source file, in a form appropriate to print to the user.
1723 This pointer is never nullptr. */
1725 const char *filename;
1727 /* Filename for this source file, used as an identifier to link with
1728 related objects such as associated macro_source_file objects. It must
1729 therefore match the name of any macro_source_file object created for this
1730 source file. The value can be the same as FILENAME if it is known to
1731 follow that rule, or another form of the same file name, this is up to
1732 the specific debug info reader.
1734 This pointer is never nullptr.*/
1735 const char *filename_for_id;
1737 /* Language of this source file. */
1739 enum language m_language;
1741 /* Full name of file as found by searching the source path.
1742 NULL if not yet known. */
1744 char *fullname;
1747 /* A range adapter to allowing iterating over all the file tables in a list. */
1749 using symtab_range = next_range<symtab>;
1751 /* Compunit symtabs contain the actual "symbol table", aka blockvector, as well
1752 as the list of all source files (what gdb has historically associated with
1753 the term "symtab").
1754 Additional information is recorded here that is common to all symtabs in a
1755 compilation unit (DWARF or otherwise).
1757 Example:
1758 For the case of a program built out of these files:
1760 foo.c
1761 foo1.h
1762 foo2.h
1763 bar.c
1764 foo1.h
1765 bar.h
1767 This is recorded as:
1769 objfile -> foo.c(cu) -> bar.c(cu) -> NULL
1772 foo.c bar.c
1775 foo1.h foo1.h
1778 foo2.h bar.h
1781 NULL NULL
1783 where "foo.c(cu)" and "bar.c(cu)" are struct compunit_symtab objects,
1784 and the files foo.c, etc. are struct symtab objects. */
1786 struct compunit_symtab
1788 struct objfile *objfile () const
1790 return m_objfile;
1793 void set_objfile (struct objfile *objfile)
1795 m_objfile = objfile;
1798 symtab_range filetabs () const
1800 return symtab_range (m_filetabs);
1803 void add_filetab (symtab *filetab)
1805 if (m_filetabs == nullptr)
1807 m_filetabs = filetab;
1808 m_last_filetab = filetab;
1810 else
1812 m_last_filetab->next = filetab;
1813 m_last_filetab = filetab;
1817 const char *debugformat () const
1819 return m_debugformat;
1822 void set_debugformat (const char *debugformat)
1824 m_debugformat = debugformat;
1827 const char *producer () const
1829 return m_producer;
1832 void set_producer (const char *producer)
1834 m_producer = producer;
1837 const char *dirname () const
1839 return m_dirname;
1842 void set_dirname (const char *dirname)
1844 m_dirname = dirname;
1847 struct blockvector *blockvector ()
1849 return m_blockvector;
1852 const struct blockvector *blockvector () const
1854 return m_blockvector;
1857 void set_blockvector (struct blockvector *blockvector)
1859 m_blockvector = blockvector;
1862 bool locations_valid () const
1864 return m_locations_valid;
1867 void set_locations_valid (bool locations_valid)
1869 m_locations_valid = locations_valid;
1872 bool epilogue_unwind_valid () const
1874 return m_epilogue_unwind_valid;
1877 void set_epilogue_unwind_valid (bool epilogue_unwind_valid)
1879 m_epilogue_unwind_valid = epilogue_unwind_valid;
1882 struct macro_table *macro_table () const
1884 return m_macro_table;
1887 void set_macro_table (struct macro_table *macro_table)
1889 m_macro_table = macro_table;
1892 /* Make PRIMARY_FILETAB the primary filetab of this compunit symtab.
1894 PRIMARY_FILETAB must already be a filetab of this compunit symtab. */
1896 void set_primary_filetab (symtab *primary_filetab);
1898 /* Return the primary filetab of the compunit. */
1899 symtab *primary_filetab () const;
1901 /* Set m_call_site_htab. */
1902 void set_call_site_htab (htab_t call_site_htab);
1904 /* Find call_site info for PC. */
1905 call_site *find_call_site (CORE_ADDR pc) const;
1907 /* Return the language of this compunit_symtab. */
1908 enum language language () const;
1910 /* Unordered chain of all compunit symtabs of this objfile. */
1911 struct compunit_symtab *next;
1913 /* Object file from which this symtab information was read. */
1914 struct objfile *m_objfile;
1916 /* Name of the symtab.
1917 This is *not* intended to be a usable filename, and is
1918 for debugging purposes only. */
1919 const char *name;
1921 /* Unordered list of file symtabs, except that by convention the "main"
1922 source file (e.g., .c, .cc) is guaranteed to be first.
1923 Each symtab is a file, either the "main" source file (e.g., .c, .cc)
1924 or header (e.g., .h). */
1925 symtab *m_filetabs;
1927 /* Last entry in FILETABS list.
1928 Subfiles are added to the end of the list so they accumulate in order,
1929 with the main source subfile living at the front.
1930 The main reason is so that the main source file symtab is at the head
1931 of the list, and the rest appear in order for debugging convenience. */
1932 symtab *m_last_filetab;
1934 /* Non-NULL string that identifies the format of the debugging information,
1935 such as "stabs", "dwarf 1", "dwarf 2", "coff", etc. This is mostly useful
1936 for automated testing of gdb but may also be information that is
1937 useful to the user. */
1938 const char *m_debugformat;
1940 /* String of producer version information, or NULL if we don't know. */
1941 const char *m_producer;
1943 /* Directory in which it was compiled, or NULL if we don't know. */
1944 const char *m_dirname;
1946 /* List of all symbol scope blocks for this symtab. It is shared among
1947 all symtabs in a given compilation unit. */
1948 struct blockvector *m_blockvector;
1950 /* Symtab has been compiled with both optimizations and debug info so that
1951 GDB may stop skipping prologues as variables locations are valid already
1952 at function entry points. */
1953 unsigned int m_locations_valid : 1;
1955 /* DWARF unwinder for this CU is valid even for epilogues (PC at the return
1956 instruction). This is supported by GCC since 4.5.0. */
1957 unsigned int m_epilogue_unwind_valid : 1;
1959 /* struct call_site entries for this compilation unit or NULL. */
1960 htab_t m_call_site_htab;
1962 /* The macro table for this symtab. Like the blockvector, this
1963 is shared between different symtabs in a given compilation unit.
1964 It's debatable whether it *should* be shared among all the symtabs in
1965 the given compilation unit, but it currently is. */
1966 struct macro_table *m_macro_table;
1968 /* If non-NULL, then this points to a NULL-terminated vector of
1969 included compunits. When searching the static or global
1970 block of this compunit, the corresponding block of all
1971 included compunits will also be searched. Note that this
1972 list must be flattened -- the symbol reader is responsible for
1973 ensuring that this vector contains the transitive closure of all
1974 included compunits. */
1975 struct compunit_symtab **includes;
1977 /* If this is an included compunit, this points to one includer
1978 of the table. This user is considered the canonical compunit
1979 containing this one. An included compunit may itself be
1980 included by another. */
1981 struct compunit_symtab *user;
1984 using compunit_symtab_range = next_range<compunit_symtab>;
1986 /* Return true if this symtab is the "main" symtab of its compunit_symtab. */
1988 static inline bool
1989 is_main_symtab_of_compunit_symtab (struct symtab *symtab)
1991 return symtab == symtab->compunit ()->primary_filetab ();
1994 /* Return true if epilogue unwind info of CUST is valid. */
1996 static inline bool
1997 compunit_epilogue_unwind_valid (struct compunit_symtab *cust)
1999 /* In absence of producer information, assume epilogue unwind info is
2000 valid. */
2001 if (cust == nullptr)
2002 return true;
2004 return cust->epilogue_unwind_valid ();
2008 /* The virtual function table is now an array of structures which have the
2009 form { int16 offset, delta; void *pfn; }.
2011 In normal virtual function tables, OFFSET is unused.
2012 DELTA is the amount which is added to the apparent object's base
2013 address in order to point to the actual object to which the
2014 virtual function should be applied.
2015 PFN is a pointer to the virtual function.
2017 Note that this macro is g++ specific (FIXME). */
2019 #define VTBL_FNADDR_OFFSET 2
2021 /* External variables and functions for the objects described above. */
2023 /* True if we are nested inside psymtab_to_symtab. */
2025 extern int currently_reading_symtab;
2027 /* symtab.c lookup functions */
2029 extern const char multiple_symbols_ask[];
2030 extern const char multiple_symbols_all[];
2031 extern const char multiple_symbols_cancel[];
2033 const char *multiple_symbols_select_mode (void);
2035 /* lookup a symbol table by source file name. */
2037 extern struct symtab *lookup_symtab (const char *);
2039 /* An object of this type is passed as the 'is_a_field_of_this'
2040 argument to lookup_symbol and lookup_symbol_in_language. */
2042 struct field_of_this_result
2044 /* The type in which the field was found. If this is NULL then the
2045 symbol was not found in 'this'. If non-NULL, then one of the
2046 other fields will be non-NULL as well. */
2048 struct type *type;
2050 /* If the symbol was found as an ordinary field of 'this', then this
2051 is non-NULL and points to the particular field. */
2053 struct field *field;
2055 /* If the symbol was found as a function field of 'this', then this
2056 is non-NULL and points to the particular field. */
2058 struct fn_fieldlist *fn_field;
2061 /* Find the definition for a specified symbol name NAME
2062 in domain DOMAIN in language LANGUAGE, visible from lexical block BLOCK
2063 if non-NULL or from global/static blocks if BLOCK is NULL.
2064 Returns the struct symbol pointer, or NULL if no symbol is found.
2065 C++: if IS_A_FIELD_OF_THIS is non-NULL on entry, check to see if
2066 NAME is a field of the current implied argument `this'. If so fill in the
2067 fields of IS_A_FIELD_OF_THIS, otherwise the fields are set to NULL.
2068 The symbol's section is fixed up if necessary. */
2070 extern struct block_symbol
2071 lookup_symbol_in_language (const char *,
2072 const struct block *,
2073 const domain_enum,
2074 enum language,
2075 struct field_of_this_result *);
2077 /* Same as lookup_symbol_in_language, but using the current language. */
2079 extern struct block_symbol lookup_symbol (const char *,
2080 const struct block *,
2081 const domain_enum,
2082 struct field_of_this_result *);
2084 /* Find the definition for a specified symbol search name in domain
2085 DOMAIN, visible from lexical block BLOCK if non-NULL or from
2086 global/static blocks if BLOCK is NULL. The passed-in search name
2087 should not come from the user; instead it should already be a
2088 search name as retrieved from a search_name () call. See definition of
2089 symbol_name_match_type::SEARCH_NAME. Returns the struct symbol
2090 pointer, or NULL if no symbol is found. The symbol's section is
2091 fixed up if necessary. */
2093 extern struct block_symbol lookup_symbol_search_name (const char *search_name,
2094 const struct block *block,
2095 domain_enum domain);
2097 /* Some helper functions for languages that need to write their own
2098 lookup_symbol_nonlocal functions. */
2100 /* Lookup a symbol in the static block associated to BLOCK, if there
2101 is one; do nothing if BLOCK is NULL or a global block.
2102 Upon success fixes up the symbol's section if necessary. */
2104 extern struct block_symbol
2105 lookup_symbol_in_static_block (const char *name,
2106 const struct block *block,
2107 const domain_enum domain);
2109 /* Search all static file-level symbols for NAME from DOMAIN.
2110 Upon success fixes up the symbol's section if necessary. */
2112 extern struct block_symbol lookup_static_symbol (const char *name,
2113 const domain_enum domain);
2115 /* Lookup a symbol in all files' global blocks.
2117 If BLOCK is non-NULL then it is used for two things:
2118 1) If a target-specific lookup routine for libraries exists, then use the
2119 routine for the objfile of BLOCK, and
2120 2) The objfile of BLOCK is used to assist in determining the search order
2121 if the target requires it.
2122 See gdbarch_iterate_over_objfiles_in_search_order.
2124 Upon success fixes up the symbol's section if necessary. */
2126 extern struct block_symbol
2127 lookup_global_symbol (const char *name,
2128 const struct block *block,
2129 const domain_enum domain);
2131 /* Lookup a symbol in block BLOCK.
2132 Upon success fixes up the symbol's section if necessary. */
2134 extern struct symbol *
2135 lookup_symbol_in_block (const char *name,
2136 symbol_name_match_type match_type,
2137 const struct block *block,
2138 const domain_enum domain);
2140 /* Look up the `this' symbol for LANG in BLOCK. Return the symbol if
2141 found, or NULL if not found. */
2143 extern struct block_symbol
2144 lookup_language_this (const struct language_defn *lang,
2145 const struct block *block);
2147 /* Lookup a [struct, union, enum] by name, within a specified block. */
2149 extern struct type *lookup_struct (const char *, const struct block *);
2151 extern struct type *lookup_union (const char *, const struct block *);
2153 extern struct type *lookup_enum (const char *, const struct block *);
2155 /* from blockframe.c: */
2157 /* lookup the function symbol corresponding to the address. The
2158 return value will not be an inlined function; the containing
2159 function will be returned instead. */
2161 extern struct symbol *find_pc_function (CORE_ADDR);
2163 /* lookup the function corresponding to the address and section. The
2164 return value will not be an inlined function; the containing
2165 function will be returned instead. */
2167 extern struct symbol *find_pc_sect_function (CORE_ADDR, struct obj_section *);
2169 /* lookup the function symbol corresponding to the address and
2170 section. The return value will be the closest enclosing function,
2171 which might be an inline function. */
2173 extern struct symbol *find_pc_sect_containing_function
2174 (CORE_ADDR pc, struct obj_section *section);
2176 /* Find the symbol at the given address. Returns NULL if no symbol
2177 found. Only exact matches for ADDRESS are considered. */
2179 extern struct symbol *find_symbol_at_address (CORE_ADDR);
2181 /* Finds the "function" (text symbol) that is smaller than PC but
2182 greatest of all of the potential text symbols in SECTION. Sets
2183 *NAME and/or *ADDRESS conditionally if that pointer is non-null.
2184 If ENDADDR is non-null, then set *ENDADDR to be the end of the
2185 function (exclusive). If the optional parameter BLOCK is non-null,
2186 then set *BLOCK to the address of the block corresponding to the
2187 function symbol, if such a symbol could be found during the lookup;
2188 nullptr is used as a return value for *BLOCK if no block is found.
2189 This function either succeeds or fails (not halfway succeeds). If
2190 it succeeds, it sets *NAME, *ADDRESS, and *ENDADDR to real
2191 information and returns true. If it fails, it sets *NAME, *ADDRESS
2192 and *ENDADDR to zero and returns false.
2194 If the function in question occupies non-contiguous ranges,
2195 *ADDRESS and *ENDADDR are (subject to the conditions noted above) set
2196 to the start and end of the range in which PC is found. Thus
2197 *ADDRESS <= PC < *ENDADDR with no intervening gaps (in which ranges
2198 from other functions might be found).
2200 This property allows find_pc_partial_function to be used (as it had
2201 been prior to the introduction of non-contiguous range support) by
2202 various tdep files for finding a start address and limit address
2203 for prologue analysis. This still isn't ideal, however, because we
2204 probably shouldn't be doing prologue analysis (in which
2205 instructions are scanned to determine frame size and stack layout)
2206 for any range that doesn't contain the entry pc. Moreover, a good
2207 argument can be made that prologue analysis ought to be performed
2208 starting from the entry pc even when PC is within some other range.
2209 This might suggest that *ADDRESS and *ENDADDR ought to be set to the
2210 limits of the entry pc range, but that will cause the
2211 *ADDRESS <= PC < *ENDADDR condition to be violated; many of the
2212 callers of find_pc_partial_function expect this condition to hold.
2214 Callers which require the start and/or end addresses for the range
2215 containing the entry pc should instead call
2216 find_function_entry_range_from_pc. */
2218 extern bool find_pc_partial_function (CORE_ADDR pc, const char **name,
2219 CORE_ADDR *address, CORE_ADDR *endaddr,
2220 const struct block **block = nullptr);
2222 /* Like find_pc_partial_function, above, but returns the underlying
2223 general_symbol_info (rather than the name) as an out parameter. */
2225 extern bool find_pc_partial_function_sym
2226 (CORE_ADDR pc, const general_symbol_info **sym,
2227 CORE_ADDR *address, CORE_ADDR *endaddr,
2228 const struct block **block = nullptr);
2230 /* Like find_pc_partial_function, above, but *ADDRESS and *ENDADDR are
2231 set to start and end addresses of the range containing the entry pc.
2233 Note that it is not necessarily the case that (for non-NULL ADDRESS
2234 and ENDADDR arguments) the *ADDRESS <= PC < *ENDADDR condition will
2235 hold.
2237 See comment for find_pc_partial_function, above, for further
2238 explanation. */
2240 extern bool find_function_entry_range_from_pc (CORE_ADDR pc,
2241 const char **name,
2242 CORE_ADDR *address,
2243 CORE_ADDR *endaddr);
2245 /* Return the type of a function with its first instruction exactly at
2246 the PC address. Return NULL otherwise. */
2248 extern struct type *find_function_type (CORE_ADDR pc);
2250 /* See if we can figure out the function's actual type from the type
2251 that the resolver returns. RESOLVER_FUNADDR is the address of the
2252 ifunc resolver. */
2254 extern struct type *find_gnu_ifunc_target_type (CORE_ADDR resolver_funaddr);
2256 /* Find the GNU ifunc minimal symbol that matches SYM. */
2257 extern bound_minimal_symbol find_gnu_ifunc (const symbol *sym);
2259 extern void clear_pc_function_cache (void);
2261 /* lookup full symbol table by address. */
2263 extern struct compunit_symtab *find_pc_compunit_symtab (CORE_ADDR);
2265 /* lookup full symbol table by address and section. */
2267 extern struct compunit_symtab *
2268 find_pc_sect_compunit_symtab (CORE_ADDR, struct obj_section *);
2270 extern bool find_pc_line_pc_range (CORE_ADDR, CORE_ADDR *, CORE_ADDR *);
2272 extern void reread_symbols (int from_tty);
2274 /* Look up a type named NAME in STRUCT_DOMAIN in the current language.
2275 The type returned must not be opaque -- i.e., must have at least one field
2276 defined. */
2278 extern struct type *lookup_transparent_type (const char *);
2280 extern struct type *basic_lookup_transparent_type (const char *);
2282 /* Macro for name of symbol to indicate a file compiled with gcc. */
2283 #ifndef GCC_COMPILED_FLAG_SYMBOL
2284 #define GCC_COMPILED_FLAG_SYMBOL "gcc_compiled."
2285 #endif
2287 /* Macro for name of symbol to indicate a file compiled with gcc2. */
2288 #ifndef GCC2_COMPILED_FLAG_SYMBOL
2289 #define GCC2_COMPILED_FLAG_SYMBOL "gcc2_compiled."
2290 #endif
2292 extern bool in_gnu_ifunc_stub (CORE_ADDR pc);
2294 /* Functions for resolving STT_GNU_IFUNC symbols which are implemented only
2295 for ELF symbol files. */
2297 struct gnu_ifunc_fns
2299 /* See elf_gnu_ifunc_resolve_addr for its real implementation. */
2300 CORE_ADDR (*gnu_ifunc_resolve_addr) (struct gdbarch *gdbarch, CORE_ADDR pc);
2302 /* See elf_gnu_ifunc_resolve_name for its real implementation. */
2303 bool (*gnu_ifunc_resolve_name) (const char *function_name,
2304 CORE_ADDR *function_address_p);
2306 /* See elf_gnu_ifunc_resolver_stop for its real implementation. */
2307 void (*gnu_ifunc_resolver_stop) (code_breakpoint *b);
2309 /* See elf_gnu_ifunc_resolver_return_stop for its real implementation. */
2310 void (*gnu_ifunc_resolver_return_stop) (code_breakpoint *b);
2313 #define gnu_ifunc_resolve_addr gnu_ifunc_fns_p->gnu_ifunc_resolve_addr
2314 #define gnu_ifunc_resolve_name gnu_ifunc_fns_p->gnu_ifunc_resolve_name
2315 #define gnu_ifunc_resolver_stop gnu_ifunc_fns_p->gnu_ifunc_resolver_stop
2316 #define gnu_ifunc_resolver_return_stop \
2317 gnu_ifunc_fns_p->gnu_ifunc_resolver_return_stop
2319 extern const struct gnu_ifunc_fns *gnu_ifunc_fns_p;
2321 extern CORE_ADDR find_solib_trampoline_target (frame_info_ptr, CORE_ADDR);
2323 struct symtab_and_line
2325 /* The program space of this sal. */
2326 struct program_space *pspace = NULL;
2328 struct symtab *symtab = NULL;
2329 struct symbol *symbol = NULL;
2330 struct obj_section *section = NULL;
2331 struct minimal_symbol *msymbol = NULL;
2332 /* Line number. Line numbers start at 1 and proceed through symtab->nlines.
2333 0 is never a valid line number; it is used to indicate that line number
2334 information is not available. */
2335 int line = 0;
2337 CORE_ADDR pc = 0;
2338 CORE_ADDR end = 0;
2339 bool explicit_pc = false;
2340 bool explicit_line = false;
2342 /* If the line number information is valid, then this indicates if this
2343 line table entry had the is-stmt flag set or not. */
2344 bool is_stmt = false;
2346 /* The probe associated with this symtab_and_line. */
2347 probe *prob = NULL;
2348 /* If PROBE is not NULL, then this is the objfile in which the probe
2349 originated. */
2350 struct objfile *objfile = NULL;
2355 /* Given a pc value, return line number it is in. Second arg nonzero means
2356 if pc is on the boundary use the previous statement's line number. */
2358 extern struct symtab_and_line find_pc_line (CORE_ADDR, int);
2360 /* Same function, but specify a section as well as an address. */
2362 extern struct symtab_and_line find_pc_sect_line (CORE_ADDR,
2363 struct obj_section *, int);
2365 /* Wrapper around find_pc_line to just return the symtab. */
2367 extern struct symtab *find_pc_line_symtab (CORE_ADDR);
2369 /* Given a symtab and line number, return the pc there. */
2371 extern bool find_line_pc (struct symtab *, int, CORE_ADDR *);
2373 extern bool find_line_pc_range (struct symtab_and_line, CORE_ADDR *,
2374 CORE_ADDR *);
2376 extern void resolve_sal_pc (struct symtab_and_line *);
2378 /* solib.c */
2380 extern void clear_solib (void);
2382 /* The reason we're calling into a completion match list collector
2383 function. */
2384 enum class complete_symbol_mode
2386 /* Completing an expression. */
2387 EXPRESSION,
2389 /* Completing a linespec. */
2390 LINESPEC,
2393 extern void default_collect_symbol_completion_matches_break_on
2394 (completion_tracker &tracker,
2395 complete_symbol_mode mode,
2396 symbol_name_match_type name_match_type,
2397 const char *text, const char *word, const char *break_on,
2398 enum type_code code);
2399 extern void collect_symbol_completion_matches
2400 (completion_tracker &tracker,
2401 complete_symbol_mode mode,
2402 symbol_name_match_type name_match_type,
2403 const char *, const char *);
2404 extern void collect_symbol_completion_matches_type (completion_tracker &tracker,
2405 const char *, const char *,
2406 enum type_code);
2408 extern void collect_file_symbol_completion_matches
2409 (completion_tracker &tracker,
2410 complete_symbol_mode,
2411 symbol_name_match_type name_match_type,
2412 const char *, const char *, const char *);
2414 extern completion_list
2415 make_source_files_completion_list (const char *, const char *);
2417 /* Return whether SYM is a function/method, as opposed to a data symbol. */
2419 extern bool symbol_is_function_or_method (symbol *sym);
2421 /* Return whether MSYMBOL is a function/method, as opposed to a data
2422 symbol */
2424 extern bool symbol_is_function_or_method (minimal_symbol *msymbol);
2426 /* Return whether SYM should be skipped in completion mode MODE. In
2427 linespec mode, we're only interested in functions/methods. */
2429 template<typename Symbol>
2430 static bool
2431 completion_skip_symbol (complete_symbol_mode mode, Symbol *sym)
2433 return (mode == complete_symbol_mode::LINESPEC
2434 && !symbol_is_function_or_method (sym));
2437 /* symtab.c */
2439 bool matching_obj_sections (struct obj_section *, struct obj_section *);
2441 extern struct symtab *find_line_symtab (struct symtab *, int, int *, bool *);
2443 /* Given a function symbol SYM, find the symtab and line for the start
2444 of the function. If FUNFIRSTLINE is true, we want the first line
2445 of real code inside the function. */
2446 extern symtab_and_line find_function_start_sal (symbol *sym, bool
2447 funfirstline);
2449 /* Same, but start with a function address/section instead of a
2450 symbol. */
2451 extern symtab_and_line find_function_start_sal (CORE_ADDR func_addr,
2452 obj_section *section,
2453 bool funfirstline);
2455 extern void skip_prologue_sal (struct symtab_and_line *);
2457 /* symtab.c */
2459 extern CORE_ADDR skip_prologue_using_sal (struct gdbarch *gdbarch,
2460 CORE_ADDR func_addr);
2462 /* If SYM requires a section index, find it either via minimal symbols
2463 or examining OBJFILE's sections. Note that SYM's current address
2464 must not have any runtime offsets applied. */
2466 extern void fixup_symbol_section (struct symbol *sym,
2467 struct objfile *objfile);
2469 /* If MSYMBOL is an text symbol, look for a function debug symbol with
2470 the same address. Returns NULL if not found. This is necessary in
2471 case a function is an alias to some other function, because debug
2472 information is only emitted for the alias target function's
2473 definition, not for the alias. */
2474 extern symbol *find_function_alias_target (bound_minimal_symbol msymbol);
2476 /* Symbol searching */
2478 /* When using the symbol_searcher struct to search for symbols, a vector of
2479 the following structs is returned. */
2480 struct symbol_search
2482 symbol_search (block_enum block_, struct symbol *symbol_)
2483 : block (block_),
2484 symbol (symbol_)
2486 msymbol.minsym = nullptr;
2487 msymbol.objfile = nullptr;
2490 symbol_search (block_enum block_, struct minimal_symbol *minsym,
2491 struct objfile *objfile)
2492 : block (block_),
2493 symbol (nullptr)
2495 msymbol.minsym = minsym;
2496 msymbol.objfile = objfile;
2499 bool operator< (const symbol_search &other) const
2501 return compare_search_syms (*this, other) < 0;
2504 bool operator== (const symbol_search &other) const
2506 return compare_search_syms (*this, other) == 0;
2509 /* The block in which the match was found. Either STATIC_BLOCK or
2510 GLOBAL_BLOCK. */
2511 block_enum block;
2513 /* Information describing what was found.
2515 If symbol is NOT NULL, then information was found for this match. */
2516 struct symbol *symbol;
2518 /* If msymbol is non-null, then a match was made on something for
2519 which only minimal_symbols exist. */
2520 struct bound_minimal_symbol msymbol;
2522 private:
2524 static int compare_search_syms (const symbol_search &sym_a,
2525 const symbol_search &sym_b);
2528 /* In order to search for global symbols of a particular kind matching
2529 particular regular expressions, create an instance of this structure and
2530 call the SEARCH member function. */
2531 class global_symbol_searcher
2533 public:
2535 /* Constructor. */
2536 global_symbol_searcher (enum search_domain kind,
2537 const char *symbol_name_regexp)
2538 : m_kind (kind),
2539 m_symbol_name_regexp (symbol_name_regexp)
2541 /* The symbol searching is designed to only find one kind of thing. */
2542 gdb_assert (m_kind != ALL_DOMAIN);
2545 /* Set the optional regexp that matches against the symbol type. */
2546 void set_symbol_type_regexp (const char *regexp)
2548 m_symbol_type_regexp = regexp;
2551 /* Set the flag to exclude minsyms from the search results. */
2552 void set_exclude_minsyms (bool exclude_minsyms)
2554 m_exclude_minsyms = exclude_minsyms;
2557 /* Set the maximum number of search results to be returned. */
2558 void set_max_search_results (size_t max_search_results)
2560 m_max_search_results = max_search_results;
2563 /* Search the symbols from all objfiles in the current program space
2564 looking for matches as defined by the current state of this object.
2566 Within each file the results are sorted locally; each symtab's global
2567 and static blocks are separately alphabetized. Duplicate entries are
2568 removed. */
2569 std::vector<symbol_search> search () const;
2571 /* The set of source files to search in for matching symbols. This is
2572 currently public so that it can be populated after this object has
2573 been constructed. */
2574 std::vector<const char *> filenames;
2576 private:
2577 /* The kind of symbols are we searching for.
2578 VARIABLES_DOMAIN - Search all symbols, excluding functions, type
2579 names, and constants (enums).
2580 FUNCTIONS_DOMAIN - Search all functions..
2581 TYPES_DOMAIN - Search all type names.
2582 MODULES_DOMAIN - Search all Fortran modules.
2583 ALL_DOMAIN - Not valid for this function. */
2584 enum search_domain m_kind;
2586 /* Regular expression to match against the symbol name. */
2587 const char *m_symbol_name_regexp = nullptr;
2589 /* Regular expression to match against the symbol type. */
2590 const char *m_symbol_type_regexp = nullptr;
2592 /* When this flag is false then minsyms that match M_SYMBOL_REGEXP will
2593 be included in the results, otherwise they are excluded. */
2594 bool m_exclude_minsyms = false;
2596 /* Maximum number of search results. We currently impose a hard limit
2597 of SIZE_MAX, there is no "unlimited". */
2598 size_t m_max_search_results = SIZE_MAX;
2600 /* Expand symtabs in OBJFILE that match PREG, are of type M_KIND. Return
2601 true if any msymbols were seen that we should later consider adding to
2602 the results list. */
2603 bool expand_symtabs (objfile *objfile,
2604 const gdb::optional<compiled_regex> &preg) const;
2606 /* Add symbols from symtabs in OBJFILE that match PREG, and TREG, and are
2607 of type M_KIND, to the results set RESULTS_SET. Return false if we
2608 stop adding results early due to having already found too many results
2609 (based on M_MAX_SEARCH_RESULTS limit), otherwise return true.
2610 Returning true does not indicate that any results were added, just
2611 that we didn't _not_ add a result due to reaching MAX_SEARCH_RESULTS. */
2612 bool add_matching_symbols (objfile *objfile,
2613 const gdb::optional<compiled_regex> &preg,
2614 const gdb::optional<compiled_regex> &treg,
2615 std::set<symbol_search> *result_set) const;
2617 /* Add msymbols from OBJFILE that match PREG and M_KIND, to the results
2618 vector RESULTS. Return false if we stop adding results early due to
2619 having already found too many results (based on max search results
2620 limit M_MAX_SEARCH_RESULTS), otherwise return true. Returning true
2621 does not indicate that any results were added, just that we didn't
2622 _not_ add a result due to reaching MAX_SEARCH_RESULTS. */
2623 bool add_matching_msymbols (objfile *objfile,
2624 const gdb::optional<compiled_regex> &preg,
2625 std::vector<symbol_search> *results) const;
2627 /* Return true if MSYMBOL is of type KIND. */
2628 static bool is_suitable_msymbol (const enum search_domain kind,
2629 const minimal_symbol *msymbol);
2632 /* When searching for Fortran symbols within modules (functions/variables)
2633 we return a vector of this type. The first item in the pair is the
2634 module symbol, and the second item is the symbol for the function or
2635 variable we found. */
2636 typedef std::pair<symbol_search, symbol_search> module_symbol_search;
2638 /* Searches the symbols to find function and variables symbols (depending
2639 on KIND) within Fortran modules. The MODULE_REGEXP matches against the
2640 name of the module, REGEXP matches against the name of the symbol within
2641 the module, and TYPE_REGEXP matches against the type of the symbol
2642 within the module. */
2643 extern std::vector<module_symbol_search> search_module_symbols
2644 (const char *module_regexp, const char *regexp,
2645 const char *type_regexp, search_domain kind);
2647 /* Convert a global or static symbol SYM (based on BLOCK, which should be
2648 either GLOBAL_BLOCK or STATIC_BLOCK) into a string for use in 'info'
2649 type commands (e.g. 'info variables', 'info functions', etc). KIND is
2650 the type of symbol that was searched for which gave us SYM. */
2652 extern std::string symbol_to_info_string (struct symbol *sym, int block,
2653 enum search_domain kind);
2655 extern bool treg_matches_sym_type_name (const compiled_regex &treg,
2656 const struct symbol *sym);
2658 /* The name of the ``main'' function. */
2659 extern const char *main_name ();
2660 extern enum language main_language (void);
2662 /* Lookup symbol NAME from DOMAIN in MAIN_OBJFILE's global or static blocks,
2663 as specified by BLOCK_INDEX.
2664 This searches MAIN_OBJFILE as well as any associated separate debug info
2665 objfiles of MAIN_OBJFILE.
2666 BLOCK_INDEX can be GLOBAL_BLOCK or STATIC_BLOCK.
2667 Upon success fixes up the symbol's section if necessary. */
2669 extern struct block_symbol
2670 lookup_global_symbol_from_objfile (struct objfile *main_objfile,
2671 enum block_enum block_index,
2672 const char *name,
2673 const domain_enum domain);
2675 /* Return 1 if the supplied producer string matches the ARM RealView
2676 compiler (armcc). */
2677 bool producer_is_realview (const char *producer);
2679 extern unsigned int symtab_create_debug;
2681 /* Print a "symtab-create" debug statement. */
2683 #define symtab_create_debug_printf(fmt, ...) \
2684 debug_prefixed_printf_cond (symtab_create_debug >= 1, "symtab-create", fmt, ##__VA_ARGS__)
2686 /* Print a verbose "symtab-create" debug statement, only if
2687 "set debug symtab-create" is set to 2 or higher. */
2689 #define symtab_create_debug_printf_v(fmt, ...) \
2690 debug_prefixed_printf_cond (symtab_create_debug >= 2, "symtab-create", fmt, ##__VA_ARGS__)
2692 extern unsigned int symbol_lookup_debug;
2694 /* Return true if symbol-lookup debug is turned on at all. */
2696 static inline bool
2697 symbol_lookup_debug_enabled ()
2699 return symbol_lookup_debug > 0;
2702 /* Return true if symbol-lookup debug is turned to verbose mode. */
2704 static inline bool
2705 symbol_lookup_debug_enabled_v ()
2707 return symbol_lookup_debug > 1;
2710 /* Print a "symbol-lookup" debug statement if symbol_lookup_debug is >= 1. */
2712 #define symbol_lookup_debug_printf(fmt, ...) \
2713 debug_prefixed_printf_cond (symbol_lookup_debug_enabled (), \
2714 "symbol-lookup", fmt, ##__VA_ARGS__)
2716 /* Print a "symbol-lookup" debug statement if symbol_lookup_debug is >= 2. */
2718 #define symbol_lookup_debug_printf_v(fmt, ...) \
2719 debug_prefixed_printf_cond (symbol_lookup_debug_enabled_v (), \
2720 "symbol-lookup", fmt, ##__VA_ARGS__)
2722 /* Print "symbol-lookup" enter/exit debug statements. */
2724 #define SYMBOL_LOOKUP_SCOPED_DEBUG_ENTER_EXIT \
2725 scoped_debug_enter_exit (symbol_lookup_debug_enabled, "symbol-lookup")
2727 extern bool basenames_may_differ;
2729 bool compare_filenames_for_search (const char *filename,
2730 const char *search_name);
2732 bool compare_glob_filenames_for_search (const char *filename,
2733 const char *search_name);
2735 bool iterate_over_some_symtabs (const char *name,
2736 const char *real_path,
2737 struct compunit_symtab *first,
2738 struct compunit_symtab *after_last,
2739 gdb::function_view<bool (symtab *)> callback);
2741 void iterate_over_symtabs (const char *name,
2742 gdb::function_view<bool (symtab *)> callback);
2745 std::vector<CORE_ADDR> find_pcs_for_symtab_line
2746 (struct symtab *symtab, int line, const linetable_entry **best_entry);
2748 /* Prototype for callbacks for LA_ITERATE_OVER_SYMBOLS. The callback
2749 is called once per matching symbol SYM. The callback should return
2750 true to indicate that LA_ITERATE_OVER_SYMBOLS should continue
2751 iterating, or false to indicate that the iteration should end. */
2753 typedef bool (symbol_found_callback_ftype) (struct block_symbol *bsym);
2755 /* Iterate over the symbols named NAME, matching DOMAIN, in BLOCK.
2757 For each symbol that matches, CALLBACK is called. The symbol is
2758 passed to the callback.
2760 If CALLBACK returns false, the iteration ends and this function
2761 returns false. Otherwise, the search continues, and the function
2762 eventually returns true. */
2764 bool iterate_over_symbols (const struct block *block,
2765 const lookup_name_info &name,
2766 const domain_enum domain,
2767 gdb::function_view<symbol_found_callback_ftype> callback);
2769 /* Like iterate_over_symbols, but if all calls to CALLBACK return
2770 true, then calls CALLBACK one additional time with a block_symbol
2771 that has a valid block but a NULL symbol. */
2773 bool iterate_over_symbols_terminated
2774 (const struct block *block,
2775 const lookup_name_info &name,
2776 const domain_enum domain,
2777 gdb::function_view<symbol_found_callback_ftype> callback);
2779 /* Storage type used by demangle_for_lookup. demangle_for_lookup
2780 either returns a const char * pointer that points to either of the
2781 fields of this type, or a pointer to the input NAME. This is done
2782 this way to avoid depending on the precise details of the storage
2783 for the string. */
2784 class demangle_result_storage
2786 public:
2788 /* Swap the malloc storage to STR, and return a pointer to the
2789 beginning of the new string. */
2790 const char *set_malloc_ptr (gdb::unique_xmalloc_ptr<char> &&str)
2792 m_malloc = std::move (str);
2793 return m_malloc.get ();
2796 /* Set the malloc storage to now point at PTR. Any previous malloc
2797 storage is released. */
2798 const char *set_malloc_ptr (char *ptr)
2800 m_malloc.reset (ptr);
2801 return ptr;
2804 private:
2806 /* The storage. */
2807 gdb::unique_xmalloc_ptr<char> m_malloc;
2810 const char *
2811 demangle_for_lookup (const char *name, enum language lang,
2812 demangle_result_storage &storage);
2814 /* Test to see if the symbol of language SYMBOL_LANGUAGE specified by
2815 SYMNAME (which is already demangled for C++ symbols) matches
2816 SYM_TEXT in the first SYM_TEXT_LEN characters. If so, add it to
2817 the current completion list and return true. Otherwise, return
2818 false. */
2819 bool completion_list_add_name (completion_tracker &tracker,
2820 language symbol_language,
2821 const char *symname,
2822 const lookup_name_info &lookup_name,
2823 const char *text, const char *word);
2825 /* A simple symbol searching class. */
2827 class symbol_searcher
2829 public:
2830 /* Returns the symbols found for the search. */
2831 const std::vector<block_symbol> &
2832 matching_symbols () const
2834 return m_symbols;
2837 /* Returns the minimal symbols found for the search. */
2838 const std::vector<bound_minimal_symbol> &
2839 matching_msymbols () const
2841 return m_minimal_symbols;
2844 /* Search for all symbols named NAME in LANGUAGE with DOMAIN, restricting
2845 search to FILE_SYMTABS and SEARCH_PSPACE, both of which may be NULL
2846 to search all symtabs and program spaces. */
2847 void find_all_symbols (const std::string &name,
2848 const struct language_defn *language,
2849 enum search_domain search_domain,
2850 std::vector<symtab *> *search_symtabs,
2851 struct program_space *search_pspace);
2853 /* Reset this object to perform another search. */
2854 void reset ()
2856 m_symbols.clear ();
2857 m_minimal_symbols.clear ();
2860 private:
2861 /* Matching debug symbols. */
2862 std::vector<block_symbol> m_symbols;
2864 /* Matching non-debug symbols. */
2865 std::vector<bound_minimal_symbol> m_minimal_symbols;
2868 /* Class used to encapsulate the filename filtering for the "info sources"
2869 command. */
2871 struct info_sources_filter
2873 /* If filename filtering is being used (see M_C_REGEXP) then which part
2874 of the filename is being filtered against? */
2875 enum class match_on
2877 /* Match against the full filename. */
2878 FULLNAME,
2880 /* Match only against the directory part of the full filename. */
2881 DIRNAME,
2883 /* Match only against the basename part of the full filename. */
2884 BASENAME
2887 /* Create a filter of MATCH_TYPE using regular expression REGEXP. If
2888 REGEXP is nullptr then all files will match the filter and MATCH_TYPE
2889 is ignored.
2891 The string pointed too by REGEXP must remain live and unchanged for
2892 this lifetime of this object as the object only retains a copy of the
2893 pointer. */
2894 info_sources_filter (match_on match_type, const char *regexp);
2896 DISABLE_COPY_AND_ASSIGN (info_sources_filter);
2898 /* Does FULLNAME match the filter defined by this object, return true if
2899 it does, otherwise, return false. If there is no filtering defined
2900 then this function will always return true. */
2901 bool matches (const char *fullname) const;
2903 private:
2905 /* The type of filtering in place. */
2906 match_on m_match_type;
2908 /* Points to the original regexp used to create this filter. */
2909 const char *m_regexp;
2911 /* A compiled version of M_REGEXP. This object is only given a value if
2912 M_REGEXP is not nullptr and is not the empty string. */
2913 gdb::optional<compiled_regex> m_c_regexp;
2916 /* Perform the core of the 'info sources' command.
2918 FILTER is used to perform regular expression based filtering on the
2919 source files that will be displayed.
2921 Output is written to UIOUT in CLI or MI style as appropriate. */
2923 extern void info_sources_worker (struct ui_out *uiout,
2924 bool group_by_objfile,
2925 const info_sources_filter &filter);
2927 #endif /* !defined(SYMTAB_H) */