symtab.h revision 1.7 1 1.1 christos /* Symbol table definitions for GDB.
2 1.1 christos
3 1.7 christos Copyright (C) 1986-2017 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.7 christos #include <vector>
24 1.1 christos #include "gdb_vecs.h"
25 1.1 christos #include "gdbtypes.h"
26 1.6 christos #include "common/enum-flags.h"
27 1.7 christos #include "common/function-view.h"
28 1.1 christos
29 1.1 christos /* Opaque declarations. */
30 1.1 christos struct ui_file;
31 1.1 christos struct frame_info;
32 1.1 christos struct symbol;
33 1.1 christos struct obstack;
34 1.1 christos struct objfile;
35 1.1 christos struct block;
36 1.1 christos struct blockvector;
37 1.1 christos struct axs_value;
38 1.1 christos struct agent_expr;
39 1.1 christos struct program_space;
40 1.1 christos struct language_defn;
41 1.1 christos struct probe;
42 1.1 christos struct common_block;
43 1.6 christos struct obj_section;
44 1.6 christos struct cmd_list_element;
45 1.1 christos
46 1.1 christos /* Some of the structures in this file are space critical.
47 1.1 christos The space-critical structures are:
48 1.1 christos
49 1.1 christos struct general_symbol_info
50 1.1 christos struct symbol
51 1.1 christos struct partial_symbol
52 1.1 christos
53 1.1 christos These structures are laid out to encourage good packing.
54 1.1 christos They use ENUM_BITFIELD and short int fields, and they order the
55 1.1 christos structure members so that fields less than a word are next
56 1.1 christos to each other so they can be packed together. */
57 1.1 christos
58 1.1 christos /* Rearranged: used ENUM_BITFIELD and rearranged field order in
59 1.1 christos all the space critical structures (plus struct minimal_symbol).
60 1.1 christos Memory usage dropped from 99360768 bytes to 90001408 bytes.
61 1.1 christos I measured this with before-and-after tests of
62 1.1 christos "HEAD-old-gdb -readnow HEAD-old-gdb" and
63 1.1 christos "HEAD-new-gdb -readnow HEAD-old-gdb" on native i686-pc-linux-gnu,
64 1.1 christos red hat linux 8, with LD_LIBRARY_PATH=/usr/lib/debug,
65 1.1 christos typing "maint space 1" at the first command prompt.
66 1.1 christos
67 1.1 christos Here is another measurement (from andrew c):
68 1.1 christos # no /usr/lib/debug, just plain glibc, like a normal user
69 1.1 christos gdb HEAD-old-gdb
70 1.1 christos (gdb) break internal_error
71 1.1 christos (gdb) run
72 1.1 christos (gdb) maint internal-error
73 1.1 christos (gdb) backtrace
74 1.1 christos (gdb) maint space 1
75 1.1 christos
76 1.1 christos gdb gdb_6_0_branch 2003-08-19 space used: 8896512
77 1.1 christos gdb HEAD 2003-08-19 space used: 8904704
78 1.1 christos gdb HEAD 2003-08-21 space used: 8396800 (+symtab.h)
79 1.1 christos gdb HEAD 2003-08-21 space used: 8265728 (+gdbtypes.h)
80 1.1 christos
81 1.1 christos The third line shows the savings from the optimizations in symtab.h.
82 1.1 christos The fourth line shows the savings from the optimizations in
83 1.1 christos gdbtypes.h. Both optimizations are in gdb HEAD now.
84 1.1 christos
85 1.1 christos --chastain 2003-08-21 */
86 1.1 christos
87 1.1 christos /* Define a structure for the information that is common to all symbol types,
88 1.1 christos including minimal symbols, partial symbols, and full symbols. In a
89 1.1 christos multilanguage environment, some language specific information may need to
90 1.1 christos be recorded along with each symbol. */
91 1.1 christos
92 1.1 christos /* This structure is space critical. See space comments at the top. */
93 1.1 christos
94 1.1 christos struct general_symbol_info
95 1.1 christos {
96 1.1 christos /* Name of the symbol. This is a required field. Storage for the
97 1.1 christos name is allocated on the objfile_obstack for the associated
98 1.1 christos objfile. For languages like C++ that make a distinction between
99 1.1 christos the mangled name and demangled name, this is the mangled
100 1.1 christos name. */
101 1.1 christos
102 1.1 christos const char *name;
103 1.1 christos
104 1.1 christos /* Value of the symbol. Which member of this union to use, and what
105 1.1 christos it means, depends on what kind of symbol this is and its
106 1.1 christos SYMBOL_CLASS. See comments there for more details. All of these
107 1.1 christos are in host byte order (though what they point to might be in
108 1.1 christos target byte order, e.g. LOC_CONST_BYTES). */
109 1.1 christos
110 1.1 christos union
111 1.1 christos {
112 1.1 christos LONGEST ivalue;
113 1.1 christos
114 1.3 christos const struct block *block;
115 1.1 christos
116 1.1 christos const gdb_byte *bytes;
117 1.1 christos
118 1.1 christos CORE_ADDR address;
119 1.1 christos
120 1.1 christos /* A common block. Used with LOC_COMMON_BLOCK. */
121 1.1 christos
122 1.3 christos const struct common_block *common_block;
123 1.1 christos
124 1.1 christos /* For opaque typedef struct chain. */
125 1.1 christos
126 1.1 christos struct symbol *chain;
127 1.1 christos }
128 1.1 christos value;
129 1.1 christos
130 1.1 christos /* Since one and only one language can apply, wrap the language specific
131 1.1 christos information inside a union. */
132 1.1 christos
133 1.1 christos union
134 1.1 christos {
135 1.1 christos /* A pointer to an obstack that can be used for storage associated
136 1.1 christos with this symbol. This is only used by Ada, and only when the
137 1.1 christos 'ada_mangled' field is zero. */
138 1.1 christos struct obstack *obstack;
139 1.1 christos
140 1.1 christos /* This is used by languages which wish to store a demangled name.
141 1.7 christos currently used by Ada, C++, and Objective C. */
142 1.6 christos const char *demangled_name;
143 1.1 christos }
144 1.1 christos language_specific;
145 1.1 christos
146 1.1 christos /* Record the source code language that applies to this symbol.
147 1.1 christos This is used to select one of the fields from the language specific
148 1.1 christos union above. */
149 1.1 christos
150 1.6 christos ENUM_BITFIELD(language) language : LANGUAGE_BITS;
151 1.1 christos
152 1.6 christos /* This is only used by Ada. If set, then the 'demangled_name' field
153 1.1 christos of language_specific is valid. Otherwise, the 'obstack' field is
154 1.1 christos valid. */
155 1.1 christos unsigned int ada_mangled : 1;
156 1.1 christos
157 1.1 christos /* Which section is this symbol in? This is an index into
158 1.1 christos section_offsets for this objfile. Negative means that the symbol
159 1.1 christos does not get relocated relative to a section. */
160 1.1 christos
161 1.1 christos short section;
162 1.1 christos };
163 1.1 christos
164 1.1 christos extern void symbol_set_demangled_name (struct general_symbol_info *,
165 1.1 christos const char *,
166 1.1 christos struct obstack *);
167 1.1 christos
168 1.1 christos extern const char *symbol_get_demangled_name
169 1.1 christos (const struct general_symbol_info *);
170 1.1 christos
171 1.1 christos extern CORE_ADDR symbol_overlayed_address (CORE_ADDR, struct obj_section *);
172 1.1 christos
173 1.1 christos /* Note that all the following SYMBOL_* macros are used with the
174 1.3 christos SYMBOL argument being either a partial symbol or
175 1.3 christos a full symbol. Both types have a ginfo field. In particular
176 1.1 christos the SYMBOL_SET_LANGUAGE, SYMBOL_DEMANGLED_NAME, etc.
177 1.1 christos macros cannot be entirely substituted by
178 1.1 christos functions, unless the callers are changed to pass in the ginfo
179 1.1 christos field only, instead of the SYMBOL parameter. */
180 1.1 christos
181 1.1 christos #define SYMBOL_VALUE(symbol) (symbol)->ginfo.value.ivalue
182 1.1 christos #define SYMBOL_VALUE_ADDRESS(symbol) (symbol)->ginfo.value.address
183 1.1 christos #define SYMBOL_VALUE_BYTES(symbol) (symbol)->ginfo.value.bytes
184 1.1 christos #define SYMBOL_VALUE_COMMON_BLOCK(symbol) (symbol)->ginfo.value.common_block
185 1.1 christos #define SYMBOL_BLOCK_VALUE(symbol) (symbol)->ginfo.value.block
186 1.1 christos #define SYMBOL_VALUE_CHAIN(symbol) (symbol)->ginfo.value.chain
187 1.1 christos #define SYMBOL_LANGUAGE(symbol) (symbol)->ginfo.language
188 1.1 christos #define SYMBOL_SECTION(symbol) (symbol)->ginfo.section
189 1.1 christos #define SYMBOL_OBJ_SECTION(objfile, symbol) \
190 1.1 christos (((symbol)->ginfo.section >= 0) \
191 1.1 christos ? (&(((objfile)->sections)[(symbol)->ginfo.section])) \
192 1.1 christos : NULL)
193 1.1 christos
194 1.1 christos /* Initializes the language dependent portion of a symbol
195 1.1 christos depending upon the language for the symbol. */
196 1.1 christos #define SYMBOL_SET_LANGUAGE(symbol,language,obstack) \
197 1.1 christos (symbol_set_language (&(symbol)->ginfo, (language), (obstack)))
198 1.1 christos extern void symbol_set_language (struct general_symbol_info *symbol,
199 1.1 christos enum language language,
200 1.1 christos struct obstack *obstack);
201 1.1 christos
202 1.1 christos /* Set just the linkage name of a symbol; do not try to demangle
203 1.1 christos it. Used for constructs which do not have a mangled name,
204 1.1 christos e.g. struct tags. Unlike SYMBOL_SET_NAMES, linkage_name must
205 1.1 christos be terminated and either already on the objfile's obstack or
206 1.1 christos permanently allocated. */
207 1.1 christos #define SYMBOL_SET_LINKAGE_NAME(symbol,linkage_name) \
208 1.1 christos (symbol)->ginfo.name = (linkage_name)
209 1.1 christos
210 1.1 christos /* Set the linkage and natural names of a symbol, by demangling
211 1.1 christos the linkage name. */
212 1.1 christos #define SYMBOL_SET_NAMES(symbol,linkage_name,len,copy_name,objfile) \
213 1.1 christos symbol_set_names (&(symbol)->ginfo, linkage_name, len, copy_name, objfile)
214 1.1 christos extern void symbol_set_names (struct general_symbol_info *symbol,
215 1.1 christos const char *linkage_name, int len, int copy_name,
216 1.1 christos struct objfile *objfile);
217 1.1 christos
218 1.1 christos /* Now come lots of name accessor macros. Short version as to when to
219 1.1 christos use which: Use SYMBOL_NATURAL_NAME to refer to the name of the
220 1.1 christos symbol in the original source code. Use SYMBOL_LINKAGE_NAME if you
221 1.1 christos want to know what the linker thinks the symbol's name is. Use
222 1.1 christos SYMBOL_PRINT_NAME for output. Use SYMBOL_DEMANGLED_NAME if you
223 1.1 christos specifically need to know whether SYMBOL_NATURAL_NAME and
224 1.1 christos SYMBOL_LINKAGE_NAME are different. */
225 1.1 christos
226 1.1 christos /* Return SYMBOL's "natural" name, i.e. the name that it was called in
227 1.1 christos the original source code. In languages like C++ where symbols may
228 1.1 christos be mangled for ease of manipulation by the linker, this is the
229 1.1 christos demangled name. */
230 1.1 christos
231 1.1 christos #define SYMBOL_NATURAL_NAME(symbol) \
232 1.1 christos (symbol_natural_name (&(symbol)->ginfo))
233 1.1 christos extern const char *symbol_natural_name
234 1.1 christos (const struct general_symbol_info *symbol);
235 1.1 christos
236 1.1 christos /* Return SYMBOL's name from the point of view of the linker. In
237 1.1 christos languages like C++ where symbols may be mangled for ease of
238 1.1 christos manipulation by the linker, this is the mangled name; otherwise,
239 1.1 christos it's the same as SYMBOL_NATURAL_NAME. */
240 1.1 christos
241 1.1 christos #define SYMBOL_LINKAGE_NAME(symbol) (symbol)->ginfo.name
242 1.1 christos
243 1.1 christos /* Return the demangled name for a symbol based on the language for
244 1.1 christos that symbol. If no demangled name exists, return NULL. */
245 1.1 christos #define SYMBOL_DEMANGLED_NAME(symbol) \
246 1.1 christos (symbol_demangled_name (&(symbol)->ginfo))
247 1.1 christos extern const char *symbol_demangled_name
248 1.1 christos (const struct general_symbol_info *symbol);
249 1.1 christos
250 1.1 christos /* Macro that returns a version of the name of a symbol that is
251 1.1 christos suitable for output. In C++ this is the "demangled" form of the
252 1.1 christos name if demangle is on and the "mangled" form of the name if
253 1.1 christos demangle is off. In other languages this is just the symbol name.
254 1.1 christos The result should never be NULL. Don't use this for internal
255 1.1 christos purposes (e.g. storing in a hashtable): it's only suitable for output.
256 1.1 christos
257 1.1 christos N.B. symbol may be anything with a ginfo member,
258 1.1 christos e.g., struct symbol or struct minimal_symbol. */
259 1.1 christos
260 1.1 christos #define SYMBOL_PRINT_NAME(symbol) \
261 1.1 christos (demangle ? SYMBOL_NATURAL_NAME (symbol) : SYMBOL_LINKAGE_NAME (symbol))
262 1.1 christos extern int demangle;
263 1.1 christos
264 1.1 christos /* Macro that returns the name to be used when sorting and searching symbols.
265 1.7 christos In C++, we search for the demangled form of a name,
266 1.1 christos and so sort symbols accordingly. In Ada, however, we search by mangled
267 1.1 christos name. If there is no distinct demangled name, then SYMBOL_SEARCH_NAME
268 1.1 christos returns the same value (same pointer) as SYMBOL_LINKAGE_NAME. */
269 1.1 christos #define SYMBOL_SEARCH_NAME(symbol) \
270 1.1 christos (symbol_search_name (&(symbol)->ginfo))
271 1.1 christos extern const char *symbol_search_name (const struct general_symbol_info *);
272 1.1 christos
273 1.1 christos /* Return non-zero if NAME matches the "search" name of SYMBOL.
274 1.1 christos Whitespace and trailing parentheses are ignored.
275 1.1 christos See strcmp_iw for details about its behavior. */
276 1.1 christos #define SYMBOL_MATCHES_SEARCH_NAME(symbol, name) \
277 1.1 christos (strcmp_iw (SYMBOL_SEARCH_NAME (symbol), (name)) == 0)
278 1.1 christos
279 1.1 christos /* Classification types for a minimal symbol. These should be taken as
280 1.1 christos "advisory only", since if gdb can't easily figure out a
281 1.1 christos classification it simply selects mst_unknown. It may also have to
282 1.1 christos guess when it can't figure out which is a better match between two
283 1.1 christos types (mst_data versus mst_bss) for example. Since the minimal
284 1.1 christos symbol info is sometimes derived from the BFD library's view of a
285 1.1 christos file, we need to live with what information bfd supplies. */
286 1.1 christos
287 1.1 christos enum minimal_symbol_type
288 1.1 christos {
289 1.1 christos mst_unknown = 0, /* Unknown type, the default */
290 1.1 christos mst_text, /* Generally executable instructions */
291 1.1 christos mst_text_gnu_ifunc, /* Executable code returning address
292 1.1 christos of executable code */
293 1.1 christos mst_slot_got_plt, /* GOT entries for .plt sections */
294 1.1 christos mst_data, /* Generally initialized data */
295 1.1 christos mst_bss, /* Generally uninitialized data */
296 1.1 christos mst_abs, /* Generally absolute (nonrelocatable) */
297 1.1 christos /* GDB uses mst_solib_trampoline for the start address of a shared
298 1.1 christos library trampoline entry. Breakpoints for shared library functions
299 1.1 christos are put there if the shared library is not yet loaded.
300 1.1 christos After the shared library is loaded, lookup_minimal_symbol will
301 1.1 christos prefer the minimal symbol from the shared library (usually
302 1.1 christos a mst_text symbol) over the mst_solib_trampoline symbol, and the
303 1.1 christos breakpoints will be moved to their true address in the shared
304 1.1 christos library via breakpoint_re_set. */
305 1.1 christos mst_solib_trampoline, /* Shared library trampoline code */
306 1.1 christos /* For the mst_file* types, the names are only guaranteed to be unique
307 1.1 christos within a given .o file. */
308 1.1 christos mst_file_text, /* Static version of mst_text */
309 1.1 christos mst_file_data, /* Static version of mst_data */
310 1.6 christos mst_file_bss, /* Static version of mst_bss */
311 1.6 christos nr_minsym_types
312 1.1 christos };
313 1.1 christos
314 1.6 christos /* The number of enum minimal_symbol_type values, with some padding for
315 1.6 christos reasonable growth. */
316 1.6 christos #define MINSYM_TYPE_BITS 4
317 1.6 christos gdb_static_assert (nr_minsym_types <= (1 << MINSYM_TYPE_BITS));
318 1.6 christos
319 1.1 christos /* Define a simple structure used to hold some very basic information about
320 1.1 christos all defined global symbols (text, data, bss, abs, etc). The only required
321 1.1 christos information is the general_symbol_info.
322 1.1 christos
323 1.1 christos In many cases, even if a file was compiled with no special options for
324 1.1 christos debugging at all, as long as was not stripped it will contain sufficient
325 1.1 christos information to build a useful minimal symbol table using this structure.
326 1.1 christos Even when a file contains enough debugging information to build a full
327 1.1 christos symbol table, these minimal symbols are still useful for quickly mapping
328 1.1 christos between names and addresses, and vice versa. They are also sometimes
329 1.1 christos used to figure out what full symbol table entries need to be read in. */
330 1.1 christos
331 1.1 christos struct minimal_symbol
332 1.1 christos {
333 1.1 christos
334 1.1 christos /* The general symbol info required for all types of symbols.
335 1.1 christos
336 1.1 christos The SYMBOL_VALUE_ADDRESS contains the address that this symbol
337 1.1 christos corresponds to. */
338 1.1 christos
339 1.3 christos struct general_symbol_info mginfo;
340 1.1 christos
341 1.6 christos /* Size of this symbol. dbx_end_psymtab in dbxread.c uses this
342 1.1 christos information to calculate the end of the partial symtab based on the
343 1.1 christos address of the last symbol plus the size of the last symbol. */
344 1.1 christos
345 1.1 christos unsigned long size;
346 1.1 christos
347 1.1 christos /* Which source file is this symbol in? Only relevant for mst_file_*. */
348 1.1 christos const char *filename;
349 1.1 christos
350 1.1 christos /* Classification type for this minimal symbol. */
351 1.1 christos
352 1.6 christos ENUM_BITFIELD(minimal_symbol_type) type : MINSYM_TYPE_BITS;
353 1.1 christos
354 1.1 christos /* Non-zero if this symbol was created by gdb.
355 1.1 christos Such symbols do not appear in the output of "info var|fun". */
356 1.1 christos unsigned int created_by_gdb : 1;
357 1.1 christos
358 1.1 christos /* Two flag bits provided for the use of the target. */
359 1.1 christos unsigned int target_flag_1 : 1;
360 1.1 christos unsigned int target_flag_2 : 1;
361 1.1 christos
362 1.1 christos /* Nonzero iff the size of the minimal symbol has been set.
363 1.1 christos Symbol size information can sometimes not be determined, because
364 1.1 christos the object file format may not carry that piece of information. */
365 1.1 christos unsigned int has_size : 1;
366 1.1 christos
367 1.1 christos /* Minimal symbols with the same hash key are kept on a linked
368 1.1 christos list. This is the link. */
369 1.1 christos
370 1.1 christos struct minimal_symbol *hash_next;
371 1.1 christos
372 1.1 christos /* Minimal symbols are stored in two different hash tables. This is
373 1.1 christos the `next' pointer for the demangled hash table. */
374 1.1 christos
375 1.1 christos struct minimal_symbol *demangled_hash_next;
376 1.1 christos };
377 1.1 christos
378 1.1 christos #define MSYMBOL_TARGET_FLAG_1(msymbol) (msymbol)->target_flag_1
379 1.1 christos #define MSYMBOL_TARGET_FLAG_2(msymbol) (msymbol)->target_flag_2
380 1.1 christos #define MSYMBOL_SIZE(msymbol) ((msymbol)->size + 0)
381 1.1 christos #define SET_MSYMBOL_SIZE(msymbol, sz) \
382 1.1 christos do \
383 1.1 christos { \
384 1.1 christos (msymbol)->size = sz; \
385 1.1 christos (msymbol)->has_size = 1; \
386 1.1 christos } while (0)
387 1.1 christos #define MSYMBOL_HAS_SIZE(msymbol) ((msymbol)->has_size + 0)
388 1.1 christos #define MSYMBOL_TYPE(msymbol) (msymbol)->type
389 1.1 christos
390 1.3 christos #define MSYMBOL_VALUE(symbol) (symbol)->mginfo.value.ivalue
391 1.3 christos /* The unrelocated address of the minimal symbol. */
392 1.3 christos #define MSYMBOL_VALUE_RAW_ADDRESS(symbol) ((symbol)->mginfo.value.address + 0)
393 1.3 christos /* The relocated address of the minimal symbol, using the section
394 1.3 christos offsets from OBJFILE. */
395 1.3 christos #define MSYMBOL_VALUE_ADDRESS(objfile, symbol) \
396 1.3 christos ((symbol)->mginfo.value.address \
397 1.3 christos + ANOFFSET ((objfile)->section_offsets, ((symbol)->mginfo.section)))
398 1.3 christos /* For a bound minsym, we can easily compute the address directly. */
399 1.3 christos #define BMSYMBOL_VALUE_ADDRESS(symbol) \
400 1.3 christos MSYMBOL_VALUE_ADDRESS ((symbol).objfile, (symbol).minsym)
401 1.3 christos #define SET_MSYMBOL_VALUE_ADDRESS(symbol, new_value) \
402 1.3 christos ((symbol)->mginfo.value.address = (new_value))
403 1.3 christos #define MSYMBOL_VALUE_BYTES(symbol) (symbol)->mginfo.value.bytes
404 1.3 christos #define MSYMBOL_BLOCK_VALUE(symbol) (symbol)->mginfo.value.block
405 1.3 christos #define MSYMBOL_VALUE_CHAIN(symbol) (symbol)->mginfo.value.chain
406 1.3 christos #define MSYMBOL_LANGUAGE(symbol) (symbol)->mginfo.language
407 1.3 christos #define MSYMBOL_SECTION(symbol) (symbol)->mginfo.section
408 1.3 christos #define MSYMBOL_OBJ_SECTION(objfile, symbol) \
409 1.3 christos (((symbol)->mginfo.section >= 0) \
410 1.3 christos ? (&(((objfile)->sections)[(symbol)->mginfo.section])) \
411 1.3 christos : NULL)
412 1.3 christos
413 1.3 christos #define MSYMBOL_NATURAL_NAME(symbol) \
414 1.3 christos (symbol_natural_name (&(symbol)->mginfo))
415 1.3 christos #define MSYMBOL_LINKAGE_NAME(symbol) (symbol)->mginfo.name
416 1.3 christos #define MSYMBOL_PRINT_NAME(symbol) \
417 1.3 christos (demangle ? MSYMBOL_NATURAL_NAME (symbol) : MSYMBOL_LINKAGE_NAME (symbol))
418 1.3 christos #define MSYMBOL_DEMANGLED_NAME(symbol) \
419 1.3 christos (symbol_demangled_name (&(symbol)->mginfo))
420 1.3 christos #define MSYMBOL_SET_LANGUAGE(symbol,language,obstack) \
421 1.3 christos (symbol_set_language (&(symbol)->mginfo, (language), (obstack)))
422 1.3 christos #define MSYMBOL_SEARCH_NAME(symbol) \
423 1.3 christos (symbol_search_name (&(symbol)->mginfo))
424 1.3 christos #define MSYMBOL_MATCHES_SEARCH_NAME(symbol, name) \
425 1.3 christos (strcmp_iw (MSYMBOL_SEARCH_NAME (symbol), (name)) == 0)
426 1.3 christos #define MSYMBOL_SET_NAMES(symbol,linkage_name,len,copy_name,objfile) \
427 1.3 christos symbol_set_names (&(symbol)->mginfo, linkage_name, len, copy_name, objfile)
428 1.3 christos
429 1.1 christos #include "minsyms.h"
430 1.1 christos
431 1.1 christos
432 1.1 christos
434 1.1 christos /* Represent one symbol name; a variable, constant, function or typedef. */
435 1.1 christos
436 1.1 christos /* Different name domains for symbols. Looking up a symbol specifies a
437 1.1 christos domain and ignores symbol definitions in other name domains. */
438 1.1 christos
439 1.1 christos typedef enum domain_enum_tag
440 1.1 christos {
441 1.1 christos /* UNDEF_DOMAIN is used when a domain has not been discovered or
442 1.1 christos none of the following apply. This usually indicates an error either
443 1.1 christos in the symbol information or in gdb's handling of symbols. */
444 1.1 christos
445 1.1 christos UNDEF_DOMAIN,
446 1.1 christos
447 1.1 christos /* VAR_DOMAIN is the usual domain. In C, this contains variables,
448 1.1 christos function names, typedef names and enum type values. */
449 1.1 christos
450 1.1 christos VAR_DOMAIN,
451 1.1 christos
452 1.1 christos /* STRUCT_DOMAIN is used in C to hold struct, union and enum type names.
453 1.1 christos Thus, if `struct foo' is used in a C program, it produces a symbol named
454 1.1 christos `foo' in the STRUCT_DOMAIN. */
455 1.1 christos
456 1.1 christos STRUCT_DOMAIN,
457 1.1 christos
458 1.1 christos /* MODULE_DOMAIN is used in Fortran to hold module type names. */
459 1.1 christos
460 1.1 christos MODULE_DOMAIN,
461 1.1 christos
462 1.1 christos /* LABEL_DOMAIN may be used for names of labels (for gotos). */
463 1.1 christos
464 1.1 christos LABEL_DOMAIN,
465 1.1 christos
466 1.1 christos /* Fortran common blocks. Their naming must be separate from VAR_DOMAIN.
467 1.6 christos They also always use LOC_COMMON_BLOCK. */
468 1.6 christos COMMON_BLOCK_DOMAIN,
469 1.6 christos
470 1.6 christos /* This must remain last. */
471 1.1 christos NR_DOMAINS
472 1.1 christos } domain_enum;
473 1.3 christos
474 1.3 christos /* The number of bits in a symbol used to represent the domain. */
475 1.6 christos
476 1.6 christos #define SYMBOL_DOMAIN_BITS 3
477 1.3 christos gdb_static_assert (NR_DOMAINS <= (1 << SYMBOL_DOMAIN_BITS));
478 1.1 christos
479 1.1 christos extern const char *domain_name (domain_enum);
480 1.1 christos
481 1.1 christos /* Searching domains, used for `search_symbols'. Element numbers are
482 1.1 christos hardcoded in GDB, check all enum uses before changing it. */
483 1.1 christos
484 1.1 christos enum search_domain
485 1.1 christos {
486 1.1 christos /* Everything in VAR_DOMAIN minus FUNCTIONS_DOMAIN and
487 1.1 christos TYPES_DOMAIN. */
488 1.1 christos VARIABLES_DOMAIN = 0,
489 1.1 christos
490 1.1 christos /* All functions -- for some reason not methods, though. */
491 1.1 christos FUNCTIONS_DOMAIN = 1,
492 1.1 christos
493 1.1 christos /* All defined types */
494 1.1 christos TYPES_DOMAIN = 2,
495 1.1 christos
496 1.1 christos /* Any type. */
497 1.1 christos ALL_DOMAIN = 3
498 1.1 christos };
499 1.1 christos
500 1.1 christos extern const char *search_domain_name (enum search_domain);
501 1.1 christos
502 1.1 christos /* An address-class says where to find the value of a symbol. */
503 1.1 christos
504 1.1 christos enum address_class
505 1.1 christos {
506 1.1 christos /* Not used; catches errors. */
507 1.1 christos
508 1.1 christos LOC_UNDEF,
509 1.1 christos
510 1.1 christos /* Value is constant int SYMBOL_VALUE, host byteorder. */
511 1.1 christos
512 1.1 christos LOC_CONST,
513 1.1 christos
514 1.1 christos /* Value is at fixed address SYMBOL_VALUE_ADDRESS. */
515 1.1 christos
516 1.1 christos LOC_STATIC,
517 1.1 christos
518 1.1 christos /* Value is in register. SYMBOL_VALUE is the register number
519 1.1 christos in the original debug format. SYMBOL_REGISTER_OPS holds a
520 1.1 christos function that can be called to transform this into the
521 1.1 christos actual register number this represents in a specific target
522 1.1 christos architecture (gdbarch).
523 1.1 christos
524 1.1 christos For some symbol formats (stabs, for some compilers at least),
525 1.1 christos the compiler generates two symbols, an argument and a register.
526 1.1 christos In some cases we combine them to a single LOC_REGISTER in symbol
527 1.1 christos reading, but currently not for all cases (e.g. it's passed on the
528 1.1 christos stack and then loaded into a register). */
529 1.1 christos
530 1.1 christos LOC_REGISTER,
531 1.1 christos
532 1.1 christos /* It's an argument; the value is at SYMBOL_VALUE offset in arglist. */
533 1.1 christos
534 1.1 christos LOC_ARG,
535 1.1 christos
536 1.1 christos /* Value address is at SYMBOL_VALUE offset in arglist. */
537 1.1 christos
538 1.1 christos LOC_REF_ARG,
539 1.1 christos
540 1.1 christos /* Value is in specified register. Just like LOC_REGISTER except the
541 1.1 christos register holds the address of the argument instead of the argument
542 1.1 christos itself. This is currently used for the passing of structs and unions
543 1.1 christos on sparc and hppa. It is also used for call by reference where the
544 1.1 christos address is in a register, at least by mipsread.c. */
545 1.1 christos
546 1.1 christos LOC_REGPARM_ADDR,
547 1.1 christos
548 1.1 christos /* Value is a local variable at SYMBOL_VALUE offset in stack frame. */
549 1.1 christos
550 1.1 christos LOC_LOCAL,
551 1.1 christos
552 1.1 christos /* Value not used; definition in SYMBOL_TYPE. Symbols in the domain
553 1.1 christos STRUCT_DOMAIN all have this class. */
554 1.1 christos
555 1.1 christos LOC_TYPEDEF,
556 1.1 christos
557 1.1 christos /* Value is address SYMBOL_VALUE_ADDRESS in the code. */
558 1.1 christos
559 1.1 christos LOC_LABEL,
560 1.1 christos
561 1.1 christos /* In a symbol table, value is SYMBOL_BLOCK_VALUE of a `struct block'.
562 1.1 christos In a partial symbol table, SYMBOL_VALUE_ADDRESS is the start address
563 1.1 christos of the block. Function names have this class. */
564 1.1 christos
565 1.1 christos LOC_BLOCK,
566 1.1 christos
567 1.1 christos /* Value is a constant byte-sequence pointed to by SYMBOL_VALUE_BYTES, in
568 1.1 christos target byte order. */
569 1.1 christos
570 1.1 christos LOC_CONST_BYTES,
571 1.1 christos
572 1.1 christos /* Value is at fixed address, but the address of the variable has
573 1.1 christos to be determined from the minimal symbol table whenever the
574 1.1 christos variable is referenced.
575 1.1 christos This happens if debugging information for a global symbol is
576 1.1 christos emitted and the corresponding minimal symbol is defined
577 1.1 christos in another object file or runtime common storage.
578 1.1 christos The linker might even remove the minimal symbol if the global
579 1.1 christos symbol is never referenced, in which case the symbol remains
580 1.1 christos unresolved.
581 1.1 christos
582 1.1 christos GDB would normally find the symbol in the minimal symbol table if it will
583 1.1 christos not find it in the full symbol table. But a reference to an external
584 1.1 christos symbol in a local block shadowing other definition requires full symbol
585 1.6 christos without possibly having its address available for LOC_STATIC. Testcase
586 1.6 christos is provided as `gdb.dwarf2/dw2-unresolved.exp'.
587 1.6 christos
588 1.6 christos This is also used for thread local storage (TLS) variables. In this case,
589 1.6 christos the address of the TLS variable must be determined when the variable is
590 1.6 christos referenced, from the MSYMBOL_VALUE_RAW_ADDRESS, which is the offset
591 1.6 christos of the TLS variable in the thread local storage of the shared
592 1.1 christos library/object. */
593 1.1 christos
594 1.1 christos LOC_UNRESOLVED,
595 1.1 christos
596 1.1 christos /* The variable does not actually exist in the program.
597 1.1 christos The value is ignored. */
598 1.1 christos
599 1.1 christos LOC_OPTIMIZED_OUT,
600 1.1 christos
601 1.1 christos /* The variable's address is computed by a set of location
602 1.1 christos functions (see "struct symbol_computed_ops" below). */
603 1.1 christos LOC_COMPUTED,
604 1.1 christos
605 1.1 christos /* The variable uses general_symbol_info->value->common_block field.
606 1.1 christos It also always uses COMMON_BLOCK_DOMAIN. */
607 1.1 christos LOC_COMMON_BLOCK,
608 1.1 christos
609 1.1 christos /* Not used, just notes the boundary of the enum. */
610 1.1 christos LOC_FINAL_VALUE
611 1.1 christos };
612 1.6 christos
613 1.6 christos /* The number of bits needed for values in enum address_class, with some
614 1.6 christos padding for reasonable growth, and room for run-time registered address
615 1.6 christos classes. See symtab.c:MAX_SYMBOL_IMPLS.
616 1.6 christos This is a #define so that we can have a assertion elsewhere to
617 1.6 christos verify that we have reserved enough space for synthetic address
618 1.6 christos classes. */
619 1.6 christos #define SYMBOL_ACLASS_BITS 5
620 1.6 christos gdb_static_assert (LOC_FINAL_VALUE <= (1 << SYMBOL_ACLASS_BITS));
621 1.1 christos
622 1.1 christos /* The methods needed to implement LOC_COMPUTED. These methods can
623 1.1 christos use the symbol's .aux_value for additional per-symbol information.
624 1.1 christos
625 1.1 christos At present this is only used to implement location expressions. */
626 1.1 christos
627 1.1 christos struct symbol_computed_ops
628 1.1 christos {
629 1.1 christos
630 1.1 christos /* Return the value of the variable SYMBOL, relative to the stack
631 1.1 christos frame FRAME. If the variable has been optimized out, return
632 1.1 christos zero.
633 1.6 christos
634 1.6 christos Iff `read_needs_frame (SYMBOL)' is not SYMBOL_NEEDS_FRAME, then
635 1.1 christos FRAME may be zero. */
636 1.1 christos
637 1.1 christos struct value *(*read_variable) (struct symbol * symbol,
638 1.1 christos struct frame_info * frame);
639 1.1 christos
640 1.1 christos /* Read variable SYMBOL like read_variable at (callee) FRAME's function
641 1.1 christos entry. SYMBOL should be a function parameter, otherwise
642 1.1 christos NO_ENTRY_VALUE_ERROR will be thrown. */
643 1.1 christos struct value *(*read_variable_at_entry) (struct symbol *symbol,
644 1.1 christos struct frame_info *frame);
645 1.6 christos
646 1.6 christos /* Find the "symbol_needs_kind" value for the given symbol. This
647 1.6 christos value determines whether reading the symbol needs memory (e.g., a
648 1.6 christos global variable), just registers (a thread-local), or a frame (a
649 1.6 christos local variable). */
650 1.1 christos enum symbol_needs_kind (*get_symbol_read_needs) (struct symbol * symbol);
651 1.1 christos
652 1.1 christos /* Write to STREAM a natural-language description of the location of
653 1.1 christos SYMBOL, in the context of ADDR. */
654 1.1 christos void (*describe_location) (struct symbol * symbol, CORE_ADDR addr,
655 1.1 christos struct ui_file * stream);
656 1.1 christos
657 1.1 christos /* Non-zero if this symbol's address computation is dependent on PC. */
658 1.1 christos unsigned char location_has_loclist;
659 1.1 christos
660 1.1 christos /* Tracepoint support. Append bytecodes to the tracepoint agent
661 1.1 christos expression AX that push the address of the object SYMBOL. Set
662 1.1 christos VALUE appropriately. Note --- for objects in registers, this
663 1.1 christos needn't emit any code; as long as it sets VALUE properly, then
664 1.1 christos the caller will generate the right code in the process of
665 1.1 christos treating this as an lvalue or rvalue. */
666 1.1 christos
667 1.1 christos void (*tracepoint_var_ref) (struct symbol *symbol, struct gdbarch *gdbarch,
668 1.3 christos struct agent_expr *ax, struct axs_value *value);
669 1.3 christos
670 1.3 christos /* Generate C code to compute the location of SYMBOL. The C code is
671 1.3 christos emitted to STREAM. GDBARCH is the current architecture and PC is
672 1.3 christos the PC at which SYMBOL's location should be evaluated.
673 1.3 christos REGISTERS_USED is a vector indexed by register number; the
674 1.3 christos generator function should set an element in this vector if the
675 1.3 christos corresponding register is needed by the location computation.
676 1.3 christos The generated C code must assign the location to a local
677 1.3 christos variable; this variable's name is RESULT_NAME. */
678 1.7 christos
679 1.3 christos void (*generate_c_location) (struct symbol *symbol, string_file &stream,
680 1.3 christos struct gdbarch *gdbarch,
681 1.3 christos unsigned char *registers_used,
682 1.3 christos CORE_ADDR pc, const char *result_name);
683 1.1 christos
684 1.1 christos };
685 1.1 christos
686 1.1 christos /* The methods needed to implement LOC_BLOCK for inferior functions.
687 1.1 christos These methods can use the symbol's .aux_value for additional
688 1.1 christos per-symbol information. */
689 1.1 christos
690 1.1 christos struct symbol_block_ops
691 1.1 christos {
692 1.1 christos /* Fill in *START and *LENGTH with DWARF block data of function
693 1.1 christos FRAMEFUNC valid for inferior context address PC. Set *LENGTH to
694 1.1 christos zero if such location is not valid for PC; *START is left
695 1.1 christos uninitialized in such case. */
696 1.1 christos void (*find_frame_base_location) (struct symbol *framefunc, CORE_ADDR pc,
697 1.6 christos const gdb_byte **start, size_t *length);
698 1.6 christos
699 1.6 christos /* Return the frame base address. FRAME is the frame for which we want to
700 1.6 christos compute the base address while FRAMEFUNC is the symbol for the
701 1.6 christos corresponding function. Return 0 on failure (FRAMEFUNC may not hold the
702 1.6 christos information we need).
703 1.6 christos
704 1.6 christos This method is designed to work with static links (nested functions
705 1.6 christos handling). Static links are function properties whose evaluation returns
706 1.6 christos the frame base address for the enclosing frame. However, there are
707 1.6 christos multiple definitions for "frame base": the content of the frame base
708 1.6 christos register, the CFA as defined by DWARF unwinding information, ...
709 1.6 christos
710 1.6 christos So this specific method is supposed to compute the frame base address such
711 1.6 christos as for nested fuctions, the static link computes the same address. For
712 1.6 christos instance, considering DWARF debugging information, the static link is
713 1.6 christos computed with DW_AT_static_link and this method must be used to compute
714 1.6 christos the corresponding DW_AT_frame_base attribute. */
715 1.6 christos CORE_ADDR (*get_frame_base) (struct symbol *framefunc,
716 1.1 christos struct frame_info *frame);
717 1.1 christos };
718 1.1 christos
719 1.1 christos /* Functions used with LOC_REGISTER and LOC_REGPARM_ADDR. */
720 1.1 christos
721 1.1 christos struct symbol_register_ops
722 1.1 christos {
723 1.1 christos int (*register_number) (struct symbol *symbol, struct gdbarch *gdbarch);
724 1.1 christos };
725 1.1 christos
726 1.1 christos /* Objects of this type are used to find the address class and the
727 1.1 christos various computed ops vectors of a symbol. */
728 1.1 christos
729 1.1 christos struct symbol_impl
730 1.1 christos {
731 1.1 christos enum address_class aclass;
732 1.1 christos
733 1.1 christos /* Used with LOC_COMPUTED. */
734 1.1 christos const struct symbol_computed_ops *ops_computed;
735 1.1 christos
736 1.1 christos /* Used with LOC_BLOCK. */
737 1.1 christos const struct symbol_block_ops *ops_block;
738 1.1 christos
739 1.1 christos /* Used with LOC_REGISTER and LOC_REGPARM_ADDR. */
740 1.1 christos const struct symbol_register_ops *ops_register;
741 1.1 christos };
742 1.1 christos
743 1.1 christos /* This structure is space critical. See space comments at the top. */
744 1.1 christos
745 1.1 christos struct symbol
746 1.1 christos {
747 1.1 christos
748 1.1 christos /* The general symbol info required for all types of symbols. */
749 1.1 christos
750 1.1 christos struct general_symbol_info ginfo;
751 1.1 christos
752 1.1 christos /* Data type of value */
753 1.1 christos
754 1.1 christos struct type *type;
755 1.3 christos
756 1.3 christos /* The owner of this symbol.
757 1.3 christos Which one to use is defined by symbol.is_objfile_owned. */
758 1.3 christos
759 1.3 christos union
760 1.3 christos {
761 1.3 christos /* The symbol table containing this symbol. This is the file associated
762 1.3 christos with LINE. It can be NULL during symbols read-in but it is never NULL
763 1.3 christos during normal operation. */
764 1.3 christos struct symtab *symtab;
765 1.3 christos
766 1.3 christos /* For types defined by the architecture. */
767 1.3 christos struct gdbarch *arch;
768 1.1 christos } owner;
769 1.1 christos
770 1.1 christos /* Domain code. */
771 1.3 christos
772 1.1 christos ENUM_BITFIELD(domain_enum_tag) domain : SYMBOL_DOMAIN_BITS;
773 1.1 christos
774 1.1 christos /* Address class. This holds an index into the 'symbol_impls'
775 1.1 christos table. The actual enum address_class value is stored there,
776 1.1 christos alongside any per-class ops vectors. */
777 1.1 christos
778 1.1 christos unsigned int aclass_index : SYMBOL_ACLASS_BITS;
779 1.3 christos
780 1.3 christos /* If non-zero then symbol is objfile-owned, use owner.symtab.
781 1.3 christos Otherwise symbol is arch-owned, use owner.arch. */
782 1.3 christos
783 1.3 christos unsigned int is_objfile_owned : 1;
784 1.1 christos
785 1.1 christos /* Whether this is an argument. */
786 1.1 christos
787 1.1 christos unsigned is_argument : 1;
788 1.1 christos
789 1.1 christos /* Whether this is an inlined function (class LOC_BLOCK only). */
790 1.1 christos unsigned is_inlined : 1;
791 1.1 christos
792 1.1 christos /* True if this is a C++ function symbol with template arguments.
793 1.1 christos In this case the symbol is really a "struct template_symbol". */
794 1.1 christos unsigned is_cplus_template_function : 1;
795 1.1 christos
796 1.1 christos /* Line number of this symbol's definition, except for inlined
797 1.1 christos functions. For an inlined function (class LOC_BLOCK and
798 1.1 christos SYMBOL_INLINED set) this is the line number of the function's call
799 1.1 christos site. Inlined function symbols are not definitions, and they are
800 1.3 christos never found by symbol table lookup.
801 1.1 christos If this symbol is arch-owned, LINE shall be zero.
802 1.1 christos
803 1.1 christos FIXME: Should we really make the assumption that nobody will try
804 1.1 christos to debug files longer than 64K lines? What about machine
805 1.1 christos generated programs? */
806 1.1 christos
807 1.1 christos unsigned short line;
808 1.1 christos
809 1.1 christos /* An arbitrary data pointer, allowing symbol readers to record
810 1.1 christos additional information on a per-symbol basis. Note that this data
811 1.6 christos must be allocated using the same obstack as the symbol itself. */
812 1.6 christos /* So far it is only used by:
813 1.6 christos LOC_COMPUTED: to find the location information
814 1.6 christos LOC_BLOCK (DWARF2 function): information used internally by the
815 1.1 christos DWARF 2 code --- specifically, the location expression for the frame
816 1.1 christos base for this function. */
817 1.1 christos /* FIXME drow/2003-02-21: For the LOC_BLOCK case, it might be better
818 1.1 christos to add a magic symbol to the block containing this information,
819 1.1 christos or to have a generic debug info annotation slot for symbols. */
820 1.1 christos
821 1.1 christos void *aux_value;
822 1.1 christos
823 1.1 christos struct symbol *hash_next;
824 1.1 christos };
825 1.6 christos
826 1.6 christos /* Several lookup functions return both a symbol and the block in which the
827 1.6 christos symbol is found. This structure is used in these cases. */
828 1.6 christos
829 1.6 christos struct block_symbol
830 1.6 christos {
831 1.6 christos /* The symbol that was found, or NULL if no symbol was found. */
832 1.6 christos struct symbol *symbol;
833 1.6 christos
834 1.6 christos /* If SYMBOL is not NULL, then this is the block in which the symbol is
835 1.6 christos defined. */
836 1.6 christos const struct block *block;
837 1.6 christos };
838 1.1 christos
839 1.1 christos extern const struct symbol_impl *symbol_impls;
840 1.6 christos
841 1.6 christos /* For convenience. All fields are NULL. This means "there is no
842 1.6 christos symbol". */
843 1.6 christos extern const struct block_symbol null_block_symbol;
844 1.3 christos
845 1.3 christos /* Note: There is no accessor macro for symbol.owner because it is
846 1.3 christos "private". */
847 1.1 christos
848 1.1 christos #define SYMBOL_DOMAIN(symbol) (symbol)->domain
849 1.1 christos #define SYMBOL_IMPL(symbol) (symbol_impls[(symbol)->aclass_index])
850 1.1 christos #define SYMBOL_ACLASS_INDEX(symbol) (symbol)->aclass_index
851 1.3 christos #define SYMBOL_CLASS(symbol) (SYMBOL_IMPL (symbol).aclass)
852 1.1 christos #define SYMBOL_OBJFILE_OWNED(symbol) ((symbol)->is_objfile_owned)
853 1.1 christos #define SYMBOL_IS_ARGUMENT(symbol) (symbol)->is_argument
854 1.1 christos #define SYMBOL_INLINED(symbol) (symbol)->is_inlined
855 1.1 christos #define SYMBOL_IS_CPLUS_TEMPLATE_FUNCTION(symbol) \
856 1.1 christos (symbol)->is_cplus_template_function
857 1.1 christos #define SYMBOL_TYPE(symbol) (symbol)->type
858 1.1 christos #define SYMBOL_LINE(symbol) (symbol)->line
859 1.1 christos #define SYMBOL_COMPUTED_OPS(symbol) (SYMBOL_IMPL (symbol).ops_computed)
860 1.1 christos #define SYMBOL_BLOCK_OPS(symbol) (SYMBOL_IMPL (symbol).ops_block)
861 1.1 christos #define SYMBOL_REGISTER_OPS(symbol) (SYMBOL_IMPL (symbol).ops_register)
862 1.1 christos #define SYMBOL_LOCATION_BATON(symbol) (symbol)->aux_value
863 1.1 christos
864 1.1 christos extern int register_symbol_computed_impl (enum address_class,
865 1.1 christos const struct symbol_computed_ops *);
866 1.1 christos
867 1.1 christos extern int register_symbol_block_impl (enum address_class aclass,
868 1.1 christos const struct symbol_block_ops *ops);
869 1.1 christos
870 1.1 christos extern int register_symbol_register_impl (enum address_class,
871 1.1 christos const struct symbol_register_ops *);
872 1.3 christos
873 1.3 christos /* Return the OBJFILE of SYMBOL.
874 1.3 christos It is an error to call this if symbol.is_objfile_owned is false, which
875 1.3 christos only happens for architecture-provided types. */
876 1.3 christos
877 1.3 christos extern struct objfile *symbol_objfile (const struct symbol *symbol);
878 1.3 christos
879 1.3 christos /* Return the ARCH of SYMBOL. */
880 1.3 christos
881 1.3 christos extern struct gdbarch *symbol_arch (const struct symbol *symbol);
882 1.3 christos
883 1.3 christos /* Return the SYMTAB of SYMBOL.
884 1.3 christos It is an error to call this if symbol.is_objfile_owned is false, which
885 1.3 christos only happens for architecture-provided types. */
886 1.3 christos
887 1.3 christos extern struct symtab *symbol_symtab (const struct symbol *symbol);
888 1.3 christos
889 1.3 christos /* Set the symtab of SYMBOL to SYMTAB.
890 1.3 christos It is an error to call this if symbol.is_objfile_owned is false, which
891 1.3 christos only happens for architecture-provided types. */
892 1.3 christos
893 1.3 christos extern void symbol_set_symtab (struct symbol *symbol, struct symtab *symtab);
894 1.1 christos
895 1.1 christos /* An instance of this type is used to represent a C++ template
896 1.1 christos function. It includes a "struct symbol" as a kind of base class;
897 1.1 christos users downcast to "struct template_symbol *" when needed. A symbol
898 1.1 christos is really of this type iff SYMBOL_IS_CPLUS_TEMPLATE_FUNCTION is
899 1.1 christos true. */
900 1.1 christos
901 1.1 christos struct template_symbol
902 1.1 christos {
903 1.1 christos /* The base class. */
904 1.1 christos struct symbol base;
905 1.1 christos
906 1.1 christos /* The number of template arguments. */
907 1.1 christos int n_template_arguments;
908 1.1 christos
909 1.1 christos /* The template arguments. This is an array with
910 1.1 christos N_TEMPLATE_ARGUMENTS elements. */
911 1.1 christos struct symbol **template_arguments;
912 1.1 christos };
913 1.1 christos
914 1.1 christos
915 1.1 christos /* Each item represents a line-->pc (or the reverse) mapping. This is
917 1.1 christos somewhat more wasteful of space than one might wish, but since only
918 1.1 christos the files which are actually debugged are read in to core, we don't
919 1.1 christos waste much space. */
920 1.1 christos
921 1.1 christos struct linetable_entry
922 1.1 christos {
923 1.1 christos int line;
924 1.1 christos CORE_ADDR pc;
925 1.1 christos };
926 1.1 christos
927 1.1 christos /* The order of entries in the linetable is significant. They should
928 1.1 christos be sorted by increasing values of the pc field. If there is more than
929 1.1 christos one entry for a given pc, then I'm not sure what should happen (and
930 1.1 christos I not sure whether we currently handle it the best way).
931 1.1 christos
932 1.1 christos Example: a C for statement generally looks like this
933 1.1 christos
934 1.1 christos 10 0x100 - for the init/test part of a for stmt.
935 1.1 christos 20 0x200
936 1.1 christos 30 0x300
937 1.1 christos 10 0x400 - for the increment part of a for stmt.
938 1.1 christos
939 1.1 christos If an entry has a line number of zero, it marks the start of a PC
940 1.1 christos range for which no line number information is available. It is
941 1.1 christos acceptable, though wasteful of table space, for such a range to be
942 1.1 christos zero length. */
943 1.1 christos
944 1.1 christos struct linetable
945 1.1 christos {
946 1.1 christos int nitems;
947 1.1 christos
948 1.1 christos /* Actually NITEMS elements. If you don't like this use of the
949 1.1 christos `struct hack', you can shove it up your ANSI (seriously, if the
950 1.1 christos committee tells us how to do it, we can probably go along). */
951 1.1 christos struct linetable_entry item[1];
952 1.1 christos };
953 1.1 christos
954 1.1 christos /* How to relocate the symbols from each section in a symbol file.
955 1.1 christos Each struct contains an array of offsets.
956 1.1 christos The ordering and meaning of the offsets is file-type-dependent;
957 1.1 christos typically it is indexed by section numbers or symbol types or
958 1.1 christos something like that.
959 1.1 christos
960 1.1 christos To give us flexibility in changing the internal representation
961 1.1 christos of these offsets, the ANOFFSET macro must be used to insert and
962 1.1 christos extract offset values in the struct. */
963 1.1 christos
964 1.1 christos struct section_offsets
965 1.1 christos {
966 1.1 christos CORE_ADDR offsets[1]; /* As many as needed. */
967 1.1 christos };
968 1.1 christos
969 1.1 christos #define ANOFFSET(secoff, whichone) \
970 1.1 christos ((whichone == -1) \
971 1.1 christos ? (internal_error (__FILE__, __LINE__, \
972 1.1 christos _("Section index is uninitialized")), -1) \
973 1.1 christos : secoff->offsets[whichone])
974 1.1 christos
975 1.1 christos /* The size of a section_offsets table for N sections. */
976 1.1 christos #define SIZEOF_N_SECTION_OFFSETS(n) \
977 1.1 christos (sizeof (struct section_offsets) \
978 1.1 christos + sizeof (((struct section_offsets *) 0)->offsets) * ((n)-1))
979 1.3 christos
980 1.1 christos /* Each source file or header is represented by a struct symtab.
981 1.1 christos The name "symtab" is historical, another name for it is "filetab".
982 1.1 christos These objects are chained through the `next' field. */
983 1.1 christos
984 1.5 christos struct symtab
985 1.5 christos {
986 1.1 christos /* Unordered chain of all filetabs in the compunit, with the exception
987 1.1 christos that the "main" source file is the first entry in the list. */
988 1.1 christos
989 1.3 christos struct symtab *next;
990 1.1 christos
991 1.3 christos /* Backlink to containing compunit symtab. */
992 1.1 christos
993 1.1 christos struct compunit_symtab *compunit_symtab;
994 1.1 christos
995 1.1 christos /* Table mapping core addresses to line numbers for this file.
996 1.1 christos Can be NULL if none. Never shared between different symtabs. */
997 1.1 christos
998 1.1 christos struct linetable *linetable;
999 1.1 christos
1000 1.1 christos /* Name of this source file. This pointer is never NULL. */
1001 1.1 christos
1002 1.1 christos const char *filename;
1003 1.1 christos
1004 1.1 christos /* Total number of lines found in source file. */
1005 1.1 christos
1006 1.1 christos int nlines;
1007 1.1 christos
1008 1.1 christos /* line_charpos[N] is the position of the (N-1)th line of the
1009 1.1 christos source file. "position" means something we can lseek() to; it
1010 1.1 christos is not guaranteed to be useful any other way. */
1011 1.1 christos
1012 1.1 christos int *line_charpos;
1013 1.1 christos
1014 1.1 christos /* Language of this source file. */
1015 1.1 christos
1016 1.3 christos enum language language;
1017 1.3 christos
1018 1.3 christos /* Full name of file as found by searching the source path.
1019 1.3 christos NULL if not yet known. */
1020 1.3 christos
1021 1.3 christos char *fullname;
1022 1.3 christos };
1023 1.3 christos
1024 1.3 christos #define SYMTAB_COMPUNIT(symtab) ((symtab)->compunit_symtab)
1025 1.3 christos #define SYMTAB_LINETABLE(symtab) ((symtab)->linetable)
1026 1.3 christos #define SYMTAB_LANGUAGE(symtab) ((symtab)->language)
1027 1.3 christos #define SYMTAB_BLOCKVECTOR(symtab) \
1028 1.3 christos COMPUNIT_BLOCKVECTOR (SYMTAB_COMPUNIT (symtab))
1029 1.3 christos #define SYMTAB_OBJFILE(symtab) \
1030 1.3 christos COMPUNIT_OBJFILE (SYMTAB_COMPUNIT (symtab))
1031 1.3 christos #define SYMTAB_PSPACE(symtab) (SYMTAB_OBJFILE (symtab)->pspace)
1032 1.3 christos #define SYMTAB_DIRNAME(symtab) \
1033 1.3 christos COMPUNIT_DIRNAME (SYMTAB_COMPUNIT (symtab))
1034 1.3 christos
1035 1.3 christos typedef struct symtab *symtab_ptr;
1036 1.3 christos DEF_VEC_P (symtab_ptr);
1037 1.3 christos
1038 1.3 christos /* Compunit symtabs contain the actual "symbol table", aka blockvector, as well
1039 1.3 christos as the list of all source files (what gdb has historically associated with
1040 1.3 christos the term "symtab").
1041 1.3 christos Additional information is recorded here that is common to all symtabs in a
1042 1.3 christos compilation unit (DWARF or otherwise).
1043 1.3 christos
1044 1.3 christos Example:
1045 1.3 christos For the case of a program built out of these files:
1046 1.3 christos
1047 1.3 christos foo.c
1048 1.3 christos foo1.h
1049 1.3 christos foo2.h
1050 1.3 christos bar.c
1051 1.3 christos foo1.h
1052 1.3 christos bar.h
1053 1.3 christos
1054 1.3 christos This is recorded as:
1055 1.3 christos
1056 1.3 christos objfile -> foo.c(cu) -> bar.c(cu) -> NULL
1057 1.3 christos | |
1058 1.3 christos v v
1059 1.3 christos foo.c bar.c
1060 1.3 christos | |
1061 1.3 christos v v
1062 1.3 christos foo1.h foo1.h
1063 1.3 christos | |
1064 1.3 christos v v
1065 1.3 christos foo2.h bar.h
1066 1.3 christos | |
1067 1.3 christos v v
1068 1.3 christos NULL NULL
1069 1.3 christos
1070 1.3 christos where "foo.c(cu)" and "bar.c(cu)" are struct compunit_symtab objects,
1071 1.3 christos and the files foo.c, etc. are struct symtab objects. */
1072 1.3 christos
1073 1.3 christos struct compunit_symtab
1074 1.3 christos {
1075 1.3 christos /* Unordered chain of all compunit symtabs of this objfile. */
1076 1.3 christos struct compunit_symtab *next;
1077 1.3 christos
1078 1.3 christos /* Object file from which this symtab information was read. */
1079 1.3 christos struct objfile *objfile;
1080 1.3 christos
1081 1.3 christos /* Name of the symtab.
1082 1.3 christos This is *not* intended to be a usable filename, and is
1083 1.3 christos for debugging purposes only. */
1084 1.3 christos const char *name;
1085 1.3 christos
1086 1.3 christos /* Unordered list of file symtabs, except that by convention the "main"
1087 1.3 christos source file (e.g., .c, .cc) is guaranteed to be first.
1088 1.3 christos Each symtab is a file, either the "main" source file (e.g., .c, .cc)
1089 1.3 christos or header (e.g., .h). */
1090 1.3 christos struct symtab *filetabs;
1091 1.3 christos
1092 1.3 christos /* Last entry in FILETABS list.
1093 1.3 christos Subfiles are added to the end of the list so they accumulate in order,
1094 1.3 christos with the main source subfile living at the front.
1095 1.3 christos The main reason is so that the main source file symtab is at the head
1096 1.3 christos of the list, and the rest appear in order for debugging convenience. */
1097 1.3 christos struct symtab *last_filetab;
1098 1.3 christos
1099 1.1 christos /* Non-NULL string that identifies the format of the debugging information,
1100 1.1 christos such as "stabs", "dwarf 1", "dwarf 2", "coff", etc. This is mostly useful
1101 1.1 christos for automated testing of gdb but may also be information that is
1102 1.1 christos useful to the user. */
1103 1.3 christos const char *debugformat;
1104 1.3 christos
1105 1.1 christos /* String of producer version information, or NULL if we don't know. */
1106 1.3 christos const char *producer;
1107 1.3 christos
1108 1.1 christos /* Directory in which it was compiled, or NULL if we don't know. */
1109 1.3 christos const char *dirname;
1110 1.3 christos
1111 1.3 christos /* List of all symbol scope blocks for this symtab. It is shared among
1112 1.1 christos all symtabs in a given compilation unit. */
1113 1.3 christos const struct blockvector *blockvector;
1114 1.3 christos
1115 1.3 christos /* Section in objfile->section_offsets for the blockvector and
1116 1.1 christos the linetable. Probably always SECT_OFF_TEXT. */
1117 1.3 christos int block_line_section;
1118 1.3 christos
1119 1.3 christos /* Symtab has been compiled with both optimizations and debug info so that
1120 1.3 christos GDB may stop skipping prologues as variables locations are valid already
1121 1.1 christos at function entry points. */
1122 1.3 christos unsigned int locations_valid : 1;
1123 1.3 christos
1124 1.3 christos /* DWARF unwinder for this CU is valid even for epilogues (PC at the return
1125 1.1 christos instruction). This is supported by GCC since 4.5.0. */
1126 1.1 christos unsigned int epilogue_unwind_valid : 1;
1127 1.3 christos
1128 1.1 christos /* struct call_site entries for this compilation unit or NULL. */
1129 1.3 christos htab_t call_site_htab;
1130 1.3 christos
1131 1.3 christos /* The macro table for this symtab. Like the blockvector, this
1132 1.3 christos is shared between different symtabs in a given compilation unit.
1133 1.3 christos It's debatable whether it *should* be shared among all the symtabs in
1134 1.1 christos the given compilation unit, but it currently is. */
1135 1.1 christos struct macro_table *macro_table;
1136 1.3 christos
1137 1.3 christos /* If non-NULL, then this points to a NULL-terminated vector of
1138 1.3 christos included compunits. When searching the static or global
1139 1.1 christos block of this compunit, the corresponding block of all
1140 1.1 christos included compunits will also be searched. Note that this
1141 1.3 christos list must be flattened -- the symbol reader is responsible for
1142 1.3 christos ensuring that this vector contains the transitive closure of all
1143 1.3 christos included compunits. */
1144 1.3 christos struct compunit_symtab **includes;
1145 1.3 christos
1146 1.3 christos /* If this is an included compunit, this points to one includer
1147 1.3 christos of the table. This user is considered the canonical compunit
1148 1.3 christos containing this one. An included compunit may itself be
1149 1.3 christos included by another. */
1150 1.1 christos struct compunit_symtab *user;
1151 1.3 christos };
1152 1.3 christos
1153 1.3 christos #define COMPUNIT_OBJFILE(cust) ((cust)->objfile)
1154 1.3 christos #define COMPUNIT_FILETABS(cust) ((cust)->filetabs)
1155 1.3 christos #define COMPUNIT_DEBUGFORMAT(cust) ((cust)->debugformat)
1156 1.3 christos #define COMPUNIT_PRODUCER(cust) ((cust)->producer)
1157 1.3 christos #define COMPUNIT_DIRNAME(cust) ((cust)->dirname)
1158 1.3 christos #define COMPUNIT_BLOCKVECTOR(cust) ((cust)->blockvector)
1159 1.3 christos #define COMPUNIT_BLOCK_LINE_SECTION(cust) ((cust)->block_line_section)
1160 1.3 christos #define COMPUNIT_LOCATIONS_VALID(cust) ((cust)->locations_valid)
1161 1.3 christos #define COMPUNIT_EPILOGUE_UNWIND_VALID(cust) ((cust)->epilogue_unwind_valid)
1162 1.1 christos #define COMPUNIT_CALL_SITE_HTAB(cust) ((cust)->call_site_htab)
1163 1.3 christos #define COMPUNIT_MACRO_TABLE(cust) ((cust)->macro_table)
1164 1.3 christos
1165 1.3 christos /* Iterate over all file tables (struct symtab) within a compunit. */
1166 1.3 christos
1167 1.3 christos #define ALL_COMPUNIT_FILETABS(cu, s) \
1168 1.3 christos for ((s) = (cu) -> filetabs; (s) != NULL; (s) = (s) -> next)
1169 1.1 christos
1170 1.3 christos /* Return the primary symtab of CUST. */
1171 1.3 christos
1172 1.1 christos extern struct symtab *
1173 1.3 christos compunit_primary_filetab (const struct compunit_symtab *cust);
1174 1.1 christos
1175 1.3 christos /* Return the language of CUST. */
1176 1.1 christos
1177 1.3 christos extern enum language compunit_language (const struct compunit_symtab *cust);
1178 1.3 christos
1179 1.1 christos typedef struct compunit_symtab *compunit_symtab_ptr;
1180 1.1 christos DEF_VEC_P (compunit_symtab_ptr);
1181 1.1 christos
1182 1.1 christos
1183 1.1 christos
1185 1.1 christos /* The virtual function table is now an array of structures which have the
1186 1.1 christos form { int16 offset, delta; void *pfn; }.
1187 1.1 christos
1188 1.1 christos In normal virtual function tables, OFFSET is unused.
1189 1.1 christos DELTA is the amount which is added to the apparent object's base
1190 1.1 christos address in order to point to the actual object to which the
1191 1.1 christos virtual function should be applied.
1192 1.1 christos PFN is a pointer to the virtual function.
1193 1.1 christos
1194 1.1 christos Note that this macro is g++ specific (FIXME). */
1195 1.1 christos
1196 1.1 christos #define VTBL_FNADDR_OFFSET 2
1197 1.1 christos
1198 1.1 christos /* External variables and functions for the objects described above. */
1199 1.1 christos
1200 1.1 christos /* True if we are nested inside psymtab_to_symtab. */
1201 1.1 christos
1202 1.1 christos extern int currently_reading_symtab;
1203 1.1 christos
1204 1.1 christos /* symtab.c lookup functions */
1205 1.1 christos
1206 1.1 christos extern const char multiple_symbols_ask[];
1207 1.1 christos extern const char multiple_symbols_all[];
1208 1.1 christos extern const char multiple_symbols_cancel[];
1209 1.1 christos
1210 1.1 christos const char *multiple_symbols_select_mode (void);
1211 1.1 christos
1212 1.1 christos int symbol_matches_domain (enum language symbol_language,
1213 1.1 christos domain_enum symbol_domain,
1214 1.1 christos domain_enum domain);
1215 1.1 christos
1216 1.1 christos /* lookup a symbol table by source file name. */
1217 1.1 christos
1218 1.1 christos extern struct symtab *lookup_symtab (const char *);
1219 1.1 christos
1220 1.1 christos /* An object of this type is passed as the 'is_a_field_of_this'
1221 1.1 christos argument to lookup_symbol and lookup_symbol_in_language. */
1222 1.1 christos
1223 1.1 christos struct field_of_this_result
1224 1.1 christos {
1225 1.1 christos /* The type in which the field was found. If this is NULL then the
1226 1.1 christos symbol was not found in 'this'. If non-NULL, then one of the
1227 1.1 christos other fields will be non-NULL as well. */
1228 1.1 christos
1229 1.1 christos struct type *type;
1230 1.1 christos
1231 1.1 christos /* If the symbol was found as an ordinary field of 'this', then this
1232 1.1 christos is non-NULL and points to the particular field. */
1233 1.3 christos
1234 1.1 christos struct field *field;
1235 1.1 christos
1236 1.1 christos /* If the symbol was found as a function field of 'this', then this
1237 1.1 christos is non-NULL and points to the particular field. */
1238 1.1 christos
1239 1.3 christos struct fn_fieldlist *fn_field;
1240 1.3 christos };
1241 1.3 christos
1242 1.3 christos /* Find the definition for a specified symbol name NAME
1243 1.3 christos in domain DOMAIN in language LANGUAGE, visible from lexical block BLOCK
1244 1.3 christos if non-NULL or from global/static blocks if BLOCK is NULL.
1245 1.3 christos Returns the struct symbol pointer, or NULL if no symbol is found.
1246 1.3 christos C++: if IS_A_FIELD_OF_THIS is non-NULL on entry, check to see if
1247 1.1 christos NAME is a field of the current implied argument `this'. If so fill in the
1248 1.6 christos fields of IS_A_FIELD_OF_THIS, otherwise the fields are set to NULL.
1249 1.6 christos The symbol's section is fixed up if necessary. */
1250 1.6 christos
1251 1.6 christos extern struct block_symbol
1252 1.6 christos lookup_symbol_in_language (const char *,
1253 1.6 christos const struct block *,
1254 1.1 christos const domain_enum,
1255 1.3 christos enum language,
1256 1.1 christos struct field_of_this_result *);
1257 1.6 christos
1258 1.6 christos /* Same as lookup_symbol_in_language, but using the current language. */
1259 1.6 christos
1260 1.6 christos extern struct block_symbol lookup_symbol (const char *,
1261 1.1 christos const struct block *,
1262 1.1 christos const domain_enum,
1263 1.3 christos struct field_of_this_result *);
1264 1.3 christos
1265 1.1 christos /* A default version of lookup_symbol_nonlocal for use by languages
1266 1.6 christos that can't think of anything better to do.
1267 1.3 christos This implements the C lookup rules. */
1268 1.3 christos
1269 1.3 christos extern struct block_symbol
1270 1.3 christos basic_lookup_symbol_nonlocal (const struct language_defn *langdef,
1271 1.1 christos const char *,
1272 1.1 christos const struct block *,
1273 1.1 christos const domain_enum);
1274 1.1 christos
1275 1.1 christos /* Some helper functions for languages that need to write their own
1276 1.3 christos lookup_symbol_nonlocal functions. */
1277 1.6 christos
1278 1.3 christos /* Lookup a symbol in the static block associated to BLOCK, if there
1279 1.6 christos is one; do nothing if BLOCK is NULL or a global block.
1280 1.6 christos Upon success fixes up the symbol's section if necessary. */
1281 1.6 christos
1282 1.6 christos extern struct block_symbol
1283 1.3 christos lookup_symbol_in_static_block (const char *name,
1284 1.3 christos const struct block *block,
1285 1.6 christos const domain_enum domain);
1286 1.1 christos
1287 1.6 christos /* Search all static file-level symbols for NAME from DOMAIN.
1288 1.6 christos Upon success fixes up the symbol's section if necessary. */
1289 1.1 christos
1290 1.3 christos extern struct block_symbol lookup_static_symbol (const char *name,
1291 1.3 christos const domain_enum domain);
1292 1.3 christos
1293 1.3 christos /* Lookup a symbol in all files' global blocks.
1294 1.3 christos
1295 1.3 christos If BLOCK is non-NULL then it is used for two things:
1296 1.3 christos 1) If a target-specific lookup routine for libraries exists, then use the
1297 1.3 christos routine for the objfile of BLOCK, and
1298 1.1 christos 2) The objfile of BLOCK is used to assist in determining the search order
1299 1.6 christos if the target requires it.
1300 1.3 christos See gdbarch_iterate_over_objfiles_in_search_order.
1301 1.6 christos
1302 1.6 christos Upon success fixes up the symbol's section if necessary. */
1303 1.6 christos
1304 1.6 christos extern struct block_symbol
1305 1.1 christos lookup_global_symbol (const char *name,
1306 1.3 christos const struct block *block,
1307 1.6 christos const domain_enum domain);
1308 1.3 christos
1309 1.6 christos /* Lookup a symbol in block BLOCK.
1310 1.6 christos Upon success fixes up the symbol's section if necessary. */
1311 1.6 christos
1312 1.6 christos extern struct symbol *
1313 1.3 christos lookup_symbol_in_block (const char *name,
1314 1.3 christos const struct block *block,
1315 1.3 christos const domain_enum domain);
1316 1.1 christos
1317 1.6 christos /* Look up the `this' symbol for LANG in BLOCK. Return the symbol if
1318 1.6 christos found, or NULL if not found. */
1319 1.6 christos
1320 1.1 christos extern struct block_symbol
1321 1.3 christos lookup_language_this (const struct language_defn *lang,
1322 1.1 christos const struct block *block);
1323 1.1 christos
1324 1.1 christos /* Lookup a [struct, union, enum] by name, within a specified block. */
1325 1.1 christos
1326 1.1 christos extern struct type *lookup_struct (const char *, const struct block *);
1327 1.1 christos
1328 1.1 christos extern struct type *lookup_union (const char *, const struct block *);
1329 1.1 christos
1330 1.1 christos extern struct type *lookup_enum (const char *, const struct block *);
1331 1.1 christos
1332 1.1 christos /* from blockframe.c: */
1333 1.1 christos
1334 1.1 christos /* lookup the function symbol corresponding to the address. */
1335 1.1 christos
1336 1.1 christos extern struct symbol *find_pc_function (CORE_ADDR);
1337 1.1 christos
1338 1.1 christos /* lookup the function corresponding to the address and section. */
1339 1.1 christos
1340 1.1 christos extern struct symbol *find_pc_sect_function (CORE_ADDR, struct obj_section *);
1341 1.1 christos
1342 1.1 christos extern int find_pc_partial_function_gnu_ifunc (CORE_ADDR pc, const char **name,
1343 1.1 christos CORE_ADDR *address,
1344 1.1 christos CORE_ADDR *endaddr,
1345 1.1 christos int *is_gnu_ifunc_p);
1346 1.1 christos
1347 1.1 christos /* lookup function from address, return name, start addr and end addr. */
1348 1.1 christos
1349 1.1 christos extern int find_pc_partial_function (CORE_ADDR, const char **, CORE_ADDR *,
1350 1.1 christos CORE_ADDR *);
1351 1.3 christos
1352 1.1 christos extern void clear_pc_function_cache (void);
1353 1.3 christos
1354 1.1 christos /* Expand symtab containing PC, SECTION if not already expanded. */
1355 1.1 christos
1356 1.1 christos extern void expand_symtab_containing_pc (CORE_ADDR, struct obj_section *);
1357 1.3 christos
1358 1.1 christos /* lookup full symbol table by address. */
1359 1.1 christos
1360 1.1 christos extern struct compunit_symtab *find_pc_compunit_symtab (CORE_ADDR);
1361 1.3 christos
1362 1.3 christos /* lookup full symbol table by address and section. */
1363 1.1 christos
1364 1.1 christos extern struct compunit_symtab *
1365 1.1 christos find_pc_sect_compunit_symtab (CORE_ADDR, struct obj_section *);
1366 1.1 christos
1367 1.1 christos extern int find_pc_line_pc_range (CORE_ADDR, CORE_ADDR *, CORE_ADDR *);
1368 1.3 christos
1369 1.3 christos extern void reread_symbols (void);
1370 1.3 christos
1371 1.3 christos /* Look up a type named NAME in STRUCT_DOMAIN in the current language.
1372 1.1 christos The type returned must not be opaque -- i.e., must have at least one field
1373 1.3 christos defined. */
1374 1.1 christos
1375 1.1 christos extern struct type *lookup_transparent_type (const char *);
1376 1.1 christos
1377 1.1 christos extern struct type *basic_lookup_transparent_type (const char *);
1378 1.1 christos
1379 1.1 christos /* Macro for name of symbol to indicate a file compiled with gcc. */
1380 1.1 christos #ifndef GCC_COMPILED_FLAG_SYMBOL
1381 1.1 christos #define GCC_COMPILED_FLAG_SYMBOL "gcc_compiled."
1382 1.1 christos #endif
1383 1.1 christos
1384 1.1 christos /* Macro for name of symbol to indicate a file compiled with gcc2. */
1385 1.1 christos #ifndef GCC2_COMPILED_FLAG_SYMBOL
1386 1.1 christos #define GCC2_COMPILED_FLAG_SYMBOL "gcc2_compiled."
1387 1.1 christos #endif
1388 1.1 christos
1389 1.1 christos extern int in_gnu_ifunc_stub (CORE_ADDR pc);
1390 1.1 christos
1391 1.1 christos /* Functions for resolving STT_GNU_IFUNC symbols which are implemented only
1392 1.1 christos for ELF symbol files. */
1393 1.1 christos
1394 1.1 christos struct gnu_ifunc_fns
1395 1.1 christos {
1396 1.1 christos /* See elf_gnu_ifunc_resolve_addr for its real implementation. */
1397 1.1 christos CORE_ADDR (*gnu_ifunc_resolve_addr) (struct gdbarch *gdbarch, CORE_ADDR pc);
1398 1.1 christos
1399 1.1 christos /* See elf_gnu_ifunc_resolve_name for its real implementation. */
1400 1.1 christos int (*gnu_ifunc_resolve_name) (const char *function_name,
1401 1.1 christos CORE_ADDR *function_address_p);
1402 1.1 christos
1403 1.1 christos /* See elf_gnu_ifunc_resolver_stop for its real implementation. */
1404 1.1 christos void (*gnu_ifunc_resolver_stop) (struct breakpoint *b);
1405 1.1 christos
1406 1.1 christos /* See elf_gnu_ifunc_resolver_return_stop for its real implementation. */
1407 1.1 christos void (*gnu_ifunc_resolver_return_stop) (struct breakpoint *b);
1408 1.1 christos };
1409 1.1 christos
1410 1.1 christos #define gnu_ifunc_resolve_addr gnu_ifunc_fns_p->gnu_ifunc_resolve_addr
1411 1.1 christos #define gnu_ifunc_resolve_name gnu_ifunc_fns_p->gnu_ifunc_resolve_name
1412 1.1 christos #define gnu_ifunc_resolver_stop gnu_ifunc_fns_p->gnu_ifunc_resolver_stop
1413 1.1 christos #define gnu_ifunc_resolver_return_stop \
1414 1.1 christos gnu_ifunc_fns_p->gnu_ifunc_resolver_return_stop
1415 1.1 christos
1416 1.1 christos extern const struct gnu_ifunc_fns *gnu_ifunc_fns_p;
1417 1.1 christos
1418 1.1 christos extern CORE_ADDR find_solib_trampoline_target (struct frame_info *, CORE_ADDR);
1419 1.1 christos
1420 1.1 christos struct symtab_and_line
1421 1.1 christos {
1422 1.1 christos /* The program space of this sal. */
1423 1.1 christos struct program_space *pspace;
1424 1.1 christos
1425 1.1 christos struct symtab *symtab;
1426 1.1 christos struct obj_section *section;
1427 1.1 christos /* Line number. Line numbers start at 1 and proceed through symtab->nlines.
1428 1.1 christos 0 is never a valid line number; it is used to indicate that line number
1429 1.1 christos information is not available. */
1430 1.1 christos int line;
1431 1.1 christos
1432 1.1 christos CORE_ADDR pc;
1433 1.1 christos CORE_ADDR end;
1434 1.1 christos int explicit_pc;
1435 1.1 christos int explicit_line;
1436 1.3 christos
1437 1.3 christos /* The probe associated with this symtab_and_line. */
1438 1.3 christos struct probe *probe;
1439 1.1 christos /* If PROBE is not NULL, then this is the objfile in which the probe
1440 1.1 christos originated. */
1441 1.1 christos struct objfile *objfile;
1442 1.1 christos };
1443 1.1 christos
1444 1.1 christos extern void init_sal (struct symtab_and_line *sal);
1445 1.1 christos
1446 1.1 christos struct symtabs_and_lines
1447 1.1 christos {
1448 1.1 christos struct symtab_and_line *sals;
1449 1.1 christos int nelts;
1450 1.1 christos };
1451 1.1 christos
1452 1.1 christos
1454 1.1 christos /* Given a pc value, return line number it is in. Second arg nonzero means
1455 1.1 christos if pc is on the boundary use the previous statement's line number. */
1456 1.1 christos
1457 1.1 christos extern struct symtab_and_line find_pc_line (CORE_ADDR, int);
1458 1.1 christos
1459 1.1 christos /* Same function, but specify a section as well as an address. */
1460 1.3 christos
1461 1.3 christos extern struct symtab_and_line find_pc_sect_line (CORE_ADDR,
1462 1.3 christos struct obj_section *, int);
1463 1.3 christos
1464 1.1 christos /* Wrapper around find_pc_line to just return the symtab. */
1465 1.1 christos
1466 1.1 christos extern struct symtab *find_pc_line_symtab (CORE_ADDR);
1467 1.1 christos
1468 1.1 christos /* Given a symtab and line number, return the pc there. */
1469 1.1 christos
1470 1.1 christos extern int find_line_pc (struct symtab *, int, CORE_ADDR *);
1471 1.1 christos
1472 1.1 christos extern int find_line_pc_range (struct symtab_and_line, CORE_ADDR *,
1473 1.5 christos CORE_ADDR *);
1474 1.1 christos
1475 1.1 christos extern void resolve_sal_pc (struct symtab_and_line *);
1476 1.1 christos
1477 1.1 christos /* solib.c */
1478 1.1 christos
1479 1.1 christos extern void clear_solib (void);
1480 1.1 christos
1481 1.1 christos /* source.c */
1482 1.1 christos
1483 1.6 christos extern int identify_source_line (struct symtab *, int, int, CORE_ADDR);
1484 1.1 christos
1485 1.1 christos /* Flags passed as 4th argument to print_source_lines. */
1486 1.1 christos
1487 1.1 christos enum print_source_lines_flag
1488 1.1 christos {
1489 1.1 christos /* Do not print an error message. */
1490 1.1 christos PRINT_SOURCE_LINES_NOERROR = (1 << 0),
1491 1.6 christos
1492 1.1 christos /* Print the filename in front of the source lines. */
1493 1.1 christos PRINT_SOURCE_LINES_FILENAME = (1 << 1)
1494 1.6 christos };
1495 1.1 christos DEF_ENUM_FLAGS_TYPE (enum print_source_lines_flag, print_source_lines_flags);
1496 1.1 christos
1497 1.1 christos extern void print_source_lines (struct symtab *, int, int,
1498 1.1 christos print_source_lines_flags);
1499 1.1 christos
1500 1.1 christos extern void forget_cached_source_info_for_objfile (struct objfile *);
1501 1.1 christos extern void forget_cached_source_info (void);
1502 1.1 christos
1503 1.1 christos extern void select_source_symtab (struct symtab *);
1504 1.1 christos
1505 1.1 christos extern VEC (char_ptr) *default_make_symbol_completion_list_break_on
1506 1.1 christos (const char *text, const char *word, const char *break_on,
1507 1.1 christos enum type_code code);
1508 1.1 christos extern VEC (char_ptr) *default_make_symbol_completion_list (const char *,
1509 1.1 christos const char *,
1510 1.1 christos enum type_code);
1511 1.1 christos extern VEC (char_ptr) *make_symbol_completion_list (const char *, const char *);
1512 1.1 christos extern VEC (char_ptr) *make_symbol_completion_type (const char *, const char *,
1513 1.1 christos enum type_code);
1514 1.1 christos extern VEC (char_ptr) *make_symbol_completion_list_fn (struct cmd_list_element *,
1515 1.1 christos const char *,
1516 1.1 christos const char *);
1517 1.1 christos
1518 1.1 christos extern VEC (char_ptr) *make_file_symbol_completion_list (const char *,
1519 1.1 christos const char *,
1520 1.1 christos const char *);
1521 1.1 christos
1522 1.1 christos extern VEC (char_ptr) *make_source_files_completion_list (const char *,
1523 1.1 christos const char *);
1524 1.1 christos
1525 1.1 christos /* symtab.c */
1526 1.1 christos
1527 1.1 christos int matching_obj_sections (struct obj_section *, struct obj_section *);
1528 1.1 christos
1529 1.1 christos extern struct symtab *find_line_symtab (struct symtab *, int, int *, int *);
1530 1.1 christos
1531 1.1 christos extern struct symtab_and_line find_function_start_sal (struct symbol *sym,
1532 1.1 christos int);
1533 1.1 christos
1534 1.1 christos extern void skip_prologue_sal (struct symtab_and_line *);
1535 1.1 christos
1536 1.1 christos /* symtab.c */
1537 1.1 christos
1538 1.1 christos extern CORE_ADDR skip_prologue_using_sal (struct gdbarch *gdbarch,
1539 1.1 christos CORE_ADDR func_addr);
1540 1.1 christos
1541 1.1 christos extern struct symbol *fixup_symbol_section (struct symbol *,
1542 1.1 christos struct objfile *);
1543 1.1 christos
1544 1.1 christos /* Symbol searching */
1545 1.1 christos /* Note: struct symbol_search, search_symbols, et.al. are declared here,
1546 1.1 christos instead of making them local to symtab.c, for gdbtk's sake. */
1547 1.1 christos
1548 1.1 christos /* When using search_symbols, a list of the following structs is returned.
1549 1.1 christos Callers must free the search list using free_search_symbols! */
1550 1.1 christos struct symbol_search
1551 1.1 christos {
1552 1.1 christos /* The block in which the match was found. Could be, for example,
1553 1.1 christos STATIC_BLOCK or GLOBAL_BLOCK. */
1554 1.3 christos int block;
1555 1.1 christos
1556 1.1 christos /* Information describing what was found.
1557 1.1 christos
1558 1.1 christos If symbol is NOT NULL, then information was found for this match. */
1559 1.1 christos struct symbol *symbol;
1560 1.1 christos
1561 1.1 christos /* If msymbol is non-null, then a match was made on something for
1562 1.1 christos which only minimal_symbols exist. */
1563 1.1 christos struct bound_minimal_symbol msymbol;
1564 1.1 christos
1565 1.3 christos /* A link to the next match, or NULL for the end. */
1566 1.3 christos struct symbol_search *next;
1567 1.1 christos };
1568 1.1 christos
1569 1.1 christos extern void search_symbols (const char *, enum search_domain, int,
1570 1.1 christos const char **, struct symbol_search **);
1571 1.1 christos extern void free_search_symbols (struct symbol_search *);
1572 1.1 christos extern struct cleanup *make_cleanup_free_search_symbols (struct symbol_search
1573 1.1 christos **);
1574 1.1 christos
1575 1.1 christos /* The name of the ``main'' function.
1576 1.3 christos FIXME: cagney/2001-03-20: Can't make main_name() const since some
1577 1.1 christos of the calling code currently assumes that the string isn't
1578 1.3 christos const. */
1579 1.3 christos extern /*const */ char *main_name (void);
1580 1.3 christos extern enum language main_language (void);
1581 1.6 christos
1582 1.3 christos /* Lookup symbol NAME from DOMAIN in MAIN_OBJFILE's global blocks.
1583 1.6 christos This searches MAIN_OBJFILE as well as any associated separate debug info
1584 1.3 christos objfiles of MAIN_OBJFILE.
1585 1.3 christos Upon success fixes up the symbol's section if necessary. */
1586 1.3 christos
1587 1.1 christos extern struct block_symbol
1588 1.1 christos lookup_global_symbol_from_objfile (struct objfile *main_objfile,
1589 1.1 christos const char *name,
1590 1.1 christos const domain_enum domain);
1591 1.1 christos
1592 1.1 christos /* Return 1 if the supplied producer string matches the ARM RealView
1593 1.1 christos compiler (armcc). */
1594 1.1 christos int producer_is_realview (const char *producer);
1595 1.3 christos
1596 1.3 christos void fixup_section (struct general_symbol_info *ginfo,
1597 1.1 christos CORE_ADDR addr, struct objfile *objfile);
1598 1.1 christos
1599 1.1 christos /* Look up objfile containing BLOCK. */
1600 1.1 christos
1601 1.3 christos struct objfile *lookup_objfile_from_block (const struct block *block);
1602 1.3 christos
1603 1.1 christos extern unsigned int symtab_create_debug;
1604 1.1 christos
1605 1.1 christos extern unsigned int symbol_lookup_debug;
1606 1.1 christos
1607 1.1 christos extern int basenames_may_differ;
1608 1.6 christos
1609 1.6 christos int compare_filenames_for_search (const char *filename,
1610 1.6 christos const char *search_name);
1611 1.7 christos
1612 1.7 christos int compare_glob_filenames_for_search (const char *filename,
1613 1.7 christos const char *search_name);
1614 1.7 christos
1615 1.7 christos bool iterate_over_some_symtabs (const char *name,
1616 1.1 christos const char *real_path,
1617 1.1 christos struct compunit_symtab *first,
1618 1.7 christos struct compunit_symtab *after_last,
1619 1.1 christos gdb::function_view<bool (symtab *)> callback);
1620 1.7 christos
1621 1.7 christos void iterate_over_symtabs (const char *name,
1622 1.7 christos gdb::function_view<bool (symtab *)> callback);
1623 1.7 christos
1624 1.7 christos
1625 1.7 christos std::vector<CORE_ADDR> find_pcs_for_symtab_line
1626 1.7 christos (struct symtab *symtab, int line, struct linetable_entry **best_entry);
1627 1.7 christos
1628 1.7 christos /* Prototype for callbacks for LA_ITERATE_OVER_SYMBOLS. The callback
1629 1.7 christos is called once per matching symbol SYM. The callback should return
1630 1.1 christos true to indicate that LA_ITERATE_OVER_SYMBOLS should continue
1631 1.1 christos iterating, or false to indicate that the iteration should end. */
1632 1.1 christos
1633 1.7 christos typedef bool (symbol_found_callback_ftype) (symbol *sym);
1634 1.7 christos
1635 1.7 christos void iterate_over_symbols (const struct block *block, const char *name,
1636 1.7 christos const domain_enum domain,
1637 1.7 christos gdb::function_view<symbol_found_callback_ftype> callback);
1638 1.7 christos
1639 1.7 christos /* Storage type used by demangle_for_lookup. demangle_for_lookup
1640 1.7 christos either returns a const char * pointer that points to either of the
1641 1.7 christos fields of this type, or a pointer to the input NAME. This is done
1642 1.7 christos this way because the underlying functions that demangle_for_lookup
1643 1.7 christos calls either return a std::string (e.g., cp_canonicalize_string) or
1644 1.7 christos a malloc'ed buffer (libiberty's demangled), and we want to avoid
1645 1.7 christos unnecessary reallocation/string copying. */
1646 1.7 christos class demangle_result_storage
1647 1.7 christos {
1648 1.7 christos public:
1649 1.7 christos
1650 1.7 christos /* Swap the std::string storage with STR, and return a pointer to
1651 1.7 christos the beginning of the new string. */
1652 1.7 christos const char *swap_string (std::string &str)
1653 1.7 christos {
1654 1.7 christos std::swap (m_string, str);
1655 1.7 christos return m_string.c_str ();
1656 1.7 christos }
1657 1.7 christos
1658 1.7 christos /* Set the malloc storage to now point at PTR. Any previous malloc
1659 1.7 christos storage is released. */
1660 1.7 christos const char *set_malloc_ptr (char *ptr)
1661 1.7 christos {
1662 1.7 christos m_malloc.reset (ptr);
1663 1.7 christos return ptr;
1664 1.7 christos }
1665 1.7 christos
1666 1.7 christos private:
1667 1.7 christos
1668 1.1 christos /* The storage. */
1669 1.7 christos std::string m_string;
1670 1.7 christos gdb::unique_xmalloc_ptr<char> m_malloc;
1671 1.7 christos };
1672 1.1 christos
1673 1.1 christos const char *
1674 1.1 christos demangle_for_lookup (const char *name, enum language lang,
1675 1.3 christos demangle_result_storage &storage);
1676 1.1 christos
1677 1.1 christos struct symbol *allocate_symbol (struct objfile *);
1678 1.1 christos
1679 1.1 christos void initialize_objfile_symbol (struct symbol *);
1680
1681 struct template_symbol *allocate_template_symbol (struct objfile *);
1682
1683 #endif /* !defined(SYMTAB_H) */
1684