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