1 /* Symbol table definitions for GDB.
3 Copyright (C) 1986-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #if !defined (SYMTAB_H)
27 #include "gdbsupport/gdb_vecs.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 "gdbsupport/iterator-range.h"
37 #include "completer.h"
38 #include "gdb-demangle.h"
39 #include "split-name.h"
43 /* Opaque declarations. */
57 struct cmd_list_element
;
59 struct lookup_name_info
;
60 struct code_breakpoint
;
62 /* How to match a lookup name against a symbol search name. */
63 enum class symbol_name_match_type
65 /* Wild matching. Matches unqualified symbol names in all
66 namespace/module/packages, etc. */
69 /* Full matching. The lookup name indicates a fully-qualified name,
70 and only matches symbol search names in the specified
71 namespace/module/package. */
74 /* Search name matching. This is like FULL, but the search name did
75 not come from the user; instead it is already a search name
76 retrieved from a search_name () call.
77 For Ada, this avoids re-encoding an already-encoded search name
78 (which would potentially incorrectly lowercase letters in the
79 linkage/search name that should remain uppercase). For C++, it
80 avoids trying to demangle a name we already know is
84 /* Expression matching. The same as FULL matching in most
85 languages. The same as WILD matching in Ada. */
89 /* Hash the given symbol search name according to LANGUAGE's
91 extern unsigned int search_name_hash (enum language language
,
92 const char *search_name
);
94 /* Ada-specific bits of a lookup_name_info object. This is lazily
95 constructed on demand. */
97 class ada_lookup_name_info final
101 explicit ada_lookup_name_info (const lookup_name_info
&lookup_name
);
103 /* Compare SYMBOL_SEARCH_NAME with our lookup name, using MATCH_TYPE
104 as name match type. Returns true if there's a match, false
105 otherwise. If non-NULL, store the matching results in MATCH. */
106 bool matches (const char *symbol_search_name
,
107 symbol_name_match_type match_type
,
108 completion_match_result
*comp_match_res
) const;
110 /* The Ada-encoded lookup name. */
111 const std::string
&lookup_name () const
112 { return m_encoded_name
; }
114 /* Return true if we're supposed to be doing a wild match look
116 bool wild_match_p () const
117 { return m_wild_match_p
; }
119 /* Return true if we're looking up a name inside package
121 bool standard_p () const
122 { return m_standard_p
; }
124 /* Return true if doing a verbatim match. */
125 bool verbatim_p () const
126 { return m_verbatim_p
; }
128 /* A wrapper for ::split_name that handles some Ada-specific
130 std::vector
<std::string_view
> split_name () const
134 /* For verbatim matches, just return the encoded name
136 std::vector
<std::string_view
> result
;
137 result
.emplace_back (m_encoded_name
);
140 /* Otherwise, split the decoded name for matching. */
141 return ::split_name (m_decoded_name
.c_str (), split_style::DOT_STYLE
);
145 /* The Ada-encoded lookup name. */
146 std::string m_encoded_name
;
148 /* The decoded lookup name. This is formed by calling ada_decode
149 with both 'operators' and 'wide' set to false. */
150 std::string m_decoded_name
;
152 /* Whether the user-provided lookup name was Ada encoded. If so,
153 then return encoded names in the 'matches' method's 'completion
154 match result' output. */
155 bool m_encoded_p
: 1;
157 /* True if really doing wild matching. Even if the user requests
158 wild matching, some cases require full matching. */
159 bool m_wild_match_p
: 1;
161 /* True if doing a verbatim match. This is true if the decoded
162 version of the symbol name is wrapped in '<'/'>'. This is an
163 escape hatch users can use to look up symbols the Ada encoding
164 does not understand. */
165 bool m_verbatim_p
: 1;
167 /* True if the user specified a symbol name that is inside package
168 Standard. Symbol names inside package Standard are handled
169 specially. We always do a non-wild match of the symbol name
170 without the "standard__" prefix, and only search static and
171 global symbols. This was primarily introduced in order to allow
172 the user to specifically access the standard exceptions using,
173 for instance, Standard.Constraint_Error when Constraint_Error is
174 ambiguous (due to the user defining its own Constraint_Error
175 entity inside its program). */
176 bool m_standard_p
: 1;
179 /* Language-specific bits of a lookup_name_info object, for languages
180 that do name searching using demangled names (C++/D/Go). This is
181 lazily constructed on demand. */
183 struct demangle_for_lookup_info final
186 demangle_for_lookup_info (const lookup_name_info
&lookup_name
,
189 /* The demangled lookup name. */
190 const std::string
&lookup_name () const
191 { return m_demangled_name
; }
194 /* The demangled lookup name. */
195 std::string m_demangled_name
;
198 /* Object that aggregates all information related to a symbol lookup
199 name. I.e., the name that is matched against the symbol's search
200 name. Caches per-language information so that it doesn't require
201 recomputing it for every symbol comparison, like for example the
202 Ada encoded name and the symbol's name hash for a given language.
203 The object is conceptually immutable once constructed, and thus has
204 no setters. This is to prevent some code path from tweaking some
205 property of the lookup name for some local reason and accidentally
206 altering the results of any continuing search(es).
207 lookup_name_info objects are generally passed around as a const
208 reference to reinforce that. (They're not passed around by value
209 because they're not small.) */
210 class lookup_name_info final
213 /* We delete this overload so that the callers are required to
214 explicitly handle the lifetime of the name. */
215 lookup_name_info (std::string
&&name
,
216 symbol_name_match_type match_type
,
217 bool completion_mode
= false,
218 bool ignore_parameters
= false) = delete;
220 /* This overload requires that NAME have a lifetime at least as long
221 as the lifetime of this object. */
222 lookup_name_info (const std::string
&name
,
223 symbol_name_match_type match_type
,
224 bool completion_mode
= false,
225 bool ignore_parameters
= false)
226 : m_match_type (match_type
),
227 m_completion_mode (completion_mode
),
228 m_ignore_parameters (ignore_parameters
),
232 /* This overload requires that NAME have a lifetime at least as long
233 as the lifetime of this object. */
234 lookup_name_info (const char *name
,
235 symbol_name_match_type match_type
,
236 bool completion_mode
= false,
237 bool ignore_parameters
= false)
238 : m_match_type (match_type
),
239 m_completion_mode (completion_mode
),
240 m_ignore_parameters (ignore_parameters
),
244 /* Getters. See description of each corresponding field. */
245 symbol_name_match_type
match_type () const { return m_match_type
; }
246 bool completion_mode () const { return m_completion_mode
; }
247 std::string_view
name () const { return m_name
; }
248 const bool ignore_parameters () const { return m_ignore_parameters
; }
250 /* Like the "name" method but guarantees that the returned string is
252 const char *c_str () const
254 /* Actually this is always guaranteed due to how the class is
256 return m_name
.data ();
259 /* Return a version of this lookup name that is usable with
260 comparisons against symbols have no parameter info, such as
261 psymbols and GDB index symbols. */
262 lookup_name_info
make_ignore_params () const
264 return lookup_name_info (c_str (), m_match_type
, m_completion_mode
,
265 true /* ignore params */);
268 /* Get the search name hash for searches in language LANG. */
269 unsigned int search_name_hash (language lang
) const;
271 /* Get the search name for searches in language LANG. */
272 const char *language_lookup_name (language lang
) const
277 return ada ().lookup_name ().c_str ();
279 return cplus ().lookup_name ().c_str ();
281 return d ().lookup_name ().c_str ();
283 return go ().lookup_name ().c_str ();
285 return m_name
.data ();
289 /* A wrapper for ::split_name (see split-name.h) that splits this
290 name, and that handles any language-specific peculiarities. */
291 std::vector
<std::string_view
> split_name (language lang
) const
293 if (lang
== language_ada
)
294 return ada ().split_name ();
295 split_style style
= split_style::NONE
;
300 style
= split_style::CXX
;
304 style
= split_style::DOT_STYLE
;
307 return ::split_name (language_lookup_name (lang
), style
);
310 /* Get the Ada-specific lookup info. */
311 const ada_lookup_name_info
&ada () const
317 /* Get the C++-specific lookup info. */
318 const demangle_for_lookup_info
&cplus () const
320 maybe_init (m_cplus
, language_cplus
);
324 /* Get the D-specific lookup info. */
325 const demangle_for_lookup_info
&d () const
327 maybe_init (m_d
, language_d
);
331 /* Get the Go-specific lookup info. */
332 const demangle_for_lookup_info
&go () const
334 maybe_init (m_go
, language_go
);
338 /* Get a reference to a lookup_name_info object that matches any
340 static const lookup_name_info
&match_any ();
343 /* Initialize FIELD, if not initialized yet. */
344 template<typename Field
, typename
... Args
>
345 void maybe_init (Field
&field
, Args
&&... args
) const
348 field
.emplace (*this, std::forward
<Args
> (args
)...);
351 /* The lookup info as passed to the ctor. */
352 symbol_name_match_type m_match_type
;
353 bool m_completion_mode
;
354 bool m_ignore_parameters
;
355 std::string_view m_name
;
357 /* Language-specific info. These fields are filled lazily the first
358 time a lookup is done in the corresponding language. They're
359 mutable because lookup_name_info objects are typically passed
360 around by const reference (see intro), and they're conceptually
361 "cache" that can always be reconstructed from the non-mutable
363 mutable std::optional
<ada_lookup_name_info
> m_ada
;
364 mutable std::optional
<demangle_for_lookup_info
> m_cplus
;
365 mutable std::optional
<demangle_for_lookup_info
> m_d
;
366 mutable std::optional
<demangle_for_lookup_info
> m_go
;
368 /* The demangled hashes. Stored in an array with one entry for each
369 possible language. The second array records whether we've
370 already computed the each language's hash. (These are separate
371 arrays instead of a single array of optional<unsigned> to avoid
372 alignment padding). */
373 mutable std::array
<unsigned int, nr_languages
> m_demangled_hashes
;
374 mutable std::array
<bool, nr_languages
> m_demangled_hashes_p
{};
377 /* Comparison function for completion symbol lookup.
379 Returns true if the symbol name matches against LOOKUP_NAME.
381 SYMBOL_SEARCH_NAME should be a symbol's "search" name.
383 On success and if non-NULL, COMP_MATCH_RES->match is set to point
384 to the symbol name as should be presented to the user as a
385 completion match list element. In most languages, this is the same
386 as the symbol's search name, but in some, like Ada, the display
387 name is dynamically computed within the comparison routine.
389 Also, on success and if non-NULL, COMP_MATCH_RES->match_for_lcd
390 points the part of SYMBOL_SEARCH_NAME that was considered to match
391 LOOKUP_NAME. E.g., in C++, in linespec/wild mode, if the symbol is
392 "foo::function()" and LOOKUP_NAME is "function(", MATCH_FOR_LCD
393 points to "function()" inside SYMBOL_SEARCH_NAME. */
394 typedef bool (symbol_name_matcher_ftype
)
395 (const char *symbol_search_name
,
396 const lookup_name_info
&lookup_name
,
397 completion_match_result
*comp_match_res
);
399 /* Some of the structures in this file are space critical.
400 The space-critical structures are:
402 struct general_symbol_info
404 struct partial_symbol
406 These structures are laid out to encourage good packing.
407 They use ENUM_BITFIELD and short int fields, and they order the
408 structure members so that fields less than a word are next
409 to each other so they can be packed together. */
411 /* Rearranged: used ENUM_BITFIELD and rearranged field order in
412 all the space critical structures (plus struct minimal_symbol).
413 Memory usage dropped from 99360768 bytes to 90001408 bytes.
414 I measured this with before-and-after tests of
415 "HEAD-old-gdb -readnow HEAD-old-gdb" and
416 "HEAD-new-gdb -readnow HEAD-old-gdb" on native i686-pc-linux-gnu,
417 red hat linux 8, with LD_LIBRARY_PATH=/usr/lib/debug,
418 typing "maint space 1" at the first command prompt.
420 Here is another measurement (from andrew c):
421 # no /usr/lib/debug, just plain glibc, like a normal user
423 (gdb) break internal_error
425 (gdb) maint internal-error
429 gdb gdb_6_0_branch 2003-08-19 space used: 8896512
430 gdb HEAD 2003-08-19 space used: 8904704
431 gdb HEAD 2003-08-21 space used: 8396800 (+symtab.h)
432 gdb HEAD 2003-08-21 space used: 8265728 (+gdbtypes.h)
434 The third line shows the savings from the optimizations in symtab.h.
435 The fourth line shows the savings from the optimizations in
436 gdbtypes.h. Both optimizations are in gdb HEAD now.
438 --chastain 2003-08-21 */
440 /* Define a structure for the information that is common to all symbol types,
441 including minimal symbols, partial symbols, and full symbols. In a
442 multilanguage environment, some language specific information may need to
443 be recorded along with each symbol. */
445 /* This structure is space critical. See space comments at the top. */
447 struct general_symbol_info
449 /* Short version as to when to use which name accessor:
450 Use natural_name () to refer to the name of the symbol in the original
451 source code. Use linkage_name () if you want to know what the linker
452 thinks the symbol's name is. Use print_name () for output. Use
453 demangled_name () if you specifically need to know whether natural_name ()
454 and linkage_name () are different. */
456 const char *linkage_name () const
459 /* Return SYMBOL's "natural" name, i.e. the name that it was called in
460 the original source code. In languages like C++ where symbols may
461 be mangled for ease of manipulation by the linker, this is the
463 const char *natural_name () const;
465 /* Returns a version of the name of a symbol that is
466 suitable for output. In C++ this is the "demangled" form of the
467 name if demangle is on and the "mangled" form of the name if
468 demangle is off. In other languages this is just the symbol name.
469 The result should never be NULL. Don't use this for internal
470 purposes (e.g. storing in a hashtable): it's only suitable for output. */
471 const char *print_name () const
472 { return demangle
? natural_name () : linkage_name (); }
474 /* Return the demangled name for a symbol based on the language for
475 that symbol. If no demangled name exists, return NULL. */
476 const char *demangled_name () const;
478 /* Returns the name to be used when sorting and searching symbols.
479 In C++, we search for the demangled form of a name,
480 and so sort symbols accordingly. In Ada, however, we search by mangled
481 name. If there is no distinct demangled name, then this
482 returns the same value (same pointer) as linkage_name (). */
483 const char *search_name () const;
485 /* Set just the linkage name of a symbol; do not try to demangle
486 it. Used for constructs which do not have a mangled name,
487 e.g. struct tags. Unlike compute_and_set_names, linkage_name must
488 be terminated and either already on the objfile's obstack or
489 permanently allocated. */
490 void set_linkage_name (const char *linkage_name
)
491 { m_name
= linkage_name
; }
493 /* Set the demangled name of this symbol to NAME. NAME must be
494 already correctly allocated. If the symbol's language is Ada,
495 then the name is ignored and the obstack is set. */
496 void set_demangled_name (const char *name
, struct obstack
*obstack
);
498 enum language
language () const
499 { return m_language
; }
501 /* Initializes the language dependent portion of a symbol
502 depending upon the language for the symbol. */
503 void set_language (enum language language
, struct obstack
*obstack
);
505 /* Set the linkage and natural names of a symbol, by demangling
506 the linkage name. If linkage_name may not be nullterminated,
507 copy_name must be set to true. */
508 void compute_and_set_names (std::string_view linkage_name
, bool copy_name
,
509 struct objfile_per_bfd_storage
*per_bfd
,
510 std::optional
<hashval_t
> hash
511 = std::optional
<hashval_t
> ());
513 CORE_ADDR
value_address () const
515 return m_value
.address
;
518 void set_value_address (CORE_ADDR address
)
520 m_value
.address
= address
;
523 /* Return the unrelocated address of this symbol. */
524 unrelocated_addr
unrelocated_address () const
526 return m_value
.unrel_addr
;
529 /* Set the unrelocated address of this symbol. */
530 void set_unrelocated_address (unrelocated_addr addr
)
532 m_value
.unrel_addr
= addr
;
535 /* Name of the symbol. This is a required field. Storage for the
536 name is allocated on the objfile_obstack for the associated
537 objfile. For languages like C++ that make a distinction between
538 the mangled name and demangled name, this is the mangled
543 /* Value of the symbol. Which member of this union to use, and what
544 it means, depends on what kind of symbol this is and its
545 SYMBOL_CLASS. See comments there for more details. All of these
546 are in host byte order (though what they point to might be in
547 target byte order, e.g. LOC_CONST_BYTES). */
553 const struct block
*block
;
555 const gdb_byte
*bytes
;
559 /* The address, if unrelocated. An unrelocated symbol does not
560 have the runtime section offset applied. */
561 unrelocated_addr unrel_addr
;
563 /* A common block. Used with LOC_COMMON_BLOCK. */
565 const struct common_block
*common_block
;
567 /* For opaque typedef struct chain. */
569 struct symbol
*chain
;
573 /* Since one and only one language can apply, wrap the language specific
574 information inside a union. */
578 /* A pointer to an obstack that can be used for storage associated
579 with this symbol. This is only used by Ada, and only when the
580 'ada_mangled' field is zero. */
581 struct obstack
*obstack
;
583 /* This is used by languages which wish to store a demangled name.
584 currently used by Ada, C++, and Objective C. */
585 const char *demangled_name
;
589 /* Record the source code language that applies to this symbol.
590 This is used to select one of the fields from the language specific
593 ENUM_BITFIELD(language
) m_language
: LANGUAGE_BITS
;
595 /* This is only used by Ada. If set, then the 'demangled_name' field
596 of language_specific is valid. Otherwise, the 'obstack' field is
598 unsigned int ada_mangled
: 1;
600 /* Which section is this symbol in? This is an index into
601 section_offsets for this objfile. Negative means that the symbol
602 does not get relocated relative to a section. */
606 /* Set the index into the obj_section list (within the containing
607 objfile) for the section that contains this symbol. See M_SECTION
610 void set_section_index (int idx
)
613 /* Return the index into the obj_section list (within the containing
614 objfile) for the section that contains this symbol. See M_SECTION
617 auto section_index () const
618 { return m_section
; }
620 /* Return the obj_section from OBJFILE for this symbol. The symbol
621 returned is based on the SECTION member variable, and can be nullptr
622 if SECTION is negative. */
624 struct obj_section
*obj_section (const struct objfile
*objfile
) const;
627 extern CORE_ADDR
symbol_overlayed_address (CORE_ADDR
, struct obj_section
*);
629 /* Try to determine the demangled name for a symbol, based on the
630 language of that symbol. If the language is set to language_auto,
631 it will attempt to find any demangling algorithm that works and
632 then set the language appropriately. The returned name is allocated
633 by the demangler and should be xfree'd. */
635 extern gdb::unique_xmalloc_ptr
<char> symbol_find_demangled_name
636 (struct general_symbol_info
*gsymbol
, const char *mangled
);
638 /* Return true if NAME matches the "search" name of GSYMBOL, according
639 to the symbol's language. */
640 extern bool symbol_matches_search_name
641 (const struct general_symbol_info
*gsymbol
,
642 const lookup_name_info
&name
);
644 /* Compute the hash of the given symbol search name of a symbol of
645 language LANGUAGE. */
646 extern unsigned int search_name_hash (enum language language
,
647 const char *search_name
);
649 /* Classification types for a minimal symbol. These should be taken as
650 "advisory only", since if gdb can't easily figure out a
651 classification it simply selects mst_unknown. It may also have to
652 guess when it can't figure out which is a better match between two
653 types (mst_data versus mst_bss) for example. Since the minimal
654 symbol info is sometimes derived from the BFD library's view of a
655 file, we need to live with what information bfd supplies. */
657 enum minimal_symbol_type
659 mst_unknown
= 0, /* Unknown type, the default */
660 mst_text
, /* Generally executable instructions */
662 /* A GNU ifunc symbol, in the .text section. GDB uses to know
663 whether the user is setting a breakpoint on a GNU ifunc function,
664 and thus GDB needs to actually set the breakpoint on the target
665 function. It is also used to know whether the program stepped
666 into an ifunc resolver -- the resolver may get a separate
667 symbol/alias under a different name, but it'll have the same
668 address as the ifunc symbol. */
669 mst_text_gnu_ifunc
, /* Executable code returning address
670 of executable code */
672 /* A GNU ifunc function descriptor symbol, in a data section
673 (typically ".opd"). Seen on architectures that use function
674 descriptors, like PPC64/ELFv1. In this case, this symbol's value
675 is the address of the descriptor. There'll be a corresponding
676 mst_text_gnu_ifunc synthetic symbol for the text/entry
678 mst_data_gnu_ifunc
, /* Executable code returning address
679 of executable code */
681 mst_slot_got_plt
, /* GOT entries for .plt sections */
682 mst_data
, /* Generally initialized data */
683 mst_bss
, /* Generally uninitialized data */
684 mst_abs
, /* Generally absolute (nonrelocatable) */
685 /* GDB uses mst_solib_trampoline for the start address of a shared
686 library trampoline entry. Breakpoints for shared library functions
687 are put there if the shared library is not yet loaded.
688 After the shared library is loaded, lookup_minimal_symbol will
689 prefer the minimal symbol from the shared library (usually
690 a mst_text symbol) over the mst_solib_trampoline symbol, and the
691 breakpoints will be moved to their true address in the shared
692 library via breakpoint_re_set. */
693 mst_solib_trampoline
, /* Shared library trampoline code */
694 /* For the mst_file* types, the names are only guaranteed to be unique
695 within a given .o file. */
696 mst_file_text
, /* Static version of mst_text */
697 mst_file_data
, /* Static version of mst_data */
698 mst_file_bss
, /* Static version of mst_bss */
702 /* The number of enum minimal_symbol_type values, with some padding for
703 reasonable growth. */
704 #define MINSYM_TYPE_BITS 4
705 static_assert (nr_minsym_types
<= (1 << MINSYM_TYPE_BITS
));
707 /* Define a simple structure used to hold some very basic information about
708 all defined global symbols (text, data, bss, abs, etc). The only required
709 information is the general_symbol_info.
711 In many cases, even if a file was compiled with no special options for
712 debugging at all, as long as was not stripped it will contain sufficient
713 information to build a useful minimal symbol table using this structure.
714 Even when a file contains enough debugging information to build a full
715 symbol table, these minimal symbols are still useful for quickly mapping
716 between names and addresses, and vice versa. They are also sometimes
717 used to figure out what full symbol table entries need to be read in. */
719 struct minimal_symbol
: public general_symbol_info
721 LONGEST
value_longest () const
723 return m_value
.ivalue
;
726 /* The relocated address of the minimal symbol, using the section
727 offsets from OBJFILE. */
728 CORE_ADDR
value_address (objfile
*objfile
) const;
730 /* It does not make sense to call this for minimal symbols, as they
731 are stored unrelocated. */
732 CORE_ADDR
value_address () const = delete;
734 /* The unrelocated address of the minimal symbol. */
735 unrelocated_addr
unrelocated_address () const
737 return m_value
.unrel_addr
;
740 /* The unrelocated address just after the end of the the minimal
742 unrelocated_addr
unrelocated_end_address () const
744 return unrelocated_addr (CORE_ADDR (unrelocated_address ()) + size ());
747 /* Return this minimal symbol's type. */
749 minimal_symbol_type
type () const
754 /* Set this minimal symbol's type. */
756 void set_type (minimal_symbol_type type
)
761 /* Return this minimal symbol's size. */
763 unsigned long size () const
768 /* Set this minimal symbol's size. */
770 void set_size (unsigned long size
)
776 /* Return true if this minimal symbol's size is known. */
778 bool has_size () const
783 /* Return this minimal symbol's first target-specific flag. */
785 bool target_flag_1 () const
787 return m_target_flag_1
;
790 /* Set this minimal symbol's first target-specific flag. */
792 void set_target_flag_1 (bool target_flag_1
)
794 m_target_flag_1
= target_flag_1
;
797 /* Return this minimal symbol's second target-specific flag. */
799 bool target_flag_2 () const
801 return m_target_flag_2
;
804 /* Set this minimal symbol's second target-specific flag. */
806 void set_target_flag_2 (bool target_flag_2
)
808 m_target_flag_2
= target_flag_2
;
811 /* Size of this symbol. stabs_end_psymtab in stabsread.c uses this
812 information to calculate the end of the partial symtab based on the
813 address of the last symbol plus the size of the last symbol. */
815 unsigned long m_size
;
817 /* Which source file is this symbol in? Only relevant for mst_file_*. */
818 const char *filename
;
820 /* Classification type for this minimal symbol. */
822 ENUM_BITFIELD(minimal_symbol_type
) m_type
: MINSYM_TYPE_BITS
;
824 /* Non-zero if this symbol was created by gdb.
825 Such symbols do not appear in the output of "info var|fun". */
826 unsigned int created_by_gdb
: 1;
828 /* Two flag bits provided for the use of the target. */
829 unsigned int m_target_flag_1
: 1;
830 unsigned int m_target_flag_2
: 1;
832 /* Nonzero iff the size of the minimal symbol has been set.
833 Symbol size information can sometimes not be determined, because
834 the object file format may not carry that piece of information. */
835 unsigned int m_has_size
: 1;
837 /* Non-zero if this symbol ever had its demangled name set (even if
838 it was set to NULL). */
839 unsigned int name_set
: 1;
841 /* Minimal symbols with the same hash key are kept on a linked
842 list. This is the link. */
844 struct minimal_symbol
*hash_next
;
846 /* Minimal symbols are stored in two different hash tables. This is
847 the `next' pointer for the demangled hash table. */
849 struct minimal_symbol
*demangled_hash_next
;
851 /* True if this symbol is of some data type. */
853 bool data_p () const;
855 /* True if MSYMBOL is of some text type. */
857 bool text_p () const;
859 /* For data symbols only, given an objfile, if 'maybe_copied'
860 evaluates to 'true' for that objfile, then the symbol might be
861 subject to copy relocation. In this case, a minimal symbol
862 matching the symbol's linkage name is first looked for in the
863 main objfile. If found, then that address is used; otherwise the
864 address in this symbol is used. */
866 bool maybe_copied (objfile
*objfile
) const;
869 /* Return the address of this minimal symbol, in the context of OBJF. The
870 MAYBE_COPIED flag must be set. If the minimal symbol appears in the
871 main program's minimal symbols, then that minsym's address is
872 returned; otherwise, this minimal symbol's address is returned. */
873 CORE_ADDR
get_maybe_copied_address (objfile
*objf
) const;
880 /* Represent one symbol name; a variable, constant, function or typedef. */
882 /* Different name domains for symbols. Looking up a symbol specifies a
883 domain and ignores symbol definitions in other name domains. */
887 #define SYM_DOMAIN(X) X ## _DOMAIN,
888 #include "sym-domains.def"
892 /* The number of bits in a symbol used to represent the domain. */
894 #define SYMBOL_DOMAIN_BITS 3
896 extern const char *domain_name (domain_enum
);
898 /* Flags used for searching symbol tables. These can be combined to
899 let the search match multiple kinds of symbol. */
900 enum domain_search_flag
902 #define SYM_DOMAIN(X) \
903 SEARCH_ ## X ## _DOMAIN = (1 << X ## _DOMAIN),
904 #include "sym-domains.def"
907 DEF_ENUM_FLAGS_TYPE (enum domain_search_flag
, domain_search_flags
);
909 /* A convenience constant to search for any symbol. */
910 constexpr domain_search_flags SEARCH_ALL_DOMAINS
911 = ((domain_search_flags
) 0
912 #define SYM_DOMAIN(X) | SEARCH_ ## X ## _DOMAIN
913 #include "sym-domains.def"
917 /* A convenience define for "C-like" name lookups, matching variables,
918 types, and functions. */
920 (SEARCH_VAR_DOMAIN | SEARCH_FUNCTION_DOMAIN | SEARCH_TYPE_DOMAIN)
922 /* Return a string representing the given flags. */
923 extern std::string
domain_name (domain_search_flags
);
925 /* Convert a symbol domain to search flags. */
926 static inline domain_search_flags
927 to_search_flags (domain_enum domain
)
929 return domain_search_flags (domain_search_flag (1 << domain
));
932 /* Return true if the given domain matches the given flags, false
935 search_flags_matches (domain_search_flags flags
, domain_enum domain
)
937 return (flags
& to_search_flags (domain
)) != 0;
940 /* Some helpers for Python and Guile to account for backward
941 compatibility. Those exposed the domains for lookup as well as
942 checking attributes of a symbol, so special encoding and decoding
943 is needed to continue to support both uses. Domain constants must
944 remain unchanged, so that comparing a symbol's domain against a
945 constant yields the correct result, so search symbols are
946 distinguished by adding a flag bit. This way, either sort of
947 constant can be used for lookup. */
950 constexpr int SCRIPTING_SEARCH_FLAG
= 0x8000;
951 static_assert (SCRIPTING_SEARCH_FLAG
> SEARCH_ALL_DOMAINS
);
953 /* Convert a domain constant to a "scripting domain". */
954 static constexpr inline int
955 to_scripting_domain (domain_enum val
)
960 /* Convert a search constant to a "scripting domain". */
961 static constexpr inline int
962 to_scripting_domain (domain_search_flags val
)
964 return SCRIPTING_SEARCH_FLAG
| (int) val
;
967 /* Convert from a "scripting domain" constant back to search flags.
968 Throws an exception if VAL is not one of the allowable values. */
969 extern domain_search_flags
from_scripting_domain (int val
);
971 /* An address-class says where to find the value of a symbol. */
975 /* Not used; catches errors. */
979 /* Value is constant int SYMBOL_VALUE, host byteorder. */
983 /* Value is at fixed address SYMBOL_VALUE_ADDRESS. */
987 /* Value is in register. SYMBOL_VALUE is the register number
988 in the original debug format. SYMBOL_REGISTER_OPS holds a
989 function that can be called to transform this into the
990 actual register number this represents in a specific target
991 architecture (gdbarch).
993 For some symbol formats (stabs, for some compilers at least),
994 the compiler generates two symbols, an argument and a register.
995 In some cases we combine them to a single LOC_REGISTER in symbol
996 reading, but currently not for all cases (e.g. it's passed on the
997 stack and then loaded into a register). */
1001 /* It's an argument; the value is at SYMBOL_VALUE offset in arglist. */
1005 /* Value address is at SYMBOL_VALUE offset in arglist. */
1009 /* Value is in specified register. Just like LOC_REGISTER except the
1010 register holds the address of the argument instead of the argument
1011 itself. This is currently used for the passing of structs and unions
1012 on sparc and hppa. It is also used for call by reference where the
1013 address is in a register, at least by mipsread.c. */
1017 /* Value is a local variable at SYMBOL_VALUE offset in stack frame. */
1021 /* Value not used; definition in SYMBOL_TYPE. Symbols in the domain
1022 STRUCT_DOMAIN all have this class. */
1026 /* Value is address SYMBOL_VALUE_ADDRESS in the code. */
1030 /* In a symbol table, value is SYMBOL_BLOCK_VALUE of a `struct block'.
1031 In a partial symbol table, SYMBOL_VALUE_ADDRESS is the start address
1032 of the block. Function names have this class. */
1036 /* Value is a constant byte-sequence pointed to by SYMBOL_VALUE_BYTES, in
1037 target byte order. */
1041 /* Value is at fixed address, but the address of the variable has
1042 to be determined from the minimal symbol table whenever the
1043 variable is referenced.
1044 This happens if debugging information for a global symbol is
1045 emitted and the corresponding minimal symbol is defined
1046 in another object file or runtime common storage.
1047 The linker might even remove the minimal symbol if the global
1048 symbol is never referenced, in which case the symbol remains
1051 GDB would normally find the symbol in the minimal symbol table if it will
1052 not find it in the full symbol table. But a reference to an external
1053 symbol in a local block shadowing other definition requires full symbol
1054 without possibly having its address available for LOC_STATIC. Testcase
1055 is provided as `gdb.dwarf2/dw2-unresolved.exp'.
1057 This is also used for thread local storage (TLS) variables. In
1058 this case, the address of the TLS variable must be determined
1059 when the variable is referenced, from the msymbol's address,
1060 which is the offset of the TLS variable in the thread local
1061 storage of the shared library/object. */
1065 /* The variable does not actually exist in the program.
1066 The value is ignored. */
1070 /* The variable's address is computed by a set of location
1071 functions (see "struct symbol_computed_ops" below). */
1074 /* The variable uses general_symbol_info->value->common_block field.
1075 It also always uses COMMON_BLOCK_DOMAIN. */
1078 /* Not used, just notes the boundary of the enum. */
1082 /* The number of bits needed for values in enum address_class, with some
1083 padding for reasonable growth, and room for run-time registered address
1084 classes. See symtab.c:MAX_SYMBOL_IMPLS.
1085 This is a #define so that we can have a assertion elsewhere to
1086 verify that we have reserved enough space for synthetic address
1088 #define SYMBOL_ACLASS_BITS 5
1089 static_assert (LOC_FINAL_VALUE
<= (1 << SYMBOL_ACLASS_BITS
));
1091 /* The methods needed to implement LOC_COMPUTED. These methods can
1092 use the symbol's .aux_value for additional per-symbol information.
1094 At present this is only used to implement location expressions. */
1096 struct symbol_computed_ops
1099 /* Return the value of the variable SYMBOL, relative to the stack
1100 frame FRAME. If the variable has been optimized out, return
1103 Iff `read_needs_frame (SYMBOL)' is not SYMBOL_NEEDS_FRAME, then
1104 FRAME may be zero. */
1106 struct value
*(*read_variable
) (struct symbol
* symbol
,
1107 const frame_info_ptr
&frame
);
1109 /* Read variable SYMBOL like read_variable at (callee) FRAME's function
1110 entry. SYMBOL should be a function parameter, otherwise
1111 NO_ENTRY_VALUE_ERROR will be thrown. */
1112 struct value
*(*read_variable_at_entry
) (struct symbol
*symbol
,
1113 const frame_info_ptr
&frame
);
1115 /* Find the "symbol_needs_kind" value for the given symbol. This
1116 value determines whether reading the symbol needs memory (e.g., a
1117 global variable), just registers (a thread-local), or a frame (a
1119 enum symbol_needs_kind (*get_symbol_read_needs
) (struct symbol
* symbol
);
1121 /* Write to STREAM a natural-language description of the location of
1122 SYMBOL, in the context of ADDR. */
1123 void (*describe_location
) (struct symbol
* symbol
, CORE_ADDR addr
,
1124 struct ui_file
* stream
);
1126 /* Non-zero if this symbol's address computation is dependent on PC. */
1127 unsigned char location_has_loclist
;
1129 /* Tracepoint support. Append bytecodes to the tracepoint agent
1130 expression AX that push the address of the object SYMBOL. Set
1131 VALUE appropriately. Note --- for objects in registers, this
1132 needn't emit any code; as long as it sets VALUE properly, then
1133 the caller will generate the right code in the process of
1134 treating this as an lvalue or rvalue. */
1136 void (*tracepoint_var_ref
) (struct symbol
*symbol
, struct agent_expr
*ax
,
1137 struct axs_value
*value
);
1139 /* Generate C code to compute the location of SYMBOL. The C code is
1140 emitted to STREAM. GDBARCH is the current architecture and PC is
1141 the PC at which SYMBOL's location should be evaluated.
1142 REGISTERS_USED is a vector indexed by register number; the
1143 generator function should set an element in this vector if the
1144 corresponding register is needed by the location computation.
1145 The generated C code must assign the location to a local
1146 variable; this variable's name is RESULT_NAME. */
1148 void (*generate_c_location
) (struct symbol
*symbol
, string_file
*stream
,
1149 struct gdbarch
*gdbarch
,
1150 std::vector
<bool> ®isters_used
,
1151 CORE_ADDR pc
, const char *result_name
);
1155 /* The methods needed to implement LOC_BLOCK for inferior functions.
1156 These methods can use the symbol's .aux_value for additional
1157 per-symbol information. */
1159 struct symbol_block_ops
1161 /* Fill in *START and *LENGTH with DWARF block data of function
1162 FRAMEFUNC valid for inferior context address PC. Set *LENGTH to
1163 zero if such location is not valid for PC; *START is left
1164 uninitialized in such case. */
1165 void (*find_frame_base_location
) (struct symbol
*framefunc
, CORE_ADDR pc
,
1166 const gdb_byte
**start
, size_t *length
);
1168 /* Return the frame base address. FRAME is the frame for which we want to
1169 compute the base address while FRAMEFUNC is the symbol for the
1170 corresponding function. Return 0 on failure (FRAMEFUNC may not hold the
1171 information we need).
1173 This method is designed to work with static links (nested functions
1174 handling). Static links are function properties whose evaluation returns
1175 the frame base address for the enclosing frame. However, there are
1176 multiple definitions for "frame base": the content of the frame base
1177 register, the CFA as defined by DWARF unwinding information, ...
1179 So this specific method is supposed to compute the frame base address such
1180 as for nested functions, the static link computes the same address. For
1181 instance, considering DWARF debugging information, the static link is
1182 computed with DW_AT_static_link and this method must be used to compute
1183 the corresponding DW_AT_frame_base attribute. */
1184 CORE_ADDR (*get_frame_base
) (struct symbol
*framefunc
,
1185 const frame_info_ptr
&frame
);
1187 /* Return the block for this function. So far, this is used to
1188 implement function aliases. So, if this is set, then it's not
1189 necessary to set the other functions in this structure; and vice
1191 const block
*(*get_block_value
) (const struct symbol
*sym
);
1194 /* Functions used with LOC_REGISTER and LOC_REGPARM_ADDR. */
1196 struct symbol_register_ops
1198 int (*register_number
) (struct symbol
*symbol
, struct gdbarch
*gdbarch
);
1201 /* Objects of this type are used to find the address class and the
1202 various computed ops vectors of a symbol. */
1206 enum address_class aclass
;
1208 /* Used with LOC_COMPUTED. */
1209 const struct symbol_computed_ops
*ops_computed
;
1211 /* Used with LOC_BLOCK. */
1212 const struct symbol_block_ops
*ops_block
;
1214 /* Used with LOC_REGISTER and LOC_REGPARM_ADDR. */
1215 const struct symbol_register_ops
*ops_register
;
1218 /* struct symbol has some subclasses. This enum is used to
1219 differentiate between them. */
1221 enum symbol_subclass_kind
1223 /* Plain struct symbol. */
1226 /* struct template_symbol. */
1229 /* struct rust_vtable_symbol. */
1233 extern gdb::array_view
<const struct symbol_impl
> symbol_impls
;
1235 /* This structure is space critical. See space comments at the top. */
1237 struct symbol
: public general_symbol_info
, public allocate_on_obstack
<symbol
>
1240 /* Class-initialization of bitfields is only allowed in C++20. */
1241 : m_domain (UNDEF_DOMAIN
),
1243 m_is_objfile_owned (1),
1247 subclass (SYMBOL_NONE
),
1248 m_artificial (false)
1250 /* We can't use an initializer list for members of a base class, and
1251 general_symbol_info needs to stay a POD type. */
1254 language_specific
.obstack
= nullptr;
1255 m_language
= language_unknown
;
1258 /* GCC 4.8.5 (on CentOS 7) does not correctly compile class-
1259 initialization of unions, so we initialize it manually here. */
1260 owner
.symtab
= nullptr;
1263 symbol (const symbol
&) = default;
1264 symbol
&operator= (const symbol
&) = default;
1266 void set_aclass_index (unsigned int aclass_index
)
1268 m_aclass_index
= aclass_index
;
1271 const symbol_impl
&impl () const
1273 return symbol_impls
[this->m_aclass_index
];
1276 const symbol_block_ops
*block_ops () const
1278 return this->impl ().ops_block
;
1281 const symbol_computed_ops
*computed_ops () const
1283 return this->impl ().ops_computed
;
1286 const symbol_register_ops
*register_ops () const
1288 return this->impl ().ops_register
;
1291 address_class
aclass () const
1293 return this->impl ().aclass
;
1296 /* Return true if this symbol's domain matches FLAGS. */
1297 bool matches (domain_search_flags flags
) const;
1299 domain_enum
domain () const
1304 void set_domain (domain_enum domain
)
1309 bool is_objfile_owned () const
1311 return m_is_objfile_owned
;
1314 void set_is_objfile_owned (bool is_objfile_owned
)
1316 m_is_objfile_owned
= is_objfile_owned
;
1319 bool is_argument () const
1321 return m_is_argument
;
1324 void set_is_argument (bool is_argument
)
1326 m_is_argument
= is_argument
;
1329 bool is_inlined () const
1331 return m_is_inlined
;
1334 void set_is_inlined (bool is_inlined
)
1336 m_is_inlined
= is_inlined
;
1339 /* Return true if this symbol is a template function. Template
1340 functions actually are of type 'template_symbol' and have extra
1341 symbols (the template parameters) attached. */
1343 bool is_template_function () const
1345 return this->subclass
== SYMBOL_TEMPLATE
;
1348 struct type
*type () const
1353 void set_type (struct type
*type
)
1358 unsigned int line () const
1363 void set_line (unsigned int line
)
1368 LONGEST
value_longest () const
1370 return m_value
.ivalue
;
1373 void set_value_longest (LONGEST value
)
1375 m_value
.ivalue
= value
;
1378 CORE_ADDR
value_address () const
1380 if (this->maybe_copied
)
1381 return this->get_maybe_copied_address ();
1383 return m_value
.address
;
1386 void set_value_address (CORE_ADDR address
)
1388 m_value
.address
= address
;
1391 const gdb_byte
*value_bytes () const
1393 return m_value
.bytes
;
1396 void set_value_bytes (const gdb_byte
*bytes
)
1398 m_value
.bytes
= bytes
;
1401 const common_block
*value_common_block () const
1403 return m_value
.common_block
;
1406 void set_value_common_block (const common_block
*common_block
)
1408 m_value
.common_block
= common_block
;
1411 const block
*value_block () const;
1413 void set_value_block (const block
*block
)
1415 m_value
.block
= block
;
1418 symbol
*value_chain () const
1420 return m_value
.chain
;
1423 void set_value_chain (symbol
*sym
)
1425 m_value
.chain
= sym
;
1428 /* Return true if this symbol was marked as artificial. */
1429 bool is_artificial () const
1431 return m_artificial
;
1434 /* Set the 'artificial' flag on this symbol. */
1435 void set_is_artificial (bool artificial
)
1437 m_artificial
= artificial
;
1440 /* Return the OBJFILE of this symbol. It is an error to call this
1441 if is_objfile_owned is false, which only happens for
1442 architecture-provided types. */
1444 struct objfile
*objfile () const;
1446 /* Return the ARCH of this symbol. */
1448 struct gdbarch
*arch () const;
1450 /* Return the symtab of this symbol. It is an error to call this if
1451 is_objfile_owned is false, which only happens for
1452 architecture-provided types. */
1454 struct symtab
*symtab () const;
1456 /* Set the symtab of this symbol to SYMTAB. It is an error to call
1457 this if is_objfile_owned is false, which only happens for
1458 architecture-provided types. */
1460 void set_symtab (struct symtab
*symtab
);
1462 /* Data type of value */
1464 struct type
*m_type
= nullptr;
1466 /* The owner of this symbol.
1467 Which one to use is defined by symbol.is_objfile_owned. */
1471 /* The symbol table containing this symbol. This is the file associated
1472 with LINE. It can be NULL during symbols read-in but it is never NULL
1473 during normal operation. */
1474 struct symtab
*symtab
;
1476 /* For types defined by the architecture. */
1477 struct gdbarch
*arch
;
1482 ENUM_BITFIELD(domain_enum
) m_domain
: SYMBOL_DOMAIN_BITS
;
1484 /* Address class. This holds an index into the 'symbol_impls'
1485 table. The actual enum address_class value is stored there,
1486 alongside any per-class ops vectors. */
1488 unsigned int m_aclass_index
: SYMBOL_ACLASS_BITS
;
1490 /* If non-zero then symbol is objfile-owned, use owner.symtab.
1491 Otherwise symbol is arch-owned, use owner.arch. */
1493 unsigned int m_is_objfile_owned
: 1;
1495 /* Whether this is an argument. */
1497 unsigned m_is_argument
: 1;
1499 /* Whether this is an inlined function (class LOC_BLOCK only). */
1500 unsigned m_is_inlined
: 1;
1502 /* For LOC_STATIC only, if this is set, then the symbol might be
1503 subject to copy relocation. In this case, a minimal symbol
1504 matching the symbol's linkage name is first looked for in the
1505 main objfile. If found, then that address is used; otherwise the
1506 address in this symbol is used. */
1508 unsigned maybe_copied
: 1;
1510 /* The concrete type of this symbol. */
1512 ENUM_BITFIELD (symbol_subclass_kind
) subclass
: 2;
1514 /* Whether this symbol is artificial. */
1516 bool m_artificial
: 1;
1518 /* Line number of this symbol's definition, except for inlined
1519 functions. For an inlined function (class LOC_BLOCK and
1520 SYMBOL_INLINED set) this is the line number of the function's call
1521 site. Inlined function symbols are not definitions, and they are
1522 never found by symbol table lookup.
1523 If this symbol is arch-owned, LINE shall be zero. */
1525 unsigned int m_line
= 0;
1527 /* An arbitrary data pointer, allowing symbol readers to record
1528 additional information on a per-symbol basis. Note that this data
1529 must be allocated using the same obstack as the symbol itself. */
1530 /* So far it is only used by:
1531 LOC_COMPUTED: to find the location information
1532 LOC_BLOCK (DWARF2 function): information used internally by the
1533 DWARF 2 code --- specifically, the location expression for the frame
1534 base for this function. */
1535 /* FIXME drow/2003-02-21: For the LOC_BLOCK case, it might be better
1536 to add a magic symbol to the block containing this information,
1537 or to have a generic debug info annotation slot for symbols. */
1539 void *aux_value
= nullptr;
1541 struct symbol
*hash_next
= nullptr;
1544 /* Return the address of this symbol. The MAYBE_COPIED flag must be set.
1545 If the symbol appears in the main program's minimal symbols, then
1546 that minsym's address is returned; otherwise, this symbol's address is
1548 CORE_ADDR
get_maybe_copied_address () const;
1551 /* Several lookup functions return both a symbol and the block in which the
1552 symbol is found. This structure is used in these cases. */
1556 /* The symbol that was found, or NULL if no symbol was found. */
1557 struct symbol
*symbol
;
1559 /* If SYMBOL is not NULL, then this is the block in which the symbol is
1561 const struct block
*block
;
1564 /* Note: There is no accessor macro for symbol.owner because it is
1567 #define SYMBOL_LOCATION_BATON(symbol) (symbol)->aux_value
1569 inline const block
*
1570 symbol::value_block () const
1572 if (const symbol_block_ops
*block_ops
= this->block_ops ();
1573 block_ops
!= nullptr && block_ops
->get_block_value
!= nullptr)
1574 return block_ops
->get_block_value (this);
1576 return m_value
.block
;
1579 extern int register_symbol_computed_impl (enum address_class
,
1580 const struct symbol_computed_ops
*);
1582 extern int register_symbol_block_impl (enum address_class aclass
,
1583 const struct symbol_block_ops
*ops
);
1585 extern int register_symbol_register_impl (enum address_class
,
1586 const struct symbol_register_ops
*);
1588 /* An instance of this type is used to represent a C++ template
1589 function. A symbol is really of this type iff
1590 symbol::is_template_function is true. */
1592 struct template_symbol
: public symbol
1594 /* The number of template arguments. */
1595 int n_template_arguments
= 0;
1597 /* The template arguments. This is an array with
1598 N_TEMPLATE_ARGUMENTS elements. */
1599 struct symbol
**template_arguments
= nullptr;
1602 /* A symbol that represents a Rust virtual table object. */
1604 struct rust_vtable_symbol
: public symbol
1606 /* The concrete type for which this vtable was created; that is, in
1607 "impl Trait for Type", this is "Type". */
1608 struct type
*concrete_type
= nullptr;
1612 /* Each item represents a line-->pc (or the reverse) mapping. This is
1613 somewhat more wasteful of space than one might wish, but since only
1614 the files which are actually debugged are read in to core, we don't
1615 waste much space. */
1617 struct linetable_entry
1619 /* Set the (unrelocated) PC for this entry. */
1620 void set_unrelocated_pc (unrelocated_addr pc
)
1623 /* Return the unrelocated PC for this entry. */
1624 unrelocated_addr
unrelocated_pc () const
1627 /* Return the relocated PC for this entry. */
1628 CORE_ADDR
pc (const struct objfile
*objfile
) const;
1630 bool operator< (const linetable_entry
&other
) const
1632 if (m_pc
== other
.m_pc
1633 && (line
!= 0) != (other
.line
!= 0))
1635 return m_pc
< other
.m_pc
;
1638 /* Two entries are equal if they have the same line and PC. The
1639 other members are ignored. */
1640 bool operator== (const linetable_entry
&other
) const
1641 { return line
== other
.line
&& m_pc
== other
.m_pc
; }
1643 /* The line number for this entry. */
1646 /* True if this PC is a good location to place a breakpoint for LINE. */
1649 /* True if this location is a good location to place a breakpoint after a
1650 function prologue. */
1651 bool prologue_end
: 1;
1653 /* True if this location marks the start of the epilogue. */
1654 bool epilogue_begin
: 1;
1658 /* The address for this entry. */
1659 unrelocated_addr m_pc
;
1662 /* The order of entries in the linetable is significant. They should
1663 be sorted by increasing values of the pc field. If there is more than
1664 one entry for a given pc, then I'm not sure what should happen (and
1665 I not sure whether we currently handle it the best way).
1667 Example: a C for statement generally looks like this
1669 10 0x100 - for the init/test part of a for stmt.
1672 10 0x400 - for the increment part of a for stmt.
1674 If an entry has a line number of zero, it marks the start of a PC
1675 range for which no line number information is available. It is
1676 acceptable, though wasteful of table space, for such a range to be
1683 /* Actually NITEMS elements. If you don't like this use of the
1684 `struct hack', you can shove it up your ANSI (seriously, if the
1685 committee tells us how to do it, we can probably go along). */
1686 struct linetable_entry item
[1];
1689 /* How to relocate the symbols from each section in a symbol file.
1690 The ordering and meaning of the offsets is file-type-dependent;
1691 typically it is indexed by section numbers or symbol types or
1692 something like that. */
1694 typedef std::vector
<CORE_ADDR
> section_offsets
;
1696 /* Each source file or header is represented by a struct symtab.
1697 The name "symtab" is historical, another name for it is "filetab".
1698 These objects are chained through the `next' field. */
1702 struct compunit_symtab
*compunit () const
1707 void set_compunit (struct compunit_symtab
*compunit
)
1709 m_compunit
= compunit
;
1712 const struct linetable
*linetable () const
1717 void set_linetable (const struct linetable
*linetable
)
1719 m_linetable
= linetable
;
1722 enum language
language () const
1727 void set_language (enum language language
)
1729 m_language
= language
;
1732 /* Return the current full name of this symtab. */
1733 const char *fullname () const
1734 { return m_fullname
; }
1736 /* Transfer ownership of the current full name to the caller. The
1737 full name is reset to nullptr. */
1738 gdb::unique_xmalloc_ptr
<char> release_fullname ()
1740 gdb::unique_xmalloc_ptr
<char> result (m_fullname
);
1741 m_fullname
= nullptr;
1745 /* Set the current full name to NAME, transferring ownership to this
1747 void set_fullname (gdb::unique_xmalloc_ptr
<char> name
)
1749 gdb_assert (m_fullname
== nullptr);
1750 m_fullname
= name
.release ();
1753 /* Unordered chain of all filetabs in the compunit, with the exception
1754 that the "main" source file is the first entry in the list. */
1756 struct symtab
*next
;
1758 /* Name of this source file, in a form appropriate to print to the user.
1760 This pointer is never nullptr. */
1762 const char *filename
;
1764 /* Filename for this source file, used as an identifier to link with
1765 related objects such as associated macro_source_file objects. It must
1766 therefore match the name of any macro_source_file object created for this
1767 source file. The value can be the same as FILENAME if it is known to
1768 follow that rule, or another form of the same file name, this is up to
1769 the specific debug info reader.
1771 This pointer is never nullptr.*/
1772 const char *filename_for_id
;
1776 /* Backlink to containing compunit symtab. */
1778 struct compunit_symtab
*m_compunit
;
1780 /* Table mapping core addresses to line numbers for this file.
1781 Can be NULL if none. Never shared between different symtabs. */
1783 const struct linetable
*m_linetable
;
1785 /* Language of this source file. */
1787 enum language m_language
;
1789 /* Full name of file as found by searching the source path.
1790 NULL if not yet known. */
1795 /* A range adapter to allowing iterating over all the file tables in a list. */
1797 using symtab_range
= next_range
<symtab
>;
1799 /* Compunit symtabs contain the actual "symbol table", aka blockvector, as well
1800 as the list of all source files (what gdb has historically associated with
1802 Additional information is recorded here that is common to all symtabs in a
1803 compilation unit (DWARF or otherwise).
1806 For the case of a program built out of these files:
1815 This is recorded as:
1817 objfile -> foo.c(cu) -> bar.c(cu) -> NULL
1831 where "foo.c(cu)" and "bar.c(cu)" are struct compunit_symtab objects,
1832 and the files foo.c, etc. are struct symtab objects. */
1834 struct compunit_symtab
1836 struct objfile
*objfile () const
1841 void set_objfile (struct objfile
*objfile
)
1843 m_objfile
= objfile
;
1846 symtab_range
filetabs () const
1848 return symtab_range (m_filetabs
);
1851 void add_filetab (symtab
*filetab
)
1853 if (m_filetabs
== nullptr)
1855 m_filetabs
= filetab
;
1856 m_last_filetab
= filetab
;
1860 m_last_filetab
->next
= filetab
;
1861 m_last_filetab
= filetab
;
1865 const char *debugformat () const
1867 return m_debugformat
;
1870 void set_debugformat (const char *debugformat
)
1872 m_debugformat
= debugformat
;
1875 const char *producer () const
1880 void set_producer (const char *producer
)
1882 m_producer
= producer
;
1885 const char *dirname () const
1890 void set_dirname (const char *dirname
)
1892 m_dirname
= dirname
;
1895 struct blockvector
*blockvector ()
1897 return m_blockvector
;
1900 const struct blockvector
*blockvector () const
1902 return m_blockvector
;
1905 void set_blockvector (struct blockvector
*blockvector
)
1907 m_blockvector
= blockvector
;
1910 bool locations_valid () const
1912 return m_locations_valid
;
1915 void set_locations_valid (bool locations_valid
)
1917 m_locations_valid
= locations_valid
;
1920 bool epilogue_unwind_valid () const
1922 return m_epilogue_unwind_valid
;
1925 void set_epilogue_unwind_valid (bool epilogue_unwind_valid
)
1927 m_epilogue_unwind_valid
= epilogue_unwind_valid
;
1930 struct macro_table
*macro_table () const
1932 return m_macro_table
;
1935 void set_macro_table (struct macro_table
*macro_table
)
1937 m_macro_table
= macro_table
;
1940 /* Make PRIMARY_FILETAB the primary filetab of this compunit symtab.
1942 PRIMARY_FILETAB must already be a filetab of this compunit symtab. */
1944 void set_primary_filetab (symtab
*primary_filetab
);
1946 /* Return the primary filetab of the compunit. */
1947 symtab
*primary_filetab () const;
1949 /* Set m_call_site_htab. */
1950 void set_call_site_htab (htab_up call_site_htab
);
1952 /* Find call_site info for PC. */
1953 call_site
*find_call_site (CORE_ADDR pc
) const;
1955 /* Return the language of this compunit_symtab. */
1956 enum language
language () const;
1958 /* Clear any cached source file names. */
1959 void forget_cached_source_info ();
1961 /* This is called when an objfile is being destroyed and will free
1962 any resources used by this compunit_symtab. Normally a
1963 destructor would be used instead, but at the moment
1964 compunit_symtab objects are allocated on an obstack. */
1967 /* Unordered chain of all compunit symtabs of this objfile. */
1968 struct compunit_symtab
*next
;
1970 /* Object file from which this symtab information was read. */
1971 struct objfile
*m_objfile
;
1973 /* Name of the symtab.
1974 This is *not* intended to be a usable filename, and is
1975 for debugging purposes only. */
1978 /* Unordered list of file symtabs, except that by convention the "main"
1979 source file (e.g., .c, .cc) is guaranteed to be first.
1980 Each symtab is a file, either the "main" source file (e.g., .c, .cc)
1981 or header (e.g., .h). */
1984 /* Last entry in FILETABS list.
1985 Subfiles are added to the end of the list so they accumulate in order,
1986 with the main source subfile living at the front.
1987 The main reason is so that the main source file symtab is at the head
1988 of the list, and the rest appear in order for debugging convenience. */
1989 symtab
*m_last_filetab
;
1991 /* Non-NULL string that identifies the format of the debugging information,
1992 such as "stabs", "dwarf 1", "dwarf 2", "coff", etc. This is mostly useful
1993 for automated testing of gdb but may also be information that is
1994 useful to the user. */
1995 const char *m_debugformat
;
1997 /* String of producer version information, or NULL if we don't know. */
1998 const char *m_producer
;
2000 /* Directory in which it was compiled, or NULL if we don't know. */
2001 const char *m_dirname
;
2003 /* List of all symbol scope blocks for this symtab. It is shared among
2004 all symtabs in a given compilation unit. */
2005 struct blockvector
*m_blockvector
;
2007 /* Symtab has been compiled with both optimizations and debug info so that
2008 GDB may stop skipping prologues as variables locations are valid already
2009 at function entry points. */
2010 unsigned int m_locations_valid
: 1;
2012 /* DWARF unwinder for this CU is valid even for epilogues (PC at the return
2013 instruction). This is supported by GCC since 4.5.0. */
2014 unsigned int m_epilogue_unwind_valid
: 1;
2016 /* struct call_site entries for this compilation unit or NULL. */
2017 htab_t m_call_site_htab
;
2019 /* The macro table for this symtab. Like the blockvector, this
2020 is shared between different symtabs in a given compilation unit.
2021 It's debatable whether it *should* be shared among all the symtabs in
2022 the given compilation unit, but it currently is. */
2023 struct macro_table
*m_macro_table
;
2025 /* If non-NULL, then this points to a NULL-terminated vector of
2026 included compunits. When searching the static or global
2027 block of this compunit, the corresponding block of all
2028 included compunits will also be searched. Note that this
2029 list must be flattened -- the symbol reader is responsible for
2030 ensuring that this vector contains the transitive closure of all
2031 included compunits. */
2032 struct compunit_symtab
**includes
;
2034 /* If this is an included compunit, this points to one includer
2035 of the table. This user is considered the canonical compunit
2036 containing this one. An included compunit may itself be
2037 included by another. */
2038 struct compunit_symtab
*user
;
2041 using compunit_symtab_range
= next_range
<compunit_symtab
>;
2043 /* Return true if this symtab is the "main" symtab of its compunit_symtab. */
2046 is_main_symtab_of_compunit_symtab (struct symtab
*symtab
)
2048 return symtab
== symtab
->compunit ()->primary_filetab ();
2051 /* Return true if epilogue unwind info of CUST is valid. */
2054 compunit_epilogue_unwind_valid (struct compunit_symtab
*cust
)
2056 /* In absence of producer information, assume epilogue unwind info is
2058 if (cust
== nullptr)
2061 return cust
->epilogue_unwind_valid ();
2065 /* The virtual function table is now an array of structures which have the
2066 form { int16 offset, delta; void *pfn; }.
2068 In normal virtual function tables, OFFSET is unused.
2069 DELTA is the amount which is added to the apparent object's base
2070 address in order to point to the actual object to which the
2071 virtual function should be applied.
2072 PFN is a pointer to the virtual function.
2074 Note that this macro is g++ specific (FIXME). */
2076 #define VTBL_FNADDR_OFFSET 2
2078 /* External variables and functions for the objects described above. */
2080 /* True if we are nested inside psymtab_to_symtab. */
2082 extern int currently_reading_symtab
;
2084 /* symtab.c lookup functions */
2086 extern const char multiple_symbols_ask
[];
2087 extern const char multiple_symbols_all
[];
2088 extern const char multiple_symbols_cancel
[];
2090 const char *multiple_symbols_select_mode (void);
2092 /* lookup a symbol table by source file name. */
2094 extern struct symtab
*lookup_symtab (const char *);
2096 /* An object of this type is passed as the 'is_a_field_of_this'
2097 argument to lookup_symbol and lookup_symbol_in_language. */
2099 struct field_of_this_result
2101 /* The type in which the field was found. If this is NULL then the
2102 symbol was not found in 'this'. If non-NULL, then one of the
2103 other fields will be non-NULL as well. */
2107 /* If the symbol was found as an ordinary field of 'this', then this
2108 is non-NULL and points to the particular field. */
2110 struct field
*field
;
2112 /* If the symbol was found as a function field of 'this', then this
2113 is non-NULL and points to the particular field. */
2115 struct fn_fieldlist
*fn_field
;
2118 /* Find the definition for a specified symbol name NAME
2119 in domain DOMAIN in language LANGUAGE, visible from lexical block BLOCK
2120 if non-NULL or from global/static blocks if BLOCK is NULL.
2121 Returns the struct symbol pointer, or NULL if no symbol is found.
2122 C++: if IS_A_FIELD_OF_THIS is non-NULL on entry, check to see if
2123 NAME is a field of the current implied argument `this'. If so fill in the
2124 fields of IS_A_FIELD_OF_THIS, otherwise the fields are set to NULL.
2125 The symbol's section is fixed up if necessary. */
2127 extern struct block_symbol
2128 lookup_symbol_in_language (const char *,
2129 const struct block
*,
2130 const domain_search_flags
,
2132 struct field_of_this_result
*);
2134 /* Same as lookup_symbol_in_language, but using the current language. */
2136 extern struct block_symbol
lookup_symbol (const char *,
2137 const struct block
*,
2138 const domain_search_flags
,
2139 struct field_of_this_result
*);
2141 /* Find the definition for a specified symbol search name in domain
2142 DOMAIN, visible from lexical block BLOCK if non-NULL or from
2143 global/static blocks if BLOCK is NULL. The passed-in search name
2144 should not come from the user; instead it should already be a
2145 search name as retrieved from a search_name () call. See definition of
2146 symbol_name_match_type::SEARCH_NAME. Returns the struct symbol
2147 pointer, or NULL if no symbol is found. The symbol's section is
2148 fixed up if necessary. */
2150 extern struct block_symbol lookup_symbol_search_name
2151 (const char *search_name
,
2152 const struct block
*block
,
2153 domain_search_flags domain
);
2155 /* Some helper functions for languages that need to write their own
2156 lookup_symbol_nonlocal functions. */
2158 /* Lookup a symbol in the static block associated to BLOCK, if there
2159 is one; do nothing if BLOCK is NULL or a global block.
2160 Upon success fixes up the symbol's section if necessary. */
2162 extern struct block_symbol
2163 lookup_symbol_in_static_block (const char *name
,
2164 const struct block
*block
,
2165 const domain_search_flags domain
);
2167 /* Search all static file-level symbols for NAME from DOMAIN.
2168 Upon success fixes up the symbol's section if necessary. */
2170 extern struct block_symbol lookup_static_symbol
2171 (const char *name
, const domain_search_flags domain
);
2173 /* Lookup a symbol in all files' global blocks.
2175 If BLOCK is non-NULL then it is used for two things:
2176 1) If a target-specific lookup routine for libraries exists, then use the
2177 routine for the objfile of BLOCK, and
2178 2) The objfile of BLOCK is used to assist in determining the search order
2179 if the target requires it.
2180 See gdbarch_iterate_over_objfiles_in_search_order.
2182 Upon success fixes up the symbol's section if necessary. */
2184 extern struct block_symbol
2185 lookup_global_symbol (const char *name
,
2186 const struct block
*block
,
2187 const domain_search_flags domain
);
2189 /* Lookup a symbol in block BLOCK.
2190 Upon success fixes up the symbol's section if necessary. */
2192 extern struct symbol
*
2193 lookup_symbol_in_block (const char *name
,
2194 symbol_name_match_type match_type
,
2195 const struct block
*block
,
2196 const domain_search_flags domain
);
2198 /* Look up the `this' symbol for LANG in BLOCK. Return the symbol if
2199 found, or NULL if not found. */
2201 extern struct block_symbol
2202 lookup_language_this (const struct language_defn
*lang
,
2203 const struct block
*block
);
2205 /* Lookup a [struct, union, enum] by name, within a specified block. */
2207 extern struct type
*lookup_struct (const char *, const struct block
*);
2209 extern struct type
*lookup_union (const char *, const struct block
*);
2211 extern struct type
*lookup_enum (const char *, const struct block
*);
2213 /* from blockframe.c: */
2215 /* lookup the function symbol corresponding to the address. The
2216 return value will not be an inlined function; the containing
2217 function will be returned instead. */
2219 extern struct symbol
*find_pc_function (CORE_ADDR
);
2221 /* lookup the function corresponding to the address and section. The
2222 return value will not be an inlined function; the containing
2223 function will be returned instead. */
2225 extern struct symbol
*find_pc_sect_function (CORE_ADDR
, struct obj_section
*);
2227 /* lookup the function symbol corresponding to the address and
2228 section. The return value will be the closest enclosing function,
2229 which might be an inline function. */
2231 extern struct symbol
*find_pc_sect_containing_function
2232 (CORE_ADDR pc
, struct obj_section
*section
);
2234 /* Find the symbol at the given address. Returns NULL if no symbol
2235 found. Only exact matches for ADDRESS are considered. */
2237 extern struct symbol
*find_symbol_at_address (CORE_ADDR
);
2239 /* Finds the "function" (text symbol) that is smaller than PC but
2240 greatest of all of the potential text symbols in SECTION. Sets
2241 *NAME and/or *ADDRESS conditionally if that pointer is non-null.
2242 If ENDADDR is non-null, then set *ENDADDR to be the end of the
2243 function (exclusive). If the optional parameter BLOCK is non-null,
2244 then set *BLOCK to the address of the block corresponding to the
2245 function symbol, if such a symbol could be found during the lookup;
2246 nullptr is used as a return value for *BLOCK if no block is found.
2247 This function either succeeds or fails (not halfway succeeds). If
2248 it succeeds, it sets *NAME, *ADDRESS, and *ENDADDR to real
2249 information and returns true. If it fails, it sets *NAME, *ADDRESS
2250 and *ENDADDR to zero and returns false.
2252 If the function in question occupies non-contiguous ranges,
2253 *ADDRESS and *ENDADDR are (subject to the conditions noted above) set
2254 to the start and end of the range in which PC is found. Thus
2255 *ADDRESS <= PC < *ENDADDR with no intervening gaps (in which ranges
2256 from other functions might be found).
2258 This property allows find_pc_partial_function to be used (as it had
2259 been prior to the introduction of non-contiguous range support) by
2260 various tdep files for finding a start address and limit address
2261 for prologue analysis. This still isn't ideal, however, because we
2262 probably shouldn't be doing prologue analysis (in which
2263 instructions are scanned to determine frame size and stack layout)
2264 for any range that doesn't contain the entry pc. Moreover, a good
2265 argument can be made that prologue analysis ought to be performed
2266 starting from the entry pc even when PC is within some other range.
2267 This might suggest that *ADDRESS and *ENDADDR ought to be set to the
2268 limits of the entry pc range, but that will cause the
2269 *ADDRESS <= PC < *ENDADDR condition to be violated; many of the
2270 callers of find_pc_partial_function expect this condition to hold.
2272 Callers which require the start and/or end addresses for the range
2273 containing the entry pc should instead call
2274 find_function_entry_range_from_pc. */
2276 extern bool find_pc_partial_function (CORE_ADDR pc
, const char **name
,
2277 CORE_ADDR
*address
, CORE_ADDR
*endaddr
,
2278 const struct block
**block
= nullptr);
2280 /* Like find_pc_partial_function, above, but returns the underlying
2281 general_symbol_info (rather than the name) as an out parameter. */
2283 extern bool find_pc_partial_function_sym
2284 (CORE_ADDR pc
, const general_symbol_info
**sym
,
2285 CORE_ADDR
*address
, CORE_ADDR
*endaddr
,
2286 const struct block
**block
= nullptr);
2288 /* Like find_pc_partial_function, above, but *ADDRESS and *ENDADDR are
2289 set to start and end addresses of the range containing the entry pc.
2291 Note that it is not necessarily the case that (for non-NULL ADDRESS
2292 and ENDADDR arguments) the *ADDRESS <= PC < *ENDADDR condition will
2295 See comment for find_pc_partial_function, above, for further
2298 extern bool find_function_entry_range_from_pc (CORE_ADDR pc
,
2301 CORE_ADDR
*endaddr
);
2303 /* Return the type of a function with its first instruction exactly at
2304 the PC address. Return NULL otherwise. */
2306 extern struct type
*find_function_type (CORE_ADDR pc
);
2308 /* See if we can figure out the function's actual type from the type
2309 that the resolver returns. RESOLVER_FUNADDR is the address of the
2312 extern struct type
*find_gnu_ifunc_target_type (CORE_ADDR resolver_funaddr
);
2314 /* Find the GNU ifunc minimal symbol that matches SYM. */
2315 extern bound_minimal_symbol
find_gnu_ifunc (const symbol
*sym
);
2317 extern void clear_pc_function_cache (void);
2319 /* lookup full symbol table by address. */
2321 extern struct compunit_symtab
*find_pc_compunit_symtab (CORE_ADDR
);
2323 /* lookup full symbol table by address and section. */
2325 extern struct compunit_symtab
*
2326 find_pc_sect_compunit_symtab (CORE_ADDR
, struct obj_section
*);
2328 extern bool find_pc_line_pc_range (CORE_ADDR
, CORE_ADDR
*, CORE_ADDR
*);
2330 extern void reread_symbols (int from_tty
);
2332 /* Look up a type named NAME in STRUCT_DOMAIN in the current language.
2333 The type returned must not be opaque -- i.e., must have at least one field
2336 extern struct type
*lookup_transparent_type
2337 (const char *name
, domain_search_flags flags
= SEARCH_STRUCT_DOMAIN
);
2339 extern struct type
*basic_lookup_transparent_type
2340 (const char *name
, domain_search_flags flags
= SEARCH_STRUCT_DOMAIN
);
2342 /* Macro for name of symbol to indicate a file compiled with gcc. */
2343 #ifndef GCC_COMPILED_FLAG_SYMBOL
2344 #define GCC_COMPILED_FLAG_SYMBOL "gcc_compiled."
2347 /* Macro for name of symbol to indicate a file compiled with gcc2. */
2348 #ifndef GCC2_COMPILED_FLAG_SYMBOL
2349 #define GCC2_COMPILED_FLAG_SYMBOL "gcc2_compiled."
2352 extern bool in_gnu_ifunc_stub (CORE_ADDR pc
);
2354 /* Functions for resolving STT_GNU_IFUNC symbols which are implemented only
2355 for ELF symbol files. */
2357 struct gnu_ifunc_fns
2359 /* See elf_gnu_ifunc_resolve_addr for its real implementation. */
2360 CORE_ADDR (*gnu_ifunc_resolve_addr
) (struct gdbarch
*gdbarch
, CORE_ADDR pc
);
2362 /* See elf_gnu_ifunc_resolve_name for its real implementation. */
2363 bool (*gnu_ifunc_resolve_name
) (const char *function_name
,
2364 CORE_ADDR
*function_address_p
);
2366 /* See elf_gnu_ifunc_resolver_stop for its real implementation. */
2367 void (*gnu_ifunc_resolver_stop
) (code_breakpoint
*b
);
2369 /* See elf_gnu_ifunc_resolver_return_stop for its real implementation. */
2370 void (*gnu_ifunc_resolver_return_stop
) (code_breakpoint
*b
);
2373 #define gnu_ifunc_resolve_addr gnu_ifunc_fns_p->gnu_ifunc_resolve_addr
2374 #define gnu_ifunc_resolve_name gnu_ifunc_fns_p->gnu_ifunc_resolve_name
2375 #define gnu_ifunc_resolver_stop gnu_ifunc_fns_p->gnu_ifunc_resolver_stop
2376 #define gnu_ifunc_resolver_return_stop \
2377 gnu_ifunc_fns_p->gnu_ifunc_resolver_return_stop
2379 extern const struct gnu_ifunc_fns
*gnu_ifunc_fns_p
;
2381 extern CORE_ADDR
find_solib_trampoline_target (const frame_info_ptr
&, CORE_ADDR
);
2383 struct symtab_and_line
2385 /* The program space of this sal. */
2386 struct program_space
*pspace
= NULL
;
2388 struct symtab
*symtab
= NULL
;
2389 struct symbol
*symbol
= NULL
;
2390 struct obj_section
*section
= NULL
;
2391 struct minimal_symbol
*msymbol
= NULL
;
2392 /* Line number. Line numbers start at 1 and proceed through symtab->nlines.
2393 0 is never a valid line number; it is used to indicate that line number
2394 information is not available. */
2399 bool explicit_pc
= false;
2400 bool explicit_line
= false;
2402 /* If the line number information is valid, then this indicates if this
2403 line table entry had the is-stmt flag set or not. */
2404 bool is_stmt
= false;
2406 /* The probe associated with this symtab_and_line. */
2408 /* If PROBE is not NULL, then this is the objfile in which the probe
2410 struct objfile
*objfile
= NULL
;
2415 /* Given a pc value, return line number it is in. Second arg nonzero means
2416 if pc is on the boundary use the previous statement's line number. */
2418 extern struct symtab_and_line
find_pc_line (CORE_ADDR
, int);
2420 /* Same function, but specify a section as well as an address. */
2422 extern struct symtab_and_line
find_pc_sect_line (CORE_ADDR
,
2423 struct obj_section
*, int);
2425 /* Given PC, and assuming it is part of a range of addresses that is part of
2426 a line, go back through the linetable and find the starting PC of that
2429 For example, suppose we have 3 PC ranges for line X:
2431 Line X - [0x0 - 0x8]
2432 Line X - [0x8 - 0x10]
2433 Line X - [0x10 - 0x18]
2435 If we call the function with PC == 0x14, we want to return 0x0, as that is
2436 the starting PC of line X, and the ranges are contiguous.
2439 extern std::optional
<CORE_ADDR
> find_line_range_start (CORE_ADDR pc
);
2441 /* Wrapper around find_pc_line to just return the symtab. */
2443 extern struct symtab
*find_pc_line_symtab (CORE_ADDR
);
2445 /* Given a symtab and line number, return the pc there. */
2447 extern bool find_line_pc (struct symtab
*, int, CORE_ADDR
*);
2449 extern bool find_line_pc_range (struct symtab_and_line
, CORE_ADDR
*,
2452 extern void resolve_sal_pc (struct symtab_and_line
*);
2454 /* The reason we're calling into a completion match list collector
2456 enum class complete_symbol_mode
2458 /* Completing an expression. */
2461 /* Completing a linespec. */
2465 extern void default_collect_symbol_completion_matches_break_on
2466 (completion_tracker
&tracker
,
2467 complete_symbol_mode mode
,
2468 symbol_name_match_type name_match_type
,
2469 const char *text
, const char *word
, const char *break_on
,
2470 enum type_code code
);
2471 extern void collect_symbol_completion_matches
2472 (completion_tracker
&tracker
,
2473 complete_symbol_mode mode
,
2474 symbol_name_match_type name_match_type
,
2475 const char *, const char *);
2476 extern void collect_symbol_completion_matches_type (completion_tracker
&tracker
,
2477 const char *, const char *,
2480 extern void collect_file_symbol_completion_matches
2481 (completion_tracker
&tracker
,
2482 complete_symbol_mode
,
2483 symbol_name_match_type name_match_type
,
2484 const char *, const char *, const char *);
2486 extern completion_list
2487 make_source_files_completion_list (const char *, const char *);
2489 /* Return whether SYM is a function/method, as opposed to a data symbol. */
2491 extern bool symbol_is_function_or_method (symbol
*sym
);
2493 /* Return whether MSYMBOL is a function/method, as opposed to a data
2496 extern bool symbol_is_function_or_method (minimal_symbol
*msymbol
);
2498 /* Return whether SYM should be skipped in completion mode MODE. In
2499 linespec mode, we're only interested in functions/methods. */
2501 template<typename Symbol
>
2503 completion_skip_symbol (complete_symbol_mode mode
, Symbol
*sym
)
2505 return (mode
== complete_symbol_mode::LINESPEC
2506 && !symbol_is_function_or_method (sym
));
2511 bool matching_obj_sections (struct obj_section
*, struct obj_section
*);
2513 extern struct symtab
*find_line_symtab (struct symtab
*, int, int *, bool *);
2515 /* Given a function symbol SYM, find the symtab and line for the start
2516 of the function. If FUNFIRSTLINE is true, we want the first line
2517 of real code inside the function. */
2518 extern symtab_and_line
find_function_start_sal (symbol
*sym
, bool
2521 /* Same, but start with a function address/section instead of a
2523 extern symtab_and_line
find_function_start_sal (CORE_ADDR func_addr
,
2524 obj_section
*section
,
2527 extern void skip_prologue_sal (struct symtab_and_line
*);
2531 extern CORE_ADDR
skip_prologue_using_sal (struct gdbarch
*gdbarch
,
2532 CORE_ADDR func_addr
);
2534 /* If SYM requires a section index, find it either via minimal symbols
2535 or examining OBJFILE's sections. Note that SYM's current address
2536 must not have any runtime offsets applied. */
2538 extern void fixup_symbol_section (struct symbol
*sym
,
2539 struct objfile
*objfile
);
2541 /* If MSYMBOL is an text symbol, look for a function debug symbol with
2542 the same address. Returns NULL if not found. This is necessary in
2543 case a function is an alias to some other function, because debug
2544 information is only emitted for the alias target function's
2545 definition, not for the alias. */
2546 extern symbol
*find_function_alias_target (bound_minimal_symbol msymbol
);
2548 /* Symbol searching */
2550 /* When using the symbol_searcher struct to search for symbols, a vector of
2551 the following structs is returned. */
2552 struct symbol_search
2554 symbol_search (block_enum block_
, struct symbol
*symbol_
)
2558 msymbol
.minsym
= nullptr;
2559 msymbol
.objfile
= nullptr;
2562 symbol_search (block_enum block_
, struct minimal_symbol
*minsym
,
2563 struct objfile
*objfile
)
2567 msymbol
.minsym
= minsym
;
2568 msymbol
.objfile
= objfile
;
2571 bool operator< (const symbol_search
&other
) const
2573 return compare_search_syms (*this, other
) < 0;
2576 bool operator== (const symbol_search
&other
) const
2578 return compare_search_syms (*this, other
) == 0;
2581 /* The block in which the match was found. Either STATIC_BLOCK or
2585 /* Information describing what was found.
2587 If symbol is NOT NULL, then information was found for this match. */
2588 struct symbol
*symbol
;
2590 /* If msymbol is non-null, then a match was made on something for
2591 which only minimal_symbols exist. */
2592 bound_minimal_symbol msymbol
;
2596 static int compare_search_syms (const symbol_search
&sym_a
,
2597 const symbol_search
&sym_b
);
2600 /* In order to search for global symbols of a particular kind matching
2601 particular regular expressions, create an instance of this structure and
2602 call the SEARCH member function. */
2603 class global_symbol_searcher
2608 global_symbol_searcher (domain_search_flags kind
,
2609 const char *symbol_name_regexp
)
2611 m_symbol_name_regexp (symbol_name_regexp
)
2615 /* Set the optional regexp that matches against the symbol type. */
2616 void set_symbol_type_regexp (const char *regexp
)
2618 m_symbol_type_regexp
= regexp
;
2621 /* Set the flag to exclude minsyms from the search results. */
2622 void set_exclude_minsyms (bool exclude_minsyms
)
2624 m_exclude_minsyms
= exclude_minsyms
;
2627 /* Set the maximum number of search results to be returned. */
2628 void set_max_search_results (size_t max_search_results
)
2630 m_max_search_results
= max_search_results
;
2633 /* Search the symbols from all objfiles in the current program space
2634 looking for matches as defined by the current state of this object.
2636 Within each file the results are sorted locally; each symtab's global
2637 and static blocks are separately alphabetized. Duplicate entries are
2639 std::vector
<symbol_search
> search () const;
2641 /* Add a filename to the list of file names to search. */
2642 void add_filename (gdb::unique_xmalloc_ptr
<char> filename
)
2643 { m_filenames
.push_back (std::move (filename
)); }
2646 /* The set of source files to search in for matching symbols. */
2647 std::vector
<gdb::unique_xmalloc_ptr
<char>> m_filenames
;
2649 /* The kind of symbols are we searching for.
2650 VARIABLES_DOMAIN - Search all symbols, excluding functions, type
2651 names, and constants (enums).
2652 FUNCTIONS_DOMAIN - Search all functions..
2653 TYPES_DOMAIN - Search all type names.
2654 MODULES_DOMAIN - Search all Fortran modules.
2655 ALL_DOMAIN - Not valid for this function. */
2656 domain_search_flags m_kind
;
2658 /* Regular expression to match against the symbol name. */
2659 const char *m_symbol_name_regexp
= nullptr;
2661 /* Regular expression to match against the symbol type. */
2662 const char *m_symbol_type_regexp
= nullptr;
2664 /* When this flag is false then minsyms that match M_SYMBOL_REGEXP will
2665 be included in the results, otherwise they are excluded. */
2666 bool m_exclude_minsyms
= false;
2668 /* Maximum number of search results. We currently impose a hard limit
2669 of SIZE_MAX, there is no "unlimited". */
2670 size_t m_max_search_results
= SIZE_MAX
;
2672 /* Expand symtabs in OBJFILE that match PREG, are of type M_KIND. Return
2673 true if any msymbols were seen that we should later consider adding to
2674 the results list. */
2675 bool expand_symtabs (objfile
*objfile
,
2676 const std::optional
<compiled_regex
> &preg
) const;
2678 /* Add symbols from symtabs in OBJFILE that match PREG, and TREG, and are
2679 of type M_KIND, to the results set RESULTS_SET. Return false if we
2680 stop adding results early due to having already found too many results
2681 (based on M_MAX_SEARCH_RESULTS limit), otherwise return true.
2682 Returning true does not indicate that any results were added, just
2683 that we didn't _not_ add a result due to reaching MAX_SEARCH_RESULTS. */
2684 bool add_matching_symbols (objfile
*objfile
,
2685 const std::optional
<compiled_regex
> &preg
,
2686 const std::optional
<compiled_regex
> &treg
,
2687 std::set
<symbol_search
> *result_set
) const;
2689 /* Add msymbols from OBJFILE that match PREG and M_KIND, to the results
2690 vector RESULTS. Return false if we stop adding results early due to
2691 having already found too many results (based on max search results
2692 limit M_MAX_SEARCH_RESULTS), otherwise return true. Returning true
2693 does not indicate that any results were added, just that we didn't
2694 _not_ add a result due to reaching MAX_SEARCH_RESULTS. */
2695 bool add_matching_msymbols (objfile
*objfile
,
2696 const std::optional
<compiled_regex
> &preg
,
2697 std::vector
<symbol_search
> *results
) const;
2699 /* Return true if MSYMBOL is of type KIND. */
2700 static bool is_suitable_msymbol (const domain_search_flags kind
,
2701 const minimal_symbol
*msymbol
);
2704 /* When searching for Fortran symbols within modules (functions/variables)
2705 we return a vector of this type. The first item in the pair is the
2706 module symbol, and the second item is the symbol for the function or
2707 variable we found. */
2708 typedef std::pair
<symbol_search
, symbol_search
> module_symbol_search
;
2710 /* Searches the symbols to find function and variables symbols (depending
2711 on KIND) within Fortran modules. The MODULE_REGEXP matches against the
2712 name of the module, REGEXP matches against the name of the symbol within
2713 the module, and TYPE_REGEXP matches against the type of the symbol
2714 within the module. */
2715 extern std::vector
<module_symbol_search
> search_module_symbols
2716 (const char *module_regexp
, const char *regexp
,
2717 const char *type_regexp
, domain_search_flags kind
);
2719 /* Convert a global or static symbol SYM (based on BLOCK, which should be
2720 either GLOBAL_BLOCK or STATIC_BLOCK) into a string for use in 'info'
2721 type commands (e.g. 'info variables', 'info functions', etc). */
2723 extern std::string
symbol_to_info_string (struct symbol
*sym
, int block
);
2725 extern bool treg_matches_sym_type_name (const compiled_regex
&treg
,
2726 const struct symbol
*sym
);
2728 /* The name of the ``main'' function. */
2729 extern const char *main_name ();
2730 extern enum language
main_language (void);
2732 /* Lookup symbol NAME from DOMAIN in MAIN_OBJFILE's global or static blocks,
2733 as specified by BLOCK_INDEX.
2734 This searches MAIN_OBJFILE as well as any associated separate debug info
2735 objfiles of MAIN_OBJFILE.
2736 BLOCK_INDEX can be GLOBAL_BLOCK or STATIC_BLOCK.
2737 Upon success fixes up the symbol's section if necessary. */
2739 extern struct block_symbol
2740 lookup_global_symbol_from_objfile (struct objfile
*main_objfile
,
2741 enum block_enum block_index
,
2743 const domain_search_flags domain
);
2745 /* Return 1 if the supplied producer string matches the ARM RealView
2746 compiler (armcc). */
2747 bool producer_is_realview (const char *producer
);
2749 extern unsigned int symtab_create_debug
;
2751 /* Print a "symtab-create" debug statement. */
2753 #define symtab_create_debug_printf(fmt, ...) \
2754 debug_prefixed_printf_cond (symtab_create_debug >= 1, "symtab-create", fmt, ##__VA_ARGS__)
2756 /* Print a verbose "symtab-create" debug statement, only if
2757 "set debug symtab-create" is set to 2 or higher. */
2759 #define symtab_create_debug_printf_v(fmt, ...) \
2760 debug_prefixed_printf_cond (symtab_create_debug >= 2, "symtab-create", fmt, ##__VA_ARGS__)
2762 extern unsigned int symbol_lookup_debug
;
2764 /* Return true if symbol-lookup debug is turned on at all. */
2767 symbol_lookup_debug_enabled ()
2769 return symbol_lookup_debug
> 0;
2772 /* Return true if symbol-lookup debug is turned to verbose mode. */
2775 symbol_lookup_debug_enabled_v ()
2777 return symbol_lookup_debug
> 1;
2780 /* Print a "symbol-lookup" debug statement if symbol_lookup_debug is >= 1. */
2782 #define symbol_lookup_debug_printf(fmt, ...) \
2783 debug_prefixed_printf_cond (symbol_lookup_debug_enabled (), \
2784 "symbol-lookup", fmt, ##__VA_ARGS__)
2786 /* Print a "symbol-lookup" debug statement if symbol_lookup_debug is >= 2. */
2788 #define symbol_lookup_debug_printf_v(fmt, ...) \
2789 debug_prefixed_printf_cond (symbol_lookup_debug_enabled_v (), \
2790 "symbol-lookup", fmt, ##__VA_ARGS__)
2792 /* Print "symbol-lookup" enter/exit debug statements. */
2794 #define SYMBOL_LOOKUP_SCOPED_DEBUG_ENTER_EXIT \
2795 scoped_debug_enter_exit (symbol_lookup_debug_enabled, "symbol-lookup")
2797 extern bool basenames_may_differ
;
2799 bool compare_filenames_for_search (const char *filename
,
2800 const char *search_name
);
2802 bool compare_glob_filenames_for_search (const char *filename
,
2803 const char *search_name
);
2805 bool iterate_over_some_symtabs (const char *name
,
2806 const char *real_path
,
2807 struct compunit_symtab
*first
,
2808 struct compunit_symtab
*after_last
,
2809 gdb::function_view
<bool (symtab
*)> callback
);
2811 void iterate_over_symtabs (const char *name
,
2812 gdb::function_view
<bool (symtab
*)> callback
);
2815 std::vector
<CORE_ADDR
> find_pcs_for_symtab_line
2816 (struct symtab
*symtab
, int line
, const linetable_entry
**best_entry
);
2818 /* Prototype for callbacks for LA_ITERATE_OVER_SYMBOLS. The callback
2819 is called once per matching symbol SYM. The callback should return
2820 true to indicate that LA_ITERATE_OVER_SYMBOLS should continue
2821 iterating, or false to indicate that the iteration should end. */
2823 typedef bool (symbol_found_callback_ftype
) (struct block_symbol
*bsym
);
2825 /* Iterate over the symbols named NAME, matching DOMAIN, in BLOCK.
2827 For each symbol that matches, CALLBACK is called. The symbol is
2828 passed to the callback.
2830 If CALLBACK returns false, the iteration ends and this function
2831 returns false. Otherwise, the search continues, and the function
2832 eventually returns true. */
2834 bool iterate_over_symbols (const struct block
*block
,
2835 const lookup_name_info
&name
,
2836 const domain_search_flags domain
,
2837 gdb::function_view
<symbol_found_callback_ftype
> callback
);
2839 /* Like iterate_over_symbols, but if all calls to CALLBACK return
2840 true, then calls CALLBACK one additional time with a block_symbol
2841 that has a valid block but a NULL symbol. */
2843 bool iterate_over_symbols_terminated
2844 (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 /* Storage type used by demangle_for_lookup. demangle_for_lookup
2850 either returns a const char * pointer that points to either of the
2851 fields of this type, or a pointer to the input NAME. This is done
2852 this way to avoid depending on the precise details of the storage
2854 class demangle_result_storage
2858 /* Swap the malloc storage to STR, and return a pointer to the
2859 beginning of the new string. */
2860 const char *set_malloc_ptr (gdb::unique_xmalloc_ptr
<char> &&str
)
2862 m_malloc
= std::move (str
);
2863 return m_malloc
.get ();
2866 /* Set the malloc storage to now point at PTR. Any previous malloc
2867 storage is released. */
2868 const char *set_malloc_ptr (char *ptr
)
2870 m_malloc
.reset (ptr
);
2877 gdb::unique_xmalloc_ptr
<char> m_malloc
;
2881 demangle_for_lookup (const char *name
, enum language lang
,
2882 demangle_result_storage
&storage
);
2884 /* Test to see if the symbol of language SYMBOL_LANGUAGE specified by
2885 SYMNAME (which is already demangled for C++ symbols) matches
2886 SYM_TEXT in the first SYM_TEXT_LEN characters. If so, add it to
2887 the current completion list and return true. Otherwise, return
2889 bool completion_list_add_name (completion_tracker
&tracker
,
2890 language symbol_language
,
2891 const char *symname
,
2892 const lookup_name_info
&lookup_name
,
2893 const char *text
, const char *word
);
2895 /* A simple symbol searching class. */
2897 class symbol_searcher
2900 /* Returns the symbols found for the search. */
2901 const std::vector
<block_symbol
> &
2902 matching_symbols () const
2907 /* Returns the minimal symbols found for the search. */
2908 const std::vector
<bound_minimal_symbol
> &
2909 matching_msymbols () const
2911 return m_minimal_symbols
;
2914 /* Search for all symbols named NAME in LANGUAGE with DOMAIN, restricting
2915 search to FILE_SYMTABS and SEARCH_PSPACE, both of which may be NULL
2916 to search all symtabs and program spaces. */
2917 void find_all_symbols (const std::string
&name
,
2918 const struct language_defn
*language
,
2919 domain_search_flags domain_search_flags
,
2920 std::vector
<symtab
*> *search_symtabs
,
2921 struct program_space
*search_pspace
);
2923 /* Reset this object to perform another search. */
2927 m_minimal_symbols
.clear ();
2931 /* Matching debug symbols. */
2932 std::vector
<block_symbol
> m_symbols
;
2934 /* Matching non-debug symbols. */
2935 std::vector
<bound_minimal_symbol
> m_minimal_symbols
;
2938 /* Class used to encapsulate the filename filtering for the "info sources"
2941 struct info_sources_filter
2943 /* If filename filtering is being used (see M_C_REGEXP) then which part
2944 of the filename is being filtered against? */
2947 /* Match against the full filename. */
2950 /* Match only against the directory part of the full filename. */
2953 /* Match only against the basename part of the full filename. */
2957 /* Create a filter of MATCH_TYPE using regular expression REGEXP. If
2958 REGEXP is nullptr then all files will match the filter and MATCH_TYPE
2961 The string pointed too by REGEXP must remain live and unchanged for
2962 this lifetime of this object as the object only retains a copy of the
2964 info_sources_filter (match_on match_type
, const char *regexp
);
2966 DISABLE_COPY_AND_ASSIGN (info_sources_filter
);
2968 /* Does FULLNAME match the filter defined by this object, return true if
2969 it does, otherwise, return false. If there is no filtering defined
2970 then this function will always return true. */
2971 bool matches (const char *fullname
) const;
2975 /* The type of filtering in place. */
2976 match_on m_match_type
;
2978 /* Points to the original regexp used to create this filter. */
2979 const char *m_regexp
;
2981 /* A compiled version of M_REGEXP. This object is only given a value if
2982 M_REGEXP is not nullptr and is not the empty string. */
2983 std::optional
<compiled_regex
> m_c_regexp
;
2986 /* Perform the core of the 'info sources' command.
2988 FILTER is used to perform regular expression based filtering on the
2989 source files that will be displayed.
2991 Output is written to UIOUT in CLI or MI style as appropriate. */
2993 extern void info_sources_worker (struct ui_out
*uiout
,
2994 bool group_by_objfile
,
2995 const info_sources_filter
&filter
);
2997 /* This function returns the address at which the function epilogue begins,
2998 according to the linetable.
3000 Returns an empty optional if EPILOGUE_BEGIN is never set in the
3003 std::optional
<CORE_ADDR
> find_epilogue_using_linetable (CORE_ADDR func_addr
);
3005 /* Search an array of symbols for one named NAME. Name comparison is
3006 done using strcmp -- i.e., this is only useful for simple names.
3007 Returns the symbol, if found, or nullptr if not. */
3009 extern struct symbol
*search_symbol_list (const char *name
, int num
,
3010 struct symbol
**syms
);
3012 #endif /* !defined(SYMTAB_H) */