Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Symbol table definitions for GDB. |
1bac305b | 2 | |
4a94e368 | 3 | Copyright (C) 1986-2022 Free Software Foundation, Inc. |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 10 | (at your option) any later version. |
c906108c | 11 | |
c5aa993b JM |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
c906108c | 16 | |
c5aa993b | 17 | You should have received a copy of the GNU General Public License |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
19 | |
20 | #if !defined (SYMTAB_H) | |
21 | #define SYMTAB_H 1 | |
22 | ||
a014b87a | 23 | #include <array> |
67d89901 | 24 | #include <vector> |
b5ec771e | 25 | #include <string> |
c2512106 | 26 | #include <set> |
268a13a5 | 27 | #include "gdbsupport/gdb_vecs.h" |
2f68a895 | 28 | #include "gdbtypes.h" |
bf31fd38 | 29 | #include "gdbsupport/gdb_obstack.h" |
d322d6d6 | 30 | #include "gdbsupport/gdb_regex.h" |
268a13a5 TT |
31 | #include "gdbsupport/enum-flags.h" |
32 | #include "gdbsupport/function-view.h" | |
33 | #include "gdbsupport/gdb_optional.h" | |
31edb802 | 34 | #include "gdbsupport/gdb_string_view.h" |
268a13a5 | 35 | #include "gdbsupport/next-iterator.h" |
9be25986 | 36 | #include "gdbsupport/iterator-range.h" |
eb3ff9a5 | 37 | #include "completer.h" |
f10ffa41 | 38 | #include "gdb-demangle.h" |
b2bc564f | 39 | #include "split-name.h" |
f8eba3c6 | 40 | |
5f8a3188 | 41 | /* Opaque declarations. */ |
da3331ec | 42 | struct ui_file; |
bd2b40ac | 43 | class frame_info_ptr; |
da3331ec | 44 | struct symbol; |
5f8a3188 | 45 | struct obstack; |
6a2f5abf | 46 | struct objfile; |
fe898f56 DC |
47 | struct block; |
48 | struct blockvector; | |
4c2df51b DJ |
49 | struct axs_value; |
50 | struct agent_expr; | |
6c95b8df | 51 | struct program_space; |
66a17cb6 | 52 | struct language_defn; |
4357ac6c | 53 | struct common_block; |
06096720 AB |
54 | struct obj_section; |
55 | struct cmd_list_element; | |
935676c9 | 56 | class probe; |
b5ec771e | 57 | struct lookup_name_info; |
74421c0b | 58 | struct code_breakpoint; |
b5ec771e PA |
59 | |
60 | /* How to match a lookup name against a symbol search name. */ | |
61 | enum class symbol_name_match_type | |
62 | { | |
63 | /* Wild matching. Matches unqualified symbol names in all | |
64 | namespace/module/packages, etc. */ | |
65 | WILD, | |
66 | ||
67 | /* Full matching. The lookup name indicates a fully-qualified name, | |
68 | and only matches symbol search names in the specified | |
69 | namespace/module/package. */ | |
70 | FULL, | |
71 | ||
de63c46b PA |
72 | /* Search name matching. This is like FULL, but the search name did |
73 | not come from the user; instead it is already a search name | |
987012b8 | 74 | retrieved from a search_name () call. |
de63c46b PA |
75 | For Ada, this avoids re-encoding an already-encoded search name |
76 | (which would potentially incorrectly lowercase letters in the | |
77 | linkage/search name that should remain uppercase). For C++, it | |
78 | avoids trying to demangle a name we already know is | |
79 | demangled. */ | |
80 | SEARCH_NAME, | |
81 | ||
b5ec771e PA |
82 | /* Expression matching. The same as FULL matching in most |
83 | languages. The same as WILD matching in Ada. */ | |
84 | EXPRESSION, | |
85 | }; | |
86 | ||
87 | /* Hash the given symbol search name according to LANGUAGE's | |
88 | rules. */ | |
89 | extern unsigned int search_name_hash (enum language language, | |
90 | const char *search_name); | |
91 | ||
92 | /* Ada-specific bits of a lookup_name_info object. This is lazily | |
93 | constructed on demand. */ | |
94 | ||
95 | class ada_lookup_name_info final | |
96 | { | |
97 | public: | |
98 | /* Construct. */ | |
99 | explicit ada_lookup_name_info (const lookup_name_info &lookup_name); | |
100 | ||
101 | /* Compare SYMBOL_SEARCH_NAME with our lookup name, using MATCH_TYPE | |
102 | as name match type. Returns true if there's a match, false | |
103 | otherwise. If non-NULL, store the matching results in MATCH. */ | |
104 | bool matches (const char *symbol_search_name, | |
105 | symbol_name_match_type match_type, | |
a207cff2 | 106 | completion_match_result *comp_match_res) const; |
b5ec771e PA |
107 | |
108 | /* The Ada-encoded lookup name. */ | |
109 | const std::string &lookup_name () const | |
110 | { return m_encoded_name; } | |
111 | ||
112 | /* Return true if we're supposed to be doing a wild match look | |
113 | up. */ | |
114 | bool wild_match_p () const | |
115 | { return m_wild_match_p; } | |
116 | ||
117 | /* Return true if we're looking up a name inside package | |
118 | Standard. */ | |
119 | bool standard_p () const | |
120 | { return m_standard_p; } | |
121 | ||
c63d3e8d PA |
122 | /* Return true if doing a verbatim match. */ |
123 | bool verbatim_p () const | |
124 | { return m_verbatim_p; } | |
125 | ||
b2bc564f TT |
126 | /* A wrapper for ::split_name that handles some Ada-specific |
127 | peculiarities. */ | |
128 | std::vector<gdb::string_view> split_name () const | |
129 | { | |
130 | if (m_verbatim_p || m_standard_p) | |
131 | { | |
132 | std::vector<gdb::string_view> result; | |
133 | if (m_standard_p) | |
134 | result.emplace_back ("standard"); | |
135 | result.emplace_back (m_encoded_name); | |
136 | return result; | |
137 | } | |
138 | return ::split_name (m_encoded_name.c_str (), split_style::UNDERSCORE); | |
139 | } | |
140 | ||
c63d3e8d | 141 | private: |
b5ec771e PA |
142 | /* The Ada-encoded lookup name. */ |
143 | std::string m_encoded_name; | |
144 | ||
145 | /* Whether the user-provided lookup name was Ada encoded. If so, | |
146 | then return encoded names in the 'matches' method's 'completion | |
147 | match result' output. */ | |
148 | bool m_encoded_p : 1; | |
149 | ||
150 | /* True if really doing wild matching. Even if the user requests | |
151 | wild matching, some cases require full matching. */ | |
152 | bool m_wild_match_p : 1; | |
153 | ||
154 | /* True if doing a verbatim match. This is true if the decoded | |
155 | version of the symbol name is wrapped in '<'/'>'. This is an | |
156 | escape hatch users can use to look up symbols the Ada encoding | |
157 | does not understand. */ | |
158 | bool m_verbatim_p : 1; | |
159 | ||
160 | /* True if the user specified a symbol name that is inside package | |
161 | Standard. Symbol names inside package Standard are handled | |
162 | specially. We always do a non-wild match of the symbol name | |
163 | without the "standard__" prefix, and only search static and | |
164 | global symbols. This was primarily introduced in order to allow | |
165 | the user to specifically access the standard exceptions using, | |
166 | for instance, Standard.Constraint_Error when Constraint_Error is | |
167 | ambiguous (due to the user defining its own Constraint_Error | |
168 | entity inside its program). */ | |
169 | bool m_standard_p : 1; | |
170 | }; | |
171 | ||
172 | /* Language-specific bits of a lookup_name_info object, for languages | |
173 | that do name searching using demangled names (C++/D/Go). This is | |
174 | lazily constructed on demand. */ | |
175 | ||
176 | struct demangle_for_lookup_info final | |
177 | { | |
178 | public: | |
179 | demangle_for_lookup_info (const lookup_name_info &lookup_name, | |
180 | language lang); | |
181 | ||
182 | /* The demangled lookup name. */ | |
183 | const std::string &lookup_name () const | |
184 | { return m_demangled_name; } | |
185 | ||
186 | private: | |
187 | /* The demangled lookup name. */ | |
188 | std::string m_demangled_name; | |
189 | }; | |
190 | ||
191 | /* Object that aggregates all information related to a symbol lookup | |
192 | name. I.e., the name that is matched against the symbol's search | |
193 | name. Caches per-language information so that it doesn't require | |
194 | recomputing it for every symbol comparison, like for example the | |
195 | Ada encoded name and the symbol's name hash for a given language. | |
196 | The object is conceptually immutable once constructed, and thus has | |
197 | no setters. This is to prevent some code path from tweaking some | |
198 | property of the lookup name for some local reason and accidentally | |
199 | altering the results of any continuing search(es). | |
200 | lookup_name_info objects are generally passed around as a const | |
201 | reference to reinforce that. (They're not passed around by value | |
202 | because they're not small.) */ | |
203 | class lookup_name_info final | |
204 | { | |
205 | public: | |
e0802d59 TT |
206 | /* We delete this overload so that the callers are required to |
207 | explicitly handle the lifetime of the name. */ | |
208 | lookup_name_info (std::string &&name, | |
209 | symbol_name_match_type match_type, | |
210 | bool completion_mode = false, | |
211 | bool ignore_parameters = false) = delete; | |
212 | ||
213 | /* This overload requires that NAME have a lifetime at least as long | |
214 | as the lifetime of this object. */ | |
215 | lookup_name_info (const std::string &name, | |
216 | symbol_name_match_type match_type, | |
217 | bool completion_mode = false, | |
218 | bool ignore_parameters = false) | |
219 | : m_match_type (match_type), | |
220 | m_completion_mode (completion_mode), | |
221 | m_ignore_parameters (ignore_parameters), | |
222 | m_name (name) | |
223 | {} | |
224 | ||
225 | /* This overload requires that NAME have a lifetime at least as long | |
226 | as the lifetime of this object. */ | |
227 | lookup_name_info (const char *name, | |
b5ec771e | 228 | symbol_name_match_type match_type, |
c62446b1 PA |
229 | bool completion_mode = false, |
230 | bool ignore_parameters = false) | |
b5ec771e PA |
231 | : m_match_type (match_type), |
232 | m_completion_mode (completion_mode), | |
c62446b1 | 233 | m_ignore_parameters (ignore_parameters), |
e0802d59 | 234 | m_name (name) |
b5ec771e PA |
235 | {} |
236 | ||
237 | /* Getters. See description of each corresponding field. */ | |
238 | symbol_name_match_type match_type () const { return m_match_type; } | |
239 | bool completion_mode () const { return m_completion_mode; } | |
e0802d59 | 240 | gdb::string_view name () const { return m_name; } |
c62446b1 PA |
241 | const bool ignore_parameters () const { return m_ignore_parameters; } |
242 | ||
e0802d59 TT |
243 | /* Like the "name" method but guarantees that the returned string is |
244 | \0-terminated. */ | |
245 | const char *c_str () const | |
246 | { | |
247 | /* Actually this is always guaranteed due to how the class is | |
248 | constructed. */ | |
249 | return m_name.data (); | |
250 | } | |
251 | ||
c62446b1 PA |
252 | /* Return a version of this lookup name that is usable with |
253 | comparisons against symbols have no parameter info, such as | |
254 | psymbols and GDB index symbols. */ | |
255 | lookup_name_info make_ignore_params () const | |
256 | { | |
e0802d59 | 257 | return lookup_name_info (c_str (), m_match_type, m_completion_mode, |
c62446b1 PA |
258 | true /* ignore params */); |
259 | } | |
b5ec771e PA |
260 | |
261 | /* Get the search name hash for searches in language LANG. */ | |
262 | unsigned int search_name_hash (language lang) const | |
263 | { | |
264 | /* Only compute each language's hash once. */ | |
265 | if (!m_demangled_hashes_p[lang]) | |
266 | { | |
267 | m_demangled_hashes[lang] | |
e0802d59 | 268 | = ::search_name_hash (lang, language_lookup_name (lang)); |
b5ec771e PA |
269 | m_demangled_hashes_p[lang] = true; |
270 | } | |
271 | return m_demangled_hashes[lang]; | |
272 | } | |
273 | ||
274 | /* Get the search name for searches in language LANG. */ | |
e0802d59 | 275 | const char *language_lookup_name (language lang) const |
b5ec771e PA |
276 | { |
277 | switch (lang) | |
278 | { | |
279 | case language_ada: | |
e0802d59 | 280 | return ada ().lookup_name ().c_str (); |
b5ec771e | 281 | case language_cplus: |
e0802d59 | 282 | return cplus ().lookup_name ().c_str (); |
b5ec771e | 283 | case language_d: |
e0802d59 | 284 | return d ().lookup_name ().c_str (); |
b5ec771e | 285 | case language_go: |
e0802d59 | 286 | return go ().lookup_name ().c_str (); |
b5ec771e | 287 | default: |
e0802d59 | 288 | return m_name.data (); |
b5ec771e PA |
289 | } |
290 | } | |
291 | ||
b2bc564f TT |
292 | /* A wrapper for ::split_name (see split-name.h) that splits this |
293 | name, and that handles any language-specific peculiarities. */ | |
294 | std::vector<gdb::string_view> split_name (language lang) const | |
295 | { | |
296 | if (lang == language_ada) | |
297 | return ada ().split_name (); | |
298 | split_style style = split_style::NONE; | |
299 | switch (lang) | |
300 | { | |
301 | case language_cplus: | |
302 | case language_rust: | |
303 | style = split_style::CXX; | |
304 | break; | |
305 | case language_d: | |
306 | case language_go: | |
307 | style = split_style::DOT; | |
308 | break; | |
309 | } | |
310 | return ::split_name (language_lookup_name (lang), style); | |
311 | } | |
312 | ||
b5ec771e PA |
313 | /* Get the Ada-specific lookup info. */ |
314 | const ada_lookup_name_info &ada () const | |
315 | { | |
316 | maybe_init (m_ada); | |
317 | return *m_ada; | |
318 | } | |
319 | ||
320 | /* Get the C++-specific lookup info. */ | |
321 | const demangle_for_lookup_info &cplus () const | |
322 | { | |
323 | maybe_init (m_cplus, language_cplus); | |
324 | return *m_cplus; | |
325 | } | |
326 | ||
327 | /* Get the D-specific lookup info. */ | |
328 | const demangle_for_lookup_info &d () const | |
329 | { | |
330 | maybe_init (m_d, language_d); | |
331 | return *m_d; | |
332 | } | |
333 | ||
334 | /* Get the Go-specific lookup info. */ | |
335 | const demangle_for_lookup_info &go () const | |
336 | { | |
337 | maybe_init (m_go, language_go); | |
338 | return *m_go; | |
339 | } | |
340 | ||
341 | /* Get a reference to a lookup_name_info object that matches any | |
342 | symbol name. */ | |
343 | static const lookup_name_info &match_any (); | |
344 | ||
345 | private: | |
346 | /* Initialize FIELD, if not initialized yet. */ | |
347 | template<typename Field, typename... Args> | |
348 | void maybe_init (Field &field, Args&&... args) const | |
349 | { | |
350 | if (!field) | |
351 | field.emplace (*this, std::forward<Args> (args)...); | |
352 | } | |
353 | ||
354 | /* The lookup info as passed to the ctor. */ | |
355 | symbol_name_match_type m_match_type; | |
356 | bool m_completion_mode; | |
c62446b1 | 357 | bool m_ignore_parameters; |
e0802d59 | 358 | gdb::string_view m_name; |
b5ec771e PA |
359 | |
360 | /* Language-specific info. These fields are filled lazily the first | |
361 | time a lookup is done in the corresponding language. They're | |
362 | mutable because lookup_name_info objects are typically passed | |
363 | around by const reference (see intro), and they're conceptually | |
364 | "cache" that can always be reconstructed from the non-mutable | |
365 | fields. */ | |
366 | mutable gdb::optional<ada_lookup_name_info> m_ada; | |
367 | mutable gdb::optional<demangle_for_lookup_info> m_cplus; | |
368 | mutable gdb::optional<demangle_for_lookup_info> m_d; | |
369 | mutable gdb::optional<demangle_for_lookup_info> m_go; | |
370 | ||
371 | /* The demangled hashes. Stored in an array with one entry for each | |
372 | possible language. The second array records whether we've | |
373 | already computed the each language's hash. (These are separate | |
374 | arrays instead of a single array of optional<unsigned> to avoid | |
375 | alignment padding). */ | |
376 | mutable std::array<unsigned int, nr_languages> m_demangled_hashes; | |
377 | mutable std::array<bool, nr_languages> m_demangled_hashes_p {}; | |
378 | }; | |
379 | ||
380 | /* Comparison function for completion symbol lookup. | |
381 | ||
382 | Returns true if the symbol name matches against LOOKUP_NAME. | |
383 | ||
384 | SYMBOL_SEARCH_NAME should be a symbol's "search" name. | |
385 | ||
a207cff2 PA |
386 | On success and if non-NULL, COMP_MATCH_RES->match is set to point |
387 | to the symbol name as should be presented to the user as a | |
388 | completion match list element. In most languages, this is the same | |
389 | as the symbol's search name, but in some, like Ada, the display | |
390 | name is dynamically computed within the comparison routine. | |
391 | ||
392 | Also, on success and if non-NULL, COMP_MATCH_RES->match_for_lcd | |
393 | points the part of SYMBOL_SEARCH_NAME that was considered to match | |
394 | LOOKUP_NAME. E.g., in C++, in linespec/wild mode, if the symbol is | |
395 | "foo::function()" and LOOKUP_NAME is "function(", MATCH_FOR_LCD | |
396 | points to "function()" inside SYMBOL_SEARCH_NAME. */ | |
b5ec771e PA |
397 | typedef bool (symbol_name_matcher_ftype) |
398 | (const char *symbol_search_name, | |
399 | const lookup_name_info &lookup_name, | |
a207cff2 | 400 | completion_match_result *comp_match_res); |
c906108c | 401 | |
a7f19c79 MC |
402 | /* Some of the structures in this file are space critical. |
403 | The space-critical structures are: | |
404 | ||
405 | struct general_symbol_info | |
406 | struct symbol | |
407 | struct partial_symbol | |
408 | ||
5bccb4d1 | 409 | These structures are laid out to encourage good packing. |
a7f19c79 MC |
410 | They use ENUM_BITFIELD and short int fields, and they order the |
411 | structure members so that fields less than a word are next | |
c378eb4e | 412 | to each other so they can be packed together. */ |
a7f19c79 MC |
413 | |
414 | /* Rearranged: used ENUM_BITFIELD and rearranged field order in | |
415 | all the space critical structures (plus struct minimal_symbol). | |
416 | Memory usage dropped from 99360768 bytes to 90001408 bytes. | |
417 | I measured this with before-and-after tests of | |
418 | "HEAD-old-gdb -readnow HEAD-old-gdb" and | |
419 | "HEAD-new-gdb -readnow HEAD-old-gdb" on native i686-pc-linux-gnu, | |
420 | red hat linux 8, with LD_LIBRARY_PATH=/usr/lib/debug, | |
421 | typing "maint space 1" at the first command prompt. | |
422 | ||
423 | Here is another measurement (from andrew c): | |
424 | # no /usr/lib/debug, just plain glibc, like a normal user | |
425 | gdb HEAD-old-gdb | |
426 | (gdb) break internal_error | |
427 | (gdb) run | |
428 | (gdb) maint internal-error | |
429 | (gdb) backtrace | |
430 | (gdb) maint space 1 | |
431 | ||
432 | gdb gdb_6_0_branch 2003-08-19 space used: 8896512 | |
433 | gdb HEAD 2003-08-19 space used: 8904704 | |
434 | gdb HEAD 2003-08-21 space used: 8396800 (+symtab.h) | |
435 | gdb HEAD 2003-08-21 space used: 8265728 (+gdbtypes.h) | |
436 | ||
437 | The third line shows the savings from the optimizations in symtab.h. | |
438 | The fourth line shows the savings from the optimizations in | |
439 | gdbtypes.h. Both optimizations are in gdb HEAD now. | |
440 | ||
441 | --chastain 2003-08-21 */ | |
442 | ||
c906108c SS |
443 | /* Define a structure for the information that is common to all symbol types, |
444 | including minimal symbols, partial symbols, and full symbols. In a | |
445 | multilanguage environment, some language specific information may need to | |
c378eb4e | 446 | be recorded along with each symbol. */ |
c906108c | 447 | |
c378eb4e | 448 | /* This structure is space critical. See space comments at the top. */ |
c906108c SS |
449 | |
450 | struct general_symbol_info | |
17c5ed2c | 451 | { |
c9d95fa3 CB |
452 | /* Short version as to when to use which name accessor: |
453 | Use natural_name () to refer to the name of the symbol in the original | |
454 | source code. Use linkage_name () if you want to know what the linker | |
455 | thinks the symbol's name is. Use print_name () for output. Use | |
456 | demangled_name () if you specifically need to know whether natural_name () | |
457 | and linkage_name () are different. */ | |
458 | ||
459 | const char *linkage_name () const | |
4d4eaa30 | 460 | { return m_name; } |
c9d95fa3 CB |
461 | |
462 | /* Return SYMBOL's "natural" name, i.e. the name that it was called in | |
463 | the original source code. In languages like C++ where symbols may | |
464 | be mangled for ease of manipulation by the linker, this is the | |
465 | demangled name. */ | |
466 | const char *natural_name () const; | |
467 | ||
468 | /* Returns a version of the name of a symbol that is | |
469 | suitable for output. In C++ this is the "demangled" form of the | |
470 | name if demangle is on and the "mangled" form of the name if | |
471 | demangle is off. In other languages this is just the symbol name. | |
472 | The result should never be NULL. Don't use this for internal | |
473 | purposes (e.g. storing in a hashtable): it's only suitable for output. */ | |
474 | const char *print_name () const | |
475 | { return demangle ? natural_name () : linkage_name (); } | |
476 | ||
477 | /* Return the demangled name for a symbol based on the language for | |
478 | that symbol. If no demangled name exists, return NULL. */ | |
479 | const char *demangled_name () const; | |
480 | ||
481 | /* Returns the name to be used when sorting and searching symbols. | |
482 | In C++, we search for the demangled form of a name, | |
483 | and so sort symbols accordingly. In Ada, however, we search by mangled | |
484 | name. If there is no distinct demangled name, then this | |
485 | returns the same value (same pointer) as linkage_name (). */ | |
486 | const char *search_name () const; | |
487 | ||
43678b0a CB |
488 | /* Set just the linkage name of a symbol; do not try to demangle |
489 | it. Used for constructs which do not have a mangled name, | |
4d4eaa30 | 490 | e.g. struct tags. Unlike compute_and_set_names, linkage_name must |
43678b0a CB |
491 | be terminated and either already on the objfile's obstack or |
492 | permanently allocated. */ | |
493 | void set_linkage_name (const char *linkage_name) | |
4d4eaa30 | 494 | { m_name = linkage_name; } |
43678b0a | 495 | |
ff985671 TT |
496 | /* Set the demangled name of this symbol to NAME. NAME must be |
497 | already correctly allocated. If the symbol's language is Ada, | |
498 | then the name is ignored and the obstack is set. */ | |
499 | void set_demangled_name (const char *name, struct obstack *obstack); | |
500 | ||
c1b5c1eb CB |
501 | enum language language () const |
502 | { return m_language; } | |
503 | ||
d3ecddab CB |
504 | /* Initializes the language dependent portion of a symbol |
505 | depending upon the language for the symbol. */ | |
506 | void set_language (enum language language, struct obstack *obstack); | |
507 | ||
4d4eaa30 CB |
508 | /* Set the linkage and natural names of a symbol, by demangling |
509 | the linkage name. If linkage_name may not be nullterminated, | |
510 | copy_name must be set to true. */ | |
511 | void compute_and_set_names (gdb::string_view linkage_name, bool copy_name, | |
512 | struct objfile_per_bfd_storage *per_bfd, | |
513 | gdb::optional<hashval_t> hash | |
dda83cd7 | 514 | = gdb::optional<hashval_t> ()); |
4d4eaa30 | 515 | |
4aeddc50 SM |
516 | CORE_ADDR value_address () const |
517 | { | |
518 | return m_value.address; | |
519 | } | |
520 | ||
521 | void set_value_address (CORE_ADDR address) | |
522 | { | |
523 | m_value.address = address; | |
524 | } | |
525 | ||
22abf04a | 526 | /* Name of the symbol. This is a required field. Storage for the |
4a146b47 EZ |
527 | name is allocated on the objfile_obstack for the associated |
528 | objfile. For languages like C++ that make a distinction between | |
529 | the mangled name and demangled name, this is the mangled | |
530 | name. */ | |
c906108c | 531 | |
4d4eaa30 | 532 | const char *m_name; |
c906108c | 533 | |
17c5ed2c DC |
534 | /* Value of the symbol. Which member of this union to use, and what |
535 | it means, depends on what kind of symbol this is and its | |
536 | SYMBOL_CLASS. See comments there for more details. All of these | |
537 | are in host byte order (though what they point to might be in | |
538 | target byte order, e.g. LOC_CONST_BYTES). */ | |
c906108c | 539 | |
17c5ed2c DC |
540 | union |
541 | { | |
12df843f | 542 | LONGEST ivalue; |
c906108c | 543 | |
3977b71f | 544 | const struct block *block; |
c906108c | 545 | |
d47a1bc1 | 546 | const gdb_byte *bytes; |
c906108c | 547 | |
17c5ed2c | 548 | CORE_ADDR address; |
c906108c | 549 | |
5a352474 | 550 | /* A common block. Used with LOC_COMMON_BLOCK. */ |
4357ac6c | 551 | |
17a40b44 | 552 | const struct common_block *common_block; |
4357ac6c | 553 | |
c378eb4e | 554 | /* For opaque typedef struct chain. */ |
c906108c | 555 | |
17c5ed2c DC |
556 | struct symbol *chain; |
557 | } | |
4aeddc50 | 558 | m_value; |
c906108c | 559 | |
17c5ed2c | 560 | /* Since one and only one language can apply, wrap the language specific |
29df156d | 561 | information inside a union. */ |
c906108c | 562 | |
17c5ed2c DC |
563 | union |
564 | { | |
f85f34ed TT |
565 | /* A pointer to an obstack that can be used for storage associated |
566 | with this symbol. This is only used by Ada, and only when the | |
567 | 'ada_mangled' field is zero. */ | |
568 | struct obstack *obstack; | |
569 | ||
afa16725 | 570 | /* This is used by languages which wish to store a demangled name. |
9c37b5ae | 571 | currently used by Ada, C++, and Objective C. */ |
615b3f62 | 572 | const char *demangled_name; |
17c5ed2c DC |
573 | } |
574 | language_specific; | |
c5aa993b | 575 | |
17c5ed2c DC |
576 | /* Record the source code language that applies to this symbol. |
577 | This is used to select one of the fields from the language specific | |
c378eb4e | 578 | union above. */ |
c5aa993b | 579 | |
c1b5c1eb | 580 | ENUM_BITFIELD(language) m_language : LANGUAGE_BITS; |
c5aa993b | 581 | |
a04a15f5 | 582 | /* This is only used by Ada. If set, then the 'demangled_name' field |
f85f34ed TT |
583 | of language_specific is valid. Otherwise, the 'obstack' field is |
584 | valid. */ | |
585 | unsigned int ada_mangled : 1; | |
586 | ||
17c5ed2c DC |
587 | /* Which section is this symbol in? This is an index into |
588 | section_offsets for this objfile. Negative means that the symbol | |
e27d198c | 589 | does not get relocated relative to a section. */ |
c5aa993b | 590 | |
a52d653e AB |
591 | short m_section; |
592 | ||
593 | /* Set the index into the obj_section list (within the containing | |
594 | objfile) for the section that contains this symbol. See M_SECTION | |
595 | for more details. */ | |
596 | ||
597 | void set_section_index (short idx) | |
598 | { m_section = idx; } | |
599 | ||
600 | /* Return the index into the obj_section list (within the containing | |
601 | objfile) for the section that contains this symbol. See M_SECTION | |
602 | for more details. */ | |
603 | ||
604 | short section_index () const | |
605 | { return m_section; } | |
ebbc3a7d AB |
606 | |
607 | /* Return the obj_section from OBJFILE for this symbol. The symbol | |
608 | returned is based on the SECTION member variable, and can be nullptr | |
609 | if SECTION is negative. */ | |
610 | ||
611 | struct obj_section *obj_section (const struct objfile *objfile) const; | |
17c5ed2c | 612 | }; |
c906108c | 613 | |
714835d5 | 614 | extern CORE_ADDR symbol_overlayed_address (CORE_ADDR, struct obj_section *); |
c906108c | 615 | |
4b610737 TT |
616 | /* Return the address of SYM. The MAYBE_COPIED flag must be set on |
617 | SYM. If SYM appears in the main program's minimal symbols, then | |
618 | that minsym's address is returned; otherwise, SYM's address is | |
619 | returned. This should generally only be used via the | |
620 | SYMBOL_VALUE_ADDRESS macro. */ | |
621 | ||
622 | extern CORE_ADDR get_symbol_address (const struct symbol *sym); | |
623 | ||
d55c9a68 TT |
624 | /* Try to determine the demangled name for a symbol, based on the |
625 | language of that symbol. If the language is set to language_auto, | |
626 | it will attempt to find any demangling algorithm that works and | |
627 | then set the language appropriately. The returned name is allocated | |
628 | by the demangler and should be xfree'd. */ | |
629 | ||
3456e70c TT |
630 | extern gdb::unique_xmalloc_ptr<char> symbol_find_demangled_name |
631 | (struct general_symbol_info *gsymbol, const char *mangled); | |
d55c9a68 | 632 | |
81e32b6a | 633 | /* Return true if NAME matches the "search" name of GSYMBOL, according |
b5ec771e | 634 | to the symbol's language. */ |
b5ec771e PA |
635 | extern bool symbol_matches_search_name |
636 | (const struct general_symbol_info *gsymbol, | |
637 | const lookup_name_info &name); | |
4725b721 | 638 | |
5ffa0793 PA |
639 | /* Compute the hash of the given symbol search name of a symbol of |
640 | language LANGUAGE. */ | |
641 | extern unsigned int search_name_hash (enum language language, | |
642 | const char *search_name); | |
643 | ||
87193939 MC |
644 | /* Classification types for a minimal symbol. These should be taken as |
645 | "advisory only", since if gdb can't easily figure out a | |
646 | classification it simply selects mst_unknown. It may also have to | |
647 | guess when it can't figure out which is a better match between two | |
648 | types (mst_data versus mst_bss) for example. Since the minimal | |
649 | symbol info is sometimes derived from the BFD library's view of a | |
c378eb4e | 650 | file, we need to live with what information bfd supplies. */ |
87193939 MC |
651 | |
652 | enum minimal_symbol_type | |
653 | { | |
654 | mst_unknown = 0, /* Unknown type, the default */ | |
655 | mst_text, /* Generally executable instructions */ | |
f50776aa PA |
656 | |
657 | /* A GNU ifunc symbol, in the .text section. GDB uses to know | |
658 | whether the user is setting a breakpoint on a GNU ifunc function, | |
659 | and thus GDB needs to actually set the breakpoint on the target | |
660 | function. It is also used to know whether the program stepped | |
661 | into an ifunc resolver -- the resolver may get a separate | |
662 | symbol/alias under a different name, but it'll have the same | |
663 | address as the ifunc symbol. */ | |
664 | mst_text_gnu_ifunc, /* Executable code returning address | |
665 | of executable code */ | |
666 | ||
667 | /* A GNU ifunc function descriptor symbol, in a data section | |
668 | (typically ".opd"). Seen on architectures that use function | |
669 | descriptors, like PPC64/ELFv1. In this case, this symbol's value | |
670 | is the address of the descriptor. There'll be a corresponding | |
671 | mst_text_gnu_ifunc synthetic symbol for the text/entry | |
672 | address. */ | |
673 | mst_data_gnu_ifunc, /* Executable code returning address | |
0875794a | 674 | of executable code */ |
f50776aa | 675 | |
0875794a | 676 | mst_slot_got_plt, /* GOT entries for .plt sections */ |
87193939 MC |
677 | mst_data, /* Generally initialized data */ |
678 | mst_bss, /* Generally uninitialized data */ | |
679 | mst_abs, /* Generally absolute (nonrelocatable) */ | |
680 | /* GDB uses mst_solib_trampoline for the start address of a shared | |
681 | library trampoline entry. Breakpoints for shared library functions | |
682 | are put there if the shared library is not yet loaded. | |
683 | After the shared library is loaded, lookup_minimal_symbol will | |
684 | prefer the minimal symbol from the shared library (usually | |
685 | a mst_text symbol) over the mst_solib_trampoline symbol, and the | |
686 | breakpoints will be moved to their true address in the shared | |
687 | library via breakpoint_re_set. */ | |
688 | mst_solib_trampoline, /* Shared library trampoline code */ | |
689 | /* For the mst_file* types, the names are only guaranteed to be unique | |
690 | within a given .o file. */ | |
691 | mst_file_text, /* Static version of mst_text */ | |
692 | mst_file_data, /* Static version of mst_data */ | |
51cdc993 DE |
693 | mst_file_bss, /* Static version of mst_bss */ |
694 | nr_minsym_types | |
87193939 MC |
695 | }; |
696 | ||
51cdc993 DE |
697 | /* The number of enum minimal_symbol_type values, with some padding for |
698 | reasonable growth. */ | |
699 | #define MINSYM_TYPE_BITS 4 | |
700 | gdb_static_assert (nr_minsym_types <= (1 << MINSYM_TYPE_BITS)); | |
701 | ||
4aeddc50 SM |
702 | /* Return the address of MINSYM, which comes from OBJF. The |
703 | MAYBE_COPIED flag must be set on MINSYM. If MINSYM appears in the | |
704 | main program's minimal symbols, then that minsym's address is | |
705 | returned; otherwise, MINSYM's address is returned. This should | |
706 | generally only be used via the MSYMBOL_VALUE_ADDRESS macro. */ | |
707 | ||
708 | extern CORE_ADDR get_msymbol_address (struct objfile *objf, | |
709 | const struct minimal_symbol *minsym); | |
710 | ||
c906108c SS |
711 | /* Define a simple structure used to hold some very basic information about |
712 | all defined global symbols (text, data, bss, abs, etc). The only required | |
713 | information is the general_symbol_info. | |
714 | ||
715 | In many cases, even if a file was compiled with no special options for | |
716 | debugging at all, as long as was not stripped it will contain sufficient | |
717 | information to build a useful minimal symbol table using this structure. | |
718 | Even when a file contains enough debugging information to build a full | |
719 | symbol table, these minimal symbols are still useful for quickly mapping | |
720 | between names and addresses, and vice versa. They are also sometimes | |
c378eb4e | 721 | used to figure out what full symbol table entries need to be read in. */ |
c906108c | 722 | |
eefba3da | 723 | struct minimal_symbol : public general_symbol_info |
17c5ed2c | 724 | { |
4aeddc50 SM |
725 | LONGEST value_longest () const |
726 | { | |
727 | return m_value.ivalue; | |
728 | } | |
729 | ||
730 | /* The relocated address of the minimal symbol, using the section | |
731 | offsets from OBJFILE. */ | |
732 | CORE_ADDR value_address (objfile *objfile) const; | |
733 | ||
734 | /* The unrelocated address of the minimal symbol. */ | |
735 | CORE_ADDR value_raw_address () const | |
736 | { | |
737 | return m_value.address; | |
738 | } | |
739 | ||
60f62e2b SM |
740 | /* Return this minimal symbol's type. */ |
741 | ||
742 | minimal_symbol_type type () const | |
743 | { | |
744 | return m_type; | |
745 | } | |
746 | ||
747 | /* Set this minimal symbol's type. */ | |
748 | ||
749 | void set_type (minimal_symbol_type type) | |
750 | { | |
751 | m_type = type; | |
752 | } | |
753 | ||
5bbfd12d SM |
754 | /* Return this minimal symbol's size. */ |
755 | ||
756 | unsigned long size () const | |
757 | { | |
758 | return m_size; | |
759 | } | |
760 | ||
761 | /* Set this minimal symbol's size. */ | |
762 | ||
763 | void set_size (unsigned long size) | |
764 | { | |
765 | m_size = size; | |
766 | m_has_size = 1; | |
767 | } | |
768 | ||
769 | /* Return true if this minimal symbol's size is known. */ | |
770 | ||
771 | bool has_size () const | |
772 | { | |
773 | return m_has_size; | |
774 | } | |
775 | ||
e165fcef SM |
776 | /* Return this minimal symbol's first target-specific flag. */ |
777 | ||
778 | bool target_flag_1 () const | |
779 | { | |
780 | return m_target_flag_1; | |
781 | } | |
782 | ||
783 | /* Set this minimal symbol's first target-specific flag. */ | |
784 | ||
785 | void set_target_flag_1 (bool target_flag_1) | |
786 | { | |
787 | m_target_flag_1 = target_flag_1; | |
788 | } | |
789 | ||
790 | /* Return this minimal symbol's second target-specific flag. */ | |
791 | ||
792 | bool target_flag_2 () const | |
793 | { | |
794 | return m_target_flag_2; | |
795 | } | |
796 | ||
797 | /* Set this minimal symbol's second target-specific flag. */ | |
798 | ||
799 | void set_target_flag_2 (bool target_flag_2) | |
800 | { | |
801 | m_target_flag_2 = target_flag_2; | |
802 | } | |
803 | ||
8763cede | 804 | /* Size of this symbol. dbx_end_psymtab in dbxread.c uses this |
f594e5e9 MC |
805 | information to calculate the end of the partial symtab based on the |
806 | address of the last symbol plus the size of the last symbol. */ | |
807 | ||
5bbfd12d | 808 | unsigned long m_size; |
f594e5e9 | 809 | |
17c5ed2c | 810 | /* Which source file is this symbol in? Only relevant for mst_file_*. */ |
04aba065 | 811 | const char *filename; |
c906108c | 812 | |
87193939 | 813 | /* Classification type for this minimal symbol. */ |
17c5ed2c | 814 | |
60f62e2b | 815 | ENUM_BITFIELD(minimal_symbol_type) m_type : MINSYM_TYPE_BITS; |
17c5ed2c | 816 | |
422d65e7 DE |
817 | /* Non-zero if this symbol was created by gdb. |
818 | Such symbols do not appear in the output of "info var|fun". */ | |
819 | unsigned int created_by_gdb : 1; | |
820 | ||
b887350f | 821 | /* Two flag bits provided for the use of the target. */ |
e165fcef SM |
822 | unsigned int m_target_flag_1 : 1; |
823 | unsigned int m_target_flag_2 : 1; | |
b887350f | 824 | |
d9eaeb59 JB |
825 | /* Nonzero iff the size of the minimal symbol has been set. |
826 | Symbol size information can sometimes not be determined, because | |
827 | the object file format may not carry that piece of information. */ | |
5bbfd12d | 828 | unsigned int m_has_size : 1; |
d9eaeb59 | 829 | |
4b610737 TT |
830 | /* For data symbols only, if this is set, then the symbol might be |
831 | subject to copy relocation. In this case, a minimal symbol | |
832 | matching the symbol's linkage name is first looked for in the | |
833 | main objfile. If found, then that address is used; otherwise the | |
834 | address in this symbol is used. */ | |
835 | ||
836 | unsigned maybe_copied : 1; | |
837 | ||
5a79c107 TT |
838 | /* Non-zero if this symbol ever had its demangled name set (even if |
839 | it was set to NULL). */ | |
840 | unsigned int name_set : 1; | |
841 | ||
17c5ed2c DC |
842 | /* Minimal symbols with the same hash key are kept on a linked |
843 | list. This is the link. */ | |
844 | ||
845 | struct minimal_symbol *hash_next; | |
846 | ||
847 | /* Minimal symbols are stored in two different hash tables. This is | |
848 | the `next' pointer for the demangled hash table. */ | |
849 | ||
850 | struct minimal_symbol *demangled_hash_next; | |
1ed9f74e | 851 | |
eefba3da | 852 | /* True if this symbol is of some data type. */ |
1ed9f74e PW |
853 | |
854 | bool data_p () const; | |
855 | ||
856 | /* True if MSYMBOL is of some text type. */ | |
857 | ||
858 | bool text_p () const; | |
17c5ed2c | 859 | }; |
c906108c | 860 | |
c35384fb TT |
861 | #include "minsyms.h" |
862 | ||
c906108c | 863 | \f |
c5aa993b | 864 | |
c906108c SS |
865 | /* Represent one symbol name; a variable, constant, function or typedef. */ |
866 | ||
176620f1 | 867 | /* Different name domains for symbols. Looking up a symbol specifies a |
c378eb4e | 868 | domain and ignores symbol definitions in other name domains. */ |
c906108c | 869 | |
0d1703b8 | 870 | enum domain_enum |
17c5ed2c | 871 | { |
176620f1 | 872 | /* UNDEF_DOMAIN is used when a domain has not been discovered or |
17c5ed2c | 873 | none of the following apply. This usually indicates an error either |
c378eb4e | 874 | in the symbol information or in gdb's handling of symbols. */ |
c906108c | 875 | |
176620f1 | 876 | UNDEF_DOMAIN, |
c906108c | 877 | |
176620f1 | 878 | /* VAR_DOMAIN is the usual domain. In C, this contains variables, |
c378eb4e | 879 | function names, typedef names and enum type values. */ |
c906108c | 880 | |
176620f1 | 881 | VAR_DOMAIN, |
c906108c | 882 | |
176620f1 | 883 | /* STRUCT_DOMAIN is used in C to hold struct, union and enum type names. |
17c5ed2c | 884 | Thus, if `struct foo' is used in a C program, it produces a symbol named |
c378eb4e | 885 | `foo' in the STRUCT_DOMAIN. */ |
c906108c | 886 | |
176620f1 | 887 | STRUCT_DOMAIN, |
c906108c | 888 | |
530e8392 KB |
889 | /* MODULE_DOMAIN is used in Fortran to hold module type names. */ |
890 | ||
891 | MODULE_DOMAIN, | |
892 | ||
0f5238ed | 893 | /* LABEL_DOMAIN may be used for names of labels (for gotos). */ |
c906108c | 894 | |
4357ac6c TT |
895 | LABEL_DOMAIN, |
896 | ||
5a352474 JK |
897 | /* Fortran common blocks. Their naming must be separate from VAR_DOMAIN. |
898 | They also always use LOC_COMMON_BLOCK. */ | |
51cdc993 DE |
899 | COMMON_BLOCK_DOMAIN, |
900 | ||
901 | /* This must remain last. */ | |
902 | NR_DOMAINS | |
0d1703b8 | 903 | }; |
c906108c | 904 | |
c01feb36 DE |
905 | /* The number of bits in a symbol used to represent the domain. */ |
906 | ||
51cdc993 DE |
907 | #define SYMBOL_DOMAIN_BITS 3 |
908 | gdb_static_assert (NR_DOMAINS <= (1 << SYMBOL_DOMAIN_BITS)); | |
c01feb36 | 909 | |
20c681d1 DE |
910 | extern const char *domain_name (domain_enum); |
911 | ||
470c0b1c | 912 | /* Searching domains, used when searching for symbols. Element numbers are |
e8930875 | 913 | hardcoded in GDB, check all enum uses before changing it. */ |
c906108c | 914 | |
8903c50d TT |
915 | enum search_domain |
916 | { | |
bd2e94ce TT |
917 | /* Everything in VAR_DOMAIN minus FUNCTIONS_DOMAIN and |
918 | TYPES_DOMAIN. */ | |
e8930875 | 919 | VARIABLES_DOMAIN = 0, |
c906108c | 920 | |
c378eb4e | 921 | /* All functions -- for some reason not methods, though. */ |
e8930875 | 922 | FUNCTIONS_DOMAIN = 1, |
c906108c | 923 | |
17c5ed2c | 924 | /* All defined types */ |
e8930875 | 925 | TYPES_DOMAIN = 2, |
7b08b9eb | 926 | |
59c35742 AB |
927 | /* All modules. */ |
928 | MODULES_DOMAIN = 3, | |
929 | ||
7b08b9eb | 930 | /* Any type. */ |
59c35742 | 931 | ALL_DOMAIN = 4 |
8903c50d | 932 | }; |
c906108c | 933 | |
20c681d1 DE |
934 | extern const char *search_domain_name (enum search_domain); |
935 | ||
c906108c SS |
936 | /* An address-class says where to find the value of a symbol. */ |
937 | ||
938 | enum address_class | |
17c5ed2c | 939 | { |
c378eb4e | 940 | /* Not used; catches errors. */ |
c5aa993b | 941 | |
17c5ed2c | 942 | LOC_UNDEF, |
c906108c | 943 | |
c378eb4e | 944 | /* Value is constant int SYMBOL_VALUE, host byteorder. */ |
c906108c | 945 | |
17c5ed2c | 946 | LOC_CONST, |
c906108c | 947 | |
c378eb4e | 948 | /* Value is at fixed address SYMBOL_VALUE_ADDRESS. */ |
c906108c | 949 | |
17c5ed2c | 950 | LOC_STATIC, |
c906108c | 951 | |
768a979c UW |
952 | /* Value is in register. SYMBOL_VALUE is the register number |
953 | in the original debug format. SYMBOL_REGISTER_OPS holds a | |
954 | function that can be called to transform this into the | |
955 | actual register number this represents in a specific target | |
956 | architecture (gdbarch). | |
2a2d4dc3 AS |
957 | |
958 | For some symbol formats (stabs, for some compilers at least), | |
959 | the compiler generates two symbols, an argument and a register. | |
960 | In some cases we combine them to a single LOC_REGISTER in symbol | |
961 | reading, but currently not for all cases (e.g. it's passed on the | |
962 | stack and then loaded into a register). */ | |
c906108c | 963 | |
17c5ed2c | 964 | LOC_REGISTER, |
c906108c | 965 | |
17c5ed2c | 966 | /* It's an argument; the value is at SYMBOL_VALUE offset in arglist. */ |
c906108c | 967 | |
17c5ed2c | 968 | LOC_ARG, |
c906108c | 969 | |
17c5ed2c | 970 | /* Value address is at SYMBOL_VALUE offset in arglist. */ |
c906108c | 971 | |
17c5ed2c | 972 | LOC_REF_ARG, |
c906108c | 973 | |
2a2d4dc3 | 974 | /* Value is in specified register. Just like LOC_REGISTER except the |
17c5ed2c | 975 | register holds the address of the argument instead of the argument |
c378eb4e | 976 | itself. This is currently used for the passing of structs and unions |
17c5ed2c DC |
977 | on sparc and hppa. It is also used for call by reference where the |
978 | address is in a register, at least by mipsread.c. */ | |
c906108c | 979 | |
17c5ed2c | 980 | LOC_REGPARM_ADDR, |
c906108c | 981 | |
17c5ed2c | 982 | /* Value is a local variable at SYMBOL_VALUE offset in stack frame. */ |
c906108c | 983 | |
17c5ed2c | 984 | LOC_LOCAL, |
c906108c | 985 | |
176620f1 EZ |
986 | /* Value not used; definition in SYMBOL_TYPE. Symbols in the domain |
987 | STRUCT_DOMAIN all have this class. */ | |
c906108c | 988 | |
17c5ed2c | 989 | LOC_TYPEDEF, |
c906108c | 990 | |
c378eb4e | 991 | /* Value is address SYMBOL_VALUE_ADDRESS in the code. */ |
c906108c | 992 | |
17c5ed2c | 993 | LOC_LABEL, |
c906108c | 994 | |
17c5ed2c DC |
995 | /* In a symbol table, value is SYMBOL_BLOCK_VALUE of a `struct block'. |
996 | In a partial symbol table, SYMBOL_VALUE_ADDRESS is the start address | |
c378eb4e | 997 | of the block. Function names have this class. */ |
c906108c | 998 | |
17c5ed2c | 999 | LOC_BLOCK, |
c906108c | 1000 | |
17c5ed2c DC |
1001 | /* Value is a constant byte-sequence pointed to by SYMBOL_VALUE_BYTES, in |
1002 | target byte order. */ | |
c906108c | 1003 | |
17c5ed2c | 1004 | LOC_CONST_BYTES, |
c906108c | 1005 | |
17c5ed2c DC |
1006 | /* Value is at fixed address, but the address of the variable has |
1007 | to be determined from the minimal symbol table whenever the | |
1008 | variable is referenced. | |
1009 | This happens if debugging information for a global symbol is | |
1010 | emitted and the corresponding minimal symbol is defined | |
1011 | in another object file or runtime common storage. | |
1012 | The linker might even remove the minimal symbol if the global | |
1013 | symbol is never referenced, in which case the symbol remains | |
de40b933 JK |
1014 | unresolved. |
1015 | ||
1016 | GDB would normally find the symbol in the minimal symbol table if it will | |
1017 | not find it in the full symbol table. But a reference to an external | |
1018 | symbol in a local block shadowing other definition requires full symbol | |
1019 | without possibly having its address available for LOC_STATIC. Testcase | |
5382cfab PW |
1020 | is provided as `gdb.dwarf2/dw2-unresolved.exp'. |
1021 | ||
1022 | This is also used for thread local storage (TLS) variables. In this case, | |
1023 | the address of the TLS variable must be determined when the variable is | |
1024 | referenced, from the MSYMBOL_VALUE_RAW_ADDRESS, which is the offset | |
1025 | of the TLS variable in the thread local storage of the shared | |
1026 | library/object. */ | |
c906108c | 1027 | |
17c5ed2c | 1028 | LOC_UNRESOLVED, |
c906108c | 1029 | |
17c5ed2c DC |
1030 | /* The variable does not actually exist in the program. |
1031 | The value is ignored. */ | |
c906108c | 1032 | |
17c5ed2c | 1033 | LOC_OPTIMIZED_OUT, |
c906108c | 1034 | |
4c2df51b | 1035 | /* The variable's address is computed by a set of location |
768a979c | 1036 | functions (see "struct symbol_computed_ops" below). */ |
4c2df51b | 1037 | LOC_COMPUTED, |
5a352474 JK |
1038 | |
1039 | /* The variable uses general_symbol_info->value->common_block field. | |
1040 | It also always uses COMMON_BLOCK_DOMAIN. */ | |
1041 | LOC_COMMON_BLOCK, | |
f1e6e072 TT |
1042 | |
1043 | /* Not used, just notes the boundary of the enum. */ | |
1044 | LOC_FINAL_VALUE | |
4c2df51b DJ |
1045 | }; |
1046 | ||
51cdc993 DE |
1047 | /* The number of bits needed for values in enum address_class, with some |
1048 | padding for reasonable growth, and room for run-time registered address | |
1049 | classes. See symtab.c:MAX_SYMBOL_IMPLS. | |
1050 | This is a #define so that we can have a assertion elsewhere to | |
1051 | verify that we have reserved enough space for synthetic address | |
1052 | classes. */ | |
1053 | #define SYMBOL_ACLASS_BITS 5 | |
1054 | gdb_static_assert (LOC_FINAL_VALUE <= (1 << SYMBOL_ACLASS_BITS)); | |
1055 | ||
768a979c | 1056 | /* The methods needed to implement LOC_COMPUTED. These methods can |
a67af2b9 AC |
1057 | use the symbol's .aux_value for additional per-symbol information. |
1058 | ||
1059 | At present this is only used to implement location expressions. */ | |
1060 | ||
768a979c | 1061 | struct symbol_computed_ops |
4c2df51b DJ |
1062 | { |
1063 | ||
1064 | /* Return the value of the variable SYMBOL, relative to the stack | |
1065 | frame FRAME. If the variable has been optimized out, return | |
1066 | zero. | |
1067 | ||
0b31a4bc TT |
1068 | Iff `read_needs_frame (SYMBOL)' is not SYMBOL_NEEDS_FRAME, then |
1069 | FRAME may be zero. */ | |
4c2df51b DJ |
1070 | |
1071 | struct value *(*read_variable) (struct symbol * symbol, | |
9efe17a3 | 1072 | frame_info_ptr frame); |
4c2df51b | 1073 | |
e18b2753 JK |
1074 | /* Read variable SYMBOL like read_variable at (callee) FRAME's function |
1075 | entry. SYMBOL should be a function parameter, otherwise | |
1076 | NO_ENTRY_VALUE_ERROR will be thrown. */ | |
1077 | struct value *(*read_variable_at_entry) (struct symbol *symbol, | |
bd2b40ac | 1078 | frame_info_ptr frame); |
e18b2753 | 1079 | |
0b31a4bc TT |
1080 | /* Find the "symbol_needs_kind" value for the given symbol. This |
1081 | value determines whether reading the symbol needs memory (e.g., a | |
1082 | global variable), just registers (a thread-local), or a frame (a | |
1083 | local variable). */ | |
1084 | enum symbol_needs_kind (*get_symbol_read_needs) (struct symbol * symbol); | |
4c2df51b DJ |
1085 | |
1086 | /* Write to STREAM a natural-language description of the location of | |
08922a10 SS |
1087 | SYMBOL, in the context of ADDR. */ |
1088 | void (*describe_location) (struct symbol * symbol, CORE_ADDR addr, | |
1089 | struct ui_file * stream); | |
4c2df51b | 1090 | |
f1e6e072 TT |
1091 | /* Non-zero if this symbol's address computation is dependent on PC. */ |
1092 | unsigned char location_has_loclist; | |
1093 | ||
4c2df51b DJ |
1094 | /* Tracepoint support. Append bytecodes to the tracepoint agent |
1095 | expression AX that push the address of the object SYMBOL. Set | |
1096 | VALUE appropriately. Note --- for objects in registers, this | |
1097 | needn't emit any code; as long as it sets VALUE properly, then | |
1098 | the caller will generate the right code in the process of | |
1099 | treating this as an lvalue or rvalue. */ | |
1100 | ||
40f4af28 SM |
1101 | void (*tracepoint_var_ref) (struct symbol *symbol, struct agent_expr *ax, |
1102 | struct axs_value *value); | |
bb2ec1b3 TT |
1103 | |
1104 | /* Generate C code to compute the location of SYMBOL. The C code is | |
1105 | emitted to STREAM. GDBARCH is the current architecture and PC is | |
1106 | the PC at which SYMBOL's location should be evaluated. | |
1107 | REGISTERS_USED is a vector indexed by register number; the | |
1108 | generator function should set an element in this vector if the | |
1109 | corresponding register is needed by the location computation. | |
1110 | The generated C code must assign the location to a local | |
1111 | variable; this variable's name is RESULT_NAME. */ | |
1112 | ||
d82b3862 | 1113 | void (*generate_c_location) (struct symbol *symbol, string_file *stream, |
bb2ec1b3 | 1114 | struct gdbarch *gdbarch, |
3637a558 | 1115 | std::vector<bool> ®isters_used, |
bb2ec1b3 TT |
1116 | CORE_ADDR pc, const char *result_name); |
1117 | ||
17c5ed2c | 1118 | }; |
c906108c | 1119 | |
f1e6e072 TT |
1120 | /* The methods needed to implement LOC_BLOCK for inferior functions. |
1121 | These methods can use the symbol's .aux_value for additional | |
1122 | per-symbol information. */ | |
1123 | ||
1124 | struct symbol_block_ops | |
1125 | { | |
1126 | /* Fill in *START and *LENGTH with DWARF block data of function | |
1127 | FRAMEFUNC valid for inferior context address PC. Set *LENGTH to | |
1128 | zero if such location is not valid for PC; *START is left | |
1129 | uninitialized in such case. */ | |
1130 | void (*find_frame_base_location) (struct symbol *framefunc, CORE_ADDR pc, | |
1131 | const gdb_byte **start, size_t *length); | |
63e43d3a PMR |
1132 | |
1133 | /* Return the frame base address. FRAME is the frame for which we want to | |
1134 | compute the base address while FRAMEFUNC is the symbol for the | |
1135 | corresponding function. Return 0 on failure (FRAMEFUNC may not hold the | |
1136 | information we need). | |
1137 | ||
1138 | This method is designed to work with static links (nested functions | |
1139 | handling). Static links are function properties whose evaluation returns | |
1140 | the frame base address for the enclosing frame. However, there are | |
1141 | multiple definitions for "frame base": the content of the frame base | |
1142 | register, the CFA as defined by DWARF unwinding information, ... | |
1143 | ||
1144 | So this specific method is supposed to compute the frame base address such | |
30baf67b | 1145 | as for nested functions, the static link computes the same address. For |
63e43d3a PMR |
1146 | instance, considering DWARF debugging information, the static link is |
1147 | computed with DW_AT_static_link and this method must be used to compute | |
1148 | the corresponding DW_AT_frame_base attribute. */ | |
1149 | CORE_ADDR (*get_frame_base) (struct symbol *framefunc, | |
bd2b40ac | 1150 | frame_info_ptr frame); |
f1e6e072 TT |
1151 | }; |
1152 | ||
768a979c UW |
1153 | /* Functions used with LOC_REGISTER and LOC_REGPARM_ADDR. */ |
1154 | ||
1155 | struct symbol_register_ops | |
1156 | { | |
1157 | int (*register_number) (struct symbol *symbol, struct gdbarch *gdbarch); | |
1158 | }; | |
1159 | ||
f1e6e072 TT |
1160 | /* Objects of this type are used to find the address class and the |
1161 | various computed ops vectors of a symbol. */ | |
1162 | ||
1163 | struct symbol_impl | |
1164 | { | |
1165 | enum address_class aclass; | |
1166 | ||
1167 | /* Used with LOC_COMPUTED. */ | |
1168 | const struct symbol_computed_ops *ops_computed; | |
1169 | ||
1170 | /* Used with LOC_BLOCK. */ | |
1171 | const struct symbol_block_ops *ops_block; | |
1172 | ||
1173 | /* Used with LOC_REGISTER and LOC_REGPARM_ADDR. */ | |
1174 | const struct symbol_register_ops *ops_register; | |
1175 | }; | |
1176 | ||
cf724bc9 TT |
1177 | /* struct symbol has some subclasses. This enum is used to |
1178 | differentiate between them. */ | |
1179 | ||
1180 | enum symbol_subclass_kind | |
1181 | { | |
1182 | /* Plain struct symbol. */ | |
1183 | SYMBOL_NONE, | |
1184 | ||
1185 | /* struct template_symbol. */ | |
1186 | SYMBOL_TEMPLATE, | |
1187 | ||
1188 | /* struct rust_vtable_symbol. */ | |
1189 | SYMBOL_RUST_VTABLE | |
1190 | }; | |
1191 | ||
6bc3c5b4 | 1192 | extern gdb::array_view<const struct symbol_impl> symbol_impls; |
d1eebf9a | 1193 | |
c378eb4e | 1194 | /* This structure is space critical. See space comments at the top. */ |
a7f19c79 | 1195 | |
468c0cbb | 1196 | struct symbol : public general_symbol_info, public allocate_on_obstack |
17c5ed2c | 1197 | { |
468c0cbb CB |
1198 | symbol () |
1199 | /* Class-initialization of bitfields is only allowed in C++20. */ | |
6c9c307c | 1200 | : m_domain (UNDEF_DOMAIN), |
ba44b1a3 | 1201 | m_aclass_index (0), |
7b3ecc75 | 1202 | m_is_objfile_owned (1), |
d9743061 | 1203 | m_is_argument (0), |
32177d6e | 1204 | m_is_inlined (0), |
468c0cbb | 1205 | maybe_copied (0), |
2c71f639 | 1206 | subclass (SYMBOL_NONE), |
496feb16 | 1207 | m_artificial (false) |
468c0cbb CB |
1208 | { |
1209 | /* We can't use an initializer list for members of a base class, and | |
dda83cd7 | 1210 | general_symbol_info needs to stay a POD type. */ |
4d4eaa30 | 1211 | m_name = nullptr; |
4aeddc50 | 1212 | m_value.ivalue = 0; |
468c0cbb | 1213 | language_specific.obstack = nullptr; |
c1b5c1eb | 1214 | m_language = language_unknown; |
468c0cbb | 1215 | ada_mangled = 0; |
a52d653e | 1216 | m_section = -1; |
6edc43ec | 1217 | /* GCC 4.8.5 (on CentOS 7) does not correctly compile class- |
dda83cd7 | 1218 | initialization of unions, so we initialize it manually here. */ |
6edc43ec | 1219 | owner.symtab = nullptr; |
468c0cbb | 1220 | } |
c906108c | 1221 | |
8c14c3a3 | 1222 | symbol (const symbol &) = default; |
1b453aed | 1223 | symbol &operator= (const symbol &) = default; |
8c14c3a3 | 1224 | |
ba44b1a3 SM |
1225 | void set_aclass_index (unsigned int aclass_index) |
1226 | { | |
1227 | m_aclass_index = aclass_index; | |
1228 | } | |
1229 | ||
d1eebf9a SM |
1230 | const symbol_impl &impl () const |
1231 | { | |
f66b5363 | 1232 | return symbol_impls[this->m_aclass_index]; |
d1eebf9a SM |
1233 | } |
1234 | ||
66d7f48f SM |
1235 | address_class aclass () const |
1236 | { | |
1237 | return this->impl ().aclass; | |
1238 | } | |
1239 | ||
6c9c307c SM |
1240 | domain_enum domain () const |
1241 | { | |
1242 | return m_domain; | |
1243 | } | |
1244 | ||
1245 | void set_domain (domain_enum domain) | |
1246 | { | |
1247 | m_domain = domain; | |
1248 | } | |
1249 | ||
7b3ecc75 SM |
1250 | bool is_objfile_owned () const |
1251 | { | |
1252 | return m_is_objfile_owned; | |
1253 | } | |
1254 | ||
1255 | void set_is_objfile_owned (bool is_objfile_owned) | |
1256 | { | |
1257 | m_is_objfile_owned = is_objfile_owned; | |
1258 | } | |
1259 | ||
d9743061 SM |
1260 | bool is_argument () const |
1261 | { | |
1262 | return m_is_argument; | |
1263 | } | |
1264 | ||
1265 | void set_is_argument (bool is_argument) | |
1266 | { | |
1267 | m_is_argument = is_argument; | |
1268 | } | |
1269 | ||
32177d6e SM |
1270 | bool is_inlined () const |
1271 | { | |
1272 | return m_is_inlined; | |
1273 | } | |
1274 | ||
1275 | void set_is_inlined (bool is_inlined) | |
1276 | { | |
1277 | m_is_inlined = is_inlined; | |
1278 | } | |
1279 | ||
f5abd8f2 SM |
1280 | bool is_cplus_template_function () const |
1281 | { | |
1282 | return this->subclass == SYMBOL_TEMPLATE; | |
1283 | } | |
1284 | ||
5f9c5a63 SM |
1285 | struct type *type () const |
1286 | { | |
1287 | return m_type; | |
1288 | } | |
1289 | ||
1290 | void set_type (struct type *type) | |
1291 | { | |
1292 | m_type = type; | |
1293 | } | |
1294 | ||
5d0027b9 SM |
1295 | unsigned short line () const |
1296 | { | |
1297 | return m_line; | |
1298 | } | |
1299 | ||
1300 | void set_line (unsigned short line) | |
1301 | { | |
1302 | m_line = line; | |
1303 | } | |
1304 | ||
4aeddc50 SM |
1305 | LONGEST value_longest () const |
1306 | { | |
1307 | return m_value.ivalue; | |
1308 | } | |
1309 | ||
1310 | void set_value_longest (LONGEST value) | |
1311 | { | |
1312 | m_value.ivalue = value; | |
1313 | } | |
1314 | ||
1315 | CORE_ADDR value_address () const | |
1316 | { | |
1317 | if (this->maybe_copied) | |
1318 | return get_symbol_address (this); | |
1319 | else | |
1320 | return m_value.address; | |
1321 | } | |
1322 | ||
1323 | void set_value_address (CORE_ADDR address) | |
1324 | { | |
1325 | m_value.address = address; | |
1326 | } | |
1327 | ||
1328 | const gdb_byte *value_bytes () const | |
1329 | { | |
1330 | return m_value.bytes; | |
1331 | } | |
1332 | ||
1333 | void set_value_bytes (const gdb_byte *bytes) | |
1334 | { | |
1335 | m_value.bytes = bytes; | |
1336 | } | |
1337 | ||
1338 | const common_block *value_common_block () const | |
1339 | { | |
1340 | return m_value.common_block; | |
1341 | } | |
1342 | ||
1343 | void set_value_common_block (const common_block *common_block) | |
1344 | { | |
1345 | m_value.common_block = common_block; | |
1346 | } | |
1347 | ||
1348 | const block *value_block () const | |
1349 | { | |
1350 | return m_value.block; | |
1351 | } | |
1352 | ||
1353 | void set_value_block (const block *block) | |
1354 | { | |
1355 | m_value.block = block; | |
1356 | } | |
1357 | ||
1358 | symbol *value_chain () const | |
1359 | { | |
1360 | return m_value.chain; | |
1361 | } | |
1362 | ||
1363 | void set_value_chain (symbol *sym) | |
1364 | { | |
1365 | m_value.chain = sym; | |
1366 | } | |
1367 | ||
496feb16 TT |
1368 | /* Return true if this symbol was marked as artificial. */ |
1369 | bool is_artificial () const | |
1370 | { | |
1371 | return m_artificial; | |
1372 | } | |
1373 | ||
1374 | /* Set the 'artificial' flag on this symbol. */ | |
1375 | void set_is_artificial (bool artificial) | |
1376 | { | |
1377 | m_artificial = artificial; | |
1378 | } | |
1379 | ||
e19b2d94 TT |
1380 | /* Return the OBJFILE of this symbol. It is an error to call this |
1381 | if is_objfile_owned is false, which only happens for | |
1382 | architecture-provided types. */ | |
1383 | ||
1384 | struct objfile *objfile () const; | |
1385 | ||
bcd6845e TT |
1386 | /* Return the ARCH of this symbol. */ |
1387 | ||
1388 | struct gdbarch *arch () const; | |
1389 | ||
4206d69e TT |
1390 | /* Return the symtab of this symbol. It is an error to call this if |
1391 | is_objfile_owned is false, which only happens for | |
1392 | architecture-provided types. */ | |
1393 | ||
1394 | struct symtab *symtab () const; | |
1395 | ||
1396 | /* Set the symtab of this symbol to SYMTAB. It is an error to call | |
1397 | this if is_objfile_owned is false, which only happens for | |
1398 | architecture-provided types. */ | |
1399 | ||
1400 | void set_symtab (struct symtab *symtab); | |
1401 | ||
17c5ed2c | 1402 | /* Data type of value */ |
c906108c | 1403 | |
5f9c5a63 | 1404 | struct type *m_type = nullptr; |
c906108c | 1405 | |
1994afbf | 1406 | /* The owner of this symbol. |
e2ada9cb | 1407 | Which one to use is defined by symbol.is_objfile_owned. */ |
1994afbf DE |
1408 | |
1409 | union | |
1410 | { | |
1411 | /* The symbol table containing this symbol. This is the file associated | |
1412 | with LINE. It can be NULL during symbols read-in but it is never NULL | |
1413 | during normal operation. */ | |
6edc43ec | 1414 | struct symtab *symtab; |
1994afbf DE |
1415 | |
1416 | /* For types defined by the architecture. */ | |
1417 | struct gdbarch *arch; | |
1418 | } owner; | |
cb1df416 | 1419 | |
176620f1 | 1420 | /* Domain code. */ |
c906108c | 1421 | |
0d1703b8 | 1422 | ENUM_BITFIELD(domain_enum) m_domain : SYMBOL_DOMAIN_BITS; |
c906108c | 1423 | |
f1e6e072 TT |
1424 | /* Address class. This holds an index into the 'symbol_impls' |
1425 | table. The actual enum address_class value is stored there, | |
1426 | alongside any per-class ops vectors. */ | |
c906108c | 1427 | |
ba44b1a3 | 1428 | unsigned int m_aclass_index : SYMBOL_ACLASS_BITS; |
c906108c | 1429 | |
1994afbf | 1430 | /* If non-zero then symbol is objfile-owned, use owner.symtab. |
468c0cbb | 1431 | Otherwise symbol is arch-owned, use owner.arch. */ |
1994afbf | 1432 | |
7b3ecc75 | 1433 | unsigned int m_is_objfile_owned : 1; |
1994afbf | 1434 | |
2a2d4dc3 AS |
1435 | /* Whether this is an argument. */ |
1436 | ||
d9743061 | 1437 | unsigned m_is_argument : 1; |
2a2d4dc3 | 1438 | |
edb3359d | 1439 | /* Whether this is an inlined function (class LOC_BLOCK only). */ |
32177d6e | 1440 | unsigned m_is_inlined : 1; |
edb3359d | 1441 | |
4b610737 TT |
1442 | /* For LOC_STATIC only, if this is set, then the symbol might be |
1443 | subject to copy relocation. In this case, a minimal symbol | |
1444 | matching the symbol's linkage name is first looked for in the | |
1445 | main objfile. If found, then that address is used; otherwise the | |
1446 | address in this symbol is used. */ | |
1447 | ||
1448 | unsigned maybe_copied : 1; | |
1449 | ||
cf724bc9 | 1450 | /* The concrete type of this symbol. */ |
71a3c369 | 1451 | |
cf724bc9 | 1452 | ENUM_BITFIELD (symbol_subclass_kind) subclass : 2; |
71a3c369 | 1453 | |
2c71f639 TV |
1454 | /* Whether this symbol is artificial. */ |
1455 | ||
496feb16 | 1456 | bool m_artificial : 1; |
2c71f639 | 1457 | |
edb3359d DJ |
1458 | /* Line number of this symbol's definition, except for inlined |
1459 | functions. For an inlined function (class LOC_BLOCK and | |
1460 | SYMBOL_INLINED set) this is the line number of the function's call | |
1461 | site. Inlined function symbols are not definitions, and they are | |
1462 | never found by symbol table lookup. | |
1994afbf | 1463 | If this symbol is arch-owned, LINE shall be zero. |
edb3359d DJ |
1464 | |
1465 | FIXME: Should we really make the assumption that nobody will try | |
1466 | to debug files longer than 64K lines? What about machine | |
1467 | generated programs? */ | |
c906108c | 1468 | |
5d0027b9 | 1469 | unsigned short m_line = 0; |
c906108c | 1470 | |
10f4ecb8 UW |
1471 | /* An arbitrary data pointer, allowing symbol readers to record |
1472 | additional information on a per-symbol basis. Note that this data | |
1473 | must be allocated using the same obstack as the symbol itself. */ | |
1cd36e54 DE |
1474 | /* So far it is only used by: |
1475 | LOC_COMPUTED: to find the location information | |
1476 | LOC_BLOCK (DWARF2 function): information used internally by the | |
1477 | DWARF 2 code --- specifically, the location expression for the frame | |
10f4ecb8 UW |
1478 | base for this function. */ |
1479 | /* FIXME drow/2003-02-21: For the LOC_BLOCK case, it might be better | |
1480 | to add a magic symbol to the block containing this information, | |
1481 | or to have a generic debug info annotation slot for symbols. */ | |
1482 | ||
468c0cbb | 1483 | void *aux_value = nullptr; |
c906108c | 1484 | |
468c0cbb | 1485 | struct symbol *hash_next = nullptr; |
17c5ed2c | 1486 | }; |
c906108c | 1487 | |
d12307c1 PMR |
1488 | /* Several lookup functions return both a symbol and the block in which the |
1489 | symbol is found. This structure is used in these cases. */ | |
1490 | ||
1491 | struct block_symbol | |
1492 | { | |
1493 | /* The symbol that was found, or NULL if no symbol was found. */ | |
1494 | struct symbol *symbol; | |
1495 | ||
1496 | /* If SYMBOL is not NULL, then this is the block in which the symbol is | |
1497 | defined. */ | |
1498 | const struct block *block; | |
1499 | }; | |
1500 | ||
1994afbf DE |
1501 | /* Note: There is no accessor macro for symbol.owner because it is |
1502 | "private". */ | |
1503 | ||
d1eebf9a SM |
1504 | #define SYMBOL_COMPUTED_OPS(symbol) ((symbol)->impl ().ops_computed) |
1505 | #define SYMBOL_BLOCK_OPS(symbol) ((symbol)->impl ().ops_block) | |
1506 | #define SYMBOL_REGISTER_OPS(symbol) ((symbol)->impl ().ops_register) | |
10f4ecb8 | 1507 | #define SYMBOL_LOCATION_BATON(symbol) (symbol)->aux_value |
34eaf542 | 1508 | |
f1e6e072 TT |
1509 | extern int register_symbol_computed_impl (enum address_class, |
1510 | const struct symbol_computed_ops *); | |
1511 | ||
1512 | extern int register_symbol_block_impl (enum address_class aclass, | |
1513 | const struct symbol_block_ops *ops); | |
1514 | ||
1515 | extern int register_symbol_register_impl (enum address_class, | |
1516 | const struct symbol_register_ops *); | |
1517 | ||
34eaf542 | 1518 | /* An instance of this type is used to represent a C++ template |
68e745e3 | 1519 | function. A symbol is really of this type iff |
f5abd8f2 | 1520 | symbol::is_cplus_template_function is true. */ |
34eaf542 | 1521 | |
68e745e3 | 1522 | struct template_symbol : public symbol |
34eaf542 | 1523 | { |
34eaf542 | 1524 | /* The number of template arguments. */ |
468c0cbb | 1525 | int n_template_arguments = 0; |
34eaf542 TT |
1526 | |
1527 | /* The template arguments. This is an array with | |
1528 | N_TEMPLATE_ARGUMENTS elements. */ | |
468c0cbb | 1529 | struct symbol **template_arguments = nullptr; |
34eaf542 TT |
1530 | }; |
1531 | ||
71a3c369 TT |
1532 | /* A symbol that represents a Rust virtual table object. */ |
1533 | ||
1534 | struct rust_vtable_symbol : public symbol | |
1535 | { | |
1536 | /* The concrete type for which this vtable was created; that is, in | |
1537 | "impl Trait for Type", this is "Type". */ | |
468c0cbb | 1538 | struct type *concrete_type = nullptr; |
71a3c369 TT |
1539 | }; |
1540 | ||
c906108c | 1541 | \f |
c906108c SS |
1542 | /* Each item represents a line-->pc (or the reverse) mapping. This is |
1543 | somewhat more wasteful of space than one might wish, but since only | |
1544 | the files which are actually debugged are read in to core, we don't | |
1545 | waste much space. */ | |
1546 | ||
1547 | struct linetable_entry | |
17c5ed2c | 1548 | { |
8c95582d | 1549 | /* The line number for this entry. */ |
17c5ed2c | 1550 | int line; |
8c95582d AB |
1551 | |
1552 | /* True if this PC is a good location to place a breakpoint for LINE. */ | |
1553 | unsigned is_stmt : 1; | |
1554 | ||
cc96ae7f LS |
1555 | /* True if this location is a good location to place a breakpoint after a |
1556 | function prologue. */ | |
1557 | bool prologue_end : 1; | |
1558 | ||
8c95582d | 1559 | /* The address for this entry. */ |
17c5ed2c DC |
1560 | CORE_ADDR pc; |
1561 | }; | |
c906108c SS |
1562 | |
1563 | /* The order of entries in the linetable is significant. They should | |
1564 | be sorted by increasing values of the pc field. If there is more than | |
1565 | one entry for a given pc, then I'm not sure what should happen (and | |
1566 | I not sure whether we currently handle it the best way). | |
1567 | ||
1568 | Example: a C for statement generally looks like this | |
1569 | ||
c5aa993b JM |
1570 | 10 0x100 - for the init/test part of a for stmt. |
1571 | 20 0x200 | |
1572 | 30 0x300 | |
1573 | 10 0x400 - for the increment part of a for stmt. | |
c906108c | 1574 | |
e8717518 FF |
1575 | If an entry has a line number of zero, it marks the start of a PC |
1576 | range for which no line number information is available. It is | |
1577 | acceptable, though wasteful of table space, for such a range to be | |
1578 | zero length. */ | |
c906108c SS |
1579 | |
1580 | struct linetable | |
17c5ed2c DC |
1581 | { |
1582 | int nitems; | |
c906108c | 1583 | |
17c5ed2c DC |
1584 | /* Actually NITEMS elements. If you don't like this use of the |
1585 | `struct hack', you can shove it up your ANSI (seriously, if the | |
1586 | committee tells us how to do it, we can probably go along). */ | |
1587 | struct linetable_entry item[1]; | |
1588 | }; | |
c906108c | 1589 | |
c906108c | 1590 | /* How to relocate the symbols from each section in a symbol file. |
c906108c SS |
1591 | The ordering and meaning of the offsets is file-type-dependent; |
1592 | typically it is indexed by section numbers or symbol types or | |
6a053cb1 | 1593 | something like that. */ |
c906108c | 1594 | |
6a053cb1 | 1595 | typedef std::vector<CORE_ADDR> section_offsets; |
b29c9944 | 1596 | |
c378eb4e | 1597 | /* Each source file or header is represented by a struct symtab. |
43f3e411 | 1598 | The name "symtab" is historical, another name for it is "filetab". |
c906108c SS |
1599 | These objects are chained through the `next' field. */ |
1600 | ||
1601 | struct symtab | |
17c5ed2c | 1602 | { |
c6159652 SM |
1603 | struct compunit_symtab *compunit () const |
1604 | { | |
1605 | return m_compunit; | |
1606 | } | |
1607 | ||
1608 | void set_compunit (struct compunit_symtab *compunit) | |
1609 | { | |
1610 | m_compunit = compunit; | |
1611 | } | |
1612 | ||
5b607461 SM |
1613 | struct linetable *linetable () const |
1614 | { | |
1615 | return m_linetable; | |
1616 | } | |
1617 | ||
1618 | void set_linetable (struct linetable *linetable) | |
1619 | { | |
1620 | m_linetable = linetable; | |
1621 | } | |
1622 | ||
1ee2e9f9 SM |
1623 | enum language language () const |
1624 | { | |
1625 | return m_language; | |
1626 | } | |
1627 | ||
1628 | void set_language (enum language language) | |
1629 | { | |
1630 | m_language = language; | |
1631 | } | |
1632 | ||
b7236fbe DE |
1633 | /* Unordered chain of all filetabs in the compunit, with the exception |
1634 | that the "main" source file is the first entry in the list. */ | |
c906108c | 1635 | |
17c5ed2c | 1636 | struct symtab *next; |
c906108c | 1637 | |
43f3e411 | 1638 | /* Backlink to containing compunit symtab. */ |
c906108c | 1639 | |
c6159652 | 1640 | struct compunit_symtab *m_compunit; |
c906108c | 1641 | |
17c5ed2c DC |
1642 | /* Table mapping core addresses to line numbers for this file. |
1643 | Can be NULL if none. Never shared between different symtabs. */ | |
c906108c | 1644 | |
5b607461 | 1645 | struct linetable *m_linetable; |
c906108c | 1646 | |
f71ad555 SM |
1647 | /* Name of this source file, in a form appropriate to print to the user. |
1648 | ||
1649 | This pointer is never nullptr. */ | |
c906108c | 1650 | |
21ea9eec | 1651 | const char *filename; |
c906108c | 1652 | |
f71ad555 SM |
1653 | /* Filename for this source file, used as an identifier to link with |
1654 | related objects such as associated macro_source_file objects. It must | |
1655 | therefore match the name of any macro_source_file object created for this | |
1656 | source file. The value can be the same as FILENAME if it is known to | |
1657 | follow that rule, or another form of the same file name, this is up to | |
1658 | the specific debug info reader. | |
1659 | ||
1660 | This pointer is never nullptr.*/ | |
1661 | const char *filename_for_id; | |
1662 | ||
17c5ed2c | 1663 | /* Language of this source file. */ |
c906108c | 1664 | |
1ee2e9f9 | 1665 | enum language m_language; |
c906108c | 1666 | |
43f3e411 DE |
1667 | /* Full name of file as found by searching the source path. |
1668 | NULL if not yet known. */ | |
1669 | ||
1670 | char *fullname; | |
1671 | }; | |
1672 | ||
102cc235 SM |
1673 | /* A range adapter to allowing iterating over all the file tables in a list. */ |
1674 | ||
1675 | using symtab_range = next_range<symtab>; | |
1676 | ||
43f3e411 DE |
1677 | /* Compunit symtabs contain the actual "symbol table", aka blockvector, as well |
1678 | as the list of all source files (what gdb has historically associated with | |
1679 | the term "symtab"). | |
1680 | Additional information is recorded here that is common to all symtabs in a | |
1681 | compilation unit (DWARF or otherwise). | |
1682 | ||
1683 | Example: | |
1684 | For the case of a program built out of these files: | |
1685 | ||
1686 | foo.c | |
1687 | foo1.h | |
1688 | foo2.h | |
1689 | bar.c | |
1690 | foo1.h | |
1691 | bar.h | |
1692 | ||
1693 | This is recorded as: | |
1694 | ||
1695 | objfile -> foo.c(cu) -> bar.c(cu) -> NULL | |
dda83cd7 SM |
1696 | | | |
1697 | v v | |
1698 | foo.c bar.c | |
1699 | | | | |
1700 | v v | |
1701 | foo1.h foo1.h | |
1702 | | | | |
1703 | v v | |
1704 | foo2.h bar.h | |
1705 | | | | |
1706 | v v | |
1707 | NULL NULL | |
43f3e411 DE |
1708 | |
1709 | where "foo.c(cu)" and "bar.c(cu)" are struct compunit_symtab objects, | |
1710 | and the files foo.c, etc. are struct symtab objects. */ | |
1711 | ||
1712 | struct compunit_symtab | |
1713 | { | |
f1f58f10 SM |
1714 | struct objfile *objfile () const |
1715 | { | |
1716 | return m_objfile; | |
1717 | } | |
1718 | ||
1719 | void set_objfile (struct objfile *objfile) | |
1720 | { | |
1721 | m_objfile = objfile; | |
1722 | } | |
1723 | ||
102cc235 SM |
1724 | symtab_range filetabs () const |
1725 | { | |
1726 | return symtab_range (m_filetabs); | |
1727 | } | |
1728 | ||
43b49762 SM |
1729 | void add_filetab (symtab *filetab) |
1730 | { | |
102cc235 | 1731 | if (m_filetabs == nullptr) |
43b49762 | 1732 | { |
102cc235 SM |
1733 | m_filetabs = filetab; |
1734 | m_last_filetab = filetab; | |
43b49762 SM |
1735 | } |
1736 | else | |
1737 | { | |
102cc235 SM |
1738 | m_last_filetab->next = filetab; |
1739 | m_last_filetab = filetab; | |
43b49762 SM |
1740 | } |
1741 | } | |
1742 | ||
422f1ea2 SM |
1743 | const char *debugformat () const |
1744 | { | |
1745 | return m_debugformat; | |
1746 | } | |
1747 | ||
1748 | void set_debugformat (const char *debugformat) | |
1749 | { | |
1750 | m_debugformat = debugformat; | |
1751 | } | |
1752 | ||
ab5f850e SM |
1753 | const char *producer () const |
1754 | { | |
1755 | return m_producer; | |
1756 | } | |
1757 | ||
1758 | void set_producer (const char *producer) | |
1759 | { | |
1760 | m_producer = producer; | |
1761 | } | |
1762 | ||
0d9acb45 SM |
1763 | const char *dirname () const |
1764 | { | |
1765 | return m_dirname; | |
1766 | } | |
1767 | ||
1768 | void set_dirname (const char *dirname) | |
1769 | { | |
1770 | m_dirname = dirname; | |
1771 | } | |
1772 | ||
63d609de SM |
1773 | struct blockvector *blockvector () |
1774 | { | |
1775 | return m_blockvector; | |
1776 | } | |
1777 | ||
af39c5c8 SM |
1778 | const struct blockvector *blockvector () const |
1779 | { | |
1780 | return m_blockvector; | |
1781 | } | |
1782 | ||
63d609de | 1783 | void set_blockvector (struct blockvector *blockvector) |
af39c5c8 SM |
1784 | { |
1785 | m_blockvector = blockvector; | |
1786 | } | |
1787 | ||
c1e35bc9 SM |
1788 | int block_line_section () const |
1789 | { | |
1790 | return m_block_line_section; | |
1791 | } | |
1792 | ||
1793 | void set_block_line_section (int block_line_section) | |
1794 | { | |
1795 | m_block_line_section = block_line_section; | |
1796 | } | |
1797 | ||
b0fc0e82 SM |
1798 | bool locations_valid () const |
1799 | { | |
1800 | return m_locations_valid; | |
1801 | } | |
1802 | ||
1803 | void set_locations_valid (bool locations_valid) | |
1804 | { | |
1805 | m_locations_valid = locations_valid; | |
1806 | } | |
1807 | ||
3908b699 SM |
1808 | bool epilogue_unwind_valid () const |
1809 | { | |
1810 | return m_epilogue_unwind_valid; | |
1811 | } | |
1812 | ||
1813 | void set_epilogue_unwind_valid (bool epilogue_unwind_valid) | |
1814 | { | |
1815 | m_epilogue_unwind_valid = epilogue_unwind_valid; | |
1816 | } | |
1817 | ||
10cc645b SM |
1818 | struct macro_table *macro_table () const |
1819 | { | |
1820 | return m_macro_table; | |
1821 | } | |
1822 | ||
1823 | void set_macro_table (struct macro_table *macro_table) | |
1824 | { | |
1825 | m_macro_table = macro_table; | |
1826 | } | |
1827 | ||
36664835 SM |
1828 | /* Make PRIMARY_FILETAB the primary filetab of this compunit symtab. |
1829 | ||
1830 | PRIMARY_FILETAB must already be a filetab of this compunit symtab. */ | |
1831 | ||
1832 | void set_primary_filetab (symtab *primary_filetab); | |
1833 | ||
0b17a4f7 SM |
1834 | /* Return the primary filetab of the compunit. */ |
1835 | symtab *primary_filetab () const; | |
1836 | ||
b625c770 SM |
1837 | /* Set m_call_site_htab. */ |
1838 | void set_call_site_htab (htab_t call_site_htab); | |
1839 | ||
1840 | /* Find call_site info for PC. */ | |
1841 | call_site *find_call_site (CORE_ADDR pc) const; | |
1842 | ||
425d5e76 TT |
1843 | /* Return the language of this compunit_symtab. */ |
1844 | enum language language () const; | |
1845 | ||
43f3e411 DE |
1846 | /* Unordered chain of all compunit symtabs of this objfile. */ |
1847 | struct compunit_symtab *next; | |
1848 | ||
1849 | /* Object file from which this symtab information was read. */ | |
f1f58f10 | 1850 | struct objfile *m_objfile; |
43f3e411 DE |
1851 | |
1852 | /* Name of the symtab. | |
1853 | This is *not* intended to be a usable filename, and is | |
1854 | for debugging purposes only. */ | |
1855 | const char *name; | |
1856 | ||
1857 | /* Unordered list of file symtabs, except that by convention the "main" | |
1858 | source file (e.g., .c, .cc) is guaranteed to be first. | |
1859 | Each symtab is a file, either the "main" source file (e.g., .c, .cc) | |
1860 | or header (e.g., .h). */ | |
102cc235 | 1861 | symtab *m_filetabs; |
43f3e411 DE |
1862 | |
1863 | /* Last entry in FILETABS list. | |
1864 | Subfiles are added to the end of the list so they accumulate in order, | |
1865 | with the main source subfile living at the front. | |
1866 | The main reason is so that the main source file symtab is at the head | |
1867 | of the list, and the rest appear in order for debugging convenience. */ | |
102cc235 | 1868 | symtab *m_last_filetab; |
43f3e411 DE |
1869 | |
1870 | /* Non-NULL string that identifies the format of the debugging information, | |
1871 | such as "stabs", "dwarf 1", "dwarf 2", "coff", etc. This is mostly useful | |
17c5ed2c | 1872 | for automated testing of gdb but may also be information that is |
c378eb4e | 1873 | useful to the user. */ |
422f1ea2 | 1874 | const char *m_debugformat; |
c906108c | 1875 | |
43f3e411 | 1876 | /* String of producer version information, or NULL if we don't know. */ |
ab5f850e | 1877 | const char *m_producer; |
c906108c | 1878 | |
43f3e411 | 1879 | /* Directory in which it was compiled, or NULL if we don't know. */ |
0d9acb45 | 1880 | const char *m_dirname; |
c906108c | 1881 | |
43f3e411 DE |
1882 | /* List of all symbol scope blocks for this symtab. It is shared among |
1883 | all symtabs in a given compilation unit. */ | |
63d609de | 1884 | struct blockvector *m_blockvector; |
c906108c | 1885 | |
43f3e411 DE |
1886 | /* Section in objfile->section_offsets for the blockvector and |
1887 | the linetable. Probably always SECT_OFF_TEXT. */ | |
c1e35bc9 | 1888 | int m_block_line_section; |
c906108c | 1889 | |
43f3e411 DE |
1890 | /* Symtab has been compiled with both optimizations and debug info so that |
1891 | GDB may stop skipping prologues as variables locations are valid already | |
1892 | at function entry points. */ | |
b0fc0e82 | 1893 | unsigned int m_locations_valid : 1; |
c906108c | 1894 | |
43f3e411 DE |
1895 | /* DWARF unwinder for this CU is valid even for epilogues (PC at the return |
1896 | instruction). This is supported by GCC since 4.5.0. */ | |
3908b699 | 1897 | unsigned int m_epilogue_unwind_valid : 1; |
8e3b41a9 | 1898 | |
43f3e411 | 1899 | /* struct call_site entries for this compilation unit or NULL. */ |
b625c770 | 1900 | htab_t m_call_site_htab; |
b5b04b5b | 1901 | |
43f3e411 DE |
1902 | /* The macro table for this symtab. Like the blockvector, this |
1903 | is shared between different symtabs in a given compilation unit. | |
1904 | It's debatable whether it *should* be shared among all the symtabs in | |
1905 | the given compilation unit, but it currently is. */ | |
10cc645b | 1906 | struct macro_table *m_macro_table; |
43f3e411 | 1907 | |
b5b04b5b | 1908 | /* If non-NULL, then this points to a NULL-terminated vector of |
43f3e411 DE |
1909 | included compunits. When searching the static or global |
1910 | block of this compunit, the corresponding block of all | |
1911 | included compunits will also be searched. Note that this | |
b5b04b5b TT |
1912 | list must be flattened -- the symbol reader is responsible for |
1913 | ensuring that this vector contains the transitive closure of all | |
43f3e411 DE |
1914 | included compunits. */ |
1915 | struct compunit_symtab **includes; | |
b5b04b5b | 1916 | |
43f3e411 DE |
1917 | /* If this is an included compunit, this points to one includer |
1918 | of the table. This user is considered the canonical compunit | |
1919 | containing this one. An included compunit may itself be | |
b5b04b5b | 1920 | included by another. */ |
43f3e411 | 1921 | struct compunit_symtab *user; |
17c5ed2c | 1922 | }; |
c906108c | 1923 | |
9be25986 SM |
1924 | using compunit_symtab_range = next_range<compunit_symtab>; |
1925 | ||
7b1eff95 TV |
1926 | /* Return true if this symtab is the "main" symtab of its compunit_symtab. */ |
1927 | ||
1928 | static inline bool | |
1929 | is_main_symtab_of_compunit_symtab (struct symtab *symtab) | |
1930 | { | |
c6159652 | 1931 | return symtab == symtab->compunit ()->primary_filetab (); |
7b1eff95 | 1932 | } |
c906108c | 1933 | \f |
c5aa993b | 1934 | |
c906108c | 1935 | /* The virtual function table is now an array of structures which have the |
a960f249 | 1936 | form { int16 offset, delta; void *pfn; }. |
c906108c SS |
1937 | |
1938 | In normal virtual function tables, OFFSET is unused. | |
1939 | DELTA is the amount which is added to the apparent object's base | |
1940 | address in order to point to the actual object to which the | |
1941 | virtual function should be applied. | |
1942 | PFN is a pointer to the virtual function. | |
1943 | ||
c378eb4e | 1944 | Note that this macro is g++ specific (FIXME). */ |
c5aa993b | 1945 | |
c906108c SS |
1946 | #define VTBL_FNADDR_OFFSET 2 |
1947 | ||
c378eb4e | 1948 | /* External variables and functions for the objects described above. */ |
c906108c | 1949 | |
c378eb4e | 1950 | /* True if we are nested inside psymtab_to_symtab. */ |
c906108c SS |
1951 | |
1952 | extern int currently_reading_symtab; | |
1953 | ||
c906108c SS |
1954 | /* symtab.c lookup functions */ |
1955 | ||
7fc830e2 MK |
1956 | extern const char multiple_symbols_ask[]; |
1957 | extern const char multiple_symbols_all[]; | |
1958 | extern const char multiple_symbols_cancel[]; | |
717d2f5a JB |
1959 | |
1960 | const char *multiple_symbols_select_mode (void); | |
1961 | ||
ececd218 CB |
1962 | bool symbol_matches_domain (enum language symbol_language, |
1963 | domain_enum symbol_domain, | |
1964 | domain_enum domain); | |
4186eb54 | 1965 | |
c378eb4e | 1966 | /* lookup a symbol table by source file name. */ |
c906108c | 1967 | |
1f8cc6db | 1968 | extern struct symtab *lookup_symtab (const char *); |
c906108c | 1969 | |
1993b719 TT |
1970 | /* An object of this type is passed as the 'is_a_field_of_this' |
1971 | argument to lookup_symbol and lookup_symbol_in_language. */ | |
1972 | ||
1973 | struct field_of_this_result | |
1974 | { | |
1975 | /* The type in which the field was found. If this is NULL then the | |
1976 | symbol was not found in 'this'. If non-NULL, then one of the | |
1977 | other fields will be non-NULL as well. */ | |
1978 | ||
1979 | struct type *type; | |
1980 | ||
1981 | /* If the symbol was found as an ordinary field of 'this', then this | |
1982 | is non-NULL and points to the particular field. */ | |
1983 | ||
1984 | struct field *field; | |
1985 | ||
cf901d3b | 1986 | /* If the symbol was found as a function field of 'this', then this |
1993b719 TT |
1987 | is non-NULL and points to the particular field. */ |
1988 | ||
1989 | struct fn_fieldlist *fn_field; | |
1990 | }; | |
1991 | ||
cf901d3b DE |
1992 | /* Find the definition for a specified symbol name NAME |
1993 | in domain DOMAIN in language LANGUAGE, visible from lexical block BLOCK | |
1994 | if non-NULL or from global/static blocks if BLOCK is NULL. | |
1995 | Returns the struct symbol pointer, or NULL if no symbol is found. | |
1996 | C++: if IS_A_FIELD_OF_THIS is non-NULL on entry, check to see if | |
1997 | NAME is a field of the current implied argument `this'. If so fill in the | |
1998 | fields of IS_A_FIELD_OF_THIS, otherwise the fields are set to NULL. | |
cf901d3b | 1999 | The symbol's section is fixed up if necessary. */ |
53c5240f | 2000 | |
d12307c1 PMR |
2001 | extern struct block_symbol |
2002 | lookup_symbol_in_language (const char *, | |
2003 | const struct block *, | |
2004 | const domain_enum, | |
2005 | enum language, | |
2006 | struct field_of_this_result *); | |
53c5240f | 2007 | |
cf901d3b | 2008 | /* Same as lookup_symbol_in_language, but using the current language. */ |
c906108c | 2009 | |
d12307c1 PMR |
2010 | extern struct block_symbol lookup_symbol (const char *, |
2011 | const struct block *, | |
2012 | const domain_enum, | |
2013 | struct field_of_this_result *); | |
c906108c | 2014 | |
de63c46b PA |
2015 | /* Find the definition for a specified symbol search name in domain |
2016 | DOMAIN, visible from lexical block BLOCK if non-NULL or from | |
2017 | global/static blocks if BLOCK is NULL. The passed-in search name | |
2018 | should not come from the user; instead it should already be a | |
987012b8 | 2019 | search name as retrieved from a search_name () call. See definition of |
de63c46b PA |
2020 | symbol_name_match_type::SEARCH_NAME. Returns the struct symbol |
2021 | pointer, or NULL if no symbol is found. The symbol's section is | |
2022 | fixed up if necessary. */ | |
2023 | ||
2024 | extern struct block_symbol lookup_symbol_search_name (const char *search_name, | |
2025 | const struct block *block, | |
2026 | domain_enum domain); | |
2027 | ||
5f9a71c3 DC |
2028 | /* Some helper functions for languages that need to write their own |
2029 | lookup_symbol_nonlocal functions. */ | |
2030 | ||
2031 | /* Lookup a symbol in the static block associated to BLOCK, if there | |
cf901d3b | 2032 | is one; do nothing if BLOCK is NULL or a global block. |
d12307c1 | 2033 | Upon success fixes up the symbol's section if necessary. */ |
5f9a71c3 | 2034 | |
d12307c1 PMR |
2035 | extern struct block_symbol |
2036 | lookup_symbol_in_static_block (const char *name, | |
2037 | const struct block *block, | |
2038 | const domain_enum domain); | |
5f9a71c3 | 2039 | |
08724ab7 | 2040 | /* Search all static file-level symbols for NAME from DOMAIN. |
d12307c1 | 2041 | Upon success fixes up the symbol's section if necessary. */ |
08724ab7 | 2042 | |
d12307c1 PMR |
2043 | extern struct block_symbol lookup_static_symbol (const char *name, |
2044 | const domain_enum domain); | |
08724ab7 | 2045 | |
cf901d3b | 2046 | /* Lookup a symbol in all files' global blocks. |
67be31e5 DE |
2047 | |
2048 | If BLOCK is non-NULL then it is used for two things: | |
2049 | 1) If a target-specific lookup routine for libraries exists, then use the | |
2050 | routine for the objfile of BLOCK, and | |
2051 | 2) The objfile of BLOCK is used to assist in determining the search order | |
2052 | if the target requires it. | |
2053 | See gdbarch_iterate_over_objfiles_in_search_order. | |
2054 | ||
d12307c1 | 2055 | Upon success fixes up the symbol's section if necessary. */ |
5f9a71c3 | 2056 | |
d12307c1 PMR |
2057 | extern struct block_symbol |
2058 | lookup_global_symbol (const char *name, | |
2059 | const struct block *block, | |
2060 | const domain_enum domain); | |
5f9a71c3 | 2061 | |
d1a2d36d | 2062 | /* Lookup a symbol in block BLOCK. |
d12307c1 | 2063 | Upon success fixes up the symbol's section if necessary. */ |
5f9a71c3 | 2064 | |
d12307c1 PMR |
2065 | extern struct symbol * |
2066 | lookup_symbol_in_block (const char *name, | |
de63c46b | 2067 | symbol_name_match_type match_type, |
d12307c1 PMR |
2068 | const struct block *block, |
2069 | const domain_enum domain); | |
5f9a71c3 | 2070 | |
cf901d3b DE |
2071 | /* Look up the `this' symbol for LANG in BLOCK. Return the symbol if |
2072 | found, or NULL if not found. */ | |
2073 | ||
d12307c1 PMR |
2074 | extern struct block_symbol |
2075 | lookup_language_this (const struct language_defn *lang, | |
2076 | const struct block *block); | |
66a17cb6 | 2077 | |
cf901d3b | 2078 | /* Lookup a [struct, union, enum] by name, within a specified block. */ |
c906108c | 2079 | |
270140bd | 2080 | extern struct type *lookup_struct (const char *, const struct block *); |
c906108c | 2081 | |
270140bd | 2082 | extern struct type *lookup_union (const char *, const struct block *); |
c906108c | 2083 | |
270140bd | 2084 | extern struct type *lookup_enum (const char *, const struct block *); |
c906108c | 2085 | |
c906108c SS |
2086 | /* from blockframe.c: */ |
2087 | ||
cd2bb709 PA |
2088 | /* lookup the function symbol corresponding to the address. The |
2089 | return value will not be an inlined function; the containing | |
2090 | function will be returned instead. */ | |
c906108c | 2091 | |
a14ed312 | 2092 | extern struct symbol *find_pc_function (CORE_ADDR); |
c906108c | 2093 | |
cd2bb709 PA |
2094 | /* lookup the function corresponding to the address and section. The |
2095 | return value will not be an inlined function; the containing | |
2096 | function will be returned instead. */ | |
c906108c | 2097 | |
714835d5 | 2098 | extern struct symbol *find_pc_sect_function (CORE_ADDR, struct obj_section *); |
c5aa993b | 2099 | |
cd2bb709 PA |
2100 | /* lookup the function symbol corresponding to the address and |
2101 | section. The return value will be the closest enclosing function, | |
2102 | which might be an inline function. */ | |
2103 | ||
2104 | extern struct symbol *find_pc_sect_containing_function | |
2105 | (CORE_ADDR pc, struct obj_section *section); | |
2106 | ||
71a3c369 TT |
2107 | /* Find the symbol at the given address. Returns NULL if no symbol |
2108 | found. Only exact matches for ADDRESS are considered. */ | |
2109 | ||
2110 | extern struct symbol *find_symbol_at_address (CORE_ADDR); | |
2111 | ||
fc811edd KB |
2112 | /* Finds the "function" (text symbol) that is smaller than PC but |
2113 | greatest of all of the potential text symbols in SECTION. Sets | |
2114 | *NAME and/or *ADDRESS conditionally if that pointer is non-null. | |
2115 | If ENDADDR is non-null, then set *ENDADDR to be the end of the | |
2116 | function (exclusive). If the optional parameter BLOCK is non-null, | |
2117 | then set *BLOCK to the address of the block corresponding to the | |
2118 | function symbol, if such a symbol could be found during the lookup; | |
2119 | nullptr is used as a return value for *BLOCK if no block is found. | |
2120 | This function either succeeds or fails (not halfway succeeds). If | |
2121 | it succeeds, it sets *NAME, *ADDRESS, and *ENDADDR to real | |
ececd218 CB |
2122 | information and returns true. If it fails, it sets *NAME, *ADDRESS |
2123 | and *ENDADDR to zero and returns false. | |
fc811edd KB |
2124 | |
2125 | If the function in question occupies non-contiguous ranges, | |
2126 | *ADDRESS and *ENDADDR are (subject to the conditions noted above) set | |
2127 | to the start and end of the range in which PC is found. Thus | |
2128 | *ADDRESS <= PC < *ENDADDR with no intervening gaps (in which ranges | |
2129 | from other functions might be found). | |
2130 | ||
2131 | This property allows find_pc_partial_function to be used (as it had | |
2132 | been prior to the introduction of non-contiguous range support) by | |
2133 | various tdep files for finding a start address and limit address | |
2134 | for prologue analysis. This still isn't ideal, however, because we | |
2135 | probably shouldn't be doing prologue analysis (in which | |
2136 | instructions are scanned to determine frame size and stack layout) | |
2137 | for any range that doesn't contain the entry pc. Moreover, a good | |
2138 | argument can be made that prologue analysis ought to be performed | |
2139 | starting from the entry pc even when PC is within some other range. | |
2140 | This might suggest that *ADDRESS and *ENDADDR ought to be set to the | |
2141 | limits of the entry pc range, but that will cause the | |
2142 | *ADDRESS <= PC < *ENDADDR condition to be violated; many of the | |
59adbf5d KB |
2143 | callers of find_pc_partial_function expect this condition to hold. |
2144 | ||
2145 | Callers which require the start and/or end addresses for the range | |
2146 | containing the entry pc should instead call | |
2147 | find_function_entry_range_from_pc. */ | |
fc811edd | 2148 | |
ececd218 CB |
2149 | extern bool find_pc_partial_function (CORE_ADDR pc, const char **name, |
2150 | CORE_ADDR *address, CORE_ADDR *endaddr, | |
2151 | const struct block **block = nullptr); | |
c906108c | 2152 | |
f75a0693 AB |
2153 | /* Like find_pc_partial_function, above, but returns the underlying |
2154 | general_symbol_info (rather than the name) as an out parameter. */ | |
2155 | ||
2156 | extern bool find_pc_partial_function_sym | |
2157 | (CORE_ADDR pc, const general_symbol_info **sym, | |
2158 | CORE_ADDR *address, CORE_ADDR *endaddr, | |
2159 | const struct block **block = nullptr); | |
2160 | ||
59adbf5d KB |
2161 | /* Like find_pc_partial_function, above, but *ADDRESS and *ENDADDR are |
2162 | set to start and end addresses of the range containing the entry pc. | |
2163 | ||
2164 | Note that it is not necessarily the case that (for non-NULL ADDRESS | |
2165 | and ENDADDR arguments) the *ADDRESS <= PC < *ENDADDR condition will | |
2166 | hold. | |
2167 | ||
2168 | See comment for find_pc_partial_function, above, for further | |
2169 | explanation. */ | |
2170 | ||
2171 | extern bool find_function_entry_range_from_pc (CORE_ADDR pc, | |
2172 | const char **name, | |
2173 | CORE_ADDR *address, | |
2174 | CORE_ADDR *endaddr); | |
2175 | ||
8388016d PA |
2176 | /* Return the type of a function with its first instruction exactly at |
2177 | the PC address. Return NULL otherwise. */ | |
2178 | ||
2179 | extern struct type *find_function_type (CORE_ADDR pc); | |
2180 | ||
2181 | /* See if we can figure out the function's actual type from the type | |
2182 | that the resolver returns. RESOLVER_FUNADDR is the address of the | |
2183 | ifunc resolver. */ | |
2184 | ||
2185 | extern struct type *find_gnu_ifunc_target_type (CORE_ADDR resolver_funaddr); | |
2186 | ||
ca31ab1d PA |
2187 | /* Find the GNU ifunc minimal symbol that matches SYM. */ |
2188 | extern bound_minimal_symbol find_gnu_ifunc (const symbol *sym); | |
2189 | ||
a14ed312 | 2190 | extern void clear_pc_function_cache (void); |
c906108c | 2191 | |
2097ae25 | 2192 | /* Expand symtab containing PC, SECTION if not already expanded. */ |
c906108c | 2193 | |
2097ae25 | 2194 | extern void expand_symtab_containing_pc (CORE_ADDR, struct obj_section *); |
c906108c | 2195 | |
c378eb4e | 2196 | /* lookup full symbol table by address. */ |
c906108c | 2197 | |
43f3e411 | 2198 | extern struct compunit_symtab *find_pc_compunit_symtab (CORE_ADDR); |
c906108c | 2199 | |
c378eb4e | 2200 | /* lookup full symbol table by address and section. */ |
c906108c | 2201 | |
43f3e411 DE |
2202 | extern struct compunit_symtab * |
2203 | find_pc_sect_compunit_symtab (CORE_ADDR, struct obj_section *); | |
c906108c | 2204 | |
ececd218 | 2205 | extern bool find_pc_line_pc_range (CORE_ADDR, CORE_ADDR *, CORE_ADDR *); |
c906108c | 2206 | |
9dec38d3 | 2207 | extern void reread_symbols (int from_tty); |
c906108c | 2208 | |
cf901d3b DE |
2209 | /* Look up a type named NAME in STRUCT_DOMAIN in the current language. |
2210 | The type returned must not be opaque -- i.e., must have at least one field | |
2211 | defined. */ | |
2212 | ||
a14ed312 | 2213 | extern struct type *lookup_transparent_type (const char *); |
c906108c | 2214 | |
cf901d3b | 2215 | extern struct type *basic_lookup_transparent_type (const char *); |
c906108c | 2216 | |
c378eb4e | 2217 | /* Macro for name of symbol to indicate a file compiled with gcc. */ |
c906108c SS |
2218 | #ifndef GCC_COMPILED_FLAG_SYMBOL |
2219 | #define GCC_COMPILED_FLAG_SYMBOL "gcc_compiled." | |
2220 | #endif | |
2221 | ||
c378eb4e | 2222 | /* Macro for name of symbol to indicate a file compiled with gcc2. */ |
c906108c SS |
2223 | #ifndef GCC2_COMPILED_FLAG_SYMBOL |
2224 | #define GCC2_COMPILED_FLAG_SYMBOL "gcc2_compiled." | |
2225 | #endif | |
2226 | ||
ececd218 | 2227 | extern bool in_gnu_ifunc_stub (CORE_ADDR pc); |
0875794a | 2228 | |
07be84bf JK |
2229 | /* Functions for resolving STT_GNU_IFUNC symbols which are implemented only |
2230 | for ELF symbol files. */ | |
2231 | ||
2232 | struct gnu_ifunc_fns | |
2233 | { | |
2234 | /* See elf_gnu_ifunc_resolve_addr for its real implementation. */ | |
2235 | CORE_ADDR (*gnu_ifunc_resolve_addr) (struct gdbarch *gdbarch, CORE_ADDR pc); | |
2236 | ||
2237 | /* See elf_gnu_ifunc_resolve_name for its real implementation. */ | |
ececd218 | 2238 | bool (*gnu_ifunc_resolve_name) (const char *function_name, |
07be84bf | 2239 | CORE_ADDR *function_address_p); |
0e30163f JK |
2240 | |
2241 | /* See elf_gnu_ifunc_resolver_stop for its real implementation. */ | |
74421c0b | 2242 | void (*gnu_ifunc_resolver_stop) (code_breakpoint *b); |
0e30163f JK |
2243 | |
2244 | /* See elf_gnu_ifunc_resolver_return_stop for its real implementation. */ | |
74421c0b | 2245 | void (*gnu_ifunc_resolver_return_stop) (code_breakpoint *b); |
07be84bf JK |
2246 | }; |
2247 | ||
2248 | #define gnu_ifunc_resolve_addr gnu_ifunc_fns_p->gnu_ifunc_resolve_addr | |
2249 | #define gnu_ifunc_resolve_name gnu_ifunc_fns_p->gnu_ifunc_resolve_name | |
0e30163f JK |
2250 | #define gnu_ifunc_resolver_stop gnu_ifunc_fns_p->gnu_ifunc_resolver_stop |
2251 | #define gnu_ifunc_resolver_return_stop \ | |
2252 | gnu_ifunc_fns_p->gnu_ifunc_resolver_return_stop | |
07be84bf JK |
2253 | |
2254 | extern const struct gnu_ifunc_fns *gnu_ifunc_fns_p; | |
2255 | ||
9efe17a3 | 2256 | extern CORE_ADDR find_solib_trampoline_target (frame_info_ptr, CORE_ADDR); |
c906108c | 2257 | |
c906108c | 2258 | struct symtab_and_line |
17c5ed2c | 2259 | { |
6c95b8df | 2260 | /* The program space of this sal. */ |
51abb421 | 2261 | struct program_space *pspace = NULL; |
6c95b8df | 2262 | |
51abb421 | 2263 | struct symtab *symtab = NULL; |
06871ae8 | 2264 | struct symbol *symbol = NULL; |
51abb421 | 2265 | struct obj_section *section = NULL; |
3467ec66 | 2266 | struct minimal_symbol *msymbol = NULL; |
17c5ed2c DC |
2267 | /* Line number. Line numbers start at 1 and proceed through symtab->nlines. |
2268 | 0 is never a valid line number; it is used to indicate that line number | |
2269 | information is not available. */ | |
51abb421 | 2270 | int line = 0; |
17c5ed2c | 2271 | |
51abb421 PA |
2272 | CORE_ADDR pc = 0; |
2273 | CORE_ADDR end = 0; | |
2274 | bool explicit_pc = false; | |
2275 | bool explicit_line = false; | |
55aa24fb | 2276 | |
8c95582d AB |
2277 | /* If the line number information is valid, then this indicates if this |
2278 | line table entry had the is-stmt flag set or not. */ | |
2279 | bool is_stmt = false; | |
2280 | ||
55aa24fb | 2281 | /* The probe associated with this symtab_and_line. */ |
935676c9 | 2282 | probe *prob = NULL; |
729662a5 TT |
2283 | /* If PROBE is not NULL, then this is the objfile in which the probe |
2284 | originated. */ | |
51abb421 | 2285 | struct objfile *objfile = NULL; |
17c5ed2c | 2286 | }; |
c906108c | 2287 | |
c5aa993b | 2288 | \f |
c906108c | 2289 | |
c906108c SS |
2290 | /* Given a pc value, return line number it is in. Second arg nonzero means |
2291 | if pc is on the boundary use the previous statement's line number. */ | |
2292 | ||
a14ed312 | 2293 | extern struct symtab_and_line find_pc_line (CORE_ADDR, int); |
c906108c | 2294 | |
c378eb4e | 2295 | /* Same function, but specify a section as well as an address. */ |
c906108c | 2296 | |
714835d5 UW |
2297 | extern struct symtab_and_line find_pc_sect_line (CORE_ADDR, |
2298 | struct obj_section *, int); | |
c906108c | 2299 | |
34248c3a DE |
2300 | /* Wrapper around find_pc_line to just return the symtab. */ |
2301 | ||
2302 | extern struct symtab *find_pc_line_symtab (CORE_ADDR); | |
2303 | ||
c906108c SS |
2304 | /* Given a symtab and line number, return the pc there. */ |
2305 | ||
ececd218 | 2306 | extern bool find_line_pc (struct symtab *, int, CORE_ADDR *); |
c906108c | 2307 | |
ececd218 CB |
2308 | extern bool find_line_pc_range (struct symtab_and_line, CORE_ADDR *, |
2309 | CORE_ADDR *); | |
c906108c | 2310 | |
a14ed312 | 2311 | extern void resolve_sal_pc (struct symtab_and_line *); |
c906108c | 2312 | |
f176c4b5 | 2313 | /* solib.c */ |
c906108c | 2314 | |
a14ed312 | 2315 | extern void clear_solib (void); |
c906108c | 2316 | |
c6756f62 PA |
2317 | /* The reason we're calling into a completion match list collector |
2318 | function. */ | |
2319 | enum class complete_symbol_mode | |
2320 | { | |
2321 | /* Completing an expression. */ | |
2322 | EXPRESSION, | |
2323 | ||
2324 | /* Completing a linespec. */ | |
2325 | LINESPEC, | |
2326 | }; | |
2327 | ||
eb3ff9a5 PA |
2328 | extern void default_collect_symbol_completion_matches_break_on |
2329 | (completion_tracker &tracker, | |
c6756f62 | 2330 | complete_symbol_mode mode, |
b5ec771e | 2331 | symbol_name_match_type name_match_type, |
eb3ff9a5 | 2332 | const char *text, const char *word, const char *break_on, |
2f68a895 | 2333 | enum type_code code); |
b5ec771e PA |
2334 | extern void collect_symbol_completion_matches |
2335 | (completion_tracker &tracker, | |
2336 | complete_symbol_mode mode, | |
2337 | symbol_name_match_type name_match_type, | |
2338 | const char *, const char *); | |
eb3ff9a5 PA |
2339 | extern void collect_symbol_completion_matches_type (completion_tracker &tracker, |
2340 | const char *, const char *, | |
2f68a895 | 2341 | enum type_code); |
c906108c | 2342 | |
b5ec771e PA |
2343 | extern void collect_file_symbol_completion_matches |
2344 | (completion_tracker &tracker, | |
2345 | complete_symbol_mode, | |
2346 | symbol_name_match_type name_match_type, | |
2347 | const char *, const char *, const char *); | |
c94fdfd0 | 2348 | |
eb3ff9a5 PA |
2349 | extern completion_list |
2350 | make_source_files_completion_list (const char *, const char *); | |
c94fdfd0 | 2351 | |
f9d67a22 PA |
2352 | /* Return whether SYM is a function/method, as opposed to a data symbol. */ |
2353 | ||
2354 | extern bool symbol_is_function_or_method (symbol *sym); | |
2355 | ||
2356 | /* Return whether MSYMBOL is a function/method, as opposed to a data | |
2357 | symbol */ | |
2358 | ||
2359 | extern bool symbol_is_function_or_method (minimal_symbol *msymbol); | |
2360 | ||
2361 | /* Return whether SYM should be skipped in completion mode MODE. In | |
2362 | linespec mode, we're only interested in functions/methods. */ | |
2363 | ||
2364 | template<typename Symbol> | |
2365 | static bool | |
2366 | completion_skip_symbol (complete_symbol_mode mode, Symbol *sym) | |
2367 | { | |
2368 | return (mode == complete_symbol_mode::LINESPEC | |
2369 | && !symbol_is_function_or_method (sym)); | |
2370 | } | |
2371 | ||
c906108c SS |
2372 | /* symtab.c */ |
2373 | ||
ececd218 | 2374 | bool matching_obj_sections (struct obj_section *, struct obj_section *); |
94277a38 | 2375 | |
ececd218 | 2376 | extern struct symtab *find_line_symtab (struct symtab *, int, int *, bool *); |
50641945 | 2377 | |
42ddae10 PA |
2378 | /* Given a function symbol SYM, find the symtab and line for the start |
2379 | of the function. If FUNFIRSTLINE is true, we want the first line | |
2380 | of real code inside the function. */ | |
2381 | extern symtab_and_line find_function_start_sal (symbol *sym, bool | |
2382 | funfirstline); | |
2383 | ||
2384 | /* Same, but start with a function address/section instead of a | |
2385 | symbol. */ | |
2386 | extern symtab_and_line find_function_start_sal (CORE_ADDR func_addr, | |
2387 | obj_section *section, | |
2388 | bool funfirstline); | |
50641945 | 2389 | |
059acae7 UW |
2390 | extern void skip_prologue_sal (struct symtab_and_line *); |
2391 | ||
c906108c SS |
2392 | /* symtab.c */ |
2393 | ||
d80b854b UW |
2394 | extern CORE_ADDR skip_prologue_using_sal (struct gdbarch *gdbarch, |
2395 | CORE_ADDR func_addr); | |
634aa483 | 2396 | |
a14ed312 KB |
2397 | extern struct symbol *fixup_symbol_section (struct symbol *, |
2398 | struct objfile *); | |
c906108c | 2399 | |
bf223d3e PA |
2400 | /* If MSYMBOL is an text symbol, look for a function debug symbol with |
2401 | the same address. Returns NULL if not found. This is necessary in | |
2402 | case a function is an alias to some other function, because debug | |
2403 | information is only emitted for the alias target function's | |
2404 | definition, not for the alias. */ | |
2405 | extern symbol *find_function_alias_target (bound_minimal_symbol msymbol); | |
2406 | ||
c906108c SS |
2407 | /* Symbol searching */ |
2408 | ||
470c0b1c AB |
2409 | /* When using the symbol_searcher struct to search for symbols, a vector of |
2410 | the following structs is returned. */ | |
c906108c | 2411 | struct symbol_search |
17c5ed2c | 2412 | { |
b9c04fb2 TT |
2413 | symbol_search (int block_, struct symbol *symbol_) |
2414 | : block (block_), | |
2415 | symbol (symbol_) | |
2416 | { | |
2417 | msymbol.minsym = nullptr; | |
2418 | msymbol.objfile = nullptr; | |
2419 | } | |
2420 | ||
2421 | symbol_search (int block_, struct minimal_symbol *minsym, | |
2422 | struct objfile *objfile) | |
2423 | : block (block_), | |
2424 | symbol (nullptr) | |
2425 | { | |
2426 | msymbol.minsym = minsym; | |
2427 | msymbol.objfile = objfile; | |
2428 | } | |
2429 | ||
2430 | bool operator< (const symbol_search &other) const | |
2431 | { | |
2432 | return compare_search_syms (*this, other) < 0; | |
2433 | } | |
2434 | ||
2435 | bool operator== (const symbol_search &other) const | |
2436 | { | |
2437 | return compare_search_syms (*this, other) == 0; | |
2438 | } | |
2439 | ||
c378eb4e MS |
2440 | /* The block in which the match was found. Could be, for example, |
2441 | STATIC_BLOCK or GLOBAL_BLOCK. */ | |
17c5ed2c | 2442 | int block; |
c906108c | 2443 | |
17c5ed2c | 2444 | /* Information describing what was found. |
c906108c | 2445 | |
d01060f0 | 2446 | If symbol is NOT NULL, then information was found for this match. */ |
17c5ed2c | 2447 | struct symbol *symbol; |
c906108c | 2448 | |
17c5ed2c | 2449 | /* If msymbol is non-null, then a match was made on something for |
c378eb4e | 2450 | which only minimal_symbols exist. */ |
7c7b6655 | 2451 | struct bound_minimal_symbol msymbol; |
c906108c | 2452 | |
b9c04fb2 TT |
2453 | private: |
2454 | ||
2455 | static int compare_search_syms (const symbol_search &sym_a, | |
2456 | const symbol_search &sym_b); | |
17c5ed2c | 2457 | }; |
c906108c | 2458 | |
470c0b1c AB |
2459 | /* In order to search for global symbols of a particular kind matching |
2460 | particular regular expressions, create an instance of this structure and | |
2461 | call the SEARCH member function. */ | |
2462 | class global_symbol_searcher | |
2463 | { | |
2464 | public: | |
2465 | ||
2466 | /* Constructor. */ | |
2467 | global_symbol_searcher (enum search_domain kind, | |
2468 | const char *symbol_name_regexp) | |
2469 | : m_kind (kind), | |
2470 | m_symbol_name_regexp (symbol_name_regexp) | |
2471 | { | |
2472 | /* The symbol searching is designed to only find one kind of thing. */ | |
2473 | gdb_assert (m_kind != ALL_DOMAIN); | |
2474 | } | |
2475 | ||
2476 | /* Set the optional regexp that matches against the symbol type. */ | |
2477 | void set_symbol_type_regexp (const char *regexp) | |
2478 | { | |
2479 | m_symbol_type_regexp = regexp; | |
2480 | } | |
2481 | ||
2482 | /* Set the flag to exclude minsyms from the search results. */ | |
2483 | void set_exclude_minsyms (bool exclude_minsyms) | |
2484 | { | |
2485 | m_exclude_minsyms = exclude_minsyms; | |
2486 | } | |
2487 | ||
c2512106 AB |
2488 | /* Set the maximum number of search results to be returned. */ |
2489 | void set_max_search_results (size_t max_search_results) | |
2490 | { | |
2491 | m_max_search_results = max_search_results; | |
2492 | } | |
2493 | ||
470c0b1c AB |
2494 | /* Search the symbols from all objfiles in the current program space |
2495 | looking for matches as defined by the current state of this object. | |
2496 | ||
2497 | Within each file the results are sorted locally; each symtab's global | |
2498 | and static blocks are separately alphabetized. Duplicate entries are | |
2499 | removed. */ | |
2500 | std::vector<symbol_search> search () const; | |
2501 | ||
2502 | /* The set of source files to search in for matching symbols. This is | |
2503 | currently public so that it can be populated after this object has | |
2504 | been constructed. */ | |
2505 | std::vector<const char *> filenames; | |
2506 | ||
2507 | private: | |
2508 | /* The kind of symbols are we searching for. | |
2509 | VARIABLES_DOMAIN - Search all symbols, excluding functions, type | |
dda83cd7 | 2510 | names, and constants (enums). |
470c0b1c AB |
2511 | FUNCTIONS_DOMAIN - Search all functions.. |
2512 | TYPES_DOMAIN - Search all type names. | |
2513 | MODULES_DOMAIN - Search all Fortran modules. | |
2514 | ALL_DOMAIN - Not valid for this function. */ | |
2515 | enum search_domain m_kind; | |
2516 | ||
2517 | /* Regular expression to match against the symbol name. */ | |
2518 | const char *m_symbol_name_regexp = nullptr; | |
2519 | ||
2520 | /* Regular expression to match against the symbol type. */ | |
2521 | const char *m_symbol_type_regexp = nullptr; | |
2522 | ||
2523 | /* When this flag is false then minsyms that match M_SYMBOL_REGEXP will | |
2524 | be included in the results, otherwise they are excluded. */ | |
2525 | bool m_exclude_minsyms = false; | |
f97a63c5 | 2526 | |
c2512106 AB |
2527 | /* Maximum number of search results. We currently impose a hard limit |
2528 | of SIZE_MAX, there is no "unlimited". */ | |
2529 | size_t m_max_search_results = SIZE_MAX; | |
2530 | ||
f97a63c5 AB |
2531 | /* Expand symtabs in OBJFILE that match PREG, are of type M_KIND. Return |
2532 | true if any msymbols were seen that we should later consider adding to | |
2533 | the results list. */ | |
2534 | bool expand_symtabs (objfile *objfile, | |
2535 | const gdb::optional<compiled_regex> &preg) const; | |
2536 | ||
2537 | /* Add symbols from symtabs in OBJFILE that match PREG, and TREG, and are | |
c2512106 AB |
2538 | of type M_KIND, to the results set RESULTS_SET. Return false if we |
2539 | stop adding results early due to having already found too many results | |
2540 | (based on M_MAX_SEARCH_RESULTS limit), otherwise return true. | |
2541 | Returning true does not indicate that any results were added, just | |
2542 | that we didn't _not_ add a result due to reaching MAX_SEARCH_RESULTS. */ | |
2543 | bool add_matching_symbols (objfile *objfile, | |
f97a63c5 AB |
2544 | const gdb::optional<compiled_regex> &preg, |
2545 | const gdb::optional<compiled_regex> &treg, | |
c2512106 AB |
2546 | std::set<symbol_search> *result_set) const; |
2547 | ||
2548 | /* Add msymbols from OBJFILE that match PREG and M_KIND, to the results | |
2549 | vector RESULTS. Return false if we stop adding results early due to | |
2550 | having already found too many results (based on max search results | |
2551 | limit M_MAX_SEARCH_RESULTS), otherwise return true. Returning true | |
2552 | does not indicate that any results were added, just that we didn't | |
2553 | _not_ add a result due to reaching MAX_SEARCH_RESULTS. */ | |
2554 | bool add_matching_msymbols (objfile *objfile, | |
f97a63c5 AB |
2555 | const gdb::optional<compiled_regex> &preg, |
2556 | std::vector<symbol_search> *results) const; | |
2557 | ||
2558 | /* Return true if MSYMBOL is of type KIND. */ | |
2559 | static bool is_suitable_msymbol (const enum search_domain kind, | |
2560 | const minimal_symbol *msymbol); | |
470c0b1c | 2561 | }; |
165f8965 AB |
2562 | |
2563 | /* When searching for Fortran symbols within modules (functions/variables) | |
2564 | we return a vector of this type. The first item in the pair is the | |
2565 | module symbol, and the second item is the symbol for the function or | |
2566 | variable we found. */ | |
2567 | typedef std::pair<symbol_search, symbol_search> module_symbol_search; | |
2568 | ||
2569 | /* Searches the symbols to find function and variables symbols (depending | |
2570 | on KIND) within Fortran modules. The MODULE_REGEXP matches against the | |
2571 | name of the module, REGEXP matches against the name of the symbol within | |
2572 | the module, and TYPE_REGEXP matches against the type of the symbol | |
2573 | within the module. */ | |
2574 | extern std::vector<module_symbol_search> search_module_symbols | |
2575 | (const char *module_regexp, const char *regexp, | |
2576 | const char *type_regexp, search_domain kind); | |
2577 | ||
5f512a7d AB |
2578 | /* Convert a global or static symbol SYM (based on BLOCK, which should be |
2579 | either GLOBAL_BLOCK or STATIC_BLOCK) into a string for use in 'info' | |
2580 | type commands (e.g. 'info variables', 'info functions', etc). KIND is | |
2581 | the type of symbol that was searched for which gave us SYM. */ | |
2582 | ||
2583 | extern std::string symbol_to_info_string (struct symbol *sym, int block, | |
2584 | enum search_domain kind); | |
2585 | ||
12615cba PW |
2586 | extern bool treg_matches_sym_type_name (const compiled_regex &treg, |
2587 | const struct symbol *sym); | |
c906108c | 2588 | |
cd215b2e TT |
2589 | /* The name of the ``main'' function. */ |
2590 | extern const char *main_name (); | |
9e6c82ad | 2591 | extern enum language main_language (void); |
51cc5b07 | 2592 | |
442853af CB |
2593 | /* Lookup symbol NAME from DOMAIN in MAIN_OBJFILE's global or static blocks, |
2594 | as specified by BLOCK_INDEX. | |
cf901d3b DE |
2595 | This searches MAIN_OBJFILE as well as any associated separate debug info |
2596 | objfiles of MAIN_OBJFILE. | |
442853af | 2597 | BLOCK_INDEX can be GLOBAL_BLOCK or STATIC_BLOCK. |
d12307c1 | 2598 | Upon success fixes up the symbol's section if necessary. */ |
cf901d3b | 2599 | |
d12307c1 | 2600 | extern struct block_symbol |
efad9b6a | 2601 | lookup_global_symbol_from_objfile (struct objfile *main_objfile, |
442853af | 2602 | enum block_enum block_index, |
cf901d3b DE |
2603 | const char *name, |
2604 | const domain_enum domain); | |
3a40aaa0 | 2605 | |
a6c727b2 DJ |
2606 | /* Return 1 if the supplied producer string matches the ARM RealView |
2607 | compiler (armcc). */ | |
ececd218 | 2608 | bool producer_is_realview (const char *producer); |
3a40aaa0 | 2609 | |
ccefe4c4 TT |
2610 | void fixup_section (struct general_symbol_info *ginfo, |
2611 | CORE_ADDR addr, struct objfile *objfile); | |
2612 | ||
db0fec5c | 2613 | extern unsigned int symtab_create_debug; |
45cfd468 | 2614 | |
2ab317fb SM |
2615 | /* Print a "symtab-create" debug statement. */ |
2616 | ||
2617 | #define symtab_create_debug_printf(fmt, ...) \ | |
2618 | debug_prefixed_printf_cond (symtab_create_debug >= 1, "symtab-create", fmt, ##__VA_ARGS__) | |
2619 | ||
2620 | /* Print a verbose "symtab-create" debug statement, only if | |
2621 | "set debug symtab-create" is set to 2 or higher. */ | |
2622 | ||
2623 | #define symtab_create_debug_printf_v(fmt, ...) \ | |
2624 | debug_prefixed_printf_cond (symtab_create_debug >= 2, "symtab-create", fmt, ##__VA_ARGS__) | |
2625 | ||
cc485e62 DE |
2626 | extern unsigned int symbol_lookup_debug; |
2627 | ||
491144b5 | 2628 | extern bool basenames_may_differ; |
c011a4f4 | 2629 | |
ececd218 CB |
2630 | bool compare_filenames_for_search (const char *filename, |
2631 | const char *search_name); | |
4aac40c8 | 2632 | |
ececd218 CB |
2633 | bool compare_glob_filenames_for_search (const char *filename, |
2634 | const char *search_name); | |
cce0e923 | 2635 | |
14bc53a8 PA |
2636 | bool iterate_over_some_symtabs (const char *name, |
2637 | const char *real_path, | |
2638 | struct compunit_symtab *first, | |
2639 | struct compunit_symtab *after_last, | |
2640 | gdb::function_view<bool (symtab *)> callback); | |
f8eba3c6 TT |
2641 | |
2642 | void iterate_over_symtabs (const char *name, | |
14bc53a8 PA |
2643 | gdb::function_view<bool (symtab *)> callback); |
2644 | ||
f8eba3c6 | 2645 | |
67d89901 TT |
2646 | std::vector<CORE_ADDR> find_pcs_for_symtab_line |
2647 | (struct symtab *symtab, int line, struct linetable_entry **best_entry); | |
f8eba3c6 | 2648 | |
14bc53a8 PA |
2649 | /* Prototype for callbacks for LA_ITERATE_OVER_SYMBOLS. The callback |
2650 | is called once per matching symbol SYM. The callback should return | |
2651 | true to indicate that LA_ITERATE_OVER_SYMBOLS should continue | |
2652 | iterating, or false to indicate that the iteration should end. */ | |
8e704927 | 2653 | |
7e41c8db | 2654 | typedef bool (symbol_found_callback_ftype) (struct block_symbol *bsym); |
8e704927 | 2655 | |
6969f124 TT |
2656 | /* Iterate over the symbols named NAME, matching DOMAIN, in BLOCK. |
2657 | ||
2658 | For each symbol that matches, CALLBACK is called. The symbol is | |
2659 | passed to the callback. | |
2660 | ||
2661 | If CALLBACK returns false, the iteration ends and this function | |
2662 | returns false. Otherwise, the search continues, and the function | |
2663 | eventually returns true. */ | |
2664 | ||
2665 | bool iterate_over_symbols (const struct block *block, | |
b5ec771e | 2666 | const lookup_name_info &name, |
f8eba3c6 | 2667 | const domain_enum domain, |
14bc53a8 | 2668 | gdb::function_view<symbol_found_callback_ftype> callback); |
f8eba3c6 | 2669 | |
6a3dbf1b TT |
2670 | /* Like iterate_over_symbols, but if all calls to CALLBACK return |
2671 | true, then calls CALLBACK one additional time with a block_symbol | |
2672 | that has a valid block but a NULL symbol. */ | |
2673 | ||
2674 | bool iterate_over_symbols_terminated | |
2675 | (const struct block *block, | |
2676 | const lookup_name_info &name, | |
2677 | const domain_enum domain, | |
2678 | gdb::function_view<symbol_found_callback_ftype> callback); | |
2679 | ||
2f408ecb PA |
2680 | /* Storage type used by demangle_for_lookup. demangle_for_lookup |
2681 | either returns a const char * pointer that points to either of the | |
2682 | fields of this type, or a pointer to the input NAME. This is done | |
596dc4ad TT |
2683 | this way to avoid depending on the precise details of the storage |
2684 | for the string. */ | |
2f408ecb PA |
2685 | class demangle_result_storage |
2686 | { | |
2687 | public: | |
2688 | ||
596dc4ad TT |
2689 | /* Swap the malloc storage to STR, and return a pointer to the |
2690 | beginning of the new string. */ | |
2691 | const char *set_malloc_ptr (gdb::unique_xmalloc_ptr<char> &&str) | |
2f408ecb | 2692 | { |
596dc4ad TT |
2693 | m_malloc = std::move (str); |
2694 | return m_malloc.get (); | |
2f408ecb PA |
2695 | } |
2696 | ||
2697 | /* Set the malloc storage to now point at PTR. Any previous malloc | |
2698 | storage is released. */ | |
2699 | const char *set_malloc_ptr (char *ptr) | |
2700 | { | |
2701 | m_malloc.reset (ptr); | |
2702 | return ptr; | |
2703 | } | |
2704 | ||
2705 | private: | |
2706 | ||
2707 | /* The storage. */ | |
2f408ecb PA |
2708 | gdb::unique_xmalloc_ptr<char> m_malloc; |
2709 | }; | |
2710 | ||
2711 | const char * | |
2712 | demangle_for_lookup (const char *name, enum language lang, | |
2713 | demangle_result_storage &storage); | |
f8eba3c6 | 2714 | |
b5ec771e PA |
2715 | /* Test to see if the symbol of language SYMBOL_LANGUAGE specified by |
2716 | SYMNAME (which is already demangled for C++ symbols) matches | |
2717 | SYM_TEXT in the first SYM_TEXT_LEN characters. If so, add it to | |
e08bd6c5 PA |
2718 | the current completion list and return true. Otherwise, return |
2719 | false. */ | |
2720 | bool completion_list_add_name (completion_tracker &tracker, | |
b5ec771e PA |
2721 | language symbol_language, |
2722 | const char *symname, | |
2723 | const lookup_name_info &lookup_name, | |
b5ec771e PA |
2724 | const char *text, const char *word); |
2725 | ||
fcaad03c KS |
2726 | /* A simple symbol searching class. */ |
2727 | ||
2728 | class symbol_searcher | |
2729 | { | |
2730 | public: | |
2731 | /* Returns the symbols found for the search. */ | |
2732 | const std::vector<block_symbol> & | |
2733 | matching_symbols () const | |
2734 | { | |
2735 | return m_symbols; | |
2736 | } | |
2737 | ||
2738 | /* Returns the minimal symbols found for the search. */ | |
2739 | const std::vector<bound_minimal_symbol> & | |
2740 | matching_msymbols () const | |
2741 | { | |
2742 | return m_minimal_symbols; | |
2743 | } | |
2744 | ||
2745 | /* Search for all symbols named NAME in LANGUAGE with DOMAIN, restricting | |
2746 | search to FILE_SYMTABS and SEARCH_PSPACE, both of which may be NULL | |
2747 | to search all symtabs and program spaces. */ | |
2748 | void find_all_symbols (const std::string &name, | |
2749 | const struct language_defn *language, | |
2750 | enum search_domain search_domain, | |
2751 | std::vector<symtab *> *search_symtabs, | |
2752 | struct program_space *search_pspace); | |
2753 | ||
2754 | /* Reset this object to perform another search. */ | |
2755 | void reset () | |
2756 | { | |
2757 | m_symbols.clear (); | |
2758 | m_minimal_symbols.clear (); | |
2759 | } | |
2760 | ||
2761 | private: | |
2762 | /* Matching debug symbols. */ | |
2763 | std::vector<block_symbol> m_symbols; | |
2764 | ||
2765 | /* Matching non-debug symbols. */ | |
2766 | std::vector<bound_minimal_symbol> m_minimal_symbols; | |
2767 | }; | |
2768 | ||
0e350a05 AB |
2769 | /* Class used to encapsulate the filename filtering for the "info sources" |
2770 | command. */ | |
2771 | ||
2772 | struct info_sources_filter | |
2773 | { | |
2774 | /* If filename filtering is being used (see M_C_REGEXP) then which part | |
2775 | of the filename is being filtered against? */ | |
2776 | enum class match_on | |
2777 | { | |
2778 | /* Match against the full filename. */ | |
2779 | FULLNAME, | |
2780 | ||
2781 | /* Match only against the directory part of the full filename. */ | |
2782 | DIRNAME, | |
2783 | ||
2784 | /* Match only against the basename part of the full filename. */ | |
2785 | BASENAME | |
2786 | }; | |
2787 | ||
2788 | /* Create a filter of MATCH_TYPE using regular expression REGEXP. If | |
2789 | REGEXP is nullptr then all files will match the filter and MATCH_TYPE | |
2790 | is ignored. | |
2791 | ||
2792 | The string pointed too by REGEXP must remain live and unchanged for | |
2793 | this lifetime of this object as the object only retains a copy of the | |
2794 | pointer. */ | |
2795 | info_sources_filter (match_on match_type, const char *regexp); | |
2796 | ||
2797 | DISABLE_COPY_AND_ASSIGN (info_sources_filter); | |
2798 | ||
2799 | /* Does FULLNAME match the filter defined by this object, return true if | |
2800 | it does, otherwise, return false. If there is no filtering defined | |
2801 | then this function will always return true. */ | |
2802 | bool matches (const char *fullname) const; | |
2803 | ||
0e350a05 AB |
2804 | private: |
2805 | ||
2806 | /* The type of filtering in place. */ | |
2807 | match_on m_match_type; | |
2808 | ||
2809 | /* Points to the original regexp used to create this filter. */ | |
2810 | const char *m_regexp; | |
2811 | ||
2812 | /* A compiled version of M_REGEXP. This object is only given a value if | |
2813 | M_REGEXP is not nullptr and is not the empty string. */ | |
2814 | gdb::optional<compiled_regex> m_c_regexp; | |
2815 | }; | |
2816 | ||
2817 | /* Perform the core of the 'info sources' command. | |
2818 | ||
2819 | FILTER is used to perform regular expression based filtering on the | |
2820 | source files that will be displayed. | |
2821 | ||
2822 | Output is written to UIOUT in CLI or MI style as appropriate. */ | |
2823 | ||
2824 | extern void info_sources_worker (struct ui_out *uiout, | |
1fb1ce02 | 2825 | bool group_by_objfile, |
0e350a05 AB |
2826 | const info_sources_filter &filter); |
2827 | ||
c906108c | 2828 | #endif /* !defined(SYMTAB_H) */ |