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