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