1 /* Symbol table definitions for GDB.
3 Copyright (C) 1986-2019 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)
26 #include "gdbsupport/gdb_vecs.h"
28 #include "gdb_obstack.h"
29 #include "gdb_regex.h"
30 #include "gdbsupport/enum-flags.h"
31 #include "gdbsupport/function-view.h"
32 #include "gdbsupport/gdb_optional.h"
33 #include "gdbsupport/gdb_string_view.h"
34 #include "gdbsupport/next-iterator.h"
35 #include "completer.h"
37 /* Opaque declarations. */
51 struct cmd_list_element
;
53 struct lookup_name_info
;
55 /* How to match a lookup name against a symbol search name. */
56 enum class symbol_name_match_type
58 /* Wild matching. Matches unqualified symbol names in all
59 namespace/module/packages, etc. */
62 /* Full matching. The lookup name indicates a fully-qualified name,
63 and only matches symbol search names in the specified
64 namespace/module/package. */
67 /* Search name matching. This is like FULL, but the search name did
68 not come from the user; instead it is already a search name
69 retrieved from a SYMBOL_SEARCH_NAME/MSYMBOL_SEARCH_NAME call.
70 For Ada, this avoids re-encoding an already-encoded search name
71 (which would potentially incorrectly lowercase letters in the
72 linkage/search name that should remain uppercase). For C++, it
73 avoids trying to demangle a name we already know is
77 /* Expression matching. The same as FULL matching in most
78 languages. The same as WILD matching in Ada. */
82 /* Hash the given symbol search name according to LANGUAGE's
84 extern unsigned int search_name_hash (enum language language
,
85 const char *search_name
);
87 /* Ada-specific bits of a lookup_name_info object. This is lazily
88 constructed on demand. */
90 class ada_lookup_name_info final
94 explicit ada_lookup_name_info (const lookup_name_info
&lookup_name
);
96 /* Compare SYMBOL_SEARCH_NAME with our lookup name, using MATCH_TYPE
97 as name match type. Returns true if there's a match, false
98 otherwise. If non-NULL, store the matching results in MATCH. */
99 bool matches (const char *symbol_search_name
,
100 symbol_name_match_type match_type
,
101 completion_match_result
*comp_match_res
) const;
103 /* The Ada-encoded lookup name. */
104 const std::string
&lookup_name () const
105 { return m_encoded_name
; }
107 /* Return true if we're supposed to be doing a wild match look
109 bool wild_match_p () const
110 { return m_wild_match_p
; }
112 /* Return true if we're looking up a name inside package
114 bool standard_p () const
115 { return m_standard_p
; }
117 /* Return true if doing a verbatim match. */
118 bool verbatim_p () const
119 { return m_verbatim_p
; }
122 /* The Ada-encoded lookup name. */
123 std::string m_encoded_name
;
125 /* Whether the user-provided lookup name was Ada encoded. If so,
126 then return encoded names in the 'matches' method's 'completion
127 match result' output. */
128 bool m_encoded_p
: 1;
130 /* True if really doing wild matching. Even if the user requests
131 wild matching, some cases require full matching. */
132 bool m_wild_match_p
: 1;
134 /* True if doing a verbatim match. This is true if the decoded
135 version of the symbol name is wrapped in '<'/'>'. This is an
136 escape hatch users can use to look up symbols the Ada encoding
137 does not understand. */
138 bool m_verbatim_p
: 1;
140 /* True if the user specified a symbol name that is inside package
141 Standard. Symbol names inside package Standard are handled
142 specially. We always do a non-wild match of the symbol name
143 without the "standard__" prefix, and only search static and
144 global symbols. This was primarily introduced in order to allow
145 the user to specifically access the standard exceptions using,
146 for instance, Standard.Constraint_Error when Constraint_Error is
147 ambiguous (due to the user defining its own Constraint_Error
148 entity inside its program). */
149 bool m_standard_p
: 1;
152 /* Language-specific bits of a lookup_name_info object, for languages
153 that do name searching using demangled names (C++/D/Go). This is
154 lazily constructed on demand. */
156 struct demangle_for_lookup_info final
159 demangle_for_lookup_info (const lookup_name_info
&lookup_name
,
162 /* The demangled lookup name. */
163 const std::string
&lookup_name () const
164 { return m_demangled_name
; }
167 /* The demangled lookup name. */
168 std::string m_demangled_name
;
171 /* Object that aggregates all information related to a symbol lookup
172 name. I.e., the name that is matched against the symbol's search
173 name. Caches per-language information so that it doesn't require
174 recomputing it for every symbol comparison, like for example the
175 Ada encoded name and the symbol's name hash for a given language.
176 The object is conceptually immutable once constructed, and thus has
177 no setters. This is to prevent some code path from tweaking some
178 property of the lookup name for some local reason and accidentally
179 altering the results of any continuing search(es).
180 lookup_name_info objects are generally passed around as a const
181 reference to reinforce that. (They're not passed around by value
182 because they're not small.) */
183 class lookup_name_info final
186 /* Create a new object. */
187 lookup_name_info (std::string name
,
188 symbol_name_match_type match_type
,
189 bool completion_mode
= false,
190 bool ignore_parameters
= false)
191 : m_match_type (match_type
),
192 m_completion_mode (completion_mode
),
193 m_ignore_parameters (ignore_parameters
),
194 m_name (std::move (name
))
197 /* Getters. See description of each corresponding field. */
198 symbol_name_match_type
match_type () const { return m_match_type
; }
199 bool completion_mode () const { return m_completion_mode
; }
200 const std::string
&name () const { return m_name
; }
201 const bool ignore_parameters () const { return m_ignore_parameters
; }
203 /* Return a version of this lookup name that is usable with
204 comparisons against symbols have no parameter info, such as
205 psymbols and GDB index symbols. */
206 lookup_name_info
make_ignore_params () const
208 return lookup_name_info (m_name
, m_match_type
, m_completion_mode
,
209 true /* ignore params */);
212 /* Get the search name hash for searches in language LANG. */
213 unsigned int search_name_hash (language lang
) const
215 /* Only compute each language's hash once. */
216 if (!m_demangled_hashes_p
[lang
])
218 m_demangled_hashes
[lang
]
219 = ::search_name_hash (lang
, language_lookup_name (lang
).c_str ());
220 m_demangled_hashes_p
[lang
] = true;
222 return m_demangled_hashes
[lang
];
225 /* Get the search name for searches in language LANG. */
226 const std::string
&language_lookup_name (language lang
) const
231 return ada ().lookup_name ();
233 return cplus ().lookup_name ();
235 return d ().lookup_name ();
237 return go ().lookup_name ();
243 /* Get the Ada-specific lookup info. */
244 const ada_lookup_name_info
&ada () const
250 /* Get the C++-specific lookup info. */
251 const demangle_for_lookup_info
&cplus () const
253 maybe_init (m_cplus
, language_cplus
);
257 /* Get the D-specific lookup info. */
258 const demangle_for_lookup_info
&d () const
260 maybe_init (m_d
, language_d
);
264 /* Get the Go-specific lookup info. */
265 const demangle_for_lookup_info
&go () const
267 maybe_init (m_go
, language_go
);
271 /* Get a reference to a lookup_name_info object that matches any
273 static const lookup_name_info
&match_any ();
276 /* Initialize FIELD, if not initialized yet. */
277 template<typename Field
, typename
... Args
>
278 void maybe_init (Field
&field
, Args
&&... args
) const
281 field
.emplace (*this, std::forward
<Args
> (args
)...);
284 /* The lookup info as passed to the ctor. */
285 symbol_name_match_type m_match_type
;
286 bool m_completion_mode
;
287 bool m_ignore_parameters
;
290 /* Language-specific info. These fields are filled lazily the first
291 time a lookup is done in the corresponding language. They're
292 mutable because lookup_name_info objects are typically passed
293 around by const reference (see intro), and they're conceptually
294 "cache" that can always be reconstructed from the non-mutable
296 mutable gdb::optional
<ada_lookup_name_info
> m_ada
;
297 mutable gdb::optional
<demangle_for_lookup_info
> m_cplus
;
298 mutable gdb::optional
<demangle_for_lookup_info
> m_d
;
299 mutable gdb::optional
<demangle_for_lookup_info
> m_go
;
301 /* The demangled hashes. Stored in an array with one entry for each
302 possible language. The second array records whether we've
303 already computed the each language's hash. (These are separate
304 arrays instead of a single array of optional<unsigned> to avoid
305 alignment padding). */
306 mutable std::array
<unsigned int, nr_languages
> m_demangled_hashes
;
307 mutable std::array
<bool, nr_languages
> m_demangled_hashes_p
{};
310 /* Comparison function for completion symbol lookup.
312 Returns true if the symbol name matches against LOOKUP_NAME.
314 SYMBOL_SEARCH_NAME should be a symbol's "search" name.
316 On success and if non-NULL, COMP_MATCH_RES->match is set to point
317 to the symbol name as should be presented to the user as a
318 completion match list element. In most languages, this is the same
319 as the symbol's search name, but in some, like Ada, the display
320 name is dynamically computed within the comparison routine.
322 Also, on success and if non-NULL, COMP_MATCH_RES->match_for_lcd
323 points the part of SYMBOL_SEARCH_NAME that was considered to match
324 LOOKUP_NAME. E.g., in C++, in linespec/wild mode, if the symbol is
325 "foo::function()" and LOOKUP_NAME is "function(", MATCH_FOR_LCD
326 points to "function()" inside SYMBOL_SEARCH_NAME. */
327 typedef bool (symbol_name_matcher_ftype
)
328 (const char *symbol_search_name
,
329 const lookup_name_info
&lookup_name
,
330 completion_match_result
*comp_match_res
);
332 /* Some of the structures in this file are space critical.
333 The space-critical structures are:
335 struct general_symbol_info
337 struct partial_symbol
339 These structures are laid out to encourage good packing.
340 They use ENUM_BITFIELD and short int fields, and they order the
341 structure members so that fields less than a word are next
342 to each other so they can be packed together. */
344 /* Rearranged: used ENUM_BITFIELD and rearranged field order in
345 all the space critical structures (plus struct minimal_symbol).
346 Memory usage dropped from 99360768 bytes to 90001408 bytes.
347 I measured this with before-and-after tests of
348 "HEAD-old-gdb -readnow HEAD-old-gdb" and
349 "HEAD-new-gdb -readnow HEAD-old-gdb" on native i686-pc-linux-gnu,
350 red hat linux 8, with LD_LIBRARY_PATH=/usr/lib/debug,
351 typing "maint space 1" at the first command prompt.
353 Here is another measurement (from andrew c):
354 # no /usr/lib/debug, just plain glibc, like a normal user
356 (gdb) break internal_error
358 (gdb) maint internal-error
362 gdb gdb_6_0_branch 2003-08-19 space used: 8896512
363 gdb HEAD 2003-08-19 space used: 8904704
364 gdb HEAD 2003-08-21 space used: 8396800 (+symtab.h)
365 gdb HEAD 2003-08-21 space used: 8265728 (+gdbtypes.h)
367 The third line shows the savings from the optimizations in symtab.h.
368 The fourth line shows the savings from the optimizations in
369 gdbtypes.h. Both optimizations are in gdb HEAD now.
371 --chastain 2003-08-21 */
373 /* Define a structure for the information that is common to all symbol types,
374 including minimal symbols, partial symbols, and full symbols. In a
375 multilanguage environment, some language specific information may need to
376 be recorded along with each symbol. */
378 /* This structure is space critical. See space comments at the top. */
380 struct general_symbol_info
382 /* Name of the symbol. This is a required field. Storage for the
383 name is allocated on the objfile_obstack for the associated
384 objfile. For languages like C++ that make a distinction between
385 the mangled name and demangled name, this is the mangled
390 /* Value of the symbol. Which member of this union to use, and what
391 it means, depends on what kind of symbol this is and its
392 SYMBOL_CLASS. See comments there for more details. All of these
393 are in host byte order (though what they point to might be in
394 target byte order, e.g. LOC_CONST_BYTES). */
400 const struct block
*block
;
402 const gdb_byte
*bytes
;
406 /* A common block. Used with LOC_COMMON_BLOCK. */
408 const struct common_block
*common_block
;
410 /* For opaque typedef struct chain. */
412 struct symbol
*chain
;
416 /* Since one and only one language can apply, wrap the language specific
417 information inside a union. */
421 /* A pointer to an obstack that can be used for storage associated
422 with this symbol. This is only used by Ada, and only when the
423 'ada_mangled' field is zero. */
424 struct obstack
*obstack
;
426 /* This is used by languages which wish to store a demangled name.
427 currently used by Ada, C++, and Objective C. */
428 const char *demangled_name
;
432 /* Record the source code language that applies to this symbol.
433 This is used to select one of the fields from the language specific
436 ENUM_BITFIELD(language
) language
: LANGUAGE_BITS
;
438 /* This is only used by Ada. If set, then the 'demangled_name' field
439 of language_specific is valid. Otherwise, the 'obstack' field is
441 unsigned int ada_mangled
: 1;
443 /* Which section is this symbol in? This is an index into
444 section_offsets for this objfile. Negative means that the symbol
445 does not get relocated relative to a section. */
450 /* This struct is size-critical (see comment at the top), so this assert
451 makes sure the size doesn't change accidentally. Be careful when
452 purposely increasing the size. */
453 gdb_static_assert ((sizeof (void *) == 8 && sizeof (general_symbol_info
) == 32)
454 || (sizeof (void *) == 4
455 && sizeof (general_symbol_info
) == 20));
457 extern void symbol_set_demangled_name (struct general_symbol_info
*,
461 extern const char *symbol_get_demangled_name
462 (const struct general_symbol_info
*);
464 extern CORE_ADDR
symbol_overlayed_address (CORE_ADDR
, struct obj_section
*);
466 /* Return the address of SYM. The MAYBE_COPIED flag must be set on
467 SYM. If SYM appears in the main program's minimal symbols, then
468 that minsym's address is returned; otherwise, SYM's address is
469 returned. This should generally only be used via the
470 SYMBOL_VALUE_ADDRESS macro. */
472 extern CORE_ADDR
get_symbol_address (const struct symbol
*sym
);
474 /* Note that these macros only work with symbol, not partial_symbol. */
476 #define SYMBOL_VALUE(symbol) (symbol)->value.ivalue
477 #define SYMBOL_VALUE_ADDRESS(symbol) \
478 (((symbol)->maybe_copied) ? get_symbol_address (symbol) \
479 : ((symbol)->value.address))
480 #define SET_SYMBOL_VALUE_ADDRESS(symbol, new_value) \
481 ((symbol)->value.address = (new_value))
482 #define SYMBOL_VALUE_BYTES(symbol) (symbol)->value.bytes
483 #define SYMBOL_VALUE_COMMON_BLOCK(symbol) (symbol)->value.common_block
484 #define SYMBOL_BLOCK_VALUE(symbol) (symbol)->value.block
485 #define SYMBOL_VALUE_CHAIN(symbol) (symbol)->value.chain
486 #define SYMBOL_LANGUAGE(symbol) (symbol)->language
487 #define SYMBOL_SECTION(symbol) (symbol)->section
488 #define SYMBOL_OBJ_SECTION(objfile, symbol) \
489 (((symbol)->section >= 0) \
490 ? (&(((objfile)->sections)[(symbol)->section])) \
493 /* Initializes the language dependent portion of a symbol
494 depending upon the language for the symbol. */
495 #define SYMBOL_SET_LANGUAGE(symbol,language,obstack) \
496 (symbol_set_language ((symbol), (language), (obstack)))
497 extern void symbol_set_language (struct general_symbol_info
*symbol
,
498 enum language language
,
499 struct obstack
*obstack
);
501 /* Set just the linkage name of a symbol; do not try to demangle
502 it. Used for constructs which do not have a mangled name,
503 e.g. struct tags. Unlike SYMBOL_SET_NAMES, linkage_name must
504 be terminated and either already on the objfile's obstack or
505 permanently allocated. */
506 #define SYMBOL_SET_LINKAGE_NAME(symbol,linkage_name) \
507 (symbol)->name = (linkage_name)
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 #define SYMBOL_SET_NAMES(symbol,linkage_name,copy_name,objfile) \
513 symbol_set_names ((symbol), linkage_name, copy_name, \
515 extern void symbol_set_names (struct general_symbol_info
*symbol
,
516 gdb::string_view linkage_name
, bool copy_name
,
517 struct objfile_per_bfd_storage
*per_bfd
);
519 /* Now come lots of name accessor macros. Short version as to when to
520 use which: Use SYMBOL_NATURAL_NAME to refer to the name of the
521 symbol in the original source code. Use SYMBOL_LINKAGE_NAME if you
522 want to know what the linker thinks the symbol's name is. Use
523 SYMBOL_PRINT_NAME for output. Use SYMBOL_DEMANGLED_NAME if you
524 specifically need to know whether SYMBOL_NATURAL_NAME and
525 SYMBOL_LINKAGE_NAME are different. */
527 /* Return SYMBOL's "natural" name, i.e. the name that it was called in
528 the original source code. In languages like C++ where symbols may
529 be mangled for ease of manipulation by the linker, this is the
532 #define SYMBOL_NATURAL_NAME(symbol) \
533 (symbol_natural_name ((symbol)))
534 extern const char *symbol_natural_name
535 (const struct general_symbol_info
*symbol
);
537 /* Return SYMBOL's name from the point of view of the linker. In
538 languages like C++ where symbols may be mangled for ease of
539 manipulation by the linker, this is the mangled name; otherwise,
540 it's the same as SYMBOL_NATURAL_NAME. */
542 #define SYMBOL_LINKAGE_NAME(symbol) (symbol)->name
544 /* Return the demangled name for a symbol based on the language for
545 that symbol. If no demangled name exists, return NULL. */
546 #define SYMBOL_DEMANGLED_NAME(symbol) \
547 (symbol_demangled_name ((symbol)))
548 extern const char *symbol_demangled_name
549 (const struct general_symbol_info
*symbol
);
551 /* Macro that returns a version of the name of a symbol that is
552 suitable for output. In C++ this is the "demangled" form of the
553 name if demangle is on and the "mangled" form of the name if
554 demangle is off. In other languages this is just the symbol name.
555 The result should never be NULL. Don't use this for internal
556 purposes (e.g. storing in a hashtable): it's only suitable for output.
558 N.B. symbol may be anything inheriting from general_symbol_info,
559 e.g., struct symbol or struct minimal_symbol. */
561 #define SYMBOL_PRINT_NAME(symbol) \
562 (demangle ? SYMBOL_NATURAL_NAME (symbol) : SYMBOL_LINKAGE_NAME (symbol))
563 extern bool demangle
;
565 /* Macro that returns the name to be used when sorting and searching symbols.
566 In C++, we search for the demangled form of a name,
567 and so sort symbols accordingly. In Ada, however, we search by mangled
568 name. If there is no distinct demangled name, then SYMBOL_SEARCH_NAME
569 returns the same value (same pointer) as SYMBOL_LINKAGE_NAME. */
570 #define SYMBOL_SEARCH_NAME(symbol) \
571 (symbol_search_name (symbol))
572 extern const char *symbol_search_name (const struct general_symbol_info
*ginfo
);
574 /* Return true if NAME matches the "search" name of SYMBOL, according
575 to the symbol's language. */
576 #define SYMBOL_MATCHES_SEARCH_NAME(symbol, name) \
577 symbol_matches_search_name ((symbol), (name))
579 /* Helper for SYMBOL_MATCHES_SEARCH_NAME that works with both symbols
581 extern bool symbol_matches_search_name
582 (const struct general_symbol_info
*gsymbol
,
583 const lookup_name_info
&name
);
585 /* Compute the hash of the given symbol search name of a symbol of
586 language LANGUAGE. */
587 extern unsigned int search_name_hash (enum language language
,
588 const char *search_name
);
590 /* Classification types for a minimal symbol. These should be taken as
591 "advisory only", since if gdb can't easily figure out a
592 classification it simply selects mst_unknown. It may also have to
593 guess when it can't figure out which is a better match between two
594 types (mst_data versus mst_bss) for example. Since the minimal
595 symbol info is sometimes derived from the BFD library's view of a
596 file, we need to live with what information bfd supplies. */
598 enum minimal_symbol_type
600 mst_unknown
= 0, /* Unknown type, the default */
601 mst_text
, /* Generally executable instructions */
603 /* A GNU ifunc symbol, in the .text section. GDB uses to know
604 whether the user is setting a breakpoint on a GNU ifunc function,
605 and thus GDB needs to actually set the breakpoint on the target
606 function. It is also used to know whether the program stepped
607 into an ifunc resolver -- the resolver may get a separate
608 symbol/alias under a different name, but it'll have the same
609 address as the ifunc symbol. */
610 mst_text_gnu_ifunc
, /* Executable code returning address
611 of executable code */
613 /* A GNU ifunc function descriptor symbol, in a data section
614 (typically ".opd"). Seen on architectures that use function
615 descriptors, like PPC64/ELFv1. In this case, this symbol's value
616 is the address of the descriptor. There'll be a corresponding
617 mst_text_gnu_ifunc synthetic symbol for the text/entry
619 mst_data_gnu_ifunc
, /* Executable code returning address
620 of executable code */
622 mst_slot_got_plt
, /* GOT entries for .plt sections */
623 mst_data
, /* Generally initialized data */
624 mst_bss
, /* Generally uninitialized data */
625 mst_abs
, /* Generally absolute (nonrelocatable) */
626 /* GDB uses mst_solib_trampoline for the start address of a shared
627 library trampoline entry. Breakpoints for shared library functions
628 are put there if the shared library is not yet loaded.
629 After the shared library is loaded, lookup_minimal_symbol will
630 prefer the minimal symbol from the shared library (usually
631 a mst_text symbol) over the mst_solib_trampoline symbol, and the
632 breakpoints will be moved to their true address in the shared
633 library via breakpoint_re_set. */
634 mst_solib_trampoline
, /* Shared library trampoline code */
635 /* For the mst_file* types, the names are only guaranteed to be unique
636 within a given .o file. */
637 mst_file_text
, /* Static version of mst_text */
638 mst_file_data
, /* Static version of mst_data */
639 mst_file_bss
, /* Static version of mst_bss */
643 /* The number of enum minimal_symbol_type values, with some padding for
644 reasonable growth. */
645 #define MINSYM_TYPE_BITS 4
646 gdb_static_assert (nr_minsym_types
<= (1 << MINSYM_TYPE_BITS
));
648 /* Define a simple structure used to hold some very basic information about
649 all defined global symbols (text, data, bss, abs, etc). The only required
650 information is the general_symbol_info.
652 In many cases, even if a file was compiled with no special options for
653 debugging at all, as long as was not stripped it will contain sufficient
654 information to build a useful minimal symbol table using this structure.
655 Even when a file contains enough debugging information to build a full
656 symbol table, these minimal symbols are still useful for quickly mapping
657 between names and addresses, and vice versa. They are also sometimes
658 used to figure out what full symbol table entries need to be read in. */
660 struct minimal_symbol
: public general_symbol_info
662 /* Size of this symbol. dbx_end_psymtab in dbxread.c uses this
663 information to calculate the end of the partial symtab based on the
664 address of the last symbol plus the size of the last symbol. */
668 /* Which source file is this symbol in? Only relevant for mst_file_*. */
669 const char *filename
;
671 /* Classification type for this minimal symbol. */
673 ENUM_BITFIELD(minimal_symbol_type
) type
: MINSYM_TYPE_BITS
;
675 /* Non-zero if this symbol was created by gdb.
676 Such symbols do not appear in the output of "info var|fun". */
677 unsigned int created_by_gdb
: 1;
679 /* Two flag bits provided for the use of the target. */
680 unsigned int target_flag_1
: 1;
681 unsigned int target_flag_2
: 1;
683 /* Nonzero iff the size of the minimal symbol has been set.
684 Symbol size information can sometimes not be determined, because
685 the object file format may not carry that piece of information. */
686 unsigned int has_size
: 1;
688 /* For data symbols only, if this is set, then the symbol might be
689 subject to copy relocation. In this case, a minimal symbol
690 matching the symbol's linkage name is first looked for in the
691 main objfile. If found, then that address is used; otherwise the
692 address in this symbol is used. */
694 unsigned maybe_copied
: 1;
696 /* Minimal symbols with the same hash key are kept on a linked
697 list. This is the link. */
699 struct minimal_symbol
*hash_next
;
701 /* Minimal symbols are stored in two different hash tables. This is
702 the `next' pointer for the demangled hash table. */
704 struct minimal_symbol
*demangled_hash_next
;
706 /* True if this symbol is of some data type. */
708 bool data_p () const;
710 /* True if MSYMBOL is of some text type. */
712 bool text_p () const;
715 /* Return the address of MINSYM, which comes from OBJF. The
716 MAYBE_COPIED flag must be set on MINSYM. If MINSYM appears in the
717 main program's minimal symbols, then that minsym's address is
718 returned; otherwise, MINSYM's address is returned. This should
719 generally only be used via the MSYMBOL_VALUE_ADDRESS macro. */
721 extern CORE_ADDR
get_msymbol_address (struct objfile
*objf
,
722 const struct minimal_symbol
*minsym
);
724 #define MSYMBOL_TARGET_FLAG_1(msymbol) (msymbol)->target_flag_1
725 #define MSYMBOL_TARGET_FLAG_2(msymbol) (msymbol)->target_flag_2
726 #define MSYMBOL_SIZE(msymbol) ((msymbol)->size + 0)
727 #define SET_MSYMBOL_SIZE(msymbol, sz) \
730 (msymbol)->size = sz; \
731 (msymbol)->has_size = 1; \
733 #define MSYMBOL_HAS_SIZE(msymbol) ((msymbol)->has_size + 0)
734 #define MSYMBOL_TYPE(msymbol) (msymbol)->type
736 #define MSYMBOL_VALUE(symbol) (symbol)->value.ivalue
737 /* The unrelocated address of the minimal symbol. */
738 #define MSYMBOL_VALUE_RAW_ADDRESS(symbol) ((symbol)->value.address + 0)
739 /* The relocated address of the minimal symbol, using the section
740 offsets from OBJFILE. */
741 #define MSYMBOL_VALUE_ADDRESS(objfile, symbol) \
742 (((symbol)->maybe_copied) ? get_msymbol_address (objfile, symbol) \
743 : ((symbol)->value.address \
744 + ANOFFSET ((objfile)->section_offsets, ((symbol)->section))))
745 /* For a bound minsym, we can easily compute the address directly. */
746 #define BMSYMBOL_VALUE_ADDRESS(symbol) \
747 MSYMBOL_VALUE_ADDRESS ((symbol).objfile, (symbol).minsym)
748 #define SET_MSYMBOL_VALUE_ADDRESS(symbol, new_value) \
749 ((symbol)->value.address = (new_value))
750 #define MSYMBOL_VALUE_BYTES(symbol) (symbol)->value.bytes
751 #define MSYMBOL_BLOCK_VALUE(symbol) (symbol)->value.block
752 #define MSYMBOL_VALUE_CHAIN(symbol) (symbol)->value.chain
753 #define MSYMBOL_LANGUAGE(symbol) (symbol)->language
754 #define MSYMBOL_SECTION(symbol) (symbol)->section
755 #define MSYMBOL_OBJ_SECTION(objfile, symbol) \
756 (((symbol)->section >= 0) \
757 ? (&(((objfile)->sections)[(symbol)->section])) \
760 #define MSYMBOL_NATURAL_NAME(symbol) \
761 (symbol_natural_name (symbol))
762 #define MSYMBOL_LINKAGE_NAME(symbol) (symbol)->name
763 #define MSYMBOL_PRINT_NAME(symbol) \
764 (demangle ? MSYMBOL_NATURAL_NAME (symbol) : MSYMBOL_LINKAGE_NAME (symbol))
765 #define MSYMBOL_DEMANGLED_NAME(symbol) \
766 (symbol_demangled_name (symbol))
767 #define MSYMBOL_SEARCH_NAME(symbol) \
768 (symbol_search_name (symbol))
774 /* Represent one symbol name; a variable, constant, function or typedef. */
776 /* Different name domains for symbols. Looking up a symbol specifies a
777 domain and ignores symbol definitions in other name domains. */
779 typedef enum domain_enum_tag
781 /* UNDEF_DOMAIN is used when a domain has not been discovered or
782 none of the following apply. This usually indicates an error either
783 in the symbol information or in gdb's handling of symbols. */
787 /* VAR_DOMAIN is the usual domain. In C, this contains variables,
788 function names, typedef names and enum type values. */
792 /* STRUCT_DOMAIN is used in C to hold struct, union and enum type names.
793 Thus, if `struct foo' is used in a C program, it produces a symbol named
794 `foo' in the STRUCT_DOMAIN. */
798 /* MODULE_DOMAIN is used in Fortran to hold module type names. */
802 /* LABEL_DOMAIN may be used for names of labels (for gotos). */
806 /* Fortran common blocks. Their naming must be separate from VAR_DOMAIN.
807 They also always use LOC_COMMON_BLOCK. */
810 /* This must remain last. */
814 /* The number of bits in a symbol used to represent the domain. */
816 #define SYMBOL_DOMAIN_BITS 3
817 gdb_static_assert (NR_DOMAINS
<= (1 << SYMBOL_DOMAIN_BITS
));
819 extern const char *domain_name (domain_enum
);
821 /* Searching domains, used for `search_symbols'. Element numbers are
822 hardcoded in GDB, check all enum uses before changing it. */
826 /* Everything in VAR_DOMAIN minus FUNCTIONS_DOMAIN and
828 VARIABLES_DOMAIN
= 0,
830 /* All functions -- for some reason not methods, though. */
831 FUNCTIONS_DOMAIN
= 1,
833 /* All defined types */
843 extern const char *search_domain_name (enum search_domain
);
845 /* An address-class says where to find the value of a symbol. */
849 /* Not used; catches errors. */
853 /* Value is constant int SYMBOL_VALUE, host byteorder. */
857 /* Value is at fixed address SYMBOL_VALUE_ADDRESS. */
861 /* Value is in register. SYMBOL_VALUE is the register number
862 in the original debug format. SYMBOL_REGISTER_OPS holds a
863 function that can be called to transform this into the
864 actual register number this represents in a specific target
865 architecture (gdbarch).
867 For some symbol formats (stabs, for some compilers at least),
868 the compiler generates two symbols, an argument and a register.
869 In some cases we combine them to a single LOC_REGISTER in symbol
870 reading, but currently not for all cases (e.g. it's passed on the
871 stack and then loaded into a register). */
875 /* It's an argument; the value is at SYMBOL_VALUE offset in arglist. */
879 /* Value address is at SYMBOL_VALUE offset in arglist. */
883 /* Value is in specified register. Just like LOC_REGISTER except the
884 register holds the address of the argument instead of the argument
885 itself. This is currently used for the passing of structs and unions
886 on sparc and hppa. It is also used for call by reference where the
887 address is in a register, at least by mipsread.c. */
891 /* Value is a local variable at SYMBOL_VALUE offset in stack frame. */
895 /* Value not used; definition in SYMBOL_TYPE. Symbols in the domain
896 STRUCT_DOMAIN all have this class. */
900 /* Value is address SYMBOL_VALUE_ADDRESS in the code. */
904 /* In a symbol table, value is SYMBOL_BLOCK_VALUE of a `struct block'.
905 In a partial symbol table, SYMBOL_VALUE_ADDRESS is the start address
906 of the block. Function names have this class. */
910 /* Value is a constant byte-sequence pointed to by SYMBOL_VALUE_BYTES, in
911 target byte order. */
915 /* Value is at fixed address, but the address of the variable has
916 to be determined from the minimal symbol table whenever the
917 variable is referenced.
918 This happens if debugging information for a global symbol is
919 emitted and the corresponding minimal symbol is defined
920 in another object file or runtime common storage.
921 The linker might even remove the minimal symbol if the global
922 symbol is never referenced, in which case the symbol remains
925 GDB would normally find the symbol in the minimal symbol table if it will
926 not find it in the full symbol table. But a reference to an external
927 symbol in a local block shadowing other definition requires full symbol
928 without possibly having its address available for LOC_STATIC. Testcase
929 is provided as `gdb.dwarf2/dw2-unresolved.exp'.
931 This is also used for thread local storage (TLS) variables. In this case,
932 the address of the TLS variable must be determined when the variable is
933 referenced, from the MSYMBOL_VALUE_RAW_ADDRESS, which is the offset
934 of the TLS variable in the thread local storage of the shared
939 /* The variable does not actually exist in the program.
940 The value is ignored. */
944 /* The variable's address is computed by a set of location
945 functions (see "struct symbol_computed_ops" below). */
948 /* The variable uses general_symbol_info->value->common_block field.
949 It also always uses COMMON_BLOCK_DOMAIN. */
952 /* Not used, just notes the boundary of the enum. */
956 /* The number of bits needed for values in enum address_class, with some
957 padding for reasonable growth, and room for run-time registered address
958 classes. See symtab.c:MAX_SYMBOL_IMPLS.
959 This is a #define so that we can have a assertion elsewhere to
960 verify that we have reserved enough space for synthetic address
962 #define SYMBOL_ACLASS_BITS 5
963 gdb_static_assert (LOC_FINAL_VALUE
<= (1 << SYMBOL_ACLASS_BITS
));
965 /* The methods needed to implement LOC_COMPUTED. These methods can
966 use the symbol's .aux_value for additional per-symbol information.
968 At present this is only used to implement location expressions. */
970 struct symbol_computed_ops
973 /* Return the value of the variable SYMBOL, relative to the stack
974 frame FRAME. If the variable has been optimized out, return
977 Iff `read_needs_frame (SYMBOL)' is not SYMBOL_NEEDS_FRAME, then
978 FRAME may be zero. */
980 struct value
*(*read_variable
) (struct symbol
* symbol
,
981 struct frame_info
* frame
);
983 /* Read variable SYMBOL like read_variable at (callee) FRAME's function
984 entry. SYMBOL should be a function parameter, otherwise
985 NO_ENTRY_VALUE_ERROR will be thrown. */
986 struct value
*(*read_variable_at_entry
) (struct symbol
*symbol
,
987 struct frame_info
*frame
);
989 /* Find the "symbol_needs_kind" value for the given symbol. This
990 value determines whether reading the symbol needs memory (e.g., a
991 global variable), just registers (a thread-local), or a frame (a
993 enum symbol_needs_kind (*get_symbol_read_needs
) (struct symbol
* symbol
);
995 /* Write to STREAM a natural-language description of the location of
996 SYMBOL, in the context of ADDR. */
997 void (*describe_location
) (struct symbol
* symbol
, CORE_ADDR addr
,
998 struct ui_file
* stream
);
1000 /* Non-zero if this symbol's address computation is dependent on PC. */
1001 unsigned char location_has_loclist
;
1003 /* Tracepoint support. Append bytecodes to the tracepoint agent
1004 expression AX that push the address of the object SYMBOL. Set
1005 VALUE appropriately. Note --- for objects in registers, this
1006 needn't emit any code; as long as it sets VALUE properly, then
1007 the caller will generate the right code in the process of
1008 treating this as an lvalue or rvalue. */
1010 void (*tracepoint_var_ref
) (struct symbol
*symbol
, struct agent_expr
*ax
,
1011 struct axs_value
*value
);
1013 /* Generate C code to compute the location of SYMBOL. The C code is
1014 emitted to STREAM. GDBARCH is the current architecture and PC is
1015 the PC at which SYMBOL's location should be evaluated.
1016 REGISTERS_USED is a vector indexed by register number; the
1017 generator function should set an element in this vector if the
1018 corresponding register is needed by the location computation.
1019 The generated C code must assign the location to a local
1020 variable; this variable's name is RESULT_NAME. */
1022 void (*generate_c_location
) (struct symbol
*symbol
, string_file
*stream
,
1023 struct gdbarch
*gdbarch
,
1024 unsigned char *registers_used
,
1025 CORE_ADDR pc
, const char *result_name
);
1029 /* The methods needed to implement LOC_BLOCK for inferior functions.
1030 These methods can use the symbol's .aux_value for additional
1031 per-symbol information. */
1033 struct symbol_block_ops
1035 /* Fill in *START and *LENGTH with DWARF block data of function
1036 FRAMEFUNC valid for inferior context address PC. Set *LENGTH to
1037 zero if such location is not valid for PC; *START is left
1038 uninitialized in such case. */
1039 void (*find_frame_base_location
) (struct symbol
*framefunc
, CORE_ADDR pc
,
1040 const gdb_byte
**start
, size_t *length
);
1042 /* Return the frame base address. FRAME is the frame for which we want to
1043 compute the base address while FRAMEFUNC is the symbol for the
1044 corresponding function. Return 0 on failure (FRAMEFUNC may not hold the
1045 information we need).
1047 This method is designed to work with static links (nested functions
1048 handling). Static links are function properties whose evaluation returns
1049 the frame base address for the enclosing frame. However, there are
1050 multiple definitions for "frame base": the content of the frame base
1051 register, the CFA as defined by DWARF unwinding information, ...
1053 So this specific method is supposed to compute the frame base address such
1054 as for nested functions, the static link computes the same address. For
1055 instance, considering DWARF debugging information, the static link is
1056 computed with DW_AT_static_link and this method must be used to compute
1057 the corresponding DW_AT_frame_base attribute. */
1058 CORE_ADDR (*get_frame_base
) (struct symbol
*framefunc
,
1059 struct frame_info
*frame
);
1062 /* Functions used with LOC_REGISTER and LOC_REGPARM_ADDR. */
1064 struct symbol_register_ops
1066 int (*register_number
) (struct symbol
*symbol
, struct gdbarch
*gdbarch
);
1069 /* Objects of this type are used to find the address class and the
1070 various computed ops vectors of a symbol. */
1074 enum address_class aclass
;
1076 /* Used with LOC_COMPUTED. */
1077 const struct symbol_computed_ops
*ops_computed
;
1079 /* Used with LOC_BLOCK. */
1080 const struct symbol_block_ops
*ops_block
;
1082 /* Used with LOC_REGISTER and LOC_REGPARM_ADDR. */
1083 const struct symbol_register_ops
*ops_register
;
1086 /* struct symbol has some subclasses. This enum is used to
1087 differentiate between them. */
1089 enum symbol_subclass_kind
1091 /* Plain struct symbol. */
1094 /* struct template_symbol. */
1097 /* struct rust_vtable_symbol. */
1101 /* This structure is space critical. See space comments at the top. */
1103 struct symbol
: public general_symbol_info
, public allocate_on_obstack
1106 /* Class-initialization of bitfields is only allowed in C++20. */
1107 : domain (UNDEF_DOMAIN
),
1109 is_objfile_owned (0),
1113 subclass (SYMBOL_NONE
)
1115 /* We can't use an initializer list for members of a base class, and
1116 general_symbol_info needs to stay a POD type. */
1119 language_specific
.obstack
= nullptr;
1120 language
= language_unknown
;
1125 /* Data type of value */
1127 struct type
*type
= nullptr;
1129 /* The owner of this symbol.
1130 Which one to use is defined by symbol.is_objfile_owned. */
1134 /* The symbol table containing this symbol. This is the file associated
1135 with LINE. It can be NULL during symbols read-in but it is never NULL
1136 during normal operation. */
1137 struct symtab
*symtab
= nullptr;
1139 /* For types defined by the architecture. */
1140 struct gdbarch
*arch
;
1145 ENUM_BITFIELD(domain_enum_tag
) domain
: SYMBOL_DOMAIN_BITS
;
1147 /* Address class. This holds an index into the 'symbol_impls'
1148 table. The actual enum address_class value is stored there,
1149 alongside any per-class ops vectors. */
1151 unsigned int aclass_index
: SYMBOL_ACLASS_BITS
;
1153 /* If non-zero then symbol is objfile-owned, use owner.symtab.
1154 Otherwise symbol is arch-owned, use owner.arch. */
1156 unsigned int is_objfile_owned
: 1;
1158 /* Whether this is an argument. */
1160 unsigned is_argument
: 1;
1162 /* Whether this is an inlined function (class LOC_BLOCK only). */
1163 unsigned is_inlined
: 1;
1165 /* For LOC_STATIC only, if this is set, then the symbol might be
1166 subject to copy relocation. In this case, a minimal symbol
1167 matching the symbol's linkage name is first looked for in the
1168 main objfile. If found, then that address is used; otherwise the
1169 address in this symbol is used. */
1171 unsigned maybe_copied
: 1;
1173 /* The concrete type of this symbol. */
1175 ENUM_BITFIELD (symbol_subclass_kind
) subclass
: 2;
1177 /* Line number of this symbol's definition, except for inlined
1178 functions. For an inlined function (class LOC_BLOCK and
1179 SYMBOL_INLINED set) this is the line number of the function's call
1180 site. Inlined function symbols are not definitions, and they are
1181 never found by symbol table lookup.
1182 If this symbol is arch-owned, LINE shall be zero.
1184 FIXME: Should we really make the assumption that nobody will try
1185 to debug files longer than 64K lines? What about machine
1186 generated programs? */
1188 unsigned short line
= 0;
1190 /* An arbitrary data pointer, allowing symbol readers to record
1191 additional information on a per-symbol basis. Note that this data
1192 must be allocated using the same obstack as the symbol itself. */
1193 /* So far it is only used by:
1194 LOC_COMPUTED: to find the location information
1195 LOC_BLOCK (DWARF2 function): information used internally by the
1196 DWARF 2 code --- specifically, the location expression for the frame
1197 base for this function. */
1198 /* FIXME drow/2003-02-21: For the LOC_BLOCK case, it might be better
1199 to add a magic symbol to the block containing this information,
1200 or to have a generic debug info annotation slot for symbols. */
1202 void *aux_value
= nullptr;
1204 struct symbol
*hash_next
= nullptr;
1207 /* This struct is size-critical (see comment at the top), so this assert
1208 makes sure the size doesn't change accidentally. Be careful when
1209 purposely increasing the size. */
1210 gdb_static_assert ((sizeof (void *) == 8 && sizeof (symbol
) == 72)
1211 || (sizeof (void *) == 4 && sizeof (symbol
) == 40));
1213 /* Several lookup functions return both a symbol and the block in which the
1214 symbol is found. This structure is used in these cases. */
1218 /* The symbol that was found, or NULL if no symbol was found. */
1219 struct symbol
*symbol
;
1221 /* If SYMBOL is not NULL, then this is the block in which the symbol is
1223 const struct block
*block
;
1226 extern const struct symbol_impl
*symbol_impls
;
1228 /* Note: There is no accessor macro for symbol.owner because it is
1231 #define SYMBOL_DOMAIN(symbol) (symbol)->domain
1232 #define SYMBOL_IMPL(symbol) (symbol_impls[(symbol)->aclass_index])
1233 #define SYMBOL_ACLASS_INDEX(symbol) (symbol)->aclass_index
1234 #define SYMBOL_CLASS(symbol) (SYMBOL_IMPL (symbol).aclass)
1235 #define SYMBOL_OBJFILE_OWNED(symbol) ((symbol)->is_objfile_owned)
1236 #define SYMBOL_IS_ARGUMENT(symbol) (symbol)->is_argument
1237 #define SYMBOL_INLINED(symbol) (symbol)->is_inlined
1238 #define SYMBOL_IS_CPLUS_TEMPLATE_FUNCTION(symbol) \
1239 (((symbol)->subclass) == SYMBOL_TEMPLATE)
1240 #define SYMBOL_TYPE(symbol) (symbol)->type
1241 #define SYMBOL_LINE(symbol) (symbol)->line
1242 #define SYMBOL_COMPUTED_OPS(symbol) (SYMBOL_IMPL (symbol).ops_computed)
1243 #define SYMBOL_BLOCK_OPS(symbol) (SYMBOL_IMPL (symbol).ops_block)
1244 #define SYMBOL_REGISTER_OPS(symbol) (SYMBOL_IMPL (symbol).ops_register)
1245 #define SYMBOL_LOCATION_BATON(symbol) (symbol)->aux_value
1247 extern int register_symbol_computed_impl (enum address_class
,
1248 const struct symbol_computed_ops
*);
1250 extern int register_symbol_block_impl (enum address_class aclass
,
1251 const struct symbol_block_ops
*ops
);
1253 extern int register_symbol_register_impl (enum address_class
,
1254 const struct symbol_register_ops
*);
1256 /* Return the OBJFILE of SYMBOL.
1257 It is an error to call this if symbol.is_objfile_owned is false, which
1258 only happens for architecture-provided types. */
1260 extern struct objfile
*symbol_objfile (const struct symbol
*symbol
);
1262 /* Return the ARCH of SYMBOL. */
1264 extern struct gdbarch
*symbol_arch (const struct symbol
*symbol
);
1266 /* Return the SYMTAB of SYMBOL.
1267 It is an error to call this if symbol.is_objfile_owned is false, which
1268 only happens for architecture-provided types. */
1270 extern struct symtab
*symbol_symtab (const struct symbol
*symbol
);
1272 /* Set the symtab of SYMBOL to SYMTAB.
1273 It is an error to call this if symbol.is_objfile_owned is false, which
1274 only happens for architecture-provided types. */
1276 extern void symbol_set_symtab (struct symbol
*symbol
, struct symtab
*symtab
);
1278 /* An instance of this type is used to represent a C++ template
1279 function. A symbol is really of this type iff
1280 SYMBOL_IS_CPLUS_TEMPLATE_FUNCTION is true. */
1282 struct template_symbol
: public symbol
1284 /* The number of template arguments. */
1285 int n_template_arguments
= 0;
1287 /* The template arguments. This is an array with
1288 N_TEMPLATE_ARGUMENTS elements. */
1289 struct symbol
**template_arguments
= nullptr;
1292 /* A symbol that represents a Rust virtual table object. */
1294 struct rust_vtable_symbol
: public symbol
1296 /* The concrete type for which this vtable was created; that is, in
1297 "impl Trait for Type", this is "Type". */
1298 struct type
*concrete_type
= nullptr;
1302 /* Each item represents a line-->pc (or the reverse) mapping. This is
1303 somewhat more wasteful of space than one might wish, but since only
1304 the files which are actually debugged are read in to core, we don't
1305 waste much space. */
1307 struct linetable_entry
1313 /* The order of entries in the linetable is significant. They should
1314 be sorted by increasing values of the pc field. If there is more than
1315 one entry for a given pc, then I'm not sure what should happen (and
1316 I not sure whether we currently handle it the best way).
1318 Example: a C for statement generally looks like this
1320 10 0x100 - for the init/test part of a for stmt.
1323 10 0x400 - for the increment part of a for stmt.
1325 If an entry has a line number of zero, it marks the start of a PC
1326 range for which no line number information is available. It is
1327 acceptable, though wasteful of table space, for such a range to be
1334 /* Actually NITEMS elements. If you don't like this use of the
1335 `struct hack', you can shove it up your ANSI (seriously, if the
1336 committee tells us how to do it, we can probably go along). */
1337 struct linetable_entry item
[1];
1340 /* How to relocate the symbols from each section in a symbol file.
1341 Each struct contains an array of offsets.
1342 The ordering and meaning of the offsets is file-type-dependent;
1343 typically it is indexed by section numbers or symbol types or
1344 something like that.
1346 To give us flexibility in changing the internal representation
1347 of these offsets, the ANOFFSET macro must be used to insert and
1348 extract offset values in the struct. */
1350 struct section_offsets
1352 CORE_ADDR offsets
[1]; /* As many as needed. */
1355 #define ANOFFSET(secoff, whichone) \
1357 ? (internal_error (__FILE__, __LINE__, \
1358 _("Section index is uninitialized")), -1) \
1359 : secoff->offsets[whichone])
1361 /* The size of a section_offsets table for N sections. */
1362 #define SIZEOF_N_SECTION_OFFSETS(n) \
1363 (sizeof (struct section_offsets) \
1364 + sizeof (((struct section_offsets *) 0)->offsets) * ((n)-1))
1366 /* Each source file or header is represented by a struct symtab.
1367 The name "symtab" is historical, another name for it is "filetab".
1368 These objects are chained through the `next' field. */
1372 /* Unordered chain of all filetabs in the compunit, with the exception
1373 that the "main" source file is the first entry in the list. */
1375 struct symtab
*next
;
1377 /* Backlink to containing compunit symtab. */
1379 struct compunit_symtab
*compunit_symtab
;
1381 /* Table mapping core addresses to line numbers for this file.
1382 Can be NULL if none. Never shared between different symtabs. */
1384 struct linetable
*linetable
;
1386 /* Name of this source file. This pointer is never NULL. */
1388 const char *filename
;
1390 /* Language of this source file. */
1392 enum language language
;
1394 /* Full name of file as found by searching the source path.
1395 NULL if not yet known. */
1400 #define SYMTAB_COMPUNIT(symtab) ((symtab)->compunit_symtab)
1401 #define SYMTAB_LINETABLE(symtab) ((symtab)->linetable)
1402 #define SYMTAB_LANGUAGE(symtab) ((symtab)->language)
1403 #define SYMTAB_BLOCKVECTOR(symtab) \
1404 COMPUNIT_BLOCKVECTOR (SYMTAB_COMPUNIT (symtab))
1405 #define SYMTAB_OBJFILE(symtab) \
1406 COMPUNIT_OBJFILE (SYMTAB_COMPUNIT (symtab))
1407 #define SYMTAB_PSPACE(symtab) (SYMTAB_OBJFILE (symtab)->pspace)
1408 #define SYMTAB_DIRNAME(symtab) \
1409 COMPUNIT_DIRNAME (SYMTAB_COMPUNIT (symtab))
1411 /* Compunit symtabs contain the actual "symbol table", aka blockvector, as well
1412 as the list of all source files (what gdb has historically associated with
1414 Additional information is recorded here that is common to all symtabs in a
1415 compilation unit (DWARF or otherwise).
1418 For the case of a program built out of these files:
1427 This is recorded as:
1429 objfile -> foo.c(cu) -> bar.c(cu) -> NULL
1443 where "foo.c(cu)" and "bar.c(cu)" are struct compunit_symtab objects,
1444 and the files foo.c, etc. are struct symtab objects. */
1446 struct compunit_symtab
1448 /* Unordered chain of all compunit symtabs of this objfile. */
1449 struct compunit_symtab
*next
;
1451 /* Object file from which this symtab information was read. */
1452 struct objfile
*objfile
;
1454 /* Name of the symtab.
1455 This is *not* intended to be a usable filename, and is
1456 for debugging purposes only. */
1459 /* Unordered list of file symtabs, except that by convention the "main"
1460 source file (e.g., .c, .cc) is guaranteed to be first.
1461 Each symtab is a file, either the "main" source file (e.g., .c, .cc)
1462 or header (e.g., .h). */
1463 struct symtab
*filetabs
;
1465 /* Last entry in FILETABS list.
1466 Subfiles are added to the end of the list so they accumulate in order,
1467 with the main source subfile living at the front.
1468 The main reason is so that the main source file symtab is at the head
1469 of the list, and the rest appear in order for debugging convenience. */
1470 struct symtab
*last_filetab
;
1472 /* Non-NULL string that identifies the format of the debugging information,
1473 such as "stabs", "dwarf 1", "dwarf 2", "coff", etc. This is mostly useful
1474 for automated testing of gdb but may also be information that is
1475 useful to the user. */
1476 const char *debugformat
;
1478 /* String of producer version information, or NULL if we don't know. */
1479 const char *producer
;
1481 /* Directory in which it was compiled, or NULL if we don't know. */
1482 const char *dirname
;
1484 /* List of all symbol scope blocks for this symtab. It is shared among
1485 all symtabs in a given compilation unit. */
1486 const struct blockvector
*blockvector
;
1488 /* Section in objfile->section_offsets for the blockvector and
1489 the linetable. Probably always SECT_OFF_TEXT. */
1490 int block_line_section
;
1492 /* Symtab has been compiled with both optimizations and debug info so that
1493 GDB may stop skipping prologues as variables locations are valid already
1494 at function entry points. */
1495 unsigned int locations_valid
: 1;
1497 /* DWARF unwinder for this CU is valid even for epilogues (PC at the return
1498 instruction). This is supported by GCC since 4.5.0. */
1499 unsigned int epilogue_unwind_valid
: 1;
1501 /* struct call_site entries for this compilation unit or NULL. */
1502 htab_t call_site_htab
;
1504 /* The macro table for this symtab. Like the blockvector, this
1505 is shared between different symtabs in a given compilation unit.
1506 It's debatable whether it *should* be shared among all the symtabs in
1507 the given compilation unit, but it currently is. */
1508 struct macro_table
*macro_table
;
1510 /* If non-NULL, then this points to a NULL-terminated vector of
1511 included compunits. When searching the static or global
1512 block of this compunit, the corresponding block of all
1513 included compunits will also be searched. Note that this
1514 list must be flattened -- the symbol reader is responsible for
1515 ensuring that this vector contains the transitive closure of all
1516 included compunits. */
1517 struct compunit_symtab
**includes
;
1519 /* If this is an included compunit, this points to one includer
1520 of the table. This user is considered the canonical compunit
1521 containing this one. An included compunit may itself be
1522 included by another. */
1523 struct compunit_symtab
*user
;
1526 #define COMPUNIT_OBJFILE(cust) ((cust)->objfile)
1527 #define COMPUNIT_FILETABS(cust) ((cust)->filetabs)
1528 #define COMPUNIT_DEBUGFORMAT(cust) ((cust)->debugformat)
1529 #define COMPUNIT_PRODUCER(cust) ((cust)->producer)
1530 #define COMPUNIT_DIRNAME(cust) ((cust)->dirname)
1531 #define COMPUNIT_BLOCKVECTOR(cust) ((cust)->blockvector)
1532 #define COMPUNIT_BLOCK_LINE_SECTION(cust) ((cust)->block_line_section)
1533 #define COMPUNIT_LOCATIONS_VALID(cust) ((cust)->locations_valid)
1534 #define COMPUNIT_EPILOGUE_UNWIND_VALID(cust) ((cust)->epilogue_unwind_valid)
1535 #define COMPUNIT_CALL_SITE_HTAB(cust) ((cust)->call_site_htab)
1536 #define COMPUNIT_MACRO_TABLE(cust) ((cust)->macro_table)
1538 /* A range adapter to allowing iterating over all the file tables
1539 within a compunit. */
1541 struct compunit_filetabs
: public next_adapter
<struct symtab
>
1543 compunit_filetabs (struct compunit_symtab
*cu
)
1544 : next_adapter
<struct symtab
> (cu
->filetabs
)
1549 /* Return the primary symtab of CUST. */
1551 extern struct symtab
*
1552 compunit_primary_filetab (const struct compunit_symtab
*cust
);
1554 /* Return the language of CUST. */
1556 extern enum language
compunit_language (const struct compunit_symtab
*cust
);
1560 /* The virtual function table is now an array of structures which have the
1561 form { int16 offset, delta; void *pfn; }.
1563 In normal virtual function tables, OFFSET is unused.
1564 DELTA is the amount which is added to the apparent object's base
1565 address in order to point to the actual object to which the
1566 virtual function should be applied.
1567 PFN is a pointer to the virtual function.
1569 Note that this macro is g++ specific (FIXME). */
1571 #define VTBL_FNADDR_OFFSET 2
1573 /* External variables and functions for the objects described above. */
1575 /* True if we are nested inside psymtab_to_symtab. */
1577 extern int currently_reading_symtab
;
1579 /* symtab.c lookup functions */
1581 extern const char multiple_symbols_ask
[];
1582 extern const char multiple_symbols_all
[];
1583 extern const char multiple_symbols_cancel
[];
1585 const char *multiple_symbols_select_mode (void);
1587 bool symbol_matches_domain (enum language symbol_language
,
1588 domain_enum symbol_domain
,
1589 domain_enum domain
);
1591 /* lookup a symbol table by source file name. */
1593 extern struct symtab
*lookup_symtab (const char *);
1595 /* An object of this type is passed as the 'is_a_field_of_this'
1596 argument to lookup_symbol and lookup_symbol_in_language. */
1598 struct field_of_this_result
1600 /* The type in which the field was found. If this is NULL then the
1601 symbol was not found in 'this'. If non-NULL, then one of the
1602 other fields will be non-NULL as well. */
1606 /* If the symbol was found as an ordinary field of 'this', then this
1607 is non-NULL and points to the particular field. */
1609 struct field
*field
;
1611 /* If the symbol was found as a function field of 'this', then this
1612 is non-NULL and points to the particular field. */
1614 struct fn_fieldlist
*fn_field
;
1617 /* Find the definition for a specified symbol name NAME
1618 in domain DOMAIN in language LANGUAGE, visible from lexical block BLOCK
1619 if non-NULL or from global/static blocks if BLOCK is NULL.
1620 Returns the struct symbol pointer, or NULL if no symbol is found.
1621 C++: if IS_A_FIELD_OF_THIS is non-NULL on entry, check to see if
1622 NAME is a field of the current implied argument `this'. If so fill in the
1623 fields of IS_A_FIELD_OF_THIS, otherwise the fields are set to NULL.
1624 The symbol's section is fixed up if necessary. */
1626 extern struct block_symbol
1627 lookup_symbol_in_language (const char *,
1628 const struct block
*,
1631 struct field_of_this_result
*);
1633 /* Same as lookup_symbol_in_language, but using the current language. */
1635 extern struct block_symbol
lookup_symbol (const char *,
1636 const struct block
*,
1638 struct field_of_this_result
*);
1640 /* Find the definition for a specified symbol search name in domain
1641 DOMAIN, visible from lexical block BLOCK if non-NULL or from
1642 global/static blocks if BLOCK is NULL. The passed-in search name
1643 should not come from the user; instead it should already be a
1644 search name as retrieved from a
1645 SYMBOL_SEARCH_NAME/MSYMBOL_SEARCH_NAME call. See definition of
1646 symbol_name_match_type::SEARCH_NAME. Returns the struct symbol
1647 pointer, or NULL if no symbol is found. The symbol's section is
1648 fixed up if necessary. */
1650 extern struct block_symbol
lookup_symbol_search_name (const char *search_name
,
1651 const struct block
*block
,
1652 domain_enum domain
);
1654 /* A default version of lookup_symbol_nonlocal for use by languages
1655 that can't think of anything better to do.
1656 This implements the C lookup rules. */
1658 extern struct block_symbol
1659 basic_lookup_symbol_nonlocal (const struct language_defn
*langdef
,
1661 const struct block
*,
1664 /* Some helper functions for languages that need to write their own
1665 lookup_symbol_nonlocal functions. */
1667 /* Lookup a symbol in the static block associated to BLOCK, if there
1668 is one; do nothing if BLOCK is NULL or a global block.
1669 Upon success fixes up the symbol's section if necessary. */
1671 extern struct block_symbol
1672 lookup_symbol_in_static_block (const char *name
,
1673 const struct block
*block
,
1674 const domain_enum domain
);
1676 /* Search all static file-level symbols for NAME from DOMAIN.
1677 Upon success fixes up the symbol's section if necessary. */
1679 extern struct block_symbol
lookup_static_symbol (const char *name
,
1680 const domain_enum domain
);
1682 /* Lookup a symbol in all files' global blocks.
1684 If BLOCK is non-NULL then it is used for two things:
1685 1) If a target-specific lookup routine for libraries exists, then use the
1686 routine for the objfile of BLOCK, and
1687 2) The objfile of BLOCK is used to assist in determining the search order
1688 if the target requires it.
1689 See gdbarch_iterate_over_objfiles_in_search_order.
1691 Upon success fixes up the symbol's section if necessary. */
1693 extern struct block_symbol
1694 lookup_global_symbol (const char *name
,
1695 const struct block
*block
,
1696 const domain_enum domain
);
1698 /* Lookup a symbol in block BLOCK.
1699 Upon success fixes up the symbol's section if necessary. */
1701 extern struct symbol
*
1702 lookup_symbol_in_block (const char *name
,
1703 symbol_name_match_type match_type
,
1704 const struct block
*block
,
1705 const domain_enum domain
);
1707 /* Look up the `this' symbol for LANG in BLOCK. Return the symbol if
1708 found, or NULL if not found. */
1710 extern struct block_symbol
1711 lookup_language_this (const struct language_defn
*lang
,
1712 const struct block
*block
);
1714 /* Lookup a [struct, union, enum] by name, within a specified block. */
1716 extern struct type
*lookup_struct (const char *, const struct block
*);
1718 extern struct type
*lookup_union (const char *, const struct block
*);
1720 extern struct type
*lookup_enum (const char *, const struct block
*);
1722 /* from blockframe.c: */
1724 /* lookup the function symbol corresponding to the address. The
1725 return value will not be an inlined function; the containing
1726 function will be returned instead. */
1728 extern struct symbol
*find_pc_function (CORE_ADDR
);
1730 /* lookup the function corresponding to the address and section. The
1731 return value will not be an inlined function; the containing
1732 function will be returned instead. */
1734 extern struct symbol
*find_pc_sect_function (CORE_ADDR
, struct obj_section
*);
1736 /* lookup the function symbol corresponding to the address and
1737 section. The return value will be the closest enclosing function,
1738 which might be an inline function. */
1740 extern struct symbol
*find_pc_sect_containing_function
1741 (CORE_ADDR pc
, struct obj_section
*section
);
1743 /* Find the symbol at the given address. Returns NULL if no symbol
1744 found. Only exact matches for ADDRESS are considered. */
1746 extern struct symbol
*find_symbol_at_address (CORE_ADDR
);
1748 /* Finds the "function" (text symbol) that is smaller than PC but
1749 greatest of all of the potential text symbols in SECTION. Sets
1750 *NAME and/or *ADDRESS conditionally if that pointer is non-null.
1751 If ENDADDR is non-null, then set *ENDADDR to be the end of the
1752 function (exclusive). If the optional parameter BLOCK is non-null,
1753 then set *BLOCK to the address of the block corresponding to the
1754 function symbol, if such a symbol could be found during the lookup;
1755 nullptr is used as a return value for *BLOCK if no block is found.
1756 This function either succeeds or fails (not halfway succeeds). If
1757 it succeeds, it sets *NAME, *ADDRESS, and *ENDADDR to real
1758 information and returns true. If it fails, it sets *NAME, *ADDRESS
1759 and *ENDADDR to zero and returns false.
1761 If the function in question occupies non-contiguous ranges,
1762 *ADDRESS and *ENDADDR are (subject to the conditions noted above) set
1763 to the start and end of the range in which PC is found. Thus
1764 *ADDRESS <= PC < *ENDADDR with no intervening gaps (in which ranges
1765 from other functions might be found).
1767 This property allows find_pc_partial_function to be used (as it had
1768 been prior to the introduction of non-contiguous range support) by
1769 various tdep files for finding a start address and limit address
1770 for prologue analysis. This still isn't ideal, however, because we
1771 probably shouldn't be doing prologue analysis (in which
1772 instructions are scanned to determine frame size and stack layout)
1773 for any range that doesn't contain the entry pc. Moreover, a good
1774 argument can be made that prologue analysis ought to be performed
1775 starting from the entry pc even when PC is within some other range.
1776 This might suggest that *ADDRESS and *ENDADDR ought to be set to the
1777 limits of the entry pc range, but that will cause the
1778 *ADDRESS <= PC < *ENDADDR condition to be violated; many of the
1779 callers of find_pc_partial_function expect this condition to hold.
1781 Callers which require the start and/or end addresses for the range
1782 containing the entry pc should instead call
1783 find_function_entry_range_from_pc. */
1785 extern bool find_pc_partial_function (CORE_ADDR pc
, const char **name
,
1786 CORE_ADDR
*address
, CORE_ADDR
*endaddr
,
1787 const struct block
**block
= nullptr);
1789 /* Like find_pc_partial_function, above, but *ADDRESS and *ENDADDR are
1790 set to start and end addresses of the range containing the entry pc.
1792 Note that it is not necessarily the case that (for non-NULL ADDRESS
1793 and ENDADDR arguments) the *ADDRESS <= PC < *ENDADDR condition will
1796 See comment for find_pc_partial_function, above, for further
1799 extern bool find_function_entry_range_from_pc (CORE_ADDR pc
,
1802 CORE_ADDR
*endaddr
);
1804 /* Return the type of a function with its first instruction exactly at
1805 the PC address. Return NULL otherwise. */
1807 extern struct type
*find_function_type (CORE_ADDR pc
);
1809 /* See if we can figure out the function's actual type from the type
1810 that the resolver returns. RESOLVER_FUNADDR is the address of the
1813 extern struct type
*find_gnu_ifunc_target_type (CORE_ADDR resolver_funaddr
);
1815 /* Find the GNU ifunc minimal symbol that matches SYM. */
1816 extern bound_minimal_symbol
find_gnu_ifunc (const symbol
*sym
);
1818 extern void clear_pc_function_cache (void);
1820 /* Expand symtab containing PC, SECTION if not already expanded. */
1822 extern void expand_symtab_containing_pc (CORE_ADDR
, struct obj_section
*);
1824 /* lookup full symbol table by address. */
1826 extern struct compunit_symtab
*find_pc_compunit_symtab (CORE_ADDR
);
1828 /* lookup full symbol table by address and section. */
1830 extern struct compunit_symtab
*
1831 find_pc_sect_compunit_symtab (CORE_ADDR
, struct obj_section
*);
1833 extern bool find_pc_line_pc_range (CORE_ADDR
, CORE_ADDR
*, CORE_ADDR
*);
1835 extern void reread_symbols (void);
1837 /* Look up a type named NAME in STRUCT_DOMAIN in the current language.
1838 The type returned must not be opaque -- i.e., must have at least one field
1841 extern struct type
*lookup_transparent_type (const char *);
1843 extern struct type
*basic_lookup_transparent_type (const char *);
1845 /* Macro for name of symbol to indicate a file compiled with gcc. */
1846 #ifndef GCC_COMPILED_FLAG_SYMBOL
1847 #define GCC_COMPILED_FLAG_SYMBOL "gcc_compiled."
1850 /* Macro for name of symbol to indicate a file compiled with gcc2. */
1851 #ifndef GCC2_COMPILED_FLAG_SYMBOL
1852 #define GCC2_COMPILED_FLAG_SYMBOL "gcc2_compiled."
1855 extern bool in_gnu_ifunc_stub (CORE_ADDR pc
);
1857 /* Functions for resolving STT_GNU_IFUNC symbols which are implemented only
1858 for ELF symbol files. */
1860 struct gnu_ifunc_fns
1862 /* See elf_gnu_ifunc_resolve_addr for its real implementation. */
1863 CORE_ADDR (*gnu_ifunc_resolve_addr
) (struct gdbarch
*gdbarch
, CORE_ADDR pc
);
1865 /* See elf_gnu_ifunc_resolve_name for its real implementation. */
1866 bool (*gnu_ifunc_resolve_name
) (const char *function_name
,
1867 CORE_ADDR
*function_address_p
);
1869 /* See elf_gnu_ifunc_resolver_stop for its real implementation. */
1870 void (*gnu_ifunc_resolver_stop
) (struct breakpoint
*b
);
1872 /* See elf_gnu_ifunc_resolver_return_stop for its real implementation. */
1873 void (*gnu_ifunc_resolver_return_stop
) (struct breakpoint
*b
);
1876 #define gnu_ifunc_resolve_addr gnu_ifunc_fns_p->gnu_ifunc_resolve_addr
1877 #define gnu_ifunc_resolve_name gnu_ifunc_fns_p->gnu_ifunc_resolve_name
1878 #define gnu_ifunc_resolver_stop gnu_ifunc_fns_p->gnu_ifunc_resolver_stop
1879 #define gnu_ifunc_resolver_return_stop \
1880 gnu_ifunc_fns_p->gnu_ifunc_resolver_return_stop
1882 extern const struct gnu_ifunc_fns
*gnu_ifunc_fns_p
;
1884 extern CORE_ADDR
find_solib_trampoline_target (struct frame_info
*, CORE_ADDR
);
1886 struct symtab_and_line
1888 /* The program space of this sal. */
1889 struct program_space
*pspace
= NULL
;
1891 struct symtab
*symtab
= NULL
;
1892 struct symbol
*symbol
= NULL
;
1893 struct obj_section
*section
= NULL
;
1894 struct minimal_symbol
*msymbol
= NULL
;
1895 /* Line number. Line numbers start at 1 and proceed through symtab->nlines.
1896 0 is never a valid line number; it is used to indicate that line number
1897 information is not available. */
1902 bool explicit_pc
= false;
1903 bool explicit_line
= false;
1905 /* The probe associated with this symtab_and_line. */
1907 /* If PROBE is not NULL, then this is the objfile in which the probe
1909 struct objfile
*objfile
= NULL
;
1914 /* Given a pc value, return line number it is in. Second arg nonzero means
1915 if pc is on the boundary use the previous statement's line number. */
1917 extern struct symtab_and_line
find_pc_line (CORE_ADDR
, int);
1919 /* Same function, but specify a section as well as an address. */
1921 extern struct symtab_and_line
find_pc_sect_line (CORE_ADDR
,
1922 struct obj_section
*, int);
1924 /* Wrapper around find_pc_line to just return the symtab. */
1926 extern struct symtab
*find_pc_line_symtab (CORE_ADDR
);
1928 /* Given a symtab and line number, return the pc there. */
1930 extern bool find_line_pc (struct symtab
*, int, CORE_ADDR
*);
1932 extern bool find_line_pc_range (struct symtab_and_line
, CORE_ADDR
*,
1935 extern void resolve_sal_pc (struct symtab_and_line
*);
1939 extern void clear_solib (void);
1941 /* The reason we're calling into a completion match list collector
1943 enum class complete_symbol_mode
1945 /* Completing an expression. */
1948 /* Completing a linespec. */
1952 extern void default_collect_symbol_completion_matches_break_on
1953 (completion_tracker
&tracker
,
1954 complete_symbol_mode mode
,
1955 symbol_name_match_type name_match_type
,
1956 const char *text
, const char *word
, const char *break_on
,
1957 enum type_code code
);
1958 extern void default_collect_symbol_completion_matches
1959 (completion_tracker
&tracker
,
1960 complete_symbol_mode
,
1961 symbol_name_match_type name_match_type
,
1965 extern void collect_symbol_completion_matches
1966 (completion_tracker
&tracker
,
1967 complete_symbol_mode mode
,
1968 symbol_name_match_type name_match_type
,
1969 const char *, const char *);
1970 extern void collect_symbol_completion_matches_type (completion_tracker
&tracker
,
1971 const char *, const char *,
1974 extern void collect_file_symbol_completion_matches
1975 (completion_tracker
&tracker
,
1976 complete_symbol_mode
,
1977 symbol_name_match_type name_match_type
,
1978 const char *, const char *, const char *);
1980 extern completion_list
1981 make_source_files_completion_list (const char *, const char *);
1983 /* Return whether SYM is a function/method, as opposed to a data symbol. */
1985 extern bool symbol_is_function_or_method (symbol
*sym
);
1987 /* Return whether MSYMBOL is a function/method, as opposed to a data
1990 extern bool symbol_is_function_or_method (minimal_symbol
*msymbol
);
1992 /* Return whether SYM should be skipped in completion mode MODE. In
1993 linespec mode, we're only interested in functions/methods. */
1995 template<typename Symbol
>
1997 completion_skip_symbol (complete_symbol_mode mode
, Symbol
*sym
)
1999 return (mode
== complete_symbol_mode::LINESPEC
2000 && !symbol_is_function_or_method (sym
));
2005 bool matching_obj_sections (struct obj_section
*, struct obj_section
*);
2007 extern struct symtab
*find_line_symtab (struct symtab
*, int, int *, bool *);
2009 /* Given a function symbol SYM, find the symtab and line for the start
2010 of the function. If FUNFIRSTLINE is true, we want the first line
2011 of real code inside the function. */
2012 extern symtab_and_line
find_function_start_sal (symbol
*sym
, bool
2015 /* Same, but start with a function address/section instead of a
2017 extern symtab_and_line
find_function_start_sal (CORE_ADDR func_addr
,
2018 obj_section
*section
,
2021 extern void skip_prologue_sal (struct symtab_and_line
*);
2025 extern CORE_ADDR
skip_prologue_using_sal (struct gdbarch
*gdbarch
,
2026 CORE_ADDR func_addr
);
2028 extern struct symbol
*fixup_symbol_section (struct symbol
*,
2031 /* If MSYMBOL is an text symbol, look for a function debug symbol with
2032 the same address. Returns NULL if not found. This is necessary in
2033 case a function is an alias to some other function, because debug
2034 information is only emitted for the alias target function's
2035 definition, not for the alias. */
2036 extern symbol
*find_function_alias_target (bound_minimal_symbol msymbol
);
2038 /* Symbol searching */
2039 /* Note: struct symbol_search, search_symbols, et.al. are declared here,
2040 instead of making them local to symtab.c, for gdbtk's sake. */
2042 /* When using search_symbols, a vector of the following structs is
2044 struct symbol_search
2046 symbol_search (int block_
, struct symbol
*symbol_
)
2050 msymbol
.minsym
= nullptr;
2051 msymbol
.objfile
= nullptr;
2054 symbol_search (int block_
, struct minimal_symbol
*minsym
,
2055 struct objfile
*objfile
)
2059 msymbol
.minsym
= minsym
;
2060 msymbol
.objfile
= objfile
;
2063 bool operator< (const symbol_search
&other
) const
2065 return compare_search_syms (*this, other
) < 0;
2068 bool operator== (const symbol_search
&other
) const
2070 return compare_search_syms (*this, other
) == 0;
2073 /* The block in which the match was found. Could be, for example,
2074 STATIC_BLOCK or GLOBAL_BLOCK. */
2077 /* Information describing what was found.
2079 If symbol is NOT NULL, then information was found for this match. */
2080 struct symbol
*symbol
;
2082 /* If msymbol is non-null, then a match was made on something for
2083 which only minimal_symbols exist. */
2084 struct bound_minimal_symbol msymbol
;
2088 static int compare_search_syms (const symbol_search
&sym_a
,
2089 const symbol_search
&sym_b
);
2092 extern std::vector
<symbol_search
> search_symbols (const char *,
2099 /* When searching for Fortran symbols within modules (functions/variables)
2100 we return a vector of this type. The first item in the pair is the
2101 module symbol, and the second item is the symbol for the function or
2102 variable we found. */
2103 typedef std::pair
<symbol_search
, symbol_search
> module_symbol_search
;
2105 /* Searches the symbols to find function and variables symbols (depending
2106 on KIND) within Fortran modules. The MODULE_REGEXP matches against the
2107 name of the module, REGEXP matches against the name of the symbol within
2108 the module, and TYPE_REGEXP matches against the type of the symbol
2109 within the module. */
2110 extern std::vector
<module_symbol_search
> search_module_symbols
2111 (const char *module_regexp
, const char *regexp
,
2112 const char *type_regexp
, search_domain kind
);
2114 extern bool treg_matches_sym_type_name (const compiled_regex
&treg
,
2115 const struct symbol
*sym
);
2117 /* The name of the ``main'' function. */
2118 extern const char *main_name ();
2119 extern enum language
main_language (void);
2121 /* Lookup symbol NAME from DOMAIN in MAIN_OBJFILE's global or static blocks,
2122 as specified by BLOCK_INDEX.
2123 This searches MAIN_OBJFILE as well as any associated separate debug info
2124 objfiles of MAIN_OBJFILE.
2125 BLOCK_INDEX can be GLOBAL_BLOCK or STATIC_BLOCK.
2126 Upon success fixes up the symbol's section if necessary. */
2128 extern struct block_symbol
2129 lookup_global_symbol_from_objfile (struct objfile
*main_objfile
,
2130 enum block_enum block_index
,
2132 const domain_enum domain
);
2134 /* Return 1 if the supplied producer string matches the ARM RealView
2135 compiler (armcc). */
2136 bool producer_is_realview (const char *producer
);
2138 void fixup_section (struct general_symbol_info
*ginfo
,
2139 CORE_ADDR addr
, struct objfile
*objfile
);
2141 /* Look up objfile containing BLOCK. */
2143 struct objfile
*lookup_objfile_from_block (const struct block
*block
);
2145 extern unsigned int symtab_create_debug
;
2147 extern unsigned int symbol_lookup_debug
;
2149 extern bool basenames_may_differ
;
2151 bool compare_filenames_for_search (const char *filename
,
2152 const char *search_name
);
2154 bool compare_glob_filenames_for_search (const char *filename
,
2155 const char *search_name
);
2157 bool iterate_over_some_symtabs (const char *name
,
2158 const char *real_path
,
2159 struct compunit_symtab
*first
,
2160 struct compunit_symtab
*after_last
,
2161 gdb::function_view
<bool (symtab
*)> callback
);
2163 void iterate_over_symtabs (const char *name
,
2164 gdb::function_view
<bool (symtab
*)> callback
);
2167 std::vector
<CORE_ADDR
> find_pcs_for_symtab_line
2168 (struct symtab
*symtab
, int line
, struct linetable_entry
**best_entry
);
2170 /* Prototype for callbacks for LA_ITERATE_OVER_SYMBOLS. The callback
2171 is called once per matching symbol SYM. The callback should return
2172 true to indicate that LA_ITERATE_OVER_SYMBOLS should continue
2173 iterating, or false to indicate that the iteration should end. */
2175 typedef bool (symbol_found_callback_ftype
) (struct block_symbol
*bsym
);
2177 /* Iterate over the symbols named NAME, matching DOMAIN, in BLOCK.
2179 For each symbol that matches, CALLBACK is called. The symbol is
2180 passed to the callback.
2182 If CALLBACK returns false, the iteration ends and this function
2183 returns false. Otherwise, the search continues, and the function
2184 eventually returns true. */
2186 bool iterate_over_symbols (const struct block
*block
,
2187 const lookup_name_info
&name
,
2188 const domain_enum domain
,
2189 gdb::function_view
<symbol_found_callback_ftype
> callback
);
2191 /* Like iterate_over_symbols, but if all calls to CALLBACK return
2192 true, then calls CALLBACK one additional time with a block_symbol
2193 that has a valid block but a NULL symbol. */
2195 bool iterate_over_symbols_terminated
2196 (const struct block
*block
,
2197 const lookup_name_info
&name
,
2198 const domain_enum domain
,
2199 gdb::function_view
<symbol_found_callback_ftype
> callback
);
2201 /* Storage type used by demangle_for_lookup. demangle_for_lookup
2202 either returns a const char * pointer that points to either of the
2203 fields of this type, or a pointer to the input NAME. This is done
2204 this way because the underlying functions that demangle_for_lookup
2205 calls either return a std::string (e.g., cp_canonicalize_string) or
2206 a malloc'ed buffer (libiberty's demangled), and we want to avoid
2207 unnecessary reallocation/string copying. */
2208 class demangle_result_storage
2212 /* Swap the std::string storage with STR, and return a pointer to
2213 the beginning of the new string. */
2214 const char *swap_string (std::string
&str
)
2216 std::swap (m_string
, str
);
2217 return m_string
.c_str ();
2220 /* Set the malloc storage to now point at PTR. Any previous malloc
2221 storage is released. */
2222 const char *set_malloc_ptr (char *ptr
)
2224 m_malloc
.reset (ptr
);
2231 std::string m_string
;
2232 gdb::unique_xmalloc_ptr
<char> m_malloc
;
2236 demangle_for_lookup (const char *name
, enum language lang
,
2237 demangle_result_storage
&storage
);
2239 struct symbol
*allocate_symbol (struct objfile
*);
2241 void initialize_objfile_symbol (struct symbol
*);
2243 struct template_symbol
*allocate_template_symbol (struct objfile
*);
2245 /* Test to see if the symbol of language SYMBOL_LANGUAGE specified by
2246 SYMNAME (which is already demangled for C++ symbols) matches
2247 SYM_TEXT in the first SYM_TEXT_LEN characters. If so, add it to
2248 the current completion list. */
2249 void completion_list_add_name (completion_tracker
&tracker
,
2250 language symbol_language
,
2251 const char *symname
,
2252 const lookup_name_info
&lookup_name
,
2253 const char *text
, const char *word
);
2255 /* A simple symbol searching class. */
2257 class symbol_searcher
2260 /* Returns the symbols found for the search. */
2261 const std::vector
<block_symbol
> &
2262 matching_symbols () const
2267 /* Returns the minimal symbols found for the search. */
2268 const std::vector
<bound_minimal_symbol
> &
2269 matching_msymbols () const
2271 return m_minimal_symbols
;
2274 /* Search for all symbols named NAME in LANGUAGE with DOMAIN, restricting
2275 search to FILE_SYMTABS and SEARCH_PSPACE, both of which may be NULL
2276 to search all symtabs and program spaces. */
2277 void find_all_symbols (const std::string
&name
,
2278 const struct language_defn
*language
,
2279 enum search_domain search_domain
,
2280 std::vector
<symtab
*> *search_symtabs
,
2281 struct program_space
*search_pspace
);
2283 /* Reset this object to perform another search. */
2287 m_minimal_symbols
.clear ();
2291 /* Matching debug symbols. */
2292 std::vector
<block_symbol
> m_symbols
;
2294 /* Matching non-debug symbols. */
2295 std::vector
<bound_minimal_symbol
> m_minimal_symbols
;
2298 #endif /* !defined(SYMTAB_H) */