Change minimal_symbol_reader to store objfile
[deliverable/binutils-gdb.git] / gdb / minsyms.h
1 /* Minimal symbol table definitions for GDB.
2
3 Copyright (C) 2011-2016 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 /* Several lookup functions return both a minimal symbol and the
24 objfile in which it is found. This structure is used in these
25 cases. */
26
27 struct bound_minimal_symbol
28 {
29 /* The minimal symbol that was found, or NULL if no minimal symbol
30 was found. */
31
32 struct minimal_symbol *minsym;
33
34 /* If MINSYM is not NULL, then this is the objfile in which the
35 symbol is defined. */
36
37 struct objfile *objfile;
38 };
39
40 /* This header declares most of the API for dealing with minimal
41 symbols and minimal symbol tables. A few things are declared
42 elsewhere; see below.
43
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.
47
48 For the definition of the minimal symbol structure, see struct
49 minimal_symbol in symtab.h.
50
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.
54 */
55
56 /* An RAII-based object that is used to record minimal symbols while
57 they are being read. */
58 class minimal_symbol_reader
59 {
60 public:
61
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. */
66
67 explicit minimal_symbol_reader (struct objfile *);
68
69 ~minimal_symbol_reader ();
70
71 /* Install the minimal symbols that have been collected into the
72 given objfile. */
73
74 void install ();
75
76 private:
77
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 &);
82
83 struct objfile *m_objfile;
84 };
85
86 /* Record a new minimal symbol. This is the "full" entry point;
87 simpler convenience entry points are also provided below.
88
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.
94
95 Arguments are:
96
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. */
107
108 struct minimal_symbol *prim_record_minimal_symbol_full
109 (const char *name,
110 int name_len,
111 int copy_name,
112 CORE_ADDR address,
113 enum minimal_symbol_type ms_type,
114 int section,
115 struct objfile *objfile);
116
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
121
122 This variant does not return the new symbol. */
123
124 void prim_record_minimal_symbol (const char *, CORE_ADDR,
125 enum minimal_symbol_type,
126 struct objfile *);
127
128 /* Like prim_record_minimal_symbol_full, but:
129 - uses strlen to compute NAME_LEN,
130 - passes COPY_NAME = 1. */
131
132 struct minimal_symbol *prim_record_minimal_symbol_and_info
133 (const char *,
134 CORE_ADDR,
135 enum minimal_symbol_type,
136 int section,
137 struct objfile *);
138
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]. */
143
144 void terminate_minimal_symbol_table (struct objfile *objfile);
145
146 \f
147
148 /* Compute a hash code for the string argument. */
149
150 unsigned int msymbol_hash (const char *);
151
152 /* Like msymbol_hash, but compute a hash code that is compatible with
153 strcmp_iw. */
154
155 unsigned int msymbol_hash_iw (const char *);
156
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
159 requirements. */
160
161 #define SYMBOL_HASH_NEXT(hash, c) \
162 ((hash) * 67 + tolower ((unsigned char) (c)) - 113)
163
164 \f
165
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. */
172
173 struct bound_minimal_symbol lookup_minimal_symbol (const char *,
174 const char *,
175 struct objfile *);
176
177 /* Like lookup_minimal_symbol, but searches all files and
178 objfiles. */
179
180 struct bound_minimal_symbol lookup_bound_minimal_symbol (const char *);
181
182 /* Find the minimal symbol named NAME, and return both the minsym
183 struct and its objfile. This only checks the linkage name. */
184
185 struct bound_minimal_symbol lookup_minimal_symbol_and_objfile (const char *);
186
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
191 otherwise.
192
193 This function only searches the mangled (linkage) names. */
194
195 struct bound_minimal_symbol lookup_minimal_symbol_text (const char *,
196 struct objfile *);
197
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
202 found.
203
204 This function only searches the mangled (linkage) names. */
205
206 struct bound_minimal_symbol lookup_minimal_symbol_solib_trampoline
207 (const char *,
208 struct objfile *);
209
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. */
214
215 struct minimal_symbol *lookup_minimal_symbol_by_pc_name
216 (CORE_ADDR, const char *, struct objfile *);
217
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.
221
222 If SECTION is NULL, this uses the result of find_pc_section
223 instead.
224
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. */
227
228 struct bound_minimal_symbol lookup_minimal_symbol_by_pc_section
229 (CORE_ADDR,
230 struct obj_section *);
231
232 /* Backward compatibility: search through the minimal symbol table
233 for a matching PC (no section given).
234
235 This is a wrapper that calls lookup_minimal_symbol_by_pc_section
236 with a NULL section argument. */
237
238 struct bound_minimal_symbol lookup_minimal_symbol_by_pc (CORE_ADDR);
239
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.
244
245 For each matching symbol, CALLBACK is called with the symbol and
246 USER_DATA as arguments. */
247
248 void iterate_over_minimal_symbols (struct objfile *objf,
249 const char *name,
250 void (*callback) (struct minimal_symbol *,
251 void *),
252 void *user_data);
253
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
258 of the function. */
259
260 CORE_ADDR minimal_symbol_upper_bound (struct bound_minimal_symbol minsym);
261
262 #endif /* MINSYMS_H */
This page took 0.04336 seconds and 4 git commands to generate.