GDB (xrefs)

/tmp/gdb-8.1/gdb/minsyms.h
Go to the documentation of this file.
1 /* Minimal symbol table definitions for GDB.
2
3 Copyright (C) 2011-2018 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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.
11
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.
16
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/>. */
19
20 #ifndef MINSYMS_H
21 #define MINSYMS_H
22
23 struct type;
24
25 /* Several lookup functions return both a minimal symbol and the
26 objfile in which it is found. This structure is used in these
27 cases. */
28
29 struct bound_minimal_symbol
30 {
31 /* The minimal symbol that was found, or NULL if no minimal symbol
32 was found. */
33
34 struct minimal_symbol *minsym;
35
36 /* If MINSYM is not NULL, then this is the objfile in which the
37 symbol is defined. */
38
39 struct objfile *objfile;
40 };
41
42 /* This header declares most of the API for dealing with minimal
43 symbols and minimal symbol tables. A few things are declared
44 elsewhere; see below.
45
46 A minimal symbol is a symbol for which there is no direct debug
47 information. For example, for an ELF binary, minimal symbols are
48 created from the ELF symbol table.
49
50 For the definition of the minimal symbol structure, see struct
51 minimal_symbol in symtab.h.
52
53 Minimal symbols are stored in tables attached to an objfile; see
54 objfiles.h for details. Code should generally treat these tables
55 as opaque and use functions provided by minsyms.c to inspect them.
56 */
57
58 struct msym_bunch;
59
60 /* An RAII-based object that is used to record minimal symbols while
61 they are being read. */
62 class minimal_symbol_reader
63 {
64 public:
65
66 /* Prepare to start collecting minimal symbols. This should be
67 called by a symbol reader to initialize the minimal symbol
68 module. */
69
70 explicit minimal_symbol_reader (struct objfile *);
71
72 ~minimal_symbol_reader ();
73
74 /* Install the minimal symbols that have been collected into the
75 given objfile. */
76
77 void install ();
78
79 /* Record a new minimal symbol. This is the "full" entry point;
80 simpler convenience entry points are also provided below.
81
82 This returns a new minimal symbol. It is ok to modify the returned
83 minimal symbol (though generally not necessary). It is not ok,
84 though, to stash the pointer anywhere; as minimal symbols may be
85 moved after creation. The memory for the returned minimal symbol
86 is still owned by the minsyms.c code, and should not be freed.
87
88 Arguments are:
89
90 NAME - the symbol's name
91 NAME_LEN - the length of the name
92 COPY_NAME - if true, the minsym code must make a copy of NAME. If
93 false, then NAME must be NUL-terminated, and must have a lifetime
94 that is at least as long as OBJFILE's lifetime.
95 ADDRESS - the address of the symbol
96 MS_TYPE - the type of the symbol
97 SECTION - the symbol's section
98 */
99
100 struct minimal_symbol *record_full (const char *name,
101 int name_len,
102 bool copy_name,
103 CORE_ADDR address,
104 enum minimal_symbol_type ms_type,
105 int section);
106
107 /* Like record_full, but:
108 - uses strlen to compute NAME_LEN,
109 - passes COPY_NAME = true,
110 - and passes a default SECTION, depending on the type
111
112 This variant does not return the new symbol. */
113
114 void record (const char *name, CORE_ADDR address,
115 enum minimal_symbol_type ms_type);
116
117 /* Like record_full, but:
118 - uses strlen to compute NAME_LEN,
119 - passes COPY_NAME = true. */
120
121 struct minimal_symbol *record_with_info (const char *name,
122 CORE_ADDR address,
123 enum minimal_symbol_type ms_type,
124 int section)
125 {
126 return record_full (name, strlen (name), true, address, ms_type, section);
127 }
128
129 private:
130
131 /* No need for these. They are intentionally not defined anywhere. */
132 minimal_symbol_reader &operator=
133 (const minimal_symbol_reader &);
134 minimal_symbol_reader (const minimal_symbol_reader &);
135
136 struct objfile *m_objfile;
137
138 /* Bunch currently being filled up.
139 The next field points to chain of filled bunches. */
140
141 struct msym_bunch *m_msym_bunch;
142
143 /* Number of slots filled in current bunch. */
144
145 int m_msym_bunch_index;
146
147 /* Total number of minimal symbols recorded so far for the
148 objfile. */
149
150 int m_msym_count;
151 };
152
153 /* Create the terminating entry of OBJFILE's minimal symbol table.
154 If OBJFILE->msymbols is zero, allocate a single entry from
155 OBJFILE->objfile_obstack; otherwise, just initialize
156 OBJFILE->msymbols[OBJFILE->minimal_symbol_count]. */
157
158 void terminate_minimal_symbol_table (struct objfile *objfile);
159
160
161
162 /* Return whether MSYMBOL is a function/method. If FUNC_ADDRESS_P is
163 non-NULL, and the MSYMBOL is a function, then *FUNC_ADDRESS_P is
164 set to the function's address, already resolved if MINSYM points to
165 a function descriptor. */
166
167 bool msymbol_is_function (struct objfile *objfile,
168 minimal_symbol *minsym,
169 CORE_ADDR *func_address_p = NULL);
170
171 /* Compute a hash code for the string argument. */
172
173 unsigned int msymbol_hash (const char *);
174
175 /* Like msymbol_hash, but compute a hash code that is compatible with
176 strcmp_iw. */
177
178 unsigned int msymbol_hash_iw (const char *);
179
180 /* Compute the next hash value from previous HASH and the character C. This
181 is only a GDB in-memory computed value with no external files compatibility
182 requirements. */
183
184 #define SYMBOL_HASH_NEXT(hash, c) \
185 ((hash) * 67 + TOLOWER ((unsigned char) (c)) - 113)
186
187
188
189 /* Look through all the current minimal symbol tables and find the
190 first minimal symbol that matches NAME. If OBJF is non-NULL, limit
191 the search to that objfile. If SFILE is non-NULL, the only
192 file-scope symbols considered will be from that source file (global
193 symbols are still preferred). Returns a bound minimal symbol that
194 matches, or an empty bound minimal symbol if no match is found. */
195
196 struct bound_minimal_symbol lookup_minimal_symbol (const char *,
197 const char *,
198 struct objfile *);
199
200 /* Like lookup_minimal_symbol, but searches all files and
201 objfiles. */
202
203 struct bound_minimal_symbol lookup_bound_minimal_symbol (const char *);
204
205 /* Find the minimal symbol named NAME, and return both the minsym
206 struct and its objfile. This only checks the linkage name. */
207
208 struct bound_minimal_symbol lookup_minimal_symbol_and_objfile (const char *);
209
210 /* Look through all the current minimal symbol tables and find the
211 first minimal symbol that matches NAME and has text type. If OBJF
212 is non-NULL, limit the search to that objfile. Returns a bound
213 minimal symbol that matches, or an "empty" bound minimal symbol
214 otherwise.
215
216 This function only searches the mangled (linkage) names. */
217
218 struct bound_minimal_symbol lookup_minimal_symbol_text (const char *,
219 struct objfile *);
220
221 /* Look through all the current minimal symbol tables and find the
222 first minimal symbol that matches NAME and is a solib trampoline.
223 If OBJF is non-NULL, limit the search to that objfile. Returns a
224 pointer to the minimal symbol that matches, or NULL if no match is
225 found.
226
227 This function only searches the mangled (linkage) names. */
228
229 struct bound_minimal_symbol lookup_minimal_symbol_solib_trampoline
230 (const char *,
231 struct objfile *);
232
233 /* Look through all the current minimal symbol tables and find the
234 first minimal symbol that matches NAME and PC. If OBJF is non-NULL,
235 limit the search to that objfile. Returns a pointer to the minimal
236 symbol that matches, or NULL if no match is found. */
237
238 struct minimal_symbol *lookup_minimal_symbol_by_pc_name
239 (CORE_ADDR, const char *, struct objfile *);
240
241 /* Search through the minimal symbol table for each objfile and find
242 the symbol whose address is the largest address that is still less
243 than or equal to PC, and which matches SECTION.
244
245 If SECTION is NULL, this uses the result of find_pc_section
246 instead.
247
248 The result has a non-NULL 'minsym' member if such a symbol is
249 found, or NULL if PC is not in a suitable range. */
250
251 struct bound_minimal_symbol lookup_minimal_symbol_by_pc_section
252 (CORE_ADDR,
253 struct obj_section *);
254
255 /* Backward compatibility: search through the minimal symbol table
256 for a matching PC (no section given).
257
258 This is a wrapper that calls lookup_minimal_symbol_by_pc_section
259 with a NULL section argument. */
260
261 struct bound_minimal_symbol lookup_minimal_symbol_by_pc (CORE_ADDR);
262
263 /* Iterate over all the minimal symbols in the objfile OBJF which
264 match NAME. Both the ordinary and demangled names of each symbol
265 are considered. The caller is responsible for canonicalizing NAME,
266 should that need to be done.
267
268 For each matching symbol, CALLBACK is called with the symbol and
269 USER_DATA as arguments. */
270
271 void iterate_over_minimal_symbols (struct objfile *objf,
272 const lookup_name_info &name,
273 void (*callback) (struct minimal_symbol *,
274 void *),
275 void *user_data);
276
277 /* Compute the upper bound of MINSYM. The upper bound is the last
278 address thought to be part of the symbol. If the symbol has a
279 size, it is used. Otherwise use the lesser of the next minimal
280 symbol in the same section, or the end of the section, as the end
281 of the function. */
282
283 CORE_ADDR minimal_symbol_upper_bound (struct bound_minimal_symbol minsym);
284
285 /* Return the type of MSYMBOL, a minimal symbol of OBJFILE. If
286 ADDRESS_P is not NULL, set it to the MSYMBOL's resolved
287 address. */
288
289 type *find_minsym_type_and_address (minimal_symbol *msymbol, objfile *objf,
290 CORE_ADDR *address_p);
291
292 #endif /* MINSYMS_H */
lookup_minimal_symbol
struct bound_minimal_symbol lookup_minimal_symbol(const char *, const char *, struct objfile *)
Definition: minsyms.c:311
minimal_symbol_reader::install
void install()
Definition: minsyms.c:1346
msym_bunch
Definition: minsyms.c:98
lookup_minimal_symbol_by_pc_name
struct minimal_symbol * lookup_minimal_symbol_by_pc_name(CORE_ADDR, const char *, struct objfile *)
Definition: minsyms.c:570
iterate_over_minimal_symbols
void iterate_over_minimal_symbols(struct objfile *objf, const lookup_name_info &name, void(*callback)(struct minimal_symbol *, void *), void *user_data)
Definition: minsyms.c:472
minimal_symbol_reader::m_msym_bunch
struct msym_bunch * m_msym_bunch
Definition: minsyms.h:141
CORE_ADDR
bfd_vma CORE_ADDR
Definition: common-types.h:41
minimal_symbol_reader::record
void record(const char *name, CORE_ADDR address, enum minimal_symbol_type ms_type)
Definition: minsyms.c:1085
msymbol_hash_iw
unsigned int msymbol_hash_iw(const char *)
Definition: minsyms.c:107
lookup_minimal_symbol_solib_trampoline
struct bound_minimal_symbol lookup_minimal_symbol_solib_trampoline(const char *, struct objfile *)
Definition: minsyms.c:602
lookup_minimal_symbol_by_pc_section
struct bound_minimal_symbol lookup_minimal_symbol_by_pc_section(CORE_ADDR, struct obj_section *)
Definition: minsyms.c:906
minimal_symbol_reader::m_objfile
struct objfile * m_objfile
Definition: minsyms.h:136
terminate_minimal_symbol_table
void terminate_minimal_symbol_table(struct objfile *objfile)
Definition: minsyms.c:1441
minimal_symbol_reader::record_full
struct minimal_symbol * record_full(const char *name, int name_len, bool copy_name, CORE_ADDR address, enum minimal_symbol_type ms_type, int section)
Definition: minsyms.c:1116
msymbol_hash
unsigned int msymbol_hash(const char *)
Definition: minsyms.c:126
lookup_minimal_symbol_and_objfile
struct bound_minimal_symbol lookup_minimal_symbol_and_objfile(const char *)
Definition: minsyms.c:1008
name
const char *const name
Definition: aarch64-tdep.c:76
find_minsym_type_and_address
type * find_minsym_type_and_address(minimal_symbol *msymbol, objfile *objf, CORE_ADDR *address_p)
Definition: parse.c:444
minimal_symbol_upper_bound
CORE_ADDR minimal_symbol_upper_bound(struct bound_minimal_symbol minsym)
Definition: minsyms.c:1532
bound_minimal_symbol
Definition: minsyms.h:29
minimal_symbol_reader::~minimal_symbol_reader
~minimal_symbol_reader()
Definition: minsyms.c:1070
type
Definition: gdbtypes.h:749
lookup_minimal_symbol_by_pc
struct bound_minimal_symbol lookup_minimal_symbol_by_pc(CORE_ADDR)
Definition: minsyms.c:928
minimal_symbol_reader::minimal_symbol_reader
minimal_symbol_reader(struct objfile *)
Definition: minsyms.c:1051
objfile
Definition: objfiles.h:286
obj_section
Definition: objfiles.h:123
minimal_symbol_reader::record_with_info
struct minimal_symbol * record_with_info(const char *name, CORE_ADDR address, enum minimal_symbol_type ms_type, int section)
Definition: minsyms.h:121
bound_minimal_symbol::minsym
struct minimal_symbol * minsym
Definition: minsyms.h:34
minimal_symbol_reader::m_msym_bunch_index
int m_msym_bunch_index
Definition: minsyms.h:145
minimal_symbol_reader::m_msym_count
int m_msym_count
Definition: minsyms.h:150
msymbol_is_function
bool msymbol_is_function(struct objfile *objfile, minimal_symbol *minsym, CORE_ADDR *func_address_p=NULL)
Definition: minsyms.c:60
minimal_symbol
Definition: symtab.h:623
bound_minimal_symbol::objfile
struct objfile * objfile
Definition: minsyms.h:39
lookup_minimal_symbol_text
struct bound_minimal_symbol lookup_minimal_symbol_text(const char *, struct objfile *)
Definition: minsyms.c:519
minimal_symbol_type
minimal_symbol_type
Definition: symtab.h:579
minimal_symbol_reader
Definition: minsyms.h:62
lookup_name_info
Definition: symtab.h:179
lookup_bound_minimal_symbol
struct bound_minimal_symbol lookup_bound_minimal_symbol(const char *)
Definition: minsyms.c:430
copy_name
char * copy_name(struct stoken token)
Definition: parse.c:761