1 /* Symbol table definitions for GDB.
3 Copyright (C) 1986-2018 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #if !defined (SYMTAB_H)
28 #include "common/enum-flags.h"
29 #include "common/function-view.h"
30 #include "common/gdb_optional.h"
31 #include "completer.h"
33 /* Opaque declarations. */
47 struct cmd_list_element
;
49 struct lookup_name_info
;
51 /* How to match a lookup name against a symbol search name. */
52 enum class symbol_name_match_type
54 /* Wild matching. Matches unqualified symbol names in all
55 namespace/module/packages, etc. */
58 /* Full matching. The lookup name indicates a fully-qualified name,
59 and only matches symbol search names in the specified
60 namespace/module/package. */
63 /* Search name matching. This is like FULL, but the search name did
64 not come from the user; instead it is already a search name
65 retrieved from a SYMBOL_SEARCH_NAME/MSYMBOL_SEARCH_NAME call.
66 For Ada, this avoids re-encoding an already-encoded search name
67 (which would potentially incorrectly lowercase letters in the
68 linkage/search name that should remain uppercase). For C++, it
69 avoids trying to demangle a name we already know is
73 /* Expression matching. The same as FULL matching in most
74 languages. The same as WILD matching in Ada. */
78 /* Hash the given symbol search name according to LANGUAGE's
80 extern unsigned int search_name_hash (enum language language
,
81 const char *search_name
);
83 /* Ada-specific bits of a lookup_name_info object. This is lazily
84 constructed on demand. */
86 class ada_lookup_name_info final
90 explicit ada_lookup_name_info (const lookup_name_info
&lookup_name
);
92 /* Compare SYMBOL_SEARCH_NAME with our lookup name, using MATCH_TYPE
93 as name match type. Returns true if there's a match, false
94 otherwise. If non-NULL, store the matching results in MATCH. */
95 bool matches (const char *symbol_search_name
,
96 symbol_name_match_type match_type
,
97 completion_match_result
*comp_match_res
) const;
99 /* The Ada-encoded lookup name. */
100 const std::string
&lookup_name () const
101 { return m_encoded_name
; }
103 /* Return true if we're supposed to be doing a wild match look
105 bool wild_match_p () const
106 { return m_wild_match_p
; }
108 /* Return true if we're looking up a name inside package
110 bool standard_p () const
111 { return m_standard_p
; }
114 /* The Ada-encoded lookup name. */
115 std::string m_encoded_name
;
117 /* Whether the user-provided lookup name was Ada encoded. If so,
118 then return encoded names in the 'matches' method's 'completion
119 match result' output. */
120 bool m_encoded_p
: 1;
122 /* True if really doing wild matching. Even if the user requests
123 wild matching, some cases require full matching. */
124 bool m_wild_match_p
: 1;
126 /* True if doing a verbatim match. This is true if the decoded
127 version of the symbol name is wrapped in '<'/'>'. This is an
128 escape hatch users can use to look up symbols the Ada encoding
129 does not understand. */
130 bool m_verbatim_p
: 1;
132 /* True if the user specified a symbol name that is inside package
133 Standard. Symbol names inside package Standard are handled
134 specially. We always do a non-wild match of the symbol name
135 without the "standard__" prefix, and only search static and
136 global symbols. This was primarily introduced in order to allow
137 the user to specifically access the standard exceptions using,
138 for instance, Standard.Constraint_Error when Constraint_Error is
139 ambiguous (due to the user defining its own Constraint_Error
140 entity inside its program). */
141 bool m_standard_p
: 1;
144 /* Language-specific bits of a lookup_name_info object, for languages
145 that do name searching using demangled names (C++/D/Go). This is
146 lazily constructed on demand. */
148 struct demangle_for_lookup_info final
151 demangle_for_lookup_info (const lookup_name_info
&lookup_name
,
154 /* The demangled lookup name. */
155 const std::string
&lookup_name () const
156 { return m_demangled_name
; }
159 /* The demangled lookup name. */
160 std::string m_demangled_name
;
163 /* Object that aggregates all information related to a symbol lookup
164 name. I.e., the name that is matched against the symbol's search
165 name. Caches per-language information so that it doesn't require
166 recomputing it for every symbol comparison, like for example the
167 Ada encoded name and the symbol's name hash for a given language.
168 The object is conceptually immutable once constructed, and thus has
169 no setters. This is to prevent some code path from tweaking some
170 property of the lookup name for some local reason and accidentally
171 altering the results of any continuing search(es).
172 lookup_name_info objects are generally passed around as a const
173 reference to reinforce that. (They're not passed around by value
174 because they're not small.) */
175 class lookup_name_info final
178 /* Create a new object. */
179 lookup_name_info (std::string name
,
180 symbol_name_match_type match_type
,
181 bool completion_mode
= false,
182 bool ignore_parameters
= false)
183 : m_match_type (match_type
),
184 m_completion_mode (completion_mode
),
185 m_ignore_parameters (ignore_parameters
),
186 m_name (std::move (name
))
189 /* Getters. See description of each corresponding field. */
190 symbol_name_match_type
match_type () const { return m_match_type
; }
191 bool completion_mode () const { return m_completion_mode
; }
192 const std::string
&name () const { return m_name
; }
193 const bool ignore_parameters () const { return m_ignore_parameters
; }
195 /* Return a version of this lookup name that is usable with
196 comparisons against symbols have no parameter info, such as
197 psymbols and GDB index symbols. */
198 lookup_name_info
make_ignore_params () const
200 return lookup_name_info (m_name
, m_match_type
, m_completion_mode
,
201 true /* ignore params */);
204 /* Get the search name hash for searches in language LANG. */
205 unsigned int search_name_hash (language lang
) const
207 /* Only compute each language's hash once. */
208 if (!m_demangled_hashes_p
[lang
])
210 m_demangled_hashes
[lang
]
211 = ::search_name_hash (lang
, language_lookup_name (lang
).c_str ());
212 m_demangled_hashes_p
[lang
] = true;
214 return m_demangled_hashes
[lang
];
217 /* Get the search name for searches in language LANG. */
218 const std::string
&language_lookup_name (language lang
) const
223 return ada ().lookup_name ();
225 return cplus ().lookup_name ();
227 return d ().lookup_name ();
229 return go ().lookup_name ();
235 /* Get the Ada-specific lookup info. */
236 const ada_lookup_name_info
&ada () const
242 /* Get the C++-specific lookup info. */
243 const demangle_for_lookup_info
&cplus () const
245 maybe_init (m_cplus
, language_cplus
);
249 /* Get the D-specific lookup info. */
250 const demangle_for_lookup_info
&d () const
252 maybe_init (m_d
, language_d
);
256 /* Get the Go-specific lookup info. */
257 const demangle_for_lookup_info
&go () const
259 maybe_init (m_go
, language_go
);
263 /* Get a reference to a lookup_name_info object that matches any
265 static const lookup_name_info
&match_any ();
268 /* Initialize FIELD, if not initialized yet. */
269 template<typename Field
, typename
... Args
>
270 void maybe_init (Field
&field
, Args
&&... args
) const
273 field
.emplace (*this, std::forward
<Args
> (args
)...);
276 /* The lookup info as passed to the ctor. */
277 symbol_name_match_type m_match_type
;
278 bool m_completion_mode
;
279 bool m_ignore_parameters
;
282 /* Language-specific info. These fields are filled lazily the first
283 time a lookup is done in the corresponding language. They're
284 mutable because lookup_name_info objects are typically passed
285 around by const reference (see intro), and they're conceptually
286 "cache" that can always be reconstructed from the non-mutable
288 mutable gdb::optional
<ada_lookup_name_info
> m_ada
;
289 mutable gdb::optional
<demangle_for_lookup_info
> m_cplus
;
290 mutable gdb::optional
<demangle_for_lookup_info
> m_d
;
291 mutable gdb::optional
<demangle_for_lookup_info
> m_go
;
293 /* The demangled hashes. Stored in an array with one entry for each
294 possible language. The second array records whether we've
295 already computed the each language's hash. (These are separate
296 arrays instead of a single array of optional<unsigned> to avoid
297 alignment padding). */
298 mutable std::array
<unsigned int, nr_languages
> m_demangled_hashes
;
299 mutable std::array
<bool, nr_languages
> m_demangled_hashes_p
{};
302 /* Comparison function for completion symbol lookup.
304 Returns true if the symbol name matches against LOOKUP_NAME.
306 SYMBOL_SEARCH_NAME should be a symbol's "search" name.
308 On success and if non-NULL, COMP_MATCH_RES->match is set to point
309 to the symbol name as should be presented to the user as a
310 completion match list element. In most languages, this is the same
311 as the symbol's search name, but in some, like Ada, the display
312 name is dynamically computed within the comparison routine.
314 Also, on success and if non-NULL, COMP_MATCH_RES->match_for_lcd
315 points the part of SYMBOL_SEARCH_NAME that was considered to match
316 LOOKUP_NAME. E.g., in C++, in linespec/wild mode, if the symbol is
317 "foo::function()" and LOOKUP_NAME is "function(", MATCH_FOR_LCD
318 points to "function()" inside SYMBOL_SEARCH_NAME. */
319 typedef bool (symbol_name_matcher_ftype
)
320 (const char *symbol_search_name
,
321 const lookup_name_info
&lookup_name
,
322 completion_match_result
*comp_match_res
);
324 /* Some of the structures in this file are space critical.
325 The space-critical structures are:
327 struct general_symbol_info
329 struct partial_symbol
331 These structures are laid out to encourage good packing.
332 They use ENUM_BITFIELD and short int fields, and they order the
333 structure members so that fields less than a word are next
334 to each other so they can be packed together. */
336 /* Rearranged: used ENUM_BITFIELD and rearranged field order in
337 all the space critical structures (plus struct minimal_symbol).
338 Memory usage dropped from 99360768 bytes to 90001408 bytes.
339 I measured this with before-and-after tests of
340 "HEAD-old-gdb -readnow HEAD-old-gdb" and
341 "HEAD-new-gdb -readnow HEAD-old-gdb" on native i686-pc-linux-gnu,
342 red hat linux 8, with LD_LIBRARY_PATH=/usr/lib/debug,
343 typing "maint space 1" at the first command prompt.
345 Here is another measurement (from andrew c):
346 # no /usr/lib/debug, just plain glibc, like a normal user
348 (gdb) break internal_error
350 (gdb) maint internal-error
354 gdb gdb_6_0_branch 2003-08-19 space used: 8896512
355 gdb HEAD 2003-08-19 space used: 8904704
356 gdb HEAD 2003-08-21 space used: 8396800 (+symtab.h)
357 gdb HEAD 2003-08-21 space used: 8265728 (+gdbtypes.h)
359 The third line shows the savings from the optimizations in symtab.h.
360 The fourth line shows the savings from the optimizations in
361 gdbtypes.h. Both optimizations are in gdb HEAD now.
363 --chastain 2003-08-21 */
365 /* Define a structure for the information that is common to all symbol types,
366 including minimal symbols, partial symbols, and full symbols. In a
367 multilanguage environment, some language specific information may need to
368 be recorded along with each symbol. */
370 /* This structure is space critical. See space comments at the top. */
372 struct general_symbol_info
374 /* Name of the symbol. This is a required field. Storage for the
375 name is allocated on the objfile_obstack for the associated
376 objfile. For languages like C++ that make a distinction between
377 the mangled name and demangled name, this is the mangled
382 /* Value of the symbol. Which member of this union to use, and what
383 it means, depends on what kind of symbol this is and its
384 SYMBOL_CLASS. See comments there for more details. All of these
385 are in host byte order (though what they point to might be in
386 target byte order, e.g. LOC_CONST_BYTES). */
392 const struct block
*block
;
394 const gdb_byte
*bytes
;
398 /* A common block. Used with LOC_COMMON_BLOCK. */
400 const struct common_block
*common_block
;
402 /* For opaque typedef struct chain. */
404 struct symbol
*chain
;
408 /* Since one and only one language can apply, wrap the language specific
409 information inside a union. */
413 /* A pointer to an obstack that can be used for storage associated
414 with this symbol. This is only used by Ada, and only when the
415 'ada_mangled' field is zero. */
416 struct obstack
*obstack
;
418 /* This is used by languages which wish to store a demangled name.
419 currently used by Ada, C++, and Objective C. */
420 const char *demangled_name
;
424 /* Record the source code language that applies to this symbol.
425 This is used to select one of the fields from the language specific
428 ENUM_BITFIELD(language
) language
: LANGUAGE_BITS
;
430 /* This is only used by Ada. If set, then the 'demangled_name' field
431 of language_specific is valid. Otherwise, the 'obstack' field is
433 unsigned int ada_mangled
: 1;
435 /* Which section is this symbol in? This is an index into
436 section_offsets for this objfile. Negative means that the symbol
437 does not get relocated relative to a section. */
442 extern void symbol_set_demangled_name (struct general_symbol_info
*,
446 extern const char *symbol_get_demangled_name
447 (const struct general_symbol_info
*);
449 extern CORE_ADDR
symbol_overlayed_address (CORE_ADDR
, struct obj_section
*);
451 /* Note that all the following SYMBOL_* macros are used with the
452 SYMBOL argument being either a partial symbol or
453 a full symbol. Both types have a ginfo field. In particular
454 the SYMBOL_SET_LANGUAGE, SYMBOL_DEMANGLED_NAME, etc.
455 macros cannot be entirely substituted by
456 functions, unless the callers are changed to pass in the ginfo
457 field only, instead of the SYMBOL parameter. */
459 #define SYMBOL_VALUE(symbol) (symbol)->ginfo.value.ivalue
460 #define SYMBOL_VALUE_ADDRESS(symbol) (symbol)->ginfo.value.address
461 #define SYMBOL_VALUE_BYTES(symbol) (symbol)->ginfo.value.bytes
462 #define SYMBOL_VALUE_COMMON_BLOCK(symbol) (symbol)->ginfo.value.common_block
463 #define SYMBOL_BLOCK_VALUE(symbol) (symbol)->ginfo.value.block
464 #define SYMBOL_VALUE_CHAIN(symbol) (symbol)->ginfo.value.chain
465 #define SYMBOL_LANGUAGE(symbol) (symbol)->ginfo.language
466 #define SYMBOL_SECTION(symbol) (symbol)->ginfo.section
467 #define SYMBOL_OBJ_SECTION(objfile, symbol) \
468 (((symbol)->ginfo.section >= 0) \
469 ? (&(((objfile)->sections)[(symbol)->ginfo.section])) \
472 /* Initializes the language dependent portion of a symbol
473 depending upon the language for the symbol. */
474 #define SYMBOL_SET_LANGUAGE(symbol,language,obstack) \
475 (symbol_set_language (&(symbol)->ginfo, (language), (obstack)))
476 extern void symbol_set_language (struct general_symbol_info
*symbol
,
477 enum language language
,
478 struct obstack
*obstack
);
480 /* Set just the linkage name of a symbol; do not try to demangle
481 it. Used for constructs which do not have a mangled name,
482 e.g. struct tags. Unlike SYMBOL_SET_NAMES, linkage_name must
483 be terminated and either already on the objfile's obstack or
484 permanently allocated. */
485 #define SYMBOL_SET_LINKAGE_NAME(symbol,linkage_name) \
486 (symbol)->ginfo.name = (linkage_name)
488 /* Set the linkage and natural names of a symbol, by demangling
490 #define SYMBOL_SET_NAMES(symbol,linkage_name,len,copy_name,objfile) \
491 symbol_set_names (&(symbol)->ginfo, linkage_name, len, copy_name, objfile)
492 extern void symbol_set_names (struct general_symbol_info
*symbol
,
493 const char *linkage_name
, int len
, int copy_name
,
494 struct objfile
*objfile
);
496 /* Now come lots of name accessor macros. Short version as to when to
497 use which: Use SYMBOL_NATURAL_NAME to refer to the name of the
498 symbol in the original source code. Use SYMBOL_LINKAGE_NAME if you
499 want to know what the linker thinks the symbol's name is. Use
500 SYMBOL_PRINT_NAME for output. Use SYMBOL_DEMANGLED_NAME if you
501 specifically need to know whether SYMBOL_NATURAL_NAME and
502 SYMBOL_LINKAGE_NAME are different. */
504 /* Return SYMBOL's "natural" name, i.e. the name that it was called in
505 the original source code. In languages like C++ where symbols may
506 be mangled for ease of manipulation by the linker, this is the
509 #define SYMBOL_NATURAL_NAME(symbol) \
510 (symbol_natural_name (&(symbol)->ginfo))
511 extern const char *symbol_natural_name
512 (const struct general_symbol_info
*symbol
);
514 /* Return SYMBOL's name from the point of view of the linker. In
515 languages like C++ where symbols may be mangled for ease of
516 manipulation by the linker, this is the mangled name; otherwise,
517 it's the same as SYMBOL_NATURAL_NAME. */
519 #define SYMBOL_LINKAGE_NAME(symbol) (symbol)->ginfo.name
521 /* Return the demangled name for a symbol based on the language for
522 that symbol. If no demangled name exists, return NULL. */
523 #define SYMBOL_DEMANGLED_NAME(symbol) \
524 (symbol_demangled_name (&(symbol)->ginfo))
525 extern const char *symbol_demangled_name
526 (const struct general_symbol_info
*symbol
);
528 /* Macro that returns a version of the name of a symbol that is
529 suitable for output. In C++ this is the "demangled" form of the
530 name if demangle is on and the "mangled" form of the name if
531 demangle is off. In other languages this is just the symbol name.
532 The result should never be NULL. Don't use this for internal
533 purposes (e.g. storing in a hashtable): it's only suitable for output.
535 N.B. symbol may be anything with a ginfo member,
536 e.g., struct symbol or struct minimal_symbol. */
538 #define SYMBOL_PRINT_NAME(symbol) \
539 (demangle ? SYMBOL_NATURAL_NAME (symbol) : SYMBOL_LINKAGE_NAME (symbol))
542 /* Macro that returns the name to be used when sorting and searching symbols.
543 In C++, we search for the demangled form of a name,
544 and so sort symbols accordingly. In Ada, however, we search by mangled
545 name. If there is no distinct demangled name, then SYMBOL_SEARCH_NAME
546 returns the same value (same pointer) as SYMBOL_LINKAGE_NAME. */
547 #define SYMBOL_SEARCH_NAME(symbol) \
548 (symbol_search_name (&(symbol)->ginfo))
549 extern const char *symbol_search_name (const struct general_symbol_info
*ginfo
);
551 /* Return true if NAME matches the "search" name of SYMBOL, according
552 to the symbol's language. */
553 #define SYMBOL_MATCHES_SEARCH_NAME(symbol, name) \
554 symbol_matches_search_name (&(symbol)->ginfo, (name))
556 /* Helper for SYMBOL_MATCHES_SEARCH_NAME that works with both symbols
558 extern bool symbol_matches_search_name
559 (const struct general_symbol_info
*gsymbol
,
560 const lookup_name_info
&name
);
562 /* Compute the hash of the given symbol search name of a symbol of
563 language LANGUAGE. */
564 extern unsigned int search_name_hash (enum language language
,
565 const char *search_name
);
567 /* Classification types for a minimal symbol. These should be taken as
568 "advisory only", since if gdb can't easily figure out a
569 classification it simply selects mst_unknown. It may also have to
570 guess when it can't figure out which is a better match between two
571 types (mst_data versus mst_bss) for example. Since the minimal
572 symbol info is sometimes derived from the BFD library's view of a
573 file, we need to live with what information bfd supplies. */
575 enum minimal_symbol_type
577 mst_unknown
= 0, /* Unknown type, the default */
578 mst_text
, /* Generally executable instructions */
579 mst_text_gnu_ifunc
, /* Executable code returning address
580 of executable code */
581 mst_slot_got_plt
, /* GOT entries for .plt sections */
582 mst_data
, /* Generally initialized data */
583 mst_bss
, /* Generally uninitialized data */
584 mst_abs
, /* Generally absolute (nonrelocatable) */
585 /* GDB uses mst_solib_trampoline for the start address of a shared
586 library trampoline entry. Breakpoints for shared library functions
587 are put there if the shared library is not yet loaded.
588 After the shared library is loaded, lookup_minimal_symbol will
589 prefer the minimal symbol from the shared library (usually
590 a mst_text symbol) over the mst_solib_trampoline symbol, and the
591 breakpoints will be moved to their true address in the shared
592 library via breakpoint_re_set. */
593 mst_solib_trampoline
, /* Shared library trampoline code */
594 /* For the mst_file* types, the names are only guaranteed to be unique
595 within a given .o file. */
596 mst_file_text
, /* Static version of mst_text */
597 mst_file_data
, /* Static version of mst_data */
598 mst_file_bss
, /* Static version of mst_bss */
602 /* The number of enum minimal_symbol_type values, with some padding for
603 reasonable growth. */
604 #define MINSYM_TYPE_BITS 4
605 gdb_static_assert (nr_minsym_types
<= (1 << MINSYM_TYPE_BITS
));
607 /* Define a simple structure used to hold some very basic information about
608 all defined global symbols (text, data, bss, abs, etc). The only required
609 information is the general_symbol_info.
611 In many cases, even if a file was compiled with no special options for
612 debugging at all, as long as was not stripped it will contain sufficient
613 information to build a useful minimal symbol table using this structure.
614 Even when a file contains enough debugging information to build a full
615 symbol table, these minimal symbols are still useful for quickly mapping
616 between names and addresses, and vice versa. They are also sometimes
617 used to figure out what full symbol table entries need to be read in. */
619 struct minimal_symbol
622 /* The general symbol info required for all types of symbols.
624 The SYMBOL_VALUE_ADDRESS contains the address that this symbol
627 struct general_symbol_info mginfo
;
629 /* Size of this symbol. dbx_end_psymtab in dbxread.c uses this
630 information to calculate the end of the partial symtab based on the
631 address of the last symbol plus the size of the last symbol. */
635 /* Which source file is this symbol in? Only relevant for mst_file_*. */
636 const char *filename
;
638 /* Classification type for this minimal symbol. */
640 ENUM_BITFIELD(minimal_symbol_type
) type
: MINSYM_TYPE_BITS
;
642 /* Non-zero if this symbol was created by gdb.
643 Such symbols do not appear in the output of "info var|fun". */
644 unsigned int created_by_gdb
: 1;
646 /* Two flag bits provided for the use of the target. */
647 unsigned int target_flag_1
: 1;
648 unsigned int target_flag_2
: 1;
650 /* Nonzero iff the size of the minimal symbol has been set.
651 Symbol size information can sometimes not be determined, because
652 the object file format may not carry that piece of information. */
653 unsigned int has_size
: 1;
655 /* Minimal symbols with the same hash key are kept on a linked
656 list. This is the link. */
658 struct minimal_symbol
*hash_next
;
660 /* Minimal symbols are stored in two different hash tables. This is
661 the `next' pointer for the demangled hash table. */
663 struct minimal_symbol
*demangled_hash_next
;
666 #define MSYMBOL_TARGET_FLAG_1(msymbol) (msymbol)->target_flag_1
667 #define MSYMBOL_TARGET_FLAG_2(msymbol) (msymbol)->target_flag_2
668 #define MSYMBOL_SIZE(msymbol) ((msymbol)->size + 0)
669 #define SET_MSYMBOL_SIZE(msymbol, sz) \
672 (msymbol)->size = sz; \
673 (msymbol)->has_size = 1; \
675 #define MSYMBOL_HAS_SIZE(msymbol) ((msymbol)->has_size + 0)
676 #define MSYMBOL_TYPE(msymbol) (msymbol)->type
678 #define MSYMBOL_VALUE(symbol) (symbol)->mginfo.value.ivalue
679 /* The unrelocated address of the minimal symbol. */
680 #define MSYMBOL_VALUE_RAW_ADDRESS(symbol) ((symbol)->mginfo.value.address + 0)
681 /* The relocated address of the minimal symbol, using the section
682 offsets from OBJFILE. */
683 #define MSYMBOL_VALUE_ADDRESS(objfile, symbol) \
684 ((symbol)->mginfo.value.address \
685 + ANOFFSET ((objfile)->section_offsets, ((symbol)->mginfo.section)))
686 /* For a bound minsym, we can easily compute the address directly. */
687 #define BMSYMBOL_VALUE_ADDRESS(symbol) \
688 MSYMBOL_VALUE_ADDRESS ((symbol).objfile, (symbol).minsym)
689 #define SET_MSYMBOL_VALUE_ADDRESS(symbol, new_value) \
690 ((symbol)->mginfo.value.address = (new_value))
691 #define MSYMBOL_VALUE_BYTES(symbol) (symbol)->mginfo.value.bytes
692 #define MSYMBOL_BLOCK_VALUE(symbol) (symbol)->mginfo.value.block
693 #define MSYMBOL_VALUE_CHAIN(symbol) (symbol)->mginfo.value.chain
694 #define MSYMBOL_LANGUAGE(symbol) (symbol)->mginfo.language
695 #define MSYMBOL_SECTION(symbol) (symbol)->mginfo.section
696 #define MSYMBOL_OBJ_SECTION(objfile, symbol) \
697 (((symbol)->mginfo.section >= 0) \
698 ? (&(((objfile)->sections)[(symbol)->mginfo.section])) \
701 #define MSYMBOL_NATURAL_NAME(symbol) \
702 (symbol_natural_name (&(symbol)->mginfo))
703 #define MSYMBOL_LINKAGE_NAME(symbol) (symbol)->mginfo.name
704 #define MSYMBOL_PRINT_NAME(symbol) \
705 (demangle ? MSYMBOL_NATURAL_NAME (symbol) : MSYMBOL_LINKAGE_NAME (symbol))
706 #define MSYMBOL_DEMANGLED_NAME(symbol) \
707 (symbol_demangled_name (&(symbol)->mginfo))
708 #define MSYMBOL_SET_LANGUAGE(symbol,language,obstack) \
709 (symbol_set_language (&(symbol)->mginfo, (language), (obstack)))
710 #define MSYMBOL_SEARCH_NAME(symbol) \
711 (symbol_search_name (&(symbol)->mginfo))
712 #define MSYMBOL_SET_NAMES(symbol,linkage_name,len,copy_name,objfile) \
713 symbol_set_names (&(symbol)->mginfo, linkage_name, len, copy_name, objfile)
719 /* Represent one symbol name; a variable, constant, function or typedef. */
721 /* Different name domains for symbols. Looking up a symbol specifies a
722 domain and ignores symbol definitions in other name domains. */
724 typedef enum domain_enum_tag
726 /* UNDEF_DOMAIN is used when a domain has not been discovered or
727 none of the following apply. This usually indicates an error either
728 in the symbol information or in gdb's handling of symbols. */
732 /* VAR_DOMAIN is the usual domain. In C, this contains variables,
733 function names, typedef names and enum type values. */
737 /* STRUCT_DOMAIN is used in C to hold struct, union and enum type names.
738 Thus, if `struct foo' is used in a C program, it produces a symbol named
739 `foo' in the STRUCT_DOMAIN. */
743 /* MODULE_DOMAIN is used in Fortran to hold module type names. */
747 /* LABEL_DOMAIN may be used for names of labels (for gotos). */
751 /* Fortran common blocks. Their naming must be separate from VAR_DOMAIN.
752 They also always use LOC_COMMON_BLOCK. */
755 /* This must remain last. */
759 /* The number of bits in a symbol used to represent the domain. */
761 #define SYMBOL_DOMAIN_BITS 3
762 gdb_static_assert (NR_DOMAINS
<= (1 << SYMBOL_DOMAIN_BITS
));
764 extern const char *domain_name (domain_enum
);
766 /* Searching domains, used for `search_symbols'. Element numbers are
767 hardcoded in GDB, check all enum uses before changing it. */
771 /* Everything in VAR_DOMAIN minus FUNCTIONS_DOMAIN and
773 VARIABLES_DOMAIN
= 0,
775 /* All functions -- for some reason not methods, though. */
776 FUNCTIONS_DOMAIN
= 1,
778 /* All defined types */
785 extern const char *search_domain_name (enum search_domain
);
787 /* An address-class says where to find the value of a symbol. */
791 /* Not used; catches errors. */
795 /* Value is constant int SYMBOL_VALUE, host byteorder. */
799 /* Value is at fixed address SYMBOL_VALUE_ADDRESS. */
803 /* Value is in register. SYMBOL_VALUE is the register number
804 in the original debug format. SYMBOL_REGISTER_OPS holds a
805 function that can be called to transform this into the
806 actual register number this represents in a specific target
807 architecture (gdbarch).
809 For some symbol formats (stabs, for some compilers at least),
810 the compiler generates two symbols, an argument and a register.
811 In some cases we combine them to a single LOC_REGISTER in symbol
812 reading, but currently not for all cases (e.g. it's passed on the
813 stack and then loaded into a register). */
817 /* It's an argument; the value is at SYMBOL_VALUE offset in arglist. */
821 /* Value address is at SYMBOL_VALUE offset in arglist. */
825 /* Value is in specified register. Just like LOC_REGISTER except the
826 register holds the address of the argument instead of the argument
827 itself. This is currently used for the passing of structs and unions
828 on sparc and hppa. It is also used for call by reference where the
829 address is in a register, at least by mipsread.c. */
833 /* Value is a local variable at SYMBOL_VALUE offset in stack frame. */
837 /* Value not used; definition in SYMBOL_TYPE. Symbols in the domain
838 STRUCT_DOMAIN all have this class. */
842 /* Value is address SYMBOL_VALUE_ADDRESS in the code. */
846 /* In a symbol table, value is SYMBOL_BLOCK_VALUE of a `struct block'.
847 In a partial symbol table, SYMBOL_VALUE_ADDRESS is the start address
848 of the block. Function names have this class. */
852 /* Value is a constant byte-sequence pointed to by SYMBOL_VALUE_BYTES, in
853 target byte order. */
857 /* Value is at fixed address, but the address of the variable has
858 to be determined from the minimal symbol table whenever the
859 variable is referenced.
860 This happens if debugging information for a global symbol is
861 emitted and the corresponding minimal symbol is defined
862 in another object file or runtime common storage.
863 The linker might even remove the minimal symbol if the global
864 symbol is never referenced, in which case the symbol remains
867 GDB would normally find the symbol in the minimal symbol table if it will
868 not find it in the full symbol table. But a reference to an external
869 symbol in a local block shadowing other definition requires full symbol
870 without possibly having its address available for LOC_STATIC. Testcase
871 is provided as `gdb.dwarf2/dw2-unresolved.exp'.
873 This is also used for thread local storage (TLS) variables. In this case,
874 the address of the TLS variable must be determined when the variable is
875 referenced, from the MSYMBOL_VALUE_RAW_ADDRESS, which is the offset
876 of the TLS variable in the thread local storage of the shared
881 /* The variable does not actually exist in the program.
882 The value is ignored. */
886 /* The variable's address is computed by a set of location
887 functions (see "struct symbol_computed_ops" below). */
890 /* The variable uses general_symbol_info->value->common_block field.
891 It also always uses COMMON_BLOCK_DOMAIN. */
894 /* Not used, just notes the boundary of the enum. */
898 /* The number of bits needed for values in enum address_class, with some
899 padding for reasonable growth, and room for run-time registered address
900 classes. See symtab.c:MAX_SYMBOL_IMPLS.
901 This is a #define so that we can have a assertion elsewhere to
902 verify that we have reserved enough space for synthetic address
904 #define SYMBOL_ACLASS_BITS 5
905 gdb_static_assert (LOC_FINAL_VALUE
<= (1 << SYMBOL_ACLASS_BITS
));
907 /* The methods needed to implement LOC_COMPUTED. These methods can
908 use the symbol's .aux_value for additional per-symbol information.
910 At present this is only used to implement location expressions. */
912 struct symbol_computed_ops
915 /* Return the value of the variable SYMBOL, relative to the stack
916 frame FRAME. If the variable has been optimized out, return
919 Iff `read_needs_frame (SYMBOL)' is not SYMBOL_NEEDS_FRAME, then
920 FRAME may be zero. */
922 struct value
*(*read_variable
) (struct symbol
* symbol
,
923 struct frame_info
* frame
);
925 /* Read variable SYMBOL like read_variable at (callee) FRAME's function
926 entry. SYMBOL should be a function parameter, otherwise
927 NO_ENTRY_VALUE_ERROR will be thrown. */
928 struct value
*(*read_variable_at_entry
) (struct symbol
*symbol
,
929 struct frame_info
*frame
);
931 /* Find the "symbol_needs_kind" value for the given symbol. This
932 value determines whether reading the symbol needs memory (e.g., a
933 global variable), just registers (a thread-local), or a frame (a
935 enum symbol_needs_kind (*get_symbol_read_needs
) (struct symbol
* symbol
);
937 /* Write to STREAM a natural-language description of the location of
938 SYMBOL, in the context of ADDR. */
939 void (*describe_location
) (struct symbol
* symbol
, CORE_ADDR addr
,
940 struct ui_file
* stream
);
942 /* Non-zero if this symbol's address computation is dependent on PC. */
943 unsigned char location_has_loclist
;
945 /* Tracepoint support. Append bytecodes to the tracepoint agent
946 expression AX that push the address of the object SYMBOL. Set
947 VALUE appropriately. Note --- for objects in registers, this
948 needn't emit any code; as long as it sets VALUE properly, then
949 the caller will generate the right code in the process of
950 treating this as an lvalue or rvalue. */
952 void (*tracepoint_var_ref
) (struct symbol
*symbol
, struct agent_expr
*ax
,
953 struct axs_value
*value
);
955 /* Generate C code to compute the location of SYMBOL. The C code is
956 emitted to STREAM. GDBARCH is the current architecture and PC is
957 the PC at which SYMBOL's location should be evaluated.
958 REGISTERS_USED is a vector indexed by register number; the
959 generator function should set an element in this vector if the
960 corresponding register is needed by the location computation.
961 The generated C code must assign the location to a local
962 variable; this variable's name is RESULT_NAME. */
964 void (*generate_c_location
) (struct symbol
*symbol
, string_file
&stream
,
965 struct gdbarch
*gdbarch
,
966 unsigned char *registers_used
,
967 CORE_ADDR pc
, const char *result_name
);
971 /* The methods needed to implement LOC_BLOCK for inferior functions.
972 These methods can use the symbol's .aux_value for additional
973 per-symbol information. */
975 struct symbol_block_ops
977 /* Fill in *START and *LENGTH with DWARF block data of function
978 FRAMEFUNC valid for inferior context address PC. Set *LENGTH to
979 zero if such location is not valid for PC; *START is left
980 uninitialized in such case. */
981 void (*find_frame_base_location
) (struct symbol
*framefunc
, CORE_ADDR pc
,
982 const gdb_byte
**start
, size_t *length
);
984 /* Return the frame base address. FRAME is the frame for which we want to
985 compute the base address while FRAMEFUNC is the symbol for the
986 corresponding function. Return 0 on failure (FRAMEFUNC may not hold the
987 information we need).
989 This method is designed to work with static links (nested functions
990 handling). Static links are function properties whose evaluation returns
991 the frame base address for the enclosing frame. However, there are
992 multiple definitions for "frame base": the content of the frame base
993 register, the CFA as defined by DWARF unwinding information, ...
995 So this specific method is supposed to compute the frame base address such
996 as for nested fuctions, the static link computes the same address. For
997 instance, considering DWARF debugging information, the static link is
998 computed with DW_AT_static_link and this method must be used to compute
999 the corresponding DW_AT_frame_base attribute. */
1000 CORE_ADDR (*get_frame_base
) (struct symbol
*framefunc
,
1001 struct frame_info
*frame
);
1004 /* Functions used with LOC_REGISTER and LOC_REGPARM_ADDR. */
1006 struct symbol_register_ops
1008 int (*register_number
) (struct symbol
*symbol
, struct gdbarch
*gdbarch
);
1011 /* Objects of this type are used to find the address class and the
1012 various computed ops vectors of a symbol. */
1016 enum address_class aclass
;
1018 /* Used with LOC_COMPUTED. */
1019 const struct symbol_computed_ops
*ops_computed
;
1021 /* Used with LOC_BLOCK. */
1022 const struct symbol_block_ops
*ops_block
;
1024 /* Used with LOC_REGISTER and LOC_REGPARM_ADDR. */
1025 const struct symbol_register_ops
*ops_register
;
1028 /* struct symbol has some subclasses. This enum is used to
1029 differentiate between them. */
1031 enum symbol_subclass_kind
1033 /* Plain struct symbol. */
1036 /* struct template_symbol. */
1039 /* struct rust_vtable_symbol. */
1043 /* This structure is space critical. See space comments at the top. */
1048 /* The general symbol info required for all types of symbols. */
1050 struct general_symbol_info ginfo
;
1052 /* Data type of value */
1056 /* The owner of this symbol.
1057 Which one to use is defined by symbol.is_objfile_owned. */
1061 /* The symbol table containing this symbol. This is the file associated
1062 with LINE. It can be NULL during symbols read-in but it is never NULL
1063 during normal operation. */
1064 struct symtab
*symtab
;
1066 /* For types defined by the architecture. */
1067 struct gdbarch
*arch
;
1072 ENUM_BITFIELD(domain_enum_tag
) domain
: SYMBOL_DOMAIN_BITS
;
1074 /* Address class. This holds an index into the 'symbol_impls'
1075 table. The actual enum address_class value is stored there,
1076 alongside any per-class ops vectors. */
1078 unsigned int aclass_index
: SYMBOL_ACLASS_BITS
;
1080 /* If non-zero then symbol is objfile-owned, use owner.symtab.
1081 Otherwise symbol is arch-owned, use owner.arch. */
1083 unsigned int is_objfile_owned
: 1;
1085 /* Whether this is an argument. */
1087 unsigned is_argument
: 1;
1089 /* Whether this is an inlined function (class LOC_BLOCK only). */
1090 unsigned is_inlined
: 1;
1092 /* The concrete type of this symbol. */
1094 ENUM_BITFIELD (symbol_subclass_kind
) subclass
: 2;
1096 /* Line number of this symbol's definition, except for inlined
1097 functions. For an inlined function (class LOC_BLOCK and
1098 SYMBOL_INLINED set) this is the line number of the function's call
1099 site. Inlined function symbols are not definitions, and they are
1100 never found by symbol table lookup.
1101 If this symbol is arch-owned, LINE shall be zero.
1103 FIXME: Should we really make the assumption that nobody will try
1104 to debug files longer than 64K lines? What about machine
1105 generated programs? */
1107 unsigned short line
;
1109 /* An arbitrary data pointer, allowing symbol readers to record
1110 additional information on a per-symbol basis. Note that this data
1111 must be allocated using the same obstack as the symbol itself. */
1112 /* So far it is only used by:
1113 LOC_COMPUTED: to find the location information
1114 LOC_BLOCK (DWARF2 function): information used internally by the
1115 DWARF 2 code --- specifically, the location expression for the frame
1116 base for this function. */
1117 /* FIXME drow/2003-02-21: For the LOC_BLOCK case, it might be better
1118 to add a magic symbol to the block containing this information,
1119 or to have a generic debug info annotation slot for symbols. */
1123 struct symbol
*hash_next
;
1126 /* Several lookup functions return both a symbol and the block in which the
1127 symbol is found. This structure is used in these cases. */
1131 /* The symbol that was found, or NULL if no symbol was found. */
1132 struct symbol
*symbol
;
1134 /* If SYMBOL is not NULL, then this is the block in which the symbol is
1136 const struct block
*block
;
1139 extern const struct symbol_impl
*symbol_impls
;
1141 /* For convenience. All fields are NULL. This means "there is no
1143 extern const struct block_symbol null_block_symbol
;
1145 /* Note: There is no accessor macro for symbol.owner because it is
1148 #define SYMBOL_DOMAIN(symbol) (symbol)->domain
1149 #define SYMBOL_IMPL(symbol) (symbol_impls[(symbol)->aclass_index])
1150 #define SYMBOL_ACLASS_INDEX(symbol) (symbol)->aclass_index
1151 #define SYMBOL_CLASS(symbol) (SYMBOL_IMPL (symbol).aclass)
1152 #define SYMBOL_OBJFILE_OWNED(symbol) ((symbol)->is_objfile_owned)
1153 #define SYMBOL_IS_ARGUMENT(symbol) (symbol)->is_argument
1154 #define SYMBOL_INLINED(symbol) (symbol)->is_inlined
1155 #define SYMBOL_IS_CPLUS_TEMPLATE_FUNCTION(symbol) \
1156 (((symbol)->subclass) == SYMBOL_TEMPLATE)
1157 #define SYMBOL_TYPE(symbol) (symbol)->type
1158 #define SYMBOL_LINE(symbol) (symbol)->line
1159 #define SYMBOL_COMPUTED_OPS(symbol) (SYMBOL_IMPL (symbol).ops_computed)
1160 #define SYMBOL_BLOCK_OPS(symbol) (SYMBOL_IMPL (symbol).ops_block)
1161 #define SYMBOL_REGISTER_OPS(symbol) (SYMBOL_IMPL (symbol).ops_register)
1162 #define SYMBOL_LOCATION_BATON(symbol) (symbol)->aux_value
1164 extern int register_symbol_computed_impl (enum address_class
,
1165 const struct symbol_computed_ops
*);
1167 extern int register_symbol_block_impl (enum address_class aclass
,
1168 const struct symbol_block_ops
*ops
);
1170 extern int register_symbol_register_impl (enum address_class
,
1171 const struct symbol_register_ops
*);
1173 /* Return the OBJFILE of SYMBOL.
1174 It is an error to call this if symbol.is_objfile_owned is false, which
1175 only happens for architecture-provided types. */
1177 extern struct objfile
*symbol_objfile (const struct symbol
*symbol
);
1179 /* Return the ARCH of SYMBOL. */
1181 extern struct gdbarch
*symbol_arch (const struct symbol
*symbol
);
1183 /* Return the SYMTAB of SYMBOL.
1184 It is an error to call this if symbol.is_objfile_owned is false, which
1185 only happens for architecture-provided types. */
1187 extern struct symtab
*symbol_symtab (const struct symbol
*symbol
);
1189 /* Set the symtab of SYMBOL to SYMTAB.
1190 It is an error to call this if symbol.is_objfile_owned is false, which
1191 only happens for architecture-provided types. */
1193 extern void symbol_set_symtab (struct symbol
*symbol
, struct symtab
*symtab
);
1195 /* An instance of this type is used to represent a C++ template
1196 function. A symbol is really of this type iff
1197 SYMBOL_IS_CPLUS_TEMPLATE_FUNCTION is true. */
1199 struct template_symbol
: public symbol
1201 /* The number of template arguments. */
1202 int n_template_arguments
;
1204 /* The template arguments. This is an array with
1205 N_TEMPLATE_ARGUMENTS elements. */
1206 struct symbol
**template_arguments
;
1209 /* A symbol that represents a Rust virtual table object. */
1211 struct rust_vtable_symbol
: public symbol
1213 /* The concrete type for which this vtable was created; that is, in
1214 "impl Trait for Type", this is "Type". */
1215 struct type
*concrete_type
;
1219 /* Each item represents a line-->pc (or the reverse) mapping. This is
1220 somewhat more wasteful of space than one might wish, but since only
1221 the files which are actually debugged are read in to core, we don't
1222 waste much space. */
1224 struct linetable_entry
1230 /* The order of entries in the linetable is significant. They should
1231 be sorted by increasing values of the pc field. If there is more than
1232 one entry for a given pc, then I'm not sure what should happen (and
1233 I not sure whether we currently handle it the best way).
1235 Example: a C for statement generally looks like this
1237 10 0x100 - for the init/test part of a for stmt.
1240 10 0x400 - for the increment part of a for stmt.
1242 If an entry has a line number of zero, it marks the start of a PC
1243 range for which no line number information is available. It is
1244 acceptable, though wasteful of table space, for such a range to be
1251 /* Actually NITEMS elements. If you don't like this use of the
1252 `struct hack', you can shove it up your ANSI (seriously, if the
1253 committee tells us how to do it, we can probably go along). */
1254 struct linetable_entry item
[1];
1257 /* How to relocate the symbols from each section in a symbol file.
1258 Each struct contains an array of offsets.
1259 The ordering and meaning of the offsets is file-type-dependent;
1260 typically it is indexed by section numbers or symbol types or
1261 something like that.
1263 To give us flexibility in changing the internal representation
1264 of these offsets, the ANOFFSET macro must be used to insert and
1265 extract offset values in the struct. */
1267 struct section_offsets
1269 CORE_ADDR offsets
[1]; /* As many as needed. */
1272 #define ANOFFSET(secoff, whichone) \
1274 ? (internal_error (__FILE__, __LINE__, \
1275 _("Section index is uninitialized")), -1) \
1276 : secoff->offsets[whichone])
1278 /* The size of a section_offsets table for N sections. */
1279 #define SIZEOF_N_SECTION_OFFSETS(n) \
1280 (sizeof (struct section_offsets) \
1281 + sizeof (((struct section_offsets *) 0)->offsets) * ((n)-1))
1283 /* Each source file or header is represented by a struct symtab.
1284 The name "symtab" is historical, another name for it is "filetab".
1285 These objects are chained through the `next' field. */
1289 /* Unordered chain of all filetabs in the compunit, with the exception
1290 that the "main" source file is the first entry in the list. */
1292 struct symtab
*next
;
1294 /* Backlink to containing compunit symtab. */
1296 struct compunit_symtab
*compunit_symtab
;
1298 /* Table mapping core addresses to line numbers for this file.
1299 Can be NULL if none. Never shared between different symtabs. */
1301 struct linetable
*linetable
;
1303 /* Name of this source file. This pointer is never NULL. */
1305 const char *filename
;
1307 /* Total number of lines found in source file. */
1311 /* line_charpos[N] is the position of the (N-1)th line of the
1312 source file. "position" means something we can lseek() to; it
1313 is not guaranteed to be useful any other way. */
1317 /* Language of this source file. */
1319 enum language language
;
1321 /* Full name of file as found by searching the source path.
1322 NULL if not yet known. */
1327 #define SYMTAB_COMPUNIT(symtab) ((symtab)->compunit_symtab)
1328 #define SYMTAB_LINETABLE(symtab) ((symtab)->linetable)
1329 #define SYMTAB_LANGUAGE(symtab) ((symtab)->language)
1330 #define SYMTAB_BLOCKVECTOR(symtab) \
1331 COMPUNIT_BLOCKVECTOR (SYMTAB_COMPUNIT (symtab))
1332 #define SYMTAB_OBJFILE(symtab) \
1333 COMPUNIT_OBJFILE (SYMTAB_COMPUNIT (symtab))
1334 #define SYMTAB_PSPACE(symtab) (SYMTAB_OBJFILE (symtab)->pspace)
1335 #define SYMTAB_DIRNAME(symtab) \
1336 COMPUNIT_DIRNAME (SYMTAB_COMPUNIT (symtab))
1338 typedef struct symtab
*symtab_ptr
;
1339 DEF_VEC_P (symtab_ptr
);
1341 /* Compunit symtabs contain the actual "symbol table", aka blockvector, as well
1342 as the list of all source files (what gdb has historically associated with
1344 Additional information is recorded here that is common to all symtabs in a
1345 compilation unit (DWARF or otherwise).
1348 For the case of a program built out of these files:
1357 This is recorded as:
1359 objfile -> foo.c(cu) -> bar.c(cu) -> NULL
1373 where "foo.c(cu)" and "bar.c(cu)" are struct compunit_symtab objects,
1374 and the files foo.c, etc. are struct symtab objects. */
1376 struct compunit_symtab
1378 /* Unordered chain of all compunit symtabs of this objfile. */
1379 struct compunit_symtab
*next
;
1381 /* Object file from which this symtab information was read. */
1382 struct objfile
*objfile
;
1384 /* Name of the symtab.
1385 This is *not* intended to be a usable filename, and is
1386 for debugging purposes only. */
1389 /* Unordered list of file symtabs, except that by convention the "main"
1390 source file (e.g., .c, .cc) is guaranteed to be first.
1391 Each symtab is a file, either the "main" source file (e.g., .c, .cc)
1392 or header (e.g., .h). */
1393 struct symtab
*filetabs
;
1395 /* Last entry in FILETABS list.
1396 Subfiles are added to the end of the list so they accumulate in order,
1397 with the main source subfile living at the front.
1398 The main reason is so that the main source file symtab is at the head
1399 of the list, and the rest appear in order for debugging convenience. */
1400 struct symtab
*last_filetab
;
1402 /* Non-NULL string that identifies the format of the debugging information,
1403 such as "stabs", "dwarf 1", "dwarf 2", "coff", etc. This is mostly useful
1404 for automated testing of gdb but may also be information that is
1405 useful to the user. */
1406 const char *debugformat
;
1408 /* String of producer version information, or NULL if we don't know. */
1409 const char *producer
;
1411 /* Directory in which it was compiled, or NULL if we don't know. */
1412 const char *dirname
;
1414 /* List of all symbol scope blocks for this symtab. It is shared among
1415 all symtabs in a given compilation unit. */
1416 const struct blockvector
*blockvector
;
1418 /* Section in objfile->section_offsets for the blockvector and
1419 the linetable. Probably always SECT_OFF_TEXT. */
1420 int block_line_section
;
1422 /* Symtab has been compiled with both optimizations and debug info so that
1423 GDB may stop skipping prologues as variables locations are valid already
1424 at function entry points. */
1425 unsigned int locations_valid
: 1;
1427 /* DWARF unwinder for this CU is valid even for epilogues (PC at the return
1428 instruction). This is supported by GCC since 4.5.0. */
1429 unsigned int epilogue_unwind_valid
: 1;
1431 /* struct call_site entries for this compilation unit or NULL. */
1432 htab_t call_site_htab
;
1434 /* The macro table for this symtab. Like the blockvector, this
1435 is shared between different symtabs in a given compilation unit.
1436 It's debatable whether it *should* be shared among all the symtabs in
1437 the given compilation unit, but it currently is. */
1438 struct macro_table
*macro_table
;
1440 /* If non-NULL, then this points to a NULL-terminated vector of
1441 included compunits. When searching the static or global
1442 block of this compunit, the corresponding block of all
1443 included compunits will also be searched. Note that this
1444 list must be flattened -- the symbol reader is responsible for
1445 ensuring that this vector contains the transitive closure of all
1446 included compunits. */
1447 struct compunit_symtab
**includes
;
1449 /* If this is an included compunit, this points to one includer
1450 of the table. This user is considered the canonical compunit
1451 containing this one. An included compunit may itself be
1452 included by another. */
1453 struct compunit_symtab
*user
;
1456 #define COMPUNIT_OBJFILE(cust) ((cust)->objfile)
1457 #define COMPUNIT_FILETABS(cust) ((cust)->filetabs)
1458 #define COMPUNIT_DEBUGFORMAT(cust) ((cust)->debugformat)
1459 #define COMPUNIT_PRODUCER(cust) ((cust)->producer)
1460 #define COMPUNIT_DIRNAME(cust) ((cust)->dirname)
1461 #define COMPUNIT_BLOCKVECTOR(cust) ((cust)->blockvector)
1462 #define COMPUNIT_BLOCK_LINE_SECTION(cust) ((cust)->block_line_section)
1463 #define COMPUNIT_LOCATIONS_VALID(cust) ((cust)->locations_valid)
1464 #define COMPUNIT_EPILOGUE_UNWIND_VALID(cust) ((cust)->epilogue_unwind_valid)
1465 #define COMPUNIT_CALL_SITE_HTAB(cust) ((cust)->call_site_htab)
1466 #define COMPUNIT_MACRO_TABLE(cust) ((cust)->macro_table)
1468 /* Iterate over all file tables (struct symtab) within a compunit. */
1470 #define ALL_COMPUNIT_FILETABS(cu, s) \
1471 for ((s) = (cu) -> filetabs; (s) != NULL; (s) = (s) -> next)
1473 /* Return the primary symtab of CUST. */
1475 extern struct symtab
*
1476 compunit_primary_filetab (const struct compunit_symtab
*cust
);
1478 /* Return the language of CUST. */
1480 extern enum language
compunit_language (const struct compunit_symtab
*cust
);
1482 typedef struct compunit_symtab
*compunit_symtab_ptr
;
1483 DEF_VEC_P (compunit_symtab_ptr
);
1487 /* The virtual function table is now an array of structures which have the
1488 form { int16 offset, delta; void *pfn; }.
1490 In normal virtual function tables, OFFSET is unused.
1491 DELTA is the amount which is added to the apparent object's base
1492 address in order to point to the actual object to which the
1493 virtual function should be applied.
1494 PFN is a pointer to the virtual function.
1496 Note that this macro is g++ specific (FIXME). */
1498 #define VTBL_FNADDR_OFFSET 2
1500 /* External variables and functions for the objects described above. */
1502 /* True if we are nested inside psymtab_to_symtab. */
1504 extern int currently_reading_symtab
;
1506 /* symtab.c lookup functions */
1508 extern const char multiple_symbols_ask
[];
1509 extern const char multiple_symbols_all
[];
1510 extern const char multiple_symbols_cancel
[];
1512 const char *multiple_symbols_select_mode (void);
1514 int symbol_matches_domain (enum language symbol_language
,
1515 domain_enum symbol_domain
,
1516 domain_enum domain
);
1518 /* lookup a symbol table by source file name. */
1520 extern struct symtab
*lookup_symtab (const char *);
1522 /* An object of this type is passed as the 'is_a_field_of_this'
1523 argument to lookup_symbol and lookup_symbol_in_language. */
1525 struct field_of_this_result
1527 /* The type in which the field was found. If this is NULL then the
1528 symbol was not found in 'this'. If non-NULL, then one of the
1529 other fields will be non-NULL as well. */
1533 /* If the symbol was found as an ordinary field of 'this', then this
1534 is non-NULL and points to the particular field. */
1536 struct field
*field
;
1538 /* If the symbol was found as a function field of 'this', then this
1539 is non-NULL and points to the particular field. */
1541 struct fn_fieldlist
*fn_field
;
1544 /* Find the definition for a specified symbol name NAME
1545 in domain DOMAIN in language LANGUAGE, visible from lexical block BLOCK
1546 if non-NULL or from global/static blocks if BLOCK is NULL.
1547 Returns the struct symbol pointer, or NULL if no symbol is found.
1548 C++: if IS_A_FIELD_OF_THIS is non-NULL on entry, check to see if
1549 NAME is a field of the current implied argument `this'. If so fill in the
1550 fields of IS_A_FIELD_OF_THIS, otherwise the fields are set to NULL.
1551 The symbol's section is fixed up if necessary. */
1553 extern struct block_symbol
1554 lookup_symbol_in_language (const char *,
1555 const struct block
*,
1558 struct field_of_this_result
*);
1560 /* Same as lookup_symbol_in_language, but using the current language. */
1562 extern struct block_symbol
lookup_symbol (const char *,
1563 const struct block
*,
1565 struct field_of_this_result
*);
1567 /* Find the definition for a specified symbol search name in domain
1568 DOMAIN, visible from lexical block BLOCK if non-NULL or from
1569 global/static blocks if BLOCK is NULL. The passed-in search name
1570 should not come from the user; instead it should already be a
1571 search name as retrieved from a
1572 SYMBOL_SEARCH_NAME/MSYMBOL_SEARCH_NAME call. See definition of
1573 symbol_name_match_type::SEARCH_NAME. Returns the struct symbol
1574 pointer, or NULL if no symbol is found. The symbol's section is
1575 fixed up if necessary. */
1577 extern struct block_symbol
lookup_symbol_search_name (const char *search_name
,
1578 const struct block
*block
,
1579 domain_enum domain
);
1581 /* A default version of lookup_symbol_nonlocal for use by languages
1582 that can't think of anything better to do.
1583 This implements the C lookup rules. */
1585 extern struct block_symbol
1586 basic_lookup_symbol_nonlocal (const struct language_defn
*langdef
,
1588 const struct block
*,
1591 /* Some helper functions for languages that need to write their own
1592 lookup_symbol_nonlocal functions. */
1594 /* Lookup a symbol in the static block associated to BLOCK, if there
1595 is one; do nothing if BLOCK is NULL or a global block.
1596 Upon success fixes up the symbol's section if necessary. */
1598 extern struct block_symbol
1599 lookup_symbol_in_static_block (const char *name
,
1600 const struct block
*block
,
1601 const domain_enum domain
);
1603 /* Search all static file-level symbols for NAME from DOMAIN.
1604 Upon success fixes up the symbol's section if necessary. */
1606 extern struct block_symbol
lookup_static_symbol (const char *name
,
1607 const domain_enum domain
);
1609 /* Lookup a symbol in all files' global blocks.
1611 If BLOCK is non-NULL then it is used for two things:
1612 1) If a target-specific lookup routine for libraries exists, then use the
1613 routine for the objfile of BLOCK, and
1614 2) The objfile of BLOCK is used to assist in determining the search order
1615 if the target requires it.
1616 See gdbarch_iterate_over_objfiles_in_search_order.
1618 Upon success fixes up the symbol's section if necessary. */
1620 extern struct block_symbol
1621 lookup_global_symbol (const char *name
,
1622 const struct block
*block
,
1623 const domain_enum domain
);
1625 /* Lookup a symbol in block BLOCK.
1626 Upon success fixes up the symbol's section if necessary. */
1628 extern struct symbol
*
1629 lookup_symbol_in_block (const char *name
,
1630 symbol_name_match_type match_type
,
1631 const struct block
*block
,
1632 const domain_enum domain
);
1634 /* Look up the `this' symbol for LANG in BLOCK. Return the symbol if
1635 found, or NULL if not found. */
1637 extern struct block_symbol
1638 lookup_language_this (const struct language_defn
*lang
,
1639 const struct block
*block
);
1641 /* Lookup a [struct, union, enum] by name, within a specified block. */
1643 extern struct type
*lookup_struct (const char *, const struct block
*);
1645 extern struct type
*lookup_union (const char *, const struct block
*);
1647 extern struct type
*lookup_enum (const char *, const struct block
*);
1649 /* from blockframe.c: */
1651 /* lookup the function symbol corresponding to the address. */
1653 extern struct symbol
*find_pc_function (CORE_ADDR
);
1655 /* lookup the function corresponding to the address and section. */
1657 extern struct symbol
*find_pc_sect_function (CORE_ADDR
, struct obj_section
*);
1659 /* Find the symbol at the given address. Returns NULL if no symbol
1660 found. Only exact matches for ADDRESS are considered. */
1662 extern struct symbol
*find_symbol_at_address (CORE_ADDR
);
1664 extern int find_pc_partial_function_gnu_ifunc (CORE_ADDR pc
, const char **name
,
1667 int *is_gnu_ifunc_p
);
1669 /* lookup function from address, return name, start addr and end addr. */
1671 extern int find_pc_partial_function (CORE_ADDR
, const char **, CORE_ADDR
*,
1674 extern void clear_pc_function_cache (void);
1676 /* Expand symtab containing PC, SECTION if not already expanded. */
1678 extern void expand_symtab_containing_pc (CORE_ADDR
, struct obj_section
*);
1680 /* lookup full symbol table by address. */
1682 extern struct compunit_symtab
*find_pc_compunit_symtab (CORE_ADDR
);
1684 /* lookup full symbol table by address and section. */
1686 extern struct compunit_symtab
*
1687 find_pc_sect_compunit_symtab (CORE_ADDR
, struct obj_section
*);
1689 extern int find_pc_line_pc_range (CORE_ADDR
, CORE_ADDR
*, CORE_ADDR
*);
1691 extern void reread_symbols (void);
1693 /* Look up a type named NAME in STRUCT_DOMAIN in the current language.
1694 The type returned must not be opaque -- i.e., must have at least one field
1697 extern struct type
*lookup_transparent_type (const char *);
1699 extern struct type
*basic_lookup_transparent_type (const char *);
1701 /* Macro for name of symbol to indicate a file compiled with gcc. */
1702 #ifndef GCC_COMPILED_FLAG_SYMBOL
1703 #define GCC_COMPILED_FLAG_SYMBOL "gcc_compiled."
1706 /* Macro for name of symbol to indicate a file compiled with gcc2. */
1707 #ifndef GCC2_COMPILED_FLAG_SYMBOL
1708 #define GCC2_COMPILED_FLAG_SYMBOL "gcc2_compiled."
1711 extern int in_gnu_ifunc_stub (CORE_ADDR pc
);
1713 /* Functions for resolving STT_GNU_IFUNC symbols which are implemented only
1714 for ELF symbol files. */
1716 struct gnu_ifunc_fns
1718 /* See elf_gnu_ifunc_resolve_addr for its real implementation. */
1719 CORE_ADDR (*gnu_ifunc_resolve_addr
) (struct gdbarch
*gdbarch
, CORE_ADDR pc
);
1721 /* See elf_gnu_ifunc_resolve_name for its real implementation. */
1722 int (*gnu_ifunc_resolve_name
) (const char *function_name
,
1723 CORE_ADDR
*function_address_p
);
1725 /* See elf_gnu_ifunc_resolver_stop for its real implementation. */
1726 void (*gnu_ifunc_resolver_stop
) (struct breakpoint
*b
);
1728 /* See elf_gnu_ifunc_resolver_return_stop for its real implementation. */
1729 void (*gnu_ifunc_resolver_return_stop
) (struct breakpoint
*b
);
1732 #define gnu_ifunc_resolve_addr gnu_ifunc_fns_p->gnu_ifunc_resolve_addr
1733 #define gnu_ifunc_resolve_name gnu_ifunc_fns_p->gnu_ifunc_resolve_name
1734 #define gnu_ifunc_resolver_stop gnu_ifunc_fns_p->gnu_ifunc_resolver_stop
1735 #define gnu_ifunc_resolver_return_stop \
1736 gnu_ifunc_fns_p->gnu_ifunc_resolver_return_stop
1738 extern const struct gnu_ifunc_fns
*gnu_ifunc_fns_p
;
1740 extern CORE_ADDR
find_solib_trampoline_target (struct frame_info
*, CORE_ADDR
);
1742 struct symtab_and_line
1744 /* The program space of this sal. */
1745 struct program_space
*pspace
= NULL
;
1747 struct symtab
*symtab
= NULL
;
1748 struct symbol
*symbol
= NULL
;
1749 struct obj_section
*section
= NULL
;
1750 /* Line number. Line numbers start at 1 and proceed through symtab->nlines.
1751 0 is never a valid line number; it is used to indicate that line number
1752 information is not available. */
1757 bool explicit_pc
= false;
1758 bool explicit_line
= false;
1760 /* The probe associated with this symtab_and_line. */
1762 /* If PROBE is not NULL, then this is the objfile in which the probe
1764 struct objfile
*objfile
= NULL
;
1769 /* Given a pc value, return line number it is in. Second arg nonzero means
1770 if pc is on the boundary use the previous statement's line number. */
1772 extern struct symtab_and_line
find_pc_line (CORE_ADDR
, int);
1774 /* Same function, but specify a section as well as an address. */
1776 extern struct symtab_and_line
find_pc_sect_line (CORE_ADDR
,
1777 struct obj_section
*, int);
1779 /* Wrapper around find_pc_line to just return the symtab. */
1781 extern struct symtab
*find_pc_line_symtab (CORE_ADDR
);
1783 /* Given a symtab and line number, return the pc there. */
1785 extern int find_line_pc (struct symtab
*, int, CORE_ADDR
*);
1787 extern int find_line_pc_range (struct symtab_and_line
, CORE_ADDR
*,
1790 extern void resolve_sal_pc (struct symtab_and_line
*);
1794 extern void clear_solib (void);
1798 extern int identify_source_line (struct symtab
*, int, int, CORE_ADDR
);
1800 /* Flags passed as 4th argument to print_source_lines. */
1802 enum print_source_lines_flag
1804 /* Do not print an error message. */
1805 PRINT_SOURCE_LINES_NOERROR
= (1 << 0),
1807 /* Print the filename in front of the source lines. */
1808 PRINT_SOURCE_LINES_FILENAME
= (1 << 1)
1810 DEF_ENUM_FLAGS_TYPE (enum print_source_lines_flag
, print_source_lines_flags
);
1812 extern void print_source_lines (struct symtab
*, int, int,
1813 print_source_lines_flags
);
1815 extern void forget_cached_source_info_for_objfile (struct objfile
*);
1816 extern void forget_cached_source_info (void);
1818 extern void select_source_symtab (struct symtab
*);
1820 /* The reason we're calling into a completion match list collector
1822 enum class complete_symbol_mode
1824 /* Completing an expression. */
1827 /* Completing a linespec. */
1831 extern void default_collect_symbol_completion_matches_break_on
1832 (completion_tracker
&tracker
,
1833 complete_symbol_mode mode
,
1834 symbol_name_match_type name_match_type
,
1835 const char *text
, const char *word
, const char *break_on
,
1836 enum type_code code
);
1837 extern void default_collect_symbol_completion_matches
1838 (completion_tracker
&tracker
,
1839 complete_symbol_mode
,
1840 symbol_name_match_type name_match_type
,
1844 extern void collect_symbol_completion_matches
1845 (completion_tracker
&tracker
,
1846 complete_symbol_mode mode
,
1847 symbol_name_match_type name_match_type
,
1848 const char *, const char *);
1849 extern void collect_symbol_completion_matches_type (completion_tracker
&tracker
,
1850 const char *, const char *,
1853 extern void collect_file_symbol_completion_matches
1854 (completion_tracker
&tracker
,
1855 complete_symbol_mode
,
1856 symbol_name_match_type name_match_type
,
1857 const char *, const char *, const char *);
1859 extern completion_list
1860 make_source_files_completion_list (const char *, const char *);
1862 /* Return whether SYM is a function/method, as opposed to a data symbol. */
1864 extern bool symbol_is_function_or_method (symbol
*sym
);
1866 /* Return whether MSYMBOL is a function/method, as opposed to a data
1869 extern bool symbol_is_function_or_method (minimal_symbol
*msymbol
);
1871 /* Return whether SYM should be skipped in completion mode MODE. In
1872 linespec mode, we're only interested in functions/methods. */
1874 template<typename Symbol
>
1876 completion_skip_symbol (complete_symbol_mode mode
, Symbol
*sym
)
1878 return (mode
== complete_symbol_mode::LINESPEC
1879 && !symbol_is_function_or_method (sym
));
1884 int matching_obj_sections (struct obj_section
*, struct obj_section
*);
1886 extern struct symtab
*find_line_symtab (struct symtab
*, int, int *, int *);
1888 extern struct symtab_and_line
find_function_start_sal (struct symbol
*sym
,
1891 extern void skip_prologue_sal (struct symtab_and_line
*);
1895 extern CORE_ADDR
skip_prologue_using_sal (struct gdbarch
*gdbarch
,
1896 CORE_ADDR func_addr
);
1898 extern struct symbol
*fixup_symbol_section (struct symbol
*,
1901 /* If MSYMBOL is an text symbol, look for a function debug symbol with
1902 the same address. Returns NULL if not found. This is necessary in
1903 case a function is an alias to some other function, because debug
1904 information is only emitted for the alias target function's
1905 definition, not for the alias. */
1906 extern symbol
*find_function_alias_target (bound_minimal_symbol msymbol
);
1908 /* Symbol searching */
1909 /* Note: struct symbol_search, search_symbols, et.al. are declared here,
1910 instead of making them local to symtab.c, for gdbtk's sake. */
1912 /* When using search_symbols, a vector of the following structs is
1914 struct symbol_search
1916 symbol_search (int block_
, struct symbol
*symbol_
)
1920 msymbol
.minsym
= nullptr;
1921 msymbol
.objfile
= nullptr;
1924 symbol_search (int block_
, struct minimal_symbol
*minsym
,
1925 struct objfile
*objfile
)
1929 msymbol
.minsym
= minsym
;
1930 msymbol
.objfile
= objfile
;
1933 bool operator< (const symbol_search
&other
) const
1935 return compare_search_syms (*this, other
) < 0;
1938 bool operator== (const symbol_search
&other
) const
1940 return compare_search_syms (*this, other
) == 0;
1943 /* The block in which the match was found. Could be, for example,
1944 STATIC_BLOCK or GLOBAL_BLOCK. */
1947 /* Information describing what was found.
1949 If symbol is NOT NULL, then information was found for this match. */
1950 struct symbol
*symbol
;
1952 /* If msymbol is non-null, then a match was made on something for
1953 which only minimal_symbols exist. */
1954 struct bound_minimal_symbol msymbol
;
1958 static int compare_search_syms (const symbol_search
&sym_a
,
1959 const symbol_search
&sym_b
);
1962 extern std::vector
<symbol_search
> search_symbols (const char *,
1963 enum search_domain
, int,
1966 /* The name of the ``main'' function.
1967 FIXME: cagney/2001-03-20: Can't make main_name() const since some
1968 of the calling code currently assumes that the string isn't
1970 extern /*const */ char *main_name (void);
1971 extern enum language
main_language (void);
1973 /* Lookup symbol NAME from DOMAIN in MAIN_OBJFILE's global blocks.
1974 This searches MAIN_OBJFILE as well as any associated separate debug info
1975 objfiles of MAIN_OBJFILE.
1976 Upon success fixes up the symbol's section if necessary. */
1978 extern struct block_symbol
1979 lookup_global_symbol_from_objfile (struct objfile
*main_objfile
,
1981 const domain_enum domain
);
1983 /* Return 1 if the supplied producer string matches the ARM RealView
1984 compiler (armcc). */
1985 int producer_is_realview (const char *producer
);
1987 void fixup_section (struct general_symbol_info
*ginfo
,
1988 CORE_ADDR addr
, struct objfile
*objfile
);
1990 /* Look up objfile containing BLOCK. */
1992 struct objfile
*lookup_objfile_from_block (const struct block
*block
);
1994 extern unsigned int symtab_create_debug
;
1996 extern unsigned int symbol_lookup_debug
;
1998 extern int basenames_may_differ
;
2000 int compare_filenames_for_search (const char *filename
,
2001 const char *search_name
);
2003 int compare_glob_filenames_for_search (const char *filename
,
2004 const char *search_name
);
2006 bool iterate_over_some_symtabs (const char *name
,
2007 const char *real_path
,
2008 struct compunit_symtab
*first
,
2009 struct compunit_symtab
*after_last
,
2010 gdb::function_view
<bool (symtab
*)> callback
);
2012 void iterate_over_symtabs (const char *name
,
2013 gdb::function_view
<bool (symtab
*)> callback
);
2016 std::vector
<CORE_ADDR
> find_pcs_for_symtab_line
2017 (struct symtab
*symtab
, int line
, struct linetable_entry
**best_entry
);
2019 /* Prototype for callbacks for LA_ITERATE_OVER_SYMBOLS. The callback
2020 is called once per matching symbol SYM. The callback should return
2021 true to indicate that LA_ITERATE_OVER_SYMBOLS should continue
2022 iterating, or false to indicate that the iteration should end. */
2024 typedef bool (symbol_found_callback_ftype
) (symbol
*sym
);
2026 void iterate_over_symbols (const struct block
*block
,
2027 const lookup_name_info
&name
,
2028 const domain_enum domain
,
2029 gdb::function_view
<symbol_found_callback_ftype
> callback
);
2031 /* Storage type used by demangle_for_lookup. demangle_for_lookup
2032 either returns a const char * pointer that points to either of the
2033 fields of this type, or a pointer to the input NAME. This is done
2034 this way because the underlying functions that demangle_for_lookup
2035 calls either return a std::string (e.g., cp_canonicalize_string) or
2036 a malloc'ed buffer (libiberty's demangled), and we want to avoid
2037 unnecessary reallocation/string copying. */
2038 class demangle_result_storage
2042 /* Swap the std::string storage with STR, and return a pointer to
2043 the beginning of the new string. */
2044 const char *swap_string (std::string
&str
)
2046 std::swap (m_string
, str
);
2047 return m_string
.c_str ();
2050 /* Set the malloc storage to now point at PTR. Any previous malloc
2051 storage is released. */
2052 const char *set_malloc_ptr (char *ptr
)
2054 m_malloc
.reset (ptr
);
2061 std::string m_string
;
2062 gdb::unique_xmalloc_ptr
<char> m_malloc
;
2066 demangle_for_lookup (const char *name
, enum language lang
,
2067 demangle_result_storage
&storage
);
2069 struct symbol
*allocate_symbol (struct objfile
*);
2071 void initialize_objfile_symbol (struct symbol
*);
2073 struct template_symbol
*allocate_template_symbol (struct objfile
*);
2075 /* Test to see if the symbol of language SYMBOL_LANGUAGE specified by
2076 SYMNAME (which is already demangled for C++ symbols) matches
2077 SYM_TEXT in the first SYM_TEXT_LEN characters. If so, add it to
2078 the current completion list. */
2079 void completion_list_add_name (completion_tracker
&tracker
,
2080 language symbol_language
,
2081 const char *symname
,
2082 const lookup_name_info
&lookup_name
,
2083 const char *text
, const char *word
);
2085 #endif /* !defined(SYMTAB_H) */