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