1 /* Minimal symbol table definitions for GDB.
3 Copyright (C) 2011-2012 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 /* This header declares most of the API for dealing with minimal
24 symbols and minimal symbol tables. A few things are declared
27 A minimal symbol is a symbol for which there is no direct debug
28 information. For example, for an ELF binary, minimal symbols are
29 created from the ELF symbol table.
31 For the definition of the minimal symbol structure, see struct
32 minimal_symbol in symtab.h.
34 Minimal symbols are stored in tables attached to an objfile; see
35 objfiles.h for details. Code should generally treat these tables
36 as opaque and use functions provided by minsyms.c to inspect them.
39 /* Prepare to start collecting minimal symbols. This should be called
40 by a symbol reader to initialize the minimal symbol module.
41 Currently, minimal symbol table creation is not reentrant; it
42 relies on global (static) variables in minsyms.c. */
44 void init_minimal_symbol_collection (void);
46 /* Return a cleanup which is used to clean up the global state left
47 over by minimal symbol creation. After calling
48 init_minimal_symbol_collection, a symbol reader should call this
49 function. Then, after all minimal symbols have been read,
50 regardless of whether they are installed or not, the cleanup
51 returned by this function should be run. */
53 struct cleanup *make_cleanup_discard_minimal_symbols (void);
55 /* Record a new minimal symbol. This is the "full" entry point;
56 simpler convenience entry points are also provided below.
58 This returns a new minimal symbol. It is ok to modify the returned
59 minimal symbol (though generally not necessary). It is not ok,
60 though, to stash the pointer anywhere; as minimal symbols may be
61 moved after creation. The memory for the returned minimal symbol
62 is still owned by the minsyms.c code, and should not be freed.
66 NAME - the symbol's name
67 NAME_LEN - the length of the name
68 COPY_NAME - if true, the minsym code must make a copy of NAME. If
69 false, then NAME must be NUL-terminated, and must have a lifetime
70 that is at least as long as OBJFILE's lifetime.
71 ADDRESS - the address of the symbol
72 MS_TYPE - the type of the symbol
73 SECTION - the symbol's section
74 BFD_SECTION - the symbol's BFD section; used to find the
75 appropriate obj_section for the minimal symbol. This can be NULL.
76 OBJFILE - the objfile associated with the minimal symbol. */
78 struct minimal_symbol *prim_record_minimal_symbol_full
83 enum minimal_symbol_type ms_type,
85 asection *bfd_section,
86 struct objfile *objfile);
88 /* Like prim_record_minimal_symbol_full, but:
89 - uses strlen to compute NAME_LEN,
90 - passes COPY_NAME = 0,
92 - and passes BFD_SECTION = NULL.
94 This variant does not return the new symbol. */
96 void prim_record_minimal_symbol (const char *, CORE_ADDR,
97 enum minimal_symbol_type,
100 /* Like prim_record_minimal_symbol_full, but:
101 - uses strlen to compute NAME_LEN,
102 - passes COPY_NAME = 0. */
104 struct minimal_symbol *prim_record_minimal_symbol_and_info
107 enum minimal_symbol_type,
109 asection *bfd_section,
112 /* Install the minimal symbols that have been collected into the given
113 objfile. After this is called, the cleanup returned by
114 make_cleanup_discard_minimal_symbols should be run in order to
115 clean up global state. */
117 void install_minimal_symbols (struct objfile *);
119 /* Create the terminating entry of OBJFILE's minimal symbol table.
120 If OBJFILE->msymbols is zero, allocate a single entry from
121 OBJFILE->objfile_obstack; otherwise, just initialize
122 OBJFILE->msymbols[OBJFILE->minimal_symbol_count]. */
124 void terminate_minimal_symbol_table (struct objfile *objfile);
126 /* Sort all the minimal symbols in OBJFILE. This should be only be
127 called after relocating symbols; it ensures that the minimal
128 symbols are properly sorted by address. */
130 void msymbols_sort (struct objfile *objfile);
134 /* Compute a hash code for the string argument. */
136 unsigned int msymbol_hash (const char *);
138 /* Like msymbol_hash, but compute a hash code that is compatible with
141 unsigned int msymbol_hash_iw (const char *);
143 /* Compute the next hash value from previous HASH and the character C. This
144 is only a GDB in-memory computed value with no external files compatibility
147 #define SYMBOL_HASH_NEXT(hash, c) \
148 ((hash) * 67 + tolower ((unsigned char) (c)) - 113)
152 /* Return the objfile that holds the minimal symbol SYM. Every
153 minimal symbols is held by some objfile; this will never return
156 struct objfile *msymbol_objfile (struct minimal_symbol *sym);
160 /* Look through all the current minimal symbol tables and find the
161 first minimal symbol that matches NAME. If OBJF is non-NULL, limit
162 the search to that objfile. If SFILE is non-NULL, the only file-scope
163 symbols considered will be from that source file (global symbols are
164 still preferred). Returns a pointer to the minimal symbol that
165 matches, or NULL if no match is found. */
167 struct minimal_symbol *lookup_minimal_symbol (const char *,
171 /* Find the minimal symbol named NAME, and return both the minsym
172 struct and its objfile. This only checks the linkage name. Sets
173 *OBJFILE_P and returns the minimal symbol, if it is found. If it
174 is not found, returns NULL. */
176 struct minimal_symbol *lookup_minimal_symbol_and_objfile (const char *,
179 /* Look through all the current minimal symbol tables and find the
180 first minimal symbol that matches NAME and has text type. If OBJF
181 is non-NULL, limit the search to that objfile. Returns a pointer
182 to the minimal symbol that matches, or NULL if no match is found.
184 This function only searches the mangled (linkage) names. */
186 struct minimal_symbol *lookup_minimal_symbol_text (const char *,
189 /* Look through all the current minimal symbol tables and find the
190 first minimal symbol that matches NAME and is a solib trampoline.
191 If OBJF is non-NULL, limit the search to that objfile. Returns a
192 pointer to the minimal symbol that matches, or NULL if no match is
195 This function only searches the mangled (linkage) names. */
197 struct minimal_symbol *lookup_minimal_symbol_solib_trampoline
201 /* Look through all the current minimal symbol tables and find the
202 first minimal symbol that matches NAME and PC. If OBJF is non-NULL,
203 limit the search to that objfile. Returns a pointer to the minimal
204 symbol that matches, or NULL if no match is found. */
206 struct minimal_symbol *lookup_minimal_symbol_by_pc_name
207 (CORE_ADDR, const char *, struct objfile *);
209 /* Search through the minimal symbol table for each objfile and find
210 the symbol whose address is the largest address that is still less
211 than or equal to PC, and which matches SECTION.
213 If SECTION is NULL, this uses the result of find_pc_section
216 Returns a pointer to the minimal symbol if such a symbol is found,
217 or NULL if PC is not in a suitable range. */
219 struct minimal_symbol *lookup_minimal_symbol_by_pc_section
221 struct obj_section *);
223 /* Backward compatibility: search through the minimal symbol table
224 for a matching PC (no section given).
226 This is a wrapper that calls lookup_minimal_symbol_by_pc_section
227 with a NULL section argument. */
229 struct minimal_symbol *lookup_minimal_symbol_by_pc (CORE_ADDR);
231 /* Check if PC is in a shared library trampoline code stub.
232 Return minimal symbol for the trampoline entry or NULL if PC is not
233 in a trampoline code stub. */
235 struct minimal_symbol *lookup_solib_trampoline_symbol_by_pc (CORE_ADDR);
237 /* Iterate over all the minimal symbols in the objfile OBJF which
238 match NAME. Both the ordinary and demangled names of each symbol
239 are considered. The caller is responsible for canonicalizing NAME,
240 should that need to be done.
242 For each matching symbol, CALLBACK is called with the symbol and
243 USER_DATA as arguments. */
245 void iterate_over_minimal_symbols (struct objfile *objf,
247 void (*callback) (struct minimal_symbol *,
251 #endif /* MINSYMS_H */