1 /* Symbol table definitions for GDB.
3 Copyright (C) 1986-2023 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #if !defined (SYMTAB_H)
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"
33 #include "gdbsupport/gdb_optional.h"
34 #include "gdbsupport/gdb_string_view.h"
35 #include "gdbsupport/next-iterator.h"
36 #include "gdbsupport/iterator-range.h"
37 #include "completer.h"
38 #include "gdb-demangle.h"
39 #include "split-name.h"
42 /* Opaque declarations. */
56 struct cmd_list_element
;
58 struct lookup_name_info
;
59 struct code_breakpoint
;
61 /* How to match a lookup name against a symbol search name. */
62 enum class symbol_name_match_type
64 /* Wild matching. Matches unqualified symbol names in all
65 namespace/module/packages, etc. */
68 /* Full matching. The lookup name indicates a fully-qualified name,
69 and only matches symbol search names in the specified
70 namespace/module/package. */
73 /* Search name matching. This is like FULL, but the search name did
74 not come from the user; instead it is already a search name
75 retrieved from a search_name () call.
76 For Ada, this avoids re-encoding an already-encoded search name
77 (which would potentially incorrectly lowercase letters in the
78 linkage/search name that should remain uppercase). For C++, it
79 avoids trying to demangle a name we already know is
83 /* Expression matching. The same as FULL matching in most
84 languages. The same as WILD matching in Ada. */
88 /* Hash the given symbol search name according to LANGUAGE's
90 extern unsigned int search_name_hash (enum language language
,
91 const char *search_name
);
93 /* Ada-specific bits of a lookup_name_info object. This is lazily
94 constructed on demand. */
96 class ada_lookup_name_info final
100 explicit ada_lookup_name_info (const lookup_name_info
&lookup_name
);
102 /* Compare SYMBOL_SEARCH_NAME with our lookup name, using MATCH_TYPE
103 as name match type. Returns true if there's a match, false
104 otherwise. If non-NULL, store the matching results in MATCH. */
105 bool matches (const char *symbol_search_name
,
106 symbol_name_match_type match_type
,
107 completion_match_result
*comp_match_res
) const;
109 /* The Ada-encoded lookup name. */
110 const std::string
&lookup_name () const
111 { return m_encoded_name
; }
113 /* Return true if we're supposed to be doing a wild match look
115 bool wild_match_p () const
116 { return m_wild_match_p
; }
118 /* Return true if we're looking up a name inside package
120 bool standard_p () const
121 { return m_standard_p
; }
123 /* Return true if doing a verbatim match. */
124 bool verbatim_p () const
125 { return m_verbatim_p
; }
127 /* A wrapper for ::split_name that handles some Ada-specific
129 std::vector
<gdb::string_view
> split_name () const
131 if (m_verbatim_p
|| m_standard_p
)
133 std::vector
<gdb::string_view
> result
;
135 result
.emplace_back ("standard");
136 result
.emplace_back (m_encoded_name
);
139 return ::split_name (m_encoded_name
.c_str (), split_style::UNDERSCORE
);
143 /* The Ada-encoded lookup name. */
144 std::string m_encoded_name
;
146 /* Whether the user-provided lookup name was Ada encoded. If so,
147 then return encoded names in the 'matches' method's 'completion
148 match result' output. */
149 bool m_encoded_p
: 1;
151 /* True if really doing wild matching. Even if the user requests
152 wild matching, some cases require full matching. */
153 bool m_wild_match_p
: 1;
155 /* True if doing a verbatim match. This is true if the decoded
156 version of the symbol name is wrapped in '<'/'>'. This is an
157 escape hatch users can use to look up symbols the Ada encoding
158 does not understand. */
159 bool m_verbatim_p
: 1;
161 /* True if the user specified a symbol name that is inside package
162 Standard. Symbol names inside package Standard are handled
163 specially. We always do a non-wild match of the symbol name
164 without the "standard__" prefix, and only search static and
165 global symbols. This was primarily introduced in order to allow
166 the user to specifically access the standard exceptions using,
167 for instance, Standard.Constraint_Error when Constraint_Error is
168 ambiguous (due to the user defining its own Constraint_Error
169 entity inside its program). */
170 bool m_standard_p
: 1;
173 /* Language-specific bits of a lookup_name_info object, for languages
174 that do name searching using demangled names (C++/D/Go). This is
175 lazily constructed on demand. */
177 struct demangle_for_lookup_info final
180 demangle_for_lookup_info (const lookup_name_info
&lookup_name
,
183 /* The demangled lookup name. */
184 const std::string
&lookup_name () const
185 { return m_demangled_name
; }
188 /* The demangled lookup name. */
189 std::string m_demangled_name
;
192 /* Object that aggregates all information related to a symbol lookup
193 name. I.e., the name that is matched against the symbol's search
194 name. Caches per-language information so that it doesn't require
195 recomputing it for every symbol comparison, like for example the
196 Ada encoded name and the symbol's name hash for a given language.
197 The object is conceptually immutable once constructed, and thus has
198 no setters. This is to prevent some code path from tweaking some
199 property of the lookup name for some local reason and accidentally
200 altering the results of any continuing search(es).
201 lookup_name_info objects are generally passed around as a const
202 reference to reinforce that. (They're not passed around by value
203 because they're not small.) */
204 class lookup_name_info final
207 /* We delete this overload so that the callers are required to
208 explicitly handle the lifetime of the name. */
209 lookup_name_info (std::string
&&name
,
210 symbol_name_match_type match_type
,
211 bool completion_mode
= false,
212 bool ignore_parameters
= false) = delete;
214 /* This overload requires that NAME have a lifetime at least as long
215 as the lifetime of this object. */
216 lookup_name_info (const std::string
&name
,
217 symbol_name_match_type match_type
,
218 bool completion_mode
= false,
219 bool ignore_parameters
= false)
220 : m_match_type (match_type
),
221 m_completion_mode (completion_mode
),
222 m_ignore_parameters (ignore_parameters
),
226 /* This overload requires that NAME have a lifetime at least as long
227 as the lifetime of this object. */
228 lookup_name_info (const char *name
,
229 symbol_name_match_type match_type
,
230 bool completion_mode
= false,
231 bool ignore_parameters
= false)
232 : m_match_type (match_type
),
233 m_completion_mode (completion_mode
),
234 m_ignore_parameters (ignore_parameters
),
238 /* Getters. See description of each corresponding field. */
239 symbol_name_match_type
match_type () const { return m_match_type
; }
240 bool completion_mode () const { return m_completion_mode
; }
241 gdb::string_view
name () const { return m_name
; }
242 const bool ignore_parameters () const { return m_ignore_parameters
; }
244 /* Like the "name" method but guarantees that the returned string is
246 const char *c_str () const
248 /* Actually this is always guaranteed due to how the class is
250 return m_name
.data ();
253 /* Return a version of this lookup name that is usable with
254 comparisons against symbols have no parameter info, such as
255 psymbols and GDB index symbols. */
256 lookup_name_info
make_ignore_params () const
258 return lookup_name_info (c_str (), m_match_type
, m_completion_mode
,
259 true /* ignore params */);
262 /* Get the search name hash for searches in language LANG. */
263 unsigned int search_name_hash (language lang
) const
265 /* Only compute each language's hash once. */
266 if (!m_demangled_hashes_p
[lang
])
268 m_demangled_hashes
[lang
]
269 = ::search_name_hash (lang
, language_lookup_name (lang
));
270 m_demangled_hashes_p
[lang
] = true;
272 return m_demangled_hashes
[lang
];
275 /* Get the search name for searches in language LANG. */
276 const char *language_lookup_name (language lang
) const
281 return ada ().lookup_name ().c_str ();
283 return cplus ().lookup_name ().c_str ();
285 return d ().lookup_name ().c_str ();
287 return go ().lookup_name ().c_str ();
289 return m_name
.data ();
293 /* A wrapper for ::split_name (see split-name.h) that splits this
294 name, and that handles any language-specific peculiarities. */
295 std::vector
<gdb::string_view
> split_name (language lang
) const
297 if (lang
== language_ada
)
298 return ada ().split_name ();
299 split_style style
= split_style::NONE
;
304 style
= split_style::CXX
;
308 style
= split_style::DOT
;
311 return ::split_name (language_lookup_name (lang
), style
);
314 /* Get the Ada-specific lookup info. */
315 const ada_lookup_name_info
&ada () const
321 /* Get the C++-specific lookup info. */
322 const demangle_for_lookup_info
&cplus () const
324 maybe_init (m_cplus
, language_cplus
);
328 /* Get the D-specific lookup info. */
329 const demangle_for_lookup_info
&d () const
331 maybe_init (m_d
, language_d
);
335 /* Get the Go-specific lookup info. */
336 const demangle_for_lookup_info
&go () const
338 maybe_init (m_go
, language_go
);
342 /* Get a reference to a lookup_name_info object that matches any
344 static const lookup_name_info
&match_any ();
347 /* Initialize FIELD, if not initialized yet. */
348 template<typename Field
, typename
... Args
>
349 void maybe_init (Field
&field
, Args
&&... args
) const
352 field
.emplace (*this, std::forward
<Args
> (args
)...);
355 /* The lookup info as passed to the ctor. */
356 symbol_name_match_type m_match_type
;
357 bool m_completion_mode
;
358 bool m_ignore_parameters
;
359 gdb::string_view m_name
;
361 /* Language-specific info. These fields are filled lazily the first
362 time a lookup is done in the corresponding language. They're
363 mutable because lookup_name_info objects are typically passed
364 around by const reference (see intro), and they're conceptually
365 "cache" that can always be reconstructed from the non-mutable
367 mutable gdb::optional
<ada_lookup_name_info
> m_ada
;
368 mutable gdb::optional
<demangle_for_lookup_info
> m_cplus
;
369 mutable gdb::optional
<demangle_for_lookup_info
> m_d
;
370 mutable gdb::optional
<demangle_for_lookup_info
> m_go
;
372 /* The demangled hashes. Stored in an array with one entry for each
373 possible language. The second array records whether we've
374 already computed the each language's hash. (These are separate
375 arrays instead of a single array of optional<unsigned> to avoid
376 alignment padding). */
377 mutable std::array
<unsigned int, nr_languages
> m_demangled_hashes
;
378 mutable std::array
<bool, nr_languages
> m_demangled_hashes_p
{};
381 /* Comparison function for completion symbol lookup.
383 Returns true if the symbol name matches against LOOKUP_NAME.
385 SYMBOL_SEARCH_NAME should be a symbol's "search" name.
387 On success and if non-NULL, COMP_MATCH_RES->match is set to point
388 to the symbol name as should be presented to the user as a
389 completion match list element. In most languages, this is the same
390 as the symbol's search name, but in some, like Ada, the display
391 name is dynamically computed within the comparison routine.
393 Also, on success and if non-NULL, COMP_MATCH_RES->match_for_lcd
394 points the part of SYMBOL_SEARCH_NAME that was considered to match
395 LOOKUP_NAME. E.g., in C++, in linespec/wild mode, if the symbol is
396 "foo::function()" and LOOKUP_NAME is "function(", MATCH_FOR_LCD
397 points to "function()" inside SYMBOL_SEARCH_NAME. */
398 typedef bool (symbol_name_matcher_ftype
)
399 (const char *symbol_search_name
,
400 const lookup_name_info
&lookup_name
,
401 completion_match_result
*comp_match_res
);
403 /* Some of the structures in this file are space critical.
404 The space-critical structures are:
406 struct general_symbol_info
408 struct partial_symbol
410 These structures are laid out to encourage good packing.
411 They use ENUM_BITFIELD and short int fields, and they order the
412 structure members so that fields less than a word are next
413 to each other so they can be packed together. */
415 /* Rearranged: used ENUM_BITFIELD and rearranged field order in
416 all the space critical structures (plus struct minimal_symbol).
417 Memory usage dropped from 99360768 bytes to 90001408 bytes.
418 I measured this with before-and-after tests of
419 "HEAD-old-gdb -readnow HEAD-old-gdb" and
420 "HEAD-new-gdb -readnow HEAD-old-gdb" on native i686-pc-linux-gnu,
421 red hat linux 8, with LD_LIBRARY_PATH=/usr/lib/debug,
422 typing "maint space 1" at the first command prompt.
424 Here is another measurement (from andrew c):
425 # no /usr/lib/debug, just plain glibc, like a normal user
427 (gdb) break internal_error
429 (gdb) maint internal-error
433 gdb gdb_6_0_branch 2003-08-19 space used: 8896512
434 gdb HEAD 2003-08-19 space used: 8904704
435 gdb HEAD 2003-08-21 space used: 8396800 (+symtab.h)
436 gdb HEAD 2003-08-21 space used: 8265728 (+gdbtypes.h)
438 The third line shows the savings from the optimizations in symtab.h.
439 The fourth line shows the savings from the optimizations in
440 gdbtypes.h. Both optimizations are in gdb HEAD now.
442 --chastain 2003-08-21 */
444 /* Define a structure for the information that is common to all symbol types,
445 including minimal symbols, partial symbols, and full symbols. In a
446 multilanguage environment, some language specific information may need to
447 be recorded along with each symbol. */
449 /* This structure is space critical. See space comments at the top. */
451 struct general_symbol_info
453 /* Short version as to when to use which name accessor:
454 Use natural_name () to refer to the name of the symbol in the original
455 source code. Use linkage_name () if you want to know what the linker
456 thinks the symbol's name is. Use print_name () for output. Use
457 demangled_name () if you specifically need to know whether natural_name ()
458 and linkage_name () are different. */
460 const char *linkage_name () const
463 /* Return SYMBOL's "natural" name, i.e. the name that it was called in
464 the original source code. In languages like C++ where symbols may
465 be mangled for ease of manipulation by the linker, this is the
467 const char *natural_name () const;
469 /* Returns a version of the name of a symbol that is
470 suitable for output. In C++ this is the "demangled" form of the
471 name if demangle is on and the "mangled" form of the name if
472 demangle is off. In other languages this is just the symbol name.
473 The result should never be NULL. Don't use this for internal
474 purposes (e.g. storing in a hashtable): it's only suitable for output. */
475 const char *print_name () const
476 { return demangle
? natural_name () : linkage_name (); }
478 /* Return the demangled name for a symbol based on the language for
479 that symbol. If no demangled name exists, return NULL. */
480 const char *demangled_name () const;
482 /* Returns the name to be used when sorting and searching symbols.
483 In C++, we search for the demangled form of a name,
484 and so sort symbols accordingly. In Ada, however, we search by mangled
485 name. If there is no distinct demangled name, then this
486 returns the same value (same pointer) as linkage_name (). */
487 const char *search_name () const;
489 /* Set just the linkage name of a symbol; do not try to demangle
490 it. Used for constructs which do not have a mangled name,
491 e.g. struct tags. Unlike compute_and_set_names, linkage_name must
492 be terminated and either already on the objfile's obstack or
493 permanently allocated. */
494 void set_linkage_name (const char *linkage_name
)
495 { m_name
= linkage_name
; }
497 /* Set the demangled name of this symbol to NAME. NAME must be
498 already correctly allocated. If the symbol's language is Ada,
499 then the name is ignored and the obstack is set. */
500 void set_demangled_name (const char *name
, struct obstack
*obstack
);
502 enum language
language () const
503 { return m_language
; }
505 /* Initializes the language dependent portion of a symbol
506 depending upon the language for the symbol. */
507 void set_language (enum language language
, struct obstack
*obstack
);
509 /* Set the linkage and natural names of a symbol, by demangling
510 the linkage name. If linkage_name may not be nullterminated,
511 copy_name must be set to true. */
512 void compute_and_set_names (gdb::string_view linkage_name
, bool copy_name
,
513 struct objfile_per_bfd_storage
*per_bfd
,
514 gdb::optional
<hashval_t
> hash
515 = gdb::optional
<hashval_t
> ());
517 CORE_ADDR
value_address () const
519 return m_value
.address
;
522 void set_value_address (CORE_ADDR address
)
524 m_value
.address
= address
;
527 /* Name of the symbol. This is a required field. Storage for the
528 name is allocated on the objfile_obstack for the associated
529 objfile. For languages like C++ that make a distinction between
530 the mangled name and demangled name, this is the mangled
535 /* Value of the symbol. Which member of this union to use, and what
536 it means, depends on what kind of symbol this is and its
537 SYMBOL_CLASS. See comments there for more details. All of these
538 are in host byte order (though what they point to might be in
539 target byte order, e.g. LOC_CONST_BYTES). */
545 const struct block
*block
;
547 const gdb_byte
*bytes
;
551 /* A common block. Used with LOC_COMMON_BLOCK. */
553 const struct common_block
*common_block
;
555 /* For opaque typedef struct chain. */
557 struct symbol
*chain
;
561 /* Since one and only one language can apply, wrap the language specific
562 information inside a union. */
566 /* A pointer to an obstack that can be used for storage associated
567 with this symbol. This is only used by Ada, and only when the
568 'ada_mangled' field is zero. */
569 struct obstack
*obstack
;
571 /* This is used by languages which wish to store a demangled name.
572 currently used by Ada, C++, and Objective C. */
573 const char *demangled_name
;
577 /* Record the source code language that applies to this symbol.
578 This is used to select one of the fields from the language specific
581 ENUM_BITFIELD(language
) m_language
: LANGUAGE_BITS
;
583 /* This is only used by Ada. If set, then the 'demangled_name' field
584 of language_specific is valid. Otherwise, the 'obstack' field is
586 unsigned int ada_mangled
: 1;
588 /* Which section is this symbol in? This is an index into
589 section_offsets for this objfile. Negative means that the symbol
590 does not get relocated relative to a section. */
594 /* Set the index into the obj_section list (within the containing
595 objfile) for the section that contains this symbol. See M_SECTION
598 void set_section_index (short idx
)
601 /* Return the index into the obj_section list (within the containing
602 objfile) for the section that contains this symbol. See M_SECTION
605 short section_index () const
606 { return m_section
; }
608 /* Return the obj_section from OBJFILE for this symbol. The symbol
609 returned is based on the SECTION member variable, and can be nullptr
610 if SECTION is negative. */
612 struct obj_section
*obj_section (const struct objfile
*objfile
) const;
615 extern CORE_ADDR
symbol_overlayed_address (CORE_ADDR
, struct obj_section
*);
617 /* Return the address of SYM. The MAYBE_COPIED flag must be set on
618 SYM. If SYM appears in the main program's minimal symbols, then
619 that minsym's address is returned; otherwise, SYM's address is
620 returned. This should generally only be used via the
621 SYMBOL_VALUE_ADDRESS macro. */
623 extern CORE_ADDR
get_symbol_address (const struct symbol
*sym
);
625 /* Try to determine the demangled name for a symbol, based on the
626 language of that symbol. If the language is set to language_auto,
627 it will attempt to find any demangling algorithm that works and
628 then set the language appropriately. The returned name is allocated
629 by the demangler and should be xfree'd. */
631 extern gdb::unique_xmalloc_ptr
<char> symbol_find_demangled_name
632 (struct general_symbol_info
*gsymbol
, const char *mangled
);
634 /* Return true if NAME matches the "search" name of GSYMBOL, according
635 to the symbol's language. */
636 extern bool symbol_matches_search_name
637 (const struct general_symbol_info
*gsymbol
,
638 const lookup_name_info
&name
);
640 /* Compute the hash of the given symbol search name of a symbol of
641 language LANGUAGE. */
642 extern unsigned int search_name_hash (enum language language
,
643 const char *search_name
);
645 /* Classification types for a minimal symbol. These should be taken as
646 "advisory only", since if gdb can't easily figure out a
647 classification it simply selects mst_unknown. It may also have to
648 guess when it can't figure out which is a better match between two
649 types (mst_data versus mst_bss) for example. Since the minimal
650 symbol info is sometimes derived from the BFD library's view of a
651 file, we need to live with what information bfd supplies. */
653 enum minimal_symbol_type
655 mst_unknown
= 0, /* Unknown type, the default */
656 mst_text
, /* Generally executable instructions */
658 /* A GNU ifunc symbol, in the .text section. GDB uses to know
659 whether the user is setting a breakpoint on a GNU ifunc function,
660 and thus GDB needs to actually set the breakpoint on the target
661 function. It is also used to know whether the program stepped
662 into an ifunc resolver -- the resolver may get a separate
663 symbol/alias under a different name, but it'll have the same
664 address as the ifunc symbol. */
665 mst_text_gnu_ifunc
, /* Executable code returning address
666 of executable code */
668 /* A GNU ifunc function descriptor symbol, in a data section
669 (typically ".opd"). Seen on architectures that use function
670 descriptors, like PPC64/ELFv1. In this case, this symbol's value
671 is the address of the descriptor. There'll be a corresponding
672 mst_text_gnu_ifunc synthetic symbol for the text/entry
674 mst_data_gnu_ifunc
, /* Executable code returning address
675 of executable code */
677 mst_slot_got_plt
, /* GOT entries for .plt sections */
678 mst_data
, /* Generally initialized data */
679 mst_bss
, /* Generally uninitialized data */
680 mst_abs
, /* Generally absolute (nonrelocatable) */
681 /* GDB uses mst_solib_trampoline for the start address of a shared
682 library trampoline entry. Breakpoints for shared library functions
683 are put there if the shared library is not yet loaded.
684 After the shared library is loaded, lookup_minimal_symbol will
685 prefer the minimal symbol from the shared library (usually
686 a mst_text symbol) over the mst_solib_trampoline symbol, and the
687 breakpoints will be moved to their true address in the shared
688 library via breakpoint_re_set. */
689 mst_solib_trampoline
, /* Shared library trampoline code */
690 /* For the mst_file* types, the names are only guaranteed to be unique
691 within a given .o file. */
692 mst_file_text
, /* Static version of mst_text */
693 mst_file_data
, /* Static version of mst_data */
694 mst_file_bss
, /* Static version of mst_bss */
698 /* The number of enum minimal_symbol_type values, with some padding for
699 reasonable growth. */
700 #define MINSYM_TYPE_BITS 4
701 gdb_static_assert (nr_minsym_types
<= (1 << MINSYM_TYPE_BITS
));
703 /* Return the address of MINSYM, which comes from OBJF. The
704 MAYBE_COPIED flag must be set on MINSYM. If MINSYM appears in the
705 main program's minimal symbols, then that minsym's address is
706 returned; otherwise, MINSYM's address is returned. This should
707 generally only be used via the MSYMBOL_VALUE_ADDRESS macro. */
709 extern CORE_ADDR
get_msymbol_address (struct objfile
*objf
,
710 const struct minimal_symbol
*minsym
);
712 /* Define a simple structure used to hold some very basic information about
713 all defined global symbols (text, data, bss, abs, etc). The only required
714 information is the general_symbol_info.
716 In many cases, even if a file was compiled with no special options for
717 debugging at all, as long as was not stripped it will contain sufficient
718 information to build a useful minimal symbol table using this structure.
719 Even when a file contains enough debugging information to build a full
720 symbol table, these minimal symbols are still useful for quickly mapping
721 between names and addresses, and vice versa. They are also sometimes
722 used to figure out what full symbol table entries need to be read in. */
724 struct minimal_symbol
: public general_symbol_info
726 LONGEST
value_longest () const
728 return m_value
.ivalue
;
731 /* The relocated address of the minimal symbol, using the section
732 offsets from OBJFILE. */
733 CORE_ADDR
value_address (objfile
*objfile
) const;
735 /* The unrelocated address of the minimal symbol. */
736 CORE_ADDR
value_raw_address () const
738 return m_value
.address
;
741 /* Return this minimal symbol's type. */
743 minimal_symbol_type
type () const
748 /* Set this minimal symbol's type. */
750 void set_type (minimal_symbol_type type
)
755 /* Return this minimal symbol's size. */
757 unsigned long size () const
762 /* Set this minimal symbol's size. */
764 void set_size (unsigned long size
)
770 /* Return true if this minimal symbol's size is known. */
772 bool has_size () const
777 /* Return this minimal symbol's first target-specific flag. */
779 bool target_flag_1 () const
781 return m_target_flag_1
;
784 /* Set this minimal symbol's first target-specific flag. */
786 void set_target_flag_1 (bool target_flag_1
)
788 m_target_flag_1
= target_flag_1
;
791 /* Return this minimal symbol's second target-specific flag. */
793 bool target_flag_2 () const
795 return m_target_flag_2
;
798 /* Set this minimal symbol's second target-specific flag. */
800 void set_target_flag_2 (bool target_flag_2
)
802 m_target_flag_2
= target_flag_2
;
805 /* Size of this symbol. dbx_end_psymtab in dbxread.c uses this
806 information to calculate the end of the partial symtab based on the
807 address of the last symbol plus the size of the last symbol. */
809 unsigned long m_size
;
811 /* Which source file is this symbol in? Only relevant for mst_file_*. */
812 const char *filename
;
814 /* Classification type for this minimal symbol. */
816 ENUM_BITFIELD(minimal_symbol_type
) m_type
: MINSYM_TYPE_BITS
;
818 /* Non-zero if this symbol was created by gdb.
819 Such symbols do not appear in the output of "info var|fun". */
820 unsigned int created_by_gdb
: 1;
822 /* Two flag bits provided for the use of the target. */
823 unsigned int m_target_flag_1
: 1;
824 unsigned int m_target_flag_2
: 1;
826 /* Nonzero iff the size of the minimal symbol has been set.
827 Symbol size information can sometimes not be determined, because
828 the object file format may not carry that piece of information. */
829 unsigned int m_has_size
: 1;
831 /* For data symbols only, if this is set, then the symbol might be
832 subject to copy relocation. In this case, a minimal symbol
833 matching the symbol's linkage name is first looked for in the
834 main objfile. If found, then that address is used; otherwise the
835 address in this symbol is used. */
837 unsigned maybe_copied
: 1;
839 /* Non-zero if this symbol ever had its demangled name set (even if
840 it was set to NULL). */
841 unsigned int name_set
: 1;
843 /* Minimal symbols with the same hash key are kept on a linked
844 list. This is the link. */
846 struct minimal_symbol
*hash_next
;
848 /* Minimal symbols are stored in two different hash tables. This is
849 the `next' pointer for the demangled hash table. */
851 struct minimal_symbol
*demangled_hash_next
;
853 /* True if this symbol is of some data type. */
855 bool data_p () const;
857 /* True if MSYMBOL is of some text type. */
859 bool text_p () const;
866 /* Represent one symbol name; a variable, constant, function or typedef. */
868 /* Different name domains for symbols. Looking up a symbol specifies a
869 domain and ignores symbol definitions in other name domains. */
873 /* UNDEF_DOMAIN is used when a domain has not been discovered or
874 none of the following apply. This usually indicates an error either
875 in the symbol information or in gdb's handling of symbols. */
879 /* VAR_DOMAIN is the usual domain. In C, this contains variables,
880 function names, typedef names and enum type values. */
884 /* STRUCT_DOMAIN is used in C to hold struct, union and enum type names.
885 Thus, if `struct foo' is used in a C program, it produces a symbol named
886 `foo' in the STRUCT_DOMAIN. */
890 /* MODULE_DOMAIN is used in Fortran to hold module type names. */
894 /* LABEL_DOMAIN may be used for names of labels (for gotos). */
898 /* Fortran common blocks. Their naming must be separate from VAR_DOMAIN.
899 They also always use LOC_COMMON_BLOCK. */
902 /* This must remain last. */
906 /* The number of bits in a symbol used to represent the domain. */
908 #define SYMBOL_DOMAIN_BITS 3
909 gdb_static_assert (NR_DOMAINS
<= (1 << SYMBOL_DOMAIN_BITS
));
911 extern const char *domain_name (domain_enum
);
913 /* Searching domains, used when searching for symbols. Element numbers are
914 hardcoded in GDB, check all enum uses before changing it. */
918 /* Everything in VAR_DOMAIN minus FUNCTIONS_DOMAIN and
920 VARIABLES_DOMAIN
= 0,
922 /* All functions -- for some reason not methods, though. */
923 FUNCTIONS_DOMAIN
= 1,
925 /* All defined types */
935 extern const char *search_domain_name (enum search_domain
);
937 /* An address-class says where to find the value of a symbol. */
941 /* Not used; catches errors. */
945 /* Value is constant int SYMBOL_VALUE, host byteorder. */
949 /* Value is at fixed address SYMBOL_VALUE_ADDRESS. */
953 /* Value is in register. SYMBOL_VALUE is the register number
954 in the original debug format. SYMBOL_REGISTER_OPS holds a
955 function that can be called to transform this into the
956 actual register number this represents in a specific target
957 architecture (gdbarch).
959 For some symbol formats (stabs, for some compilers at least),
960 the compiler generates two symbols, an argument and a register.
961 In some cases we combine them to a single LOC_REGISTER in symbol
962 reading, but currently not for all cases (e.g. it's passed on the
963 stack and then loaded into a register). */
967 /* It's an argument; the value is at SYMBOL_VALUE offset in arglist. */
971 /* Value address is at SYMBOL_VALUE offset in arglist. */
975 /* Value is in specified register. Just like LOC_REGISTER except the
976 register holds the address of the argument instead of the argument
977 itself. This is currently used for the passing of structs and unions
978 on sparc and hppa. It is also used for call by reference where the
979 address is in a register, at least by mipsread.c. */
983 /* Value is a local variable at SYMBOL_VALUE offset in stack frame. */
987 /* Value not used; definition in SYMBOL_TYPE. Symbols in the domain
988 STRUCT_DOMAIN all have this class. */
992 /* Value is address SYMBOL_VALUE_ADDRESS in the code. */
996 /* In a symbol table, value is SYMBOL_BLOCK_VALUE of a `struct block'.
997 In a partial symbol table, SYMBOL_VALUE_ADDRESS is the start address
998 of the block. Function names have this class. */
1002 /* Value is a constant byte-sequence pointed to by SYMBOL_VALUE_BYTES, in
1003 target byte order. */
1007 /* Value is at fixed address, but the address of the variable has
1008 to be determined from the minimal symbol table whenever the
1009 variable is referenced.
1010 This happens if debugging information for a global symbol is
1011 emitted and the corresponding minimal symbol is defined
1012 in another object file or runtime common storage.
1013 The linker might even remove the minimal symbol if the global
1014 symbol is never referenced, in which case the symbol remains
1017 GDB would normally find the symbol in the minimal symbol table if it will
1018 not find it in the full symbol table. But a reference to an external
1019 symbol in a local block shadowing other definition requires full symbol
1020 without possibly having its address available for LOC_STATIC. Testcase
1021 is provided as `gdb.dwarf2/dw2-unresolved.exp'.
1023 This is also used for thread local storage (TLS) variables. In this case,
1024 the address of the TLS variable must be determined when the variable is
1025 referenced, from the MSYMBOL_VALUE_RAW_ADDRESS, which is the offset
1026 of the TLS variable in the thread local storage of the shared
1031 /* The variable does not actually exist in the program.
1032 The value is ignored. */
1036 /* The variable's address is computed by a set of location
1037 functions (see "struct symbol_computed_ops" below). */
1040 /* The variable uses general_symbol_info->value->common_block field.
1041 It also always uses COMMON_BLOCK_DOMAIN. */
1044 /* Not used, just notes the boundary of the enum. */
1048 /* The number of bits needed for values in enum address_class, with some
1049 padding for reasonable growth, and room for run-time registered address
1050 classes. See symtab.c:MAX_SYMBOL_IMPLS.
1051 This is a #define so that we can have a assertion elsewhere to
1052 verify that we have reserved enough space for synthetic address
1054 #define SYMBOL_ACLASS_BITS 5
1055 gdb_static_assert (LOC_FINAL_VALUE
<= (1 << SYMBOL_ACLASS_BITS
));
1057 /* The methods needed to implement LOC_COMPUTED. These methods can
1058 use the symbol's .aux_value for additional per-symbol information.
1060 At present this is only used to implement location expressions. */
1062 struct symbol_computed_ops
1065 /* Return the value of the variable SYMBOL, relative to the stack
1066 frame FRAME. If the variable has been optimized out, return
1069 Iff `read_needs_frame (SYMBOL)' is not SYMBOL_NEEDS_FRAME, then
1070 FRAME may be zero. */
1072 struct value
*(*read_variable
) (struct symbol
* symbol
,
1073 frame_info_ptr frame
);
1075 /* Read variable SYMBOL like read_variable at (callee) FRAME's function
1076 entry. SYMBOL should be a function parameter, otherwise
1077 NO_ENTRY_VALUE_ERROR will be thrown. */
1078 struct value
*(*read_variable_at_entry
) (struct symbol
*symbol
,
1079 frame_info_ptr frame
);
1081 /* Find the "symbol_needs_kind" value for the given symbol. This
1082 value determines whether reading the symbol needs memory (e.g., a
1083 global variable), just registers (a thread-local), or a frame (a
1085 enum symbol_needs_kind (*get_symbol_read_needs
) (struct symbol
* symbol
);
1087 /* Write to STREAM a natural-language description of the location of
1088 SYMBOL, in the context of ADDR. */
1089 void (*describe_location
) (struct symbol
* symbol
, CORE_ADDR addr
,
1090 struct ui_file
* stream
);
1092 /* Non-zero if this symbol's address computation is dependent on PC. */
1093 unsigned char location_has_loclist
;
1095 /* Tracepoint support. Append bytecodes to the tracepoint agent
1096 expression AX that push the address of the object SYMBOL. Set
1097 VALUE appropriately. Note --- for objects in registers, this
1098 needn't emit any code; as long as it sets VALUE properly, then
1099 the caller will generate the right code in the process of
1100 treating this as an lvalue or rvalue. */
1102 void (*tracepoint_var_ref
) (struct symbol
*symbol
, struct agent_expr
*ax
,
1103 struct axs_value
*value
);
1105 /* Generate C code to compute the location of SYMBOL. The C code is
1106 emitted to STREAM. GDBARCH is the current architecture and PC is
1107 the PC at which SYMBOL's location should be evaluated.
1108 REGISTERS_USED is a vector indexed by register number; the
1109 generator function should set an element in this vector if the
1110 corresponding register is needed by the location computation.
1111 The generated C code must assign the location to a local
1112 variable; this variable's name is RESULT_NAME. */
1114 void (*generate_c_location
) (struct symbol
*symbol
, string_file
*stream
,
1115 struct gdbarch
*gdbarch
,
1116 std::vector
<bool> ®isters_used
,
1117 CORE_ADDR pc
, const char *result_name
);
1121 /* The methods needed to implement LOC_BLOCK for inferior functions.
1122 These methods can use the symbol's .aux_value for additional
1123 per-symbol information. */
1125 struct symbol_block_ops
1127 /* Fill in *START and *LENGTH with DWARF block data of function
1128 FRAMEFUNC valid for inferior context address PC. Set *LENGTH to
1129 zero if such location is not valid for PC; *START is left
1130 uninitialized in such case. */
1131 void (*find_frame_base_location
) (struct symbol
*framefunc
, CORE_ADDR pc
,
1132 const gdb_byte
**start
, size_t *length
);
1134 /* Return the frame base address. FRAME is the frame for which we want to
1135 compute the base address while FRAMEFUNC is the symbol for the
1136 corresponding function. Return 0 on failure (FRAMEFUNC may not hold the
1137 information we need).
1139 This method is designed to work with static links (nested functions
1140 handling). Static links are function properties whose evaluation returns
1141 the frame base address for the enclosing frame. However, there are
1142 multiple definitions for "frame base": the content of the frame base
1143 register, the CFA as defined by DWARF unwinding information, ...
1145 So this specific method is supposed to compute the frame base address such
1146 as for nested functions, the static link computes the same address. For
1147 instance, considering DWARF debugging information, the static link is
1148 computed with DW_AT_static_link and this method must be used to compute
1149 the corresponding DW_AT_frame_base attribute. */
1150 CORE_ADDR (*get_frame_base
) (struct symbol
*framefunc
,
1151 frame_info_ptr frame
);
1154 /* Functions used with LOC_REGISTER and LOC_REGPARM_ADDR. */
1156 struct symbol_register_ops
1158 int (*register_number
) (struct symbol
*symbol
, struct gdbarch
*gdbarch
);
1161 /* Objects of this type are used to find the address class and the
1162 various computed ops vectors of a symbol. */
1166 enum address_class aclass
;
1168 /* Used with LOC_COMPUTED. */
1169 const struct symbol_computed_ops
*ops_computed
;
1171 /* Used with LOC_BLOCK. */
1172 const struct symbol_block_ops
*ops_block
;
1174 /* Used with LOC_REGISTER and LOC_REGPARM_ADDR. */
1175 const struct symbol_register_ops
*ops_register
;
1178 /* struct symbol has some subclasses. This enum is used to
1179 differentiate between them. */
1181 enum symbol_subclass_kind
1183 /* Plain struct symbol. */
1186 /* struct template_symbol. */
1189 /* struct rust_vtable_symbol. */
1193 extern gdb::array_view
<const struct symbol_impl
> symbol_impls
;
1195 /* This structure is space critical. See space comments at the top. */
1197 struct symbol
: public general_symbol_info
, public allocate_on_obstack
1200 /* Class-initialization of bitfields is only allowed in C++20. */
1201 : m_domain (UNDEF_DOMAIN
),
1203 m_is_objfile_owned (1),
1207 subclass (SYMBOL_NONE
),
1208 m_artificial (false)
1210 /* We can't use an initializer list for members of a base class, and
1211 general_symbol_info needs to stay a POD type. */
1214 language_specific
.obstack
= nullptr;
1215 m_language
= language_unknown
;
1218 /* GCC 4.8.5 (on CentOS 7) does not correctly compile class-
1219 initialization of unions, so we initialize it manually here. */
1220 owner
.symtab
= nullptr;
1223 symbol (const symbol
&) = default;
1224 symbol
&operator= (const symbol
&) = default;
1226 void set_aclass_index (unsigned int aclass_index
)
1228 m_aclass_index
= aclass_index
;
1231 const symbol_impl
&impl () const
1233 return symbol_impls
[this->m_aclass_index
];
1236 address_class
aclass () const
1238 return this->impl ().aclass
;
1241 domain_enum
domain () const
1246 void set_domain (domain_enum domain
)
1251 bool is_objfile_owned () const
1253 return m_is_objfile_owned
;
1256 void set_is_objfile_owned (bool is_objfile_owned
)
1258 m_is_objfile_owned
= is_objfile_owned
;
1261 bool is_argument () const
1263 return m_is_argument
;
1266 void set_is_argument (bool is_argument
)
1268 m_is_argument
= is_argument
;
1271 bool is_inlined () const
1273 return m_is_inlined
;
1276 void set_is_inlined (bool is_inlined
)
1278 m_is_inlined
= is_inlined
;
1281 bool is_cplus_template_function () const
1283 return this->subclass
== SYMBOL_TEMPLATE
;
1286 struct type
*type () const
1291 void set_type (struct type
*type
)
1296 unsigned short line () const
1301 void set_line (unsigned short line
)
1306 LONGEST
value_longest () const
1308 return m_value
.ivalue
;
1311 void set_value_longest (LONGEST value
)
1313 m_value
.ivalue
= value
;
1316 CORE_ADDR
value_address () const
1318 if (this->maybe_copied
)
1319 return get_symbol_address (this);
1321 return m_value
.address
;
1324 void set_value_address (CORE_ADDR address
)
1326 m_value
.address
= address
;
1329 const gdb_byte
*value_bytes () const
1331 return m_value
.bytes
;
1334 void set_value_bytes (const gdb_byte
*bytes
)
1336 m_value
.bytes
= bytes
;
1339 const common_block
*value_common_block () const
1341 return m_value
.common_block
;
1344 void set_value_common_block (const common_block
*common_block
)
1346 m_value
.common_block
= common_block
;
1349 const block
*value_block () const
1351 return m_value
.block
;
1354 void set_value_block (const block
*block
)
1356 m_value
.block
= block
;
1359 symbol
*value_chain () const
1361 return m_value
.chain
;
1364 void set_value_chain (symbol
*sym
)
1366 m_value
.chain
= sym
;
1369 /* Return true if this symbol was marked as artificial. */
1370 bool is_artificial () const
1372 return m_artificial
;
1375 /* Set the 'artificial' flag on this symbol. */
1376 void set_is_artificial (bool artificial
)
1378 m_artificial
= artificial
;
1381 /* Return the OBJFILE of this symbol. It is an error to call this
1382 if is_objfile_owned is false, which only happens for
1383 architecture-provided types. */
1385 struct objfile
*objfile () const;
1387 /* Return the ARCH of this symbol. */
1389 struct gdbarch
*arch () const;
1391 /* Return the symtab of this symbol. It is an error to call this if
1392 is_objfile_owned is false, which only happens for
1393 architecture-provided types. */
1395 struct symtab
*symtab () const;
1397 /* Set the symtab of this symbol to SYMTAB. It is an error to call
1398 this if is_objfile_owned is false, which only happens for
1399 architecture-provided types. */
1401 void set_symtab (struct symtab
*symtab
);
1403 /* Data type of value */
1405 struct type
*m_type
= nullptr;
1407 /* The owner of this symbol.
1408 Which one to use is defined by symbol.is_objfile_owned. */
1412 /* The symbol table containing this symbol. This is the file associated
1413 with LINE. It can be NULL during symbols read-in but it is never NULL
1414 during normal operation. */
1415 struct symtab
*symtab
;
1417 /* For types defined by the architecture. */
1418 struct gdbarch
*arch
;
1423 ENUM_BITFIELD(domain_enum
) m_domain
: SYMBOL_DOMAIN_BITS
;
1425 /* Address class. This holds an index into the 'symbol_impls'
1426 table. The actual enum address_class value is stored there,
1427 alongside any per-class ops vectors. */
1429 unsigned int m_aclass_index
: SYMBOL_ACLASS_BITS
;
1431 /* If non-zero then symbol is objfile-owned, use owner.symtab.
1432 Otherwise symbol is arch-owned, use owner.arch. */
1434 unsigned int m_is_objfile_owned
: 1;
1436 /* Whether this is an argument. */
1438 unsigned m_is_argument
: 1;
1440 /* Whether this is an inlined function (class LOC_BLOCK only). */
1441 unsigned m_is_inlined
: 1;
1443 /* For LOC_STATIC only, if this is set, then the symbol might be
1444 subject to copy relocation. In this case, a minimal symbol
1445 matching the symbol's linkage name is first looked for in the
1446 main objfile. If found, then that address is used; otherwise the
1447 address in this symbol is used. */
1449 unsigned maybe_copied
: 1;
1451 /* The concrete type of this symbol. */
1453 ENUM_BITFIELD (symbol_subclass_kind
) subclass
: 2;
1455 /* Whether this symbol is artificial. */
1457 bool m_artificial
: 1;
1459 /* Line number of this symbol's definition, except for inlined
1460 functions. For an inlined function (class LOC_BLOCK and
1461 SYMBOL_INLINED set) this is the line number of the function's call
1462 site. Inlined function symbols are not definitions, and they are
1463 never found by symbol table lookup.
1464 If this symbol is arch-owned, LINE shall be zero.
1466 FIXME: Should we really make the assumption that nobody will try
1467 to debug files longer than 64K lines? What about machine
1468 generated programs? */
1470 unsigned short m_line
= 0;
1472 /* An arbitrary data pointer, allowing symbol readers to record
1473 additional information on a per-symbol basis. Note that this data
1474 must be allocated using the same obstack as the symbol itself. */
1475 /* So far it is only used by:
1476 LOC_COMPUTED: to find the location information
1477 LOC_BLOCK (DWARF2 function): information used internally by the
1478 DWARF 2 code --- specifically, the location expression for the frame
1479 base for this function. */
1480 /* FIXME drow/2003-02-21: For the LOC_BLOCK case, it might be better
1481 to add a magic symbol to the block containing this information,
1482 or to have a generic debug info annotation slot for symbols. */
1484 void *aux_value
= nullptr;
1486 struct symbol
*hash_next
= nullptr;
1489 /* Several lookup functions return both a symbol and the block in which the
1490 symbol is found. This structure is used in these cases. */
1494 /* The symbol that was found, or NULL if no symbol was found. */
1495 struct symbol
*symbol
;
1497 /* If SYMBOL is not NULL, then this is the block in which the symbol is
1499 const struct block
*block
;
1502 /* Note: There is no accessor macro for symbol.owner because it is
1505 #define SYMBOL_COMPUTED_OPS(symbol) ((symbol)->impl ().ops_computed)
1506 #define SYMBOL_BLOCK_OPS(symbol) ((symbol)->impl ().ops_block)
1507 #define SYMBOL_REGISTER_OPS(symbol) ((symbol)->impl ().ops_register)
1508 #define SYMBOL_LOCATION_BATON(symbol) (symbol)->aux_value
1510 extern int register_symbol_computed_impl (enum address_class
,
1511 const struct symbol_computed_ops
*);
1513 extern int register_symbol_block_impl (enum address_class aclass
,
1514 const struct symbol_block_ops
*ops
);
1516 extern int register_symbol_register_impl (enum address_class
,
1517 const struct symbol_register_ops
*);
1519 /* An instance of this type is used to represent a C++ template
1520 function. A symbol is really of this type iff
1521 symbol::is_cplus_template_function is true. */
1523 struct template_symbol
: public symbol
1525 /* The number of template arguments. */
1526 int n_template_arguments
= 0;
1528 /* The template arguments. This is an array with
1529 N_TEMPLATE_ARGUMENTS elements. */
1530 struct symbol
**template_arguments
= nullptr;
1533 /* A symbol that represents a Rust virtual table object. */
1535 struct rust_vtable_symbol
: public symbol
1537 /* The concrete type for which this vtable was created; that is, in
1538 "impl Trait for Type", this is "Type". */
1539 struct type
*concrete_type
= nullptr;
1543 /* Each item represents a line-->pc (or the reverse) mapping. This is
1544 somewhat more wasteful of space than one might wish, but since only
1545 the files which are actually debugged are read in to core, we don't
1546 waste much space. */
1548 struct linetable_entry
1550 /* The line number for this entry. */
1553 /* True if this PC is a good location to place a breakpoint for LINE. */
1554 unsigned is_stmt
: 1;
1556 /* True if this location is a good location to place a breakpoint after a
1557 function prologue. */
1558 bool prologue_end
: 1;
1560 /* The address for this entry. */
1564 /* The order of entries in the linetable is significant. They should
1565 be sorted by increasing values of the pc field. If there is more than
1566 one entry for a given pc, then I'm not sure what should happen (and
1567 I not sure whether we currently handle it the best way).
1569 Example: a C for statement generally looks like this
1571 10 0x100 - for the init/test part of a for stmt.
1574 10 0x400 - for the increment part of a for stmt.
1576 If an entry has a line number of zero, it marks the start of a PC
1577 range for which no line number information is available. It is
1578 acceptable, though wasteful of table space, for such a range to be
1585 /* Actually NITEMS elements. If you don't like this use of the
1586 `struct hack', you can shove it up your ANSI (seriously, if the
1587 committee tells us how to do it, we can probably go along). */
1588 struct linetable_entry item
[1];
1591 /* How to relocate the symbols from each section in a symbol file.
1592 The ordering and meaning of the offsets is file-type-dependent;
1593 typically it is indexed by section numbers or symbol types or
1594 something like that. */
1596 typedef std::vector
<CORE_ADDR
> section_offsets
;
1598 /* Each source file or header is represented by a struct symtab.
1599 The name "symtab" is historical, another name for it is "filetab".
1600 These objects are chained through the `next' field. */
1604 struct compunit_symtab
*compunit () const
1609 void set_compunit (struct compunit_symtab
*compunit
)
1611 m_compunit
= compunit
;
1614 struct linetable
*linetable () const
1619 void set_linetable (struct linetable
*linetable
)
1621 m_linetable
= linetable
;
1624 enum language
language () const
1629 void set_language (enum language language
)
1631 m_language
= language
;
1634 /* Unordered chain of all filetabs in the compunit, with the exception
1635 that the "main" source file is the first entry in the list. */
1637 struct symtab
*next
;
1639 /* Backlink to containing compunit symtab. */
1641 struct compunit_symtab
*m_compunit
;
1643 /* Table mapping core addresses to line numbers for this file.
1644 Can be NULL if none. Never shared between different symtabs. */
1646 struct linetable
*m_linetable
;
1648 /* Name of this source file, in a form appropriate to print to the user.
1650 This pointer is never nullptr. */
1652 const char *filename
;
1654 /* Filename for this source file, used as an identifier to link with
1655 related objects such as associated macro_source_file objects. It must
1656 therefore match the name of any macro_source_file object created for this
1657 source file. The value can be the same as FILENAME if it is known to
1658 follow that rule, or another form of the same file name, this is up to
1659 the specific debug info reader.
1661 This pointer is never nullptr.*/
1662 const char *filename_for_id
;
1664 /* Language of this source file. */
1666 enum language m_language
;
1668 /* Full name of file as found by searching the source path.
1669 NULL if not yet known. */
1674 /* A range adapter to allowing iterating over all the file tables in a list. */
1676 using symtab_range
= next_range
<symtab
>;
1678 /* Compunit symtabs contain the actual "symbol table", aka blockvector, as well
1679 as the list of all source files (what gdb has historically associated with
1681 Additional information is recorded here that is common to all symtabs in a
1682 compilation unit (DWARF or otherwise).
1685 For the case of a program built out of these files:
1694 This is recorded as:
1696 objfile -> foo.c(cu) -> bar.c(cu) -> NULL
1710 where "foo.c(cu)" and "bar.c(cu)" are struct compunit_symtab objects,
1711 and the files foo.c, etc. are struct symtab objects. */
1713 struct compunit_symtab
1715 struct objfile
*objfile () const
1720 void set_objfile (struct objfile
*objfile
)
1722 m_objfile
= objfile
;
1725 symtab_range
filetabs () const
1727 return symtab_range (m_filetabs
);
1730 void add_filetab (symtab
*filetab
)
1732 if (m_filetabs
== nullptr)
1734 m_filetabs
= filetab
;
1735 m_last_filetab
= filetab
;
1739 m_last_filetab
->next
= filetab
;
1740 m_last_filetab
= filetab
;
1744 const char *debugformat () const
1746 return m_debugformat
;
1749 void set_debugformat (const char *debugformat
)
1751 m_debugformat
= debugformat
;
1754 const char *producer () const
1759 void set_producer (const char *producer
)
1761 m_producer
= producer
;
1764 const char *dirname () const
1769 void set_dirname (const char *dirname
)
1771 m_dirname
= dirname
;
1774 struct blockvector
*blockvector ()
1776 return m_blockvector
;
1779 const struct blockvector
*blockvector () const
1781 return m_blockvector
;
1784 void set_blockvector (struct blockvector
*blockvector
)
1786 m_blockvector
= blockvector
;
1789 bool locations_valid () const
1791 return m_locations_valid
;
1794 void set_locations_valid (bool locations_valid
)
1796 m_locations_valid
= locations_valid
;
1799 bool epilogue_unwind_valid () const
1801 return m_epilogue_unwind_valid
;
1804 void set_epilogue_unwind_valid (bool epilogue_unwind_valid
)
1806 m_epilogue_unwind_valid
= epilogue_unwind_valid
;
1809 struct macro_table
*macro_table () const
1811 return m_macro_table
;
1814 void set_macro_table (struct macro_table
*macro_table
)
1816 m_macro_table
= macro_table
;
1819 /* Make PRIMARY_FILETAB the primary filetab of this compunit symtab.
1821 PRIMARY_FILETAB must already be a filetab of this compunit symtab. */
1823 void set_primary_filetab (symtab
*primary_filetab
);
1825 /* Return the primary filetab of the compunit. */
1826 symtab
*primary_filetab () const;
1828 /* Set m_call_site_htab. */
1829 void set_call_site_htab (htab_t call_site_htab
);
1831 /* Find call_site info for PC. */
1832 call_site
*find_call_site (CORE_ADDR pc
) const;
1834 /* Return the language of this compunit_symtab. */
1835 enum language
language () const;
1837 /* Unordered chain of all compunit symtabs of this objfile. */
1838 struct compunit_symtab
*next
;
1840 /* Object file from which this symtab information was read. */
1841 struct objfile
*m_objfile
;
1843 /* Name of the symtab.
1844 This is *not* intended to be a usable filename, and is
1845 for debugging purposes only. */
1848 /* Unordered list of file symtabs, except that by convention the "main"
1849 source file (e.g., .c, .cc) is guaranteed to be first.
1850 Each symtab is a file, either the "main" source file (e.g., .c, .cc)
1851 or header (e.g., .h). */
1854 /* Last entry in FILETABS list.
1855 Subfiles are added to the end of the list so they accumulate in order,
1856 with the main source subfile living at the front.
1857 The main reason is so that the main source file symtab is at the head
1858 of the list, and the rest appear in order for debugging convenience. */
1859 symtab
*m_last_filetab
;
1861 /* Non-NULL string that identifies the format of the debugging information,
1862 such as "stabs", "dwarf 1", "dwarf 2", "coff", etc. This is mostly useful
1863 for automated testing of gdb but may also be information that is
1864 useful to the user. */
1865 const char *m_debugformat
;
1867 /* String of producer version information, or NULL if we don't know. */
1868 const char *m_producer
;
1870 /* Directory in which it was compiled, or NULL if we don't know. */
1871 const char *m_dirname
;
1873 /* List of all symbol scope blocks for this symtab. It is shared among
1874 all symtabs in a given compilation unit. */
1875 struct blockvector
*m_blockvector
;
1877 /* Symtab has been compiled with both optimizations and debug info so that
1878 GDB may stop skipping prologues as variables locations are valid already
1879 at function entry points. */
1880 unsigned int m_locations_valid
: 1;
1882 /* DWARF unwinder for this CU is valid even for epilogues (PC at the return
1883 instruction). This is supported by GCC since 4.5.0. */
1884 unsigned int m_epilogue_unwind_valid
: 1;
1886 /* struct call_site entries for this compilation unit or NULL. */
1887 htab_t m_call_site_htab
;
1889 /* The macro table for this symtab. Like the blockvector, this
1890 is shared between different symtabs in a given compilation unit.
1891 It's debatable whether it *should* be shared among all the symtabs in
1892 the given compilation unit, but it currently is. */
1893 struct macro_table
*m_macro_table
;
1895 /* If non-NULL, then this points to a NULL-terminated vector of
1896 included compunits. When searching the static or global
1897 block of this compunit, the corresponding block of all
1898 included compunits will also be searched. Note that this
1899 list must be flattened -- the symbol reader is responsible for
1900 ensuring that this vector contains the transitive closure of all
1901 included compunits. */
1902 struct compunit_symtab
**includes
;
1904 /* If this is an included compunit, this points to one includer
1905 of the table. This user is considered the canonical compunit
1906 containing this one. An included compunit may itself be
1907 included by another. */
1908 struct compunit_symtab
*user
;
1911 using compunit_symtab_range
= next_range
<compunit_symtab
>;
1913 /* Return true if this symtab is the "main" symtab of its compunit_symtab. */
1916 is_main_symtab_of_compunit_symtab (struct symtab
*symtab
)
1918 return symtab
== symtab
->compunit ()->primary_filetab ();
1922 /* The virtual function table is now an array of structures which have the
1923 form { int16 offset, delta; void *pfn; }.
1925 In normal virtual function tables, OFFSET is unused.
1926 DELTA is the amount which is added to the apparent object's base
1927 address in order to point to the actual object to which the
1928 virtual function should be applied.
1929 PFN is a pointer to the virtual function.
1931 Note that this macro is g++ specific (FIXME). */
1933 #define VTBL_FNADDR_OFFSET 2
1935 /* External variables and functions for the objects described above. */
1937 /* True if we are nested inside psymtab_to_symtab. */
1939 extern int currently_reading_symtab
;
1941 /* symtab.c lookup functions */
1943 extern const char multiple_symbols_ask
[];
1944 extern const char multiple_symbols_all
[];
1945 extern const char multiple_symbols_cancel
[];
1947 const char *multiple_symbols_select_mode (void);
1949 bool symbol_matches_domain (enum language symbol_language
,
1950 domain_enum symbol_domain
,
1951 domain_enum domain
);
1953 /* lookup a symbol table by source file name. */
1955 extern struct symtab
*lookup_symtab (const char *);
1957 /* An object of this type is passed as the 'is_a_field_of_this'
1958 argument to lookup_symbol and lookup_symbol_in_language. */
1960 struct field_of_this_result
1962 /* The type in which the field was found. If this is NULL then the
1963 symbol was not found in 'this'. If non-NULL, then one of the
1964 other fields will be non-NULL as well. */
1968 /* If the symbol was found as an ordinary field of 'this', then this
1969 is non-NULL and points to the particular field. */
1971 struct field
*field
;
1973 /* If the symbol was found as a function field of 'this', then this
1974 is non-NULL and points to the particular field. */
1976 struct fn_fieldlist
*fn_field
;
1979 /* Find the definition for a specified symbol name NAME
1980 in domain DOMAIN in language LANGUAGE, visible from lexical block BLOCK
1981 if non-NULL or from global/static blocks if BLOCK is NULL.
1982 Returns the struct symbol pointer, or NULL if no symbol is found.
1983 C++: if IS_A_FIELD_OF_THIS is non-NULL on entry, check to see if
1984 NAME is a field of the current implied argument `this'. If so fill in the
1985 fields of IS_A_FIELD_OF_THIS, otherwise the fields are set to NULL.
1986 The symbol's section is fixed up if necessary. */
1988 extern struct block_symbol
1989 lookup_symbol_in_language (const char *,
1990 const struct block
*,
1993 struct field_of_this_result
*);
1995 /* Same as lookup_symbol_in_language, but using the current language. */
1997 extern struct block_symbol
lookup_symbol (const char *,
1998 const struct block
*,
2000 struct field_of_this_result
*);
2002 /* Find the definition for a specified symbol search name in domain
2003 DOMAIN, visible from lexical block BLOCK if non-NULL or from
2004 global/static blocks if BLOCK is NULL. The passed-in search name
2005 should not come from the user; instead it should already be a
2006 search name as retrieved from a search_name () call. See definition of
2007 symbol_name_match_type::SEARCH_NAME. Returns the struct symbol
2008 pointer, or NULL if no symbol is found. The symbol's section is
2009 fixed up if necessary. */
2011 extern struct block_symbol
lookup_symbol_search_name (const char *search_name
,
2012 const struct block
*block
,
2013 domain_enum domain
);
2015 /* Some helper functions for languages that need to write their own
2016 lookup_symbol_nonlocal functions. */
2018 /* Lookup a symbol in the static block associated to BLOCK, if there
2019 is one; do nothing if BLOCK is NULL or a global block.
2020 Upon success fixes up the symbol's section if necessary. */
2022 extern struct block_symbol
2023 lookup_symbol_in_static_block (const char *name
,
2024 const struct block
*block
,
2025 const domain_enum domain
);
2027 /* Search all static file-level symbols for NAME from DOMAIN.
2028 Upon success fixes up the symbol's section if necessary. */
2030 extern struct block_symbol
lookup_static_symbol (const char *name
,
2031 const domain_enum domain
);
2033 /* Lookup a symbol in all files' global blocks.
2035 If BLOCK is non-NULL then it is used for two things:
2036 1) If a target-specific lookup routine for libraries exists, then use the
2037 routine for the objfile of BLOCK, and
2038 2) The objfile of BLOCK is used to assist in determining the search order
2039 if the target requires it.
2040 See gdbarch_iterate_over_objfiles_in_search_order.
2042 Upon success fixes up the symbol's section if necessary. */
2044 extern struct block_symbol
2045 lookup_global_symbol (const char *name
,
2046 const struct block
*block
,
2047 const domain_enum domain
);
2049 /* Lookup a symbol in block BLOCK.
2050 Upon success fixes up the symbol's section if necessary. */
2052 extern struct symbol
*
2053 lookup_symbol_in_block (const char *name
,
2054 symbol_name_match_type match_type
,
2055 const struct block
*block
,
2056 const domain_enum domain
);
2058 /* Look up the `this' symbol for LANG in BLOCK. Return the symbol if
2059 found, or NULL if not found. */
2061 extern struct block_symbol
2062 lookup_language_this (const struct language_defn
*lang
,
2063 const struct block
*block
);
2065 /* Lookup a [struct, union, enum] by name, within a specified block. */
2067 extern struct type
*lookup_struct (const char *, const struct block
*);
2069 extern struct type
*lookup_union (const char *, const struct block
*);
2071 extern struct type
*lookup_enum (const char *, const struct block
*);
2073 /* from blockframe.c: */
2075 /* lookup the function symbol corresponding to the address. The
2076 return value will not be an inlined function; the containing
2077 function will be returned instead. */
2079 extern struct symbol
*find_pc_function (CORE_ADDR
);
2081 /* lookup the function corresponding to the address and section. The
2082 return value will not be an inlined function; the containing
2083 function will be returned instead. */
2085 extern struct symbol
*find_pc_sect_function (CORE_ADDR
, struct obj_section
*);
2087 /* lookup the function symbol corresponding to the address and
2088 section. The return value will be the closest enclosing function,
2089 which might be an inline function. */
2091 extern struct symbol
*find_pc_sect_containing_function
2092 (CORE_ADDR pc
, struct obj_section
*section
);
2094 /* Find the symbol at the given address. Returns NULL if no symbol
2095 found. Only exact matches for ADDRESS are considered. */
2097 extern struct symbol
*find_symbol_at_address (CORE_ADDR
);
2099 /* Finds the "function" (text symbol) that is smaller than PC but
2100 greatest of all of the potential text symbols in SECTION. Sets
2101 *NAME and/or *ADDRESS conditionally if that pointer is non-null.
2102 If ENDADDR is non-null, then set *ENDADDR to be the end of the
2103 function (exclusive). If the optional parameter BLOCK is non-null,
2104 then set *BLOCK to the address of the block corresponding to the
2105 function symbol, if such a symbol could be found during the lookup;
2106 nullptr is used as a return value for *BLOCK if no block is found.
2107 This function either succeeds or fails (not halfway succeeds). If
2108 it succeeds, it sets *NAME, *ADDRESS, and *ENDADDR to real
2109 information and returns true. If it fails, it sets *NAME, *ADDRESS
2110 and *ENDADDR to zero and returns false.
2112 If the function in question occupies non-contiguous ranges,
2113 *ADDRESS and *ENDADDR are (subject to the conditions noted above) set
2114 to the start and end of the range in which PC is found. Thus
2115 *ADDRESS <= PC < *ENDADDR with no intervening gaps (in which ranges
2116 from other functions might be found).
2118 This property allows find_pc_partial_function to be used (as it had
2119 been prior to the introduction of non-contiguous range support) by
2120 various tdep files for finding a start address and limit address
2121 for prologue analysis. This still isn't ideal, however, because we
2122 probably shouldn't be doing prologue analysis (in which
2123 instructions are scanned to determine frame size and stack layout)
2124 for any range that doesn't contain the entry pc. Moreover, a good
2125 argument can be made that prologue analysis ought to be performed
2126 starting from the entry pc even when PC is within some other range.
2127 This might suggest that *ADDRESS and *ENDADDR ought to be set to the
2128 limits of the entry pc range, but that will cause the
2129 *ADDRESS <= PC < *ENDADDR condition to be violated; many of the
2130 callers of find_pc_partial_function expect this condition to hold.
2132 Callers which require the start and/or end addresses for the range
2133 containing the entry pc should instead call
2134 find_function_entry_range_from_pc. */
2136 extern bool find_pc_partial_function (CORE_ADDR pc
, const char **name
,
2137 CORE_ADDR
*address
, CORE_ADDR
*endaddr
,
2138 const struct block
**block
= nullptr);
2140 /* Like find_pc_partial_function, above, but returns the underlying
2141 general_symbol_info (rather than the name) as an out parameter. */
2143 extern bool find_pc_partial_function_sym
2144 (CORE_ADDR pc
, const general_symbol_info
**sym
,
2145 CORE_ADDR
*address
, CORE_ADDR
*endaddr
,
2146 const struct block
**block
= nullptr);
2148 /* Like find_pc_partial_function, above, but *ADDRESS and *ENDADDR are
2149 set to start and end addresses of the range containing the entry pc.
2151 Note that it is not necessarily the case that (for non-NULL ADDRESS
2152 and ENDADDR arguments) the *ADDRESS <= PC < *ENDADDR condition will
2155 See comment for find_pc_partial_function, above, for further
2158 extern bool find_function_entry_range_from_pc (CORE_ADDR pc
,
2161 CORE_ADDR
*endaddr
);
2163 /* Return the type of a function with its first instruction exactly at
2164 the PC address. Return NULL otherwise. */
2166 extern struct type
*find_function_type (CORE_ADDR pc
);
2168 /* See if we can figure out the function's actual type from the type
2169 that the resolver returns. RESOLVER_FUNADDR is the address of the
2172 extern struct type
*find_gnu_ifunc_target_type (CORE_ADDR resolver_funaddr
);
2174 /* Find the GNU ifunc minimal symbol that matches SYM. */
2175 extern bound_minimal_symbol
find_gnu_ifunc (const symbol
*sym
);
2177 extern void clear_pc_function_cache (void);
2179 /* Expand symtab containing PC, SECTION if not already expanded. */
2181 extern void expand_symtab_containing_pc (CORE_ADDR
, struct obj_section
*);
2183 /* lookup full symbol table by address. */
2185 extern struct compunit_symtab
*find_pc_compunit_symtab (CORE_ADDR
);
2187 /* lookup full symbol table by address and section. */
2189 extern struct compunit_symtab
*
2190 find_pc_sect_compunit_symtab (CORE_ADDR
, struct obj_section
*);
2192 extern bool find_pc_line_pc_range (CORE_ADDR
, CORE_ADDR
*, CORE_ADDR
*);
2194 extern void reread_symbols (int from_tty
);
2196 /* Look up a type named NAME in STRUCT_DOMAIN in the current language.
2197 The type returned must not be opaque -- i.e., must have at least one field
2200 extern struct type
*lookup_transparent_type (const char *);
2202 extern struct type
*basic_lookup_transparent_type (const char *);
2204 /* Macro for name of symbol to indicate a file compiled with gcc. */
2205 #ifndef GCC_COMPILED_FLAG_SYMBOL
2206 #define GCC_COMPILED_FLAG_SYMBOL "gcc_compiled."
2209 /* Macro for name of symbol to indicate a file compiled with gcc2. */
2210 #ifndef GCC2_COMPILED_FLAG_SYMBOL
2211 #define GCC2_COMPILED_FLAG_SYMBOL "gcc2_compiled."
2214 extern bool in_gnu_ifunc_stub (CORE_ADDR pc
);
2216 /* Functions for resolving STT_GNU_IFUNC symbols which are implemented only
2217 for ELF symbol files. */
2219 struct gnu_ifunc_fns
2221 /* See elf_gnu_ifunc_resolve_addr for its real implementation. */
2222 CORE_ADDR (*gnu_ifunc_resolve_addr
) (struct gdbarch
*gdbarch
, CORE_ADDR pc
);
2224 /* See elf_gnu_ifunc_resolve_name for its real implementation. */
2225 bool (*gnu_ifunc_resolve_name
) (const char *function_name
,
2226 CORE_ADDR
*function_address_p
);
2228 /* See elf_gnu_ifunc_resolver_stop for its real implementation. */
2229 void (*gnu_ifunc_resolver_stop
) (code_breakpoint
*b
);
2231 /* See elf_gnu_ifunc_resolver_return_stop for its real implementation. */
2232 void (*gnu_ifunc_resolver_return_stop
) (code_breakpoint
*b
);
2235 #define gnu_ifunc_resolve_addr gnu_ifunc_fns_p->gnu_ifunc_resolve_addr
2236 #define gnu_ifunc_resolve_name gnu_ifunc_fns_p->gnu_ifunc_resolve_name
2237 #define gnu_ifunc_resolver_stop gnu_ifunc_fns_p->gnu_ifunc_resolver_stop
2238 #define gnu_ifunc_resolver_return_stop \
2239 gnu_ifunc_fns_p->gnu_ifunc_resolver_return_stop
2241 extern const struct gnu_ifunc_fns
*gnu_ifunc_fns_p
;
2243 extern CORE_ADDR
find_solib_trampoline_target (frame_info_ptr
, CORE_ADDR
);
2245 struct symtab_and_line
2247 /* The program space of this sal. */
2248 struct program_space
*pspace
= NULL
;
2250 struct symtab
*symtab
= NULL
;
2251 struct symbol
*symbol
= NULL
;
2252 struct obj_section
*section
= NULL
;
2253 struct minimal_symbol
*msymbol
= NULL
;
2254 /* Line number. Line numbers start at 1 and proceed through symtab->nlines.
2255 0 is never a valid line number; it is used to indicate that line number
2256 information is not available. */
2261 bool explicit_pc
= false;
2262 bool explicit_line
= false;
2264 /* If the line number information is valid, then this indicates if this
2265 line table entry had the is-stmt flag set or not. */
2266 bool is_stmt
= false;
2268 /* The probe associated with this symtab_and_line. */
2270 /* If PROBE is not NULL, then this is the objfile in which the probe
2272 struct objfile
*objfile
= NULL
;
2277 /* Given a pc value, return line number it is in. Second arg nonzero means
2278 if pc is on the boundary use the previous statement's line number. */
2280 extern struct symtab_and_line
find_pc_line (CORE_ADDR
, int);
2282 /* Same function, but specify a section as well as an address. */
2284 extern struct symtab_and_line
find_pc_sect_line (CORE_ADDR
,
2285 struct obj_section
*, int);
2287 /* Wrapper around find_pc_line to just return the symtab. */
2289 extern struct symtab
*find_pc_line_symtab (CORE_ADDR
);
2291 /* Given a symtab and line number, return the pc there. */
2293 extern bool find_line_pc (struct symtab
*, int, CORE_ADDR
*);
2295 extern bool find_line_pc_range (struct symtab_and_line
, CORE_ADDR
*,
2298 extern void resolve_sal_pc (struct symtab_and_line
*);
2302 extern void clear_solib (void);
2304 /* The reason we're calling into a completion match list collector
2306 enum class complete_symbol_mode
2308 /* Completing an expression. */
2311 /* Completing a linespec. */
2315 extern void default_collect_symbol_completion_matches_break_on
2316 (completion_tracker
&tracker
,
2317 complete_symbol_mode mode
,
2318 symbol_name_match_type name_match_type
,
2319 const char *text
, const char *word
, const char *break_on
,
2320 enum type_code code
);
2321 extern void collect_symbol_completion_matches
2322 (completion_tracker
&tracker
,
2323 complete_symbol_mode mode
,
2324 symbol_name_match_type name_match_type
,
2325 const char *, const char *);
2326 extern void collect_symbol_completion_matches_type (completion_tracker
&tracker
,
2327 const char *, const char *,
2330 extern void collect_file_symbol_completion_matches
2331 (completion_tracker
&tracker
,
2332 complete_symbol_mode
,
2333 symbol_name_match_type name_match_type
,
2334 const char *, const char *, const char *);
2336 extern completion_list
2337 make_source_files_completion_list (const char *, const char *);
2339 /* Return whether SYM is a function/method, as opposed to a data symbol. */
2341 extern bool symbol_is_function_or_method (symbol
*sym
);
2343 /* Return whether MSYMBOL is a function/method, as opposed to a data
2346 extern bool symbol_is_function_or_method (minimal_symbol
*msymbol
);
2348 /* Return whether SYM should be skipped in completion mode MODE. In
2349 linespec mode, we're only interested in functions/methods. */
2351 template<typename Symbol
>
2353 completion_skip_symbol (complete_symbol_mode mode
, Symbol
*sym
)
2355 return (mode
== complete_symbol_mode::LINESPEC
2356 && !symbol_is_function_or_method (sym
));
2361 bool matching_obj_sections (struct obj_section
*, struct obj_section
*);
2363 extern struct symtab
*find_line_symtab (struct symtab
*, int, int *, bool *);
2365 /* Given a function symbol SYM, find the symtab and line for the start
2366 of the function. If FUNFIRSTLINE is true, we want the first line
2367 of real code inside the function. */
2368 extern symtab_and_line
find_function_start_sal (symbol
*sym
, bool
2371 /* Same, but start with a function address/section instead of a
2373 extern symtab_and_line
find_function_start_sal (CORE_ADDR func_addr
,
2374 obj_section
*section
,
2377 extern void skip_prologue_sal (struct symtab_and_line
*);
2381 extern CORE_ADDR
skip_prologue_using_sal (struct gdbarch
*gdbarch
,
2382 CORE_ADDR func_addr
);
2384 extern struct symbol
*fixup_symbol_section (struct symbol
*,
2387 /* If MSYMBOL is an text symbol, look for a function debug symbol with
2388 the same address. Returns NULL if not found. This is necessary in
2389 case a function is an alias to some other function, because debug
2390 information is only emitted for the alias target function's
2391 definition, not for the alias. */
2392 extern symbol
*find_function_alias_target (bound_minimal_symbol msymbol
);
2394 /* Symbol searching */
2396 /* When using the symbol_searcher struct to search for symbols, a vector of
2397 the following structs is returned. */
2398 struct symbol_search
2400 symbol_search (int block_
, struct symbol
*symbol_
)
2404 msymbol
.minsym
= nullptr;
2405 msymbol
.objfile
= nullptr;
2408 symbol_search (int block_
, struct minimal_symbol
*minsym
,
2409 struct objfile
*objfile
)
2413 msymbol
.minsym
= minsym
;
2414 msymbol
.objfile
= objfile
;
2417 bool operator< (const symbol_search
&other
) const
2419 return compare_search_syms (*this, other
) < 0;
2422 bool operator== (const symbol_search
&other
) const
2424 return compare_search_syms (*this, other
) == 0;
2427 /* The block in which the match was found. Could be, for example,
2428 STATIC_BLOCK or GLOBAL_BLOCK. */
2431 /* Information describing what was found.
2433 If symbol is NOT NULL, then information was found for this match. */
2434 struct symbol
*symbol
;
2436 /* If msymbol is non-null, then a match was made on something for
2437 which only minimal_symbols exist. */
2438 struct bound_minimal_symbol msymbol
;
2442 static int compare_search_syms (const symbol_search
&sym_a
,
2443 const symbol_search
&sym_b
);
2446 /* In order to search for global symbols of a particular kind matching
2447 particular regular expressions, create an instance of this structure and
2448 call the SEARCH member function. */
2449 class global_symbol_searcher
2454 global_symbol_searcher (enum search_domain kind
,
2455 const char *symbol_name_regexp
)
2457 m_symbol_name_regexp (symbol_name_regexp
)
2459 /* The symbol searching is designed to only find one kind of thing. */
2460 gdb_assert (m_kind
!= ALL_DOMAIN
);
2463 /* Set the optional regexp that matches against the symbol type. */
2464 void set_symbol_type_regexp (const char *regexp
)
2466 m_symbol_type_regexp
= regexp
;
2469 /* Set the flag to exclude minsyms from the search results. */
2470 void set_exclude_minsyms (bool exclude_minsyms
)
2472 m_exclude_minsyms
= exclude_minsyms
;
2475 /* Set the maximum number of search results to be returned. */
2476 void set_max_search_results (size_t max_search_results
)
2478 m_max_search_results
= max_search_results
;
2481 /* Search the symbols from all objfiles in the current program space
2482 looking for matches as defined by the current state of this object.
2484 Within each file the results are sorted locally; each symtab's global
2485 and static blocks are separately alphabetized. Duplicate entries are
2487 std::vector
<symbol_search
> search () const;
2489 /* The set of source files to search in for matching symbols. This is
2490 currently public so that it can be populated after this object has
2491 been constructed. */
2492 std::vector
<const char *> filenames
;
2495 /* The kind of symbols are we searching for.
2496 VARIABLES_DOMAIN - Search all symbols, excluding functions, type
2497 names, and constants (enums).
2498 FUNCTIONS_DOMAIN - Search all functions..
2499 TYPES_DOMAIN - Search all type names.
2500 MODULES_DOMAIN - Search all Fortran modules.
2501 ALL_DOMAIN - Not valid for this function. */
2502 enum search_domain m_kind
;
2504 /* Regular expression to match against the symbol name. */
2505 const char *m_symbol_name_regexp
= nullptr;
2507 /* Regular expression to match against the symbol type. */
2508 const char *m_symbol_type_regexp
= nullptr;
2510 /* When this flag is false then minsyms that match M_SYMBOL_REGEXP will
2511 be included in the results, otherwise they are excluded. */
2512 bool m_exclude_minsyms
= false;
2514 /* Maximum number of search results. We currently impose a hard limit
2515 of SIZE_MAX, there is no "unlimited". */
2516 size_t m_max_search_results
= SIZE_MAX
;
2518 /* Expand symtabs in OBJFILE that match PREG, are of type M_KIND. Return
2519 true if any msymbols were seen that we should later consider adding to
2520 the results list. */
2521 bool expand_symtabs (objfile
*objfile
,
2522 const gdb::optional
<compiled_regex
> &preg
) const;
2524 /* Add symbols from symtabs in OBJFILE that match PREG, and TREG, and are
2525 of type M_KIND, to the results set RESULTS_SET. Return false if we
2526 stop adding results early due to having already found too many results
2527 (based on M_MAX_SEARCH_RESULTS limit), otherwise return true.
2528 Returning true does not indicate that any results were added, just
2529 that we didn't _not_ add a result due to reaching MAX_SEARCH_RESULTS. */
2530 bool add_matching_symbols (objfile
*objfile
,
2531 const gdb::optional
<compiled_regex
> &preg
,
2532 const gdb::optional
<compiled_regex
> &treg
,
2533 std::set
<symbol_search
> *result_set
) const;
2535 /* Add msymbols from OBJFILE that match PREG and M_KIND, to the results
2536 vector RESULTS. Return false if we stop adding results early due to
2537 having already found too many results (based on max search results
2538 limit M_MAX_SEARCH_RESULTS), otherwise return true. Returning true
2539 does not indicate that any results were added, just that we didn't
2540 _not_ add a result due to reaching MAX_SEARCH_RESULTS. */
2541 bool add_matching_msymbols (objfile
*objfile
,
2542 const gdb::optional
<compiled_regex
> &preg
,
2543 std::vector
<symbol_search
> *results
) const;
2545 /* Return true if MSYMBOL is of type KIND. */
2546 static bool is_suitable_msymbol (const enum search_domain kind
,
2547 const minimal_symbol
*msymbol
);
2550 /* When searching for Fortran symbols within modules (functions/variables)
2551 we return a vector of this type. The first item in the pair is the
2552 module symbol, and the second item is the symbol for the function or
2553 variable we found. */
2554 typedef std::pair
<symbol_search
, symbol_search
> module_symbol_search
;
2556 /* Searches the symbols to find function and variables symbols (depending
2557 on KIND) within Fortran modules. The MODULE_REGEXP matches against the
2558 name of the module, REGEXP matches against the name of the symbol within
2559 the module, and TYPE_REGEXP matches against the type of the symbol
2560 within the module. */
2561 extern std::vector
<module_symbol_search
> search_module_symbols
2562 (const char *module_regexp
, const char *regexp
,
2563 const char *type_regexp
, search_domain kind
);
2565 /* Convert a global or static symbol SYM (based on BLOCK, which should be
2566 either GLOBAL_BLOCK or STATIC_BLOCK) into a string for use in 'info'
2567 type commands (e.g. 'info variables', 'info functions', etc). KIND is
2568 the type of symbol that was searched for which gave us SYM. */
2570 extern std::string
symbol_to_info_string (struct symbol
*sym
, int block
,
2571 enum search_domain kind
);
2573 extern bool treg_matches_sym_type_name (const compiled_regex
&treg
,
2574 const struct symbol
*sym
);
2576 /* The name of the ``main'' function. */
2577 extern const char *main_name ();
2578 extern enum language
main_language (void);
2580 /* Lookup symbol NAME from DOMAIN in MAIN_OBJFILE's global or static blocks,
2581 as specified by BLOCK_INDEX.
2582 This searches MAIN_OBJFILE as well as any associated separate debug info
2583 objfiles of MAIN_OBJFILE.
2584 BLOCK_INDEX can be GLOBAL_BLOCK or STATIC_BLOCK.
2585 Upon success fixes up the symbol's section if necessary. */
2587 extern struct block_symbol
2588 lookup_global_symbol_from_objfile (struct objfile
*main_objfile
,
2589 enum block_enum block_index
,
2591 const domain_enum domain
);
2593 /* Return 1 if the supplied producer string matches the ARM RealView
2594 compiler (armcc). */
2595 bool producer_is_realview (const char *producer
);
2597 extern unsigned int symtab_create_debug
;
2599 /* Print a "symtab-create" debug statement. */
2601 #define symtab_create_debug_printf(fmt, ...) \
2602 debug_prefixed_printf_cond (symtab_create_debug >= 1, "symtab-create", fmt, ##__VA_ARGS__)
2604 /* Print a verbose "symtab-create" debug statement, only if
2605 "set debug symtab-create" is set to 2 or higher. */
2607 #define symtab_create_debug_printf_v(fmt, ...) \
2608 debug_prefixed_printf_cond (symtab_create_debug >= 2, "symtab-create", fmt, ##__VA_ARGS__)
2610 extern unsigned int symbol_lookup_debug
;
2612 /* Return true if symbol-lookup debug is turned on at all. */
2615 symbol_lookup_debug_enabled ()
2617 return symbol_lookup_debug
> 0;
2620 /* Return true if symbol-lookup debug is turned to verbose mode. */
2623 symbol_lookup_debug_enabled_v ()
2625 return symbol_lookup_debug
> 1;
2628 /* Print a "symbol-lookup" debug statement if symbol_lookup_debug is >= 1. */
2630 #define symbol_lookup_debug_printf(fmt, ...) \
2631 debug_prefixed_printf_cond (symbol_lookup_debug_enabled (), \
2632 "symbol-lookup", fmt, ##__VA_ARGS__)
2634 /* Print a "symbol-lookup" debug statement if symbol_lookup_debug is >= 2. */
2636 #define symbol_lookup_debug_printf_v(fmt, ...) \
2637 debug_prefixed_printf_cond (symbol_lookup_debug_enabled_v (), \
2638 "symbol-lookup", fmt, ##__VA_ARGS__)
2640 /* Print "symbol-lookup" enter/exit debug statements. */
2642 #define SYMBOL_LOOKUP_SCOPED_DEBUG_ENTER_EXIT \
2643 scoped_debug_enter_exit (symbol_lookup_debug_enabled, "symbol-lookup")
2645 extern bool basenames_may_differ
;
2647 bool compare_filenames_for_search (const char *filename
,
2648 const char *search_name
);
2650 bool compare_glob_filenames_for_search (const char *filename
,
2651 const char *search_name
);
2653 bool iterate_over_some_symtabs (const char *name
,
2654 const char *real_path
,
2655 struct compunit_symtab
*first
,
2656 struct compunit_symtab
*after_last
,
2657 gdb::function_view
<bool (symtab
*)> callback
);
2659 void iterate_over_symtabs (const char *name
,
2660 gdb::function_view
<bool (symtab
*)> callback
);
2663 std::vector
<CORE_ADDR
> find_pcs_for_symtab_line
2664 (struct symtab
*symtab
, int line
, struct linetable_entry
**best_entry
);
2666 /* Prototype for callbacks for LA_ITERATE_OVER_SYMBOLS. The callback
2667 is called once per matching symbol SYM. The callback should return
2668 true to indicate that LA_ITERATE_OVER_SYMBOLS should continue
2669 iterating, or false to indicate that the iteration should end. */
2671 typedef bool (symbol_found_callback_ftype
) (struct block_symbol
*bsym
);
2673 /* Iterate over the symbols named NAME, matching DOMAIN, in BLOCK.
2675 For each symbol that matches, CALLBACK is called. The symbol is
2676 passed to the callback.
2678 If CALLBACK returns false, the iteration ends and this function
2679 returns false. Otherwise, the search continues, and the function
2680 eventually returns true. */
2682 bool iterate_over_symbols (const struct block
*block
,
2683 const lookup_name_info
&name
,
2684 const domain_enum domain
,
2685 gdb::function_view
<symbol_found_callback_ftype
> callback
);
2687 /* Like iterate_over_symbols, but if all calls to CALLBACK return
2688 true, then calls CALLBACK one additional time with a block_symbol
2689 that has a valid block but a NULL symbol. */
2691 bool iterate_over_symbols_terminated
2692 (const struct block
*block
,
2693 const lookup_name_info
&name
,
2694 const domain_enum domain
,
2695 gdb::function_view
<symbol_found_callback_ftype
> callback
);
2697 /* Storage type used by demangle_for_lookup. demangle_for_lookup
2698 either returns a const char * pointer that points to either of the
2699 fields of this type, or a pointer to the input NAME. This is done
2700 this way to avoid depending on the precise details of the storage
2702 class demangle_result_storage
2706 /* Swap the malloc storage to STR, and return a pointer to the
2707 beginning of the new string. */
2708 const char *set_malloc_ptr (gdb::unique_xmalloc_ptr
<char> &&str
)
2710 m_malloc
= std::move (str
);
2711 return m_malloc
.get ();
2714 /* Set the malloc storage to now point at PTR. Any previous malloc
2715 storage is released. */
2716 const char *set_malloc_ptr (char *ptr
)
2718 m_malloc
.reset (ptr
);
2725 gdb::unique_xmalloc_ptr
<char> m_malloc
;
2729 demangle_for_lookup (const char *name
, enum language lang
,
2730 demangle_result_storage
&storage
);
2732 /* Test to see if the symbol of language SYMBOL_LANGUAGE specified by
2733 SYMNAME (which is already demangled for C++ symbols) matches
2734 SYM_TEXT in the first SYM_TEXT_LEN characters. If so, add it to
2735 the current completion list and return true. Otherwise, return
2737 bool completion_list_add_name (completion_tracker
&tracker
,
2738 language symbol_language
,
2739 const char *symname
,
2740 const lookup_name_info
&lookup_name
,
2741 const char *text
, const char *word
);
2743 /* A simple symbol searching class. */
2745 class symbol_searcher
2748 /* Returns the symbols found for the search. */
2749 const std::vector
<block_symbol
> &
2750 matching_symbols () const
2755 /* Returns the minimal symbols found for the search. */
2756 const std::vector
<bound_minimal_symbol
> &
2757 matching_msymbols () const
2759 return m_minimal_symbols
;
2762 /* Search for all symbols named NAME in LANGUAGE with DOMAIN, restricting
2763 search to FILE_SYMTABS and SEARCH_PSPACE, both of which may be NULL
2764 to search all symtabs and program spaces. */
2765 void find_all_symbols (const std::string
&name
,
2766 const struct language_defn
*language
,
2767 enum search_domain search_domain
,
2768 std::vector
<symtab
*> *search_symtabs
,
2769 struct program_space
*search_pspace
);
2771 /* Reset this object to perform another search. */
2775 m_minimal_symbols
.clear ();
2779 /* Matching debug symbols. */
2780 std::vector
<block_symbol
> m_symbols
;
2782 /* Matching non-debug symbols. */
2783 std::vector
<bound_minimal_symbol
> m_minimal_symbols
;
2786 /* Class used to encapsulate the filename filtering for the "info sources"
2789 struct info_sources_filter
2791 /* If filename filtering is being used (see M_C_REGEXP) then which part
2792 of the filename is being filtered against? */
2795 /* Match against the full filename. */
2798 /* Match only against the directory part of the full filename. */
2801 /* Match only against the basename part of the full filename. */
2805 /* Create a filter of MATCH_TYPE using regular expression REGEXP. If
2806 REGEXP is nullptr then all files will match the filter and MATCH_TYPE
2809 The string pointed too by REGEXP must remain live and unchanged for
2810 this lifetime of this object as the object only retains a copy of the
2812 info_sources_filter (match_on match_type
, const char *regexp
);
2814 DISABLE_COPY_AND_ASSIGN (info_sources_filter
);
2816 /* Does FULLNAME match the filter defined by this object, return true if
2817 it does, otherwise, return false. If there is no filtering defined
2818 then this function will always return true. */
2819 bool matches (const char *fullname
) const;
2823 /* The type of filtering in place. */
2824 match_on m_match_type
;
2826 /* Points to the original regexp used to create this filter. */
2827 const char *m_regexp
;
2829 /* A compiled version of M_REGEXP. This object is only given a value if
2830 M_REGEXP is not nullptr and is not the empty string. */
2831 gdb::optional
<compiled_regex
> m_c_regexp
;
2834 /* Perform the core of the 'info sources' command.
2836 FILTER is used to perform regular expression based filtering on the
2837 source files that will be displayed.
2839 Output is written to UIOUT in CLI or MI style as appropriate. */
2841 extern void info_sources_worker (struct ui_out
*uiout
,
2842 bool group_by_objfile
,
2843 const info_sources_filter
&filter
);
2845 #endif /* !defined(SYMTAB_H) */