GDB (API)
|
00001 /* GDB routines for manipulating the minimal symbol tables. 00002 Copyright (C) 1992-2013 Free Software Foundation, Inc. 00003 Contributed by Cygnus Support, using pieces from other GDB modules. 00004 00005 This file is part of GDB. 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00019 00020 00021 /* This file contains support routines for creating, manipulating, and 00022 destroying minimal symbol tables. 00023 00024 Minimal symbol tables are used to hold some very basic information about 00025 all defined global symbols (text, data, bss, abs, etc). The only two 00026 required pieces of information are the symbol's name and the address 00027 associated with that symbol. 00028 00029 In many cases, even if a file was compiled with no special options for 00030 debugging at all, as long as was not stripped it will contain sufficient 00031 information to build useful minimal symbol tables using this structure. 00032 00033 Even when a file contains enough debugging information to build a full 00034 symbol table, these minimal symbols are still useful for quickly mapping 00035 between names and addresses, and vice versa. They are also sometimes used 00036 to figure out what full symbol table entries need to be read in. */ 00037 00038 00039 #include "defs.h" 00040 #include <ctype.h> 00041 #include "gdb_string.h" 00042 #include "symtab.h" 00043 #include "bfd.h" 00044 #include "filenames.h" 00045 #include "symfile.h" 00046 #include "objfiles.h" 00047 #include "demangle.h" 00048 #include "value.h" 00049 #include "cp-abi.h" 00050 #include "target.h" 00051 #include "cp-support.h" 00052 #include "language.h" 00053 #include "cli/cli-utils.h" 00054 00055 /* Accumulate the minimal symbols for each objfile in bunches of BUNCH_SIZE. 00056 At the end, copy them all into one newly allocated location on an objfile's 00057 symbol obstack. */ 00058 00059 #define BUNCH_SIZE 127 00060 00061 struct msym_bunch 00062 { 00063 struct msym_bunch *next; 00064 struct minimal_symbol contents[BUNCH_SIZE]; 00065 }; 00066 00067 /* Bunch currently being filled up. 00068 The next field points to chain of filled bunches. */ 00069 00070 static struct msym_bunch *msym_bunch; 00071 00072 /* Number of slots filled in current bunch. */ 00073 00074 static int msym_bunch_index; 00075 00076 /* Total number of minimal symbols recorded so far for the objfile. */ 00077 00078 static int msym_count; 00079 00080 /* See minsyms.h. */ 00081 00082 unsigned int 00083 msymbol_hash_iw (const char *string) 00084 { 00085 unsigned int hash = 0; 00086 00087 while (*string && *string != '(') 00088 { 00089 string = skip_spaces_const (string); 00090 if (*string && *string != '(') 00091 { 00092 hash = SYMBOL_HASH_NEXT (hash, *string); 00093 ++string; 00094 } 00095 } 00096 return hash; 00097 } 00098 00099 /* See minsyms.h. */ 00100 00101 unsigned int 00102 msymbol_hash (const char *string) 00103 { 00104 unsigned int hash = 0; 00105 00106 for (; *string; ++string) 00107 hash = SYMBOL_HASH_NEXT (hash, *string); 00108 return hash; 00109 } 00110 00111 /* Add the minimal symbol SYM to an objfile's minsym hash table, TABLE. */ 00112 static void 00113 add_minsym_to_hash_table (struct minimal_symbol *sym, 00114 struct minimal_symbol **table) 00115 { 00116 if (sym->hash_next == NULL) 00117 { 00118 unsigned int hash 00119 = msymbol_hash (SYMBOL_LINKAGE_NAME (sym)) % MINIMAL_SYMBOL_HASH_SIZE; 00120 00121 sym->hash_next = table[hash]; 00122 table[hash] = sym; 00123 } 00124 } 00125 00126 /* Add the minimal symbol SYM to an objfile's minsym demangled hash table, 00127 TABLE. */ 00128 static void 00129 add_minsym_to_demangled_hash_table (struct minimal_symbol *sym, 00130 struct minimal_symbol **table) 00131 { 00132 if (sym->demangled_hash_next == NULL) 00133 { 00134 unsigned int hash = msymbol_hash_iw (SYMBOL_SEARCH_NAME (sym)) 00135 % MINIMAL_SYMBOL_HASH_SIZE; 00136 00137 sym->demangled_hash_next = table[hash]; 00138 table[hash] = sym; 00139 } 00140 } 00141 00142 /* Look through all the current minimal symbol tables and find the 00143 first minimal symbol that matches NAME. If OBJF is non-NULL, limit 00144 the search to that objfile. If SFILE is non-NULL, the only file-scope 00145 symbols considered will be from that source file (global symbols are 00146 still preferred). Returns a pointer to the minimal symbol that 00147 matches, or NULL if no match is found. 00148 00149 Note: One instance where there may be duplicate minimal symbols with 00150 the same name is when the symbol tables for a shared library and the 00151 symbol tables for an executable contain global symbols with the same 00152 names (the dynamic linker deals with the duplication). 00153 00154 It's also possible to have minimal symbols with different mangled 00155 names, but identical demangled names. For example, the GNU C++ v3 00156 ABI requires the generation of two (or perhaps three) copies of 00157 constructor functions --- "in-charge", "not-in-charge", and 00158 "allocate" copies; destructors may be duplicated as well. 00159 Obviously, there must be distinct mangled names for each of these, 00160 but the demangled names are all the same: S::S or S::~S. */ 00161 00162 static struct bound_minimal_symbol 00163 lookup_minimal_symbol_internal (const char *name, const char *sfile, 00164 struct objfile *objf) 00165 { 00166 struct objfile *objfile; 00167 struct bound_minimal_symbol found_symbol = { NULL, NULL }; 00168 struct bound_minimal_symbol found_file_symbol = { NULL, NULL }; 00169 struct bound_minimal_symbol trampoline_symbol = { NULL, NULL }; 00170 00171 unsigned int hash = msymbol_hash (name) % MINIMAL_SYMBOL_HASH_SIZE; 00172 unsigned int dem_hash = msymbol_hash_iw (name) % MINIMAL_SYMBOL_HASH_SIZE; 00173 00174 int needtofreename = 0; 00175 const char *modified_name; 00176 00177 if (sfile != NULL) 00178 sfile = lbasename (sfile); 00179 00180 /* For C++, canonicalize the input name. */ 00181 modified_name = name; 00182 if (current_language->la_language == language_cplus) 00183 { 00184 char *cname = cp_canonicalize_string (name); 00185 00186 if (cname) 00187 { 00188 modified_name = cname; 00189 needtofreename = 1; 00190 } 00191 } 00192 00193 for (objfile = object_files; 00194 objfile != NULL && found_symbol.minsym == NULL; 00195 objfile = objfile->next) 00196 { 00197 struct minimal_symbol *msymbol; 00198 00199 if (objf == NULL || objf == objfile 00200 || objf == objfile->separate_debug_objfile_backlink) 00201 { 00202 /* Do two passes: the first over the ordinary hash table, 00203 and the second over the demangled hash table. */ 00204 int pass; 00205 00206 for (pass = 1; pass <= 2 && found_symbol.minsym == NULL; pass++) 00207 { 00208 /* Select hash list according to pass. */ 00209 if (pass == 1) 00210 msymbol = objfile->msymbol_hash[hash]; 00211 else 00212 msymbol = objfile->msymbol_demangled_hash[dem_hash]; 00213 00214 while (msymbol != NULL && found_symbol.minsym == NULL) 00215 { 00216 int match; 00217 00218 if (pass == 1) 00219 { 00220 int (*cmp) (const char *, const char *); 00221 00222 cmp = (case_sensitivity == case_sensitive_on 00223 ? strcmp : strcasecmp); 00224 match = cmp (SYMBOL_LINKAGE_NAME (msymbol), 00225 modified_name) == 0; 00226 } 00227 else 00228 { 00229 /* The function respects CASE_SENSITIVITY. */ 00230 match = SYMBOL_MATCHES_SEARCH_NAME (msymbol, 00231 modified_name); 00232 } 00233 00234 if (match) 00235 { 00236 switch (MSYMBOL_TYPE (msymbol)) 00237 { 00238 case mst_file_text: 00239 case mst_file_data: 00240 case mst_file_bss: 00241 if (sfile == NULL 00242 || filename_cmp (msymbol->filename, sfile) == 0) 00243 { 00244 found_file_symbol.minsym = msymbol; 00245 found_file_symbol.objfile = objfile; 00246 } 00247 break; 00248 00249 case mst_solib_trampoline: 00250 00251 /* If a trampoline symbol is found, we prefer to 00252 keep looking for the *real* symbol. If the 00253 actual symbol is not found, then we'll use the 00254 trampoline entry. */ 00255 if (trampoline_symbol.minsym == NULL) 00256 { 00257 trampoline_symbol.minsym = msymbol; 00258 trampoline_symbol.objfile = objfile; 00259 } 00260 break; 00261 00262 case mst_unknown: 00263 default: 00264 found_symbol.minsym = msymbol; 00265 found_symbol.objfile = objfile; 00266 break; 00267 } 00268 } 00269 00270 /* Find the next symbol on the hash chain. */ 00271 if (pass == 1) 00272 msymbol = msymbol->hash_next; 00273 else 00274 msymbol = msymbol->demangled_hash_next; 00275 } 00276 } 00277 } 00278 } 00279 00280 if (needtofreename) 00281 xfree ((void *) modified_name); 00282 00283 /* External symbols are best. */ 00284 if (found_symbol.minsym != NULL) 00285 return found_symbol; 00286 00287 /* File-local symbols are next best. */ 00288 if (found_file_symbol.minsym != NULL) 00289 return found_file_symbol; 00290 00291 /* Symbols for shared library trampolines are next best. */ 00292 return trampoline_symbol; 00293 } 00294 00295 /* See minsyms.h. */ 00296 00297 struct minimal_symbol * 00298 lookup_minimal_symbol (const char *name, const char *sfile, 00299 struct objfile *objf) 00300 { 00301 struct bound_minimal_symbol bms = lookup_minimal_symbol_internal (name, 00302 sfile, 00303 objf); 00304 00305 return bms.minsym; 00306 } 00307 00308 /* See minsyms.h. */ 00309 00310 struct bound_minimal_symbol 00311 lookup_bound_minimal_symbol (const char *name) 00312 { 00313 return lookup_minimal_symbol_internal (name, NULL, NULL); 00314 } 00315 00316 /* See minsyms.h. */ 00317 00318 void 00319 iterate_over_minimal_symbols (struct objfile *objf, const char *name, 00320 void (*callback) (struct minimal_symbol *, 00321 void *), 00322 void *user_data) 00323 { 00324 unsigned int hash; 00325 struct minimal_symbol *iter; 00326 int (*cmp) (const char *, const char *); 00327 00328 /* The first pass is over the ordinary hash table. */ 00329 hash = msymbol_hash (name) % MINIMAL_SYMBOL_HASH_SIZE; 00330 iter = objf->msymbol_hash[hash]; 00331 cmp = (case_sensitivity == case_sensitive_on ? strcmp : strcasecmp); 00332 while (iter) 00333 { 00334 if (cmp (SYMBOL_LINKAGE_NAME (iter), name) == 0) 00335 (*callback) (iter, user_data); 00336 iter = iter->hash_next; 00337 } 00338 00339 /* The second pass is over the demangled table. */ 00340 hash = msymbol_hash_iw (name) % MINIMAL_SYMBOL_HASH_SIZE; 00341 iter = objf->msymbol_demangled_hash[hash]; 00342 while (iter) 00343 { 00344 if (SYMBOL_MATCHES_SEARCH_NAME (iter, name)) 00345 (*callback) (iter, user_data); 00346 iter = iter->demangled_hash_next; 00347 } 00348 } 00349 00350 /* See minsyms.h. */ 00351 00352 struct minimal_symbol * 00353 lookup_minimal_symbol_text (const char *name, struct objfile *objf) 00354 { 00355 struct objfile *objfile; 00356 struct minimal_symbol *msymbol; 00357 struct minimal_symbol *found_symbol = NULL; 00358 struct minimal_symbol *found_file_symbol = NULL; 00359 00360 unsigned int hash = msymbol_hash (name) % MINIMAL_SYMBOL_HASH_SIZE; 00361 00362 for (objfile = object_files; 00363 objfile != NULL && found_symbol == NULL; 00364 objfile = objfile->next) 00365 { 00366 if (objf == NULL || objf == objfile 00367 || objf == objfile->separate_debug_objfile_backlink) 00368 { 00369 for (msymbol = objfile->msymbol_hash[hash]; 00370 msymbol != NULL && found_symbol == NULL; 00371 msymbol = msymbol->hash_next) 00372 { 00373 if (strcmp (SYMBOL_LINKAGE_NAME (msymbol), name) == 0 && 00374 (MSYMBOL_TYPE (msymbol) == mst_text 00375 || MSYMBOL_TYPE (msymbol) == mst_text_gnu_ifunc 00376 || MSYMBOL_TYPE (msymbol) == mst_file_text)) 00377 { 00378 switch (MSYMBOL_TYPE (msymbol)) 00379 { 00380 case mst_file_text: 00381 found_file_symbol = msymbol; 00382 break; 00383 default: 00384 found_symbol = msymbol; 00385 break; 00386 } 00387 } 00388 } 00389 } 00390 } 00391 /* External symbols are best. */ 00392 if (found_symbol) 00393 return found_symbol; 00394 00395 /* File-local symbols are next best. */ 00396 if (found_file_symbol) 00397 return found_file_symbol; 00398 00399 return NULL; 00400 } 00401 00402 /* See minsyms.h. */ 00403 00404 struct minimal_symbol * 00405 lookup_minimal_symbol_by_pc_name (CORE_ADDR pc, const char *name, 00406 struct objfile *objf) 00407 { 00408 struct objfile *objfile; 00409 struct minimal_symbol *msymbol; 00410 00411 unsigned int hash = msymbol_hash (name) % MINIMAL_SYMBOL_HASH_SIZE; 00412 00413 for (objfile = object_files; 00414 objfile != NULL; 00415 objfile = objfile->next) 00416 { 00417 if (objf == NULL || objf == objfile 00418 || objf == objfile->separate_debug_objfile_backlink) 00419 { 00420 for (msymbol = objfile->msymbol_hash[hash]; 00421 msymbol != NULL; 00422 msymbol = msymbol->hash_next) 00423 { 00424 if (SYMBOL_VALUE_ADDRESS (msymbol) == pc 00425 && strcmp (SYMBOL_LINKAGE_NAME (msymbol), name) == 0) 00426 return msymbol; 00427 } 00428 } 00429 } 00430 00431 return NULL; 00432 } 00433 00434 /* See minsyms.h. */ 00435 00436 struct minimal_symbol * 00437 lookup_minimal_symbol_solib_trampoline (const char *name, 00438 struct objfile *objf) 00439 { 00440 struct objfile *objfile; 00441 struct minimal_symbol *msymbol; 00442 struct minimal_symbol *found_symbol = NULL; 00443 00444 unsigned int hash = msymbol_hash (name) % MINIMAL_SYMBOL_HASH_SIZE; 00445 00446 for (objfile = object_files; 00447 objfile != NULL && found_symbol == NULL; 00448 objfile = objfile->next) 00449 { 00450 if (objf == NULL || objf == objfile 00451 || objf == objfile->separate_debug_objfile_backlink) 00452 { 00453 for (msymbol = objfile->msymbol_hash[hash]; 00454 msymbol != NULL && found_symbol == NULL; 00455 msymbol = msymbol->hash_next) 00456 { 00457 if (strcmp (SYMBOL_LINKAGE_NAME (msymbol), name) == 0 && 00458 MSYMBOL_TYPE (msymbol) == mst_solib_trampoline) 00459 return msymbol; 00460 } 00461 } 00462 } 00463 00464 return NULL; 00465 } 00466 00467 /* Search through the minimal symbol table for each objfile and find 00468 the symbol whose address is the largest address that is still less 00469 than or equal to PC, and matches SECTION (which is not NULL). 00470 Returns a pointer to the minimal symbol if such a symbol is found, 00471 or NULL if PC is not in a suitable range. 00472 Note that we need to look through ALL the minimal symbol tables 00473 before deciding on the symbol that comes closest to the specified PC. 00474 This is because objfiles can overlap, for example objfile A has .text 00475 at 0x100 and .data at 0x40000 and objfile B has .text at 0x234 and 00476 .data at 0x40048. 00477 00478 If WANT_TRAMPOLINE is set, prefer mst_solib_trampoline symbols when 00479 there are text and trampoline symbols at the same address. 00480 Otherwise prefer mst_text symbols. */ 00481 00482 static struct bound_minimal_symbol 00483 lookup_minimal_symbol_by_pc_section_1 (CORE_ADDR pc, 00484 struct obj_section *section, 00485 int want_trampoline) 00486 { 00487 int lo; 00488 int hi; 00489 int new; 00490 struct objfile *objfile; 00491 struct minimal_symbol *msymbol; 00492 struct minimal_symbol *best_symbol = NULL; 00493 struct objfile *best_objfile = NULL; 00494 struct bound_minimal_symbol result; 00495 enum minimal_symbol_type want_type, other_type; 00496 00497 want_type = want_trampoline ? mst_solib_trampoline : mst_text; 00498 other_type = want_trampoline ? mst_text : mst_solib_trampoline; 00499 00500 /* We can not require the symbol found to be in section, because 00501 e.g. IRIX 6.5 mdebug relies on this code returning an absolute 00502 symbol - but find_pc_section won't return an absolute section and 00503 hence the code below would skip over absolute symbols. We can 00504 still take advantage of the call to find_pc_section, though - the 00505 object file still must match. In case we have separate debug 00506 files, search both the file and its separate debug file. There's 00507 no telling which one will have the minimal symbols. */ 00508 00509 gdb_assert (section != NULL); 00510 00511 for (objfile = section->objfile; 00512 objfile != NULL; 00513 objfile = objfile_separate_debug_iterate (section->objfile, objfile)) 00514 { 00515 /* If this objfile has a minimal symbol table, go search it using 00516 a binary search. Note that a minimal symbol table always consists 00517 of at least two symbols, a "real" symbol and the terminating 00518 "null symbol". If there are no real symbols, then there is no 00519 minimal symbol table at all. */ 00520 00521 if (objfile->minimal_symbol_count > 0) 00522 { 00523 int best_zero_sized = -1; 00524 00525 msymbol = objfile->msymbols; 00526 lo = 0; 00527 hi = objfile->minimal_symbol_count - 1; 00528 00529 /* This code assumes that the minimal symbols are sorted by 00530 ascending address values. If the pc value is greater than or 00531 equal to the first symbol's address, then some symbol in this 00532 minimal symbol table is a suitable candidate for being the 00533 "best" symbol. This includes the last real symbol, for cases 00534 where the pc value is larger than any address in this vector. 00535 00536 By iterating until the address associated with the current 00537 hi index (the endpoint of the test interval) is less than 00538 or equal to the desired pc value, we accomplish two things: 00539 (1) the case where the pc value is larger than any minimal 00540 symbol address is trivially solved, (2) the address associated 00541 with the hi index is always the one we want when the interation 00542 terminates. In essence, we are iterating the test interval 00543 down until the pc value is pushed out of it from the high end. 00544 00545 Warning: this code is trickier than it would appear at first. */ 00546 00547 /* Should also require that pc is <= end of objfile. FIXME! */ 00548 if (pc >= SYMBOL_VALUE_ADDRESS (&msymbol[lo])) 00549 { 00550 while (SYMBOL_VALUE_ADDRESS (&msymbol[hi]) > pc) 00551 { 00552 /* pc is still strictly less than highest address. */ 00553 /* Note "new" will always be >= lo. */ 00554 new = (lo + hi) / 2; 00555 if ((SYMBOL_VALUE_ADDRESS (&msymbol[new]) >= pc) || 00556 (lo == new)) 00557 { 00558 hi = new; 00559 } 00560 else 00561 { 00562 lo = new; 00563 } 00564 } 00565 00566 /* If we have multiple symbols at the same address, we want 00567 hi to point to the last one. That way we can find the 00568 right symbol if it has an index greater than hi. */ 00569 while (hi < objfile->minimal_symbol_count - 1 00570 && (SYMBOL_VALUE_ADDRESS (&msymbol[hi]) 00571 == SYMBOL_VALUE_ADDRESS (&msymbol[hi + 1]))) 00572 hi++; 00573 00574 /* Skip various undesirable symbols. */ 00575 while (hi >= 0) 00576 { 00577 /* Skip any absolute symbols. This is apparently 00578 what adb and dbx do, and is needed for the CM-5. 00579 There are two known possible problems: (1) on 00580 ELF, apparently end, edata, etc. are absolute. 00581 Not sure ignoring them here is a big deal, but if 00582 we want to use them, the fix would go in 00583 elfread.c. (2) I think shared library entry 00584 points on the NeXT are absolute. If we want 00585 special handling for this it probably should be 00586 triggered by a special mst_abs_or_lib or some 00587 such. */ 00588 00589 if (MSYMBOL_TYPE (&msymbol[hi]) == mst_abs) 00590 { 00591 hi--; 00592 continue; 00593 } 00594 00595 /* If SECTION was specified, skip any symbol from 00596 wrong section. */ 00597 if (section 00598 /* Some types of debug info, such as COFF, 00599 don't fill the bfd_section member, so don't 00600 throw away symbols on those platforms. */ 00601 && SYMBOL_OBJ_SECTION (objfile, &msymbol[hi]) != NULL 00602 && (!matching_obj_sections 00603 (SYMBOL_OBJ_SECTION (objfile, &msymbol[hi]), 00604 section))) 00605 { 00606 hi--; 00607 continue; 00608 } 00609 00610 /* If we are looking for a trampoline and this is a 00611 text symbol, or the other way around, check the 00612 preceding symbol too. If they are otherwise 00613 identical prefer that one. */ 00614 if (hi > 0 00615 && MSYMBOL_TYPE (&msymbol[hi]) == other_type 00616 && MSYMBOL_TYPE (&msymbol[hi - 1]) == want_type 00617 && (MSYMBOL_SIZE (&msymbol[hi]) 00618 == MSYMBOL_SIZE (&msymbol[hi - 1])) 00619 && (SYMBOL_VALUE_ADDRESS (&msymbol[hi]) 00620 == SYMBOL_VALUE_ADDRESS (&msymbol[hi - 1])) 00621 && (SYMBOL_OBJ_SECTION (objfile, &msymbol[hi]) 00622 == SYMBOL_OBJ_SECTION (objfile, &msymbol[hi - 1]))) 00623 { 00624 hi--; 00625 continue; 00626 } 00627 00628 /* If the minimal symbol has a zero size, save it 00629 but keep scanning backwards looking for one with 00630 a non-zero size. A zero size may mean that the 00631 symbol isn't an object or function (e.g. a 00632 label), or it may just mean that the size was not 00633 specified. */ 00634 if (MSYMBOL_SIZE (&msymbol[hi]) == 0 00635 && best_zero_sized == -1) 00636 { 00637 best_zero_sized = hi; 00638 hi--; 00639 continue; 00640 } 00641 00642 /* If we are past the end of the current symbol, try 00643 the previous symbol if it has a larger overlapping 00644 size. This happens on i686-pc-linux-gnu with glibc; 00645 the nocancel variants of system calls are inside 00646 the cancellable variants, but both have sizes. */ 00647 if (hi > 0 00648 && MSYMBOL_SIZE (&msymbol[hi]) != 0 00649 && pc >= (SYMBOL_VALUE_ADDRESS (&msymbol[hi]) 00650 + MSYMBOL_SIZE (&msymbol[hi])) 00651 && pc < (SYMBOL_VALUE_ADDRESS (&msymbol[hi - 1]) 00652 + MSYMBOL_SIZE (&msymbol[hi - 1]))) 00653 { 00654 hi--; 00655 continue; 00656 } 00657 00658 /* Otherwise, this symbol must be as good as we're going 00659 to get. */ 00660 break; 00661 } 00662 00663 /* If HI has a zero size, and best_zero_sized is set, 00664 then we had two or more zero-sized symbols; prefer 00665 the first one we found (which may have a higher 00666 address). Also, if we ran off the end, be sure 00667 to back up. */ 00668 if (best_zero_sized != -1 00669 && (hi < 0 || MSYMBOL_SIZE (&msymbol[hi]) == 0)) 00670 hi = best_zero_sized; 00671 00672 /* If the minimal symbol has a non-zero size, and this 00673 PC appears to be outside the symbol's contents, then 00674 refuse to use this symbol. If we found a zero-sized 00675 symbol with an address greater than this symbol's, 00676 use that instead. We assume that if symbols have 00677 specified sizes, they do not overlap. */ 00678 00679 if (hi >= 0 00680 && MSYMBOL_SIZE (&msymbol[hi]) != 0 00681 && pc >= (SYMBOL_VALUE_ADDRESS (&msymbol[hi]) 00682 + MSYMBOL_SIZE (&msymbol[hi]))) 00683 { 00684 if (best_zero_sized != -1) 00685 hi = best_zero_sized; 00686 else 00687 /* Go on to the next object file. */ 00688 continue; 00689 } 00690 00691 /* The minimal symbol indexed by hi now is the best one in this 00692 objfile's minimal symbol table. See if it is the best one 00693 overall. */ 00694 00695 if (hi >= 0 00696 && ((best_symbol == NULL) || 00697 (SYMBOL_VALUE_ADDRESS (best_symbol) < 00698 SYMBOL_VALUE_ADDRESS (&msymbol[hi])))) 00699 { 00700 best_symbol = &msymbol[hi]; 00701 best_objfile = objfile; 00702 } 00703 } 00704 } 00705 } 00706 00707 result.minsym = best_symbol; 00708 result.objfile = best_objfile; 00709 return result; 00710 } 00711 00712 struct bound_minimal_symbol 00713 lookup_minimal_symbol_by_pc_section (CORE_ADDR pc, struct obj_section *section) 00714 { 00715 if (section == NULL) 00716 { 00717 /* NOTE: cagney/2004-01-27: This was using find_pc_mapped_section to 00718 force the section but that (well unless you're doing overlay 00719 debugging) always returns NULL making the call somewhat useless. */ 00720 section = find_pc_section (pc); 00721 if (section == NULL) 00722 { 00723 struct bound_minimal_symbol result; 00724 00725 memset (&result, 0, sizeof (result)); 00726 return result; 00727 } 00728 } 00729 return lookup_minimal_symbol_by_pc_section_1 (pc, section, 0); 00730 } 00731 00732 /* See minsyms.h. */ 00733 00734 struct bound_minimal_symbol 00735 lookup_minimal_symbol_by_pc (CORE_ADDR pc) 00736 { 00737 struct obj_section *section = find_pc_section (pc); 00738 00739 if (section == NULL) 00740 { 00741 struct bound_minimal_symbol result; 00742 00743 memset (&result, 0, sizeof (result)); 00744 return result; 00745 } 00746 return lookup_minimal_symbol_by_pc_section_1 (pc, section, 0); 00747 } 00748 00749 /* Return non-zero iff PC is in an STT_GNU_IFUNC function resolver. */ 00750 00751 int 00752 in_gnu_ifunc_stub (CORE_ADDR pc) 00753 { 00754 struct bound_minimal_symbol msymbol = lookup_minimal_symbol_by_pc (pc); 00755 00756 return msymbol.minsym && MSYMBOL_TYPE (msymbol.minsym) == mst_text_gnu_ifunc; 00757 } 00758 00759 /* See elf_gnu_ifunc_resolve_addr for its real implementation. */ 00760 00761 static CORE_ADDR 00762 stub_gnu_ifunc_resolve_addr (struct gdbarch *gdbarch, CORE_ADDR pc) 00763 { 00764 error (_("GDB cannot resolve STT_GNU_IFUNC symbol at address %s without " 00765 "the ELF support compiled in."), 00766 paddress (gdbarch, pc)); 00767 } 00768 00769 /* See elf_gnu_ifunc_resolve_name for its real implementation. */ 00770 00771 static int 00772 stub_gnu_ifunc_resolve_name (const char *function_name, 00773 CORE_ADDR *function_address_p) 00774 { 00775 error (_("GDB cannot resolve STT_GNU_IFUNC symbol \"%s\" without " 00776 "the ELF support compiled in."), 00777 function_name); 00778 } 00779 00780 /* See elf_gnu_ifunc_resolver_stop for its real implementation. */ 00781 00782 static void 00783 stub_gnu_ifunc_resolver_stop (struct breakpoint *b) 00784 { 00785 internal_error (__FILE__, __LINE__, 00786 _("elf_gnu_ifunc_resolver_stop cannot be reached.")); 00787 } 00788 00789 /* See elf_gnu_ifunc_resolver_return_stop for its real implementation. */ 00790 00791 static void 00792 stub_gnu_ifunc_resolver_return_stop (struct breakpoint *b) 00793 { 00794 internal_error (__FILE__, __LINE__, 00795 _("elf_gnu_ifunc_resolver_return_stop cannot be reached.")); 00796 } 00797 00798 /* See elf_gnu_ifunc_fns for its real implementation. */ 00799 00800 static const struct gnu_ifunc_fns stub_gnu_ifunc_fns = 00801 { 00802 stub_gnu_ifunc_resolve_addr, 00803 stub_gnu_ifunc_resolve_name, 00804 stub_gnu_ifunc_resolver_stop, 00805 stub_gnu_ifunc_resolver_return_stop, 00806 }; 00807 00808 /* A placeholder for &elf_gnu_ifunc_fns. */ 00809 00810 const struct gnu_ifunc_fns *gnu_ifunc_fns_p = &stub_gnu_ifunc_fns; 00811 00812 /* See minsyms.h. */ 00813 00814 struct bound_minimal_symbol 00815 lookup_minimal_symbol_and_objfile (const char *name) 00816 { 00817 struct bound_minimal_symbol result; 00818 struct objfile *objfile; 00819 unsigned int hash = msymbol_hash (name) % MINIMAL_SYMBOL_HASH_SIZE; 00820 00821 ALL_OBJFILES (objfile) 00822 { 00823 struct minimal_symbol *msym; 00824 00825 for (msym = objfile->msymbol_hash[hash]; 00826 msym != NULL; 00827 msym = msym->hash_next) 00828 { 00829 if (strcmp (SYMBOL_LINKAGE_NAME (msym), name) == 0) 00830 { 00831 result.minsym = msym; 00832 result.objfile = objfile; 00833 return result; 00834 } 00835 } 00836 } 00837 00838 memset (&result, 0, sizeof (result)); 00839 return result; 00840 } 00841 00842 00843 /* Return leading symbol character for a BFD. If BFD is NULL, 00844 return the leading symbol character from the main objfile. */ 00845 00846 static int get_symbol_leading_char (bfd *); 00847 00848 static int 00849 get_symbol_leading_char (bfd *abfd) 00850 { 00851 if (abfd != NULL) 00852 return bfd_get_symbol_leading_char (abfd); 00853 if (symfile_objfile != NULL && symfile_objfile->obfd != NULL) 00854 return bfd_get_symbol_leading_char (symfile_objfile->obfd); 00855 return 0; 00856 } 00857 00858 /* See minsyms.h. */ 00859 00860 void 00861 init_minimal_symbol_collection (void) 00862 { 00863 msym_count = 0; 00864 msym_bunch = NULL; 00865 /* Note that presetting msym_bunch_index to BUNCH_SIZE causes the 00866 first call to save a minimal symbol to allocate the memory for 00867 the first bunch. */ 00868 msym_bunch_index = BUNCH_SIZE; 00869 } 00870 00871 /* See minsyms.h. */ 00872 00873 void 00874 prim_record_minimal_symbol (const char *name, CORE_ADDR address, 00875 enum minimal_symbol_type ms_type, 00876 struct objfile *objfile) 00877 { 00878 int section; 00879 00880 switch (ms_type) 00881 { 00882 case mst_text: 00883 case mst_text_gnu_ifunc: 00884 case mst_file_text: 00885 case mst_solib_trampoline: 00886 section = SECT_OFF_TEXT (objfile); 00887 break; 00888 case mst_data: 00889 case mst_file_data: 00890 section = SECT_OFF_DATA (objfile); 00891 break; 00892 case mst_bss: 00893 case mst_file_bss: 00894 section = SECT_OFF_BSS (objfile); 00895 break; 00896 default: 00897 section = -1; 00898 } 00899 00900 prim_record_minimal_symbol_and_info (name, address, ms_type, 00901 section, objfile); 00902 } 00903 00904 /* See minsyms.h. */ 00905 00906 struct minimal_symbol * 00907 prim_record_minimal_symbol_full (const char *name, int name_len, int copy_name, 00908 CORE_ADDR address, 00909 enum minimal_symbol_type ms_type, 00910 int section, 00911 struct objfile *objfile) 00912 { 00913 struct obj_section *obj_section; 00914 struct msym_bunch *new; 00915 struct minimal_symbol *msymbol; 00916 00917 /* Don't put gcc_compiled, __gnu_compiled_cplus, and friends into 00918 the minimal symbols, because if there is also another symbol 00919 at the same address (e.g. the first function of the file), 00920 lookup_minimal_symbol_by_pc would have no way of getting the 00921 right one. */ 00922 if (ms_type == mst_file_text && name[0] == 'g' 00923 && (strcmp (name, GCC_COMPILED_FLAG_SYMBOL) == 0 00924 || strcmp (name, GCC2_COMPILED_FLAG_SYMBOL) == 0)) 00925 return (NULL); 00926 00927 /* It's safe to strip the leading char here once, since the name 00928 is also stored stripped in the minimal symbol table. */ 00929 if (name[0] == get_symbol_leading_char (objfile->obfd)) 00930 { 00931 ++name; 00932 --name_len; 00933 } 00934 00935 if (ms_type == mst_file_text && strncmp (name, "__gnu_compiled", 14) == 0) 00936 return (NULL); 00937 00938 if (msym_bunch_index == BUNCH_SIZE) 00939 { 00940 new = XCALLOC (1, struct msym_bunch); 00941 msym_bunch_index = 0; 00942 new->next = msym_bunch; 00943 msym_bunch = new; 00944 } 00945 msymbol = &msym_bunch->contents[msym_bunch_index]; 00946 SYMBOL_SET_LANGUAGE (msymbol, language_auto, &objfile->objfile_obstack); 00947 SYMBOL_SET_NAMES (msymbol, name, name_len, copy_name, objfile); 00948 00949 SYMBOL_VALUE_ADDRESS (msymbol) = address; 00950 SYMBOL_SECTION (msymbol) = section; 00951 00952 MSYMBOL_TYPE (msymbol) = ms_type; 00953 MSYMBOL_TARGET_FLAG_1 (msymbol) = 0; 00954 MSYMBOL_TARGET_FLAG_2 (msymbol) = 0; 00955 /* Do not use the SET_MSYMBOL_SIZE macro to initialize the size, 00956 as it would also set the has_size flag. */ 00957 msymbol->size = 0; 00958 00959 /* The hash pointers must be cleared! If they're not, 00960 add_minsym_to_hash_table will NOT add this msymbol to the hash table. */ 00961 msymbol->hash_next = NULL; 00962 msymbol->demangled_hash_next = NULL; 00963 00964 msym_bunch_index++; 00965 msym_count++; 00966 OBJSTAT (objfile, n_minsyms++); 00967 return msymbol; 00968 } 00969 00970 /* See minsyms.h. */ 00971 00972 struct minimal_symbol * 00973 prim_record_minimal_symbol_and_info (const char *name, CORE_ADDR address, 00974 enum minimal_symbol_type ms_type, 00975 int section, 00976 struct objfile *objfile) 00977 { 00978 return prim_record_minimal_symbol_full (name, strlen (name), 1, 00979 address, ms_type, 00980 section, objfile); 00981 } 00982 00983 /* Compare two minimal symbols by address and return a signed result based 00984 on unsigned comparisons, so that we sort into unsigned numeric order. 00985 Within groups with the same address, sort by name. */ 00986 00987 static int 00988 compare_minimal_symbols (const void *fn1p, const void *fn2p) 00989 { 00990 const struct minimal_symbol *fn1; 00991 const struct minimal_symbol *fn2; 00992 00993 fn1 = (const struct minimal_symbol *) fn1p; 00994 fn2 = (const struct minimal_symbol *) fn2p; 00995 00996 if (SYMBOL_VALUE_ADDRESS (fn1) < SYMBOL_VALUE_ADDRESS (fn2)) 00997 { 00998 return (-1); /* addr 1 is less than addr 2. */ 00999 } 01000 else if (SYMBOL_VALUE_ADDRESS (fn1) > SYMBOL_VALUE_ADDRESS (fn2)) 01001 { 01002 return (1); /* addr 1 is greater than addr 2. */ 01003 } 01004 else 01005 /* addrs are equal: sort by name */ 01006 { 01007 const char *name1 = SYMBOL_LINKAGE_NAME (fn1); 01008 const char *name2 = SYMBOL_LINKAGE_NAME (fn2); 01009 01010 if (name1 && name2) /* both have names */ 01011 return strcmp (name1, name2); 01012 else if (name2) 01013 return 1; /* fn1 has no name, so it is "less". */ 01014 else if (name1) /* fn2 has no name, so it is "less". */ 01015 return -1; 01016 else 01017 return (0); /* Neither has a name, so they're equal. */ 01018 } 01019 } 01020 01021 /* Discard the currently collected minimal symbols, if any. If we wish 01022 to save them for later use, we must have already copied them somewhere 01023 else before calling this function. 01024 01025 FIXME: We could allocate the minimal symbol bunches on their own 01026 obstack and then simply blow the obstack away when we are done with 01027 it. Is it worth the extra trouble though? */ 01028 01029 static void 01030 do_discard_minimal_symbols_cleanup (void *arg) 01031 { 01032 struct msym_bunch *next; 01033 01034 while (msym_bunch != NULL) 01035 { 01036 next = msym_bunch->next; 01037 xfree (msym_bunch); 01038 msym_bunch = next; 01039 } 01040 } 01041 01042 /* See minsyms.h. */ 01043 01044 struct cleanup * 01045 make_cleanup_discard_minimal_symbols (void) 01046 { 01047 return make_cleanup (do_discard_minimal_symbols_cleanup, 0); 01048 } 01049 01050 01051 01052 /* Compact duplicate entries out of a minimal symbol table by walking 01053 through the table and compacting out entries with duplicate addresses 01054 and matching names. Return the number of entries remaining. 01055 01056 On entry, the table resides between msymbol[0] and msymbol[mcount]. 01057 On exit, it resides between msymbol[0] and msymbol[result_count]. 01058 01059 When files contain multiple sources of symbol information, it is 01060 possible for the minimal symbol table to contain many duplicate entries. 01061 As an example, SVR4 systems use ELF formatted object files, which 01062 usually contain at least two different types of symbol tables (a 01063 standard ELF one and a smaller dynamic linking table), as well as 01064 DWARF debugging information for files compiled with -g. 01065 01066 Without compacting, the minimal symbol table for gdb itself contains 01067 over a 1000 duplicates, about a third of the total table size. Aside 01068 from the potential trap of not noticing that two successive entries 01069 identify the same location, this duplication impacts the time required 01070 to linearly scan the table, which is done in a number of places. So we 01071 just do one linear scan here and toss out the duplicates. 01072 01073 Note that we are not concerned here about recovering the space that 01074 is potentially freed up, because the strings themselves are allocated 01075 on the objfile_obstack, and will get automatically freed when the symbol 01076 table is freed. The caller can free up the unused minimal symbols at 01077 the end of the compacted region if their allocation strategy allows it. 01078 01079 Also note we only go up to the next to last entry within the loop 01080 and then copy the last entry explicitly after the loop terminates. 01081 01082 Since the different sources of information for each symbol may 01083 have different levels of "completeness", we may have duplicates 01084 that have one entry with type "mst_unknown" and the other with a 01085 known type. So if the one we are leaving alone has type mst_unknown, 01086 overwrite its type with the type from the one we are compacting out. */ 01087 01088 static int 01089 compact_minimal_symbols (struct minimal_symbol *msymbol, int mcount, 01090 struct objfile *objfile) 01091 { 01092 struct minimal_symbol *copyfrom; 01093 struct minimal_symbol *copyto; 01094 01095 if (mcount > 0) 01096 { 01097 copyfrom = copyto = msymbol; 01098 while (copyfrom < msymbol + mcount - 1) 01099 { 01100 if (SYMBOL_VALUE_ADDRESS (copyfrom) 01101 == SYMBOL_VALUE_ADDRESS ((copyfrom + 1)) 01102 && strcmp (SYMBOL_LINKAGE_NAME (copyfrom), 01103 SYMBOL_LINKAGE_NAME ((copyfrom + 1))) == 0) 01104 { 01105 if (MSYMBOL_TYPE ((copyfrom + 1)) == mst_unknown) 01106 { 01107 MSYMBOL_TYPE ((copyfrom + 1)) = MSYMBOL_TYPE (copyfrom); 01108 } 01109 copyfrom++; 01110 } 01111 else 01112 *copyto++ = *copyfrom++; 01113 } 01114 *copyto++ = *copyfrom++; 01115 mcount = copyto - msymbol; 01116 } 01117 return (mcount); 01118 } 01119 01120 /* Build (or rebuild) the minimal symbol hash tables. This is necessary 01121 after compacting or sorting the table since the entries move around 01122 thus causing the internal minimal_symbol pointers to become jumbled. */ 01123 01124 static void 01125 build_minimal_symbol_hash_tables (struct objfile *objfile) 01126 { 01127 int i; 01128 struct minimal_symbol *msym; 01129 01130 /* Clear the hash tables. */ 01131 for (i = 0; i < MINIMAL_SYMBOL_HASH_SIZE; i++) 01132 { 01133 objfile->msymbol_hash[i] = 0; 01134 objfile->msymbol_demangled_hash[i] = 0; 01135 } 01136 01137 /* Now, (re)insert the actual entries. */ 01138 for (i = objfile->minimal_symbol_count, msym = objfile->msymbols; 01139 i > 0; 01140 i--, msym++) 01141 { 01142 msym->hash_next = 0; 01143 add_minsym_to_hash_table (msym, objfile->msymbol_hash); 01144 01145 msym->demangled_hash_next = 0; 01146 if (SYMBOL_SEARCH_NAME (msym) != SYMBOL_LINKAGE_NAME (msym)) 01147 add_minsym_to_demangled_hash_table (msym, 01148 objfile->msymbol_demangled_hash); 01149 } 01150 } 01151 01152 /* Add the minimal symbols in the existing bunches to the objfile's official 01153 minimal symbol table. In most cases there is no minimal symbol table yet 01154 for this objfile, and the existing bunches are used to create one. Once 01155 in a while (for shared libraries for example), we add symbols (e.g. common 01156 symbols) to an existing objfile. 01157 01158 Because of the way minimal symbols are collected, we generally have no way 01159 of knowing what source language applies to any particular minimal symbol. 01160 Specifically, we have no way of knowing if the minimal symbol comes from a 01161 C++ compilation unit or not. So for the sake of supporting cached 01162 demangled C++ names, we have no choice but to try and demangle each new one 01163 that comes in. If the demangling succeeds, then we assume it is a C++ 01164 symbol and set the symbol's language and demangled name fields 01165 appropriately. Note that in order to avoid unnecessary demanglings, and 01166 allocating obstack space that subsequently can't be freed for the demangled 01167 names, we mark all newly added symbols with language_auto. After 01168 compaction of the minimal symbols, we go back and scan the entire minimal 01169 symbol table looking for these new symbols. For each new symbol we attempt 01170 to demangle it, and if successful, record it as a language_cplus symbol 01171 and cache the demangled form on the symbol obstack. Symbols which don't 01172 demangle are marked as language_unknown symbols, which inhibits future 01173 attempts to demangle them if we later add more minimal symbols. */ 01174 01175 void 01176 install_minimal_symbols (struct objfile *objfile) 01177 { 01178 int bindex; 01179 int mcount; 01180 struct msym_bunch *bunch; 01181 struct minimal_symbol *msymbols; 01182 int alloc_count; 01183 01184 if (msym_count > 0) 01185 { 01186 if (symtab_create_debug) 01187 { 01188 fprintf_unfiltered (gdb_stdlog, 01189 "Installing %d minimal symbols of objfile %s.\n", 01190 msym_count, objfile_name (objfile)); 01191 } 01192 01193 /* Allocate enough space in the obstack, into which we will gather the 01194 bunches of new and existing minimal symbols, sort them, and then 01195 compact out the duplicate entries. Once we have a final table, 01196 we will give back the excess space. */ 01197 01198 alloc_count = msym_count + objfile->minimal_symbol_count + 1; 01199 obstack_blank (&objfile->objfile_obstack, 01200 alloc_count * sizeof (struct minimal_symbol)); 01201 msymbols = (struct minimal_symbol *) 01202 obstack_base (&objfile->objfile_obstack); 01203 01204 /* Copy in the existing minimal symbols, if there are any. */ 01205 01206 if (objfile->minimal_symbol_count) 01207 memcpy ((char *) msymbols, (char *) objfile->msymbols, 01208 objfile->minimal_symbol_count * sizeof (struct minimal_symbol)); 01209 01210 /* Walk through the list of minimal symbol bunches, adding each symbol 01211 to the new contiguous array of symbols. Note that we start with the 01212 current, possibly partially filled bunch (thus we use the current 01213 msym_bunch_index for the first bunch we copy over), and thereafter 01214 each bunch is full. */ 01215 01216 mcount = objfile->minimal_symbol_count; 01217 01218 for (bunch = msym_bunch; bunch != NULL; bunch = bunch->next) 01219 { 01220 for (bindex = 0; bindex < msym_bunch_index; bindex++, mcount++) 01221 msymbols[mcount] = bunch->contents[bindex]; 01222 msym_bunch_index = BUNCH_SIZE; 01223 } 01224 01225 /* Sort the minimal symbols by address. */ 01226 01227 qsort (msymbols, mcount, sizeof (struct minimal_symbol), 01228 compare_minimal_symbols); 01229 01230 /* Compact out any duplicates, and free up whatever space we are 01231 no longer using. */ 01232 01233 mcount = compact_minimal_symbols (msymbols, mcount, objfile); 01234 01235 obstack_blank (&objfile->objfile_obstack, 01236 (mcount + 1 - alloc_count) * sizeof (struct minimal_symbol)); 01237 msymbols = (struct minimal_symbol *) 01238 obstack_finish (&objfile->objfile_obstack); 01239 01240 /* We also terminate the minimal symbol table with a "null symbol", 01241 which is *not* included in the size of the table. This makes it 01242 easier to find the end of the table when we are handed a pointer 01243 to some symbol in the middle of it. Zero out the fields in the 01244 "null symbol" allocated at the end of the array. Note that the 01245 symbol count does *not* include this null symbol, which is why it 01246 is indexed by mcount and not mcount-1. */ 01247 01248 memset (&msymbols[mcount], 0, sizeof (struct minimal_symbol)); 01249 01250 /* Attach the minimal symbol table to the specified objfile. 01251 The strings themselves are also located in the objfile_obstack 01252 of this objfile. */ 01253 01254 objfile->minimal_symbol_count = mcount; 01255 objfile->msymbols = msymbols; 01256 01257 /* Now build the hash tables; we can't do this incrementally 01258 at an earlier point since we weren't finished with the obstack 01259 yet. (And if the msymbol obstack gets moved, all the internal 01260 pointers to other msymbols need to be adjusted.) */ 01261 build_minimal_symbol_hash_tables (objfile); 01262 } 01263 } 01264 01265 /* See minsyms.h. */ 01266 01267 void 01268 terminate_minimal_symbol_table (struct objfile *objfile) 01269 { 01270 if (! objfile->msymbols) 01271 objfile->msymbols = ((struct minimal_symbol *) 01272 obstack_alloc (&objfile->objfile_obstack, 01273 sizeof (objfile->msymbols[0]))); 01274 01275 { 01276 struct minimal_symbol *m 01277 = &objfile->msymbols[objfile->minimal_symbol_count]; 01278 01279 memset (m, 0, sizeof (*m)); 01280 /* Don't rely on these enumeration values being 0's. */ 01281 MSYMBOL_TYPE (m) = mst_unknown; 01282 SYMBOL_SET_LANGUAGE (m, language_unknown, &objfile->objfile_obstack); 01283 } 01284 } 01285 01286 /* Sort all the minimal symbols in OBJFILE. */ 01287 01288 void 01289 msymbols_sort (struct objfile *objfile) 01290 { 01291 qsort (objfile->msymbols, objfile->minimal_symbol_count, 01292 sizeof (struct minimal_symbol), compare_minimal_symbols); 01293 build_minimal_symbol_hash_tables (objfile); 01294 } 01295 01296 /* Check if PC is in a shared library trampoline code stub. 01297 Return minimal symbol for the trampoline entry or NULL if PC is not 01298 in a trampoline code stub. */ 01299 01300 static struct minimal_symbol * 01301 lookup_solib_trampoline_symbol_by_pc (CORE_ADDR pc) 01302 { 01303 struct obj_section *section = find_pc_section (pc); 01304 struct bound_minimal_symbol msymbol; 01305 01306 if (section == NULL) 01307 return NULL; 01308 msymbol = lookup_minimal_symbol_by_pc_section_1 (pc, section, 1); 01309 01310 if (msymbol.minsym != NULL 01311 && MSYMBOL_TYPE (msymbol.minsym) == mst_solib_trampoline) 01312 return msymbol.minsym; 01313 return NULL; 01314 } 01315 01316 /* If PC is in a shared library trampoline code stub, return the 01317 address of the `real' function belonging to the stub. 01318 Return 0 if PC is not in a trampoline code stub or if the real 01319 function is not found in the minimal symbol table. 01320 01321 We may fail to find the right function if a function with the 01322 same name is defined in more than one shared library, but this 01323 is considered bad programming style. We could return 0 if we find 01324 a duplicate function in case this matters someday. */ 01325 01326 CORE_ADDR 01327 find_solib_trampoline_target (struct frame_info *frame, CORE_ADDR pc) 01328 { 01329 struct objfile *objfile; 01330 struct minimal_symbol *msymbol; 01331 struct minimal_symbol *tsymbol = lookup_solib_trampoline_symbol_by_pc (pc); 01332 01333 if (tsymbol != NULL) 01334 { 01335 ALL_MSYMBOLS (objfile, msymbol) 01336 { 01337 if ((MSYMBOL_TYPE (msymbol) == mst_text 01338 || MSYMBOL_TYPE (msymbol) == mst_text_gnu_ifunc) 01339 && strcmp (SYMBOL_LINKAGE_NAME (msymbol), 01340 SYMBOL_LINKAGE_NAME (tsymbol)) == 0) 01341 return SYMBOL_VALUE_ADDRESS (msymbol); 01342 01343 /* Also handle minimal symbols pointing to function descriptors. */ 01344 if (MSYMBOL_TYPE (msymbol) == mst_data 01345 && strcmp (SYMBOL_LINKAGE_NAME (msymbol), 01346 SYMBOL_LINKAGE_NAME (tsymbol)) == 0) 01347 { 01348 CORE_ADDR func; 01349 01350 func = gdbarch_convert_from_func_ptr_addr 01351 (get_objfile_arch (objfile), 01352 SYMBOL_VALUE_ADDRESS (msymbol), 01353 ¤t_target); 01354 01355 /* Ignore data symbols that are not function descriptors. */ 01356 if (func != SYMBOL_VALUE_ADDRESS (msymbol)) 01357 return func; 01358 } 01359 } 01360 } 01361 return 0; 01362 }