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