* minsyms.h (struct bound_minimal_symbol): New.
[deliverable/binutils-gdb.git] / gdb / minsyms.h
CommitLineData
c35384fb
TT
1/* Minimal symbol table definitions for GDB.
2
28e7fd62 3 Copyright (C) 2011-2013 Free Software Foundation, Inc.
c35384fb
TT
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
7cbd4a93
TT
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
27struct 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
b19686e0
TT
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.
c35384fb 43
b19686e0
TT
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/* Prepare to start collecting minimal symbols. This should be called
57 by a symbol reader to initialize the minimal symbol module.
58 Currently, minimal symbol table creation is not reentrant; it
59 relies on global (static) variables in minsyms.c. */
60
61void init_minimal_symbol_collection (void);
62
63/* Return a cleanup which is used to clean up the global state left
64 over by minimal symbol creation. After calling
65 init_minimal_symbol_collection, a symbol reader should call this
66 function. Then, after all minimal symbols have been read,
67 regardless of whether they are installed or not, the cleanup
68 returned by this function should be run. */
69
70struct cleanup *make_cleanup_discard_minimal_symbols (void);
71
72/* Record a new minimal symbol. This is the "full" entry point;
73 simpler convenience entry points are also provided below.
74
75 This returns a new minimal symbol. It is ok to modify the returned
76 minimal symbol (though generally not necessary). It is not ok,
77 though, to stash the pointer anywhere; as minimal symbols may be
78 moved after creation. The memory for the returned minimal symbol
79 is still owned by the minsyms.c code, and should not be freed.
80
81 Arguments are:
82
83 NAME - the symbol's name
84 NAME_LEN - the length of the name
85 COPY_NAME - if true, the minsym code must make a copy of NAME. If
86 false, then NAME must be NUL-terminated, and must have a lifetime
87 that is at least as long as OBJFILE's lifetime.
88 ADDRESS - the address of the symbol
89 MS_TYPE - the type of the symbol
90 SECTION - the symbol's section
91 BFD_SECTION - the symbol's BFD section; used to find the
92 appropriate obj_section for the minimal symbol. This can be NULL.
93 OBJFILE - the objfile associated with the minimal symbol. */
c35384fb
TT
94
95struct minimal_symbol *prim_record_minimal_symbol_full
b19686e0
TT
96 (const char *name,
97 int name_len,
98 int copy_name,
99 CORE_ADDR address,
100 enum minimal_symbol_type ms_type,
c35384fb
TT
101 int section,
102 asection *bfd_section,
b19686e0
TT
103 struct objfile *objfile);
104
105/* Like prim_record_minimal_symbol_full, but:
106 - uses strlen to compute NAME_LEN,
107 - passes COPY_NAME = 0,
108 - passes SECTION = 0,
109 - and passes BFD_SECTION = NULL.
110
111 This variant does not return the new symbol. */
112
113void prim_record_minimal_symbol (const char *, CORE_ADDR,
114 enum minimal_symbol_type,
115 struct objfile *);
116
117/* Like prim_record_minimal_symbol_full, but:
118 - uses strlen to compute NAME_LEN,
119 - passes COPY_NAME = 0. */
c35384fb
TT
120
121struct minimal_symbol *prim_record_minimal_symbol_and_info
122 (const char *,
123 CORE_ADDR,
124 enum minimal_symbol_type,
125 int section,
126 asection *bfd_section,
127 struct objfile *);
128
b19686e0
TT
129/* Install the minimal symbols that have been collected into the given
130 objfile. After this is called, the cleanup returned by
131 make_cleanup_discard_minimal_symbols should be run in order to
132 clean up global state. */
133
134void install_minimal_symbols (struct objfile *);
135
136/* Create the terminating entry of OBJFILE's minimal symbol table.
137 If OBJFILE->msymbols is zero, allocate a single entry from
138 OBJFILE->objfile_obstack; otherwise, just initialize
139 OBJFILE->msymbols[OBJFILE->minimal_symbol_count]. */
140
141void terminate_minimal_symbol_table (struct objfile *objfile);
142
143/* Sort all the minimal symbols in OBJFILE. This should be only be
144 called after relocating symbols; it ensures that the minimal
145 symbols are properly sorted by address. */
146
147void msymbols_sort (struct objfile *objfile);
148
149\f
150
151/* Compute a hash code for the string argument. */
c35384fb
TT
152
153unsigned int msymbol_hash (const char *);
154
b19686e0
TT
155/* Like msymbol_hash, but compute a hash code that is compatible with
156 strcmp_iw. */
157
158unsigned int msymbol_hash_iw (const char *);
159
c35384fb
TT
160/* Compute the next hash value from previous HASH and the character C. This
161 is only a GDB in-memory computed value with no external files compatibility
162 requirements. */
163
164#define SYMBOL_HASH_NEXT(hash, c) \
165 ((hash) * 67 + tolower ((unsigned char) (c)) - 113)
166
b19686e0
TT
167\f
168
169/* Return the objfile that holds the minimal symbol SYM. Every
170 minimal symbols is held by some objfile; this will never return
171 NULL. */
172
c35384fb
TT
173struct objfile *msymbol_objfile (struct minimal_symbol *sym);
174
b19686e0
TT
175\f
176
177/* Look through all the current minimal symbol tables and find the
178 first minimal symbol that matches NAME. If OBJF is non-NULL, limit
179 the search to that objfile. If SFILE is non-NULL, the only file-scope
180 symbols considered will be from that source file (global symbols are
181 still preferred). Returns a pointer to the minimal symbol that
182 matches, or NULL if no match is found. */
183
c35384fb
TT
184struct minimal_symbol *lookup_minimal_symbol (const char *,
185 const char *,
186 struct objfile *);
187
b19686e0 188/* Find the minimal symbol named NAME, and return both the minsym
7cbd4a93 189 struct and its objfile. This only checks the linkage name. */
b19686e0 190
7cbd4a93 191struct bound_minimal_symbol lookup_minimal_symbol_and_objfile (const char *);
b19686e0
TT
192
193/* Look through all the current minimal symbol tables and find the
194 first minimal symbol that matches NAME and has text type. If OBJF
195 is non-NULL, limit the search to that objfile. Returns a pointer
196 to the minimal symbol that matches, or NULL if no match is found.
197
198 This function only searches the mangled (linkage) names. */
199
c35384fb
TT
200struct minimal_symbol *lookup_minimal_symbol_text (const char *,
201 struct objfile *);
202
b19686e0
TT
203/* Look through all the current minimal symbol tables and find the
204 first minimal symbol that matches NAME and is a solib trampoline.
205 If OBJF is non-NULL, limit the search to that objfile. Returns a
206 pointer to the minimal symbol that matches, or NULL if no match is
207 found.
208
209 This function only searches the mangled (linkage) names. */
210
c35384fb
TT
211struct minimal_symbol *lookup_minimal_symbol_solib_trampoline
212 (const char *,
213 struct objfile *);
214
b19686e0
TT
215/* Look through all the current minimal symbol tables and find the
216 first minimal symbol that matches NAME and PC. If OBJF is non-NULL,
217 limit the search to that objfile. Returns a pointer to the minimal
218 symbol that matches, or NULL if no match is found. */
219
c35384fb 220struct minimal_symbol *lookup_minimal_symbol_by_pc_name
b19686e0 221 (CORE_ADDR, const char *, struct objfile *);
c35384fb 222
b19686e0
TT
223/* Search through the minimal symbol table for each objfile and find
224 the symbol whose address is the largest address that is still less
225 than or equal to PC, and which matches SECTION.
c35384fb 226
b19686e0
TT
227 If SECTION is NULL, this uses the result of find_pc_section
228 instead.
229
7cbd4a93
TT
230 The result has a non-NULL 'minsym' member if such a symbol is
231 found, or NULL if PC is not in a suitable range. */
c35384fb 232
7cbd4a93 233struct bound_minimal_symbol lookup_minimal_symbol_by_pc_section
c35384fb
TT
234 (CORE_ADDR,
235 struct obj_section *);
236
b19686e0
TT
237/* Backward compatibility: search through the minimal symbol table
238 for a matching PC (no section given).
239
240 This is a wrapper that calls lookup_minimal_symbol_by_pc_section
241 with a NULL section argument. */
c35384fb 242
7cbd4a93 243struct bound_minimal_symbol lookup_minimal_symbol_by_pc (CORE_ADDR);
c35384fb 244
b19686e0
TT
245/* Iterate over all the minimal symbols in the objfile OBJF which
246 match NAME. Both the ordinary and demangled names of each symbol
247 are considered. The caller is responsible for canonicalizing NAME,
248 should that need to be done.
c35384fb 249
b19686e0
TT
250 For each matching symbol, CALLBACK is called with the symbol and
251 USER_DATA as arguments. */
c35384fb
TT
252
253void iterate_over_minimal_symbols (struct objfile *objf,
254 const char *name,
255 void (*callback) (struct minimal_symbol *,
256 void *),
257 void *user_data);
258
259#endif /* MINSYMS_H */
This page took 0.170839 seconds and 4 git commands to generate.