| 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 | /* 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 | |
| 61 | void 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 | |
| 70 | struct 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 | appropriate obj_section for the minimal symbol. This can be NULL. |
| 92 | OBJFILE - the objfile associated with the minimal symbol. */ |
| 93 | |
| 94 | struct minimal_symbol *prim_record_minimal_symbol_full |
| 95 | (const char *name, |
| 96 | int name_len, |
| 97 | int copy_name, |
| 98 | CORE_ADDR address, |
| 99 | enum minimal_symbol_type ms_type, |
| 100 | int section, |
| 101 | struct objfile *objfile); |
| 102 | |
| 103 | /* Like prim_record_minimal_symbol_full, but: |
| 104 | - uses strlen to compute NAME_LEN, |
| 105 | - passes COPY_NAME = 1, |
| 106 | - and passes a default SECTION, depending on the type |
| 107 | |
| 108 | This variant does not return the new symbol. */ |
| 109 | |
| 110 | void prim_record_minimal_symbol (const char *, CORE_ADDR, |
| 111 | enum minimal_symbol_type, |
| 112 | struct objfile *); |
| 113 | |
| 114 | /* Like prim_record_minimal_symbol_full, but: |
| 115 | - uses strlen to compute NAME_LEN, |
| 116 | - passes COPY_NAME = 1. */ |
| 117 | |
| 118 | struct minimal_symbol *prim_record_minimal_symbol_and_info |
| 119 | (const char *, |
| 120 | CORE_ADDR, |
| 121 | enum minimal_symbol_type, |
| 122 | int section, |
| 123 | struct objfile *); |
| 124 | |
| 125 | /* Install the minimal symbols that have been collected into the given |
| 126 | objfile. After this is called, the cleanup returned by |
| 127 | make_cleanup_discard_minimal_symbols should be run in order to |
| 128 | clean up global state. */ |
| 129 | |
| 130 | void install_minimal_symbols (struct objfile *); |
| 131 | |
| 132 | /* Create the terminating entry of OBJFILE's minimal symbol table. |
| 133 | If OBJFILE->msymbols is zero, allocate a single entry from |
| 134 | OBJFILE->objfile_obstack; otherwise, just initialize |
| 135 | OBJFILE->msymbols[OBJFILE->minimal_symbol_count]. */ |
| 136 | |
| 137 | void terminate_minimal_symbol_table (struct objfile *objfile); |
| 138 | |
| 139 | \f |
| 140 | |
| 141 | /* Compute a hash code for the string argument. */ |
| 142 | |
| 143 | unsigned int msymbol_hash (const char *); |
| 144 | |
| 145 | /* Like msymbol_hash, but compute a hash code that is compatible with |
| 146 | strcmp_iw. */ |
| 147 | |
| 148 | unsigned int msymbol_hash_iw (const char *); |
| 149 | |
| 150 | /* Compute the next hash value from previous HASH and the character C. This |
| 151 | is only a GDB in-memory computed value with no external files compatibility |
| 152 | requirements. */ |
| 153 | |
| 154 | #define SYMBOL_HASH_NEXT(hash, c) \ |
| 155 | ((hash) * 67 + tolower ((unsigned char) (c)) - 113) |
| 156 | |
| 157 | \f |
| 158 | |
| 159 | /* Look through all the current minimal symbol tables and find the |
| 160 | first minimal symbol that matches NAME. If OBJF is non-NULL, limit |
| 161 | the search to that objfile. If SFILE is non-NULL, the only |
| 162 | file-scope symbols considered will be from that source file (global |
| 163 | symbols are still preferred). Returns a bound minimal symbol that |
| 164 | matches, or an empty bound minimal symbol if no match is found. */ |
| 165 | |
| 166 | struct bound_minimal_symbol lookup_minimal_symbol (const char *, |
| 167 | const char *, |
| 168 | struct objfile *); |
| 169 | |
| 170 | /* Like lookup_minimal_symbol, but searches all files and |
| 171 | objfiles. */ |
| 172 | |
| 173 | struct bound_minimal_symbol lookup_bound_minimal_symbol (const char *); |
| 174 | |
| 175 | /* Find the minimal symbol named NAME, and return both the minsym |
| 176 | struct and its objfile. This only checks the linkage name. */ |
| 177 | |
| 178 | struct bound_minimal_symbol lookup_minimal_symbol_and_objfile (const char *); |
| 179 | |
| 180 | /* Look through all the current minimal symbol tables and find the |
| 181 | first minimal symbol that matches NAME and has text type. If OBJF |
| 182 | is non-NULL, limit the search to that objfile. Returns a bound |
| 183 | minimal symbol that matches, or an "empty" bound minimal symbol |
| 184 | otherwise. |
| 185 | |
| 186 | This function only searches the mangled (linkage) names. */ |
| 187 | |
| 188 | struct bound_minimal_symbol lookup_minimal_symbol_text (const char *, |
| 189 | struct objfile *); |
| 190 | |
| 191 | /* Look through all the current minimal symbol tables and find the |
| 192 | first minimal symbol that matches NAME and is a solib trampoline. |
| 193 | If OBJF is non-NULL, limit the search to that objfile. Returns a |
| 194 | pointer to the minimal symbol that matches, or NULL if no match is |
| 195 | found. |
| 196 | |
| 197 | This function only searches the mangled (linkage) names. */ |
| 198 | |
| 199 | struct bound_minimal_symbol lookup_minimal_symbol_solib_trampoline |
| 200 | (const char *, |
| 201 | struct objfile *); |
| 202 | |
| 203 | /* Look through all the current minimal symbol tables and find the |
| 204 | first minimal symbol that matches NAME and PC. If OBJF is non-NULL, |
| 205 | limit the search to that objfile. Returns a pointer to the minimal |
| 206 | symbol that matches, or NULL if no match is found. */ |
| 207 | |
| 208 | struct minimal_symbol *lookup_minimal_symbol_by_pc_name |
| 209 | (CORE_ADDR, const char *, struct objfile *); |
| 210 | |
| 211 | /* Search through the minimal symbol table for each objfile and find |
| 212 | the symbol whose address is the largest address that is still less |
| 213 | than or equal to PC, and which matches SECTION. |
| 214 | |
| 215 | If SECTION is NULL, this uses the result of find_pc_section |
| 216 | instead. |
| 217 | |
| 218 | The result has a non-NULL 'minsym' member if such a symbol is |
| 219 | found, or NULL if PC is not in a suitable range. */ |
| 220 | |
| 221 | struct bound_minimal_symbol lookup_minimal_symbol_by_pc_section |
| 222 | (CORE_ADDR, |
| 223 | struct obj_section *); |
| 224 | |
| 225 | /* Backward compatibility: search through the minimal symbol table |
| 226 | for a matching PC (no section given). |
| 227 | |
| 228 | This is a wrapper that calls lookup_minimal_symbol_by_pc_section |
| 229 | with a NULL section argument. */ |
| 230 | |
| 231 | struct bound_minimal_symbol lookup_minimal_symbol_by_pc (CORE_ADDR); |
| 232 | |
| 233 | /* Iterate over all the minimal symbols in the objfile OBJF which |
| 234 | match NAME. Both the ordinary and demangled names of each symbol |
| 235 | are considered. The caller is responsible for canonicalizing NAME, |
| 236 | should that need to be done. |
| 237 | |
| 238 | For each matching symbol, CALLBACK is called with the symbol and |
| 239 | USER_DATA as arguments. */ |
| 240 | |
| 241 | void iterate_over_minimal_symbols (struct objfile *objf, |
| 242 | const char *name, |
| 243 | void (*callback) (struct minimal_symbol *, |
| 244 | void *), |
| 245 | void *user_data); |
| 246 | |
| 247 | /* Compute the upper bound of MINSYM. The upper bound is the last |
| 248 | address thought to be part of the symbol. If the symbol has a |
| 249 | size, it is used. Otherwise use the lesser of the next minimal |
| 250 | symbol in the same section, or the end of the section, as the end |
| 251 | of the function. */ |
| 252 | |
| 253 | CORE_ADDR minimal_symbol_upper_bound (struct bound_minimal_symbol minsym); |
| 254 | |
| 255 | #endif /* MINSYMS_H */ |