Fix setting-breakpoints regression on PPC64 (function descriptors)
[deliverable/binutils-gdb.git] / gdb / symtab.h
CommitLineData
c906108c 1/* Symbol table definitions for GDB.
1bac305b 2
61baf725 3 Copyright (C) 1986-2017 Free Software Foundation, Inc.
c906108c 4
c5aa993b 5 This file is part of GDB.
c906108c 6
c5aa993b
JM
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
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
c5aa993b 10 (at your option) any later version.
c906108c 11
c5aa993b
JM
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.
c906108c 16
c5aa993b 17 You should have received a copy of the GNU General Public License
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
19
20#if !defined (SYMTAB_H)
21#define SYMTAB_H 1
22
a014b87a 23#include <array>
67d89901 24#include <vector>
b5ec771e 25#include <string>
49c4e619 26#include "gdb_vecs.h"
2f68a895 27#include "gdbtypes.h"
8d297bbf 28#include "common/enum-flags.h"
14bc53a8 29#include "common/function-view.h"
b5ec771e 30#include "common/gdb_optional.h"
eb3ff9a5 31#include "completer.h"
f8eba3c6 32
5f8a3188 33/* Opaque declarations. */
da3331ec
AC
34struct ui_file;
35struct frame_info;
36struct symbol;
5f8a3188 37struct obstack;
6a2f5abf 38struct objfile;
fe898f56
DC
39struct block;
40struct blockvector;
4c2df51b
DJ
41struct axs_value;
42struct agent_expr;
6c95b8df 43struct program_space;
66a17cb6 44struct language_defn;
4357ac6c 45struct common_block;
06096720
AB
46struct obj_section;
47struct cmd_list_element;
935676c9 48class probe;
b5ec771e
PA
49struct lookup_name_info;
50
51/* How to match a lookup name against a symbol search name. */
52enum class symbol_name_match_type
53{
54 /* Wild matching. Matches unqualified symbol names in all
55 namespace/module/packages, etc. */
56 WILD,
57
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. */
61 FULL,
62
63 /* Expression matching. The same as FULL matching in most
64 languages. The same as WILD matching in Ada. */
65 EXPRESSION,
66};
67
68/* Hash the given symbol search name according to LANGUAGE's
69 rules. */
70extern unsigned int search_name_hash (enum language language,
71 const char *search_name);
72
73/* Ada-specific bits of a lookup_name_info object. This is lazily
74 constructed on demand. */
75
76class ada_lookup_name_info final
77{
78 public:
79 /* Construct. */
80 explicit ada_lookup_name_info (const lookup_name_info &lookup_name);
81
82 /* Compare SYMBOL_SEARCH_NAME with our lookup name, using MATCH_TYPE
83 as name match type. Returns true if there's a match, false
84 otherwise. If non-NULL, store the matching results in MATCH. */
85 bool matches (const char *symbol_search_name,
86 symbol_name_match_type match_type,
87 completion_match *match) const;
88
89 /* The Ada-encoded lookup name. */
90 const std::string &lookup_name () const
91 { return m_encoded_name; }
92
93 /* Return true if we're supposed to be doing a wild match look
94 up. */
95 bool wild_match_p () const
96 { return m_wild_match_p; }
97
98 /* Return true if we're looking up a name inside package
99 Standard. */
100 bool standard_p () const
101 { return m_standard_p; }
102
103 private:
104 /* The Ada-encoded lookup name. */
105 std::string m_encoded_name;
106
107 /* Whether the user-provided lookup name was Ada encoded. If so,
108 then return encoded names in the 'matches' method's 'completion
109 match result' output. */
110 bool m_encoded_p : 1;
111
112 /* True if really doing wild matching. Even if the user requests
113 wild matching, some cases require full matching. */
114 bool m_wild_match_p : 1;
115
116 /* True if doing a verbatim match. This is true if the decoded
117 version of the symbol name is wrapped in '<'/'>'. This is an
118 escape hatch users can use to look up symbols the Ada encoding
119 does not understand. */
120 bool m_verbatim_p : 1;
121
122 /* True if the user specified a symbol name that is inside package
123 Standard. Symbol names inside package Standard are handled
124 specially. We always do a non-wild match of the symbol name
125 without the "standard__" prefix, and only search static and
126 global symbols. This was primarily introduced in order to allow
127 the user to specifically access the standard exceptions using,
128 for instance, Standard.Constraint_Error when Constraint_Error is
129 ambiguous (due to the user defining its own Constraint_Error
130 entity inside its program). */
131 bool m_standard_p : 1;
132};
133
134/* Language-specific bits of a lookup_name_info object, for languages
135 that do name searching using demangled names (C++/D/Go). This is
136 lazily constructed on demand. */
137
138struct demangle_for_lookup_info final
139{
140public:
141 demangle_for_lookup_info (const lookup_name_info &lookup_name,
142 language lang);
143
144 /* The demangled lookup name. */
145 const std::string &lookup_name () const
146 { return m_demangled_name; }
147
148private:
149 /* The demangled lookup name. */
150 std::string m_demangled_name;
151};
152
153/* Object that aggregates all information related to a symbol lookup
154 name. I.e., the name that is matched against the symbol's search
155 name. Caches per-language information so that it doesn't require
156 recomputing it for every symbol comparison, like for example the
157 Ada encoded name and the symbol's name hash for a given language.
158 The object is conceptually immutable once constructed, and thus has
159 no setters. This is to prevent some code path from tweaking some
160 property of the lookup name for some local reason and accidentally
161 altering the results of any continuing search(es).
162 lookup_name_info objects are generally passed around as a const
163 reference to reinforce that. (They're not passed around by value
164 because they're not small.) */
165class lookup_name_info final
166{
167 public:
168 /* Create a new object. */
169 lookup_name_info (std::string name,
170 symbol_name_match_type match_type,
c62446b1
PA
171 bool completion_mode = false,
172 bool ignore_parameters = false)
b5ec771e
PA
173 : m_match_type (match_type),
174 m_completion_mode (completion_mode),
c62446b1 175 m_ignore_parameters (ignore_parameters),
b5ec771e
PA
176 m_name (std::move (name))
177 {}
178
179 /* Getters. See description of each corresponding field. */
180 symbol_name_match_type match_type () const { return m_match_type; }
181 bool completion_mode () const { return m_completion_mode; }
182 const std::string &name () const { return m_name; }
c62446b1
PA
183 const bool ignore_parameters () const { return m_ignore_parameters; }
184
185 /* Return a version of this lookup name that is usable with
186 comparisons against symbols have no parameter info, such as
187 psymbols and GDB index symbols. */
188 lookup_name_info make_ignore_params () const
189 {
190 return lookup_name_info (m_name, m_match_type, m_completion_mode,
191 true /* ignore params */);
192 }
b5ec771e
PA
193
194 /* Get the search name hash for searches in language LANG. */
195 unsigned int search_name_hash (language lang) const
196 {
197 /* Only compute each language's hash once. */
198 if (!m_demangled_hashes_p[lang])
199 {
200 m_demangled_hashes[lang]
201 = ::search_name_hash (lang, language_lookup_name (lang).c_str ());
202 m_demangled_hashes_p[lang] = true;
203 }
204 return m_demangled_hashes[lang];
205 }
206
207 /* Get the search name for searches in language LANG. */
208 const std::string &language_lookup_name (language lang) const
209 {
210 switch (lang)
211 {
212 case language_ada:
213 return ada ().lookup_name ();
214 case language_cplus:
215 return cplus ().lookup_name ();
216 case language_d:
217 return d ().lookup_name ();
218 case language_go:
219 return go ().lookup_name ();
220 default:
221 return m_name;
222 }
223 }
224
225 /* Get the Ada-specific lookup info. */
226 const ada_lookup_name_info &ada () const
227 {
228 maybe_init (m_ada);
229 return *m_ada;
230 }
231
232 /* Get the C++-specific lookup info. */
233 const demangle_for_lookup_info &cplus () const
234 {
235 maybe_init (m_cplus, language_cplus);
236 return *m_cplus;
237 }
238
239 /* Get the D-specific lookup info. */
240 const demangle_for_lookup_info &d () const
241 {
242 maybe_init (m_d, language_d);
243 return *m_d;
244 }
245
246 /* Get the Go-specific lookup info. */
247 const demangle_for_lookup_info &go () const
248 {
249 maybe_init (m_go, language_go);
250 return *m_go;
251 }
252
253 /* Get a reference to a lookup_name_info object that matches any
254 symbol name. */
255 static const lookup_name_info &match_any ();
256
257private:
258 /* Initialize FIELD, if not initialized yet. */
259 template<typename Field, typename... Args>
260 void maybe_init (Field &field, Args&&... args) const
261 {
262 if (!field)
263 field.emplace (*this, std::forward<Args> (args)...);
264 }
265
266 /* The lookup info as passed to the ctor. */
267 symbol_name_match_type m_match_type;
268 bool m_completion_mode;
c62446b1 269 bool m_ignore_parameters;
b5ec771e
PA
270 std::string m_name;
271
272 /* Language-specific info. These fields are filled lazily the first
273 time a lookup is done in the corresponding language. They're
274 mutable because lookup_name_info objects are typically passed
275 around by const reference (see intro), and they're conceptually
276 "cache" that can always be reconstructed from the non-mutable
277 fields. */
278 mutable gdb::optional<ada_lookup_name_info> m_ada;
279 mutable gdb::optional<demangle_for_lookup_info> m_cplus;
280 mutable gdb::optional<demangle_for_lookup_info> m_d;
281 mutable gdb::optional<demangle_for_lookup_info> m_go;
282
283 /* The demangled hashes. Stored in an array with one entry for each
284 possible language. The second array records whether we've
285 already computed the each language's hash. (These are separate
286 arrays instead of a single array of optional<unsigned> to avoid
287 alignment padding). */
288 mutable std::array<unsigned int, nr_languages> m_demangled_hashes;
289 mutable std::array<bool, nr_languages> m_demangled_hashes_p {};
290};
291
292/* Comparison function for completion symbol lookup.
293
294 Returns true if the symbol name matches against LOOKUP_NAME.
295
296 SYMBOL_SEARCH_NAME should be a symbol's "search" name.
297
298 On success and if non-NULL, MATCH is set to point to the symbol
299 name as should be presented to the user as a completion match list
300 element. In most languages, this is the same as the symbol's
301 search name, but in some, like Ada, the display name is dynamically
302 computed within the comparison routine. */
303typedef bool (symbol_name_matcher_ftype)
304 (const char *symbol_search_name,
305 const lookup_name_info &lookup_name,
306 completion_match *match);
c906108c 307
a7f19c79
MC
308/* Some of the structures in this file are space critical.
309 The space-critical structures are:
310
311 struct general_symbol_info
312 struct symbol
313 struct partial_symbol
314
5bccb4d1 315 These structures are laid out to encourage good packing.
a7f19c79
MC
316 They use ENUM_BITFIELD and short int fields, and they order the
317 structure members so that fields less than a word are next
c378eb4e 318 to each other so they can be packed together. */
a7f19c79
MC
319
320/* Rearranged: used ENUM_BITFIELD and rearranged field order in
321 all the space critical structures (plus struct minimal_symbol).
322 Memory usage dropped from 99360768 bytes to 90001408 bytes.
323 I measured this with before-and-after tests of
324 "HEAD-old-gdb -readnow HEAD-old-gdb" and
325 "HEAD-new-gdb -readnow HEAD-old-gdb" on native i686-pc-linux-gnu,
326 red hat linux 8, with LD_LIBRARY_PATH=/usr/lib/debug,
327 typing "maint space 1" at the first command prompt.
328
329 Here is another measurement (from andrew c):
330 # no /usr/lib/debug, just plain glibc, like a normal user
331 gdb HEAD-old-gdb
332 (gdb) break internal_error
333 (gdb) run
334 (gdb) maint internal-error
335 (gdb) backtrace
336 (gdb) maint space 1
337
338 gdb gdb_6_0_branch 2003-08-19 space used: 8896512
339 gdb HEAD 2003-08-19 space used: 8904704
340 gdb HEAD 2003-08-21 space used: 8396800 (+symtab.h)
341 gdb HEAD 2003-08-21 space used: 8265728 (+gdbtypes.h)
342
343 The third line shows the savings from the optimizations in symtab.h.
344 The fourth line shows the savings from the optimizations in
345 gdbtypes.h. Both optimizations are in gdb HEAD now.
346
347 --chastain 2003-08-21 */
348
c906108c
SS
349/* Define a structure for the information that is common to all symbol types,
350 including minimal symbols, partial symbols, and full symbols. In a
351 multilanguage environment, some language specific information may need to
c378eb4e 352 be recorded along with each symbol. */
c906108c 353
c378eb4e 354/* This structure is space critical. See space comments at the top. */
c906108c
SS
355
356struct general_symbol_info
17c5ed2c 357{
22abf04a 358 /* Name of the symbol. This is a required field. Storage for the
4a146b47
EZ
359 name is allocated on the objfile_obstack for the associated
360 objfile. For languages like C++ that make a distinction between
361 the mangled name and demangled name, this is the mangled
362 name. */
c906108c 363
0d5cff50 364 const char *name;
c906108c 365
17c5ed2c
DC
366 /* Value of the symbol. Which member of this union to use, and what
367 it means, depends on what kind of symbol this is and its
368 SYMBOL_CLASS. See comments there for more details. All of these
369 are in host byte order (though what they point to might be in
370 target byte order, e.g. LOC_CONST_BYTES). */
c906108c 371
17c5ed2c
DC
372 union
373 {
12df843f 374 LONGEST ivalue;
c906108c 375
3977b71f 376 const struct block *block;
c906108c 377
d47a1bc1 378 const gdb_byte *bytes;
c906108c 379
17c5ed2c 380 CORE_ADDR address;
c906108c 381
5a352474 382 /* A common block. Used with LOC_COMMON_BLOCK. */
4357ac6c 383
17a40b44 384 const struct common_block *common_block;
4357ac6c 385
c378eb4e 386 /* For opaque typedef struct chain. */
c906108c 387
17c5ed2c
DC
388 struct symbol *chain;
389 }
390 value;
c906108c 391
17c5ed2c 392 /* Since one and only one language can apply, wrap the language specific
29df156d 393 information inside a union. */
c906108c 394
17c5ed2c
DC
395 union
396 {
f85f34ed
TT
397 /* A pointer to an obstack that can be used for storage associated
398 with this symbol. This is only used by Ada, and only when the
399 'ada_mangled' field is zero. */
400 struct obstack *obstack;
401
afa16725 402 /* This is used by languages which wish to store a demangled name.
9c37b5ae 403 currently used by Ada, C++, and Objective C. */
615b3f62 404 const char *demangled_name;
17c5ed2c
DC
405 }
406 language_specific;
c5aa993b 407
17c5ed2c
DC
408 /* Record the source code language that applies to this symbol.
409 This is used to select one of the fields from the language specific
c378eb4e 410 union above. */
c5aa993b 411
51cdc993 412 ENUM_BITFIELD(language) language : LANGUAGE_BITS;
c5aa993b 413
a04a15f5 414 /* This is only used by Ada. If set, then the 'demangled_name' field
f85f34ed
TT
415 of language_specific is valid. Otherwise, the 'obstack' field is
416 valid. */
417 unsigned int ada_mangled : 1;
418
17c5ed2c
DC
419 /* Which section is this symbol in? This is an index into
420 section_offsets for this objfile. Negative means that the symbol
e27d198c 421 does not get relocated relative to a section. */
c5aa993b 422
17c5ed2c 423 short section;
17c5ed2c 424};
c906108c 425
cfc594ee
TT
426extern void symbol_set_demangled_name (struct general_symbol_info *,
427 const char *,
ccde22c0 428 struct obstack *);
b250c185 429
0d5cff50
DE
430extern const char *symbol_get_demangled_name
431 (const struct general_symbol_info *);
b250c185 432
714835d5 433extern CORE_ADDR symbol_overlayed_address (CORE_ADDR, struct obj_section *);
c906108c 434
88cda038 435/* Note that all the following SYMBOL_* macros are used with the
efd66ac6
TT
436 SYMBOL argument being either a partial symbol or
437 a full symbol. Both types have a ginfo field. In particular
33e5013e 438 the SYMBOL_SET_LANGUAGE, SYMBOL_DEMANGLED_NAME, etc.
d6350901 439 macros cannot be entirely substituted by
88cda038
EZ
440 functions, unless the callers are changed to pass in the ginfo
441 field only, instead of the SYMBOL parameter. */
442
c906108c
SS
443#define SYMBOL_VALUE(symbol) (symbol)->ginfo.value.ivalue
444#define SYMBOL_VALUE_ADDRESS(symbol) (symbol)->ginfo.value.address
445#define SYMBOL_VALUE_BYTES(symbol) (symbol)->ginfo.value.bytes
4357ac6c 446#define SYMBOL_VALUE_COMMON_BLOCK(symbol) (symbol)->ginfo.value.common_block
c906108c
SS
447#define SYMBOL_BLOCK_VALUE(symbol) (symbol)->ginfo.value.block
448#define SYMBOL_VALUE_CHAIN(symbol) (symbol)->ginfo.value.chain
449#define SYMBOL_LANGUAGE(symbol) (symbol)->ginfo.language
450#define SYMBOL_SECTION(symbol) (symbol)->ginfo.section
e27d198c
TT
451#define SYMBOL_OBJ_SECTION(objfile, symbol) \
452 (((symbol)->ginfo.section >= 0) \
453 ? (&(((objfile)->sections)[(symbol)->ginfo.section])) \
454 : NULL)
c906108c 455
89aad1f9 456/* Initializes the language dependent portion of a symbol
c378eb4e 457 depending upon the language for the symbol. */
f85f34ed
TT
458#define SYMBOL_SET_LANGUAGE(symbol,language,obstack) \
459 (symbol_set_language (&(symbol)->ginfo, (language), (obstack)))
33e5013e 460extern void symbol_set_language (struct general_symbol_info *symbol,
f85f34ed
TT
461 enum language language,
462 struct obstack *obstack);
c906108c 463
3567439c
DJ
464/* Set just the linkage name of a symbol; do not try to demangle
465 it. Used for constructs which do not have a mangled name,
466 e.g. struct tags. Unlike SYMBOL_SET_NAMES, linkage_name must
1c9e8358
TT
467 be terminated and either already on the objfile's obstack or
468 permanently allocated. */
3567439c
DJ
469#define SYMBOL_SET_LINKAGE_NAME(symbol,linkage_name) \
470 (symbol)->ginfo.name = (linkage_name)
471
472/* Set the linkage and natural names of a symbol, by demangling
473 the linkage name. */
04a679b8
TT
474#define SYMBOL_SET_NAMES(symbol,linkage_name,len,copy_name,objfile) \
475 symbol_set_names (&(symbol)->ginfo, linkage_name, len, copy_name, objfile)
2de7ced7 476extern void symbol_set_names (struct general_symbol_info *symbol,
04a679b8 477 const char *linkage_name, int len, int copy_name,
2de7ced7
DJ
478 struct objfile *objfile);
479
22abf04a
DC
480/* Now come lots of name accessor macros. Short version as to when to
481 use which: Use SYMBOL_NATURAL_NAME to refer to the name of the
482 symbol in the original source code. Use SYMBOL_LINKAGE_NAME if you
483 want to know what the linker thinks the symbol's name is. Use
484 SYMBOL_PRINT_NAME for output. Use SYMBOL_DEMANGLED_NAME if you
485 specifically need to know whether SYMBOL_NATURAL_NAME and
3567439c 486 SYMBOL_LINKAGE_NAME are different. */
22abf04a
DC
487
488/* Return SYMBOL's "natural" name, i.e. the name that it was called in
489 the original source code. In languages like C++ where symbols may
490 be mangled for ease of manipulation by the linker, this is the
491 demangled name. */
492
493#define SYMBOL_NATURAL_NAME(symbol) \
494 (symbol_natural_name (&(symbol)->ginfo))
0d5cff50
DE
495extern const char *symbol_natural_name
496 (const struct general_symbol_info *symbol);
22abf04a
DC
497
498/* Return SYMBOL's name from the point of view of the linker. In
499 languages like C++ where symbols may be mangled for ease of
500 manipulation by the linker, this is the mangled name; otherwise,
3567439c 501 it's the same as SYMBOL_NATURAL_NAME. */
22abf04a
DC
502
503#define SYMBOL_LINKAGE_NAME(symbol) (symbol)->ginfo.name
504
9cc0d196 505/* Return the demangled name for a symbol based on the language for
c378eb4e 506 that symbol. If no demangled name exists, return NULL. */
9cc0d196
EZ
507#define SYMBOL_DEMANGLED_NAME(symbol) \
508 (symbol_demangled_name (&(symbol)->ginfo))
0d5cff50
DE
509extern const char *symbol_demangled_name
510 (const struct general_symbol_info *symbol);
c906108c 511
de5ad195
DC
512/* Macro that returns a version of the name of a symbol that is
513 suitable for output. In C++ this is the "demangled" form of the
514 name if demangle is on and the "mangled" form of the name if
515 demangle is off. In other languages this is just the symbol name.
516 The result should never be NULL. Don't use this for internal
50f182aa
DE
517 purposes (e.g. storing in a hashtable): it's only suitable for output.
518
519 N.B. symbol may be anything with a ginfo member,
520 e.g., struct symbol or struct minimal_symbol. */
de5ad195
DC
521
522#define SYMBOL_PRINT_NAME(symbol) \
22abf04a 523 (demangle ? SYMBOL_NATURAL_NAME (symbol) : SYMBOL_LINKAGE_NAME (symbol))
50f182aa 524extern int demangle;
c906108c 525
c378eb4e 526/* Macro that returns the name to be used when sorting and searching symbols.
9c37b5ae 527 In C++, we search for the demangled form of a name,
4725b721
PH
528 and so sort symbols accordingly. In Ada, however, we search by mangled
529 name. If there is no distinct demangled name, then SYMBOL_SEARCH_NAME
c378eb4e 530 returns the same value (same pointer) as SYMBOL_LINKAGE_NAME. */
4725b721
PH
531#define SYMBOL_SEARCH_NAME(symbol) \
532 (symbol_search_name (&(symbol)->ginfo))
b5ec771e 533extern const char *symbol_search_name (const struct general_symbol_info *ginfo);
4725b721 534
b5ec771e
PA
535/* Return true if NAME matches the "search" name of SYMBOL, according
536 to the symbol's language. */
537#define SYMBOL_MATCHES_SEARCH_NAME(symbol, name) \
538 symbol_matches_search_name (&(symbol)->ginfo, (name))
539
540/* Helper for SYMBOL_MATCHES_SEARCH_NAME that works with both symbols
541 and psymbols. */
542extern bool symbol_matches_search_name
543 (const struct general_symbol_info *gsymbol,
544 const lookup_name_info &name);
4725b721 545
5ffa0793
PA
546/* Compute the hash of the given symbol search name of a symbol of
547 language LANGUAGE. */
548extern unsigned int search_name_hash (enum language language,
549 const char *search_name);
550
87193939
MC
551/* Classification types for a minimal symbol. These should be taken as
552 "advisory only", since if gdb can't easily figure out a
553 classification it simply selects mst_unknown. It may also have to
554 guess when it can't figure out which is a better match between two
555 types (mst_data versus mst_bss) for example. Since the minimal
556 symbol info is sometimes derived from the BFD library's view of a
c378eb4e 557 file, we need to live with what information bfd supplies. */
87193939
MC
558
559enum minimal_symbol_type
560{
561 mst_unknown = 0, /* Unknown type, the default */
562 mst_text, /* Generally executable instructions */
0875794a
JK
563 mst_text_gnu_ifunc, /* Executable code returning address
564 of executable code */
565 mst_slot_got_plt, /* GOT entries for .plt sections */
87193939
MC
566 mst_data, /* Generally initialized data */
567 mst_bss, /* Generally uninitialized data */
568 mst_abs, /* Generally absolute (nonrelocatable) */
569 /* GDB uses mst_solib_trampoline for the start address of a shared
570 library trampoline entry. Breakpoints for shared library functions
571 are put there if the shared library is not yet loaded.
572 After the shared library is loaded, lookup_minimal_symbol will
573 prefer the minimal symbol from the shared library (usually
574 a mst_text symbol) over the mst_solib_trampoline symbol, and the
575 breakpoints will be moved to their true address in the shared
576 library via breakpoint_re_set. */
577 mst_solib_trampoline, /* Shared library trampoline code */
578 /* For the mst_file* types, the names are only guaranteed to be unique
579 within a given .o file. */
580 mst_file_text, /* Static version of mst_text */
581 mst_file_data, /* Static version of mst_data */
51cdc993
DE
582 mst_file_bss, /* Static version of mst_bss */
583 nr_minsym_types
87193939
MC
584};
585
51cdc993
DE
586/* The number of enum minimal_symbol_type values, with some padding for
587 reasonable growth. */
588#define MINSYM_TYPE_BITS 4
589gdb_static_assert (nr_minsym_types <= (1 << MINSYM_TYPE_BITS));
590
c906108c
SS
591/* Define a simple structure used to hold some very basic information about
592 all defined global symbols (text, data, bss, abs, etc). The only required
593 information is the general_symbol_info.
594
595 In many cases, even if a file was compiled with no special options for
596 debugging at all, as long as was not stripped it will contain sufficient
597 information to build a useful minimal symbol table using this structure.
598 Even when a file contains enough debugging information to build a full
599 symbol table, these minimal symbols are still useful for quickly mapping
600 between names and addresses, and vice versa. They are also sometimes
c378eb4e 601 used to figure out what full symbol table entries need to be read in. */
c906108c
SS
602
603struct minimal_symbol
17c5ed2c 604{
c906108c 605
17c5ed2c 606 /* The general symbol info required for all types of symbols.
c906108c 607
17c5ed2c
DC
608 The SYMBOL_VALUE_ADDRESS contains the address that this symbol
609 corresponds to. */
c906108c 610
efd66ac6 611 struct general_symbol_info mginfo;
c906108c 612
8763cede 613 /* Size of this symbol. dbx_end_psymtab in dbxread.c uses this
f594e5e9
MC
614 information to calculate the end of the partial symtab based on the
615 address of the last symbol plus the size of the last symbol. */
616
617 unsigned long size;
618
17c5ed2c 619 /* Which source file is this symbol in? Only relevant for mst_file_*. */
04aba065 620 const char *filename;
c906108c 621
87193939 622 /* Classification type for this minimal symbol. */
17c5ed2c 623
51cdc993 624 ENUM_BITFIELD(minimal_symbol_type) type : MINSYM_TYPE_BITS;
17c5ed2c 625
422d65e7
DE
626 /* Non-zero if this symbol was created by gdb.
627 Such symbols do not appear in the output of "info var|fun". */
628 unsigned int created_by_gdb : 1;
629
b887350f
TT
630 /* Two flag bits provided for the use of the target. */
631 unsigned int target_flag_1 : 1;
632 unsigned int target_flag_2 : 1;
633
d9eaeb59
JB
634 /* Nonzero iff the size of the minimal symbol has been set.
635 Symbol size information can sometimes not be determined, because
636 the object file format may not carry that piece of information. */
637 unsigned int has_size : 1;
638
17c5ed2c
DC
639 /* Minimal symbols with the same hash key are kept on a linked
640 list. This is the link. */
641
642 struct minimal_symbol *hash_next;
643
644 /* Minimal symbols are stored in two different hash tables. This is
645 the `next' pointer for the demangled hash table. */
646
647 struct minimal_symbol *demangled_hash_next;
648};
c906108c 649
b887350f
TT
650#define MSYMBOL_TARGET_FLAG_1(msymbol) (msymbol)->target_flag_1
651#define MSYMBOL_TARGET_FLAG_2(msymbol) (msymbol)->target_flag_2
d9eaeb59
JB
652#define MSYMBOL_SIZE(msymbol) ((msymbol)->size + 0)
653#define SET_MSYMBOL_SIZE(msymbol, sz) \
654 do \
655 { \
656 (msymbol)->size = sz; \
657 (msymbol)->has_size = 1; \
658 } while (0)
659#define MSYMBOL_HAS_SIZE(msymbol) ((msymbol)->has_size + 0)
c906108c 660#define MSYMBOL_TYPE(msymbol) (msymbol)->type
c906108c 661
efd66ac6 662#define MSYMBOL_VALUE(symbol) (symbol)->mginfo.value.ivalue
77e371c0
TT
663/* The unrelocated address of the minimal symbol. */
664#define MSYMBOL_VALUE_RAW_ADDRESS(symbol) ((symbol)->mginfo.value.address + 0)
2273f0ac
TT
665/* The relocated address of the minimal symbol, using the section
666 offsets from OBJFILE. */
77e371c0
TT
667#define MSYMBOL_VALUE_ADDRESS(objfile, symbol) \
668 ((symbol)->mginfo.value.address \
2273f0ac 669 + ANOFFSET ((objfile)->section_offsets, ((symbol)->mginfo.section)))
77e371c0
TT
670/* For a bound minsym, we can easily compute the address directly. */
671#define BMSYMBOL_VALUE_ADDRESS(symbol) \
672 MSYMBOL_VALUE_ADDRESS ((symbol).objfile, (symbol).minsym)
673#define SET_MSYMBOL_VALUE_ADDRESS(symbol, new_value) \
40c1a007 674 ((symbol)->mginfo.value.address = (new_value))
efd66ac6
TT
675#define MSYMBOL_VALUE_BYTES(symbol) (symbol)->mginfo.value.bytes
676#define MSYMBOL_BLOCK_VALUE(symbol) (symbol)->mginfo.value.block
677#define MSYMBOL_VALUE_CHAIN(symbol) (symbol)->mginfo.value.chain
678#define MSYMBOL_LANGUAGE(symbol) (symbol)->mginfo.language
679#define MSYMBOL_SECTION(symbol) (symbol)->mginfo.section
680#define MSYMBOL_OBJ_SECTION(objfile, symbol) \
681 (((symbol)->mginfo.section >= 0) \
682 ? (&(((objfile)->sections)[(symbol)->mginfo.section])) \
683 : NULL)
684
685#define MSYMBOL_NATURAL_NAME(symbol) \
686 (symbol_natural_name (&(symbol)->mginfo))
687#define MSYMBOL_LINKAGE_NAME(symbol) (symbol)->mginfo.name
688#define MSYMBOL_PRINT_NAME(symbol) \
689 (demangle ? MSYMBOL_NATURAL_NAME (symbol) : MSYMBOL_LINKAGE_NAME (symbol))
690#define MSYMBOL_DEMANGLED_NAME(symbol) \
691 (symbol_demangled_name (&(symbol)->mginfo))
692#define MSYMBOL_SET_LANGUAGE(symbol,language,obstack) \
693 (symbol_set_language (&(symbol)->mginfo, (language), (obstack)))
694#define MSYMBOL_SEARCH_NAME(symbol) \
695 (symbol_search_name (&(symbol)->mginfo))
efd66ac6
TT
696#define MSYMBOL_SET_NAMES(symbol,linkage_name,len,copy_name,objfile) \
697 symbol_set_names (&(symbol)->mginfo, linkage_name, len, copy_name, objfile)
698
c35384fb
TT
699#include "minsyms.h"
700
c906108c 701\f
c5aa993b 702
c906108c
SS
703/* Represent one symbol name; a variable, constant, function or typedef. */
704
176620f1 705/* Different name domains for symbols. Looking up a symbol specifies a
c378eb4e 706 domain and ignores symbol definitions in other name domains. */
c906108c 707
87193939 708typedef enum domain_enum_tag
17c5ed2c 709{
176620f1 710 /* UNDEF_DOMAIN is used when a domain has not been discovered or
17c5ed2c 711 none of the following apply. This usually indicates an error either
c378eb4e 712 in the symbol information or in gdb's handling of symbols. */
c906108c 713
176620f1 714 UNDEF_DOMAIN,
c906108c 715
176620f1 716 /* VAR_DOMAIN is the usual domain. In C, this contains variables,
c378eb4e 717 function names, typedef names and enum type values. */
c906108c 718
176620f1 719 VAR_DOMAIN,
c906108c 720
176620f1 721 /* STRUCT_DOMAIN is used in C to hold struct, union and enum type names.
17c5ed2c 722 Thus, if `struct foo' is used in a C program, it produces a symbol named
c378eb4e 723 `foo' in the STRUCT_DOMAIN. */
c906108c 724
176620f1 725 STRUCT_DOMAIN,
c906108c 726
530e8392
KB
727 /* MODULE_DOMAIN is used in Fortran to hold module type names. */
728
729 MODULE_DOMAIN,
730
0f5238ed 731 /* LABEL_DOMAIN may be used for names of labels (for gotos). */
c906108c 732
4357ac6c
TT
733 LABEL_DOMAIN,
734
5a352474
JK
735 /* Fortran common blocks. Their naming must be separate from VAR_DOMAIN.
736 They also always use LOC_COMMON_BLOCK. */
51cdc993
DE
737 COMMON_BLOCK_DOMAIN,
738
739 /* This must remain last. */
740 NR_DOMAINS
8903c50d 741} domain_enum;
c906108c 742
c01feb36
DE
743/* The number of bits in a symbol used to represent the domain. */
744
51cdc993
DE
745#define SYMBOL_DOMAIN_BITS 3
746gdb_static_assert (NR_DOMAINS <= (1 << SYMBOL_DOMAIN_BITS));
c01feb36 747
20c681d1
DE
748extern const char *domain_name (domain_enum);
749
e8930875
JK
750/* Searching domains, used for `search_symbols'. Element numbers are
751 hardcoded in GDB, check all enum uses before changing it. */
c906108c 752
8903c50d
TT
753enum search_domain
754{
bd2e94ce
TT
755 /* Everything in VAR_DOMAIN minus FUNCTIONS_DOMAIN and
756 TYPES_DOMAIN. */
e8930875 757 VARIABLES_DOMAIN = 0,
c906108c 758
c378eb4e 759 /* All functions -- for some reason not methods, though. */
e8930875 760 FUNCTIONS_DOMAIN = 1,
c906108c 761
17c5ed2c 762 /* All defined types */
e8930875 763 TYPES_DOMAIN = 2,
7b08b9eb
JK
764
765 /* Any type. */
766 ALL_DOMAIN = 3
8903c50d 767};
c906108c 768
20c681d1
DE
769extern const char *search_domain_name (enum search_domain);
770
c906108c
SS
771/* An address-class says where to find the value of a symbol. */
772
773enum address_class
17c5ed2c 774{
c378eb4e 775 /* Not used; catches errors. */
c5aa993b 776
17c5ed2c 777 LOC_UNDEF,
c906108c 778
c378eb4e 779 /* Value is constant int SYMBOL_VALUE, host byteorder. */
c906108c 780
17c5ed2c 781 LOC_CONST,
c906108c 782
c378eb4e 783 /* Value is at fixed address SYMBOL_VALUE_ADDRESS. */
c906108c 784
17c5ed2c 785 LOC_STATIC,
c906108c 786
768a979c
UW
787 /* Value is in register. SYMBOL_VALUE is the register number
788 in the original debug format. SYMBOL_REGISTER_OPS holds a
789 function that can be called to transform this into the
790 actual register number this represents in a specific target
791 architecture (gdbarch).
2a2d4dc3
AS
792
793 For some symbol formats (stabs, for some compilers at least),
794 the compiler generates two symbols, an argument and a register.
795 In some cases we combine them to a single LOC_REGISTER in symbol
796 reading, but currently not for all cases (e.g. it's passed on the
797 stack and then loaded into a register). */
c906108c 798
17c5ed2c 799 LOC_REGISTER,
c906108c 800
17c5ed2c 801 /* It's an argument; the value is at SYMBOL_VALUE offset in arglist. */
c906108c 802
17c5ed2c 803 LOC_ARG,
c906108c 804
17c5ed2c 805 /* Value address is at SYMBOL_VALUE offset in arglist. */
c906108c 806
17c5ed2c 807 LOC_REF_ARG,
c906108c 808
2a2d4dc3 809 /* Value is in specified register. Just like LOC_REGISTER except the
17c5ed2c 810 register holds the address of the argument instead of the argument
c378eb4e 811 itself. This is currently used for the passing of structs and unions
17c5ed2c
DC
812 on sparc and hppa. It is also used for call by reference where the
813 address is in a register, at least by mipsread.c. */
c906108c 814
17c5ed2c 815 LOC_REGPARM_ADDR,
c906108c 816
17c5ed2c 817 /* Value is a local variable at SYMBOL_VALUE offset in stack frame. */
c906108c 818
17c5ed2c 819 LOC_LOCAL,
c906108c 820
176620f1
EZ
821 /* Value not used; definition in SYMBOL_TYPE. Symbols in the domain
822 STRUCT_DOMAIN all have this class. */
c906108c 823
17c5ed2c 824 LOC_TYPEDEF,
c906108c 825
c378eb4e 826 /* Value is address SYMBOL_VALUE_ADDRESS in the code. */
c906108c 827
17c5ed2c 828 LOC_LABEL,
c906108c 829
17c5ed2c
DC
830 /* In a symbol table, value is SYMBOL_BLOCK_VALUE of a `struct block'.
831 In a partial symbol table, SYMBOL_VALUE_ADDRESS is the start address
c378eb4e 832 of the block. Function names have this class. */
c906108c 833
17c5ed2c 834 LOC_BLOCK,
c906108c 835
17c5ed2c
DC
836 /* Value is a constant byte-sequence pointed to by SYMBOL_VALUE_BYTES, in
837 target byte order. */
c906108c 838
17c5ed2c 839 LOC_CONST_BYTES,
c906108c 840
17c5ed2c
DC
841 /* Value is at fixed address, but the address of the variable has
842 to be determined from the minimal symbol table whenever the
843 variable is referenced.
844 This happens if debugging information for a global symbol is
845 emitted and the corresponding minimal symbol is defined
846 in another object file or runtime common storage.
847 The linker might even remove the minimal symbol if the global
848 symbol is never referenced, in which case the symbol remains
de40b933
JK
849 unresolved.
850
851 GDB would normally find the symbol in the minimal symbol table if it will
852 not find it in the full symbol table. But a reference to an external
853 symbol in a local block shadowing other definition requires full symbol
854 without possibly having its address available for LOC_STATIC. Testcase
5382cfab
PW
855 is provided as `gdb.dwarf2/dw2-unresolved.exp'.
856
857 This is also used for thread local storage (TLS) variables. In this case,
858 the address of the TLS variable must be determined when the variable is
859 referenced, from the MSYMBOL_VALUE_RAW_ADDRESS, which is the offset
860 of the TLS variable in the thread local storage of the shared
861 library/object. */
c906108c 862
17c5ed2c 863 LOC_UNRESOLVED,
c906108c 864
17c5ed2c
DC
865 /* The variable does not actually exist in the program.
866 The value is ignored. */
c906108c 867
17c5ed2c 868 LOC_OPTIMIZED_OUT,
c906108c 869
4c2df51b 870 /* The variable's address is computed by a set of location
768a979c 871 functions (see "struct symbol_computed_ops" below). */
4c2df51b 872 LOC_COMPUTED,
5a352474
JK
873
874 /* The variable uses general_symbol_info->value->common_block field.
875 It also always uses COMMON_BLOCK_DOMAIN. */
876 LOC_COMMON_BLOCK,
f1e6e072
TT
877
878 /* Not used, just notes the boundary of the enum. */
879 LOC_FINAL_VALUE
4c2df51b
DJ
880};
881
51cdc993
DE
882/* The number of bits needed for values in enum address_class, with some
883 padding for reasonable growth, and room for run-time registered address
884 classes. See symtab.c:MAX_SYMBOL_IMPLS.
885 This is a #define so that we can have a assertion elsewhere to
886 verify that we have reserved enough space for synthetic address
887 classes. */
888#define SYMBOL_ACLASS_BITS 5
889gdb_static_assert (LOC_FINAL_VALUE <= (1 << SYMBOL_ACLASS_BITS));
890
768a979c 891/* The methods needed to implement LOC_COMPUTED. These methods can
a67af2b9
AC
892 use the symbol's .aux_value for additional per-symbol information.
893
894 At present this is only used to implement location expressions. */
895
768a979c 896struct symbol_computed_ops
4c2df51b
DJ
897{
898
899 /* Return the value of the variable SYMBOL, relative to the stack
900 frame FRAME. If the variable has been optimized out, return
901 zero.
902
0b31a4bc
TT
903 Iff `read_needs_frame (SYMBOL)' is not SYMBOL_NEEDS_FRAME, then
904 FRAME may be zero. */
4c2df51b
DJ
905
906 struct value *(*read_variable) (struct symbol * symbol,
907 struct frame_info * frame);
908
e18b2753
JK
909 /* Read variable SYMBOL like read_variable at (callee) FRAME's function
910 entry. SYMBOL should be a function parameter, otherwise
911 NO_ENTRY_VALUE_ERROR will be thrown. */
912 struct value *(*read_variable_at_entry) (struct symbol *symbol,
913 struct frame_info *frame);
914
0b31a4bc
TT
915 /* Find the "symbol_needs_kind" value for the given symbol. This
916 value determines whether reading the symbol needs memory (e.g., a
917 global variable), just registers (a thread-local), or a frame (a
918 local variable). */
919 enum symbol_needs_kind (*get_symbol_read_needs) (struct symbol * symbol);
4c2df51b
DJ
920
921 /* Write to STREAM a natural-language description of the location of
08922a10
SS
922 SYMBOL, in the context of ADDR. */
923 void (*describe_location) (struct symbol * symbol, CORE_ADDR addr,
924 struct ui_file * stream);
4c2df51b 925
f1e6e072
TT
926 /* Non-zero if this symbol's address computation is dependent on PC. */
927 unsigned char location_has_loclist;
928
4c2df51b
DJ
929 /* Tracepoint support. Append bytecodes to the tracepoint agent
930 expression AX that push the address of the object SYMBOL. Set
931 VALUE appropriately. Note --- for objects in registers, this
932 needn't emit any code; as long as it sets VALUE properly, then
933 the caller will generate the right code in the process of
934 treating this as an lvalue or rvalue. */
935
40f4af28
SM
936 void (*tracepoint_var_ref) (struct symbol *symbol, struct agent_expr *ax,
937 struct axs_value *value);
bb2ec1b3
TT
938
939 /* Generate C code to compute the location of SYMBOL. The C code is
940 emitted to STREAM. GDBARCH is the current architecture and PC is
941 the PC at which SYMBOL's location should be evaluated.
942 REGISTERS_USED is a vector indexed by register number; the
943 generator function should set an element in this vector if the
944 corresponding register is needed by the location computation.
945 The generated C code must assign the location to a local
946 variable; this variable's name is RESULT_NAME. */
947
d7e74731 948 void (*generate_c_location) (struct symbol *symbol, string_file &stream,
bb2ec1b3
TT
949 struct gdbarch *gdbarch,
950 unsigned char *registers_used,
951 CORE_ADDR pc, const char *result_name);
952
17c5ed2c 953};
c906108c 954
f1e6e072
TT
955/* The methods needed to implement LOC_BLOCK for inferior functions.
956 These methods can use the symbol's .aux_value for additional
957 per-symbol information. */
958
959struct symbol_block_ops
960{
961 /* Fill in *START and *LENGTH with DWARF block data of function
962 FRAMEFUNC valid for inferior context address PC. Set *LENGTH to
963 zero if such location is not valid for PC; *START is left
964 uninitialized in such case. */
965 void (*find_frame_base_location) (struct symbol *framefunc, CORE_ADDR pc,
966 const gdb_byte **start, size_t *length);
63e43d3a
PMR
967
968 /* Return the frame base address. FRAME is the frame for which we want to
969 compute the base address while FRAMEFUNC is the symbol for the
970 corresponding function. Return 0 on failure (FRAMEFUNC may not hold the
971 information we need).
972
973 This method is designed to work with static links (nested functions
974 handling). Static links are function properties whose evaluation returns
975 the frame base address for the enclosing frame. However, there are
976 multiple definitions for "frame base": the content of the frame base
977 register, the CFA as defined by DWARF unwinding information, ...
978
979 So this specific method is supposed to compute the frame base address such
980 as for nested fuctions, the static link computes the same address. For
981 instance, considering DWARF debugging information, the static link is
982 computed with DW_AT_static_link and this method must be used to compute
983 the corresponding DW_AT_frame_base attribute. */
984 CORE_ADDR (*get_frame_base) (struct symbol *framefunc,
985 struct frame_info *frame);
f1e6e072
TT
986};
987
768a979c
UW
988/* Functions used with LOC_REGISTER and LOC_REGPARM_ADDR. */
989
990struct symbol_register_ops
991{
992 int (*register_number) (struct symbol *symbol, struct gdbarch *gdbarch);
993};
994
f1e6e072
TT
995/* Objects of this type are used to find the address class and the
996 various computed ops vectors of a symbol. */
997
998struct symbol_impl
999{
1000 enum address_class aclass;
1001
1002 /* Used with LOC_COMPUTED. */
1003 const struct symbol_computed_ops *ops_computed;
1004
1005 /* Used with LOC_BLOCK. */
1006 const struct symbol_block_ops *ops_block;
1007
1008 /* Used with LOC_REGISTER and LOC_REGPARM_ADDR. */
1009 const struct symbol_register_ops *ops_register;
1010};
1011
cf724bc9
TT
1012/* struct symbol has some subclasses. This enum is used to
1013 differentiate between them. */
1014
1015enum symbol_subclass_kind
1016{
1017 /* Plain struct symbol. */
1018 SYMBOL_NONE,
1019
1020 /* struct template_symbol. */
1021 SYMBOL_TEMPLATE,
1022
1023 /* struct rust_vtable_symbol. */
1024 SYMBOL_RUST_VTABLE
1025};
1026
c378eb4e 1027/* This structure is space critical. See space comments at the top. */
a7f19c79 1028
c906108c 1029struct symbol
17c5ed2c 1030{
c906108c 1031
c378eb4e 1032 /* The general symbol info required for all types of symbols. */
c906108c 1033
17c5ed2c 1034 struct general_symbol_info ginfo;
c906108c 1035
17c5ed2c 1036 /* Data type of value */
c906108c 1037
17c5ed2c 1038 struct type *type;
c906108c 1039
1994afbf 1040 /* The owner of this symbol.
e2ada9cb 1041 Which one to use is defined by symbol.is_objfile_owned. */
1994afbf
DE
1042
1043 union
1044 {
1045 /* The symbol table containing this symbol. This is the file associated
1046 with LINE. It can be NULL during symbols read-in but it is never NULL
1047 during normal operation. */
1048 struct symtab *symtab;
1049
1050 /* For types defined by the architecture. */
1051 struct gdbarch *arch;
1052 } owner;
cb1df416 1053
176620f1 1054 /* Domain code. */
c906108c 1055
c01feb36 1056 ENUM_BITFIELD(domain_enum_tag) domain : SYMBOL_DOMAIN_BITS;
c906108c 1057
f1e6e072
TT
1058 /* Address class. This holds an index into the 'symbol_impls'
1059 table. The actual enum address_class value is stored there,
1060 alongside any per-class ops vectors. */
c906108c 1061
f1e6e072 1062 unsigned int aclass_index : SYMBOL_ACLASS_BITS;
c906108c 1063
1994afbf
DE
1064 /* If non-zero then symbol is objfile-owned, use owner.symtab.
1065 Otherwise symbol is arch-owned, use owner.arch. */
1066
1067 unsigned int is_objfile_owned : 1;
1068
2a2d4dc3
AS
1069 /* Whether this is an argument. */
1070
1071 unsigned is_argument : 1;
1072
edb3359d
DJ
1073 /* Whether this is an inlined function (class LOC_BLOCK only). */
1074 unsigned is_inlined : 1;
1075
cf724bc9 1076 /* The concrete type of this symbol. */
71a3c369 1077
cf724bc9 1078 ENUM_BITFIELD (symbol_subclass_kind) subclass : 2;
71a3c369 1079
edb3359d
DJ
1080 /* Line number of this symbol's definition, except for inlined
1081 functions. For an inlined function (class LOC_BLOCK and
1082 SYMBOL_INLINED set) this is the line number of the function's call
1083 site. Inlined function symbols are not definitions, and they are
1084 never found by symbol table lookup.
1994afbf 1085 If this symbol is arch-owned, LINE shall be zero.
edb3359d
DJ
1086
1087 FIXME: Should we really make the assumption that nobody will try
1088 to debug files longer than 64K lines? What about machine
1089 generated programs? */
c906108c 1090
17c5ed2c 1091 unsigned short line;
c906108c 1092
10f4ecb8
UW
1093 /* An arbitrary data pointer, allowing symbol readers to record
1094 additional information on a per-symbol basis. Note that this data
1095 must be allocated using the same obstack as the symbol itself. */
1cd36e54
DE
1096 /* So far it is only used by:
1097 LOC_COMPUTED: to find the location information
1098 LOC_BLOCK (DWARF2 function): information used internally by the
1099 DWARF 2 code --- specifically, the location expression for the frame
10f4ecb8
UW
1100 base for this function. */
1101 /* FIXME drow/2003-02-21: For the LOC_BLOCK case, it might be better
1102 to add a magic symbol to the block containing this information,
1103 or to have a generic debug info annotation slot for symbols. */
1104
1105 void *aux_value;
c906108c 1106
17c5ed2c
DC
1107 struct symbol *hash_next;
1108};
c906108c 1109
d12307c1
PMR
1110/* Several lookup functions return both a symbol and the block in which the
1111 symbol is found. This structure is used in these cases. */
1112
1113struct block_symbol
1114{
1115 /* The symbol that was found, or NULL if no symbol was found. */
1116 struct symbol *symbol;
1117
1118 /* If SYMBOL is not NULL, then this is the block in which the symbol is
1119 defined. */
1120 const struct block *block;
1121};
1122
f1e6e072 1123extern const struct symbol_impl *symbol_impls;
c906108c 1124
b6b80672
PA
1125/* For convenience. All fields are NULL. This means "there is no
1126 symbol". */
1127extern const struct block_symbol null_block_symbol;
1128
1994afbf
DE
1129/* Note: There is no accessor macro for symbol.owner because it is
1130 "private". */
1131
176620f1 1132#define SYMBOL_DOMAIN(symbol) (symbol)->domain
f1e6e072
TT
1133#define SYMBOL_IMPL(symbol) (symbol_impls[(symbol)->aclass_index])
1134#define SYMBOL_ACLASS_INDEX(symbol) (symbol)->aclass_index
1135#define SYMBOL_CLASS(symbol) (SYMBOL_IMPL (symbol).aclass)
1994afbf 1136#define SYMBOL_OBJFILE_OWNED(symbol) ((symbol)->is_objfile_owned)
2a2d4dc3 1137#define SYMBOL_IS_ARGUMENT(symbol) (symbol)->is_argument
edb3359d 1138#define SYMBOL_INLINED(symbol) (symbol)->is_inlined
34eaf542 1139#define SYMBOL_IS_CPLUS_TEMPLATE_FUNCTION(symbol) \
cf724bc9 1140 (((symbol)->subclass) == SYMBOL_TEMPLATE)
c906108c
SS
1141#define SYMBOL_TYPE(symbol) (symbol)->type
1142#define SYMBOL_LINE(symbol) (symbol)->line
f1e6e072
TT
1143#define SYMBOL_COMPUTED_OPS(symbol) (SYMBOL_IMPL (symbol).ops_computed)
1144#define SYMBOL_BLOCK_OPS(symbol) (SYMBOL_IMPL (symbol).ops_block)
1145#define SYMBOL_REGISTER_OPS(symbol) (SYMBOL_IMPL (symbol).ops_register)
10f4ecb8 1146#define SYMBOL_LOCATION_BATON(symbol) (symbol)->aux_value
34eaf542 1147
f1e6e072
TT
1148extern int register_symbol_computed_impl (enum address_class,
1149 const struct symbol_computed_ops *);
1150
1151extern int register_symbol_block_impl (enum address_class aclass,
1152 const struct symbol_block_ops *ops);
1153
1154extern int register_symbol_register_impl (enum address_class,
1155 const struct symbol_register_ops *);
1156
08be3fe3
DE
1157/* Return the OBJFILE of SYMBOL.
1158 It is an error to call this if symbol.is_objfile_owned is false, which
1159 only happens for architecture-provided types. */
1160
1161extern struct objfile *symbol_objfile (const struct symbol *symbol);
1162
1163/* Return the ARCH of SYMBOL. */
1164
1165extern struct gdbarch *symbol_arch (const struct symbol *symbol);
1166
1167/* Return the SYMTAB of SYMBOL.
1168 It is an error to call this if symbol.is_objfile_owned is false, which
1169 only happens for architecture-provided types. */
1170
1171extern struct symtab *symbol_symtab (const struct symbol *symbol);
1172
1173/* Set the symtab of SYMBOL to SYMTAB.
1174 It is an error to call this if symbol.is_objfile_owned is false, which
1175 only happens for architecture-provided types. */
1176
1177extern void symbol_set_symtab (struct symbol *symbol, struct symtab *symtab);
1178
34eaf542 1179/* An instance of this type is used to represent a C++ template
68e745e3
TT
1180 function. A symbol is really of this type iff
1181 SYMBOL_IS_CPLUS_TEMPLATE_FUNCTION is true. */
34eaf542 1182
68e745e3 1183struct template_symbol : public symbol
34eaf542 1184{
34eaf542
TT
1185 /* The number of template arguments. */
1186 int n_template_arguments;
1187
1188 /* The template arguments. This is an array with
1189 N_TEMPLATE_ARGUMENTS elements. */
1190 struct symbol **template_arguments;
1191};
1192
71a3c369
TT
1193/* A symbol that represents a Rust virtual table object. */
1194
1195struct rust_vtable_symbol : public symbol
1196{
1197 /* The concrete type for which this vtable was created; that is, in
1198 "impl Trait for Type", this is "Type". */
1199 struct type *concrete_type;
1200};
1201
c906108c 1202\f
c906108c
SS
1203/* Each item represents a line-->pc (or the reverse) mapping. This is
1204 somewhat more wasteful of space than one might wish, but since only
1205 the files which are actually debugged are read in to core, we don't
1206 waste much space. */
1207
1208struct linetable_entry
17c5ed2c
DC
1209{
1210 int line;
1211 CORE_ADDR pc;
1212};
c906108c
SS
1213
1214/* The order of entries in the linetable is significant. They should
1215 be sorted by increasing values of the pc field. If there is more than
1216 one entry for a given pc, then I'm not sure what should happen (and
1217 I not sure whether we currently handle it the best way).
1218
1219 Example: a C for statement generally looks like this
1220
c5aa993b
JM
1221 10 0x100 - for the init/test part of a for stmt.
1222 20 0x200
1223 30 0x300
1224 10 0x400 - for the increment part of a for stmt.
c906108c 1225
e8717518
FF
1226 If an entry has a line number of zero, it marks the start of a PC
1227 range for which no line number information is available. It is
1228 acceptable, though wasteful of table space, for such a range to be
1229 zero length. */
c906108c
SS
1230
1231struct linetable
17c5ed2c
DC
1232{
1233 int nitems;
c906108c 1234
17c5ed2c
DC
1235 /* Actually NITEMS elements. If you don't like this use of the
1236 `struct hack', you can shove it up your ANSI (seriously, if the
1237 committee tells us how to do it, we can probably go along). */
1238 struct linetable_entry item[1];
1239};
c906108c 1240
c906108c
SS
1241/* How to relocate the symbols from each section in a symbol file.
1242 Each struct contains an array of offsets.
1243 The ordering and meaning of the offsets is file-type-dependent;
1244 typically it is indexed by section numbers or symbol types or
1245 something like that.
1246
1247 To give us flexibility in changing the internal representation
1248 of these offsets, the ANOFFSET macro must be used to insert and
1249 extract offset values in the struct. */
1250
1251struct section_offsets
17c5ed2c 1252{
c378eb4e 1253 CORE_ADDR offsets[1]; /* As many as needed. */
17c5ed2c 1254};
c906108c 1255
a4c8257b 1256#define ANOFFSET(secoff, whichone) \
3e43a32a
MS
1257 ((whichone == -1) \
1258 ? (internal_error (__FILE__, __LINE__, \
1259 _("Section index is uninitialized")), -1) \
1260 : secoff->offsets[whichone])
c906108c 1261
b29c9944
JB
1262/* The size of a section_offsets table for N sections. */
1263#define SIZEOF_N_SECTION_OFFSETS(n) \
c906108c 1264 (sizeof (struct section_offsets) \
b29c9944
JB
1265 + sizeof (((struct section_offsets *) 0)->offsets) * ((n)-1))
1266
c378eb4e 1267/* Each source file or header is represented by a struct symtab.
43f3e411 1268 The name "symtab" is historical, another name for it is "filetab".
c906108c
SS
1269 These objects are chained through the `next' field. */
1270
1271struct symtab
17c5ed2c 1272{
b7236fbe
DE
1273 /* Unordered chain of all filetabs in the compunit, with the exception
1274 that the "main" source file is the first entry in the list. */
c906108c 1275
17c5ed2c 1276 struct symtab *next;
c906108c 1277
43f3e411 1278 /* Backlink to containing compunit symtab. */
c906108c 1279
43f3e411 1280 struct compunit_symtab *compunit_symtab;
c906108c 1281
17c5ed2c
DC
1282 /* Table mapping core addresses to line numbers for this file.
1283 Can be NULL if none. Never shared between different symtabs. */
c906108c 1284
17c5ed2c 1285 struct linetable *linetable;
c906108c 1286
4e04028d 1287 /* Name of this source file. This pointer is never NULL. */
c906108c 1288
21ea9eec 1289 const char *filename;
c906108c 1290
17c5ed2c 1291 /* Total number of lines found in source file. */
c906108c 1292
17c5ed2c 1293 int nlines;
c906108c 1294
17c5ed2c
DC
1295 /* line_charpos[N] is the position of the (N-1)th line of the
1296 source file. "position" means something we can lseek() to; it
1297 is not guaranteed to be useful any other way. */
c906108c 1298
17c5ed2c 1299 int *line_charpos;
c906108c 1300
17c5ed2c 1301 /* Language of this source file. */
c906108c 1302
17c5ed2c 1303 enum language language;
c906108c 1304
43f3e411
DE
1305 /* Full name of file as found by searching the source path.
1306 NULL if not yet known. */
1307
1308 char *fullname;
1309};
1310
1311#define SYMTAB_COMPUNIT(symtab) ((symtab)->compunit_symtab)
1312#define SYMTAB_LINETABLE(symtab) ((symtab)->linetable)
1313#define SYMTAB_LANGUAGE(symtab) ((symtab)->language)
1314#define SYMTAB_BLOCKVECTOR(symtab) \
1315 COMPUNIT_BLOCKVECTOR (SYMTAB_COMPUNIT (symtab))
1316#define SYMTAB_OBJFILE(symtab) \
1317 COMPUNIT_OBJFILE (SYMTAB_COMPUNIT (symtab))
1318#define SYMTAB_PSPACE(symtab) (SYMTAB_OBJFILE (symtab)->pspace)
1319#define SYMTAB_DIRNAME(symtab) \
1320 COMPUNIT_DIRNAME (SYMTAB_COMPUNIT (symtab))
1321
1322typedef struct symtab *symtab_ptr;
1323DEF_VEC_P (symtab_ptr);
1324
1325/* Compunit symtabs contain the actual "symbol table", aka blockvector, as well
1326 as the list of all source files (what gdb has historically associated with
1327 the term "symtab").
1328 Additional information is recorded here that is common to all symtabs in a
1329 compilation unit (DWARF or otherwise).
1330
1331 Example:
1332 For the case of a program built out of these files:
1333
1334 foo.c
1335 foo1.h
1336 foo2.h
1337 bar.c
1338 foo1.h
1339 bar.h
1340
1341 This is recorded as:
1342
1343 objfile -> foo.c(cu) -> bar.c(cu) -> NULL
1344 | |
1345 v v
1346 foo.c bar.c
1347 | |
1348 v v
1349 foo1.h foo1.h
1350 | |
1351 v v
1352 foo2.h bar.h
1353 | |
1354 v v
1355 NULL NULL
1356
1357 where "foo.c(cu)" and "bar.c(cu)" are struct compunit_symtab objects,
1358 and the files foo.c, etc. are struct symtab objects. */
1359
1360struct compunit_symtab
1361{
1362 /* Unordered chain of all compunit symtabs of this objfile. */
1363 struct compunit_symtab *next;
1364
1365 /* Object file from which this symtab information was read. */
1366 struct objfile *objfile;
1367
1368 /* Name of the symtab.
1369 This is *not* intended to be a usable filename, and is
1370 for debugging purposes only. */
1371 const char *name;
1372
1373 /* Unordered list of file symtabs, except that by convention the "main"
1374 source file (e.g., .c, .cc) is guaranteed to be first.
1375 Each symtab is a file, either the "main" source file (e.g., .c, .cc)
1376 or header (e.g., .h). */
1377 struct symtab *filetabs;
1378
1379 /* Last entry in FILETABS list.
1380 Subfiles are added to the end of the list so they accumulate in order,
1381 with the main source subfile living at the front.
1382 The main reason is so that the main source file symtab is at the head
1383 of the list, and the rest appear in order for debugging convenience. */
1384 struct symtab *last_filetab;
1385
1386 /* Non-NULL string that identifies the format of the debugging information,
1387 such as "stabs", "dwarf 1", "dwarf 2", "coff", etc. This is mostly useful
17c5ed2c 1388 for automated testing of gdb but may also be information that is
c378eb4e 1389 useful to the user. */
554d387d 1390 const char *debugformat;
c906108c 1391
43f3e411 1392 /* String of producer version information, or NULL if we don't know. */
554d387d 1393 const char *producer;
c906108c 1394
43f3e411
DE
1395 /* Directory in which it was compiled, or NULL if we don't know. */
1396 const char *dirname;
c906108c 1397
43f3e411
DE
1398 /* List of all symbol scope blocks for this symtab. It is shared among
1399 all symtabs in a given compilation unit. */
1400 const struct blockvector *blockvector;
c906108c 1401
43f3e411
DE
1402 /* Section in objfile->section_offsets for the blockvector and
1403 the linetable. Probably always SECT_OFF_TEXT. */
1404 int block_line_section;
c906108c 1405
43f3e411
DE
1406 /* Symtab has been compiled with both optimizations and debug info so that
1407 GDB may stop skipping prologues as variables locations are valid already
1408 at function entry points. */
1409 unsigned int locations_valid : 1;
c906108c 1410
43f3e411
DE
1411 /* DWARF unwinder for this CU is valid even for epilogues (PC at the return
1412 instruction). This is supported by GCC since 4.5.0. */
1413 unsigned int epilogue_unwind_valid : 1;
8e3b41a9 1414
43f3e411 1415 /* struct call_site entries for this compilation unit or NULL. */
8e3b41a9 1416 htab_t call_site_htab;
b5b04b5b 1417
43f3e411
DE
1418 /* The macro table for this symtab. Like the blockvector, this
1419 is shared between different symtabs in a given compilation unit.
1420 It's debatable whether it *should* be shared among all the symtabs in
1421 the given compilation unit, but it currently is. */
1422 struct macro_table *macro_table;
1423
b5b04b5b 1424 /* If non-NULL, then this points to a NULL-terminated vector of
43f3e411
DE
1425 included compunits. When searching the static or global
1426 block of this compunit, the corresponding block of all
1427 included compunits will also be searched. Note that this
b5b04b5b
TT
1428 list must be flattened -- the symbol reader is responsible for
1429 ensuring that this vector contains the transitive closure of all
43f3e411
DE
1430 included compunits. */
1431 struct compunit_symtab **includes;
b5b04b5b 1432
43f3e411
DE
1433 /* If this is an included compunit, this points to one includer
1434 of the table. This user is considered the canonical compunit
1435 containing this one. An included compunit may itself be
b5b04b5b 1436 included by another. */
43f3e411 1437 struct compunit_symtab *user;
17c5ed2c 1438};
c906108c 1439
43f3e411
DE
1440#define COMPUNIT_OBJFILE(cust) ((cust)->objfile)
1441#define COMPUNIT_FILETABS(cust) ((cust)->filetabs)
1442#define COMPUNIT_DEBUGFORMAT(cust) ((cust)->debugformat)
1443#define COMPUNIT_PRODUCER(cust) ((cust)->producer)
1444#define COMPUNIT_DIRNAME(cust) ((cust)->dirname)
1445#define COMPUNIT_BLOCKVECTOR(cust) ((cust)->blockvector)
1446#define COMPUNIT_BLOCK_LINE_SECTION(cust) ((cust)->block_line_section)
1447#define COMPUNIT_LOCATIONS_VALID(cust) ((cust)->locations_valid)
1448#define COMPUNIT_EPILOGUE_UNWIND_VALID(cust) ((cust)->epilogue_unwind_valid)
1449#define COMPUNIT_CALL_SITE_HTAB(cust) ((cust)->call_site_htab)
1450#define COMPUNIT_MACRO_TABLE(cust) ((cust)->macro_table)
ec94af83 1451
43f3e411 1452/* Iterate over all file tables (struct symtab) within a compunit. */
db0fec5c 1453
43f3e411
DE
1454#define ALL_COMPUNIT_FILETABS(cu, s) \
1455 for ((s) = (cu) -> filetabs; (s) != NULL; (s) = (s) -> next)
1456
1457/* Return the primary symtab of CUST. */
1458
1459extern struct symtab *
1460 compunit_primary_filetab (const struct compunit_symtab *cust);
1461
1462/* Return the language of CUST. */
1463
1464extern enum language compunit_language (const struct compunit_symtab *cust);
1465
1466typedef struct compunit_symtab *compunit_symtab_ptr;
1467DEF_VEC_P (compunit_symtab_ptr);
ec94af83 1468
c906108c 1469\f
c5aa993b 1470
c906108c 1471/* The virtual function table is now an array of structures which have the
a960f249 1472 form { int16 offset, delta; void *pfn; }.
c906108c
SS
1473
1474 In normal virtual function tables, OFFSET is unused.
1475 DELTA is the amount which is added to the apparent object's base
1476 address in order to point to the actual object to which the
1477 virtual function should be applied.
1478 PFN is a pointer to the virtual function.
1479
c378eb4e 1480 Note that this macro is g++ specific (FIXME). */
c5aa993b 1481
c906108c
SS
1482#define VTBL_FNADDR_OFFSET 2
1483
c378eb4e 1484/* External variables and functions for the objects described above. */
c906108c 1485
c378eb4e 1486/* True if we are nested inside psymtab_to_symtab. */
c906108c
SS
1487
1488extern int currently_reading_symtab;
1489
c906108c
SS
1490/* symtab.c lookup functions */
1491
7fc830e2
MK
1492extern const char multiple_symbols_ask[];
1493extern const char multiple_symbols_all[];
1494extern const char multiple_symbols_cancel[];
717d2f5a
JB
1495
1496const char *multiple_symbols_select_mode (void);
1497
4186eb54
KS
1498int symbol_matches_domain (enum language symbol_language,
1499 domain_enum symbol_domain,
1500 domain_enum domain);
1501
c378eb4e 1502/* lookup a symbol table by source file name. */
c906108c 1503
1f8cc6db 1504extern struct symtab *lookup_symtab (const char *);
c906108c 1505
1993b719
TT
1506/* An object of this type is passed as the 'is_a_field_of_this'
1507 argument to lookup_symbol and lookup_symbol_in_language. */
1508
1509struct field_of_this_result
1510{
1511 /* The type in which the field was found. If this is NULL then the
1512 symbol was not found in 'this'. If non-NULL, then one of the
1513 other fields will be non-NULL as well. */
1514
1515 struct type *type;
1516
1517 /* If the symbol was found as an ordinary field of 'this', then this
1518 is non-NULL and points to the particular field. */
1519
1520 struct field *field;
1521
cf901d3b 1522 /* If the symbol was found as a function field of 'this', then this
1993b719
TT
1523 is non-NULL and points to the particular field. */
1524
1525 struct fn_fieldlist *fn_field;
1526};
1527
cf901d3b
DE
1528/* Find the definition for a specified symbol name NAME
1529 in domain DOMAIN in language LANGUAGE, visible from lexical block BLOCK
1530 if non-NULL or from global/static blocks if BLOCK is NULL.
1531 Returns the struct symbol pointer, or NULL if no symbol is found.
1532 C++: if IS_A_FIELD_OF_THIS is non-NULL on entry, check to see if
1533 NAME is a field of the current implied argument `this'. If so fill in the
1534 fields of IS_A_FIELD_OF_THIS, otherwise the fields are set to NULL.
cf901d3b 1535 The symbol's section is fixed up if necessary. */
53c5240f 1536
d12307c1
PMR
1537extern struct block_symbol
1538 lookup_symbol_in_language (const char *,
1539 const struct block *,
1540 const domain_enum,
1541 enum language,
1542 struct field_of_this_result *);
53c5240f 1543
cf901d3b 1544/* Same as lookup_symbol_in_language, but using the current language. */
c906108c 1545
d12307c1
PMR
1546extern struct block_symbol lookup_symbol (const char *,
1547 const struct block *,
1548 const domain_enum,
1549 struct field_of_this_result *);
c906108c 1550
5f9a71c3 1551/* A default version of lookup_symbol_nonlocal for use by languages
cf901d3b
DE
1552 that can't think of anything better to do.
1553 This implements the C lookup rules. */
5f9a71c3 1554
d12307c1 1555extern struct block_symbol
f606139a
DE
1556 basic_lookup_symbol_nonlocal (const struct language_defn *langdef,
1557 const char *,
1558 const struct block *,
1559 const domain_enum);
5f9a71c3
DC
1560
1561/* Some helper functions for languages that need to write their own
1562 lookup_symbol_nonlocal functions. */
1563
1564/* Lookup a symbol in the static block associated to BLOCK, if there
cf901d3b 1565 is one; do nothing if BLOCK is NULL or a global block.
d12307c1 1566 Upon success fixes up the symbol's section if necessary. */
5f9a71c3 1567
d12307c1
PMR
1568extern struct block_symbol
1569 lookup_symbol_in_static_block (const char *name,
1570 const struct block *block,
1571 const domain_enum domain);
5f9a71c3 1572
08724ab7 1573/* Search all static file-level symbols for NAME from DOMAIN.
d12307c1 1574 Upon success fixes up the symbol's section if necessary. */
08724ab7 1575
d12307c1
PMR
1576extern struct block_symbol lookup_static_symbol (const char *name,
1577 const domain_enum domain);
08724ab7 1578
cf901d3b 1579/* Lookup a symbol in all files' global blocks.
67be31e5
DE
1580
1581 If BLOCK is non-NULL then it is used for two things:
1582 1) If a target-specific lookup routine for libraries exists, then use the
1583 routine for the objfile of BLOCK, and
1584 2) The objfile of BLOCK is used to assist in determining the search order
1585 if the target requires it.
1586 See gdbarch_iterate_over_objfiles_in_search_order.
1587
d12307c1 1588 Upon success fixes up the symbol's section if necessary. */
5f9a71c3 1589
d12307c1
PMR
1590extern struct block_symbol
1591 lookup_global_symbol (const char *name,
1592 const struct block *block,
1593 const domain_enum domain);
5f9a71c3 1594
d1a2d36d 1595/* Lookup a symbol in block BLOCK.
d12307c1 1596 Upon success fixes up the symbol's section if necessary. */
5f9a71c3 1597
d12307c1
PMR
1598extern struct symbol *
1599 lookup_symbol_in_block (const char *name,
1600 const struct block *block,
1601 const domain_enum domain);
5f9a71c3 1602
cf901d3b
DE
1603/* Look up the `this' symbol for LANG in BLOCK. Return the symbol if
1604 found, or NULL if not found. */
1605
d12307c1
PMR
1606extern struct block_symbol
1607 lookup_language_this (const struct language_defn *lang,
1608 const struct block *block);
66a17cb6 1609
cf901d3b 1610/* Lookup a [struct, union, enum] by name, within a specified block. */
c906108c 1611
270140bd 1612extern struct type *lookup_struct (const char *, const struct block *);
c906108c 1613
270140bd 1614extern struct type *lookup_union (const char *, const struct block *);
c906108c 1615
270140bd 1616extern struct type *lookup_enum (const char *, const struct block *);
c906108c 1617
c906108c
SS
1618/* from blockframe.c: */
1619
c378eb4e 1620/* lookup the function symbol corresponding to the address. */
c906108c 1621
a14ed312 1622extern struct symbol *find_pc_function (CORE_ADDR);
c906108c 1623
c378eb4e 1624/* lookup the function corresponding to the address and section. */
c906108c 1625
714835d5 1626extern struct symbol *find_pc_sect_function (CORE_ADDR, struct obj_section *);
c5aa993b 1627
71a3c369
TT
1628/* Find the symbol at the given address. Returns NULL if no symbol
1629 found. Only exact matches for ADDRESS are considered. */
1630
1631extern struct symbol *find_symbol_at_address (CORE_ADDR);
1632
2c02bd72 1633extern int find_pc_partial_function_gnu_ifunc (CORE_ADDR pc, const char **name,
11c81455
JK
1634 CORE_ADDR *address,
1635 CORE_ADDR *endaddr,
1636 int *is_gnu_ifunc_p);
1637
c378eb4e 1638/* lookup function from address, return name, start addr and end addr. */
c906108c 1639
2c02bd72 1640extern int find_pc_partial_function (CORE_ADDR, const char **, CORE_ADDR *,
570b8f7c 1641 CORE_ADDR *);
c906108c 1642
a14ed312 1643extern void clear_pc_function_cache (void);
c906108c 1644
2097ae25 1645/* Expand symtab containing PC, SECTION if not already expanded. */
c906108c 1646
2097ae25 1647extern void expand_symtab_containing_pc (CORE_ADDR, struct obj_section *);
c906108c 1648
c378eb4e 1649/* lookup full symbol table by address. */
c906108c 1650
43f3e411 1651extern struct compunit_symtab *find_pc_compunit_symtab (CORE_ADDR);
c906108c 1652
c378eb4e 1653/* lookup full symbol table by address and section. */
c906108c 1654
43f3e411
DE
1655extern struct compunit_symtab *
1656 find_pc_sect_compunit_symtab (CORE_ADDR, struct obj_section *);
c906108c 1657
a14ed312 1658extern int find_pc_line_pc_range (CORE_ADDR, CORE_ADDR *, CORE_ADDR *);
c906108c 1659
a14ed312 1660extern void reread_symbols (void);
c906108c 1661
cf901d3b
DE
1662/* Look up a type named NAME in STRUCT_DOMAIN in the current language.
1663 The type returned must not be opaque -- i.e., must have at least one field
1664 defined. */
1665
a14ed312 1666extern struct type *lookup_transparent_type (const char *);
c906108c 1667
cf901d3b 1668extern struct type *basic_lookup_transparent_type (const char *);
c906108c 1669
c378eb4e 1670/* Macro for name of symbol to indicate a file compiled with gcc. */
c906108c
SS
1671#ifndef GCC_COMPILED_FLAG_SYMBOL
1672#define GCC_COMPILED_FLAG_SYMBOL "gcc_compiled."
1673#endif
1674
c378eb4e 1675/* Macro for name of symbol to indicate a file compiled with gcc2. */
c906108c
SS
1676#ifndef GCC2_COMPILED_FLAG_SYMBOL
1677#define GCC2_COMPILED_FLAG_SYMBOL "gcc2_compiled."
1678#endif
1679
0875794a
JK
1680extern int in_gnu_ifunc_stub (CORE_ADDR pc);
1681
07be84bf
JK
1682/* Functions for resolving STT_GNU_IFUNC symbols which are implemented only
1683 for ELF symbol files. */
1684
1685struct gnu_ifunc_fns
1686{
1687 /* See elf_gnu_ifunc_resolve_addr for its real implementation. */
1688 CORE_ADDR (*gnu_ifunc_resolve_addr) (struct gdbarch *gdbarch, CORE_ADDR pc);
1689
1690 /* See elf_gnu_ifunc_resolve_name for its real implementation. */
1691 int (*gnu_ifunc_resolve_name) (const char *function_name,
1692 CORE_ADDR *function_address_p);
0e30163f
JK
1693
1694 /* See elf_gnu_ifunc_resolver_stop for its real implementation. */
1695 void (*gnu_ifunc_resolver_stop) (struct breakpoint *b);
1696
1697 /* See elf_gnu_ifunc_resolver_return_stop for its real implementation. */
1698 void (*gnu_ifunc_resolver_return_stop) (struct breakpoint *b);
07be84bf
JK
1699};
1700
1701#define gnu_ifunc_resolve_addr gnu_ifunc_fns_p->gnu_ifunc_resolve_addr
1702#define gnu_ifunc_resolve_name gnu_ifunc_fns_p->gnu_ifunc_resolve_name
0e30163f
JK
1703#define gnu_ifunc_resolver_stop gnu_ifunc_fns_p->gnu_ifunc_resolver_stop
1704#define gnu_ifunc_resolver_return_stop \
1705 gnu_ifunc_fns_p->gnu_ifunc_resolver_return_stop
07be84bf
JK
1706
1707extern const struct gnu_ifunc_fns *gnu_ifunc_fns_p;
1708
52f729a7 1709extern CORE_ADDR find_solib_trampoline_target (struct frame_info *, CORE_ADDR);
c906108c 1710
c906108c 1711struct symtab_and_line
17c5ed2c 1712{
6c95b8df 1713 /* The program space of this sal. */
51abb421 1714 struct program_space *pspace = NULL;
6c95b8df 1715
51abb421 1716 struct symtab *symtab = NULL;
06871ae8 1717 struct symbol *symbol = NULL;
51abb421 1718 struct obj_section *section = NULL;
17c5ed2c
DC
1719 /* Line number. Line numbers start at 1 and proceed through symtab->nlines.
1720 0 is never a valid line number; it is used to indicate that line number
1721 information is not available. */
51abb421 1722 int line = 0;
17c5ed2c 1723
51abb421
PA
1724 CORE_ADDR pc = 0;
1725 CORE_ADDR end = 0;
1726 bool explicit_pc = false;
1727 bool explicit_line = false;
55aa24fb
SDJ
1728
1729 /* The probe associated with this symtab_and_line. */
935676c9 1730 probe *prob = NULL;
729662a5
TT
1731 /* If PROBE is not NULL, then this is the objfile in which the probe
1732 originated. */
51abb421 1733 struct objfile *objfile = NULL;
17c5ed2c 1734};
c906108c 1735
c5aa993b 1736\f
c906108c 1737
c906108c
SS
1738/* Given a pc value, return line number it is in. Second arg nonzero means
1739 if pc is on the boundary use the previous statement's line number. */
1740
a14ed312 1741extern struct symtab_and_line find_pc_line (CORE_ADDR, int);
c906108c 1742
c378eb4e 1743/* Same function, but specify a section as well as an address. */
c906108c 1744
714835d5
UW
1745extern struct symtab_and_line find_pc_sect_line (CORE_ADDR,
1746 struct obj_section *, int);
c906108c 1747
34248c3a
DE
1748/* Wrapper around find_pc_line to just return the symtab. */
1749
1750extern struct symtab *find_pc_line_symtab (CORE_ADDR);
1751
c906108c
SS
1752/* Given a symtab and line number, return the pc there. */
1753
a14ed312 1754extern int find_line_pc (struct symtab *, int, CORE_ADDR *);
c906108c 1755
570b8f7c
AC
1756extern int find_line_pc_range (struct symtab_and_line, CORE_ADDR *,
1757 CORE_ADDR *);
c906108c 1758
a14ed312 1759extern void resolve_sal_pc (struct symtab_and_line *);
c906108c 1760
f176c4b5 1761/* solib.c */
c906108c 1762
a14ed312 1763extern void clear_solib (void);
c906108c 1764
c906108c
SS
1765/* source.c */
1766
a14ed312 1767extern int identify_source_line (struct symtab *, int, int, CORE_ADDR);
c906108c 1768
dfaae886
MM
1769/* Flags passed as 4th argument to print_source_lines. */
1770
8d297bbf 1771enum print_source_lines_flag
dfaae886
MM
1772 {
1773 /* Do not print an error message. */
4cd29721
MM
1774 PRINT_SOURCE_LINES_NOERROR = (1 << 0),
1775
1776 /* Print the filename in front of the source lines. */
1777 PRINT_SOURCE_LINES_FILENAME = (1 << 1)
dfaae886 1778 };
8d297bbf 1779DEF_ENUM_FLAGS_TYPE (enum print_source_lines_flag, print_source_lines_flags);
dfaae886
MM
1780
1781extern void print_source_lines (struct symtab *, int, int,
8d297bbf 1782 print_source_lines_flags);
c906108c 1783
00174a86 1784extern void forget_cached_source_info_for_objfile (struct objfile *);
a14ed312 1785extern void forget_cached_source_info (void);
c906108c 1786
a14ed312 1787extern void select_source_symtab (struct symtab *);
c906108c 1788
c6756f62
PA
1789/* The reason we're calling into a completion match list collector
1790 function. */
1791enum class complete_symbol_mode
1792 {
1793 /* Completing an expression. */
1794 EXPRESSION,
1795
1796 /* Completing a linespec. */
1797 LINESPEC,
1798 };
1799
eb3ff9a5
PA
1800extern void default_collect_symbol_completion_matches_break_on
1801 (completion_tracker &tracker,
c6756f62 1802 complete_symbol_mode mode,
b5ec771e 1803 symbol_name_match_type name_match_type,
eb3ff9a5 1804 const char *text, const char *word, const char *break_on,
2f68a895 1805 enum type_code code);
eb3ff9a5
PA
1806extern void default_collect_symbol_completion_matches
1807 (completion_tracker &tracker,
c6756f62 1808 complete_symbol_mode,
b5ec771e 1809 symbol_name_match_type name_match_type,
eb3ff9a5
PA
1810 const char *,
1811 const char *,
1812 enum type_code);
b5ec771e
PA
1813extern void collect_symbol_completion_matches
1814 (completion_tracker &tracker,
1815 complete_symbol_mode mode,
1816 symbol_name_match_type name_match_type,
1817 const char *, const char *);
eb3ff9a5
PA
1818extern void collect_symbol_completion_matches_type (completion_tracker &tracker,
1819 const char *, const char *,
2f68a895 1820 enum type_code);
c906108c 1821
b5ec771e
PA
1822extern void collect_file_symbol_completion_matches
1823 (completion_tracker &tracker,
1824 complete_symbol_mode,
1825 symbol_name_match_type name_match_type,
1826 const char *, const char *, const char *);
c94fdfd0 1827
eb3ff9a5
PA
1828extern completion_list
1829 make_source_files_completion_list (const char *, const char *);
c94fdfd0 1830
f9d67a22
PA
1831/* Return whether SYM is a function/method, as opposed to a data symbol. */
1832
1833extern bool symbol_is_function_or_method (symbol *sym);
1834
1835/* Return whether MSYMBOL is a function/method, as opposed to a data
1836 symbol */
1837
1838extern bool symbol_is_function_or_method (minimal_symbol *msymbol);
1839
1840/* Return whether SYM should be skipped in completion mode MODE. In
1841 linespec mode, we're only interested in functions/methods. */
1842
1843template<typename Symbol>
1844static bool
1845completion_skip_symbol (complete_symbol_mode mode, Symbol *sym)
1846{
1847 return (mode == complete_symbol_mode::LINESPEC
1848 && !symbol_is_function_or_method (sym));
1849}
1850
c906108c
SS
1851/* symtab.c */
1852
714835d5 1853int matching_obj_sections (struct obj_section *, struct obj_section *);
94277a38 1854
50641945
FN
1855extern struct symtab *find_line_symtab (struct symtab *, int, int *, int *);
1856
17c5ed2c
DC
1857extern struct symtab_and_line find_function_start_sal (struct symbol *sym,
1858 int);
50641945 1859
059acae7
UW
1860extern void skip_prologue_sal (struct symtab_and_line *);
1861
c906108c
SS
1862/* symtab.c */
1863
d80b854b
UW
1864extern CORE_ADDR skip_prologue_using_sal (struct gdbarch *gdbarch,
1865 CORE_ADDR func_addr);
634aa483 1866
a14ed312
KB
1867extern struct symbol *fixup_symbol_section (struct symbol *,
1868 struct objfile *);
c906108c 1869
bf223d3e
PA
1870/* If MSYMBOL is an text symbol, look for a function debug symbol with
1871 the same address. Returns NULL if not found. This is necessary in
1872 case a function is an alias to some other function, because debug
1873 information is only emitted for the alias target function's
1874 definition, not for the alias. */
1875extern symbol *find_function_alias_target (bound_minimal_symbol msymbol);
1876
c906108c 1877/* Symbol searching */
5c04624b
DE
1878/* Note: struct symbol_search, search_symbols, et.al. are declared here,
1879 instead of making them local to symtab.c, for gdbtk's sake. */
c906108c 1880
b9c04fb2
TT
1881/* When using search_symbols, a vector of the following structs is
1882 returned. */
c906108c 1883struct symbol_search
17c5ed2c 1884{
b9c04fb2
TT
1885 symbol_search (int block_, struct symbol *symbol_)
1886 : block (block_),
1887 symbol (symbol_)
1888 {
1889 msymbol.minsym = nullptr;
1890 msymbol.objfile = nullptr;
1891 }
1892
1893 symbol_search (int block_, struct minimal_symbol *minsym,
1894 struct objfile *objfile)
1895 : block (block_),
1896 symbol (nullptr)
1897 {
1898 msymbol.minsym = minsym;
1899 msymbol.objfile = objfile;
1900 }
1901
1902 bool operator< (const symbol_search &other) const
1903 {
1904 return compare_search_syms (*this, other) < 0;
1905 }
1906
1907 bool operator== (const symbol_search &other) const
1908 {
1909 return compare_search_syms (*this, other) == 0;
1910 }
1911
c378eb4e
MS
1912 /* The block in which the match was found. Could be, for example,
1913 STATIC_BLOCK or GLOBAL_BLOCK. */
17c5ed2c 1914 int block;
c906108c 1915
17c5ed2c 1916 /* Information describing what was found.
c906108c 1917
d01060f0 1918 If symbol is NOT NULL, then information was found for this match. */
17c5ed2c 1919 struct symbol *symbol;
c906108c 1920
17c5ed2c 1921 /* If msymbol is non-null, then a match was made on something for
c378eb4e 1922 which only minimal_symbols exist. */
7c7b6655 1923 struct bound_minimal_symbol msymbol;
c906108c 1924
b9c04fb2
TT
1925private:
1926
1927 static int compare_search_syms (const symbol_search &sym_a,
1928 const symbol_search &sym_b);
17c5ed2c 1929};
c906108c 1930
b9c04fb2
TT
1931extern std::vector<symbol_search> search_symbols (const char *,
1932 enum search_domain, int,
1933 const char **);
c906108c 1934
51cc5b07
AC
1935/* The name of the ``main'' function.
1936 FIXME: cagney/2001-03-20: Can't make main_name() const since some
1937 of the calling code currently assumes that the string isn't
c378eb4e 1938 const. */
17c5ed2c 1939extern /*const */ char *main_name (void);
9e6c82ad 1940extern enum language main_language (void);
51cc5b07 1941
cf901d3b
DE
1942/* Lookup symbol NAME from DOMAIN in MAIN_OBJFILE's global blocks.
1943 This searches MAIN_OBJFILE as well as any associated separate debug info
1944 objfiles of MAIN_OBJFILE.
d12307c1 1945 Upon success fixes up the symbol's section if necessary. */
cf901d3b 1946
d12307c1 1947extern struct block_symbol
efad9b6a 1948 lookup_global_symbol_from_objfile (struct objfile *main_objfile,
cf901d3b
DE
1949 const char *name,
1950 const domain_enum domain);
3a40aaa0 1951
a6c727b2
DJ
1952/* Return 1 if the supplied producer string matches the ARM RealView
1953 compiler (armcc). */
1954int producer_is_realview (const char *producer);
3a40aaa0 1955
ccefe4c4
TT
1956void fixup_section (struct general_symbol_info *ginfo,
1957 CORE_ADDR addr, struct objfile *objfile);
1958
cf901d3b
DE
1959/* Look up objfile containing BLOCK. */
1960
c0201579
JK
1961struct objfile *lookup_objfile_from_block (const struct block *block);
1962
db0fec5c 1963extern unsigned int symtab_create_debug;
45cfd468 1964
cc485e62
DE
1965extern unsigned int symbol_lookup_debug;
1966
c011a4f4
DE
1967extern int basenames_may_differ;
1968
4aac40c8 1969int compare_filenames_for_search (const char *filename,
b57a636e 1970 const char *search_name);
4aac40c8 1971
cce0e923
DE
1972int compare_glob_filenames_for_search (const char *filename,
1973 const char *search_name);
1974
14bc53a8
PA
1975bool iterate_over_some_symtabs (const char *name,
1976 const char *real_path,
1977 struct compunit_symtab *first,
1978 struct compunit_symtab *after_last,
1979 gdb::function_view<bool (symtab *)> callback);
f8eba3c6
TT
1980
1981void iterate_over_symtabs (const char *name,
14bc53a8
PA
1982 gdb::function_view<bool (symtab *)> callback);
1983
f8eba3c6 1984
67d89901
TT
1985std::vector<CORE_ADDR> find_pcs_for_symtab_line
1986 (struct symtab *symtab, int line, struct linetable_entry **best_entry);
f8eba3c6 1987
14bc53a8
PA
1988/* Prototype for callbacks for LA_ITERATE_OVER_SYMBOLS. The callback
1989 is called once per matching symbol SYM. The callback should return
1990 true to indicate that LA_ITERATE_OVER_SYMBOLS should continue
1991 iterating, or false to indicate that the iteration should end. */
8e704927 1992
14bc53a8 1993typedef bool (symbol_found_callback_ftype) (symbol *sym);
8e704927 1994
b5ec771e
PA
1995void iterate_over_symbols (const struct block *block,
1996 const lookup_name_info &name,
f8eba3c6 1997 const domain_enum domain,
14bc53a8 1998 gdb::function_view<symbol_found_callback_ftype> callback);
f8eba3c6 1999
2f408ecb
PA
2000/* Storage type used by demangle_for_lookup. demangle_for_lookup
2001 either returns a const char * pointer that points to either of the
2002 fields of this type, or a pointer to the input NAME. This is done
2003 this way because the underlying functions that demangle_for_lookup
2004 calls either return a std::string (e.g., cp_canonicalize_string) or
2005 a malloc'ed buffer (libiberty's demangled), and we want to avoid
2006 unnecessary reallocation/string copying. */
2007class demangle_result_storage
2008{
2009public:
2010
2011 /* Swap the std::string storage with STR, and return a pointer to
2012 the beginning of the new string. */
2013 const char *swap_string (std::string &str)
2014 {
2015 std::swap (m_string, str);
2016 return m_string.c_str ();
2017 }
2018
2019 /* Set the malloc storage to now point at PTR. Any previous malloc
2020 storage is released. */
2021 const char *set_malloc_ptr (char *ptr)
2022 {
2023 m_malloc.reset (ptr);
2024 return ptr;
2025 }
2026
2027private:
2028
2029 /* The storage. */
2030 std::string m_string;
2031 gdb::unique_xmalloc_ptr<char> m_malloc;
2032};
2033
2034const char *
2035 demangle_for_lookup (const char *name, enum language lang,
2036 demangle_result_storage &storage);
f8eba3c6 2037
e623cf5d
TT
2038struct symbol *allocate_symbol (struct objfile *);
2039
38bf1463 2040void initialize_objfile_symbol (struct symbol *);
e623cf5d
TT
2041
2042struct template_symbol *allocate_template_symbol (struct objfile *);
2043
b5ec771e
PA
2044/* Test to see if the symbol of language SYMBOL_LANGUAGE specified by
2045 SYMNAME (which is already demangled for C++ symbols) matches
2046 SYM_TEXT in the first SYM_TEXT_LEN characters. If so, add it to
2047 the current completion list. */
2048void completion_list_add_name (completion_tracker &tracker,
2049 language symbol_language,
2050 const char *symname,
2051 const lookup_name_info &lookup_name,
b5ec771e
PA
2052 const char *text, const char *word);
2053
c906108c 2054#endif /* !defined(SYMTAB_H) */
This page took 2.291319 seconds and 4 git commands to generate.