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