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