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