1 /* Symbol table definitions for GDB.
3 Copyright (C) 1986-2025 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/>. */
27 #include "dwarf2/call-site.h"
29 #include "gdbsupport/gdb_obstack.h"
30 #include "gdbsupport/gdb_regex.h"
31 #include "gdbsupport/enum-flags.h"
32 #include "gdbsupport/function-view.h"
34 #include <string_view>
35 #include "gdbsupport/next-iterator.h"
36 #include "completer.h"
37 #include "gdb-demangle.h"
38 #include "split-name.h"
42 /* Opaque declarations. */
56 struct cmd_list_element
;
58 struct lookup_name_info
;
59 struct code_breakpoint
;
61 /* How to match a lookup name against a symbol search name. */
62 enum class symbol_name_match_type
64 /* Wild matching. Matches unqualified symbol names in all
65 namespace/module/packages, etc. */
68 /* Full matching. The lookup name indicates a fully-qualified name,
69 and only matches symbol search names in the specified
70 namespace/module/package. */
73 /* Search name matching. This is like FULL, but the search name did
74 not come from the user; instead it is already a search name
75 retrieved from a search_name () call.
76 For Ada, this avoids re-encoding an already-encoded search name
77 (which would potentially incorrectly lowercase letters in the
78 linkage/search name that should remain uppercase). For C++, it
79 avoids trying to demangle a name we already know is
83 /* Expression matching. The same as FULL matching in most
84 languages. The same as WILD matching in Ada. */
88 /* Hash the given symbol search name according to LANGUAGE's
90 extern unsigned int search_name_hash (enum language language
,
91 const char *search_name
);
93 /* Ada-specific bits of a lookup_name_info object. This is lazily
94 constructed on demand. */
96 class ada_lookup_name_info final
100 explicit ada_lookup_name_info (const lookup_name_info
&lookup_name
);
102 /* Compare SYMBOL_SEARCH_NAME with our lookup name, using MATCH_TYPE
103 as name match type. Returns true if there's a match, false
104 otherwise. If non-NULL, store the matching results in MATCH. */
105 bool matches (const char *symbol_search_name
,
106 symbol_name_match_type match_type
,
107 completion_match_result
*comp_match_res
) const;
109 /* The Ada-encoded lookup name. */
110 const std::string
&lookup_name () const
111 { return m_encoded_name
; }
113 /* Return true if we're supposed to be doing a wild match look
115 bool wild_match_p () const
116 { return m_wild_match_p
; }
118 /* Return true if we're looking up a name inside package
120 bool standard_p () const
121 { return m_standard_p
; }
123 /* Return true if doing a verbatim match. */
124 bool verbatim_p () const
125 { return m_verbatim_p
; }
127 /* A wrapper for ::split_name that handles some Ada-specific
129 std::vector
<std::string_view
> split_name () const
133 /* For verbatim matches, just return the encoded name
135 std::vector
<std::string_view
> result
;
136 result
.emplace_back (m_encoded_name
);
139 /* Otherwise, split the decoded name for matching. */
140 return ::split_name (m_decoded_name
.c_str (), split_style::DOT_STYLE
);
144 /* The Ada-encoded lookup name. */
145 std::string m_encoded_name
;
147 /* The decoded lookup name. This is formed by calling ada_decode
148 with both 'operators' and 'wide' set to false. */
149 std::string m_decoded_name
;
151 /* Whether the user-provided lookup name was Ada encoded. If so,
152 then return encoded names in the 'matches' method's 'completion
153 match result' output. */
154 bool m_encoded_p
: 1;
156 /* True if really doing wild matching. Even if the user requests
157 wild matching, some cases require full matching. */
158 bool m_wild_match_p
: 1;
160 /* True if doing a verbatim match. This is true if the decoded
161 version of the symbol name is wrapped in '<'/'>'. This is an
162 escape hatch users can use to look up symbols the Ada encoding
163 does not understand. */
164 bool m_verbatim_p
: 1;
166 /* True if the user specified a symbol name that is inside package
167 Standard. Symbol names inside package Standard are handled
168 specially. We always do a non-wild match of the symbol name
169 without the "standard__" prefix, and only search static and
170 global symbols. This was primarily introduced in order to allow
171 the user to specifically access the standard exceptions using,
172 for instance, Standard.Constraint_Error when Constraint_Error is
173 ambiguous (due to the user defining its own Constraint_Error
174 entity inside its program). */
175 bool m_standard_p
: 1;
178 /* Language-specific bits of a lookup_name_info object, for languages
179 that do name searching using demangled names (C++/D/Go). This is
180 lazily constructed on demand. */
182 struct demangle_for_lookup_info final
185 demangle_for_lookup_info (const lookup_name_info
&lookup_name
,
188 /* The demangled lookup name. */
189 const std::string
&lookup_name () const
190 { return m_demangled_name
; }
193 /* The demangled lookup name. */
194 std::string m_demangled_name
;
197 /* Object that aggregates all information related to a symbol lookup
198 name. I.e., the name that is matched against the symbol's search
199 name. Caches per-language information so that it doesn't require
200 recomputing it for every symbol comparison, like for example the
201 Ada encoded name and the symbol's name hash for a given language.
202 The object is conceptually immutable once constructed, and thus has
203 no setters. This is to prevent some code path from tweaking some
204 property of the lookup name for some local reason and accidentally
205 altering the results of any continuing search(es).
206 lookup_name_info objects are generally passed around as a const
207 reference to reinforce that. (They're not passed around by value
208 because they're not small.) */
209 class lookup_name_info final
212 /* We delete this overload so that the callers are required to
213 explicitly handle the lifetime of the name. */
214 lookup_name_info (std::string
&&name
,
215 symbol_name_match_type match_type
,
216 bool completion_mode
= false,
217 bool ignore_parameters
= false) = delete;
219 /* This overload requires that NAME have a lifetime at least as long
220 as the lifetime of this object. */
221 lookup_name_info (const std::string
&name
,
222 symbol_name_match_type match_type
,
223 bool completion_mode
= false,
224 bool ignore_parameters
= false)
225 : m_match_type (match_type
),
226 m_completion_mode (completion_mode
),
227 m_ignore_parameters (ignore_parameters
),
231 /* This overload requires that NAME have a lifetime at least as long
232 as the lifetime of this object. */
233 lookup_name_info (const char *name
,
234 symbol_name_match_type match_type
,
235 bool completion_mode
= false,
236 bool ignore_parameters
= false)
237 : m_match_type (match_type
),
238 m_completion_mode (completion_mode
),
239 m_ignore_parameters (ignore_parameters
),
243 /* Getters. See description of each corresponding field. */
244 symbol_name_match_type
match_type () const { return m_match_type
; }
245 bool completion_mode () const { return m_completion_mode
; }
246 std::string_view
name () const { return m_name
; }
247 const bool ignore_parameters () const { return m_ignore_parameters
; }
249 /* Like the "name" method but guarantees that the returned string is
251 const char *c_str () const
253 /* Actually this is always guaranteed due to how the class is
255 return m_name
.data ();
258 /* Return a version of this lookup name that is usable with
259 comparisons against symbols have no parameter info, such as
260 psymbols and GDB index symbols. */
261 lookup_name_info
make_ignore_params () const
263 return lookup_name_info (c_str (), m_match_type
, m_completion_mode
,
264 true /* ignore params */);
267 /* Get the search name hash for searches in language LANG. */
268 unsigned int search_name_hash (language lang
) const;
270 /* Get the search name for searches in language LANG. */
271 const char *language_lookup_name (language lang
) const
276 return ada ().lookup_name ().c_str ();
278 return cplus ().lookup_name ().c_str ();
280 return d ().lookup_name ().c_str ();
282 return go ().lookup_name ().c_str ();
284 return m_name
.data ();
288 /* A wrapper for ::split_name (see split-name.h) that splits this
289 name, and that handles any language-specific peculiarities. */
290 std::vector
<std::string_view
> split_name (language lang
) const
292 if (lang
== language_ada
)
293 return ada ().split_name ();
294 split_style style
= split_style::NONE
;
299 style
= split_style::CXX
;
303 style
= split_style::DOT_STYLE
;
306 return ::split_name (language_lookup_name (lang
), style
);
309 /* Get the Ada-specific lookup info. */
310 const ada_lookup_name_info
&ada () const
316 /* Get the C++-specific lookup info. */
317 const demangle_for_lookup_info
&cplus () const
319 maybe_init (m_cplus
, language_cplus
);
323 /* Get the D-specific lookup info. */
324 const demangle_for_lookup_info
&d () const
326 maybe_init (m_d
, language_d
);
330 /* Get the Go-specific lookup info. */
331 const demangle_for_lookup_info
&go () const
333 maybe_init (m_go
, language_go
);
337 /* Get a reference to a lookup_name_info object that matches any
339 static const lookup_name_info
&match_any ();
342 /* Initialize FIELD, if not initialized yet. */
343 template<typename Field
, typename
... Args
>
344 void maybe_init (Field
&field
, Args
&&... args
) const
347 field
.emplace (*this, std::forward
<Args
> (args
)...);
350 /* The lookup info as passed to the ctor. */
351 symbol_name_match_type m_match_type
;
352 bool m_completion_mode
;
353 bool m_ignore_parameters
;
354 std::string_view m_name
;
356 /* Language-specific info. These fields are filled lazily the first
357 time a lookup is done in the corresponding language. They're
358 mutable because lookup_name_info objects are typically passed
359 around by const reference (see intro), and they're conceptually
360 "cache" that can always be reconstructed from the non-mutable
362 mutable std::optional
<ada_lookup_name_info
> m_ada
;
363 mutable std::optional
<demangle_for_lookup_info
> m_cplus
;
364 mutable std::optional
<demangle_for_lookup_info
> m_d
;
365 mutable std::optional
<demangle_for_lookup_info
> m_go
;
367 /* The demangled hashes. Stored in an array with one entry for each
368 possible language. The second array records whether we've
369 already computed the each language's hash. (These are separate
370 arrays instead of a single array of optional<unsigned> to avoid
371 alignment padding). */
372 mutable std::array
<unsigned int, nr_languages
> m_demangled_hashes
;
373 mutable std::array
<bool, nr_languages
> m_demangled_hashes_p
{};
376 /* Comparison function for completion symbol lookup.
378 Returns true if the symbol name matches against LOOKUP_NAME.
380 SYMBOL_SEARCH_NAME should be a symbol's "search" name.
382 On success and if non-NULL, COMP_MATCH_RES->match is set to point
383 to the symbol name as should be presented to the user as a
384 completion match list element. In most languages, this is the same
385 as the symbol's search name, but in some, like Ada, the display
386 name is dynamically computed within the comparison routine.
388 Also, on success and if non-NULL, COMP_MATCH_RES->match_for_lcd
389 points the part of SYMBOL_SEARCH_NAME that was considered to match
390 LOOKUP_NAME. E.g., in C++, in linespec/wild mode, if the symbol is
391 "foo::function()" and LOOKUP_NAME is "function(", MATCH_FOR_LCD
392 points to "function()" inside SYMBOL_SEARCH_NAME. */
393 typedef bool (symbol_name_matcher_ftype
)
394 (const char *symbol_search_name
,
395 const lookup_name_info
&lookup_name
,
396 completion_match_result
*comp_match_res
);
398 /* Some of the structures in this file are space critical.
399 The space-critical structures are:
401 struct general_symbol_info
403 struct partial_symbol
405 These structures are laid out to encourage good packing.
406 They use ENUM_BITFIELD and short int fields, and they order the
407 structure members so that fields less than a word are next
408 to each other so they can be packed together. */
410 /* Rearranged: used ENUM_BITFIELD and rearranged field order in
411 all the space critical structures (plus struct minimal_symbol).
412 Memory usage dropped from 99360768 bytes to 90001408 bytes.
413 I measured this with before-and-after tests of
414 "HEAD-old-gdb -readnow HEAD-old-gdb" and
415 "HEAD-new-gdb -readnow HEAD-old-gdb" on native i686-pc-linux-gnu,
416 red hat linux 8, with LD_LIBRARY_PATH=/usr/lib/debug,
417 typing "maint space 1" at the first command prompt.
419 Here is another measurement (from andrew c):
420 # no /usr/lib/debug, just plain glibc, like a normal user
422 (gdb) break internal_error
424 (gdb) maint internal-error
428 gdb gdb_6_0_branch 2003-08-19 space used: 8896512
429 gdb HEAD 2003-08-19 space used: 8904704
430 gdb HEAD 2003-08-21 space used: 8396800 (+symtab.h)
431 gdb HEAD 2003-08-21 space used: 8265728 (+gdbtypes.h)
433 The third line shows the savings from the optimizations in symtab.h.
434 The fourth line shows the savings from the optimizations in
435 gdbtypes.h. Both optimizations are in gdb HEAD now.
437 --chastain 2003-08-21 */
439 /* Define a structure for the information that is common to all symbol types,
440 including minimal symbols, partial symbols, and full symbols. In a
441 multilanguage environment, some language specific information may need to
442 be recorded along with each symbol. */
444 /* This structure is space critical. See space comments at the top. */
446 struct general_symbol_info
448 /* Short version as to when to use which name accessor:
449 Use natural_name () to refer to the name of the symbol in the original
450 source code. Use linkage_name () if you want to know what the linker
451 thinks the symbol's name is. Use print_name () for output. Use
452 demangled_name () if you specifically need to know whether natural_name ()
453 and linkage_name () are different. */
455 const char *linkage_name () const
458 /* Return SYMBOL's "natural" name, i.e. the name that it was called in
459 the original source code. In languages like C++ where symbols may
460 be mangled for ease of manipulation by the linker, this is the
462 const char *natural_name () const;
464 /* Returns a version of the name of a symbol that is
465 suitable for output. In C++ this is the "demangled" form of the
466 name if demangle is on and the "mangled" form of the name if
467 demangle is off. In other languages this is just the symbol name.
468 The result should never be NULL. Don't use this for internal
469 purposes (e.g. storing in a hashtable): it's only suitable for output. */
470 const char *print_name () const
471 { return demangle
? natural_name () : linkage_name (); }
473 /* Return the demangled name for a symbol based on the language for
474 that symbol. If no demangled name exists, return NULL. */
475 const char *demangled_name () const;
477 /* Returns the name to be used when sorting and searching symbols.
478 In C++, we search for the demangled form of a name,
479 and so sort symbols accordingly. In Ada, however, we search by mangled
480 name. If there is no distinct demangled name, then this
481 returns the same value (same pointer) as linkage_name (). */
482 const char *search_name () const;
484 /* Set just the linkage name of a symbol; do not try to demangle
485 it. Used for constructs which do not have a mangled name,
486 e.g. struct tags. Unlike compute_and_set_names, linkage_name must
487 be terminated and either already on the objfile's obstack or
488 permanently allocated. */
489 void set_linkage_name (const char *linkage_name
)
490 { m_name
= linkage_name
; }
492 /* Set the demangled name of this symbol to NAME. NAME must be
493 already correctly allocated. If the symbol's language is Ada,
494 then the name is ignored and the obstack is set. */
495 void set_demangled_name (const char *name
, struct obstack
*obstack
);
497 enum language
language () const
498 { return m_language
; }
500 /* Initializes the language dependent portion of a symbol
501 depending upon the language for the symbol. */
502 void set_language (enum language language
, struct obstack
*obstack
);
504 /* Set the linkage and natural names of a symbol, by demangling
505 the linkage name. If linkage_name may not be nullterminated,
506 copy_name must be set to true. */
507 void compute_and_set_names (std::string_view linkage_name
, bool copy_name
,
508 struct objfile_per_bfd_storage
*per_bfd
,
509 std::optional
<hashval_t
> hash
510 = std::optional
<hashval_t
> ());
512 CORE_ADDR
value_address () const
514 return m_value
.address
;
517 void set_value_address (CORE_ADDR address
)
519 m_value
.address
= address
;
522 /* Return the unrelocated address of this symbol. */
523 unrelocated_addr
unrelocated_address () const
525 return m_value
.unrel_addr
;
528 /* Set the unrelocated address of this symbol. */
529 void set_unrelocated_address (unrelocated_addr addr
)
531 m_value
.unrel_addr
= addr
;
534 /* Name of the symbol. This is a required field. Storage for the
535 name is allocated on the objfile_obstack for the associated
536 objfile. For languages like C++ that make a distinction between
537 the mangled name and demangled name, this is the mangled
542 /* Value of the symbol. Which member of this union to use, and what
543 it means, depends on what kind of symbol this is and its
544 SYMBOL_CLASS. See comments there for more details. All of these
545 are in host byte order (though what they point to might be in
546 target byte order, e.g. LOC_CONST_BYTES). */
552 const struct block
*block
;
554 const gdb_byte
*bytes
;
558 /* The address, if unrelocated. An unrelocated symbol does not
559 have the runtime section offset applied. */
560 unrelocated_addr unrel_addr
;
562 /* A common block. Used with LOC_COMMON_BLOCK. */
564 const struct common_block
*common_block
;
566 /* For opaque typedef struct chain. */
568 struct symbol
*chain
;
572 /* Since one and only one language can apply, wrap the language specific
573 information inside a union. */
577 /* A pointer to an obstack that can be used for storage associated
578 with this symbol. This is only used by Ada, and only when the
579 'ada_mangled' field is zero. */
580 struct obstack
*obstack
;
582 /* This is used by languages which wish to store a demangled name.
583 currently used by Ada, C++, and Objective C. */
584 const char *demangled_name
;
588 /* Record the source code language that applies to this symbol.
589 This is used to select one of the fields from the language specific
592 ENUM_BITFIELD(language
) m_language
: LANGUAGE_BITS
;
594 /* This is only used by Ada. If set, then the 'demangled_name' field
595 of language_specific is valid. Otherwise, the 'obstack' field is
597 unsigned int ada_mangled
: 1;
599 /* Which section is this symbol in? This is an index into
600 section_offsets for this objfile. Negative means that the symbol
601 does not get relocated relative to a section. */
605 /* Set the index into the obj_section list (within the containing
606 objfile) for the section that contains this symbol. See M_SECTION
609 void set_section_index (int idx
)
612 /* Return the index into the obj_section list (within the containing
613 objfile) for the section that contains this symbol. See M_SECTION
616 auto section_index () const
617 { return m_section
; }
619 /* Return the obj_section from OBJFILE for this symbol. The symbol
620 returned is based on the SECTION member variable, and can be nullptr
621 if SECTION is negative. */
623 struct obj_section
*obj_section (const struct objfile
*objfile
) const;
626 extern CORE_ADDR
symbol_overlayed_address (CORE_ADDR
, struct obj_section
*);
628 /* Try to determine the demangled name for a symbol, based on the
629 language of that symbol. If the language is set to language_auto,
630 it will attempt to find any demangling algorithm that works and
631 then set the language appropriately. The returned name is allocated
632 by the demangler and should be xfree'd. */
634 extern gdb::unique_xmalloc_ptr
<char> symbol_find_demangled_name
635 (struct general_symbol_info
*gsymbol
, const char *mangled
);
637 /* Return true if NAME matches the "search" name of GSYMBOL, according
638 to the symbol's language. */
639 extern bool symbol_matches_search_name
640 (const struct general_symbol_info
*gsymbol
,
641 const lookup_name_info
&name
);
643 /* Compute the hash of the given symbol search name of a symbol of
644 language LANGUAGE. */
645 extern unsigned int search_name_hash (enum language language
,
646 const char *search_name
);
648 /* Classification types for a minimal symbol. These should be taken as
649 "advisory only", since if gdb can't easily figure out a
650 classification it simply selects mst_unknown. It may also have to
651 guess when it can't figure out which is a better match between two
652 types (mst_data versus mst_bss) for example. Since the minimal
653 symbol info is sometimes derived from the BFD library's view of a
654 file, we need to live with what information bfd supplies. */
656 enum minimal_symbol_type
658 mst_unknown
= 0, /* Unknown type, the default */
659 mst_text
, /* Generally executable instructions */
661 /* A GNU ifunc symbol, in the .text section. GDB uses to know
662 whether the user is setting a breakpoint on a GNU ifunc function,
663 and thus GDB needs to actually set the breakpoint on the target
664 function. It is also used to know whether the program stepped
665 into an ifunc resolver -- the resolver may get a separate
666 symbol/alias under a different name, but it'll have the same
667 address as the ifunc symbol. */
668 mst_text_gnu_ifunc
, /* Executable code returning address
669 of executable code */
671 /* A GNU ifunc function descriptor symbol, in a data section
672 (typically ".opd"). Seen on architectures that use function
673 descriptors, like PPC64/ELFv1. In this case, this symbol's value
674 is the address of the descriptor. There'll be a corresponding
675 mst_text_gnu_ifunc synthetic symbol for the text/entry
677 mst_data_gnu_ifunc
, /* Executable code returning address
678 of executable code */
680 mst_slot_got_plt
, /* GOT entries for .plt sections */
681 mst_data
, /* Generally initialized data */
682 mst_bss
, /* Generally uninitialized data */
683 mst_abs
, /* Generally absolute (nonrelocatable) */
684 /* GDB uses mst_solib_trampoline for the start address of a shared
685 library trampoline entry. Breakpoints for shared library functions
686 are put there if the shared library is not yet loaded.
687 After the shared library is loaded, lookup_minimal_symbol will
688 prefer the minimal symbol from the shared library (usually
689 a mst_text symbol) over the mst_solib_trampoline symbol, and the
690 breakpoints will be moved to their true address in the shared
691 library via breakpoint_re_set. */
692 mst_solib_trampoline
, /* Shared library trampoline code */
693 /* For the mst_file* types, the names are only guaranteed to be unique
694 within a given .o file. */
695 mst_file_text
, /* Static version of mst_text */
696 mst_file_data
, /* Static version of mst_data */
697 mst_file_bss
, /* Static version of mst_bss */
701 /* The number of enum minimal_symbol_type values, with some padding for
702 reasonable growth. */
703 #define MINSYM_TYPE_BITS 4
704 static_assert (nr_minsym_types
<= (1 << MINSYM_TYPE_BITS
));
706 /* Define a simple structure used to hold some very basic information about
707 all defined global symbols (text, data, bss, abs, etc). The only required
708 information is the general_symbol_info.
710 In many cases, even if a file was compiled with no special options for
711 debugging at all, as long as was not stripped it will contain sufficient
712 information to build a useful minimal symbol table using this structure.
713 Even when a file contains enough debugging information to build a full
714 symbol table, these minimal symbols are still useful for quickly mapping
715 between names and addresses, and vice versa. They are also sometimes
716 used to figure out what full symbol table entries need to be read in. */
718 struct minimal_symbol
: public general_symbol_info
720 LONGEST
value_longest () const
722 return m_value
.ivalue
;
725 /* The relocated address of the minimal symbol, using the section
726 offsets from OBJFILE. */
727 CORE_ADDR
value_address (objfile
*objfile
) const;
729 /* It does not make sense to call this for minimal symbols, as they
730 are stored unrelocated. */
731 CORE_ADDR
value_address () const = delete;
733 /* The unrelocated address of the minimal symbol. */
734 unrelocated_addr
unrelocated_address () const
736 return m_value
.unrel_addr
;
739 /* The unrelocated address just after the end of the the minimal
741 unrelocated_addr
unrelocated_end_address () const
743 return unrelocated_addr (CORE_ADDR (unrelocated_address ()) + size ());
746 /* Return this minimal symbol's type. */
748 minimal_symbol_type
type () const
753 /* Set this minimal symbol's type. */
755 void set_type (minimal_symbol_type type
)
760 /* Return this minimal symbol's size. */
762 unsigned long size () const
767 /* Set this minimal symbol's size. */
769 void set_size (unsigned long size
)
775 /* Return true if this minimal symbol's size is known. */
777 bool has_size () const
782 /* Return this minimal symbol's first target-specific flag. */
784 bool target_flag_1 () const
786 return m_target_flag_1
;
789 /* Set this minimal symbol's first target-specific flag. */
791 void set_target_flag_1 (bool target_flag_1
)
793 m_target_flag_1
= target_flag_1
;
796 /* Return this minimal symbol's second target-specific flag. */
798 bool target_flag_2 () const
800 return m_target_flag_2
;
803 /* Set this minimal symbol's second target-specific flag. */
805 void set_target_flag_2 (bool target_flag_2
)
807 m_target_flag_2
= target_flag_2
;
810 /* Size of this symbol. stabs_end_psymtab in stabsread.c uses this
811 information to calculate the end of the partial symtab based on the
812 address of the last symbol plus the size of the last symbol. */
814 unsigned long m_size
;
816 /* Which source file is this symbol in? Only relevant for mst_file_*. */
817 const char *filename
;
819 /* Classification type for this minimal symbol. */
821 ENUM_BITFIELD(minimal_symbol_type
) m_type
: MINSYM_TYPE_BITS
;
823 /* Non-zero if this symbol was created by gdb.
824 Such symbols do not appear in the output of "info var|fun". */
825 unsigned int created_by_gdb
: 1;
827 /* Two flag bits provided for the use of the target. */
828 unsigned int m_target_flag_1
: 1;
829 unsigned int m_target_flag_2
: 1;
831 /* Nonzero iff the size of the minimal symbol has been set.
832 Symbol size information can sometimes not be determined, because
833 the object file format may not carry that piece of information. */
834 unsigned int m_has_size
: 1;
836 /* Non-zero if this symbol ever had its demangled name set (even if
837 it was set to NULL). */
838 unsigned int name_set
: 1;
840 /* Minimal symbols with the same hash key are kept on a linked
841 list. This is the link. */
843 struct minimal_symbol
*hash_next
;
845 /* Minimal symbols are stored in two different hash tables. This is
846 the `next' pointer for the demangled hash table. */
848 struct minimal_symbol
*demangled_hash_next
;
850 /* True if this symbol is of some data type. */
852 bool data_p () const;
854 /* True if MSYMBOL is of some text type. */
856 bool text_p () const;
858 /* For data symbols only, given an objfile, if 'maybe_copied'
859 evaluates to 'true' for that objfile, then the symbol might be
860 subject to copy relocation. In this case, a minimal symbol
861 matching the symbol's linkage name is first looked for in the
862 main objfile. If found, then that address is used; otherwise the
863 address in this symbol is used. */
865 bool maybe_copied (objfile
*objfile
) const;
868 /* Return the address of this minimal symbol, in the context of OBJF. The
869 MAYBE_COPIED flag must be set. If the minimal symbol appears in the
870 main program's minimal symbols, then that minsym's address is
871 returned; otherwise, this minimal symbol's address is returned. */
872 CORE_ADDR
get_maybe_copied_address (objfile
*objf
) const;
879 /* Represent one symbol name; a variable, constant, function or typedef. */
881 /* Different name domains for symbols. Looking up a symbol specifies a
882 domain and ignores symbol definitions in other name domains. */
886 #define SYM_DOMAIN(X) X ## _DOMAIN,
887 #include "sym-domains.def"
891 /* The number of bits in a symbol used to represent the domain. */
893 #define SYMBOL_DOMAIN_BITS 3
895 extern const char *domain_name (domain_enum
);
897 /* Flags used for searching symbol tables. These can be combined to
898 let the search match multiple kinds of symbol. */
899 enum domain_search_flag
901 #define SYM_DOMAIN(X) \
902 SEARCH_ ## X ## _DOMAIN = (1 << X ## _DOMAIN),
903 #include "sym-domains.def"
906 DEF_ENUM_FLAGS_TYPE (enum domain_search_flag
, domain_search_flags
);
908 /* A convenience constant to search for any symbol. */
909 constexpr domain_search_flags SEARCH_ALL_DOMAINS
910 = ((domain_search_flags
) 0
911 #define SYM_DOMAIN(X) | SEARCH_ ## X ## _DOMAIN
912 #include "sym-domains.def"
916 /* A convenience define for "C-like" name lookups, matching variables,
917 types, and functions. */
919 (SEARCH_VAR_DOMAIN | SEARCH_FUNCTION_DOMAIN | SEARCH_TYPE_DOMAIN)
921 /* Return a string representing the given flags. */
922 extern std::string
domain_name (domain_search_flags
);
924 /* Convert a symbol domain to search flags. */
925 static inline domain_search_flags
926 to_search_flags (domain_enum domain
)
928 return domain_search_flags (domain_search_flag (1 << domain
));
931 /* Return true if the given domain matches the given flags, false
934 search_flags_matches (domain_search_flags flags
, domain_enum domain
)
936 return (flags
& to_search_flags (domain
)) != 0;
939 /* Some helpers for Python and Guile to account for backward
940 compatibility. Those exposed the domains for lookup as well as
941 checking attributes of a symbol, so special encoding and decoding
942 is needed to continue to support both uses. Domain constants must
943 remain unchanged, so that comparing a symbol's domain against a
944 constant yields the correct result, so search symbols are
945 distinguished by adding a flag bit. This way, either sort of
946 constant can be used for lookup. */
949 constexpr int SCRIPTING_SEARCH_FLAG
= 0x8000;
950 static_assert (SCRIPTING_SEARCH_FLAG
> SEARCH_ALL_DOMAINS
);
952 /* Convert a domain constant to a "scripting domain". */
953 static constexpr inline int
954 to_scripting_domain (domain_enum val
)
959 /* Convert a search constant to a "scripting domain". */
960 static constexpr inline int
961 to_scripting_domain (domain_search_flags val
)
963 return SCRIPTING_SEARCH_FLAG
| (int) val
;
966 /* Convert from a "scripting domain" constant back to search flags.
967 Throws an exception if VAL is not one of the allowable values. */
968 extern domain_search_flags
from_scripting_domain (int val
);
970 /* An address-class says where to find the value of a symbol. */
974 /* Not used; catches errors. */
978 /* Value is constant int SYMBOL_VALUE, host byteorder. */
982 /* Value is at fixed address SYMBOL_VALUE_ADDRESS. */
986 /* Value is in register. SYMBOL_VALUE is the register number
987 in the original debug format. SYMBOL_REGISTER_OPS holds a
988 function that can be called to transform this into the
989 actual register number this represents in a specific target
990 architecture (gdbarch).
992 For some symbol formats (stabs, for some compilers at least),
993 the compiler generates two symbols, an argument and a register.
994 In some cases we combine them to a single LOC_REGISTER in symbol
995 reading, but currently not for all cases (e.g. it's passed on the
996 stack and then loaded into a register). */
1000 /* It's an argument; the value is at SYMBOL_VALUE offset in arglist. */
1004 /* Value address is at SYMBOL_VALUE offset in arglist. */
1008 /* Value is in specified register. Just like LOC_REGISTER except the
1009 register holds the address of the argument instead of the argument
1010 itself. This is currently used for the passing of structs and unions
1011 on sparc and hppa. It is also used for call by reference where the
1012 address is in a register, at least by mipsread.c. */
1016 /* Value is a local variable at SYMBOL_VALUE offset in stack frame. */
1020 /* Value not used; definition in SYMBOL_TYPE. Symbols in the domain
1021 STRUCT_DOMAIN all have this class. */
1025 /* Value is address SYMBOL_VALUE_ADDRESS in the code. */
1029 /* In a symbol table, value is SYMBOL_BLOCK_VALUE of a `struct block'.
1030 In a partial symbol table, SYMBOL_VALUE_ADDRESS is the start address
1031 of the block. Function names have this class. */
1035 /* Value is a constant byte-sequence pointed to by SYMBOL_VALUE_BYTES, in
1036 target byte order. */
1040 /* Value is at fixed address, but the address of the variable has
1041 to be determined from the minimal symbol table whenever the
1042 variable is referenced.
1043 This happens if debugging information for a global symbol is
1044 emitted and the corresponding minimal symbol is defined
1045 in another object file or runtime common storage.
1046 The linker might even remove the minimal symbol if the global
1047 symbol is never referenced, in which case the symbol remains
1050 GDB would normally find the symbol in the minimal symbol table if it will
1051 not find it in the full symbol table. But a reference to an external
1052 symbol in a local block shadowing other definition requires full symbol
1053 without possibly having its address available for LOC_STATIC. Testcase
1054 is provided as `gdb.dwarf2/dw2-unresolved.exp'.
1056 This is also used for thread local storage (TLS) variables. In
1057 this case, the address of the TLS variable must be determined
1058 when the variable is referenced, from the msymbol's address,
1059 which is the offset of the TLS variable in the thread local
1060 storage of the shared library/object. */
1064 /* The variable does not actually exist in the program.
1065 The value is ignored. */
1069 /* The variable's address is computed by a set of location
1070 functions (see "struct symbol_computed_ops" below). */
1073 /* The variable uses general_symbol_info->value->common_block field.
1074 It also always uses COMMON_BLOCK_DOMAIN. */
1077 /* Not used, just notes the boundary of the enum. */
1081 /* The number of bits needed for values in enum address_class, with some
1082 padding for reasonable growth, and room for run-time registered address
1083 classes. See symtab.c:MAX_SYMBOL_IMPLS.
1084 This is a #define so that we can have a assertion elsewhere to
1085 verify that we have reserved enough space for synthetic address
1087 #define SYMBOL_ACLASS_BITS 5
1088 static_assert (LOC_FINAL_VALUE
<= (1 << SYMBOL_ACLASS_BITS
));
1090 /* The methods needed to implement LOC_COMPUTED. These methods can
1091 use the symbol's .aux_value for additional per-symbol information.
1093 At present this is only used to implement location expressions. */
1095 struct symbol_computed_ops
1098 /* Return the value of the variable SYMBOL, relative to the stack
1099 frame FRAME. If the variable has been optimized out, return
1102 Iff `read_needs_frame (SYMBOL)' is not SYMBOL_NEEDS_FRAME, then
1103 FRAME may be zero. */
1105 struct value
*(*read_variable
) (struct symbol
* symbol
,
1106 const frame_info_ptr
&frame
);
1108 /* Read variable SYMBOL like read_variable at (callee) FRAME's function
1109 entry. SYMBOL should be a function parameter, otherwise
1110 NO_ENTRY_VALUE_ERROR will be thrown. */
1111 struct value
*(*read_variable_at_entry
) (struct symbol
*symbol
,
1112 const frame_info_ptr
&frame
);
1114 /* Find the "symbol_needs_kind" value for the given symbol. This
1115 value determines whether reading the symbol needs memory (e.g., a
1116 global variable), just registers (a thread-local), or a frame (a
1118 enum symbol_needs_kind (*get_symbol_read_needs
) (struct symbol
* symbol
);
1120 /* Write to STREAM a natural-language description of the location of
1121 SYMBOL, in the context of ADDR. */
1122 void (*describe_location
) (struct symbol
* symbol
, CORE_ADDR addr
,
1123 struct ui_file
* stream
);
1125 /* Non-zero if this symbol's address computation is dependent on PC. */
1126 unsigned char location_has_loclist
;
1128 /* Tracepoint support. Append bytecodes to the tracepoint agent
1129 expression AX that push the address of the object SYMBOL. Set
1130 VALUE appropriately. Note --- for objects in registers, this
1131 needn't emit any code; as long as it sets VALUE properly, then
1132 the caller will generate the right code in the process of
1133 treating this as an lvalue or rvalue. */
1135 void (*tracepoint_var_ref
) (struct symbol
*symbol
, struct agent_expr
*ax
,
1136 struct axs_value
*value
);
1138 /* Generate C code to compute the location of SYMBOL. The C code is
1139 emitted to STREAM. GDBARCH is the current architecture and PC is
1140 the PC at which SYMBOL's location should be evaluated.
1141 REGISTERS_USED is a vector indexed by register number; the
1142 generator function should set an element in this vector if the
1143 corresponding register is needed by the location computation.
1144 The generated C code must assign the location to a local
1145 variable; this variable's name is RESULT_NAME. */
1147 void (*generate_c_location
) (struct symbol
*symbol
, string_file
*stream
,
1148 struct gdbarch
*gdbarch
,
1149 std::vector
<bool> ®isters_used
,
1150 CORE_ADDR pc
, const char *result_name
);
1154 /* The methods needed to implement LOC_BLOCK for inferior functions.
1155 These methods can use the symbol's .aux_value for additional
1156 per-symbol information. */
1158 struct symbol_block_ops
1160 /* Fill in *START and *LENGTH with DWARF block data of function
1161 FRAMEFUNC valid for inferior context address PC. Set *LENGTH to
1162 zero if such location is not valid for PC; *START is left
1163 uninitialized in such case. */
1164 void (*find_frame_base_location
) (struct symbol
*framefunc
, CORE_ADDR pc
,
1165 const gdb_byte
**start
, size_t *length
);
1167 /* Return the frame base address. FRAME is the frame for which we want to
1168 compute the base address while FRAMEFUNC is the symbol for the
1169 corresponding function. Return 0 on failure (FRAMEFUNC may not hold the
1170 information we need).
1172 This method is designed to work with static links (nested functions
1173 handling). Static links are function properties whose evaluation returns
1174 the frame base address for the enclosing frame. However, there are
1175 multiple definitions for "frame base": the content of the frame base
1176 register, the CFA as defined by DWARF unwinding information, ...
1178 So this specific method is supposed to compute the frame base address such
1179 as for nested functions, the static link computes the same address. For
1180 instance, considering DWARF debugging information, the static link is
1181 computed with DW_AT_static_link and this method must be used to compute
1182 the corresponding DW_AT_frame_base attribute. */
1183 CORE_ADDR (*get_frame_base
) (struct symbol
*framefunc
,
1184 const frame_info_ptr
&frame
);
1186 /* Return the block for this function. So far, this is used to
1187 implement function aliases. So, if this is set, then it's not
1188 necessary to set the other functions in this structure; and vice
1190 const block
*(*get_block_value
) (const struct symbol
*sym
);
1193 /* Functions used with LOC_REGISTER and LOC_REGPARM_ADDR. */
1195 struct symbol_register_ops
1197 int (*register_number
) (struct symbol
*symbol
, struct gdbarch
*gdbarch
);
1200 /* Objects of this type are used to find the address class and the
1201 various computed ops vectors of a symbol. */
1205 enum address_class aclass
;
1207 /* Used with LOC_COMPUTED. */
1208 const struct symbol_computed_ops
*ops_computed
;
1210 /* Used with LOC_BLOCK. */
1211 const struct symbol_block_ops
*ops_block
;
1213 /* Used with LOC_REGISTER and LOC_REGPARM_ADDR. */
1214 const struct symbol_register_ops
*ops_register
;
1217 /* struct symbol has some subclasses. This enum is used to
1218 differentiate between them. */
1220 enum symbol_subclass_kind
1222 /* Plain struct symbol. */
1225 /* struct template_symbol. */
1228 /* struct rust_vtable_symbol. */
1232 extern gdb::array_view
<const struct symbol_impl
> symbol_impls
;
1234 /* This structure is space critical. See space comments at the top. */
1236 struct symbol
: public general_symbol_info
, public allocate_on_obstack
<symbol
>
1239 /* Class-initialization of bitfields is only allowed in C++20. */
1240 : m_domain (UNDEF_DOMAIN
),
1242 m_is_objfile_owned (1),
1246 subclass (SYMBOL_NONE
),
1247 m_artificial (false)
1249 /* We can't use an initializer list for members of a base class, and
1250 general_symbol_info needs to stay a POD type. */
1253 language_specific
.obstack
= nullptr;
1254 m_language
= language_unknown
;
1257 /* GCC 4.8.5 (on CentOS 7) does not correctly compile class-
1258 initialization of unions, so we initialize it manually here. */
1259 owner
.symtab
= nullptr;
1262 symbol (const symbol
&) = default;
1263 symbol
&operator= (const symbol
&) = default;
1265 void set_aclass_index (unsigned int aclass_index
)
1267 m_aclass_index
= aclass_index
;
1270 const symbol_impl
&impl () const
1272 return symbol_impls
[this->m_aclass_index
];
1275 const symbol_block_ops
*block_ops () const
1277 return this->impl ().ops_block
;
1280 const symbol_computed_ops
*computed_ops () const
1282 return this->impl ().ops_computed
;
1285 const symbol_register_ops
*register_ops () const
1287 return this->impl ().ops_register
;
1290 address_class
aclass () const
1292 return this->impl ().aclass
;
1295 /* Return true if this symbol's domain matches FLAGS. */
1296 bool matches (domain_search_flags flags
) const;
1298 domain_enum
domain () const
1303 void set_domain (domain_enum domain
)
1308 bool is_objfile_owned () const
1310 return m_is_objfile_owned
;
1313 void set_is_objfile_owned (bool is_objfile_owned
)
1315 m_is_objfile_owned
= is_objfile_owned
;
1318 bool is_argument () const
1320 return m_is_argument
;
1323 void set_is_argument (bool is_argument
)
1325 m_is_argument
= is_argument
;
1328 bool is_inlined () const
1330 return m_is_inlined
;
1333 void set_is_inlined (bool is_inlined
)
1335 m_is_inlined
= is_inlined
;
1338 /* Return true if this symbol is a template function. Template
1339 functions actually are of type 'template_symbol' and have extra
1340 symbols (the template parameters) attached. */
1342 bool is_template_function () const
1344 return this->subclass
== SYMBOL_TEMPLATE
;
1347 struct type
*type () const
1352 void set_type (struct type
*type
)
1357 unsigned int line () const
1362 void set_line (unsigned int line
)
1367 LONGEST
value_longest () const
1369 return m_value
.ivalue
;
1372 void set_value_longest (LONGEST value
)
1374 m_value
.ivalue
= value
;
1377 CORE_ADDR
value_address () const
1379 if (this->maybe_copied
)
1380 return this->get_maybe_copied_address ();
1382 return m_value
.address
;
1385 void set_value_address (CORE_ADDR address
)
1387 m_value
.address
= address
;
1390 const gdb_byte
*value_bytes () const
1392 return m_value
.bytes
;
1395 void set_value_bytes (const gdb_byte
*bytes
)
1397 m_value
.bytes
= bytes
;
1400 const common_block
*value_common_block () const
1402 return m_value
.common_block
;
1405 void set_value_common_block (const common_block
*common_block
)
1407 m_value
.common_block
= common_block
;
1410 const block
*value_block () const;
1412 void set_value_block (const block
*block
)
1414 m_value
.block
= block
;
1417 symbol
*value_chain () const
1419 return m_value
.chain
;
1422 void set_value_chain (symbol
*sym
)
1424 m_value
.chain
= sym
;
1427 /* Return true if this symbol was marked as artificial. */
1428 bool is_artificial () const
1430 return m_artificial
;
1433 /* Set the 'artificial' flag on this symbol. */
1434 void set_is_artificial (bool artificial
)
1436 m_artificial
= artificial
;
1439 /* Return the OBJFILE of this symbol. It is an error to call this
1440 if is_objfile_owned is false, which only happens for
1441 architecture-provided types. */
1443 struct objfile
*objfile () const;
1445 /* Return the ARCH of this symbol. */
1447 struct gdbarch
*arch () const;
1449 /* Return the symtab of this symbol. It is an error to call this if
1450 is_objfile_owned is false, which only happens for
1451 architecture-provided types. */
1453 struct symtab
*symtab () const;
1455 /* Set the symtab of this symbol to SYMTAB. It is an error to call
1456 this if is_objfile_owned is false, which only happens for
1457 architecture-provided types. */
1459 void set_symtab (struct symtab
*symtab
);
1461 /* Data type of value */
1463 struct type
*m_type
= nullptr;
1465 /* The owner of this symbol.
1466 Which one to use is defined by symbol.is_objfile_owned. */
1470 /* The symbol table containing this symbol. This is the file associated
1471 with LINE. It can be NULL during symbols read-in but it is never NULL
1472 during normal operation. */
1473 struct symtab
*symtab
;
1475 /* For types defined by the architecture. */
1476 struct gdbarch
*arch
;
1481 ENUM_BITFIELD(domain_enum
) m_domain
: SYMBOL_DOMAIN_BITS
;
1483 /* Address class. This holds an index into the 'symbol_impls'
1484 table. The actual enum address_class value is stored there,
1485 alongside any per-class ops vectors. */
1487 unsigned int m_aclass_index
: SYMBOL_ACLASS_BITS
;
1489 /* If non-zero then symbol is objfile-owned, use owner.symtab.
1490 Otherwise symbol is arch-owned, use owner.arch. */
1492 unsigned int m_is_objfile_owned
: 1;
1494 /* Whether this is an argument. */
1496 unsigned m_is_argument
: 1;
1498 /* Whether this is an inlined function (class LOC_BLOCK only). */
1499 unsigned m_is_inlined
: 1;
1501 /* For LOC_STATIC only, if this is set, then the symbol might be
1502 subject to copy relocation. In this case, a minimal symbol
1503 matching the symbol's linkage name is first looked for in the
1504 main objfile. If found, then that address is used; otherwise the
1505 address in this symbol is used. */
1507 unsigned maybe_copied
: 1;
1509 /* The concrete type of this symbol. */
1511 ENUM_BITFIELD (symbol_subclass_kind
) subclass
: 2;
1513 /* Whether this symbol is artificial. */
1515 bool m_artificial
: 1;
1517 /* Line number of this symbol's definition, except for inlined
1518 functions. For an inlined function (class LOC_BLOCK and
1519 SYMBOL_INLINED set) this is the line number of the function's call
1520 site. Inlined function symbols are not definitions, and they are
1521 never found by symbol table lookup.
1522 If this symbol is arch-owned, LINE shall be zero. */
1524 unsigned int m_line
= 0;
1526 /* An arbitrary data pointer, allowing symbol readers to record
1527 additional information on a per-symbol basis. Note that this data
1528 must be allocated using the same obstack as the symbol itself. */
1529 /* So far it is only used by:
1530 LOC_COMPUTED: to find the location information
1531 LOC_BLOCK (DWARF2 function): information used internally by the
1532 DWARF 2 code --- specifically, the location expression for the frame
1533 base for this function. */
1534 /* FIXME drow/2003-02-21: For the LOC_BLOCK case, it might be better
1535 to add a magic symbol to the block containing this information,
1536 or to have a generic debug info annotation slot for symbols. */
1538 void *aux_value
= nullptr;
1540 struct symbol
*hash_next
= nullptr;
1543 /* Return the address of this symbol. The MAYBE_COPIED flag must be set.
1544 If the symbol appears in the main program's minimal symbols, then
1545 that minsym's address is returned; otherwise, this symbol's address is
1547 CORE_ADDR
get_maybe_copied_address () const;
1550 /* Several lookup functions return both a symbol and the block in which the
1551 symbol is found. This structure is used in these cases. */
1555 /* The symbol that was found, or NULL if no symbol was found. */
1556 struct symbol
*symbol
;
1558 /* If SYMBOL is not NULL, then this is the block in which the symbol is
1560 const struct block
*block
;
1563 /* Note: There is no accessor macro for symbol.owner because it is
1566 #define SYMBOL_LOCATION_BATON(symbol) (symbol)->aux_value
1568 inline const block
*
1569 symbol::value_block () const
1571 if (const symbol_block_ops
*block_ops
= this->block_ops ();
1572 block_ops
!= nullptr && block_ops
->get_block_value
!= nullptr)
1573 return block_ops
->get_block_value (this);
1575 return m_value
.block
;
1578 extern int register_symbol_computed_impl (enum address_class
,
1579 const struct symbol_computed_ops
*);
1581 extern int register_symbol_block_impl (enum address_class aclass
,
1582 const struct symbol_block_ops
*ops
);
1584 extern int register_symbol_register_impl (enum address_class
,
1585 const struct symbol_register_ops
*);
1587 /* An instance of this type is used to represent a C++ template
1588 function. A symbol is really of this type iff
1589 symbol::is_template_function is true. */
1591 struct template_symbol
: public symbol
1593 /* The number of template arguments. */
1594 int n_template_arguments
= 0;
1596 /* The template arguments. This is an array with
1597 N_TEMPLATE_ARGUMENTS elements. */
1598 struct symbol
**template_arguments
= nullptr;
1601 /* A symbol that represents a Rust virtual table object. */
1603 struct rust_vtable_symbol
: public symbol
1605 /* The concrete type for which this vtable was created; that is, in
1606 "impl Trait for Type", this is "Type". */
1607 struct type
*concrete_type
= nullptr;
1611 /* Each item represents a line-->pc (or the reverse) mapping. This is
1612 somewhat more wasteful of space than one might wish, but since only
1613 the files which are actually debugged are read in to core, we don't
1614 waste much space. */
1616 struct linetable_entry
1618 /* Set the (unrelocated) PC for this entry. */
1619 void set_unrelocated_pc (unrelocated_addr pc
)
1622 /* Return the unrelocated PC for this entry. */
1623 unrelocated_addr
unrelocated_pc () const
1626 /* Return the relocated PC for this entry. */
1627 CORE_ADDR
pc (const struct objfile
*objfile
) const;
1629 bool operator< (const linetable_entry
&other
) const
1631 if (m_pc
== other
.m_pc
1632 && (line
!= 0) != (other
.line
!= 0))
1634 return m_pc
< other
.m_pc
;
1637 /* Two entries are equal if they have the same line and PC. The
1638 other members are ignored. */
1639 bool operator== (const linetable_entry
&other
) const
1640 { return line
== other
.line
&& m_pc
== other
.m_pc
; }
1642 /* The line number for this entry. */
1645 /* True if this PC is a good location to place a breakpoint for LINE. */
1648 /* True if this location is a good location to place a breakpoint after a
1649 function prologue. */
1650 bool prologue_end
: 1;
1652 /* True if this location marks the start of the epilogue. */
1653 bool epilogue_begin
: 1;
1657 /* The address for this entry. */
1658 unrelocated_addr m_pc
;
1661 /* The order of entries in the linetable is significant. They should
1662 be sorted by increasing values of the pc field. If there is more than
1663 one entry for a given pc, then I'm not sure what should happen (and
1664 I not sure whether we currently handle it the best way).
1666 Example: a C for statement generally looks like this
1668 10 0x100 - for the init/test part of a for stmt.
1671 10 0x400 - for the increment part of a for stmt.
1673 If an entry has a line number of zero, it marks the start of a PC
1674 range for which no line number information is available. It is
1675 acceptable, though wasteful of table space, for such a range to be
1682 /* Actually NITEMS elements. If you don't like this use of the
1683 `struct hack', you can shove it up your ANSI (seriously, if the
1684 committee tells us how to do it, we can probably go along). */
1685 struct linetable_entry item
[1];
1688 /* How to relocate the symbols from each section in a symbol file.
1689 The ordering and meaning of the offsets is file-type-dependent;
1690 typically it is indexed by section numbers or symbol types or
1691 something like that. */
1693 typedef std::vector
<CORE_ADDR
> section_offsets
;
1695 /* Each source file or header is represented by a struct symtab.
1696 The name "symtab" is historical, another name for it is "filetab".
1697 These objects are chained through the `next' field. */
1701 struct compunit_symtab
*compunit () const
1706 void set_compunit (struct compunit_symtab
*compunit
)
1708 m_compunit
= compunit
;
1711 const struct linetable
*linetable () const
1716 void set_linetable (const struct linetable
*linetable
)
1718 m_linetable
= linetable
;
1721 enum language
language () const
1726 void set_language (enum language language
)
1728 m_language
= language
;
1731 /* Return the current full name of this symtab. */
1732 const char *fullname () const
1733 { return m_fullname
; }
1735 /* Transfer ownership of the current full name to the caller. The
1736 full name is reset to nullptr. */
1737 gdb::unique_xmalloc_ptr
<char> release_fullname ()
1739 gdb::unique_xmalloc_ptr
<char> result (m_fullname
);
1740 m_fullname
= nullptr;
1744 /* Set the current full name to NAME, transferring ownership to this
1746 void set_fullname (gdb::unique_xmalloc_ptr
<char> name
)
1748 gdb_assert (m_fullname
== nullptr);
1749 m_fullname
= name
.release ();
1752 /* Unordered chain of all filetabs in the compunit, with the exception
1753 that the "main" source file is the first entry in the list. */
1755 struct symtab
*next
;
1757 /* Name of this source file, in a form appropriate to print to the user.
1759 This pointer is never nullptr. */
1761 const char *filename
;
1763 /* Filename for this source file, used as an identifier to link with
1764 related objects such as associated macro_source_file objects. It must
1765 therefore match the name of any macro_source_file object created for this
1766 source file. The value can be the same as FILENAME if it is known to
1767 follow that rule, or another form of the same file name, this is up to
1768 the specific debug info reader.
1770 This pointer is never nullptr.*/
1771 const char *filename_for_id
;
1775 /* Backlink to containing compunit symtab. */
1777 struct compunit_symtab
*m_compunit
;
1779 /* Table mapping core addresses to line numbers for this file.
1780 Can be NULL if none. Never shared between different symtabs. */
1782 const struct linetable
*m_linetable
;
1784 /* Language of this source file. */
1786 enum language m_language
;
1788 /* Full name of file as found by searching the source path.
1789 NULL if not yet known. */
1794 /* A range adapter to allowing iterating over all the file tables in a list. */
1796 using symtab_range
= next_range
<symtab
>;
1798 /* Compunit symtabs contain the actual "symbol table", aka blockvector, as well
1799 as the list of all source files (what gdb has historically associated with
1801 Additional information is recorded here that is common to all symtabs in a
1802 compilation unit (DWARF or otherwise).
1805 For the case of a program built out of these files:
1814 This is recorded as:
1816 objfile -> foo.c(cu) -> bar.c(cu) -> NULL
1830 where "foo.c(cu)" and "bar.c(cu)" are struct compunit_symtab objects,
1831 and the files foo.c, etc. are struct symtab objects. */
1833 struct compunit_symtab
1835 struct objfile
*objfile () const
1840 void set_objfile (struct objfile
*objfile
)
1842 m_objfile
= objfile
;
1845 symtab_range
filetabs () const
1847 return symtab_range (m_filetabs
);
1850 void add_filetab (symtab
*filetab
)
1852 if (m_filetabs
== nullptr)
1854 m_filetabs
= filetab
;
1855 m_last_filetab
= filetab
;
1859 m_last_filetab
->next
= filetab
;
1860 m_last_filetab
= filetab
;
1864 const char *debugformat () const
1866 return m_debugformat
;
1869 void set_debugformat (const char *debugformat
)
1871 m_debugformat
= debugformat
;
1874 const char *producer () const
1879 void set_producer (const char *producer
)
1881 m_producer
= producer
;
1884 const char *dirname () const
1889 void set_dirname (const char *dirname
)
1891 m_dirname
= dirname
;
1894 struct blockvector
*blockvector ()
1896 return m_blockvector
;
1899 const struct blockvector
*blockvector () const
1901 return m_blockvector
;
1904 void set_blockvector (struct blockvector
*blockvector
)
1906 m_blockvector
= blockvector
;
1909 bool locations_valid () const
1911 return m_locations_valid
;
1914 void set_locations_valid (bool locations_valid
)
1916 m_locations_valid
= locations_valid
;
1919 bool epilogue_unwind_valid () const
1921 return m_epilogue_unwind_valid
;
1924 void set_epilogue_unwind_valid (bool epilogue_unwind_valid
)
1926 m_epilogue_unwind_valid
= epilogue_unwind_valid
;
1929 struct macro_table
*macro_table () const
1931 return m_macro_table
;
1934 void set_macro_table (struct macro_table
*macro_table
)
1936 m_macro_table
= macro_table
;
1939 /* Make PRIMARY_FILETAB the primary filetab of this compunit symtab.
1941 PRIMARY_FILETAB must already be a filetab of this compunit symtab. */
1943 void set_primary_filetab (symtab
*primary_filetab
);
1945 /* Return the primary filetab of the compunit. */
1946 symtab
*primary_filetab () const;
1948 /* Set m_call_site_htab. */
1949 void set_call_site_htab (call_site_htab_t
&&call_site_htab
);
1951 /* Find call_site info for PC. */
1952 call_site
*find_call_site (CORE_ADDR pc
) const;
1954 /* Return the language of this compunit_symtab. */
1955 enum language
language () const;
1957 /* Clear any cached source file names. */
1958 void forget_cached_source_info ();
1960 /* This is called when an objfile is being destroyed and will free
1961 any resources used by this compunit_symtab. Normally a
1962 destructor would be used instead, but at the moment
1963 compunit_symtab objects are allocated on an obstack. */
1966 /* Unordered chain of all compunit symtabs of this objfile. */
1967 struct compunit_symtab
*next
;
1969 /* Object file from which this symtab information was read. */
1970 struct objfile
*m_objfile
;
1972 /* Name of the symtab.
1973 This is *not* intended to be a usable filename, and is
1974 for debugging purposes only. */
1977 /* Unordered list of file symtabs, except that by convention the "main"
1978 source file (e.g., .c, .cc) is guaranteed to be first.
1979 Each symtab is a file, either the "main" source file (e.g., .c, .cc)
1980 or header (e.g., .h). */
1983 /* Last entry in FILETABS list.
1984 Subfiles are added to the end of the list so they accumulate in order,
1985 with the main source subfile living at the front.
1986 The main reason is so that the main source file symtab is at the head
1987 of the list, and the rest appear in order for debugging convenience. */
1988 symtab
*m_last_filetab
;
1990 /* Non-NULL string that identifies the format of the debugging information,
1991 such as "stabs", "dwarf 1", "dwarf 2", "coff", etc. This is mostly useful
1992 for automated testing of gdb but may also be information that is
1993 useful to the user. */
1994 const char *m_debugformat
;
1996 /* String of producer version information, or NULL if we don't know. */
1997 const char *m_producer
;
1999 /* Directory in which it was compiled, or NULL if we don't know. */
2000 const char *m_dirname
;
2002 /* List of all symbol scope blocks for this symtab. It is shared among
2003 all symtabs in a given compilation unit. */
2004 struct blockvector
*m_blockvector
;
2006 /* Symtab has been compiled with both optimizations and debug info so that
2007 GDB may stop skipping prologues as variables locations are valid already
2008 at function entry points. */
2009 unsigned int m_locations_valid
: 1;
2011 /* DWARF unwinder for this CU is valid even for epilogues (PC at the return
2012 instruction). This is supported by GCC since 4.5.0. */
2013 unsigned int m_epilogue_unwind_valid
: 1;
2015 /* struct call_site entries for this compilation unit or NULL. */
2016 call_site_htab_t
*m_call_site_htab
;
2018 /* The macro table for this symtab. Like the blockvector, this
2019 is shared between different symtabs in a given compilation unit.
2020 It's debatable whether it *should* be shared among all the symtabs in
2021 the given compilation unit, but it currently is. */
2022 struct macro_table
*m_macro_table
;
2024 /* If non-NULL, then this points to a NULL-terminated vector of
2025 included compunits. When searching the static or global
2026 block of this compunit, the corresponding block of all
2027 included compunits will also be searched. Note that this
2028 list must be flattened -- the symbol reader is responsible for
2029 ensuring that this vector contains the transitive closure of all
2030 included compunits. */
2031 struct compunit_symtab
**includes
;
2033 /* If this is an included compunit, this points to one includer
2034 of the table. This user is considered the canonical compunit
2035 containing this one. An included compunit may itself be
2036 included by another. */
2037 struct compunit_symtab
*user
;
2040 using compunit_symtab_range
= next_range
<compunit_symtab
>;
2042 /* Return true if this symtab is the "main" symtab of its compunit_symtab. */
2045 is_main_symtab_of_compunit_symtab (struct symtab
*symtab
)
2047 return symtab
== symtab
->compunit ()->primary_filetab ();
2050 /* Return true if epilogue unwind info of CUST is valid. */
2053 compunit_epilogue_unwind_valid (struct compunit_symtab
*cust
)
2055 /* In absence of producer information, assume epilogue unwind info is
2057 if (cust
== nullptr)
2060 return cust
->epilogue_unwind_valid ();
2064 /* The virtual function table is now an array of structures which have the
2065 form { int16 offset, delta; void *pfn; }.
2067 In normal virtual function tables, OFFSET is unused.
2068 DELTA is the amount which is added to the apparent object's base
2069 address in order to point to the actual object to which the
2070 virtual function should be applied.
2071 PFN is a pointer to the virtual function.
2073 Note that this macro is g++ specific (FIXME). */
2075 #define VTBL_FNADDR_OFFSET 2
2077 /* External variables and functions for the objects described above. */
2079 /* True if we are nested inside psymtab_to_symtab. */
2081 extern int currently_reading_symtab
;
2083 /* symtab.c lookup functions */
2085 extern const char multiple_symbols_ask
[];
2086 extern const char multiple_symbols_all
[];
2087 extern const char multiple_symbols_cancel
[];
2089 const char *multiple_symbols_select_mode (void);
2091 /* Lookup a symbol table in PSPACE by source file name. */
2093 extern symtab
*lookup_symtab (program_space
*pspace
, const char *name
);
2095 /* An object of this type is passed as the 'is_a_field_of_this'
2096 argument to lookup_symbol and lookup_symbol_in_language. */
2098 struct field_of_this_result
2100 /* The type in which the field was found. If this is NULL then the
2101 symbol was not found in 'this'. If non-NULL, then one of the
2102 other fields will be non-NULL as well. */
2104 struct type
*type
= nullptr;
2106 /* If the symbol was found as an ordinary field of 'this', then this
2107 is non-NULL and points to the particular field. */
2109 struct field
*field
= nullptr;
2111 /* If the symbol was found as a function field of 'this', then this
2112 is non-NULL and points to the particular field. */
2114 struct fn_fieldlist
*fn_field
= nullptr;
2117 /* Find the definition for a specified symbol name NAME
2118 in domain DOMAIN in language LANGUAGE, visible from lexical block BLOCK
2119 if non-NULL or from global/static blocks if BLOCK is NULL.
2120 Returns the struct symbol pointer, or NULL if no symbol is found.
2121 C++: if IS_A_FIELD_OF_THIS is non-NULL on entry, check to see if
2122 NAME is a field of the current implied argument `this'. If so fill in the
2123 fields of IS_A_FIELD_OF_THIS, otherwise the fields are set to NULL.
2124 The symbol's section is fixed up if necessary. */
2126 extern struct block_symbol
2127 lookup_symbol_in_language (const char *,
2128 const struct block
*,
2129 const domain_search_flags
,
2131 struct field_of_this_result
*);
2133 /* Same as lookup_symbol_in_language, but using the current language. */
2135 extern struct block_symbol
lookup_symbol (const char *,
2136 const struct block
*,
2137 const domain_search_flags
,
2138 struct field_of_this_result
*);
2140 /* Find the definition for a specified symbol search name in domain
2141 DOMAIN, visible from lexical block BLOCK if non-NULL or from
2142 global/static blocks if BLOCK is NULL. The passed-in search name
2143 should not come from the user; instead it should already be a
2144 search name as retrieved from a search_name () call. See definition of
2145 symbol_name_match_type::SEARCH_NAME. Returns the struct symbol
2146 pointer, or NULL if no symbol is found. The symbol's section is
2147 fixed up if necessary. */
2149 extern struct block_symbol lookup_symbol_search_name
2150 (const char *search_name
,
2151 const struct block
*block
,
2152 domain_search_flags domain
);
2154 /* Some helper functions for languages that need to write their own
2155 lookup_symbol_nonlocal functions. */
2157 /* Lookup a symbol in the static block associated to BLOCK, if there
2158 is one; do nothing if BLOCK is NULL or a global block.
2159 Upon success fixes up the symbol's section if necessary. */
2161 extern struct block_symbol
2162 lookup_symbol_in_static_block (const char *name
,
2163 const struct block
*block
,
2164 const domain_search_flags domain
);
2166 /* Search all static file-level symbols for NAME from DOMAIN.
2167 Upon success fixes up the symbol's section if necessary. */
2169 extern struct block_symbol lookup_static_symbol
2170 (const char *name
, const domain_search_flags domain
);
2172 /* Lookup a symbol in all files' global blocks.
2174 If BLOCK is non-NULL then it is used for two things:
2175 1) If a target-specific lookup routine for libraries exists, then use the
2176 routine for the objfile of BLOCK, and
2177 2) The objfile of BLOCK is used to assist in determining the search order
2178 if the target requires it.
2179 See gdbarch_iterate_over_objfiles_in_search_order.
2181 Upon success fixes up the symbol's section if necessary. */
2183 extern struct block_symbol
2184 lookup_global_symbol (const char *name
,
2185 const struct block
*block
,
2186 const domain_search_flags domain
);
2188 /* Lookup a symbol in block BLOCK.
2189 Upon success fixes up the symbol's section if necessary. */
2191 extern struct symbol
*
2192 lookup_symbol_in_block (const char *name
,
2193 symbol_name_match_type match_type
,
2194 const struct block
*block
,
2195 const domain_search_flags domain
);
2197 /* Look up the `this' symbol for LANG in BLOCK. Return the symbol if
2198 found, or NULL if not found. */
2200 extern struct block_symbol
2201 lookup_language_this (const struct language_defn
*lang
,
2202 const struct block
*block
);
2204 /* Lookup a [struct, union, enum] by name, within a specified block. */
2206 extern struct type
*lookup_struct (const char *, const struct block
*);
2208 extern struct type
*lookup_union (const char *, const struct block
*);
2210 extern struct type
*lookup_enum (const char *, const struct block
*);
2212 /* from blockframe.c: */
2214 /* lookup the function symbol corresponding to the address. The
2215 return value will not be an inlined function; the containing
2216 function will be returned instead. */
2218 extern struct symbol
*find_pc_function (CORE_ADDR
);
2220 /* lookup the function corresponding to the address and section. The
2221 return value will not be an inlined function; the containing
2222 function will be returned instead. */
2224 extern struct symbol
*find_pc_sect_function (CORE_ADDR
, struct obj_section
*);
2226 /* lookup the function symbol corresponding to the address and
2227 section. The return value will be the closest enclosing function,
2228 which might be an inline function. */
2230 extern struct symbol
*find_pc_sect_containing_function
2231 (CORE_ADDR pc
, struct obj_section
*section
);
2233 /* Find the symbol at the given address. Returns NULL if no symbol
2234 found. Only exact matches for ADDRESS are considered. */
2236 extern struct symbol
*find_symbol_at_address (CORE_ADDR
);
2238 /* Finds the "function" (text symbol) that is smaller than PC but
2239 greatest of all of the potential text symbols in SECTION. Sets
2240 *NAME and/or *ADDRESS conditionally if that pointer is non-null.
2241 If ENDADDR is non-null, then set *ENDADDR to be the end of the
2242 function (exclusive). If the optional parameter BLOCK is non-null,
2243 then set *BLOCK to the address of the block corresponding to the
2244 function symbol, if such a symbol could be found during the lookup;
2245 nullptr is used as a return value for *BLOCK if no block is found.
2246 This function either succeeds or fails (not halfway succeeds). If
2247 it succeeds, it sets *NAME, *ADDRESS, and *ENDADDR to real
2248 information and returns true. If it fails, it sets *NAME, *ADDRESS
2249 and *ENDADDR to zero and returns false.
2251 If the function in question occupies non-contiguous ranges,
2252 *ADDRESS and *ENDADDR are (subject to the conditions noted above) set
2253 to the start and end of the range in which PC is found. Thus
2254 *ADDRESS <= PC < *ENDADDR with no intervening gaps (in which ranges
2255 from other functions might be found).
2257 This property allows find_pc_partial_function to be used (as it had
2258 been prior to the introduction of non-contiguous range support) by
2259 various tdep files for finding a start address and limit address
2260 for prologue analysis. This still isn't ideal, however, because we
2261 probably shouldn't be doing prologue analysis (in which
2262 instructions are scanned to determine frame size and stack layout)
2263 for any range that doesn't contain the entry pc. Moreover, a good
2264 argument can be made that prologue analysis ought to be performed
2265 starting from the entry pc even when PC is within some other range.
2266 This might suggest that *ADDRESS and *ENDADDR ought to be set to the
2267 limits of the entry pc range, but that will cause the
2268 *ADDRESS <= PC < *ENDADDR condition to be violated; many of the
2269 callers of find_pc_partial_function expect this condition to hold.
2271 Callers which require the start and/or end addresses for the range
2272 containing the entry pc should instead call
2273 find_function_entry_range_from_pc. */
2275 extern bool find_pc_partial_function (CORE_ADDR pc
, const char **name
,
2276 CORE_ADDR
*address
, CORE_ADDR
*endaddr
,
2277 const struct block
**block
= nullptr);
2279 /* Like find_pc_partial_function, above, but returns the underlying
2280 general_symbol_info (rather than the name) as an out parameter. */
2282 extern bool find_pc_partial_function_sym
2283 (CORE_ADDR pc
, const general_symbol_info
**sym
,
2284 CORE_ADDR
*address
, CORE_ADDR
*endaddr
,
2285 const struct block
**block
= nullptr);
2287 /* Like find_pc_partial_function, above, but *ADDRESS and *ENDADDR are
2288 set to start and end addresses of the range containing the entry pc.
2290 Note that it is not necessarily the case that (for non-NULL ADDRESS
2291 and ENDADDR arguments) the *ADDRESS <= PC < *ENDADDR condition will
2294 See comment for find_pc_partial_function, above, for further
2297 extern bool find_function_entry_range_from_pc (CORE_ADDR pc
,
2300 CORE_ADDR
*endaddr
);
2302 /* Return the type of a function with its first instruction exactly at
2303 the PC address. Return NULL otherwise. */
2305 extern struct type
*find_function_type (CORE_ADDR pc
);
2307 /* See if we can figure out the function's actual type from the type
2308 that the resolver returns. RESOLVER_FUNADDR is the address of the
2311 extern struct type
*find_gnu_ifunc_target_type (CORE_ADDR resolver_funaddr
);
2313 /* Find the GNU ifunc minimal symbol that matches SYM. */
2314 extern bound_minimal_symbol
find_gnu_ifunc (const symbol
*sym
);
2316 extern void clear_pc_function_cache (void);
2318 /* lookup full symbol table by address. */
2320 extern struct compunit_symtab
*find_pc_compunit_symtab (CORE_ADDR
);
2322 /* lookup full symbol table by address and section. */
2324 extern struct compunit_symtab
*
2325 find_pc_sect_compunit_symtab (CORE_ADDR
, struct obj_section
*);
2327 extern bool find_pc_line_pc_range (CORE_ADDR
, CORE_ADDR
*, CORE_ADDR
*);
2329 extern void reread_symbols (int from_tty
);
2331 /* Look up a type named NAME in STRUCT_DOMAIN in the current language.
2332 The type returned must not be opaque -- i.e., must have at least one field
2335 extern struct type
*lookup_transparent_type
2336 (const char *name
, domain_search_flags flags
= SEARCH_STRUCT_DOMAIN
);
2338 extern struct type
*basic_lookup_transparent_type
2339 (const char *name
, domain_search_flags flags
= SEARCH_STRUCT_DOMAIN
);
2341 /* Macro for name of symbol to indicate a file compiled with gcc. */
2342 #ifndef GCC_COMPILED_FLAG_SYMBOL
2343 #define GCC_COMPILED_FLAG_SYMBOL "gcc_compiled."
2346 /* Macro for name of symbol to indicate a file compiled with gcc2. */
2347 #ifndef GCC2_COMPILED_FLAG_SYMBOL
2348 #define GCC2_COMPILED_FLAG_SYMBOL "gcc2_compiled."
2351 extern bool in_gnu_ifunc_stub (CORE_ADDR pc
);
2353 /* Functions for resolving STT_GNU_IFUNC symbols which are implemented only
2354 for ELF symbol files. */
2356 struct gnu_ifunc_fns
2358 /* See elf_gnu_ifunc_resolve_addr for its real implementation. */
2359 CORE_ADDR (*gnu_ifunc_resolve_addr
) (struct gdbarch
*gdbarch
, CORE_ADDR pc
);
2361 /* See elf_gnu_ifunc_resolve_name for its real implementation. */
2362 bool (*gnu_ifunc_resolve_name
) (const char *function_name
,
2363 CORE_ADDR
*function_address_p
);
2365 /* See elf_gnu_ifunc_resolver_stop for its real implementation. */
2366 void (*gnu_ifunc_resolver_stop
) (code_breakpoint
*b
);
2368 /* See elf_gnu_ifunc_resolver_return_stop for its real implementation. */
2369 void (*gnu_ifunc_resolver_return_stop
) (code_breakpoint
*b
);
2372 #define gnu_ifunc_resolve_addr gnu_ifunc_fns_p->gnu_ifunc_resolve_addr
2373 #define gnu_ifunc_resolve_name gnu_ifunc_fns_p->gnu_ifunc_resolve_name
2374 #define gnu_ifunc_resolver_stop gnu_ifunc_fns_p->gnu_ifunc_resolver_stop
2375 #define gnu_ifunc_resolver_return_stop \
2376 gnu_ifunc_fns_p->gnu_ifunc_resolver_return_stop
2378 extern const struct gnu_ifunc_fns
*gnu_ifunc_fns_p
;
2380 extern CORE_ADDR
find_solib_trampoline_target (const frame_info_ptr
&, CORE_ADDR
);
2382 struct symtab_and_line
2384 /* The program space of this sal. */
2385 struct program_space
*pspace
= NULL
;
2387 struct symtab
*symtab
= NULL
;
2388 struct symbol
*symbol
= NULL
;
2389 struct obj_section
*section
= NULL
;
2390 struct minimal_symbol
*msymbol
= NULL
;
2391 /* Line number. Line numbers start at 1 and proceed through symtab->nlines.
2392 0 is never a valid line number; it is used to indicate that line number
2393 information is not available. */
2398 bool explicit_pc
= false;
2399 bool explicit_line
= false;
2401 /* If the line number information is valid, then this indicates if this
2402 line table entry had the is-stmt flag set or not. */
2403 bool is_stmt
= false;
2405 /* The probe associated with this symtab_and_line. */
2407 /* If PROBE is not NULL, then this is the objfile in which the probe
2409 struct objfile
*objfile
= NULL
;
2414 /* Given a pc value, return line number it is in. Second arg nonzero means
2415 if pc is on the boundary use the previous statement's line number. */
2417 extern struct symtab_and_line
find_pc_line (CORE_ADDR
, int);
2419 /* Same function, but specify a section as well as an address. */
2421 extern struct symtab_and_line
find_pc_sect_line (CORE_ADDR
,
2422 struct obj_section
*, int);
2424 /* Given PC, and assuming it is part of a range of addresses that is part of
2425 a line, go back through the linetable and find the starting PC of that
2428 For example, suppose we have 3 PC ranges for line X:
2430 Line X - [0x0 - 0x8]
2431 Line X - [0x8 - 0x10]
2432 Line X - [0x10 - 0x18]
2434 If we call the function with PC == 0x14, we want to return 0x0, as that is
2435 the starting PC of line X, and the ranges are contiguous.
2438 extern std::optional
<CORE_ADDR
> find_line_range_start (CORE_ADDR pc
);
2440 /* Wrapper around find_pc_line to just return the symtab. */
2442 extern struct symtab
*find_pc_line_symtab (CORE_ADDR
);
2444 /* Given a symtab and line number, return the pc there. */
2446 extern bool find_line_pc (struct symtab
*, int, CORE_ADDR
*);
2448 extern bool find_line_pc_range (struct symtab_and_line
, CORE_ADDR
*,
2451 extern void resolve_sal_pc (struct symtab_and_line
*);
2453 /* The reason we're calling into a completion match list collector
2455 enum class complete_symbol_mode
2457 /* Completing an expression. */
2460 /* Completing a linespec. */
2464 extern void default_collect_symbol_completion_matches_break_on
2465 (completion_tracker
&tracker
,
2466 complete_symbol_mode mode
,
2467 symbol_name_match_type name_match_type
,
2468 const char *text
, const char *word
, const char *break_on
,
2469 enum type_code code
);
2470 extern void collect_symbol_completion_matches
2471 (completion_tracker
&tracker
,
2472 complete_symbol_mode mode
,
2473 symbol_name_match_type name_match_type
,
2474 const char *, const char *);
2475 extern void collect_symbol_completion_matches_type (completion_tracker
&tracker
,
2476 const char *, const char *,
2479 extern void collect_file_symbol_completion_matches
2480 (completion_tracker
&tracker
,
2481 complete_symbol_mode
,
2482 symbol_name_match_type name_match_type
,
2483 const char *, const char *, const char *);
2485 extern completion_list
2486 make_source_files_completion_list (const char *, const char *);
2488 /* Return whether SYM is a function/method, as opposed to a data symbol. */
2490 extern bool symbol_is_function_or_method (symbol
*sym
);
2492 /* Return whether MSYMBOL is a function/method, as opposed to a data
2495 extern bool symbol_is_function_or_method (minimal_symbol
*msymbol
);
2497 /* Return whether SYM should be skipped in completion mode MODE. In
2498 linespec mode, we're only interested in functions/methods. */
2500 template<typename Symbol
>
2502 completion_skip_symbol (complete_symbol_mode mode
, Symbol
*sym
)
2504 return (mode
== complete_symbol_mode::LINESPEC
2505 && !symbol_is_function_or_method (sym
));
2510 bool matching_obj_sections (struct obj_section
*, struct obj_section
*);
2512 /* Find line number LINE in any symtab whose name is the same as
2515 If found, return the symtab that contains the linetable in which it was
2516 found, set *INDEX to the index in the linetable of the best entry
2517 found. The returned index includes inexact matches.
2519 If not found, return NULL. */
2521 extern symtab
*find_line_symtab (symtab
*sym_tab
, int line
, int *index
);
2523 /* Given a function symbol SYM, find the symtab and line for the start
2524 of the function. If FUNFIRSTLINE is true, we want the first line
2525 of real code inside the function. */
2526 extern symtab_and_line
find_function_start_sal (symbol
*sym
, bool
2529 /* Same, but start with a function address/section instead of a
2531 extern symtab_and_line
find_function_start_sal (CORE_ADDR func_addr
,
2532 obj_section
*section
,
2535 extern void skip_prologue_sal (struct symtab_and_line
*);
2539 extern CORE_ADDR
skip_prologue_using_sal (struct gdbarch
*gdbarch
,
2540 CORE_ADDR func_addr
);
2542 /* If SYM requires a section index, find it either via minimal symbols
2543 or examining OBJFILE's sections. Note that SYM's current address
2544 must not have any runtime offsets applied. */
2546 extern void fixup_symbol_section (struct symbol
*sym
,
2547 struct objfile
*objfile
);
2549 /* If MSYMBOL is an text symbol, look for a function debug symbol with
2550 the same address. Returns NULL if not found. This is necessary in
2551 case a function is an alias to some other function, because debug
2552 information is only emitted for the alias target function's
2553 definition, not for the alias. */
2554 extern symbol
*find_function_alias_target (bound_minimal_symbol msymbol
);
2556 /* Symbol searching */
2558 /* When using the symbol_searcher struct to search for symbols, a vector of
2559 the following structs is returned. */
2560 struct symbol_search
2562 symbol_search (block_enum block_
, struct symbol
*symbol_
)
2566 msymbol
.minsym
= nullptr;
2567 msymbol
.objfile
= nullptr;
2570 symbol_search (block_enum block_
, struct minimal_symbol
*minsym
,
2571 struct objfile
*objfile
)
2575 msymbol
.minsym
= minsym
;
2576 msymbol
.objfile
= objfile
;
2579 bool operator< (const symbol_search
&other
) const
2581 return compare_search_syms (*this, other
) < 0;
2584 bool operator== (const symbol_search
&other
) const
2586 return compare_search_syms (*this, other
) == 0;
2589 /* The block in which the match was found. Either STATIC_BLOCK or
2593 /* Information describing what was found.
2595 If symbol is NOT NULL, then information was found for this match. */
2596 struct symbol
*symbol
;
2598 /* If msymbol is non-null, then a match was made on something for
2599 which only minimal_symbols exist. */
2600 bound_minimal_symbol msymbol
;
2604 static int compare_search_syms (const symbol_search
&sym_a
,
2605 const symbol_search
&sym_b
);
2608 /* In order to search for global symbols of a particular kind matching
2609 particular regular expressions, create an instance of this structure and
2610 call the SEARCH member function. */
2611 class global_symbol_searcher
2616 global_symbol_searcher (domain_search_flags kind
,
2617 const char *symbol_name_regexp
)
2619 m_symbol_name_regexp (symbol_name_regexp
)
2623 /* Set the optional regexp that matches against the symbol type. */
2624 void set_symbol_type_regexp (const char *regexp
)
2626 m_symbol_type_regexp
= regexp
;
2629 /* Set the flag to exclude minsyms from the search results. */
2630 void set_exclude_minsyms (bool exclude_minsyms
)
2632 m_exclude_minsyms
= exclude_minsyms
;
2635 /* Set the maximum number of search results to be returned. */
2636 void set_max_search_results (size_t max_search_results
)
2638 m_max_search_results
= max_search_results
;
2641 /* Search the symbols from all objfiles in the current program space
2642 looking for matches as defined by the current state of this object.
2644 Within each file the results are sorted locally; each symtab's global
2645 and static blocks are separately alphabetized. Duplicate entries are
2647 std::vector
<symbol_search
> search () const;
2649 /* Add a filename to the list of file names to search. */
2650 void add_filename (gdb::unique_xmalloc_ptr
<char> filename
)
2651 { m_filenames
.push_back (std::move (filename
)); }
2654 /* The set of source files to search in for matching symbols. */
2655 std::vector
<gdb::unique_xmalloc_ptr
<char>> m_filenames
;
2657 /* The kind of symbols are we searching for.
2658 VARIABLES_DOMAIN - Search all symbols, excluding functions, type
2659 names, and constants (enums).
2660 FUNCTIONS_DOMAIN - Search all functions..
2661 TYPES_DOMAIN - Search all type names.
2662 MODULES_DOMAIN - Search all Fortran modules.
2663 ALL_DOMAIN - Not valid for this function. */
2664 domain_search_flags m_kind
;
2666 /* Regular expression to match against the symbol name. */
2667 const char *m_symbol_name_regexp
= nullptr;
2669 /* Regular expression to match against the symbol type. */
2670 const char *m_symbol_type_regexp
= nullptr;
2672 /* When this flag is false then minsyms that match M_SYMBOL_REGEXP will
2673 be included in the results, otherwise they are excluded. */
2674 bool m_exclude_minsyms
= false;
2676 /* Maximum number of search results. We currently impose a hard limit
2677 of SIZE_MAX, there is no "unlimited". */
2678 size_t m_max_search_results
= SIZE_MAX
;
2680 /* Expand symtabs in OBJFILE that match PREG, are of type M_KIND. Return
2681 true if any msymbols were seen that we should later consider adding to
2682 the results list. */
2683 bool expand_symtabs (objfile
*objfile
,
2684 const std::optional
<compiled_regex
> &preg
) const;
2686 /* Add symbols from symtabs in OBJFILE that match PREG, and TREG, and are
2687 of type M_KIND, to the results set RESULTS_SET. Return false if we
2688 stop adding results early due to having already found too many results
2689 (based on M_MAX_SEARCH_RESULTS limit), otherwise return true.
2690 Returning true does not indicate that any results were added, just
2691 that we didn't _not_ add a result due to reaching MAX_SEARCH_RESULTS. */
2692 bool add_matching_symbols (objfile
*objfile
,
2693 const std::optional
<compiled_regex
> &preg
,
2694 const std::optional
<compiled_regex
> &treg
,
2695 std::set
<symbol_search
> *result_set
) const;
2697 /* Add msymbols from OBJFILE that match PREG and M_KIND, to the results
2698 vector RESULTS. Return false if we stop adding results early due to
2699 having already found too many results (based on max search results
2700 limit M_MAX_SEARCH_RESULTS), otherwise return true. Returning true
2701 does not indicate that any results were added, just that we didn't
2702 _not_ add a result due to reaching MAX_SEARCH_RESULTS. */
2703 bool add_matching_msymbols (objfile
*objfile
,
2704 const std::optional
<compiled_regex
> &preg
,
2705 std::vector
<symbol_search
> *results
) const;
2707 /* Return true if MSYMBOL is of type KIND. */
2708 static bool is_suitable_msymbol (const domain_search_flags kind
,
2709 const minimal_symbol
*msymbol
);
2712 /* When searching for Fortran symbols within modules (functions/variables)
2713 we return a vector of this type. The first item in the pair is the
2714 module symbol, and the second item is the symbol for the function or
2715 variable we found. */
2716 typedef std::pair
<symbol_search
, symbol_search
> module_symbol_search
;
2718 /* Searches the symbols to find function and variables symbols (depending
2719 on KIND) within Fortran modules. The MODULE_REGEXP matches against the
2720 name of the module, REGEXP matches against the name of the symbol within
2721 the module, and TYPE_REGEXP matches against the type of the symbol
2722 within the module. */
2723 extern std::vector
<module_symbol_search
> search_module_symbols
2724 (const char *module_regexp
, const char *regexp
,
2725 const char *type_regexp
, domain_search_flags kind
);
2727 /* Convert a global or static symbol SYM (based on BLOCK, which should be
2728 either GLOBAL_BLOCK or STATIC_BLOCK) into a string for use in 'info'
2729 type commands (e.g. 'info variables', 'info functions', etc). */
2731 extern std::string
symbol_to_info_string (struct symbol
*sym
, int block
);
2733 extern bool treg_matches_sym_type_name (const compiled_regex
&treg
,
2734 const struct symbol
*sym
);
2736 /* The name of the ``main'' function. */
2737 extern const char *main_name ();
2738 extern enum language
main_language (void);
2740 /* Lookup symbol NAME from DOMAIN in MAIN_OBJFILE's global or static blocks,
2741 as specified by BLOCK_INDEX.
2742 This searches MAIN_OBJFILE as well as any associated separate debug info
2743 objfiles of MAIN_OBJFILE.
2744 BLOCK_INDEX can be GLOBAL_BLOCK or STATIC_BLOCK.
2745 Upon success fixes up the symbol's section if necessary. */
2747 extern struct block_symbol
2748 lookup_global_symbol_from_objfile (struct objfile
*main_objfile
,
2749 enum block_enum block_index
,
2751 const domain_search_flags domain
);
2753 extern unsigned int symtab_create_debug
;
2755 /* Print a "symtab-create" debug statement. */
2757 #define symtab_create_debug_printf(fmt, ...) \
2758 debug_prefixed_printf_cond (symtab_create_debug >= 1, "symtab-create", fmt, ##__VA_ARGS__)
2760 /* Print a verbose "symtab-create" debug statement, only if
2761 "set debug symtab-create" is set to 2 or higher. */
2763 #define symtab_create_debug_printf_v(fmt, ...) \
2764 debug_prefixed_printf_cond (symtab_create_debug >= 2, "symtab-create", fmt, ##__VA_ARGS__)
2766 extern unsigned int symbol_lookup_debug
;
2768 /* Return true if symbol-lookup debug is turned on at all. */
2771 symbol_lookup_debug_enabled ()
2773 return symbol_lookup_debug
> 0;
2776 /* Return true if symbol-lookup debug is turned to verbose mode. */
2779 symbol_lookup_debug_enabled_v ()
2781 return symbol_lookup_debug
> 1;
2784 /* Print a "symbol-lookup" debug statement if symbol_lookup_debug is >= 1. */
2786 #define symbol_lookup_debug_printf(fmt, ...) \
2787 debug_prefixed_printf_cond (symbol_lookup_debug_enabled (), \
2788 "symbol-lookup", fmt, ##__VA_ARGS__)
2790 /* Print a "symbol-lookup" debug statement if symbol_lookup_debug is >= 2. */
2792 #define symbol_lookup_debug_printf_v(fmt, ...) \
2793 debug_prefixed_printf_cond (symbol_lookup_debug_enabled_v (), \
2794 "symbol-lookup", fmt, ##__VA_ARGS__)
2796 /* Print "symbol-lookup" enter/exit debug statements. */
2798 #define SYMBOL_LOOKUP_SCOPED_DEBUG_ENTER_EXIT \
2799 scoped_debug_enter_exit (symbol_lookup_debug_enabled, "symbol-lookup")
2801 extern bool basenames_may_differ
;
2803 bool compare_filenames_for_search (const char *filename
,
2804 const char *search_name
);
2806 bool compare_glob_filenames_for_search (const char *filename
,
2807 const char *search_name
);
2809 bool iterate_over_some_symtabs (const char *name
,
2810 const char *real_path
,
2811 struct compunit_symtab
*first
,
2812 struct compunit_symtab
*after_last
,
2813 gdb::function_view
<bool (symtab
*)> callback
);
2815 /* Check in PSPACE for a symtab of a specific name; first in symtabs, then in
2816 psymtabs. *If* there is no '/' in the name, a match after a '/' in the
2817 symtab filename will also work.
2819 Call CALLBACK with each symtab that is found. If CALLBACK returns
2820 true, the search stops. */
2822 void iterate_over_symtabs (program_space
*pspace
, const char *name
,
2823 gdb::function_view
<bool (symtab
*)> callback
);
2825 std::vector
<CORE_ADDR
> find_pcs_for_symtab_line
2826 (struct symtab
*symtab
, int line
, const linetable_entry
**best_entry
);
2828 /* Prototype for callbacks for LA_ITERATE_OVER_SYMBOLS. The callback
2829 is called once per matching symbol SYM. The callback should return
2830 true to indicate that LA_ITERATE_OVER_SYMBOLS should continue
2831 iterating, or false to indicate that the iteration should end. */
2833 typedef bool (symbol_found_callback_ftype
) (struct block_symbol
*bsym
);
2835 /* Iterate over the symbols named NAME, matching DOMAIN, in BLOCK.
2837 For each symbol that matches, CALLBACK is called. The symbol is
2838 passed to the callback.
2840 If CALLBACK returns false, the iteration ends and this function
2841 returns false. Otherwise, the search continues, and the function
2842 eventually returns true. */
2844 bool iterate_over_symbols (const struct block
*block
,
2845 const lookup_name_info
&name
,
2846 const domain_search_flags domain
,
2847 gdb::function_view
<symbol_found_callback_ftype
> callback
);
2849 /* Like iterate_over_symbols, but if all calls to CALLBACK return
2850 true, then calls CALLBACK one additional time with a block_symbol
2851 that has a valid block but a NULL symbol. */
2853 bool iterate_over_symbols_terminated
2854 (const struct block
*block
,
2855 const lookup_name_info
&name
,
2856 const domain_search_flags domain
,
2857 gdb::function_view
<symbol_found_callback_ftype
> callback
);
2859 /* Storage type used by demangle_for_lookup. demangle_for_lookup
2860 either returns a const char * pointer that points to either of the
2861 fields of this type, or a pointer to the input NAME. This is done
2862 this way to avoid depending on the precise details of the storage
2864 class demangle_result_storage
2868 /* Swap the malloc storage to STR, and return a pointer to the
2869 beginning of the new string. */
2870 const char *set_malloc_ptr (gdb::unique_xmalloc_ptr
<char> &&str
)
2872 m_malloc
= std::move (str
);
2873 return m_malloc
.get ();
2876 /* Set the malloc storage to now point at PTR. Any previous malloc
2877 storage is released. */
2878 const char *set_malloc_ptr (char *ptr
)
2880 m_malloc
.reset (ptr
);
2887 gdb::unique_xmalloc_ptr
<char> m_malloc
;
2891 demangle_for_lookup (const char *name
, enum language lang
,
2892 demangle_result_storage
&storage
);
2894 /* Test to see if the symbol of language SYMBOL_LANGUAGE specified by
2895 SYMNAME (which is already demangled for C++ symbols) matches
2896 SYM_TEXT in the first SYM_TEXT_LEN characters. If so, add it to
2897 the current completion list and return true. Otherwise, return
2899 bool completion_list_add_name (completion_tracker
&tracker
,
2900 language symbol_language
,
2901 const char *symname
,
2902 const lookup_name_info
&lookup_name
,
2903 const char *text
, const char *word
);
2905 /* A simple symbol searching class. */
2907 class symbol_searcher
2910 /* Returns the symbols found for the search. */
2911 const std::vector
<block_symbol
> &
2912 matching_symbols () const
2917 /* Returns the minimal symbols found for the search. */
2918 const std::vector
<bound_minimal_symbol
> &
2919 matching_msymbols () const
2921 return m_minimal_symbols
;
2924 /* Search for all symbols named NAME in LANGUAGE with DOMAIN, restricting
2925 search to FILE_SYMTABS and SEARCH_PSPACE, both of which may be NULL
2926 to search all symtabs and program spaces. */
2927 void find_all_symbols (const std::string
&name
,
2928 const struct language_defn
*language
,
2929 domain_search_flags domain_search_flags
,
2930 std::vector
<symtab
*> *search_symtabs
,
2931 struct program_space
*search_pspace
);
2933 /* Reset this object to perform another search. */
2937 m_minimal_symbols
.clear ();
2941 /* Matching debug symbols. */
2942 std::vector
<block_symbol
> m_symbols
;
2944 /* Matching non-debug symbols. */
2945 std::vector
<bound_minimal_symbol
> m_minimal_symbols
;
2948 /* Class used to encapsulate the filename filtering for the "info sources"
2951 struct info_sources_filter
2953 /* If filename filtering is being used (see M_C_REGEXP) then which part
2954 of the filename is being filtered against? */
2957 /* Match against the full filename. */
2960 /* Match only against the directory part of the full filename. */
2963 /* Match only against the basename part of the full filename. */
2967 /* Create a filter of MATCH_TYPE using regular expression REGEXP. If
2968 REGEXP is nullptr then all files will match the filter and MATCH_TYPE
2971 The string pointed too by REGEXP must remain live and unchanged for
2972 this lifetime of this object as the object only retains a copy of the
2974 info_sources_filter (match_on match_type
, const char *regexp
);
2976 DISABLE_COPY_AND_ASSIGN (info_sources_filter
);
2978 /* Does FULLNAME match the filter defined by this object, return true if
2979 it does, otherwise, return false. If there is no filtering defined
2980 then this function will always return true. */
2981 bool matches (const char *fullname
) const;
2985 /* The type of filtering in place. */
2986 match_on m_match_type
;
2988 /* Points to the original regexp used to create this filter. */
2989 const char *m_regexp
;
2991 /* A compiled version of M_REGEXP. This object is only given a value if
2992 M_REGEXP is not nullptr and is not the empty string. */
2993 std::optional
<compiled_regex
> m_c_regexp
;
2996 /* Perform the core of the 'info sources' command.
2998 FILTER is used to perform regular expression based filtering on the
2999 source files that will be displayed.
3001 Output is written to UIOUT in CLI or MI style as appropriate. */
3003 extern void info_sources_worker (struct ui_out
*uiout
,
3004 bool group_by_objfile
,
3005 const info_sources_filter
&filter
);
3007 /* This function returns the address at which the function epilogue begins,
3008 according to the linetable.
3010 Returns an empty optional if EPILOGUE_BEGIN is never set in the
3013 std::optional
<CORE_ADDR
> find_epilogue_using_linetable (CORE_ADDR func_addr
);
3015 /* Search an array of symbols for one named NAME. Name comparison is
3016 done using strcmp -- i.e., this is only useful for simple names.
3017 Returns the symbol, if found, or nullptr if not. */
3019 extern struct symbol
*search_symbol_list (const char *name
, int num
,
3020 struct symbol
**syms
);
3022 #endif /* GDB_SYMTAB_H */