1 /* Symbol table definitions for GDB.
3 Copyright (C) 1986-2018 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)
28 #include "gdb_regex.h"
29 #include "common/enum-flags.h"
30 #include "common/function-view.h"
31 #include "common/gdb_optional.h"
32 #include "completer.h"
34 /* Opaque declarations. */
48 struct cmd_list_element;
50 struct lookup_name_info;
52 /* How to match a lookup name against a symbol search name. */
53 enum class symbol_name_match_type
55 /* Wild matching. Matches unqualified symbol names in all
56 namespace/module/packages, etc. */
59 /* Full matching. The lookup name indicates a fully-qualified name,
60 and only matches symbol search names in the specified
61 namespace/module/package. */
64 /* Search name matching. This is like FULL, but the search name did
65 not come from the user; instead it is already a search name
66 retrieved from a SYMBOL_SEARCH_NAME/MSYMBOL_SEARCH_NAME call.
67 For Ada, this avoids re-encoding an already-encoded search name
68 (which would potentially incorrectly lowercase letters in the
69 linkage/search name that should remain uppercase). For C++, it
70 avoids trying to demangle a name we already know is
74 /* Expression matching. The same as FULL matching in most
75 languages. The same as WILD matching in Ada. */
79 /* Hash the given symbol search name according to LANGUAGE's
81 extern unsigned int search_name_hash (enum language language,
82 const char *search_name);
84 /* Ada-specific bits of a lookup_name_info object. This is lazily
85 constructed on demand. */
87 class ada_lookup_name_info final
91 explicit ada_lookup_name_info (const lookup_name_info &lookup_name);
93 /* Compare SYMBOL_SEARCH_NAME with our lookup name, using MATCH_TYPE
94 as name match type. Returns true if there's a match, false
95 otherwise. If non-NULL, store the matching results in MATCH. */
96 bool matches (const char *symbol_search_name,
97 symbol_name_match_type match_type,
98 completion_match_result *comp_match_res) const;
100 /* The Ada-encoded lookup name. */
101 const std::string &lookup_name () const
102 { return m_encoded_name; }
104 /* Return true if we're supposed to be doing a wild match look
106 bool wild_match_p () const
107 { return m_wild_match_p; }
109 /* Return true if we're looking up a name inside package
111 bool standard_p () const
112 { return m_standard_p; }
114 /* Return true if doing a verbatim match. */
115 bool verbatim_p () const
116 { return m_verbatim_p; }
119 /* The Ada-encoded lookup name. */
120 std::string m_encoded_name;
122 /* Whether the user-provided lookup name was Ada encoded. If so,
123 then return encoded names in the 'matches' method's 'completion
124 match result' output. */
125 bool m_encoded_p : 1;
127 /* True if really doing wild matching. Even if the user requests
128 wild matching, some cases require full matching. */
129 bool m_wild_match_p : 1;
131 /* True if doing a verbatim match. This is true if the decoded
132 version of the symbol name is wrapped in '<'/'>'. This is an
133 escape hatch users can use to look up symbols the Ada encoding
134 does not understand. */
135 bool m_verbatim_p : 1;
137 /* True if the user specified a symbol name that is inside package
138 Standard. Symbol names inside package Standard are handled
139 specially. We always do a non-wild match of the symbol name
140 without the "standard__" prefix, and only search static and
141 global symbols. This was primarily introduced in order to allow
142 the user to specifically access the standard exceptions using,
143 for instance, Standard.Constraint_Error when Constraint_Error is
144 ambiguous (due to the user defining its own Constraint_Error
145 entity inside its program). */
146 bool m_standard_p : 1;
149 /* Language-specific bits of a lookup_name_info object, for languages
150 that do name searching using demangled names (C++/D/Go). This is
151 lazily constructed on demand. */
153 struct demangle_for_lookup_info final
156 demangle_for_lookup_info (const lookup_name_info &lookup_name,
159 /* The demangled lookup name. */
160 const std::string &lookup_name () const
161 { return m_demangled_name; }
164 /* The demangled lookup name. */
165 std::string m_demangled_name;
168 /* Object that aggregates all information related to a symbol lookup
169 name. I.e., the name that is matched against the symbol's search
170 name. Caches per-language information so that it doesn't require
171 recomputing it for every symbol comparison, like for example the
172 Ada encoded name and the symbol's name hash for a given language.
173 The object is conceptually immutable once constructed, and thus has
174 no setters. This is to prevent some code path from tweaking some
175 property of the lookup name for some local reason and accidentally
176 altering the results of any continuing search(es).
177 lookup_name_info objects are generally passed around as a const
178 reference to reinforce that. (They're not passed around by value
179 because they're not small.) */
180 class lookup_name_info final
183 /* Create a new object. */
184 lookup_name_info (std::string name,
185 symbol_name_match_type match_type,
186 bool completion_mode = false,
187 bool ignore_parameters = false)
188 : m_match_type (match_type),
189 m_completion_mode (completion_mode),
190 m_ignore_parameters (ignore_parameters),
191 m_name (std::move (name))
194 /* Getters. See description of each corresponding field. */
195 symbol_name_match_type match_type () const { return m_match_type; }
196 bool completion_mode () const { return m_completion_mode; }
197 const std::string &name () const { return m_name; }
198 const bool ignore_parameters () const { return m_ignore_parameters; }
200 /* Return a version of this lookup name that is usable with
201 comparisons against symbols have no parameter info, such as
202 psymbols and GDB index symbols. */
203 lookup_name_info make_ignore_params () const
205 return lookup_name_info (m_name, m_match_type, m_completion_mode,
206 true /* ignore params */);
209 /* Get the search name hash for searches in language LANG. */
210 unsigned int search_name_hash (language lang) const
212 /* Only compute each language's hash once. */
213 if (!m_demangled_hashes_p[lang])
215 m_demangled_hashes[lang]
216 = ::search_name_hash (lang, language_lookup_name (lang).c_str ());
217 m_demangled_hashes_p[lang] = true;
219 return m_demangled_hashes[lang];
222 /* Get the search name for searches in language LANG. */
223 const std::string &language_lookup_name (language lang) const
228 return ada ().lookup_name ();
230 return cplus ().lookup_name ();
232 return d ().lookup_name ();
234 return go ().lookup_name ();
240 /* Get the Ada-specific lookup info. */
241 const ada_lookup_name_info &ada () const
247 /* Get the C++-specific lookup info. */
248 const demangle_for_lookup_info &cplus () const
250 maybe_init (m_cplus, language_cplus);
254 /* Get the D-specific lookup info. */
255 const demangle_for_lookup_info &d () const
257 maybe_init (m_d, language_d);
261 /* Get the Go-specific lookup info. */
262 const demangle_for_lookup_info &go () const
264 maybe_init (m_go, language_go);
268 /* Get a reference to a lookup_name_info object that matches any
270 static const lookup_name_info &match_any ();
273 /* Initialize FIELD, if not initialized yet. */
274 template<typename Field, typename... Args>
275 void maybe_init (Field &field, Args&&... args) const
278 field.emplace (*this, std::forward<Args> (args)...);
281 /* The lookup info as passed to the ctor. */
282 symbol_name_match_type m_match_type;
283 bool m_completion_mode;
284 bool m_ignore_parameters;
287 /* Language-specific info. These fields are filled lazily the first
288 time a lookup is done in the corresponding language. They're
289 mutable because lookup_name_info objects are typically passed
290 around by const reference (see intro), and they're conceptually
291 "cache" that can always be reconstructed from the non-mutable
293 mutable gdb::optional<ada_lookup_name_info> m_ada;
294 mutable gdb::optional<demangle_for_lookup_info> m_cplus;
295 mutable gdb::optional<demangle_for_lookup_info> m_d;
296 mutable gdb::optional<demangle_for_lookup_info> m_go;
298 /* The demangled hashes. Stored in an array with one entry for each
299 possible language. The second array records whether we've
300 already computed the each language's hash. (These are separate
301 arrays instead of a single array of optional<unsigned> to avoid
302 alignment padding). */
303 mutable std::array<unsigned int, nr_languages> m_demangled_hashes;
304 mutable std::array<bool, nr_languages> m_demangled_hashes_p {};
307 /* Comparison function for completion symbol lookup.
309 Returns true if the symbol name matches against LOOKUP_NAME.
311 SYMBOL_SEARCH_NAME should be a symbol's "search" name.
313 On success and if non-NULL, COMP_MATCH_RES->match is set to point
314 to the symbol name as should be presented to the user as a
315 completion match list element. In most languages, this is the same
316 as the symbol's search name, but in some, like Ada, the display
317 name is dynamically computed within the comparison routine.
319 Also, on success and if non-NULL, COMP_MATCH_RES->match_for_lcd
320 points the part of SYMBOL_SEARCH_NAME that was considered to match
321 LOOKUP_NAME. E.g., in C++, in linespec/wild mode, if the symbol is
322 "foo::function()" and LOOKUP_NAME is "function(", MATCH_FOR_LCD
323 points to "function()" inside SYMBOL_SEARCH_NAME. */
324 typedef bool (symbol_name_matcher_ftype)
325 (const char *symbol_search_name,
326 const lookup_name_info &lookup_name,
327 completion_match_result *comp_match_res);
329 /* Some of the structures in this file are space critical.
330 The space-critical structures are:
332 struct general_symbol_info
334 struct partial_symbol
336 These structures are laid out to encourage good packing.
337 They use ENUM_BITFIELD and short int fields, and they order the
338 structure members so that fields less than a word are next
339 to each other so they can be packed together. */
341 /* Rearranged: used ENUM_BITFIELD and rearranged field order in
342 all the space critical structures (plus struct minimal_symbol).
343 Memory usage dropped from 99360768 bytes to 90001408 bytes.
344 I measured this with before-and-after tests of
345 "HEAD-old-gdb -readnow HEAD-old-gdb" and
346 "HEAD-new-gdb -readnow HEAD-old-gdb" on native i686-pc-linux-gnu,
347 red hat linux 8, with LD_LIBRARY_PATH=/usr/lib/debug,
348 typing "maint space 1" at the first command prompt.
350 Here is another measurement (from andrew c):
351 # no /usr/lib/debug, just plain glibc, like a normal user
353 (gdb) break internal_error
355 (gdb) maint internal-error
359 gdb gdb_6_0_branch 2003-08-19 space used: 8896512
360 gdb HEAD 2003-08-19 space used: 8904704
361 gdb HEAD 2003-08-21 space used: 8396800 (+symtab.h)
362 gdb HEAD 2003-08-21 space used: 8265728 (+gdbtypes.h)
364 The third line shows the savings from the optimizations in symtab.h.
365 The fourth line shows the savings from the optimizations in
366 gdbtypes.h. Both optimizations are in gdb HEAD now.
368 --chastain 2003-08-21 */
370 /* Define a structure for the information that is common to all symbol types,
371 including minimal symbols, partial symbols, and full symbols. In a
372 multilanguage environment, some language specific information may need to
373 be recorded along with each symbol. */
375 /* This structure is space critical. See space comments at the top. */
377 struct general_symbol_info
379 /* Name of the symbol. This is a required field. Storage for the
380 name is allocated on the objfile_obstack for the associated
381 objfile. For languages like C++ that make a distinction between
382 the mangled name and demangled name, this is the mangled
387 /* Value of the symbol. Which member of this union to use, and what
388 it means, depends on what kind of symbol this is and its
389 SYMBOL_CLASS. See comments there for more details. All of these
390 are in host byte order (though what they point to might be in
391 target byte order, e.g. LOC_CONST_BYTES). */
397 const struct block *block;
399 const gdb_byte *bytes;
403 /* A common block. Used with LOC_COMMON_BLOCK. */
405 const struct common_block *common_block;
407 /* For opaque typedef struct chain. */
409 struct symbol *chain;
413 /* Since one and only one language can apply, wrap the language specific
414 information inside a union. */
418 /* A pointer to an obstack that can be used for storage associated
419 with this symbol. This is only used by Ada, and only when the
420 'ada_mangled' field is zero. */
421 struct obstack *obstack;
423 /* This is used by languages which wish to store a demangled name.
424 currently used by Ada, C++, and Objective C. */
425 const char *demangled_name;
429 /* Record the source code language that applies to this symbol.
430 This is used to select one of the fields from the language specific
433 ENUM_BITFIELD(language) language : LANGUAGE_BITS;
435 /* This is only used by Ada. If set, then the 'demangled_name' field
436 of language_specific is valid. Otherwise, the 'obstack' field is
438 unsigned int ada_mangled : 1;
440 /* Which section is this symbol in? This is an index into
441 section_offsets for this objfile. Negative means that the symbol
442 does not get relocated relative to a section. */
447 extern void symbol_set_demangled_name (struct general_symbol_info *,
451 extern const char *symbol_get_demangled_name
452 (const struct general_symbol_info *);
454 extern CORE_ADDR symbol_overlayed_address (CORE_ADDR, struct obj_section *);
456 /* Note that all the following SYMBOL_* macros are used with the
457 SYMBOL argument being either a partial symbol or
458 a full symbol. Both types have a ginfo field. In particular
459 the SYMBOL_SET_LANGUAGE, SYMBOL_DEMANGLED_NAME, etc.
460 macros cannot be entirely substituted by
461 functions, unless the callers are changed to pass in the ginfo
462 field only, instead of the SYMBOL parameter. */
464 #define SYMBOL_VALUE(symbol) (symbol)->ginfo.value.ivalue
465 #define SYMBOL_VALUE_ADDRESS(symbol) (symbol)->ginfo.value.address
466 #define SYMBOL_VALUE_BYTES(symbol) (symbol)->ginfo.value.bytes
467 #define SYMBOL_VALUE_COMMON_BLOCK(symbol) (symbol)->ginfo.value.common_block
468 #define SYMBOL_BLOCK_VALUE(symbol) (symbol)->ginfo.value.block
469 #define SYMBOL_VALUE_CHAIN(symbol) (symbol)->ginfo.value.chain
470 #define SYMBOL_LANGUAGE(symbol) (symbol)->ginfo.language
471 #define SYMBOL_SECTION(symbol) (symbol)->ginfo.section
472 #define SYMBOL_OBJ_SECTION(objfile, symbol) \
473 (((symbol)->ginfo.section >= 0) \
474 ? (&(((objfile)->sections)[(symbol)->ginfo.section])) \
477 /* Initializes the language dependent portion of a symbol
478 depending upon the language for the symbol. */
479 #define SYMBOL_SET_LANGUAGE(symbol,language,obstack) \
480 (symbol_set_language (&(symbol)->ginfo, (language), (obstack)))
481 extern void symbol_set_language (struct general_symbol_info *symbol,
482 enum language language,
483 struct obstack *obstack);
485 /* Set just the linkage name of a symbol; do not try to demangle
486 it. Used for constructs which do not have a mangled name,
487 e.g. struct tags. Unlike SYMBOL_SET_NAMES, linkage_name must
488 be terminated and either already on the objfile's obstack or
489 permanently allocated. */
490 #define SYMBOL_SET_LINKAGE_NAME(symbol,linkage_name) \
491 (symbol)->ginfo.name = (linkage_name)
493 /* Set the linkage and natural names of a symbol, by demangling
495 #define SYMBOL_SET_NAMES(symbol,linkage_name,len,copy_name,objfile) \
496 symbol_set_names (&(symbol)->ginfo, linkage_name, len, copy_name, objfile)
497 extern void symbol_set_names (struct general_symbol_info *symbol,
498 const char *linkage_name, int len, int copy_name,
499 struct objfile *objfile);
501 /* Now come lots of name accessor macros. Short version as to when to
502 use which: Use SYMBOL_NATURAL_NAME to refer to the name of the
503 symbol in the original source code. Use SYMBOL_LINKAGE_NAME if you
504 want to know what the linker thinks the symbol's name is. Use
505 SYMBOL_PRINT_NAME for output. Use SYMBOL_DEMANGLED_NAME if you
506 specifically need to know whether SYMBOL_NATURAL_NAME and
507 SYMBOL_LINKAGE_NAME are different. */
509 /* Return SYMBOL's "natural" name, i.e. the name that it was called in
510 the original source code. In languages like C++ where symbols may
511 be mangled for ease of manipulation by the linker, this is the
514 #define SYMBOL_NATURAL_NAME(symbol) \
515 (symbol_natural_name (&(symbol)->ginfo))
516 extern const char *symbol_natural_name
517 (const struct general_symbol_info *symbol);
519 /* Return SYMBOL's name from the point of view of the linker. In
520 languages like C++ where symbols may be mangled for ease of
521 manipulation by the linker, this is the mangled name; otherwise,
522 it's the same as SYMBOL_NATURAL_NAME. */
524 #define SYMBOL_LINKAGE_NAME(symbol) (symbol)->ginfo.name
526 /* Return the demangled name for a symbol based on the language for
527 that symbol. If no demangled name exists, return NULL. */
528 #define SYMBOL_DEMANGLED_NAME(symbol) \
529 (symbol_demangled_name (&(symbol)->ginfo))
530 extern const char *symbol_demangled_name
531 (const struct general_symbol_info *symbol);
533 /* Macro that returns a version of the name of a symbol that is
534 suitable for output. In C++ this is the "demangled" form of the
535 name if demangle is on and the "mangled" form of the name if
536 demangle is off. In other languages this is just the symbol name.
537 The result should never be NULL. Don't use this for internal
538 purposes (e.g. storing in a hashtable): it's only suitable for output.
540 N.B. symbol may be anything with a ginfo member,
541 e.g., struct symbol or struct minimal_symbol. */
543 #define SYMBOL_PRINT_NAME(symbol) \
544 (demangle ? SYMBOL_NATURAL_NAME (symbol) : SYMBOL_LINKAGE_NAME (symbol))
547 /* Macro that returns the name to be used when sorting and searching symbols.
548 In C++, we search for the demangled form of a name,
549 and so sort symbols accordingly. In Ada, however, we search by mangled
550 name. If there is no distinct demangled name, then SYMBOL_SEARCH_NAME
551 returns the same value (same pointer) as SYMBOL_LINKAGE_NAME. */
552 #define SYMBOL_SEARCH_NAME(symbol) \
553 (symbol_search_name (&(symbol)->ginfo))
554 extern const char *symbol_search_name (const struct general_symbol_info *ginfo);
556 /* Return true if NAME matches the "search" name of SYMBOL, according
557 to the symbol's language. */
558 #define SYMBOL_MATCHES_SEARCH_NAME(symbol, name) \
559 symbol_matches_search_name (&(symbol)->ginfo, (name))
561 /* Helper for SYMBOL_MATCHES_SEARCH_NAME that works with both symbols
563 extern bool symbol_matches_search_name
564 (const struct general_symbol_info *gsymbol,
565 const lookup_name_info &name);
567 /* Compute the hash of the given symbol search name of a symbol of
568 language LANGUAGE. */
569 extern unsigned int search_name_hash (enum language language,
570 const char *search_name);
572 /* Classification types for a minimal symbol. These should be taken as
573 "advisory only", since if gdb can't easily figure out a
574 classification it simply selects mst_unknown. It may also have to
575 guess when it can't figure out which is a better match between two
576 types (mst_data versus mst_bss) for example. Since the minimal
577 symbol info is sometimes derived from the BFD library's view of a
578 file, we need to live with what information bfd supplies. */
580 enum minimal_symbol_type
582 mst_unknown = 0, /* Unknown type, the default */
583 mst_text, /* Generally executable instructions */
585 /* A GNU ifunc symbol, in the .text section. GDB uses to know
586 whether the user is setting a breakpoint on a GNU ifunc function,
587 and thus GDB needs to actually set the breakpoint on the target
588 function. It is also used to know whether the program stepped
589 into an ifunc resolver -- the resolver may get a separate
590 symbol/alias under a different name, but it'll have the same
591 address as the ifunc symbol. */
592 mst_text_gnu_ifunc, /* Executable code returning address
593 of executable code */
595 /* A GNU ifunc function descriptor symbol, in a data section
596 (typically ".opd"). Seen on architectures that use function
597 descriptors, like PPC64/ELFv1. In this case, this symbol's value
598 is the address of the descriptor. There'll be a corresponding
599 mst_text_gnu_ifunc synthetic symbol for the text/entry
601 mst_data_gnu_ifunc, /* Executable code returning address
602 of executable code */
604 mst_slot_got_plt, /* GOT entries for .plt sections */
605 mst_data, /* Generally initialized data */
606 mst_bss, /* Generally uninitialized data */
607 mst_abs, /* Generally absolute (nonrelocatable) */
608 /* GDB uses mst_solib_trampoline for the start address of a shared
609 library trampoline entry. Breakpoints for shared library functions
610 are put there if the shared library is not yet loaded.
611 After the shared library is loaded, lookup_minimal_symbol will
612 prefer the minimal symbol from the shared library (usually
613 a mst_text symbol) over the mst_solib_trampoline symbol, and the
614 breakpoints will be moved to their true address in the shared
615 library via breakpoint_re_set. */
616 mst_solib_trampoline, /* Shared library trampoline code */
617 /* For the mst_file* types, the names are only guaranteed to be unique
618 within a given .o file. */
619 mst_file_text, /* Static version of mst_text */
620 mst_file_data, /* Static version of mst_data */
621 mst_file_bss, /* Static version of mst_bss */
625 /* The number of enum minimal_symbol_type values, with some padding for
626 reasonable growth. */
627 #define MINSYM_TYPE_BITS 4
628 gdb_static_assert (nr_minsym_types <= (1 << MINSYM_TYPE_BITS));
630 /* Define a simple structure used to hold some very basic information about
631 all defined global symbols (text, data, bss, abs, etc). The only required
632 information is the general_symbol_info.
634 In many cases, even if a file was compiled with no special options for
635 debugging at all, as long as was not stripped it will contain sufficient
636 information to build a useful minimal symbol table using this structure.
637 Even when a file contains enough debugging information to build a full
638 symbol table, these minimal symbols are still useful for quickly mapping
639 between names and addresses, and vice versa. They are also sometimes
640 used to figure out what full symbol table entries need to be read in. */
642 struct minimal_symbol
645 /* The general symbol info required for all types of symbols.
647 The SYMBOL_VALUE_ADDRESS contains the address that this symbol
650 struct general_symbol_info mginfo;
652 /* Size of this symbol. dbx_end_psymtab in dbxread.c uses this
653 information to calculate the end of the partial symtab based on the
654 address of the last symbol plus the size of the last symbol. */
658 /* Which source file is this symbol in? Only relevant for mst_file_*. */
659 const char *filename;
661 /* Classification type for this minimal symbol. */
663 ENUM_BITFIELD(minimal_symbol_type) type : MINSYM_TYPE_BITS;
665 /* Non-zero if this symbol was created by gdb.
666 Such symbols do not appear in the output of "info var|fun". */
667 unsigned int created_by_gdb : 1;
669 /* Two flag bits provided for the use of the target. */
670 unsigned int target_flag_1 : 1;
671 unsigned int target_flag_2 : 1;
673 /* Nonzero iff the size of the minimal symbol has been set.
674 Symbol size information can sometimes not be determined, because
675 the object file format may not carry that piece of information. */
676 unsigned int has_size : 1;
678 /* Minimal symbols with the same hash key are kept on a linked
679 list. This is the link. */
681 struct minimal_symbol *hash_next;
683 /* Minimal symbols are stored in two different hash tables. This is
684 the `next' pointer for the demangled hash table. */
686 struct minimal_symbol *demangled_hash_next;
689 #define MSYMBOL_TARGET_FLAG_1(msymbol) (msymbol)->target_flag_1
690 #define MSYMBOL_TARGET_FLAG_2(msymbol) (msymbol)->target_flag_2
691 #define MSYMBOL_SIZE(msymbol) ((msymbol)->size + 0)
692 #define SET_MSYMBOL_SIZE(msymbol, sz) \
695 (msymbol)->size = sz; \
696 (msymbol)->has_size = 1; \
698 #define MSYMBOL_HAS_SIZE(msymbol) ((msymbol)->has_size + 0)
699 #define MSYMBOL_TYPE(msymbol) (msymbol)->type
701 #define MSYMBOL_VALUE(symbol) (symbol)->mginfo.value.ivalue
702 /* The unrelocated address of the minimal symbol. */
703 #define MSYMBOL_VALUE_RAW_ADDRESS(symbol) ((symbol)->mginfo.value.address + 0)
704 /* The relocated address of the minimal symbol, using the section
705 offsets from OBJFILE. */
706 #define MSYMBOL_VALUE_ADDRESS(objfile, symbol) \
707 ((symbol)->mginfo.value.address \
708 + ANOFFSET ((objfile)->section_offsets, ((symbol)->mginfo.section)))
709 /* For a bound minsym, we can easily compute the address directly. */
710 #define BMSYMBOL_VALUE_ADDRESS(symbol) \
711 MSYMBOL_VALUE_ADDRESS ((symbol).objfile, (symbol).minsym)
712 #define SET_MSYMBOL_VALUE_ADDRESS(symbol, new_value) \
713 ((symbol)->mginfo.value.address = (new_value))
714 #define MSYMBOL_VALUE_BYTES(symbol) (symbol)->mginfo.value.bytes
715 #define MSYMBOL_BLOCK_VALUE(symbol) (symbol)->mginfo.value.block
716 #define MSYMBOL_VALUE_CHAIN(symbol) (symbol)->mginfo.value.chain
717 #define MSYMBOL_LANGUAGE(symbol) (symbol)->mginfo.language
718 #define MSYMBOL_SECTION(symbol) (symbol)->mginfo.section
719 #define MSYMBOL_OBJ_SECTION(objfile, symbol) \
720 (((symbol)->mginfo.section >= 0) \
721 ? (&(((objfile)->sections)[(symbol)->mginfo.section])) \
724 #define MSYMBOL_NATURAL_NAME(symbol) \
725 (symbol_natural_name (&(symbol)->mginfo))
726 #define MSYMBOL_LINKAGE_NAME(symbol) (symbol)->mginfo.name
727 #define MSYMBOL_PRINT_NAME(symbol) \
728 (demangle ? MSYMBOL_NATURAL_NAME (symbol) : MSYMBOL_LINKAGE_NAME (symbol))
729 #define MSYMBOL_DEMANGLED_NAME(symbol) \
730 (symbol_demangled_name (&(symbol)->mginfo))
731 #define MSYMBOL_SET_LANGUAGE(symbol,language,obstack) \
732 (symbol_set_language (&(symbol)->mginfo, (language), (obstack)))
733 #define MSYMBOL_SEARCH_NAME(symbol) \
734 (symbol_search_name (&(symbol)->mginfo))
735 #define MSYMBOL_SET_NAMES(symbol,linkage_name,len,copy_name,objfile) \
736 symbol_set_names (&(symbol)->mginfo, linkage_name, len, copy_name, objfile)
742 /* Represent one symbol name; a variable, constant, function or typedef. */
744 /* Different name domains for symbols. Looking up a symbol specifies a
745 domain and ignores symbol definitions in other name domains. */
747 typedef enum domain_enum_tag
749 /* UNDEF_DOMAIN is used when a domain has not been discovered or
750 none of the following apply. This usually indicates an error either
751 in the symbol information or in gdb's handling of symbols. */
755 /* VAR_DOMAIN is the usual domain. In C, this contains variables,
756 function names, typedef names and enum type values. */
760 /* STRUCT_DOMAIN is used in C to hold struct, union and enum type names.
761 Thus, if `struct foo' is used in a C program, it produces a symbol named
762 `foo' in the STRUCT_DOMAIN. */
766 /* MODULE_DOMAIN is used in Fortran to hold module type names. */
770 /* LABEL_DOMAIN may be used for names of labels (for gotos). */
774 /* Fortran common blocks. Their naming must be separate from VAR_DOMAIN.
775 They also always use LOC_COMMON_BLOCK. */
778 /* This must remain last. */
782 /* The number of bits in a symbol used to represent the domain. */
784 #define SYMBOL_DOMAIN_BITS 3
785 gdb_static_assert (NR_DOMAINS <= (1 << SYMBOL_DOMAIN_BITS));
787 extern const char *domain_name (domain_enum);
789 /* Searching domains, used for `search_symbols'. Element numbers are
790 hardcoded in GDB, check all enum uses before changing it. */
794 /* Everything in VAR_DOMAIN minus FUNCTIONS_DOMAIN and
796 VARIABLES_DOMAIN = 0,
798 /* All functions -- for some reason not methods, though. */
799 FUNCTIONS_DOMAIN = 1,
801 /* All defined types */
808 extern const char *search_domain_name (enum search_domain);
810 /* An address-class says where to find the value of a symbol. */
814 /* Not used; catches errors. */
818 /* Value is constant int SYMBOL_VALUE, host byteorder. */
822 /* Value is at fixed address SYMBOL_VALUE_ADDRESS. */
826 /* Value is in register. SYMBOL_VALUE is the register number
827 in the original debug format. SYMBOL_REGISTER_OPS holds a
828 function that can be called to transform this into the
829 actual register number this represents in a specific target
830 architecture (gdbarch).
832 For some symbol formats (stabs, for some compilers at least),
833 the compiler generates two symbols, an argument and a register.
834 In some cases we combine them to a single LOC_REGISTER in symbol
835 reading, but currently not for all cases (e.g. it's passed on the
836 stack and then loaded into a register). */
840 /* It's an argument; the value is at SYMBOL_VALUE offset in arglist. */
844 /* Value address is at SYMBOL_VALUE offset in arglist. */
848 /* Value is in specified register. Just like LOC_REGISTER except the
849 register holds the address of the argument instead of the argument
850 itself. This is currently used for the passing of structs and unions
851 on sparc and hppa. It is also used for call by reference where the
852 address is in a register, at least by mipsread.c. */
856 /* Value is a local variable at SYMBOL_VALUE offset in stack frame. */
860 /* Value not used; definition in SYMBOL_TYPE. Symbols in the domain
861 STRUCT_DOMAIN all have this class. */
865 /* Value is address SYMBOL_VALUE_ADDRESS in the code. */
869 /* In a symbol table, value is SYMBOL_BLOCK_VALUE of a `struct block'.
870 In a partial symbol table, SYMBOL_VALUE_ADDRESS is the start address
871 of the block. Function names have this class. */
875 /* Value is a constant byte-sequence pointed to by SYMBOL_VALUE_BYTES, in
876 target byte order. */
880 /* Value is at fixed address, but the address of the variable has
881 to be determined from the minimal symbol table whenever the
882 variable is referenced.
883 This happens if debugging information for a global symbol is
884 emitted and the corresponding minimal symbol is defined
885 in another object file or runtime common storage.
886 The linker might even remove the minimal symbol if the global
887 symbol is never referenced, in which case the symbol remains
890 GDB would normally find the symbol in the minimal symbol table if it will
891 not find it in the full symbol table. But a reference to an external
892 symbol in a local block shadowing other definition requires full symbol
893 without possibly having its address available for LOC_STATIC. Testcase
894 is provided as `gdb.dwarf2/dw2-unresolved.exp'.
896 This is also used for thread local storage (TLS) variables. In this case,
897 the address of the TLS variable must be determined when the variable is
898 referenced, from the MSYMBOL_VALUE_RAW_ADDRESS, which is the offset
899 of the TLS variable in the thread local storage of the shared
904 /* The variable does not actually exist in the program.
905 The value is ignored. */
909 /* The variable's address is computed by a set of location
910 functions (see "struct symbol_computed_ops" below). */
913 /* The variable uses general_symbol_info->value->common_block field.
914 It also always uses COMMON_BLOCK_DOMAIN. */
917 /* Not used, just notes the boundary of the enum. */
921 /* The number of bits needed for values in enum address_class, with some
922 padding for reasonable growth, and room for run-time registered address
923 classes. See symtab.c:MAX_SYMBOL_IMPLS.
924 This is a #define so that we can have a assertion elsewhere to
925 verify that we have reserved enough space for synthetic address
927 #define SYMBOL_ACLASS_BITS 5
928 gdb_static_assert (LOC_FINAL_VALUE <= (1 << SYMBOL_ACLASS_BITS));
930 /* The methods needed to implement LOC_COMPUTED. These methods can
931 use the symbol's .aux_value for additional per-symbol information.
933 At present this is only used to implement location expressions. */
935 struct symbol_computed_ops
938 /* Return the value of the variable SYMBOL, relative to the stack
939 frame FRAME. If the variable has been optimized out, return
942 Iff `read_needs_frame (SYMBOL)' is not SYMBOL_NEEDS_FRAME, then
943 FRAME may be zero. */
945 struct value *(*read_variable) (struct symbol * symbol,
946 struct frame_info * frame);
948 /* Read variable SYMBOL like read_variable at (callee) FRAME's function
949 entry. SYMBOL should be a function parameter, otherwise
950 NO_ENTRY_VALUE_ERROR will be thrown. */
951 struct value *(*read_variable_at_entry) (struct symbol *symbol,
952 struct frame_info *frame);
954 /* Find the "symbol_needs_kind" value for the given symbol. This
955 value determines whether reading the symbol needs memory (e.g., a
956 global variable), just registers (a thread-local), or a frame (a
958 enum symbol_needs_kind (*get_symbol_read_needs) (struct symbol * symbol);
960 /* Write to STREAM a natural-language description of the location of
961 SYMBOL, in the context of ADDR. */
962 void (*describe_location) (struct symbol * symbol, CORE_ADDR addr,
963 struct ui_file * stream);
965 /* Non-zero if this symbol's address computation is dependent on PC. */
966 unsigned char location_has_loclist;
968 /* Tracepoint support. Append bytecodes to the tracepoint agent
969 expression AX that push the address of the object SYMBOL. Set
970 VALUE appropriately. Note --- for objects in registers, this
971 needn't emit any code; as long as it sets VALUE properly, then
972 the caller will generate the right code in the process of
973 treating this as an lvalue or rvalue. */
975 void (*tracepoint_var_ref) (struct symbol *symbol, struct agent_expr *ax,
976 struct axs_value *value);
978 /* Generate C code to compute the location of SYMBOL. The C code is
979 emitted to STREAM. GDBARCH is the current architecture and PC is
980 the PC at which SYMBOL's location should be evaluated.
981 REGISTERS_USED is a vector indexed by register number; the
982 generator function should set an element in this vector if the
983 corresponding register is needed by the location computation.
984 The generated C code must assign the location to a local
985 variable; this variable's name is RESULT_NAME. */
987 void (*generate_c_location) (struct symbol *symbol, string_file *stream,
988 struct gdbarch *gdbarch,
989 unsigned char *registers_used,
990 CORE_ADDR pc, const char *result_name);
994 /* The methods needed to implement LOC_BLOCK for inferior functions.
995 These methods can use the symbol's .aux_value for additional
996 per-symbol information. */
998 struct symbol_block_ops
1000 /* Fill in *START and *LENGTH with DWARF block data of function
1001 FRAMEFUNC valid for inferior context address PC. Set *LENGTH to
1002 zero if such location is not valid for PC; *START is left
1003 uninitialized in such case. */
1004 void (*find_frame_base_location) (struct symbol *framefunc, CORE_ADDR pc,
1005 const gdb_byte **start, size_t *length);
1007 /* Return the frame base address. FRAME is the frame for which we want to
1008 compute the base address while FRAMEFUNC is the symbol for the
1009 corresponding function. Return 0 on failure (FRAMEFUNC may not hold the
1010 information we need).
1012 This method is designed to work with static links (nested functions
1013 handling). Static links are function properties whose evaluation returns
1014 the frame base address for the enclosing frame. However, there are
1015 multiple definitions for "frame base": the content of the frame base
1016 register, the CFA as defined by DWARF unwinding information, ...
1018 So this specific method is supposed to compute the frame base address such
1019 as for nested fuctions, the static link computes the same address. For
1020 instance, considering DWARF debugging information, the static link is
1021 computed with DW_AT_static_link and this method must be used to compute
1022 the corresponding DW_AT_frame_base attribute. */
1023 CORE_ADDR (*get_frame_base) (struct symbol *framefunc,
1024 struct frame_info *frame);
1027 /* Functions used with LOC_REGISTER and LOC_REGPARM_ADDR. */
1029 struct symbol_register_ops
1031 int (*register_number) (struct symbol *symbol, struct gdbarch *gdbarch);
1034 /* Objects of this type are used to find the address class and the
1035 various computed ops vectors of a symbol. */
1039 enum address_class aclass;
1041 /* Used with LOC_COMPUTED. */
1042 const struct symbol_computed_ops *ops_computed;
1044 /* Used with LOC_BLOCK. */
1045 const struct symbol_block_ops *ops_block;
1047 /* Used with LOC_REGISTER and LOC_REGPARM_ADDR. */
1048 const struct symbol_register_ops *ops_register;
1051 /* struct symbol has some subclasses. This enum is used to
1052 differentiate between them. */
1054 enum symbol_subclass_kind
1056 /* Plain struct symbol. */
1059 /* struct template_symbol. */
1062 /* struct rust_vtable_symbol. */
1066 /* This structure is space critical. See space comments at the top. */
1071 /* The general symbol info required for all types of symbols. */
1073 struct general_symbol_info ginfo;
1075 /* Data type of value */
1079 /* The owner of this symbol.
1080 Which one to use is defined by symbol.is_objfile_owned. */
1084 /* The symbol table containing this symbol. This is the file associated
1085 with LINE. It can be NULL during symbols read-in but it is never NULL
1086 during normal operation. */
1087 struct symtab *symtab;
1089 /* For types defined by the architecture. */
1090 struct gdbarch *arch;
1095 ENUM_BITFIELD(domain_enum_tag) domain : SYMBOL_DOMAIN_BITS;
1097 /* Address class. This holds an index into the 'symbol_impls'
1098 table. The actual enum address_class value is stored there,
1099 alongside any per-class ops vectors. */
1101 unsigned int aclass_index : SYMBOL_ACLASS_BITS;
1103 /* If non-zero then symbol is objfile-owned, use owner.symtab.
1104 Otherwise symbol is arch-owned, use owner.arch. */
1106 unsigned int is_objfile_owned : 1;
1108 /* Whether this is an argument. */
1110 unsigned is_argument : 1;
1112 /* Whether this is an inlined function (class LOC_BLOCK only). */
1113 unsigned is_inlined : 1;
1115 /* The concrete type of this symbol. */
1117 ENUM_BITFIELD (symbol_subclass_kind) subclass : 2;
1119 /* Line number of this symbol's definition, except for inlined
1120 functions. For an inlined function (class LOC_BLOCK and
1121 SYMBOL_INLINED set) this is the line number of the function's call
1122 site. Inlined function symbols are not definitions, and they are
1123 never found by symbol table lookup.
1124 If this symbol is arch-owned, LINE shall be zero.
1126 FIXME: Should we really make the assumption that nobody will try
1127 to debug files longer than 64K lines? What about machine
1128 generated programs? */
1130 unsigned short line;
1132 /* An arbitrary data pointer, allowing symbol readers to record
1133 additional information on a per-symbol basis. Note that this data
1134 must be allocated using the same obstack as the symbol itself. */
1135 /* So far it is only used by:
1136 LOC_COMPUTED: to find the location information
1137 LOC_BLOCK (DWARF2 function): information used internally by the
1138 DWARF 2 code --- specifically, the location expression for the frame
1139 base for this function. */
1140 /* FIXME drow/2003-02-21: For the LOC_BLOCK case, it might be better
1141 to add a magic symbol to the block containing this information,
1142 or to have a generic debug info annotation slot for symbols. */
1146 struct symbol *hash_next;
1149 /* Several lookup functions return both a symbol and the block in which the
1150 symbol is found. This structure is used in these cases. */
1154 /* The symbol that was found, or NULL if no symbol was found. */
1155 struct symbol *symbol;
1157 /* If SYMBOL is not NULL, then this is the block in which the symbol is
1159 const struct block *block;
1162 extern const struct symbol_impl *symbol_impls;
1164 /* For convenience. All fields are NULL. This means "there is no
1166 extern const struct block_symbol null_block_symbol;
1168 /* Note: There is no accessor macro for symbol.owner because it is
1171 #define SYMBOL_DOMAIN(symbol) (symbol)->domain
1172 #define SYMBOL_IMPL(symbol) (symbol_impls[(symbol)->aclass_index])
1173 #define SYMBOL_ACLASS_INDEX(symbol) (symbol)->aclass_index
1174 #define SYMBOL_CLASS(symbol) (SYMBOL_IMPL (symbol).aclass)
1175 #define SYMBOL_OBJFILE_OWNED(symbol) ((symbol)->is_objfile_owned)
1176 #define SYMBOL_IS_ARGUMENT(symbol) (symbol)->is_argument
1177 #define SYMBOL_INLINED(symbol) (symbol)->is_inlined
1178 #define SYMBOL_IS_CPLUS_TEMPLATE_FUNCTION(symbol) \
1179 (((symbol)->subclass) == SYMBOL_TEMPLATE)
1180 #define SYMBOL_TYPE(symbol) (symbol)->type
1181 #define SYMBOL_LINE(symbol) (symbol)->line
1182 #define SYMBOL_COMPUTED_OPS(symbol) (SYMBOL_IMPL (symbol).ops_computed)
1183 #define SYMBOL_BLOCK_OPS(symbol) (SYMBOL_IMPL (symbol).ops_block)
1184 #define SYMBOL_REGISTER_OPS(symbol) (SYMBOL_IMPL (symbol).ops_register)
1185 #define SYMBOL_LOCATION_BATON(symbol) (symbol)->aux_value
1187 extern int register_symbol_computed_impl (enum address_class,
1188 const struct symbol_computed_ops *);
1190 extern int register_symbol_block_impl (enum address_class aclass,
1191 const struct symbol_block_ops *ops);
1193 extern int register_symbol_register_impl (enum address_class,
1194 const struct symbol_register_ops *);
1196 /* Return the OBJFILE of SYMBOL.
1197 It is an error to call this if symbol.is_objfile_owned is false, which
1198 only happens for architecture-provided types. */
1200 extern struct objfile *symbol_objfile (const struct symbol *symbol);
1202 /* Return the ARCH of SYMBOL. */
1204 extern struct gdbarch *symbol_arch (const struct symbol *symbol);
1206 /* Return the SYMTAB of SYMBOL.
1207 It is an error to call this if symbol.is_objfile_owned is false, which
1208 only happens for architecture-provided types. */
1210 extern struct symtab *symbol_symtab (const struct symbol *symbol);
1212 /* Set the symtab of SYMBOL to SYMTAB.
1213 It is an error to call this if symbol.is_objfile_owned is false, which
1214 only happens for architecture-provided types. */
1216 extern void symbol_set_symtab (struct symbol *symbol, struct symtab *symtab);
1218 /* An instance of this type is used to represent a C++ template
1219 function. A symbol is really of this type iff
1220 SYMBOL_IS_CPLUS_TEMPLATE_FUNCTION is true. */
1222 struct template_symbol : public symbol
1224 /* The number of template arguments. */
1225 int n_template_arguments;
1227 /* The template arguments. This is an array with
1228 N_TEMPLATE_ARGUMENTS elements. */
1229 struct symbol **template_arguments;
1232 /* A symbol that represents a Rust virtual table object. */
1234 struct rust_vtable_symbol : public symbol
1236 /* The concrete type for which this vtable was created; that is, in
1237 "impl Trait for Type", this is "Type". */
1238 struct type *concrete_type;
1242 /* Each item represents a line-->pc (or the reverse) mapping. This is
1243 somewhat more wasteful of space than one might wish, but since only
1244 the files which are actually debugged are read in to core, we don't
1245 waste much space. */
1247 struct linetable_entry
1253 /* The order of entries in the linetable is significant. They should
1254 be sorted by increasing values of the pc field. If there is more than
1255 one entry for a given pc, then I'm not sure what should happen (and
1256 I not sure whether we currently handle it the best way).
1258 Example: a C for statement generally looks like this
1260 10 0x100 - for the init/test part of a for stmt.
1263 10 0x400 - for the increment part of a for stmt.
1265 If an entry has a line number of zero, it marks the start of a PC
1266 range for which no line number information is available. It is
1267 acceptable, though wasteful of table space, for such a range to be
1274 /* Actually NITEMS elements. If you don't like this use of the
1275 `struct hack', you can shove it up your ANSI (seriously, if the
1276 committee tells us how to do it, we can probably go along). */
1277 struct linetable_entry item[1];
1280 /* How to relocate the symbols from each section in a symbol file.
1281 Each struct contains an array of offsets.
1282 The ordering and meaning of the offsets is file-type-dependent;
1283 typically it is indexed by section numbers or symbol types or
1284 something like that.
1286 To give us flexibility in changing the internal representation
1287 of these offsets, the ANOFFSET macro must be used to insert and
1288 extract offset values in the struct. */
1290 struct section_offsets
1292 CORE_ADDR offsets[1]; /* As many as needed. */
1295 #define ANOFFSET(secoff, whichone) \
1297 ? (internal_error (__FILE__, __LINE__, \
1298 _("Section index is uninitialized")), -1) \
1299 : secoff->offsets[whichone])
1301 /* The size of a section_offsets table for N sections. */
1302 #define SIZEOF_N_SECTION_OFFSETS(n) \
1303 (sizeof (struct section_offsets) \
1304 + sizeof (((struct section_offsets *) 0)->offsets) * ((n)-1))
1306 /* Each source file or header is represented by a struct symtab.
1307 The name "symtab" is historical, another name for it is "filetab".
1308 These objects are chained through the `next' field. */
1312 /* Unordered chain of all filetabs in the compunit, with the exception
1313 that the "main" source file is the first entry in the list. */
1315 struct symtab *next;
1317 /* Backlink to containing compunit symtab. */
1319 struct compunit_symtab *compunit_symtab;
1321 /* Table mapping core addresses to line numbers for this file.
1322 Can be NULL if none. Never shared between different symtabs. */
1324 struct linetable *linetable;
1326 /* Name of this source file. This pointer is never NULL. */
1328 const char *filename;
1330 /* Total number of lines found in source file. */
1334 /* line_charpos[N] is the position of the (N-1)th line of the
1335 source file. "position" means something we can lseek() to; it
1336 is not guaranteed to be useful any other way. */
1340 /* Language of this source file. */
1342 enum language language;
1344 /* Full name of file as found by searching the source path.
1345 NULL if not yet known. */
1350 #define SYMTAB_COMPUNIT(symtab) ((symtab)->compunit_symtab)
1351 #define SYMTAB_LINETABLE(symtab) ((symtab)->linetable)
1352 #define SYMTAB_LANGUAGE(symtab) ((symtab)->language)
1353 #define SYMTAB_BLOCKVECTOR(symtab) \
1354 COMPUNIT_BLOCKVECTOR (SYMTAB_COMPUNIT (symtab))
1355 #define SYMTAB_OBJFILE(symtab) \
1356 COMPUNIT_OBJFILE (SYMTAB_COMPUNIT (symtab))
1357 #define SYMTAB_PSPACE(symtab) (SYMTAB_OBJFILE (symtab)->pspace)
1358 #define SYMTAB_DIRNAME(symtab) \
1359 COMPUNIT_DIRNAME (SYMTAB_COMPUNIT (symtab))
1361 /* Compunit symtabs contain the actual "symbol table", aka blockvector, as well
1362 as the list of all source files (what gdb has historically associated with
1364 Additional information is recorded here that is common to all symtabs in a
1365 compilation unit (DWARF or otherwise).
1368 For the case of a program built out of these files:
1377 This is recorded as:
1379 objfile -> foo.c(cu) -> bar.c(cu) -> NULL
1393 where "foo.c(cu)" and "bar.c(cu)" are struct compunit_symtab objects,
1394 and the files foo.c, etc. are struct symtab objects. */
1396 struct compunit_symtab
1398 /* Unordered chain of all compunit symtabs of this objfile. */
1399 struct compunit_symtab *next;
1401 /* Object file from which this symtab information was read. */
1402 struct objfile *objfile;
1404 /* Name of the symtab.
1405 This is *not* intended to be a usable filename, and is
1406 for debugging purposes only. */
1409 /* Unordered list of file symtabs, except that by convention the "main"
1410 source file (e.g., .c, .cc) is guaranteed to be first.
1411 Each symtab is a file, either the "main" source file (e.g., .c, .cc)
1412 or header (e.g., .h). */
1413 struct symtab *filetabs;
1415 /* Last entry in FILETABS list.
1416 Subfiles are added to the end of the list so they accumulate in order,
1417 with the main source subfile living at the front.
1418 The main reason is so that the main source file symtab is at the head
1419 of the list, and the rest appear in order for debugging convenience. */
1420 struct symtab *last_filetab;
1422 /* Non-NULL string that identifies the format of the debugging information,
1423 such as "stabs", "dwarf 1", "dwarf 2", "coff", etc. This is mostly useful
1424 for automated testing of gdb but may also be information that is
1425 useful to the user. */
1426 const char *debugformat;
1428 /* String of producer version information, or NULL if we don't know. */
1429 const char *producer;
1431 /* Directory in which it was compiled, or NULL if we don't know. */
1432 const char *dirname;
1434 /* List of all symbol scope blocks for this symtab. It is shared among
1435 all symtabs in a given compilation unit. */
1436 const struct blockvector *blockvector;
1438 /* Section in objfile->section_offsets for the blockvector and
1439 the linetable. Probably always SECT_OFF_TEXT. */
1440 int block_line_section;
1442 /* Symtab has been compiled with both optimizations and debug info so that
1443 GDB may stop skipping prologues as variables locations are valid already
1444 at function entry points. */
1445 unsigned int locations_valid : 1;
1447 /* DWARF unwinder for this CU is valid even for epilogues (PC at the return
1448 instruction). This is supported by GCC since 4.5.0. */
1449 unsigned int epilogue_unwind_valid : 1;
1451 /* struct call_site entries for this compilation unit or NULL. */
1452 htab_t call_site_htab;
1454 /* The macro table for this symtab. Like the blockvector, this
1455 is shared between different symtabs in a given compilation unit.
1456 It's debatable whether it *should* be shared among all the symtabs in
1457 the given compilation unit, but it currently is. */
1458 struct macro_table *macro_table;
1460 /* If non-NULL, then this points to a NULL-terminated vector of
1461 included compunits. When searching the static or global
1462 block of this compunit, the corresponding block of all
1463 included compunits will also be searched. Note that this
1464 list must be flattened -- the symbol reader is responsible for
1465 ensuring that this vector contains the transitive closure of all
1466 included compunits. */
1467 struct compunit_symtab **includes;
1469 /* If this is an included compunit, this points to one includer
1470 of the table. This user is considered the canonical compunit
1471 containing this one. An included compunit may itself be
1472 included by another. */
1473 struct compunit_symtab *user;
1476 #define COMPUNIT_OBJFILE(cust) ((cust)->objfile)
1477 #define COMPUNIT_FILETABS(cust) ((cust)->filetabs)
1478 #define COMPUNIT_DEBUGFORMAT(cust) ((cust)->debugformat)
1479 #define COMPUNIT_PRODUCER(cust) ((cust)->producer)
1480 #define COMPUNIT_DIRNAME(cust) ((cust)->dirname)
1481 #define COMPUNIT_BLOCKVECTOR(cust) ((cust)->blockvector)
1482 #define COMPUNIT_BLOCK_LINE_SECTION(cust) ((cust)->block_line_section)
1483 #define COMPUNIT_LOCATIONS_VALID(cust) ((cust)->locations_valid)
1484 #define COMPUNIT_EPILOGUE_UNWIND_VALID(cust) ((cust)->epilogue_unwind_valid)
1485 #define COMPUNIT_CALL_SITE_HTAB(cust) ((cust)->call_site_htab)
1486 #define COMPUNIT_MACRO_TABLE(cust) ((cust)->macro_table)
1488 /* Iterate over all file tables (struct symtab) within a compunit. */
1490 #define ALL_COMPUNIT_FILETABS(cu, s) \
1491 for ((s) = (cu) -> filetabs; (s) != NULL; (s) = (s) -> next)
1493 /* Return the primary symtab of CUST. */
1495 extern struct symtab *
1496 compunit_primary_filetab (const struct compunit_symtab *cust);
1498 /* Return the language of CUST. */
1500 extern enum language compunit_language (const struct compunit_symtab *cust);
1504 /* The virtual function table is now an array of structures which have the
1505 form { int16 offset, delta; void *pfn; }.
1507 In normal virtual function tables, OFFSET is unused.
1508 DELTA is the amount which is added to the apparent object's base
1509 address in order to point to the actual object to which the
1510 virtual function should be applied.
1511 PFN is a pointer to the virtual function.
1513 Note that this macro is g++ specific (FIXME). */
1515 #define VTBL_FNADDR_OFFSET 2
1517 /* External variables and functions for the objects described above. */
1519 /* True if we are nested inside psymtab_to_symtab. */
1521 extern int currently_reading_symtab;
1523 /* symtab.c lookup functions */
1525 extern const char multiple_symbols_ask[];
1526 extern const char multiple_symbols_all[];
1527 extern const char multiple_symbols_cancel[];
1529 const char *multiple_symbols_select_mode (void);
1531 int symbol_matches_domain (enum language symbol_language,
1532 domain_enum symbol_domain,
1533 domain_enum domain);
1535 /* lookup a symbol table by source file name. */
1537 extern struct symtab *lookup_symtab (const char *);
1539 /* An object of this type is passed as the 'is_a_field_of_this'
1540 argument to lookup_symbol and lookup_symbol_in_language. */
1542 struct field_of_this_result
1544 /* The type in which the field was found. If this is NULL then the
1545 symbol was not found in 'this'. If non-NULL, then one of the
1546 other fields will be non-NULL as well. */
1550 /* If the symbol was found as an ordinary field of 'this', then this
1551 is non-NULL and points to the particular field. */
1553 struct field *field;
1555 /* If the symbol was found as a function field of 'this', then this
1556 is non-NULL and points to the particular field. */
1558 struct fn_fieldlist *fn_field;
1561 /* Find the definition for a specified symbol name NAME
1562 in domain DOMAIN in language LANGUAGE, visible from lexical block BLOCK
1563 if non-NULL or from global/static blocks if BLOCK is NULL.
1564 Returns the struct symbol pointer, or NULL if no symbol is found.
1565 C++: if IS_A_FIELD_OF_THIS is non-NULL on entry, check to see if
1566 NAME is a field of the current implied argument `this'. If so fill in the
1567 fields of IS_A_FIELD_OF_THIS, otherwise the fields are set to NULL.
1568 The symbol's section is fixed up if necessary. */
1570 extern struct block_symbol
1571 lookup_symbol_in_language (const char *,
1572 const struct block *,
1575 struct field_of_this_result *);
1577 /* Same as lookup_symbol_in_language, but using the current language. */
1579 extern struct block_symbol lookup_symbol (const char *,
1580 const struct block *,
1582 struct field_of_this_result *);
1584 /* Find the definition for a specified symbol search name in domain
1585 DOMAIN, visible from lexical block BLOCK if non-NULL or from
1586 global/static blocks if BLOCK is NULL. The passed-in search name
1587 should not come from the user; instead it should already be a
1588 search name as retrieved from a
1589 SYMBOL_SEARCH_NAME/MSYMBOL_SEARCH_NAME call. See definition of
1590 symbol_name_match_type::SEARCH_NAME. Returns the struct symbol
1591 pointer, or NULL if no symbol is found. The symbol's section is
1592 fixed up if necessary. */
1594 extern struct block_symbol lookup_symbol_search_name (const char *search_name,
1595 const struct block *block,
1596 domain_enum domain);
1598 /* A default version of lookup_symbol_nonlocal for use by languages
1599 that can't think of anything better to do.
1600 This implements the C lookup rules. */
1602 extern struct block_symbol
1603 basic_lookup_symbol_nonlocal (const struct language_defn *langdef,
1605 const struct block *,
1608 /* Some helper functions for languages that need to write their own
1609 lookup_symbol_nonlocal functions. */
1611 /* Lookup a symbol in the static block associated to BLOCK, if there
1612 is one; do nothing if BLOCK is NULL or a global block.
1613 Upon success fixes up the symbol's section if necessary. */
1615 extern struct block_symbol
1616 lookup_symbol_in_static_block (const char *name,
1617 const struct block *block,
1618 const domain_enum domain);
1620 /* Search all static file-level symbols for NAME from DOMAIN.
1621 Upon success fixes up the symbol's section if necessary. */
1623 extern struct block_symbol lookup_static_symbol (const char *name,
1624 const domain_enum domain);
1626 /* Lookup a symbol in all files' global blocks.
1628 If BLOCK is non-NULL then it is used for two things:
1629 1) If a target-specific lookup routine for libraries exists, then use the
1630 routine for the objfile of BLOCK, and
1631 2) The objfile of BLOCK is used to assist in determining the search order
1632 if the target requires it.
1633 See gdbarch_iterate_over_objfiles_in_search_order.
1635 Upon success fixes up the symbol's section if necessary. */
1637 extern struct block_symbol
1638 lookup_global_symbol (const char *name,
1639 const struct block *block,
1640 const domain_enum domain);
1642 /* Lookup a symbol in block BLOCK.
1643 Upon success fixes up the symbol's section if necessary. */
1645 extern struct symbol *
1646 lookup_symbol_in_block (const char *name,
1647 symbol_name_match_type match_type,
1648 const struct block *block,
1649 const domain_enum domain);
1651 /* Look up the `this' symbol for LANG in BLOCK. Return the symbol if
1652 found, or NULL if not found. */
1654 extern struct block_symbol
1655 lookup_language_this (const struct language_defn *lang,
1656 const struct block *block);
1658 /* Lookup a [struct, union, enum] by name, within a specified block. */
1660 extern struct type *lookup_struct (const char *, const struct block *);
1662 extern struct type *lookup_union (const char *, const struct block *);
1664 extern struct type *lookup_enum (const char *, const struct block *);
1666 /* from blockframe.c: */
1668 /* lookup the function symbol corresponding to the address. The
1669 return value will not be an inlined function; the containing
1670 function will be returned instead. */
1672 extern struct symbol *find_pc_function (CORE_ADDR);
1674 /* lookup the function corresponding to the address and section. The
1675 return value will not be an inlined function; the containing
1676 function will be returned instead. */
1678 extern struct symbol *find_pc_sect_function (CORE_ADDR, struct obj_section *);
1680 /* lookup the function symbol corresponding to the address and
1681 section. The return value will be the closest enclosing function,
1682 which might be an inline function. */
1684 extern struct symbol *find_pc_sect_containing_function
1685 (CORE_ADDR pc, struct obj_section *section);
1687 /* Find the symbol at the given address. Returns NULL if no symbol
1688 found. Only exact matches for ADDRESS are considered. */
1690 extern struct symbol *find_symbol_at_address (CORE_ADDR);
1692 /* Finds the "function" (text symbol) that is smaller than PC but
1693 greatest of all of the potential text symbols in SECTION. Sets
1694 *NAME and/or *ADDRESS conditionally if that pointer is non-null.
1695 If ENDADDR is non-null, then set *ENDADDR to be the end of the
1696 function (exclusive). If the optional parameter BLOCK is non-null,
1697 then set *BLOCK to the address of the block corresponding to the
1698 function symbol, if such a symbol could be found during the lookup;
1699 nullptr is used as a return value for *BLOCK if no block is found.
1700 This function either succeeds or fails (not halfway succeeds). If
1701 it succeeds, it sets *NAME, *ADDRESS, and *ENDADDR to real
1702 information and returns 1. If it fails, it sets *NAME, *ADDRESS
1703 and *ENDADDR to zero and returns 0.
1705 If the function in question occupies non-contiguous ranges,
1706 *ADDRESS and *ENDADDR are (subject to the conditions noted above) set
1707 to the start and end of the range in which PC is found. Thus
1708 *ADDRESS <= PC < *ENDADDR with no intervening gaps (in which ranges
1709 from other functions might be found).
1711 This property allows find_pc_partial_function to be used (as it had
1712 been prior to the introduction of non-contiguous range support) by
1713 various tdep files for finding a start address and limit address
1714 for prologue analysis. This still isn't ideal, however, because we
1715 probably shouldn't be doing prologue analysis (in which
1716 instructions are scanned to determine frame size and stack layout)
1717 for any range that doesn't contain the entry pc. Moreover, a good
1718 argument can be made that prologue analysis ought to be performed
1719 starting from the entry pc even when PC is within some other range.
1720 This might suggest that *ADDRESS and *ENDADDR ought to be set to the
1721 limits of the entry pc range, but that will cause the
1722 *ADDRESS <= PC < *ENDADDR condition to be violated; many of the
1723 callers of find_pc_partial_function expect this condition to hold.
1725 Callers which require the start and/or end addresses for the range
1726 containing the entry pc should instead call
1727 find_function_entry_range_from_pc. */
1729 extern int find_pc_partial_function (CORE_ADDR pc, const char **name,
1730 CORE_ADDR *address, CORE_ADDR *endaddr,
1731 const struct block **block = nullptr);
1733 /* Like find_pc_partial_function, above, but *ADDRESS and *ENDADDR are
1734 set to start and end addresses of the range containing the entry pc.
1736 Note that it is not necessarily the case that (for non-NULL ADDRESS
1737 and ENDADDR arguments) the *ADDRESS <= PC < *ENDADDR condition will
1740 See comment for find_pc_partial_function, above, for further
1743 extern bool find_function_entry_range_from_pc (CORE_ADDR pc,
1746 CORE_ADDR *endaddr);
1748 /* Return the type of a function with its first instruction exactly at
1749 the PC address. Return NULL otherwise. */
1751 extern struct type *find_function_type (CORE_ADDR pc);
1753 /* See if we can figure out the function's actual type from the type
1754 that the resolver returns. RESOLVER_FUNADDR is the address of the
1757 extern struct type *find_gnu_ifunc_target_type (CORE_ADDR resolver_funaddr);
1759 /* Find the GNU ifunc minimal symbol that matches SYM. */
1760 extern bound_minimal_symbol find_gnu_ifunc (const symbol *sym);
1762 extern void clear_pc_function_cache (void);
1764 /* Expand symtab containing PC, SECTION if not already expanded. */
1766 extern void expand_symtab_containing_pc (CORE_ADDR, struct obj_section *);
1768 /* lookup full symbol table by address. */
1770 extern struct compunit_symtab *find_pc_compunit_symtab (CORE_ADDR);
1772 /* lookup full symbol table by address and section. */
1774 extern struct compunit_symtab *
1775 find_pc_sect_compunit_symtab (CORE_ADDR, struct obj_section *);
1777 extern int find_pc_line_pc_range (CORE_ADDR, CORE_ADDR *, CORE_ADDR *);
1779 extern void reread_symbols (void);
1781 /* Look up a type named NAME in STRUCT_DOMAIN in the current language.
1782 The type returned must not be opaque -- i.e., must have at least one field
1785 extern struct type *lookup_transparent_type (const char *);
1787 extern struct type *basic_lookup_transparent_type (const char *);
1789 /* Macro for name of symbol to indicate a file compiled with gcc. */
1790 #ifndef GCC_COMPILED_FLAG_SYMBOL
1791 #define GCC_COMPILED_FLAG_SYMBOL "gcc_compiled."
1794 /* Macro for name of symbol to indicate a file compiled with gcc2. */
1795 #ifndef GCC2_COMPILED_FLAG_SYMBOL
1796 #define GCC2_COMPILED_FLAG_SYMBOL "gcc2_compiled."
1799 extern int in_gnu_ifunc_stub (CORE_ADDR pc);
1801 /* Functions for resolving STT_GNU_IFUNC symbols which are implemented only
1802 for ELF symbol files. */
1804 struct gnu_ifunc_fns
1806 /* See elf_gnu_ifunc_resolve_addr for its real implementation. */
1807 CORE_ADDR (*gnu_ifunc_resolve_addr) (struct gdbarch *gdbarch, CORE_ADDR pc);
1809 /* See elf_gnu_ifunc_resolve_name for its real implementation. */
1810 int (*gnu_ifunc_resolve_name) (const char *function_name,
1811 CORE_ADDR *function_address_p);
1813 /* See elf_gnu_ifunc_resolver_stop for its real implementation. */
1814 void (*gnu_ifunc_resolver_stop) (struct breakpoint *b);
1816 /* See elf_gnu_ifunc_resolver_return_stop for its real implementation. */
1817 void (*gnu_ifunc_resolver_return_stop) (struct breakpoint *b);
1820 #define gnu_ifunc_resolve_addr gnu_ifunc_fns_p->gnu_ifunc_resolve_addr
1821 #define gnu_ifunc_resolve_name gnu_ifunc_fns_p->gnu_ifunc_resolve_name
1822 #define gnu_ifunc_resolver_stop gnu_ifunc_fns_p->gnu_ifunc_resolver_stop
1823 #define gnu_ifunc_resolver_return_stop \
1824 gnu_ifunc_fns_p->gnu_ifunc_resolver_return_stop
1826 extern const struct gnu_ifunc_fns *gnu_ifunc_fns_p;
1828 extern CORE_ADDR find_solib_trampoline_target (struct frame_info *, CORE_ADDR);
1830 struct symtab_and_line
1832 /* The program space of this sal. */
1833 struct program_space *pspace = NULL;
1835 struct symtab *symtab = NULL;
1836 struct symbol *symbol = NULL;
1837 struct obj_section *section = NULL;
1838 struct minimal_symbol *msymbol = NULL;
1839 /* Line number. Line numbers start at 1 and proceed through symtab->nlines.
1840 0 is never a valid line number; it is used to indicate that line number
1841 information is not available. */
1846 bool explicit_pc = false;
1847 bool explicit_line = false;
1849 /* The probe associated with this symtab_and_line. */
1851 /* If PROBE is not NULL, then this is the objfile in which the probe
1853 struct objfile *objfile = NULL;
1858 /* Given a pc value, return line number it is in. Second arg nonzero means
1859 if pc is on the boundary use the previous statement's line number. */
1861 extern struct symtab_and_line find_pc_line (CORE_ADDR, int);
1863 /* Same function, but specify a section as well as an address. */
1865 extern struct symtab_and_line find_pc_sect_line (CORE_ADDR,
1866 struct obj_section *, int);
1868 /* Wrapper around find_pc_line to just return the symtab. */
1870 extern struct symtab *find_pc_line_symtab (CORE_ADDR);
1872 /* Given a symtab and line number, return the pc there. */
1874 extern int find_line_pc (struct symtab *, int, CORE_ADDR *);
1876 extern int find_line_pc_range (struct symtab_and_line, CORE_ADDR *,
1879 extern void resolve_sal_pc (struct symtab_and_line *);
1883 extern void clear_solib (void);
1887 extern int identify_source_line (struct symtab *, int, int, CORE_ADDR);
1889 /* Flags passed as 4th argument to print_source_lines. */
1891 enum print_source_lines_flag
1893 /* Do not print an error message. */
1894 PRINT_SOURCE_LINES_NOERROR = (1 << 0),
1896 /* Print the filename in front of the source lines. */
1897 PRINT_SOURCE_LINES_FILENAME = (1 << 1)
1899 DEF_ENUM_FLAGS_TYPE (enum print_source_lines_flag, print_source_lines_flags);
1901 extern void print_source_lines (struct symtab *, int, int,
1902 print_source_lines_flags);
1904 extern void forget_cached_source_info_for_objfile (struct objfile *);
1905 extern void forget_cached_source_info (void);
1907 extern void select_source_symtab (struct symtab *);
1909 /* The reason we're calling into a completion match list collector
1911 enum class complete_symbol_mode
1913 /* Completing an expression. */
1916 /* Completing a linespec. */
1920 extern void default_collect_symbol_completion_matches_break_on
1921 (completion_tracker &tracker,
1922 complete_symbol_mode mode,
1923 symbol_name_match_type name_match_type,
1924 const char *text, const char *word, const char *break_on,
1925 enum type_code code);
1926 extern void default_collect_symbol_completion_matches
1927 (completion_tracker &tracker,
1928 complete_symbol_mode,
1929 symbol_name_match_type name_match_type,
1933 extern void collect_symbol_completion_matches
1934 (completion_tracker &tracker,
1935 complete_symbol_mode mode,
1936 symbol_name_match_type name_match_type,
1937 const char *, const char *);
1938 extern void collect_symbol_completion_matches_type (completion_tracker &tracker,
1939 const char *, const char *,
1942 extern void collect_file_symbol_completion_matches
1943 (completion_tracker &tracker,
1944 complete_symbol_mode,
1945 symbol_name_match_type name_match_type,
1946 const char *, const char *, const char *);
1948 extern completion_list
1949 make_source_files_completion_list (const char *, const char *);
1951 /* Return whether SYM is a function/method, as opposed to a data symbol. */
1953 extern bool symbol_is_function_or_method (symbol *sym);
1955 /* Return whether MSYMBOL is a function/method, as opposed to a data
1958 extern bool symbol_is_function_or_method (minimal_symbol *msymbol);
1960 /* Return whether SYM should be skipped in completion mode MODE. In
1961 linespec mode, we're only interested in functions/methods. */
1963 template<typename Symbol>
1965 completion_skip_symbol (complete_symbol_mode mode, Symbol *sym)
1967 return (mode == complete_symbol_mode::LINESPEC
1968 && !symbol_is_function_or_method (sym));
1973 int matching_obj_sections (struct obj_section *, struct obj_section *);
1975 extern struct symtab *find_line_symtab (struct symtab *, int, int *, int *);
1977 /* Given a function symbol SYM, find the symtab and line for the start
1978 of the function. If FUNFIRSTLINE is true, we want the first line
1979 of real code inside the function. */
1980 extern symtab_and_line find_function_start_sal (symbol *sym, bool
1983 /* Same, but start with a function address/section instead of a
1985 extern symtab_and_line find_function_start_sal (CORE_ADDR func_addr,
1986 obj_section *section,
1989 extern void skip_prologue_sal (struct symtab_and_line *);
1993 extern CORE_ADDR skip_prologue_using_sal (struct gdbarch *gdbarch,
1994 CORE_ADDR func_addr);
1996 extern struct symbol *fixup_symbol_section (struct symbol *,
1999 /* If MSYMBOL is an text symbol, look for a function debug symbol with
2000 the same address. Returns NULL if not found. This is necessary in
2001 case a function is an alias to some other function, because debug
2002 information is only emitted for the alias target function's
2003 definition, not for the alias. */
2004 extern symbol *find_function_alias_target (bound_minimal_symbol msymbol);
2006 /* Symbol searching */
2007 /* Note: struct symbol_search, search_symbols, et.al. are declared here,
2008 instead of making them local to symtab.c, for gdbtk's sake. */
2010 /* When using search_symbols, a vector of the following structs is
2012 struct symbol_search
2014 symbol_search (int block_, struct symbol *symbol_)
2018 msymbol.minsym = nullptr;
2019 msymbol.objfile = nullptr;
2022 symbol_search (int block_, struct minimal_symbol *minsym,
2023 struct objfile *objfile)
2027 msymbol.minsym = minsym;
2028 msymbol.objfile = objfile;
2031 bool operator< (const symbol_search &other) const
2033 return compare_search_syms (*this, other) < 0;
2036 bool operator== (const symbol_search &other) const
2038 return compare_search_syms (*this, other) == 0;
2041 /* The block in which the match was found. Could be, for example,
2042 STATIC_BLOCK or GLOBAL_BLOCK. */
2045 /* Information describing what was found.
2047 If symbol is NOT NULL, then information was found for this match. */
2048 struct symbol *symbol;
2050 /* If msymbol is non-null, then a match was made on something for
2051 which only minimal_symbols exist. */
2052 struct bound_minimal_symbol msymbol;
2056 static int compare_search_syms (const symbol_search &sym_a,
2057 const symbol_search &sym_b);
2060 extern std::vector<symbol_search> search_symbols (const char *,
2065 extern bool treg_matches_sym_type_name (const compiled_regex &treg,
2066 const struct symbol *sym);
2068 /* The name of the ``main'' function.
2069 FIXME: cagney/2001-03-20: Can't make main_name() const since some
2070 of the calling code currently assumes that the string isn't
2072 extern /*const */ char *main_name (void);
2073 extern enum language main_language (void);
2075 /* Lookup symbol NAME from DOMAIN in MAIN_OBJFILE's global blocks.
2076 This searches MAIN_OBJFILE as well as any associated separate debug info
2077 objfiles of MAIN_OBJFILE.
2078 Upon success fixes up the symbol's section if necessary. */
2080 extern struct block_symbol
2081 lookup_global_symbol_from_objfile (struct objfile *main_objfile,
2083 const domain_enum domain);
2085 /* Return 1 if the supplied producer string matches the ARM RealView
2086 compiler (armcc). */
2087 int producer_is_realview (const char *producer);
2089 void fixup_section (struct general_symbol_info *ginfo,
2090 CORE_ADDR addr, struct objfile *objfile);
2092 /* Look up objfile containing BLOCK. */
2094 struct objfile *lookup_objfile_from_block (const struct block *block);
2096 extern unsigned int symtab_create_debug;
2098 extern unsigned int symbol_lookup_debug;
2100 extern int basenames_may_differ;
2102 int compare_filenames_for_search (const char *filename,
2103 const char *search_name);
2105 int compare_glob_filenames_for_search (const char *filename,
2106 const char *search_name);
2108 bool iterate_over_some_symtabs (const char *name,
2109 const char *real_path,
2110 struct compunit_symtab *first,
2111 struct compunit_symtab *after_last,
2112 gdb::function_view<bool (symtab *)> callback);
2114 void iterate_over_symtabs (const char *name,
2115 gdb::function_view<bool (symtab *)> callback);
2118 std::vector<CORE_ADDR> find_pcs_for_symtab_line
2119 (struct symtab *symtab, int line, struct linetable_entry **best_entry);
2121 /* Prototype for callbacks for LA_ITERATE_OVER_SYMBOLS. The callback
2122 is called once per matching symbol SYM. The callback should return
2123 true to indicate that LA_ITERATE_OVER_SYMBOLS should continue
2124 iterating, or false to indicate that the iteration should end. */
2126 typedef bool (symbol_found_callback_ftype) (struct block_symbol *bsym);
2128 void iterate_over_symbols (const struct block *block,
2129 const lookup_name_info &name,
2130 const domain_enum domain,
2131 gdb::function_view<symbol_found_callback_ftype> callback);
2133 /* Storage type used by demangle_for_lookup. demangle_for_lookup
2134 either returns a const char * pointer that points to either of the
2135 fields of this type, or a pointer to the input NAME. This is done
2136 this way because the underlying functions that demangle_for_lookup
2137 calls either return a std::string (e.g., cp_canonicalize_string) or
2138 a malloc'ed buffer (libiberty's demangled), and we want to avoid
2139 unnecessary reallocation/string copying. */
2140 class demangle_result_storage
2144 /* Swap the std::string storage with STR, and return a pointer to
2145 the beginning of the new string. */
2146 const char *swap_string (std::string &str)
2148 std::swap (m_string, str);
2149 return m_string.c_str ();
2152 /* Set the malloc storage to now point at PTR. Any previous malloc
2153 storage is released. */
2154 const char *set_malloc_ptr (char *ptr)
2156 m_malloc.reset (ptr);
2163 std::string m_string;
2164 gdb::unique_xmalloc_ptr<char> m_malloc;
2168 demangle_for_lookup (const char *name, enum language lang,
2169 demangle_result_storage &storage);
2171 struct symbol *allocate_symbol (struct objfile *);
2173 void initialize_objfile_symbol (struct symbol *);
2175 struct template_symbol *allocate_template_symbol (struct objfile *);
2177 /* Test to see if the symbol of language SYMBOL_LANGUAGE specified by
2178 SYMNAME (which is already demangled for C++ symbols) matches
2179 SYM_TEXT in the first SYM_TEXT_LEN characters. If so, add it to
2180 the current completion list. */
2181 void completion_list_add_name (completion_tracker &tracker,
2182 language symbol_language,
2183 const char *symname,
2184 const lookup_name_info &lookup_name,
2185 const char *text, const char *word);
2187 /* A simple symbol searching class. */
2189 class symbol_searcher
2192 /* Returns the symbols found for the search. */
2193 const std::vector<block_symbol> &
2194 matching_symbols () const
2199 /* Returns the minimal symbols found for the search. */
2200 const std::vector<bound_minimal_symbol> &
2201 matching_msymbols () const
2203 return m_minimal_symbols;
2206 /* Search for all symbols named NAME in LANGUAGE with DOMAIN, restricting
2207 search to FILE_SYMTABS and SEARCH_PSPACE, both of which may be NULL
2208 to search all symtabs and program spaces. */
2209 void find_all_symbols (const std::string &name,
2210 const struct language_defn *language,
2211 enum search_domain search_domain,
2212 std::vector<symtab *> *search_symtabs,
2213 struct program_space *search_pspace);
2215 /* Reset this object to perform another search. */
2219 m_minimal_symbols.clear ();
2223 /* Matching debug symbols. */
2224 std::vector<block_symbol> m_symbols;
2226 /* Matching non-debug symbols. */
2227 std::vector<bound_minimal_symbol> m_minimal_symbols;
2230 #endif /* !defined(SYMTAB_H) */