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