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