| 1 | /* Partial symbol tables. |
| 2 | |
| 3 | Copyright (C) 2009, 2010, 2011 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 | #include "defs.h" |
| 21 | #include "symtab.h" |
| 22 | #include "psympriv.h" |
| 23 | #include "objfiles.h" |
| 24 | #include "gdb_assert.h" |
| 25 | #include "block.h" |
| 26 | #include "filenames.h" |
| 27 | #include "source.h" |
| 28 | #include "addrmap.h" |
| 29 | #include "gdbtypes.h" |
| 30 | #include "bcache.h" |
| 31 | #include "ui-out.h" |
| 32 | #include "command.h" |
| 33 | #include "readline/readline.h" |
| 34 | #include "gdb_regex.h" |
| 35 | #include "dictionary.h" |
| 36 | #include "language.h" |
| 37 | #include "cp-support.h" |
| 38 | |
| 39 | #ifndef DEV_TTY |
| 40 | #define DEV_TTY "/dev/tty" |
| 41 | #endif |
| 42 | |
| 43 | struct psymbol_bcache |
| 44 | { |
| 45 | struct bcache *bcache; |
| 46 | }; |
| 47 | |
| 48 | /* A fast way to get from a psymtab to its symtab (after the first time). */ |
| 49 | #define PSYMTAB_TO_SYMTAB(pst) \ |
| 50 | ((pst) -> symtab != NULL ? (pst) -> symtab : psymtab_to_symtab (pst)) |
| 51 | |
| 52 | static struct partial_symbol *match_partial_symbol (struct partial_symtab *, |
| 53 | int, |
| 54 | const char *, domain_enum, |
| 55 | symbol_compare_ftype *, |
| 56 | symbol_compare_ftype *); |
| 57 | |
| 58 | static struct partial_symbol *lookup_partial_symbol (struct partial_symtab *, |
| 59 | const char *, int, |
| 60 | domain_enum); |
| 61 | |
| 62 | static char *psymtab_to_fullname (struct partial_symtab *ps); |
| 63 | |
| 64 | static struct partial_symbol *find_pc_sect_psymbol (struct partial_symtab *, |
| 65 | CORE_ADDR, |
| 66 | struct obj_section *); |
| 67 | |
| 68 | static struct partial_symbol *fixup_psymbol_section (struct partial_symbol |
| 69 | *psym, |
| 70 | struct objfile *objfile); |
| 71 | |
| 72 | static struct symtab *psymtab_to_symtab (struct partial_symtab *pst); |
| 73 | |
| 74 | /* Ensure that the partial symbols for OBJFILE have been loaded. This |
| 75 | function always returns its argument, as a convenience. */ |
| 76 | |
| 77 | struct objfile * |
| 78 | require_partial_symbols (struct objfile *objfile, int verbose) |
| 79 | { |
| 80 | if ((objfile->flags & OBJF_PSYMTABS_READ) == 0) |
| 81 | { |
| 82 | objfile->flags |= OBJF_PSYMTABS_READ; |
| 83 | |
| 84 | if (objfile->sf->sym_read_psymbols) |
| 85 | { |
| 86 | if (verbose) |
| 87 | { |
| 88 | printf_unfiltered (_("Reading symbols from %s..."), |
| 89 | objfile->name); |
| 90 | gdb_flush (gdb_stdout); |
| 91 | } |
| 92 | (*objfile->sf->sym_read_psymbols) (objfile); |
| 93 | if (verbose) |
| 94 | { |
| 95 | if (!objfile_has_symbols (objfile)) |
| 96 | { |
| 97 | wrap_here (""); |
| 98 | printf_unfiltered (_("(no debugging symbols found)...")); |
| 99 | wrap_here (""); |
| 100 | } |
| 101 | |
| 102 | printf_unfiltered (_("done.\n")); |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | return objfile; |
| 108 | } |
| 109 | |
| 110 | /* Traverse all psymtabs in one objfile, requiring that the psymtabs |
| 111 | be read in. */ |
| 112 | |
| 113 | #define ALL_OBJFILE_PSYMTABS_REQUIRED(objfile, p) \ |
| 114 | for ((p) = require_partial_symbols (objfile, 1)->psymtabs; \ |
| 115 | (p) != NULL; \ |
| 116 | (p) = (p)->next) |
| 117 | |
| 118 | /* We want to make sure this file always requires psymtabs. */ |
| 119 | |
| 120 | #undef ALL_OBJFILE_PSYMTABS |
| 121 | |
| 122 | /* Traverse all psymtabs in all objfiles. */ |
| 123 | |
| 124 | #define ALL_PSYMTABS(objfile, p) \ |
| 125 | ALL_OBJFILES (objfile) \ |
| 126 | ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p) |
| 127 | |
| 128 | /* Lookup the partial symbol table of a source file named NAME. |
| 129 | *If* there is no '/' in the name, a match after a '/' |
| 130 | in the psymtab filename will also work. */ |
| 131 | |
| 132 | static struct partial_symtab * |
| 133 | lookup_partial_symtab (struct objfile *objfile, const char *name, |
| 134 | const char *full_path, const char *real_path) |
| 135 | { |
| 136 | struct partial_symtab *pst; |
| 137 | |
| 138 | ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst) |
| 139 | { |
| 140 | if (FILENAME_CMP (name, pst->filename) == 0) |
| 141 | { |
| 142 | return (pst); |
| 143 | } |
| 144 | |
| 145 | /* If the user gave us an absolute path, try to find the file in |
| 146 | this symtab and use its absolute path. */ |
| 147 | if (full_path != NULL) |
| 148 | { |
| 149 | psymtab_to_fullname (pst); |
| 150 | if (pst->fullname != NULL |
| 151 | && FILENAME_CMP (full_path, pst->fullname) == 0) |
| 152 | { |
| 153 | return pst; |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | if (real_path != NULL) |
| 158 | { |
| 159 | char *rp = NULL; |
| 160 | psymtab_to_fullname (pst); |
| 161 | if (pst->fullname != NULL) |
| 162 | { |
| 163 | rp = gdb_realpath (pst->fullname); |
| 164 | make_cleanup (xfree, rp); |
| 165 | } |
| 166 | if (rp != NULL && FILENAME_CMP (real_path, rp) == 0) |
| 167 | { |
| 168 | return pst; |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | /* Now, search for a matching tail (only if name doesn't have any dirs). */ |
| 174 | |
| 175 | if (lbasename (name) == name) |
| 176 | ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst) |
| 177 | { |
| 178 | if (FILENAME_CMP (lbasename (pst->filename), name) == 0) |
| 179 | return (pst); |
| 180 | } |
| 181 | |
| 182 | return (NULL); |
| 183 | } |
| 184 | |
| 185 | static int |
| 186 | lookup_symtab_via_partial_symtab (struct objfile *objfile, const char *name, |
| 187 | const char *full_path, const char *real_path, |
| 188 | struct symtab **result) |
| 189 | { |
| 190 | struct partial_symtab *ps; |
| 191 | |
| 192 | ps = lookup_partial_symtab (objfile, name, full_path, real_path); |
| 193 | if (!ps) |
| 194 | return 0; |
| 195 | |
| 196 | if (ps->readin) |
| 197 | error (_("Internal: readin %s pst for `%s' found when no symtab found."), |
| 198 | ps->filename, name); |
| 199 | |
| 200 | *result = PSYMTAB_TO_SYMTAB (ps); |
| 201 | return 1; |
| 202 | } |
| 203 | |
| 204 | /* Find which partial symtab contains PC and SECTION starting at psymtab PST. |
| 205 | We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */ |
| 206 | |
| 207 | static struct partial_symtab * |
| 208 | find_pc_sect_psymtab_closer (CORE_ADDR pc, struct obj_section *section, |
| 209 | struct partial_symtab *pst, |
| 210 | struct minimal_symbol *msymbol) |
| 211 | { |
| 212 | struct objfile *objfile = pst->objfile; |
| 213 | struct partial_symtab *tpst; |
| 214 | struct partial_symtab *best_pst = pst; |
| 215 | CORE_ADDR best_addr = pst->textlow; |
| 216 | |
| 217 | /* An objfile that has its functions reordered might have |
| 218 | many partial symbol tables containing the PC, but |
| 219 | we want the partial symbol table that contains the |
| 220 | function containing the PC. */ |
| 221 | if (!(objfile->flags & OBJF_REORDERED) && |
| 222 | section == 0) /* Can't validate section this way. */ |
| 223 | return pst; |
| 224 | |
| 225 | if (msymbol == NULL) |
| 226 | return (pst); |
| 227 | |
| 228 | /* The code range of partial symtabs sometimes overlap, so, in |
| 229 | the loop below, we need to check all partial symtabs and |
| 230 | find the one that fits better for the given PC address. We |
| 231 | select the partial symtab that contains a symbol whose |
| 232 | address is closest to the PC address. By closest we mean |
| 233 | that find_pc_sect_symbol returns the symbol with address |
| 234 | that is closest and still less than the given PC. */ |
| 235 | for (tpst = pst; tpst != NULL; tpst = tpst->next) |
| 236 | { |
| 237 | if (pc >= tpst->textlow && pc < tpst->texthigh) |
| 238 | { |
| 239 | struct partial_symbol *p; |
| 240 | CORE_ADDR this_addr; |
| 241 | |
| 242 | /* NOTE: This assumes that every psymbol has a |
| 243 | corresponding msymbol, which is not necessarily |
| 244 | true; the debug info might be much richer than the |
| 245 | object's symbol table. */ |
| 246 | p = find_pc_sect_psymbol (tpst, pc, section); |
| 247 | if (p != NULL |
| 248 | && SYMBOL_VALUE_ADDRESS (p) |
| 249 | == SYMBOL_VALUE_ADDRESS (msymbol)) |
| 250 | return tpst; |
| 251 | |
| 252 | /* Also accept the textlow value of a psymtab as a |
| 253 | "symbol", to provide some support for partial |
| 254 | symbol tables with line information but no debug |
| 255 | symbols (e.g. those produced by an assembler). */ |
| 256 | if (p != NULL) |
| 257 | this_addr = SYMBOL_VALUE_ADDRESS (p); |
| 258 | else |
| 259 | this_addr = tpst->textlow; |
| 260 | |
| 261 | /* Check whether it is closer than our current |
| 262 | BEST_ADDR. Since this symbol address is |
| 263 | necessarily lower or equal to PC, the symbol closer |
| 264 | to PC is the symbol which address is the highest. |
| 265 | This way we return the psymtab which contains such |
| 266 | best match symbol. This can help in cases where the |
| 267 | symbol information/debuginfo is not complete, like |
| 268 | for instance on IRIX6 with gcc, where no debug info |
| 269 | is emitted for statics. (See also the nodebug.exp |
| 270 | testcase.) */ |
| 271 | if (this_addr > best_addr) |
| 272 | { |
| 273 | best_addr = this_addr; |
| 274 | best_pst = tpst; |
| 275 | } |
| 276 | } |
| 277 | } |
| 278 | return best_pst; |
| 279 | } |
| 280 | |
| 281 | /* Find which partial symtab contains PC and SECTION. Return 0 if |
| 282 | none. We return the psymtab that contains a symbol whose address |
| 283 | exactly matches PC, or, if we cannot find an exact match, the |
| 284 | psymtab that contains a symbol whose address is closest to PC. */ |
| 285 | static struct partial_symtab * |
| 286 | find_pc_sect_psymtab (struct objfile *objfile, CORE_ADDR pc, |
| 287 | struct obj_section *section, |
| 288 | struct minimal_symbol *msymbol) |
| 289 | { |
| 290 | struct partial_symtab *pst; |
| 291 | |
| 292 | /* Try just the PSYMTABS_ADDRMAP mapping first as it has better granularity |
| 293 | than the later used TEXTLOW/TEXTHIGH one. */ |
| 294 | |
| 295 | if (objfile->psymtabs_addrmap != NULL) |
| 296 | { |
| 297 | pst = addrmap_find (objfile->psymtabs_addrmap, pc); |
| 298 | if (pst != NULL) |
| 299 | { |
| 300 | /* FIXME: addrmaps currently do not handle overlayed sections, |
| 301 | so fall back to the non-addrmap case if we're debugging |
| 302 | overlays and the addrmap returned the wrong section. */ |
| 303 | if (overlay_debugging && msymbol && section) |
| 304 | { |
| 305 | struct partial_symbol *p; |
| 306 | |
| 307 | /* NOTE: This assumes that every psymbol has a |
| 308 | corresponding msymbol, which is not necessarily |
| 309 | true; the debug info might be much richer than the |
| 310 | object's symbol table. */ |
| 311 | p = find_pc_sect_psymbol (pst, pc, section); |
| 312 | if (!p |
| 313 | || SYMBOL_VALUE_ADDRESS (p) |
| 314 | != SYMBOL_VALUE_ADDRESS (msymbol)) |
| 315 | goto next; |
| 316 | } |
| 317 | |
| 318 | /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as |
| 319 | PSYMTABS_ADDRMAP we used has already the best 1-byte |
| 320 | granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into |
| 321 | a worse chosen section due to the TEXTLOW/TEXTHIGH ranges |
| 322 | overlap. */ |
| 323 | |
| 324 | return pst; |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | next: |
| 329 | |
| 330 | /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs |
| 331 | which still have no corresponding full SYMTABs read. But it is not |
| 332 | present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB |
| 333 | so far. */ |
| 334 | |
| 335 | /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of |
| 336 | its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying |
| 337 | debug info type in single OBJFILE. */ |
| 338 | |
| 339 | ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst) |
| 340 | if (pc >= pst->textlow && pc < pst->texthigh) |
| 341 | { |
| 342 | struct partial_symtab *best_pst; |
| 343 | |
| 344 | best_pst = find_pc_sect_psymtab_closer (pc, section, pst, msymbol); |
| 345 | if (best_pst != NULL) |
| 346 | return best_pst; |
| 347 | } |
| 348 | |
| 349 | return NULL; |
| 350 | } |
| 351 | |
| 352 | static struct symtab * |
| 353 | find_pc_sect_symtab_from_partial (struct objfile *objfile, |
| 354 | struct minimal_symbol *msymbol, |
| 355 | CORE_ADDR pc, struct obj_section *section, |
| 356 | int warn_if_readin) |
| 357 | { |
| 358 | struct partial_symtab *ps = find_pc_sect_psymtab (objfile, pc, section, |
| 359 | msymbol); |
| 360 | if (ps) |
| 361 | { |
| 362 | if (warn_if_readin && ps->readin) |
| 363 | /* Might want to error() here (in case symtab is corrupt and |
| 364 | will cause a core dump), but maybe we can successfully |
| 365 | continue, so let's not. */ |
| 366 | warning (_("\ |
| 367 | (Internal error: pc %s in read in psymtab, but not in symtab.)\n"), |
| 368 | paddress (get_objfile_arch (ps->objfile), pc)); |
| 369 | return PSYMTAB_TO_SYMTAB (ps); |
| 370 | } |
| 371 | return NULL; |
| 372 | } |
| 373 | |
| 374 | /* Find which partial symbol within a psymtab matches PC and SECTION. |
| 375 | Return 0 if none. */ |
| 376 | |
| 377 | static struct partial_symbol * |
| 378 | find_pc_sect_psymbol (struct partial_symtab *psymtab, CORE_ADDR pc, |
| 379 | struct obj_section *section) |
| 380 | { |
| 381 | struct partial_symbol *best = NULL, *p, **pp; |
| 382 | CORE_ADDR best_pc; |
| 383 | |
| 384 | gdb_assert (psymtab != NULL); |
| 385 | |
| 386 | /* Cope with programs that start at address 0. */ |
| 387 | best_pc = (psymtab->textlow != 0) ? psymtab->textlow - 1 : 0; |
| 388 | |
| 389 | /* Search the global symbols as well as the static symbols, so that |
| 390 | find_pc_partial_function doesn't use a minimal symbol and thus |
| 391 | cache a bad endaddr. */ |
| 392 | for (pp = psymtab->objfile->global_psymbols.list + psymtab->globals_offset; |
| 393 | (pp - (psymtab->objfile->global_psymbols.list + psymtab->globals_offset) |
| 394 | < psymtab->n_global_syms); |
| 395 | pp++) |
| 396 | { |
| 397 | p = *pp; |
| 398 | if (SYMBOL_DOMAIN (p) == VAR_DOMAIN |
| 399 | && SYMBOL_CLASS (p) == LOC_BLOCK |
| 400 | && pc >= SYMBOL_VALUE_ADDRESS (p) |
| 401 | && (SYMBOL_VALUE_ADDRESS (p) > best_pc |
| 402 | || (psymtab->textlow == 0 |
| 403 | && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0))) |
| 404 | { |
| 405 | if (section) /* Match on a specific section. */ |
| 406 | { |
| 407 | fixup_psymbol_section (p, psymtab->objfile); |
| 408 | if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p), section)) |
| 409 | continue; |
| 410 | } |
| 411 | best_pc = SYMBOL_VALUE_ADDRESS (p); |
| 412 | best = p; |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | for (pp = psymtab->objfile->static_psymbols.list + psymtab->statics_offset; |
| 417 | (pp - (psymtab->objfile->static_psymbols.list + psymtab->statics_offset) |
| 418 | < psymtab->n_static_syms); |
| 419 | pp++) |
| 420 | { |
| 421 | p = *pp; |
| 422 | if (SYMBOL_DOMAIN (p) == VAR_DOMAIN |
| 423 | && SYMBOL_CLASS (p) == LOC_BLOCK |
| 424 | && pc >= SYMBOL_VALUE_ADDRESS (p) |
| 425 | && (SYMBOL_VALUE_ADDRESS (p) > best_pc |
| 426 | || (psymtab->textlow == 0 |
| 427 | && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0))) |
| 428 | { |
| 429 | if (section) /* Match on a specific section. */ |
| 430 | { |
| 431 | fixup_psymbol_section (p, psymtab->objfile); |
| 432 | if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p), section)) |
| 433 | continue; |
| 434 | } |
| 435 | best_pc = SYMBOL_VALUE_ADDRESS (p); |
| 436 | best = p; |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | return best; |
| 441 | } |
| 442 | |
| 443 | static struct partial_symbol * |
| 444 | fixup_psymbol_section (struct partial_symbol *psym, struct objfile *objfile) |
| 445 | { |
| 446 | CORE_ADDR addr; |
| 447 | |
| 448 | if (!psym) |
| 449 | return NULL; |
| 450 | |
| 451 | if (SYMBOL_OBJ_SECTION (psym)) |
| 452 | return psym; |
| 453 | |
| 454 | gdb_assert (objfile); |
| 455 | |
| 456 | switch (SYMBOL_CLASS (psym)) |
| 457 | { |
| 458 | case LOC_STATIC: |
| 459 | case LOC_LABEL: |
| 460 | case LOC_BLOCK: |
| 461 | addr = SYMBOL_VALUE_ADDRESS (psym); |
| 462 | break; |
| 463 | default: |
| 464 | /* Nothing else will be listed in the minsyms -- no use looking |
| 465 | it up. */ |
| 466 | return psym; |
| 467 | } |
| 468 | |
| 469 | fixup_section (&psym->ginfo, addr, objfile); |
| 470 | |
| 471 | return psym; |
| 472 | } |
| 473 | |
| 474 | static struct symtab * |
| 475 | lookup_symbol_aux_psymtabs (struct objfile *objfile, |
| 476 | int block_index, const char *name, |
| 477 | const domain_enum domain) |
| 478 | { |
| 479 | struct partial_symtab *ps; |
| 480 | const int psymtab_index = (block_index == GLOBAL_BLOCK ? 1 : 0); |
| 481 | |
| 482 | ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps) |
| 483 | { |
| 484 | if (!ps->readin && lookup_partial_symbol (ps, name, psymtab_index, domain)) |
| 485 | { |
| 486 | struct symbol *sym = NULL; |
| 487 | struct symtab *stab = PSYMTAB_TO_SYMTAB (ps); |
| 488 | |
| 489 | /* Some caution must be observed with overloaded functions |
| 490 | and methods, since the psymtab will not contain any overload |
| 491 | information (but NAME might contain it). */ |
| 492 | if (stab->primary) |
| 493 | { |
| 494 | struct blockvector *bv = BLOCKVECTOR (stab); |
| 495 | struct block *block = BLOCKVECTOR_BLOCK (bv, block_index); |
| 496 | |
| 497 | sym = lookup_block_symbol (block, name, domain); |
| 498 | } |
| 499 | |
| 500 | if (sym && strcmp_iw (SYMBOL_SEARCH_NAME (sym), name) == 0) |
| 501 | return stab; |
| 502 | |
| 503 | /* Keep looking through other psymtabs. */ |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | return NULL; |
| 508 | } |
| 509 | |
| 510 | /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search |
| 511 | the global block of PST if GLOBAL, and otherwise the static block. |
| 512 | MATCH is the comparison operation that returns true iff MATCH (s, |
| 513 | NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is |
| 514 | non-null, the symbols in the block are assumed to be ordered |
| 515 | according to it (allowing binary search). It must be compatible |
| 516 | with MATCH. Returns the symbol, if found, and otherwise NULL. */ |
| 517 | |
| 518 | static struct partial_symbol * |
| 519 | match_partial_symbol (struct partial_symtab *pst, int global, |
| 520 | const char *name, domain_enum domain, |
| 521 | symbol_compare_ftype *match, |
| 522 | symbol_compare_ftype *ordered_compare) |
| 523 | { |
| 524 | struct partial_symbol **start, **psym; |
| 525 | struct partial_symbol **top, **real_top, **bottom, **center; |
| 526 | int length = (global ? pst->n_global_syms : pst->n_static_syms); |
| 527 | int do_linear_search = 1; |
| 528 | |
| 529 | if (length == 0) |
| 530 | return NULL; |
| 531 | start = (global ? |
| 532 | pst->objfile->global_psymbols.list + pst->globals_offset : |
| 533 | pst->objfile->static_psymbols.list + pst->statics_offset); |
| 534 | |
| 535 | if (global && ordered_compare) /* Can use a binary search. */ |
| 536 | { |
| 537 | do_linear_search = 0; |
| 538 | |
| 539 | /* Binary search. This search is guaranteed to end with center |
| 540 | pointing at the earliest partial symbol whose name might be |
| 541 | correct. At that point *all* partial symbols with an |
| 542 | appropriate name will be checked against the correct |
| 543 | domain. */ |
| 544 | |
| 545 | bottom = start; |
| 546 | top = start + length - 1; |
| 547 | real_top = top; |
| 548 | while (top > bottom) |
| 549 | { |
| 550 | center = bottom + (top - bottom) / 2; |
| 551 | gdb_assert (center < top); |
| 552 | if (!do_linear_search |
| 553 | && (SYMBOL_LANGUAGE (*center) == language_java)) |
| 554 | do_linear_search = 1; |
| 555 | if (ordered_compare (SYMBOL_SEARCH_NAME (*center), name) >= 0) |
| 556 | top = center; |
| 557 | else |
| 558 | bottom = center + 1; |
| 559 | } |
| 560 | gdb_assert (top == bottom); |
| 561 | |
| 562 | while (top <= real_top |
| 563 | && match (SYMBOL_SEARCH_NAME (*top), name) == 0) |
| 564 | { |
| 565 | if (symbol_matches_domain (SYMBOL_LANGUAGE (*top), |
| 566 | SYMBOL_DOMAIN (*top), domain)) |
| 567 | return *top; |
| 568 | top++; |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | /* Can't use a binary search or else we found during the binary search that |
| 573 | we should also do a linear search. */ |
| 574 | |
| 575 | if (do_linear_search) |
| 576 | { |
| 577 | for (psym = start; psym < start + length; psym++) |
| 578 | { |
| 579 | if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym), |
| 580 | SYMBOL_DOMAIN (*psym), domain) |
| 581 | && match (SYMBOL_SEARCH_NAME (*psym), name) == 0) |
| 582 | return *psym; |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | return NULL; |
| 587 | } |
| 588 | |
| 589 | static void |
| 590 | pre_expand_symtabs_matching_psymtabs (struct objfile *objfile, |
| 591 | int kind, const char *name, |
| 592 | domain_enum domain) |
| 593 | { |
| 594 | /* Nothing. */ |
| 595 | } |
| 596 | |
| 597 | /* Returns the name used to search psymtabs. Unlike symtabs, psymtabs do |
| 598 | not contain any method/function instance information (since this would |
| 599 | force reading type information while reading psymtabs). Therefore, |
| 600 | if NAME contains overload information, it must be stripped before searching |
| 601 | psymtabs. |
| 602 | |
| 603 | The caller is responsible for freeing the return result. */ |
| 604 | |
| 605 | static char * |
| 606 | psymtab_search_name (const char *name) |
| 607 | { |
| 608 | switch (current_language->la_language) |
| 609 | { |
| 610 | case language_cplus: |
| 611 | case language_java: |
| 612 | { |
| 613 | if (strchr (name, '(')) |
| 614 | { |
| 615 | char *ret = cp_remove_params (name); |
| 616 | |
| 617 | if (ret) |
| 618 | return ret; |
| 619 | } |
| 620 | } |
| 621 | break; |
| 622 | |
| 623 | default: |
| 624 | break; |
| 625 | } |
| 626 | |
| 627 | return xstrdup (name); |
| 628 | } |
| 629 | |
| 630 | /* Look, in partial_symtab PST, for symbol whose natural name is NAME. |
| 631 | Check the global symbols if GLOBAL, the static symbols if not. */ |
| 632 | |
| 633 | static struct partial_symbol * |
| 634 | lookup_partial_symbol (struct partial_symtab *pst, const char *name, |
| 635 | int global, domain_enum domain) |
| 636 | { |
| 637 | struct partial_symbol **start, **psym; |
| 638 | struct partial_symbol **top, **real_top, **bottom, **center; |
| 639 | int length = (global ? pst->n_global_syms : pst->n_static_syms); |
| 640 | int do_linear_search = 1; |
| 641 | char *search_name; |
| 642 | struct cleanup *cleanup; |
| 643 | |
| 644 | if (length == 0) |
| 645 | { |
| 646 | return (NULL); |
| 647 | } |
| 648 | |
| 649 | search_name = psymtab_search_name (name); |
| 650 | cleanup = make_cleanup (xfree, search_name); |
| 651 | start = (global ? |
| 652 | pst->objfile->global_psymbols.list + pst->globals_offset : |
| 653 | pst->objfile->static_psymbols.list + pst->statics_offset); |
| 654 | |
| 655 | if (global) /* This means we can use a binary search. */ |
| 656 | { |
| 657 | do_linear_search = 0; |
| 658 | |
| 659 | /* Binary search. This search is guaranteed to end with center |
| 660 | pointing at the earliest partial symbol whose name might be |
| 661 | correct. At that point *all* partial symbols with an |
| 662 | appropriate name will be checked against the correct |
| 663 | domain. */ |
| 664 | |
| 665 | bottom = start; |
| 666 | top = start + length - 1; |
| 667 | real_top = top; |
| 668 | while (top > bottom) |
| 669 | { |
| 670 | center = bottom + (top - bottom) / 2; |
| 671 | if (!(center < top)) |
| 672 | internal_error (__FILE__, __LINE__, |
| 673 | _("failed internal consistency check")); |
| 674 | if (!do_linear_search |
| 675 | && SYMBOL_LANGUAGE (*center) == language_java) |
| 676 | { |
| 677 | do_linear_search = 1; |
| 678 | } |
| 679 | if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center), |
| 680 | search_name) >= 0) |
| 681 | { |
| 682 | top = center; |
| 683 | } |
| 684 | else |
| 685 | { |
| 686 | bottom = center + 1; |
| 687 | } |
| 688 | } |
| 689 | if (!(top == bottom)) |
| 690 | internal_error (__FILE__, __LINE__, |
| 691 | _("failed internal consistency check")); |
| 692 | |
| 693 | while (top <= real_top |
| 694 | && SYMBOL_MATCHES_SEARCH_NAME (*top, search_name)) |
| 695 | { |
| 696 | if (symbol_matches_domain (SYMBOL_LANGUAGE (*top), |
| 697 | SYMBOL_DOMAIN (*top), domain)) |
| 698 | { |
| 699 | do_cleanups (cleanup); |
| 700 | return (*top); |
| 701 | } |
| 702 | top++; |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | /* Can't use a binary search or else we found during the binary search that |
| 707 | we should also do a linear search. */ |
| 708 | |
| 709 | if (do_linear_search) |
| 710 | { |
| 711 | for (psym = start; psym < start + length; psym++) |
| 712 | { |
| 713 | if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym), |
| 714 | SYMBOL_DOMAIN (*psym), domain) |
| 715 | && SYMBOL_MATCHES_SEARCH_NAME (*psym, search_name)) |
| 716 | { |
| 717 | do_cleanups (cleanup); |
| 718 | return (*psym); |
| 719 | } |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | do_cleanups (cleanup); |
| 724 | return (NULL); |
| 725 | } |
| 726 | |
| 727 | /* Get the symbol table that corresponds to a partial_symtab. |
| 728 | This is fast after the first time you do it. In fact, there |
| 729 | is an even faster macro PSYMTAB_TO_SYMTAB that does the fast |
| 730 | case inline. */ |
| 731 | |
| 732 | static struct symtab * |
| 733 | psymtab_to_symtab (struct partial_symtab *pst) |
| 734 | { |
| 735 | /* If it's been looked up before, return it. */ |
| 736 | if (pst->symtab) |
| 737 | return pst->symtab; |
| 738 | |
| 739 | /* If it has not yet been read in, read it. */ |
| 740 | if (!pst->readin) |
| 741 | { |
| 742 | struct cleanup *back_to = increment_reading_symtab (); |
| 743 | |
| 744 | (*pst->read_symtab) (pst); |
| 745 | do_cleanups (back_to); |
| 746 | } |
| 747 | |
| 748 | return pst->symtab; |
| 749 | } |
| 750 | |
| 751 | static void |
| 752 | relocate_psymtabs (struct objfile *objfile, |
| 753 | struct section_offsets *new_offsets, |
| 754 | struct section_offsets *delta) |
| 755 | { |
| 756 | struct partial_symbol **psym; |
| 757 | struct partial_symtab *p; |
| 758 | |
| 759 | ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p) |
| 760 | { |
| 761 | p->textlow += ANOFFSET (delta, SECT_OFF_TEXT (objfile)); |
| 762 | p->texthigh += ANOFFSET (delta, SECT_OFF_TEXT (objfile)); |
| 763 | } |
| 764 | |
| 765 | for (psym = objfile->global_psymbols.list; |
| 766 | psym < objfile->global_psymbols.next; |
| 767 | psym++) |
| 768 | { |
| 769 | fixup_psymbol_section (*psym, objfile); |
| 770 | if (SYMBOL_SECTION (*psym) >= 0) |
| 771 | SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta, |
| 772 | SYMBOL_SECTION (*psym)); |
| 773 | } |
| 774 | for (psym = objfile->static_psymbols.list; |
| 775 | psym < objfile->static_psymbols.next; |
| 776 | psym++) |
| 777 | { |
| 778 | fixup_psymbol_section (*psym, objfile); |
| 779 | if (SYMBOL_SECTION (*psym) >= 0) |
| 780 | SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta, |
| 781 | SYMBOL_SECTION (*psym)); |
| 782 | } |
| 783 | } |
| 784 | |
| 785 | static struct symtab * |
| 786 | find_last_source_symtab_from_partial (struct objfile *ofp) |
| 787 | { |
| 788 | struct partial_symtab *ps; |
| 789 | struct partial_symtab *cs_pst = 0; |
| 790 | |
| 791 | ALL_OBJFILE_PSYMTABS_REQUIRED (ofp, ps) |
| 792 | { |
| 793 | const char *name = ps->filename; |
| 794 | int len = strlen (name); |
| 795 | |
| 796 | if (!(len > 2 && (strcmp (&name[len - 2], ".h") == 0 |
| 797 | || strcmp (name, "<<C++-namespaces>>") == 0))) |
| 798 | cs_pst = ps; |
| 799 | } |
| 800 | |
| 801 | if (cs_pst) |
| 802 | { |
| 803 | if (cs_pst->readin) |
| 804 | { |
| 805 | internal_error (__FILE__, __LINE__, |
| 806 | _("select_source_symtab: " |
| 807 | "readin pst found and no symtabs.")); |
| 808 | } |
| 809 | else |
| 810 | return PSYMTAB_TO_SYMTAB (cs_pst); |
| 811 | } |
| 812 | return NULL; |
| 813 | } |
| 814 | |
| 815 | static void |
| 816 | forget_cached_source_info_partial (struct objfile *objfile) |
| 817 | { |
| 818 | struct partial_symtab *pst; |
| 819 | |
| 820 | ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst) |
| 821 | { |
| 822 | if (pst->fullname != NULL) |
| 823 | { |
| 824 | xfree (pst->fullname); |
| 825 | pst->fullname = NULL; |
| 826 | } |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | static void |
| 831 | print_partial_symbols (struct gdbarch *gdbarch, |
| 832 | struct partial_symbol **p, int count, char *what, |
| 833 | struct ui_file *outfile) |
| 834 | { |
| 835 | fprintf_filtered (outfile, " %s partial symbols:\n", what); |
| 836 | while (count-- > 0) |
| 837 | { |
| 838 | fprintf_filtered (outfile, " `%s'", SYMBOL_LINKAGE_NAME (*p)); |
| 839 | if (SYMBOL_DEMANGLED_NAME (*p) != NULL) |
| 840 | { |
| 841 | fprintf_filtered (outfile, " `%s'", SYMBOL_DEMANGLED_NAME (*p)); |
| 842 | } |
| 843 | fputs_filtered (", ", outfile); |
| 844 | switch (SYMBOL_DOMAIN (*p)) |
| 845 | { |
| 846 | case UNDEF_DOMAIN: |
| 847 | fputs_filtered ("undefined domain, ", outfile); |
| 848 | break; |
| 849 | case VAR_DOMAIN: |
| 850 | /* This is the usual thing -- don't print it. */ |
| 851 | break; |
| 852 | case STRUCT_DOMAIN: |
| 853 | fputs_filtered ("struct domain, ", outfile); |
| 854 | break; |
| 855 | case LABEL_DOMAIN: |
| 856 | fputs_filtered ("label domain, ", outfile); |
| 857 | break; |
| 858 | default: |
| 859 | fputs_filtered ("<invalid domain>, ", outfile); |
| 860 | break; |
| 861 | } |
| 862 | switch (SYMBOL_CLASS (*p)) |
| 863 | { |
| 864 | case LOC_UNDEF: |
| 865 | fputs_filtered ("undefined", outfile); |
| 866 | break; |
| 867 | case LOC_CONST: |
| 868 | fputs_filtered ("constant int", outfile); |
| 869 | break; |
| 870 | case LOC_STATIC: |
| 871 | fputs_filtered ("static", outfile); |
| 872 | break; |
| 873 | case LOC_REGISTER: |
| 874 | fputs_filtered ("register", outfile); |
| 875 | break; |
| 876 | case LOC_ARG: |
| 877 | fputs_filtered ("pass by value", outfile); |
| 878 | break; |
| 879 | case LOC_REF_ARG: |
| 880 | fputs_filtered ("pass by reference", outfile); |
| 881 | break; |
| 882 | case LOC_REGPARM_ADDR: |
| 883 | fputs_filtered ("register address parameter", outfile); |
| 884 | break; |
| 885 | case LOC_LOCAL: |
| 886 | fputs_filtered ("stack parameter", outfile); |
| 887 | break; |
| 888 | case LOC_TYPEDEF: |
| 889 | fputs_filtered ("type", outfile); |
| 890 | break; |
| 891 | case LOC_LABEL: |
| 892 | fputs_filtered ("label", outfile); |
| 893 | break; |
| 894 | case LOC_BLOCK: |
| 895 | fputs_filtered ("function", outfile); |
| 896 | break; |
| 897 | case LOC_CONST_BYTES: |
| 898 | fputs_filtered ("constant bytes", outfile); |
| 899 | break; |
| 900 | case LOC_UNRESOLVED: |
| 901 | fputs_filtered ("unresolved", outfile); |
| 902 | break; |
| 903 | case LOC_OPTIMIZED_OUT: |
| 904 | fputs_filtered ("optimized out", outfile); |
| 905 | break; |
| 906 | case LOC_COMPUTED: |
| 907 | fputs_filtered ("computed at runtime", outfile); |
| 908 | break; |
| 909 | default: |
| 910 | fputs_filtered ("<invalid location>", outfile); |
| 911 | break; |
| 912 | } |
| 913 | fputs_filtered (", ", outfile); |
| 914 | fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (*p)), outfile); |
| 915 | fprintf_filtered (outfile, "\n"); |
| 916 | p++; |
| 917 | } |
| 918 | } |
| 919 | |
| 920 | static void |
| 921 | dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab, |
| 922 | struct ui_file *outfile) |
| 923 | { |
| 924 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
| 925 | int i; |
| 926 | |
| 927 | fprintf_filtered (outfile, "\nPartial symtab for source file %s ", |
| 928 | psymtab->filename); |
| 929 | fprintf_filtered (outfile, "(object "); |
| 930 | gdb_print_host_address (psymtab, outfile); |
| 931 | fprintf_filtered (outfile, ")\n\n"); |
| 932 | fprintf_unfiltered (outfile, " Read from object file %s (", |
| 933 | objfile->name); |
| 934 | gdb_print_host_address (objfile, outfile); |
| 935 | fprintf_unfiltered (outfile, ")\n"); |
| 936 | |
| 937 | if (psymtab->readin) |
| 938 | { |
| 939 | fprintf_filtered (outfile, |
| 940 | " Full symtab was read (at "); |
| 941 | gdb_print_host_address (psymtab->symtab, outfile); |
| 942 | fprintf_filtered (outfile, " by function at "); |
| 943 | gdb_print_host_address (psymtab->read_symtab, outfile); |
| 944 | fprintf_filtered (outfile, ")\n"); |
| 945 | } |
| 946 | |
| 947 | fprintf_filtered (outfile, " Relocate symbols by "); |
| 948 | for (i = 0; i < psymtab->objfile->num_sections; ++i) |
| 949 | { |
| 950 | if (i != 0) |
| 951 | fprintf_filtered (outfile, ", "); |
| 952 | wrap_here (" "); |
| 953 | fputs_filtered (paddress (gdbarch, |
| 954 | ANOFFSET (psymtab->section_offsets, i)), |
| 955 | outfile); |
| 956 | } |
| 957 | fprintf_filtered (outfile, "\n"); |
| 958 | |
| 959 | fprintf_filtered (outfile, " Symbols cover text addresses "); |
| 960 | fputs_filtered (paddress (gdbarch, psymtab->textlow), outfile); |
| 961 | fprintf_filtered (outfile, "-"); |
| 962 | fputs_filtered (paddress (gdbarch, psymtab->texthigh), outfile); |
| 963 | fprintf_filtered (outfile, "\n"); |
| 964 | fprintf_filtered (outfile, " Depends on %d other partial symtabs.\n", |
| 965 | psymtab->number_of_dependencies); |
| 966 | for (i = 0; i < psymtab->number_of_dependencies; i++) |
| 967 | { |
| 968 | fprintf_filtered (outfile, " %d ", i); |
| 969 | gdb_print_host_address (psymtab->dependencies[i], outfile); |
| 970 | fprintf_filtered (outfile, " %s\n", |
| 971 | psymtab->dependencies[i]->filename); |
| 972 | } |
| 973 | if (psymtab->n_global_syms > 0) |
| 974 | { |
| 975 | print_partial_symbols (gdbarch, |
| 976 | objfile->global_psymbols.list |
| 977 | + psymtab->globals_offset, |
| 978 | psymtab->n_global_syms, "Global", outfile); |
| 979 | } |
| 980 | if (psymtab->n_static_syms > 0) |
| 981 | { |
| 982 | print_partial_symbols (gdbarch, |
| 983 | objfile->static_psymbols.list |
| 984 | + psymtab->statics_offset, |
| 985 | psymtab->n_static_syms, "Static", outfile); |
| 986 | } |
| 987 | fprintf_filtered (outfile, "\n"); |
| 988 | } |
| 989 | |
| 990 | static void |
| 991 | print_psymtab_stats_for_objfile (struct objfile *objfile) |
| 992 | { |
| 993 | int i; |
| 994 | struct partial_symtab *ps; |
| 995 | |
| 996 | i = 0; |
| 997 | ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps) |
| 998 | { |
| 999 | if (ps->readin == 0) |
| 1000 | i++; |
| 1001 | } |
| 1002 | printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i); |
| 1003 | } |
| 1004 | |
| 1005 | static void |
| 1006 | dump_psymtabs_for_objfile (struct objfile *objfile) |
| 1007 | { |
| 1008 | struct partial_symtab *psymtab; |
| 1009 | |
| 1010 | if (objfile->psymtabs) |
| 1011 | { |
| 1012 | printf_filtered ("Psymtabs:\n"); |
| 1013 | for (psymtab = objfile->psymtabs; |
| 1014 | psymtab != NULL; |
| 1015 | psymtab = psymtab->next) |
| 1016 | { |
| 1017 | printf_filtered ("%s at ", |
| 1018 | psymtab->filename); |
| 1019 | gdb_print_host_address (psymtab, gdb_stdout); |
| 1020 | printf_filtered (", "); |
| 1021 | if (psymtab->objfile != objfile) |
| 1022 | { |
| 1023 | printf_filtered ("NOT ON CHAIN! "); |
| 1024 | } |
| 1025 | wrap_here (" "); |
| 1026 | } |
| 1027 | printf_filtered ("\n\n"); |
| 1028 | } |
| 1029 | } |
| 1030 | |
| 1031 | /* Look through the partial symtabs for all symbols which begin |
| 1032 | by matching FUNC_NAME. Make sure we read that symbol table in. */ |
| 1033 | |
| 1034 | static void |
| 1035 | read_symtabs_for_function (struct objfile *objfile, const char *func_name) |
| 1036 | { |
| 1037 | struct partial_symtab *ps; |
| 1038 | |
| 1039 | ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps) |
| 1040 | { |
| 1041 | if (ps->readin) |
| 1042 | continue; |
| 1043 | |
| 1044 | if ((lookup_partial_symbol (ps, func_name, 1, VAR_DOMAIN) |
| 1045 | != NULL) |
| 1046 | || (lookup_partial_symbol (ps, func_name, 0, VAR_DOMAIN) |
| 1047 | != NULL)) |
| 1048 | psymtab_to_symtab (ps); |
| 1049 | } |
| 1050 | } |
| 1051 | |
| 1052 | static void |
| 1053 | expand_partial_symbol_tables (struct objfile *objfile) |
| 1054 | { |
| 1055 | struct partial_symtab *psymtab; |
| 1056 | |
| 1057 | ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, psymtab) |
| 1058 | { |
| 1059 | psymtab_to_symtab (psymtab); |
| 1060 | } |
| 1061 | } |
| 1062 | |
| 1063 | static void |
| 1064 | read_psymtabs_with_filename (struct objfile *objfile, const char *filename) |
| 1065 | { |
| 1066 | struct partial_symtab *p; |
| 1067 | |
| 1068 | ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p) |
| 1069 | { |
| 1070 | if (strcmp (filename, p->filename) == 0) |
| 1071 | PSYMTAB_TO_SYMTAB (p); |
| 1072 | } |
| 1073 | } |
| 1074 | |
| 1075 | static void |
| 1076 | map_symbol_names_psymtab (struct objfile *objfile, |
| 1077 | void (*fun) (const char *, void *), void *data) |
| 1078 | { |
| 1079 | struct partial_symtab *ps; |
| 1080 | |
| 1081 | ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps) |
| 1082 | { |
| 1083 | struct partial_symbol **psym; |
| 1084 | |
| 1085 | /* If the psymtab's been read in we'll get it when we search |
| 1086 | through the blockvector. */ |
| 1087 | if (ps->readin) |
| 1088 | continue; |
| 1089 | |
| 1090 | for (psym = objfile->global_psymbols.list + ps->globals_offset; |
| 1091 | psym < (objfile->global_psymbols.list + ps->globals_offset |
| 1092 | + ps->n_global_syms); |
| 1093 | psym++) |
| 1094 | { |
| 1095 | /* If interrupted, then quit. */ |
| 1096 | QUIT; |
| 1097 | (*fun) (SYMBOL_NATURAL_NAME (*psym), data); |
| 1098 | } |
| 1099 | |
| 1100 | for (psym = objfile->static_psymbols.list + ps->statics_offset; |
| 1101 | psym < (objfile->static_psymbols.list + ps->statics_offset |
| 1102 | + ps->n_static_syms); |
| 1103 | psym++) |
| 1104 | { |
| 1105 | QUIT; |
| 1106 | (*fun) (SYMBOL_NATURAL_NAME (*psym), data); |
| 1107 | } |
| 1108 | } |
| 1109 | } |
| 1110 | |
| 1111 | static void |
| 1112 | map_symbol_filenames_psymtab (struct objfile *objfile, |
| 1113 | void (*fun) (const char *, const char *, |
| 1114 | void *), |
| 1115 | void *data) |
| 1116 | { |
| 1117 | struct partial_symtab *ps; |
| 1118 | |
| 1119 | ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps) |
| 1120 | { |
| 1121 | const char *fullname; |
| 1122 | |
| 1123 | if (ps->readin) |
| 1124 | continue; |
| 1125 | |
| 1126 | fullname = psymtab_to_fullname (ps); |
| 1127 | (*fun) (ps->filename, fullname, data); |
| 1128 | } |
| 1129 | } |
| 1130 | |
| 1131 | int find_and_open_source (const char *filename, |
| 1132 | const char *dirname, |
| 1133 | char **fullname); |
| 1134 | |
| 1135 | /* Finds the fullname that a partial_symtab represents. |
| 1136 | |
| 1137 | If this functions finds the fullname, it will save it in ps->fullname |
| 1138 | and it will also return the value. |
| 1139 | |
| 1140 | If this function fails to find the file that this partial_symtab represents, |
| 1141 | NULL will be returned and ps->fullname will be set to NULL. */ |
| 1142 | static char * |
| 1143 | psymtab_to_fullname (struct partial_symtab *ps) |
| 1144 | { |
| 1145 | int r; |
| 1146 | |
| 1147 | if (!ps) |
| 1148 | return NULL; |
| 1149 | |
| 1150 | /* Don't check ps->fullname here, the file could have been |
| 1151 | deleted/moved/..., look for it again. */ |
| 1152 | r = find_and_open_source (ps->filename, ps->dirname, &ps->fullname); |
| 1153 | |
| 1154 | if (r >= 0) |
| 1155 | { |
| 1156 | close (r); |
| 1157 | return ps->fullname; |
| 1158 | } |
| 1159 | |
| 1160 | return NULL; |
| 1161 | } |
| 1162 | |
| 1163 | static const char * |
| 1164 | find_symbol_file_from_partial (struct objfile *objfile, const char *name) |
| 1165 | { |
| 1166 | struct partial_symtab *pst; |
| 1167 | |
| 1168 | ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst) |
| 1169 | { |
| 1170 | if (lookup_partial_symbol (pst, name, 1, VAR_DOMAIN)) |
| 1171 | return pst->filename; |
| 1172 | } |
| 1173 | return NULL; |
| 1174 | } |
| 1175 | |
| 1176 | /* For all symbols, s, in BLOCK that are in NAMESPACE and match NAME |
| 1177 | according to the function MATCH, call CALLBACK(BLOCK, s, DATA). |
| 1178 | BLOCK is assumed to come from OBJFILE. Returns 1 iff CALLBACK |
| 1179 | ever returns non-zero, and otherwise returns 0. */ |
| 1180 | |
| 1181 | static int |
| 1182 | map_block (const char *name, domain_enum namespace, struct objfile *objfile, |
| 1183 | struct block *block, |
| 1184 | int (*callback) (struct block *, struct symbol *, void *), |
| 1185 | void *data, symbol_compare_ftype *match) |
| 1186 | { |
| 1187 | struct dict_iterator iter; |
| 1188 | struct symbol *sym; |
| 1189 | |
| 1190 | for (sym = dict_iter_match_first (BLOCK_DICT (block), name, match, &iter); |
| 1191 | sym != NULL; sym = dict_iter_match_next (name, match, &iter)) |
| 1192 | { |
| 1193 | if (symbol_matches_domain (SYMBOL_LANGUAGE (sym), |
| 1194 | SYMBOL_DOMAIN (sym), namespace)) |
| 1195 | { |
| 1196 | if (callback (block, sym, data)) |
| 1197 | return 1; |
| 1198 | } |
| 1199 | } |
| 1200 | |
| 1201 | return 0; |
| 1202 | } |
| 1203 | |
| 1204 | /* Psymtab version of map_matching_symbols. See its definition in |
| 1205 | the definition of quick_symbol_functions in symfile.h. */ |
| 1206 | |
| 1207 | static void |
| 1208 | map_matching_symbols_psymtab (const char *name, domain_enum namespace, |
| 1209 | struct objfile *objfile, int global, |
| 1210 | int (*callback) (struct block *, |
| 1211 | struct symbol *, void *), |
| 1212 | void *data, |
| 1213 | symbol_compare_ftype *match, |
| 1214 | symbol_compare_ftype *ordered_compare) |
| 1215 | { |
| 1216 | const int block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK; |
| 1217 | struct partial_symtab *ps; |
| 1218 | |
| 1219 | ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps) |
| 1220 | { |
| 1221 | QUIT; |
| 1222 | if (ps->readin |
| 1223 | || match_partial_symbol (ps, global, name, namespace, match, |
| 1224 | ordered_compare)) |
| 1225 | { |
| 1226 | struct symtab *s = PSYMTAB_TO_SYMTAB (ps); |
| 1227 | struct block *block; |
| 1228 | |
| 1229 | if (s == NULL || !s->primary) |
| 1230 | continue; |
| 1231 | block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), block_kind); |
| 1232 | if (map_block (name, namespace, objfile, block, |
| 1233 | callback, data, match)) |
| 1234 | return; |
| 1235 | if (callback (block, NULL, data)) |
| 1236 | return; |
| 1237 | } |
| 1238 | } |
| 1239 | } |
| 1240 | |
| 1241 | static void |
| 1242 | expand_symtabs_matching_via_partial (struct objfile *objfile, |
| 1243 | int (*file_matcher) (const char *, |
| 1244 | void *), |
| 1245 | int (*name_matcher) (const char *, |
| 1246 | void *), |
| 1247 | domain_enum kind, |
| 1248 | void *data) |
| 1249 | { |
| 1250 | struct partial_symtab *ps; |
| 1251 | |
| 1252 | ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps) |
| 1253 | { |
| 1254 | struct partial_symbol **psym; |
| 1255 | struct partial_symbol **bound, **gbound, **sbound; |
| 1256 | int keep_going = 1; |
| 1257 | |
| 1258 | if (ps->readin) |
| 1259 | continue; |
| 1260 | |
| 1261 | if (! (*file_matcher) (ps->filename, data)) |
| 1262 | continue; |
| 1263 | |
| 1264 | gbound = objfile->global_psymbols.list |
| 1265 | + ps->globals_offset + ps->n_global_syms; |
| 1266 | sbound = objfile->static_psymbols.list |
| 1267 | + ps->statics_offset + ps->n_static_syms; |
| 1268 | bound = gbound; |
| 1269 | |
| 1270 | /* Go through all of the symbols stored in a partial |
| 1271 | symtab in one loop. */ |
| 1272 | psym = objfile->global_psymbols.list + ps->globals_offset; |
| 1273 | while (keep_going) |
| 1274 | { |
| 1275 | if (psym >= bound) |
| 1276 | { |
| 1277 | if (bound == gbound && ps->n_static_syms != 0) |
| 1278 | { |
| 1279 | psym = objfile->static_psymbols.list + ps->statics_offset; |
| 1280 | bound = sbound; |
| 1281 | } |
| 1282 | else |
| 1283 | keep_going = 0; |
| 1284 | continue; |
| 1285 | } |
| 1286 | else |
| 1287 | { |
| 1288 | QUIT; |
| 1289 | |
| 1290 | if ((*name_matcher) (SYMBOL_NATURAL_NAME (*psym), data) |
| 1291 | && ((kind == VARIABLES_DOMAIN |
| 1292 | && SYMBOL_CLASS (*psym) != LOC_TYPEDEF |
| 1293 | && SYMBOL_CLASS (*psym) != LOC_BLOCK) |
| 1294 | || (kind == FUNCTIONS_DOMAIN |
| 1295 | && SYMBOL_CLASS (*psym) == LOC_BLOCK) |
| 1296 | || (kind == TYPES_DOMAIN |
| 1297 | && SYMBOL_CLASS (*psym) == LOC_TYPEDEF))) |
| 1298 | { |
| 1299 | PSYMTAB_TO_SYMTAB (ps); |
| 1300 | keep_going = 0; |
| 1301 | } |
| 1302 | } |
| 1303 | psym++; |
| 1304 | } |
| 1305 | } |
| 1306 | } |
| 1307 | |
| 1308 | static int |
| 1309 | objfile_has_psyms (struct objfile *objfile) |
| 1310 | { |
| 1311 | return objfile->psymtabs != NULL; |
| 1312 | } |
| 1313 | |
| 1314 | const struct quick_symbol_functions psym_functions = |
| 1315 | { |
| 1316 | objfile_has_psyms, |
| 1317 | find_last_source_symtab_from_partial, |
| 1318 | forget_cached_source_info_partial, |
| 1319 | lookup_symtab_via_partial_symtab, |
| 1320 | lookup_symbol_aux_psymtabs, |
| 1321 | pre_expand_symtabs_matching_psymtabs, |
| 1322 | print_psymtab_stats_for_objfile, |
| 1323 | dump_psymtabs_for_objfile, |
| 1324 | relocate_psymtabs, |
| 1325 | read_symtabs_for_function, |
| 1326 | expand_partial_symbol_tables, |
| 1327 | read_psymtabs_with_filename, |
| 1328 | find_symbol_file_from_partial, |
| 1329 | map_matching_symbols_psymtab, |
| 1330 | expand_symtabs_matching_via_partial, |
| 1331 | find_pc_sect_symtab_from_partial, |
| 1332 | map_symbol_names_psymtab, |
| 1333 | map_symbol_filenames_psymtab |
| 1334 | }; |
| 1335 | |
| 1336 | \f |
| 1337 | |
| 1338 | /* This compares two partial symbols by names, using strcmp_iw_ordered |
| 1339 | for the comparison. */ |
| 1340 | |
| 1341 | static int |
| 1342 | compare_psymbols (const void *s1p, const void *s2p) |
| 1343 | { |
| 1344 | struct partial_symbol *const *s1 = s1p; |
| 1345 | struct partial_symbol *const *s2 = s2p; |
| 1346 | |
| 1347 | return strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*s1), |
| 1348 | SYMBOL_SEARCH_NAME (*s2)); |
| 1349 | } |
| 1350 | |
| 1351 | void |
| 1352 | sort_pst_symbols (struct partial_symtab *pst) |
| 1353 | { |
| 1354 | /* Sort the global list; don't sort the static list. */ |
| 1355 | |
| 1356 | qsort (pst->objfile->global_psymbols.list + pst->globals_offset, |
| 1357 | pst->n_global_syms, sizeof (struct partial_symbol *), |
| 1358 | compare_psymbols); |
| 1359 | } |
| 1360 | |
| 1361 | /* Allocate and partially fill a partial symtab. It will be |
| 1362 | completely filled at the end of the symbol list. |
| 1363 | |
| 1364 | FILENAME is the name of the symbol-file we are reading from. */ |
| 1365 | |
| 1366 | struct partial_symtab * |
| 1367 | start_psymtab_common (struct objfile *objfile, |
| 1368 | struct section_offsets *section_offsets, |
| 1369 | const char *filename, |
| 1370 | CORE_ADDR textlow, struct partial_symbol **global_syms, |
| 1371 | struct partial_symbol **static_syms) |
| 1372 | { |
| 1373 | struct partial_symtab *psymtab; |
| 1374 | |
| 1375 | psymtab = allocate_psymtab (filename, objfile); |
| 1376 | psymtab->section_offsets = section_offsets; |
| 1377 | psymtab->textlow = textlow; |
| 1378 | psymtab->texthigh = psymtab->textlow; /* default */ |
| 1379 | psymtab->globals_offset = global_syms - objfile->global_psymbols.list; |
| 1380 | psymtab->statics_offset = static_syms - objfile->static_psymbols.list; |
| 1381 | return (psymtab); |
| 1382 | } |
| 1383 | |
| 1384 | /* Calculate a hash code for the given partial symbol. The hash is |
| 1385 | calculated using the symbol's value, language, domain, class |
| 1386 | and name. These are the values which are set by |
| 1387 | add_psymbol_to_bcache. */ |
| 1388 | |
| 1389 | static unsigned long |
| 1390 | psymbol_hash (const void *addr, int length) |
| 1391 | { |
| 1392 | unsigned long h = 0; |
| 1393 | struct partial_symbol *psymbol = (struct partial_symbol *) addr; |
| 1394 | unsigned int lang = psymbol->ginfo.language; |
| 1395 | unsigned int domain = PSYMBOL_DOMAIN (psymbol); |
| 1396 | unsigned int class = PSYMBOL_CLASS (psymbol); |
| 1397 | |
| 1398 | h = hash_continue (&psymbol->ginfo.value, sizeof (psymbol->ginfo.value), h); |
| 1399 | h = hash_continue (&lang, sizeof (unsigned int), h); |
| 1400 | h = hash_continue (&domain, sizeof (unsigned int), h); |
| 1401 | h = hash_continue (&class, sizeof (unsigned int), h); |
| 1402 | h = hash_continue (psymbol->ginfo.name, strlen (psymbol->ginfo.name), h); |
| 1403 | |
| 1404 | return h; |
| 1405 | } |
| 1406 | |
| 1407 | /* Returns true if the symbol at addr1 equals the symbol at addr2. |
| 1408 | For the comparison this function uses a symbols value, |
| 1409 | language, domain, class and name. */ |
| 1410 | |
| 1411 | static int |
| 1412 | psymbol_compare (const void *addr1, const void *addr2, int length) |
| 1413 | { |
| 1414 | struct partial_symbol *sym1 = (struct partial_symbol *) addr1; |
| 1415 | struct partial_symbol *sym2 = (struct partial_symbol *) addr2; |
| 1416 | |
| 1417 | return (memcmp (&sym1->ginfo.value, &sym1->ginfo.value, |
| 1418 | sizeof (sym1->ginfo.value)) == 0 |
| 1419 | && sym1->ginfo.language == sym2->ginfo.language |
| 1420 | && PSYMBOL_DOMAIN (sym1) == PSYMBOL_DOMAIN (sym2) |
| 1421 | && PSYMBOL_CLASS (sym1) == PSYMBOL_CLASS (sym2) |
| 1422 | && sym1->ginfo.name == sym2->ginfo.name); |
| 1423 | } |
| 1424 | |
| 1425 | /* Initialize a partial symbol bcache. */ |
| 1426 | |
| 1427 | struct psymbol_bcache * |
| 1428 | psymbol_bcache_init (void) |
| 1429 | { |
| 1430 | struct psymbol_bcache *bcache = XCALLOC (1, struct psymbol_bcache); |
| 1431 | bcache->bcache = bcache_xmalloc (psymbol_hash, psymbol_compare); |
| 1432 | return bcache; |
| 1433 | } |
| 1434 | |
| 1435 | /* Free a partial symbol bcache. */ |
| 1436 | void |
| 1437 | psymbol_bcache_free (struct psymbol_bcache *bcache) |
| 1438 | { |
| 1439 | if (bcache == NULL) |
| 1440 | return; |
| 1441 | |
| 1442 | bcache_xfree (bcache->bcache); |
| 1443 | xfree (bcache); |
| 1444 | } |
| 1445 | |
| 1446 | /* Return the internal bcache of the psymbol_bcache BCACHE. */ |
| 1447 | |
| 1448 | struct bcache * |
| 1449 | psymbol_bcache_get_bcache (struct psymbol_bcache *bcache) |
| 1450 | { |
| 1451 | return bcache->bcache; |
| 1452 | } |
| 1453 | |
| 1454 | /* Find a copy of the SYM in BCACHE. If BCACHE has never seen this |
| 1455 | symbol before, add a copy to BCACHE. In either case, return a pointer |
| 1456 | to BCACHE's copy of the symbol. If optional ADDED is not NULL, return |
| 1457 | 1 in case of new entry or 0 if returning an old entry. */ |
| 1458 | |
| 1459 | static const struct partial_symbol * |
| 1460 | psymbol_bcache_full (struct partial_symbol *sym, |
| 1461 | struct psymbol_bcache *bcache, |
| 1462 | int *added) |
| 1463 | { |
| 1464 | return bcache_full (sym, |
| 1465 | sizeof (struct partial_symbol), |
| 1466 | bcache->bcache, |
| 1467 | added); |
| 1468 | } |
| 1469 | |
| 1470 | /* Helper function, initialises partial symbol structure and stashes |
| 1471 | it into objfile's bcache. Note that our caching mechanism will |
| 1472 | use all fields of struct partial_symbol to determine hash value of the |
| 1473 | structure. In other words, having two symbols with the same name but |
| 1474 | different domain (or address) is possible and correct. */ |
| 1475 | |
| 1476 | static const struct partial_symbol * |
| 1477 | add_psymbol_to_bcache (const char *name, int namelength, int copy_name, |
| 1478 | domain_enum domain, |
| 1479 | enum address_class class, |
| 1480 | long val, /* Value as a long */ |
| 1481 | CORE_ADDR coreaddr, /* Value as a CORE_ADDR */ |
| 1482 | enum language language, struct objfile *objfile, |
| 1483 | int *added) |
| 1484 | { |
| 1485 | struct partial_symbol psymbol; |
| 1486 | |
| 1487 | /* We must ensure that the entire 'value' field has been zeroed |
| 1488 | before assigning to it, because an assignment may not write the |
| 1489 | entire field. */ |
| 1490 | memset (&psymbol.ginfo.value, 0, sizeof (psymbol.ginfo.value)); |
| 1491 | |
| 1492 | /* val and coreaddr are mutually exclusive, one of them *will* be zero. */ |
| 1493 | if (val != 0) |
| 1494 | { |
| 1495 | SYMBOL_VALUE (&psymbol) = val; |
| 1496 | } |
| 1497 | else |
| 1498 | { |
| 1499 | SYMBOL_VALUE_ADDRESS (&psymbol) = coreaddr; |
| 1500 | } |
| 1501 | SYMBOL_SECTION (&psymbol) = 0; |
| 1502 | SYMBOL_OBJ_SECTION (&psymbol) = NULL; |
| 1503 | SYMBOL_SET_LANGUAGE (&psymbol, language); |
| 1504 | PSYMBOL_DOMAIN (&psymbol) = domain; |
| 1505 | PSYMBOL_CLASS (&psymbol) = class; |
| 1506 | |
| 1507 | SYMBOL_SET_NAMES (&psymbol, name, namelength, copy_name, objfile); |
| 1508 | |
| 1509 | /* Stash the partial symbol away in the cache. */ |
| 1510 | return psymbol_bcache_full (&psymbol, |
| 1511 | objfile->psymbol_cache, |
| 1512 | added); |
| 1513 | } |
| 1514 | |
| 1515 | /* Increase the space allocated for LISTP, which is probably |
| 1516 | global_psymbols or static_psymbols. This space will eventually |
| 1517 | be freed in free_objfile(). */ |
| 1518 | |
| 1519 | static void |
| 1520 | extend_psymbol_list (struct psymbol_allocation_list *listp, |
| 1521 | struct objfile *objfile) |
| 1522 | { |
| 1523 | int new_size; |
| 1524 | |
| 1525 | if (listp->size == 0) |
| 1526 | { |
| 1527 | new_size = 255; |
| 1528 | listp->list = (struct partial_symbol **) |
| 1529 | xmalloc (new_size * sizeof (struct partial_symbol *)); |
| 1530 | } |
| 1531 | else |
| 1532 | { |
| 1533 | new_size = listp->size * 2; |
| 1534 | listp->list = (struct partial_symbol **) |
| 1535 | xrealloc ((char *) listp->list, |
| 1536 | new_size * sizeof (struct partial_symbol *)); |
| 1537 | } |
| 1538 | /* Next assumes we only went one over. Should be good if |
| 1539 | program works correctly. */ |
| 1540 | listp->next = listp->list + listp->size; |
| 1541 | listp->size = new_size; |
| 1542 | } |
| 1543 | |
| 1544 | /* Helper function, adds partial symbol to the given partial symbol |
| 1545 | list. */ |
| 1546 | |
| 1547 | static void |
| 1548 | append_psymbol_to_list (struct psymbol_allocation_list *list, |
| 1549 | const struct partial_symbol *psym, |
| 1550 | struct objfile *objfile) |
| 1551 | { |
| 1552 | if (list->next >= list->list + list->size) |
| 1553 | extend_psymbol_list (list, objfile); |
| 1554 | *list->next++ = (struct partial_symbol *) psym; |
| 1555 | OBJSTAT (objfile, n_psyms++); |
| 1556 | } |
| 1557 | |
| 1558 | /* Add a symbol with a long value to a psymtab. |
| 1559 | Since one arg is a struct, we pass in a ptr and deref it (sigh). |
| 1560 | Return the partial symbol that has been added. */ |
| 1561 | |
| 1562 | /* NOTE: carlton/2003-09-11: The reason why we return the partial |
| 1563 | symbol is so that callers can get access to the symbol's demangled |
| 1564 | name, which they don't have any cheap way to determine otherwise. |
| 1565 | (Currenly, dwarf2read.c is the only file who uses that information, |
| 1566 | though it's possible that other readers might in the future.) |
| 1567 | Elena wasn't thrilled about that, and I don't blame her, but we |
| 1568 | couldn't come up with a better way to get that information. If |
| 1569 | it's needed in other situations, we could consider breaking up |
| 1570 | SYMBOL_SET_NAMES to provide access to the demangled name lookup |
| 1571 | cache. */ |
| 1572 | |
| 1573 | const struct partial_symbol * |
| 1574 | add_psymbol_to_list (const char *name, int namelength, int copy_name, |
| 1575 | domain_enum domain, |
| 1576 | enum address_class class, |
| 1577 | struct psymbol_allocation_list *list, |
| 1578 | long val, /* Value as a long */ |
| 1579 | CORE_ADDR coreaddr, /* Value as a CORE_ADDR */ |
| 1580 | enum language language, struct objfile *objfile) |
| 1581 | { |
| 1582 | const struct partial_symbol *psym; |
| 1583 | |
| 1584 | int added; |
| 1585 | |
| 1586 | /* Stash the partial symbol away in the cache. */ |
| 1587 | psym = add_psymbol_to_bcache (name, namelength, copy_name, domain, class, |
| 1588 | val, coreaddr, language, objfile, &added); |
| 1589 | |
| 1590 | /* Do not duplicate global partial symbols. */ |
| 1591 | if (list == &objfile->global_psymbols |
| 1592 | && !added) |
| 1593 | return psym; |
| 1594 | |
| 1595 | /* Save pointer to partial symbol in psymtab, growing symtab if needed. */ |
| 1596 | append_psymbol_to_list (list, psym, objfile); |
| 1597 | return psym; |
| 1598 | } |
| 1599 | |
| 1600 | /* Initialize storage for partial symbols. */ |
| 1601 | |
| 1602 | void |
| 1603 | init_psymbol_list (struct objfile *objfile, int total_symbols) |
| 1604 | { |
| 1605 | /* Free any previously allocated psymbol lists. */ |
| 1606 | |
| 1607 | if (objfile->global_psymbols.list) |
| 1608 | { |
| 1609 | xfree (objfile->global_psymbols.list); |
| 1610 | } |
| 1611 | if (objfile->static_psymbols.list) |
| 1612 | { |
| 1613 | xfree (objfile->static_psymbols.list); |
| 1614 | } |
| 1615 | |
| 1616 | /* Current best guess is that approximately a twentieth |
| 1617 | of the total symbols (in a debugging file) are global or static |
| 1618 | oriented symbols. */ |
| 1619 | |
| 1620 | objfile->global_psymbols.size = total_symbols / 10; |
| 1621 | objfile->static_psymbols.size = total_symbols / 10; |
| 1622 | |
| 1623 | if (objfile->global_psymbols.size > 0) |
| 1624 | { |
| 1625 | objfile->global_psymbols.next = |
| 1626 | objfile->global_psymbols.list = (struct partial_symbol **) |
| 1627 | xmalloc ((objfile->global_psymbols.size |
| 1628 | * sizeof (struct partial_symbol *))); |
| 1629 | } |
| 1630 | if (objfile->static_psymbols.size > 0) |
| 1631 | { |
| 1632 | objfile->static_psymbols.next = |
| 1633 | objfile->static_psymbols.list = (struct partial_symbol **) |
| 1634 | xmalloc ((objfile->static_psymbols.size |
| 1635 | * sizeof (struct partial_symbol *))); |
| 1636 | } |
| 1637 | } |
| 1638 | |
| 1639 | struct partial_symtab * |
| 1640 | allocate_psymtab (const char *filename, struct objfile *objfile) |
| 1641 | { |
| 1642 | struct partial_symtab *psymtab; |
| 1643 | |
| 1644 | if (objfile->free_psymtabs) |
| 1645 | { |
| 1646 | psymtab = objfile->free_psymtabs; |
| 1647 | objfile->free_psymtabs = psymtab->next; |
| 1648 | } |
| 1649 | else |
| 1650 | psymtab = (struct partial_symtab *) |
| 1651 | obstack_alloc (&objfile->objfile_obstack, |
| 1652 | sizeof (struct partial_symtab)); |
| 1653 | |
| 1654 | memset (psymtab, 0, sizeof (struct partial_symtab)); |
| 1655 | psymtab->filename = obsavestring (filename, strlen (filename), |
| 1656 | &objfile->objfile_obstack); |
| 1657 | psymtab->symtab = NULL; |
| 1658 | |
| 1659 | /* Prepend it to the psymtab list for the objfile it belongs to. |
| 1660 | Psymtabs are searched in most recent inserted -> least recent |
| 1661 | inserted order. */ |
| 1662 | |
| 1663 | psymtab->objfile = objfile; |
| 1664 | psymtab->next = objfile->psymtabs; |
| 1665 | objfile->psymtabs = psymtab; |
| 1666 | |
| 1667 | return (psymtab); |
| 1668 | } |
| 1669 | |
| 1670 | void |
| 1671 | discard_psymtab (struct partial_symtab *pst) |
| 1672 | { |
| 1673 | struct partial_symtab **prev_pst; |
| 1674 | |
| 1675 | /* From dbxread.c: |
| 1676 | Empty psymtabs happen as a result of header files which don't |
| 1677 | have any symbols in them. There can be a lot of them. But this |
| 1678 | check is wrong, in that a psymtab with N_SLINE entries but |
| 1679 | nothing else is not empty, but we don't realize that. Fixing |
| 1680 | that without slowing things down might be tricky. */ |
| 1681 | |
| 1682 | /* First, snip it out of the psymtab chain. */ |
| 1683 | |
| 1684 | prev_pst = &(pst->objfile->psymtabs); |
| 1685 | while ((*prev_pst) != pst) |
| 1686 | prev_pst = &((*prev_pst)->next); |
| 1687 | (*prev_pst) = pst->next; |
| 1688 | |
| 1689 | /* Next, put it on a free list for recycling. */ |
| 1690 | |
| 1691 | pst->next = pst->objfile->free_psymtabs; |
| 1692 | pst->objfile->free_psymtabs = pst; |
| 1693 | } |
| 1694 | |
| 1695 | \f |
| 1696 | |
| 1697 | void |
| 1698 | maintenance_print_psymbols (char *args, int from_tty) |
| 1699 | { |
| 1700 | char **argv; |
| 1701 | struct ui_file *outfile; |
| 1702 | struct cleanup *cleanups; |
| 1703 | char *symname = NULL; |
| 1704 | char *filename = DEV_TTY; |
| 1705 | struct objfile *objfile; |
| 1706 | struct partial_symtab *ps; |
| 1707 | |
| 1708 | dont_repeat (); |
| 1709 | |
| 1710 | if (args == NULL) |
| 1711 | { |
| 1712 | error (_("\ |
| 1713 | print-psymbols takes an output file name and optional symbol file name")); |
| 1714 | } |
| 1715 | argv = gdb_buildargv (args); |
| 1716 | cleanups = make_cleanup_freeargv (argv); |
| 1717 | |
| 1718 | if (argv[0] != NULL) |
| 1719 | { |
| 1720 | filename = argv[0]; |
| 1721 | /* If a second arg is supplied, it is a source file name to match on. */ |
| 1722 | if (argv[1] != NULL) |
| 1723 | { |
| 1724 | symname = argv[1]; |
| 1725 | } |
| 1726 | } |
| 1727 | |
| 1728 | filename = tilde_expand (filename); |
| 1729 | make_cleanup (xfree, filename); |
| 1730 | |
| 1731 | outfile = gdb_fopen (filename, FOPEN_WT); |
| 1732 | if (outfile == 0) |
| 1733 | perror_with_name (filename); |
| 1734 | make_cleanup_ui_file_delete (outfile); |
| 1735 | |
| 1736 | immediate_quit++; |
| 1737 | ALL_PSYMTABS (objfile, ps) |
| 1738 | if (symname == NULL || strcmp (symname, ps->filename) == 0) |
| 1739 | dump_psymtab (objfile, ps, outfile); |
| 1740 | immediate_quit--; |
| 1741 | do_cleanups (cleanups); |
| 1742 | } |
| 1743 | |
| 1744 | /* List all the partial symbol tables whose names match REGEXP (optional). */ |
| 1745 | void |
| 1746 | maintenance_info_psymtabs (char *regexp, int from_tty) |
| 1747 | { |
| 1748 | struct program_space *pspace; |
| 1749 | struct objfile *objfile; |
| 1750 | |
| 1751 | if (regexp) |
| 1752 | re_comp (regexp); |
| 1753 | |
| 1754 | ALL_PSPACES (pspace) |
| 1755 | ALL_PSPACE_OBJFILES (pspace, objfile) |
| 1756 | { |
| 1757 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
| 1758 | struct partial_symtab *psymtab; |
| 1759 | |
| 1760 | /* We don't want to print anything for this objfile until we |
| 1761 | actually find a symtab whose name matches. */ |
| 1762 | int printed_objfile_start = 0; |
| 1763 | |
| 1764 | ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, psymtab) |
| 1765 | { |
| 1766 | QUIT; |
| 1767 | |
| 1768 | if (! regexp |
| 1769 | || re_exec (psymtab->filename)) |
| 1770 | { |
| 1771 | if (! printed_objfile_start) |
| 1772 | { |
| 1773 | printf_filtered ("{ objfile %s ", objfile->name); |
| 1774 | wrap_here (" "); |
| 1775 | printf_filtered ("((struct objfile *) %s)\n", |
| 1776 | host_address_to_string (objfile)); |
| 1777 | printed_objfile_start = 1; |
| 1778 | } |
| 1779 | |
| 1780 | printf_filtered (" { psymtab %s ", psymtab->filename); |
| 1781 | wrap_here (" "); |
| 1782 | printf_filtered ("((struct partial_symtab *) %s)\n", |
| 1783 | host_address_to_string (psymtab)); |
| 1784 | |
| 1785 | printf_filtered (" readin %s\n", |
| 1786 | psymtab->readin ? "yes" : "no"); |
| 1787 | printf_filtered (" fullname %s\n", |
| 1788 | psymtab->fullname |
| 1789 | ? psymtab->fullname : "(null)"); |
| 1790 | printf_filtered (" text addresses "); |
| 1791 | fputs_filtered (paddress (gdbarch, psymtab->textlow), |
| 1792 | gdb_stdout); |
| 1793 | printf_filtered (" -- "); |
| 1794 | fputs_filtered (paddress (gdbarch, psymtab->texthigh), |
| 1795 | gdb_stdout); |
| 1796 | printf_filtered ("\n"); |
| 1797 | printf_filtered (" globals "); |
| 1798 | if (psymtab->n_global_syms) |
| 1799 | { |
| 1800 | printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n", |
| 1801 | host_address_to_string (psymtab->objfile->global_psymbols.list |
| 1802 | + psymtab->globals_offset), |
| 1803 | psymtab->n_global_syms); |
| 1804 | } |
| 1805 | else |
| 1806 | printf_filtered ("(none)\n"); |
| 1807 | printf_filtered (" statics "); |
| 1808 | if (psymtab->n_static_syms) |
| 1809 | { |
| 1810 | printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n", |
| 1811 | host_address_to_string (psymtab->objfile->static_psymbols.list |
| 1812 | + psymtab->statics_offset), |
| 1813 | psymtab->n_static_syms); |
| 1814 | } |
| 1815 | else |
| 1816 | printf_filtered ("(none)\n"); |
| 1817 | printf_filtered (" dependencies "); |
| 1818 | if (psymtab->number_of_dependencies) |
| 1819 | { |
| 1820 | int i; |
| 1821 | |
| 1822 | printf_filtered ("{\n"); |
| 1823 | for (i = 0; i < psymtab->number_of_dependencies; i++) |
| 1824 | { |
| 1825 | struct partial_symtab *dep = psymtab->dependencies[i]; |
| 1826 | |
| 1827 | /* Note the string concatenation there --- no comma. */ |
| 1828 | printf_filtered (" psymtab %s " |
| 1829 | "((struct partial_symtab *) %s)\n", |
| 1830 | dep->filename, |
| 1831 | host_address_to_string (dep)); |
| 1832 | } |
| 1833 | printf_filtered (" }\n"); |
| 1834 | } |
| 1835 | else |
| 1836 | printf_filtered ("(none)\n"); |
| 1837 | printf_filtered (" }\n"); |
| 1838 | } |
| 1839 | } |
| 1840 | |
| 1841 | if (printed_objfile_start) |
| 1842 | printf_filtered ("}\n"); |
| 1843 | } |
| 1844 | } |
| 1845 | |
| 1846 | /* Check consistency of psymtabs and symtabs. */ |
| 1847 | |
| 1848 | void |
| 1849 | maintenance_check_symtabs (char *ignore, int from_tty) |
| 1850 | { |
| 1851 | struct symbol *sym; |
| 1852 | struct partial_symbol **psym; |
| 1853 | struct symtab *s = NULL; |
| 1854 | struct partial_symtab *ps; |
| 1855 | struct blockvector *bv; |
| 1856 | struct objfile *objfile; |
| 1857 | struct block *b; |
| 1858 | int length; |
| 1859 | |
| 1860 | ALL_PSYMTABS (objfile, ps) |
| 1861 | { |
| 1862 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
| 1863 | |
| 1864 | s = PSYMTAB_TO_SYMTAB (ps); |
| 1865 | if (s == NULL) |
| 1866 | continue; |
| 1867 | bv = BLOCKVECTOR (s); |
| 1868 | b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); |
| 1869 | psym = ps->objfile->static_psymbols.list + ps->statics_offset; |
| 1870 | length = ps->n_static_syms; |
| 1871 | while (length--) |
| 1872 | { |
| 1873 | sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym), |
| 1874 | SYMBOL_DOMAIN (*psym)); |
| 1875 | if (!sym) |
| 1876 | { |
| 1877 | printf_filtered ("Static symbol `"); |
| 1878 | puts_filtered (SYMBOL_LINKAGE_NAME (*psym)); |
| 1879 | printf_filtered ("' only found in "); |
| 1880 | puts_filtered (ps->filename); |
| 1881 | printf_filtered (" psymtab\n"); |
| 1882 | } |
| 1883 | psym++; |
| 1884 | } |
| 1885 | b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); |
| 1886 | psym = ps->objfile->global_psymbols.list + ps->globals_offset; |
| 1887 | length = ps->n_global_syms; |
| 1888 | while (length--) |
| 1889 | { |
| 1890 | sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym), |
| 1891 | SYMBOL_DOMAIN (*psym)); |
| 1892 | if (!sym) |
| 1893 | { |
| 1894 | printf_filtered ("Global symbol `"); |
| 1895 | puts_filtered (SYMBOL_LINKAGE_NAME (*psym)); |
| 1896 | printf_filtered ("' only found in "); |
| 1897 | puts_filtered (ps->filename); |
| 1898 | printf_filtered (" psymtab\n"); |
| 1899 | } |
| 1900 | psym++; |
| 1901 | } |
| 1902 | if (ps->texthigh < ps->textlow) |
| 1903 | { |
| 1904 | printf_filtered ("Psymtab "); |
| 1905 | puts_filtered (ps->filename); |
| 1906 | printf_filtered (" covers bad range "); |
| 1907 | fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout); |
| 1908 | printf_filtered (" - "); |
| 1909 | fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout); |
| 1910 | printf_filtered ("\n"); |
| 1911 | continue; |
| 1912 | } |
| 1913 | if (ps->texthigh == 0) |
| 1914 | continue; |
| 1915 | if (ps->textlow < BLOCK_START (b) || ps->texthigh > BLOCK_END (b)) |
| 1916 | { |
| 1917 | printf_filtered ("Psymtab "); |
| 1918 | puts_filtered (ps->filename); |
| 1919 | printf_filtered (" covers "); |
| 1920 | fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout); |
| 1921 | printf_filtered (" - "); |
| 1922 | fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout); |
| 1923 | printf_filtered (" but symtab covers only "); |
| 1924 | fputs_filtered (paddress (gdbarch, BLOCK_START (b)), gdb_stdout); |
| 1925 | printf_filtered (" - "); |
| 1926 | fputs_filtered (paddress (gdbarch, BLOCK_END (b)), gdb_stdout); |
| 1927 | printf_filtered ("\n"); |
| 1928 | } |
| 1929 | } |
| 1930 | } |
| 1931 | |
| 1932 | \f |
| 1933 | |
| 1934 | void |
| 1935 | map_partial_symbol_names (void (*fun) (const char *, void *), void *data) |
| 1936 | { |
| 1937 | struct objfile *objfile; |
| 1938 | |
| 1939 | ALL_OBJFILES (objfile) |
| 1940 | { |
| 1941 | if (objfile->sf) |
| 1942 | objfile->sf->qf->map_symbol_names (objfile, fun, data); |
| 1943 | } |
| 1944 | } |
| 1945 | |
| 1946 | void |
| 1947 | map_partial_symbol_filenames (void (*fun) (const char *, const char *, |
| 1948 | void *), |
| 1949 | void *data) |
| 1950 | { |
| 1951 | struct objfile *objfile; |
| 1952 | |
| 1953 | ALL_OBJFILES (objfile) |
| 1954 | { |
| 1955 | if (objfile->sf) |
| 1956 | objfile->sf->qf->map_symbol_filenames (objfile, fun, data); |
| 1957 | } |
| 1958 | } |