1 /* Minimal symbol table definitions for GDB.
3 Copyright (C) 2011-2016 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 /* Several lookup functions return both a minimal symbol and the
24 objfile in which it is found. This structure is used in these
27 struct bound_minimal_symbol
29 /* The minimal symbol that was found, or NULL if no minimal symbol
32 struct minimal_symbol
*minsym
;
34 /* If MINSYM is not NULL, then this is the objfile in which the
37 struct objfile
*objfile
;
40 /* This header declares most of the API for dealing with minimal
41 symbols and minimal symbol tables. A few things are declared
44 A minimal symbol is a symbol for which there is no direct debug
45 information. For example, for an ELF binary, minimal symbols are
46 created from the ELF symbol table.
48 For the definition of the minimal symbol structure, see struct
49 minimal_symbol in symtab.h.
51 Minimal symbols are stored in tables attached to an objfile; see
52 objfiles.h for details. Code should generally treat these tables
53 as opaque and use functions provided by minsyms.c to inspect them.
56 /* An RAII-based object that is used to record minimal symbols while
57 they are being read. */
58 class minimal_symbol_reader
62 /* Prepare to start collecting minimal symbols. This should be called
63 by a symbol reader to initialize the minimal symbol module.
64 Currently, minimal symbol table creation is not reentrant; it
65 relies on global (static) variables in minsyms.c. */
67 explicit minimal_symbol_reader (struct objfile
*);
69 ~minimal_symbol_reader ();
71 /* Install the minimal symbols that have been collected into the
78 /* No need for these. They are intentionally not defined anywhere. */
79 minimal_symbol_reader
&operator=
80 (const minimal_symbol_reader
&);
81 minimal_symbol_reader (const minimal_symbol_reader
&);
83 struct objfile
*m_objfile
;
86 /* Record a new minimal symbol. This is the "full" entry point;
87 simpler convenience entry points are also provided below.
89 This returns a new minimal symbol. It is ok to modify the returned
90 minimal symbol (though generally not necessary). It is not ok,
91 though, to stash the pointer anywhere; as minimal symbols may be
92 moved after creation. The memory for the returned minimal symbol
93 is still owned by the minsyms.c code, and should not be freed.
97 NAME - the symbol's name
98 NAME_LEN - the length of the name
99 COPY_NAME - if true, the minsym code must make a copy of NAME. If
100 false, then NAME must be NUL-terminated, and must have a lifetime
101 that is at least as long as OBJFILE's lifetime.
102 ADDRESS - the address of the symbol
103 MS_TYPE - the type of the symbol
104 SECTION - the symbol's section
105 appropriate obj_section for the minimal symbol. This can be NULL.
106 OBJFILE - the objfile associated with the minimal symbol. */
108 struct minimal_symbol
*prim_record_minimal_symbol_full
113 enum minimal_symbol_type ms_type
,
115 struct objfile
*objfile
);
117 /* Like prim_record_minimal_symbol_full, but:
118 - uses strlen to compute NAME_LEN,
119 - passes COPY_NAME = 1,
120 - and passes a default SECTION, depending on the type
122 This variant does not return the new symbol. */
124 void prim_record_minimal_symbol (const char *, CORE_ADDR
,
125 enum minimal_symbol_type
,
128 /* Like prim_record_minimal_symbol_full, but:
129 - uses strlen to compute NAME_LEN,
130 - passes COPY_NAME = 1. */
132 struct minimal_symbol
*prim_record_minimal_symbol_and_info
135 enum minimal_symbol_type
,
139 /* Create the terminating entry of OBJFILE's minimal symbol table.
140 If OBJFILE->msymbols is zero, allocate a single entry from
141 OBJFILE->objfile_obstack; otherwise, just initialize
142 OBJFILE->msymbols[OBJFILE->minimal_symbol_count]. */
144 void terminate_minimal_symbol_table (struct objfile
*objfile
);
148 /* Compute a hash code for the string argument. */
150 unsigned int msymbol_hash (const char *);
152 /* Like msymbol_hash, but compute a hash code that is compatible with
155 unsigned int msymbol_hash_iw (const char *);
157 /* Compute the next hash value from previous HASH and the character C. This
158 is only a GDB in-memory computed value with no external files compatibility
161 #define SYMBOL_HASH_NEXT(hash, c) \
162 ((hash) * 67 + tolower ((unsigned char) (c)) - 113)
166 /* Look through all the current minimal symbol tables and find the
167 first minimal symbol that matches NAME. If OBJF is non-NULL, limit
168 the search to that objfile. If SFILE is non-NULL, the only
169 file-scope symbols considered will be from that source file (global
170 symbols are still preferred). Returns a bound minimal symbol that
171 matches, or an empty bound minimal symbol if no match is found. */
173 struct bound_minimal_symbol
lookup_minimal_symbol (const char *,
177 /* Like lookup_minimal_symbol, but searches all files and
180 struct bound_minimal_symbol
lookup_bound_minimal_symbol (const char *);
182 /* Find the minimal symbol named NAME, and return both the minsym
183 struct and its objfile. This only checks the linkage name. */
185 struct bound_minimal_symbol
lookup_minimal_symbol_and_objfile (const char *);
187 /* Look through all the current minimal symbol tables and find the
188 first minimal symbol that matches NAME and has text type. If OBJF
189 is non-NULL, limit the search to that objfile. Returns a bound
190 minimal symbol that matches, or an "empty" bound minimal symbol
193 This function only searches the mangled (linkage) names. */
195 struct bound_minimal_symbol
lookup_minimal_symbol_text (const char *,
198 /* Look through all the current minimal symbol tables and find the
199 first minimal symbol that matches NAME and is a solib trampoline.
200 If OBJF is non-NULL, limit the search to that objfile. Returns a
201 pointer to the minimal symbol that matches, or NULL if no match is
204 This function only searches the mangled (linkage) names. */
206 struct bound_minimal_symbol lookup_minimal_symbol_solib_trampoline
210 /* Look through all the current minimal symbol tables and find the
211 first minimal symbol that matches NAME and PC. If OBJF is non-NULL,
212 limit the search to that objfile. Returns a pointer to the minimal
213 symbol that matches, or NULL if no match is found. */
215 struct minimal_symbol
*lookup_minimal_symbol_by_pc_name
216 (CORE_ADDR
, const char *, struct objfile
*);
218 /* Search through the minimal symbol table for each objfile and find
219 the symbol whose address is the largest address that is still less
220 than or equal to PC, and which matches SECTION.
222 If SECTION is NULL, this uses the result of find_pc_section
225 The result has a non-NULL 'minsym' member if such a symbol is
226 found, or NULL if PC is not in a suitable range. */
228 struct bound_minimal_symbol lookup_minimal_symbol_by_pc_section
230 struct obj_section
*);
232 /* Backward compatibility: search through the minimal symbol table
233 for a matching PC (no section given).
235 This is a wrapper that calls lookup_minimal_symbol_by_pc_section
236 with a NULL section argument. */
238 struct bound_minimal_symbol
lookup_minimal_symbol_by_pc (CORE_ADDR
);
240 /* Iterate over all the minimal symbols in the objfile OBJF which
241 match NAME. Both the ordinary and demangled names of each symbol
242 are considered. The caller is responsible for canonicalizing NAME,
243 should that need to be done.
245 For each matching symbol, CALLBACK is called with the symbol and
246 USER_DATA as arguments. */
248 void iterate_over_minimal_symbols (struct objfile
*objf
,
250 void (*callback
) (struct minimal_symbol
*,
254 /* Compute the upper bound of MINSYM. The upper bound is the last
255 address thought to be part of the symbol. If the symbol has a
256 size, it is used. Otherwise use the lesser of the next minimal
257 symbol in the same section, or the end of the section, as the end
260 CORE_ADDR
minimal_symbol_upper_bound (struct bound_minimal_symbol minsym
);
262 #endif /* MINSYMS_H */