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