| 1 | /* Generic symbol file reading for the GNU debugger, GDB. |
| 2 | Copyright 1990, 1991, 1992 Free Software Foundation, Inc. |
| 3 | Contributed by Cygnus Support, using pieces from other GDB modules. |
| 4 | |
| 5 | This file is part of GDB. |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 2 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program; if not, write to the Free Software |
| 19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
| 20 | |
| 21 | #include "defs.h" |
| 22 | #include "symtab.h" |
| 23 | #include "gdbtypes.h" |
| 24 | #include "gdbcore.h" |
| 25 | #include "frame.h" |
| 26 | #include "target.h" |
| 27 | #include "value.h" |
| 28 | #include "symfile.h" |
| 29 | #include "objfiles.h" |
| 30 | #include "gdbcmd.h" |
| 31 | #include "breakpoint.h" |
| 32 | |
| 33 | #include <obstack.h> |
| 34 | #include <assert.h> |
| 35 | |
| 36 | #include <sys/types.h> |
| 37 | #include <fcntl.h> |
| 38 | #include <string.h> |
| 39 | #include <sys/stat.h> |
| 40 | #include <ctype.h> |
| 41 | |
| 42 | /* Global variables owned by this file */ |
| 43 | |
| 44 | int readnow_symbol_files; /* Read full symbols immediately */ |
| 45 | |
| 46 | /* External variables and functions referenced. */ |
| 47 | |
| 48 | extern int info_verbose; |
| 49 | |
| 50 | /* Functions this file defines */ |
| 51 | |
| 52 | static void |
| 53 | load_command PARAMS ((char *, int)); |
| 54 | |
| 55 | static void |
| 56 | add_symbol_file_command PARAMS ((char *, int)); |
| 57 | |
| 58 | static void |
| 59 | cashier_psymtab PARAMS ((struct partial_symtab *)); |
| 60 | |
| 61 | static int |
| 62 | compare_psymbols PARAMS ((const void *, const void *)); |
| 63 | |
| 64 | static int |
| 65 | compare_symbols PARAMS ((const void *, const void *)); |
| 66 | |
| 67 | static bfd * |
| 68 | symfile_bfd_open PARAMS ((char *)); |
| 69 | |
| 70 | static void |
| 71 | find_sym_fns PARAMS ((struct objfile *)); |
| 72 | |
| 73 | void |
| 74 | clear_symtab_users_once PARAMS ((void)); |
| 75 | |
| 76 | /* List of all available sym_fns. On gdb startup, each object file reader |
| 77 | calls add_symtab_fns() to register information on each format it is |
| 78 | prepared to read. */ |
| 79 | |
| 80 | static struct sym_fns *symtab_fns = NULL; |
| 81 | |
| 82 | /* Structures with which to manage partial symbol allocation. */ |
| 83 | |
| 84 | struct psymbol_allocation_list global_psymbols = {0}, static_psymbols = {0}; |
| 85 | |
| 86 | /* Flag for whether user will be reloading symbols multiple times. |
| 87 | Defaults to ON for VxWorks, otherwise OFF. */ |
| 88 | |
| 89 | #ifdef SYMBOL_RELOADING_DEFAULT |
| 90 | int symbol_reloading = SYMBOL_RELOADING_DEFAULT; |
| 91 | #else |
| 92 | int symbol_reloading = 0; |
| 93 | #endif |
| 94 | |
| 95 | /* Structure to manage complaints about symbol file contents. */ |
| 96 | |
| 97 | struct complaint complaint_root[1] = { |
| 98 | {(char *) 0, 0, complaint_root}, |
| 99 | }; |
| 100 | |
| 101 | /* Some actual complaints. */ |
| 102 | |
| 103 | struct complaint oldsyms_complaint = { |
| 104 | "Replacing old symbols for `%s'", 0, 0 }; |
| 105 | |
| 106 | struct complaint empty_symtab_complaint = { |
| 107 | "Empty symbol table found for `%s'", 0, 0 }; |
| 108 | |
| 109 | \f |
| 110 | /* In the following sort, we always make sure that |
| 111 | register debug symbol declarations always come before regular |
| 112 | debug symbol declarations (as might happen when parameters are |
| 113 | then put into registers by the compiler). |
| 114 | |
| 115 | Since this function is called from within qsort, in an ANSI environment |
| 116 | it must conform to the prototype for qsort, which specifies that the |
| 117 | comparison function takes two "void *" pointers. */ |
| 118 | |
| 119 | static int |
| 120 | compare_symbols (s1p, s2p) |
| 121 | const PTR s1p; |
| 122 | const PTR s2p; |
| 123 | { |
| 124 | register struct symbol **s1, **s2; |
| 125 | register int namediff; |
| 126 | |
| 127 | s1 = (struct symbol **) s1p; |
| 128 | s2 = (struct symbol **) s2p; |
| 129 | |
| 130 | /* Compare the initial characters. */ |
| 131 | namediff = SYMBOL_NAME (*s1)[0] - SYMBOL_NAME (*s2)[0]; |
| 132 | if (namediff != 0) return namediff; |
| 133 | |
| 134 | /* If they match, compare the rest of the names. */ |
| 135 | namediff = strcmp (SYMBOL_NAME (*s1), SYMBOL_NAME (*s2)); |
| 136 | if (namediff != 0) return namediff; |
| 137 | |
| 138 | /* For symbols of the same name, registers should come first. */ |
| 139 | return ((SYMBOL_CLASS (*s2) == LOC_REGISTER) |
| 140 | - (SYMBOL_CLASS (*s1) == LOC_REGISTER)); |
| 141 | } |
| 142 | |
| 143 | /* |
| 144 | |
| 145 | LOCAL FUNCTION |
| 146 | |
| 147 | compare_psymbols -- compare two partial symbols by name |
| 148 | |
| 149 | DESCRIPTION |
| 150 | |
| 151 | Given pointer to two partial symbol table entries, compare |
| 152 | them by name and return -N, 0, or +N (ala strcmp). Typically |
| 153 | used by sorting routines like qsort(). |
| 154 | |
| 155 | NOTES |
| 156 | |
| 157 | Does direct compare of first two characters before punting |
| 158 | and passing to strcmp for longer compares. Note that the |
| 159 | original version had a bug whereby two null strings or two |
| 160 | identically named one character strings would return the |
| 161 | comparison of memory following the null byte. |
| 162 | |
| 163 | */ |
| 164 | |
| 165 | static int |
| 166 | compare_psymbols (s1p, s2p) |
| 167 | const PTR s1p; |
| 168 | const PTR s2p; |
| 169 | { |
| 170 | register char *st1 = SYMBOL_NAME ((struct partial_symbol *) s1p); |
| 171 | register char *st2 = SYMBOL_NAME ((struct partial_symbol *) s2p); |
| 172 | |
| 173 | if ((st1[0] - st2[0]) || !st1[0]) |
| 174 | { |
| 175 | return (st1[0] - st2[0]); |
| 176 | } |
| 177 | else if ((st1[1] - st2[1]) || !st1[1]) |
| 178 | { |
| 179 | return (st1[1] - st2[1]); |
| 180 | } |
| 181 | else |
| 182 | { |
| 183 | return (strcmp (st1 + 2, st2 + 2)); |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | void |
| 188 | sort_pst_symbols (pst) |
| 189 | struct partial_symtab *pst; |
| 190 | { |
| 191 | /* Sort the global list; don't sort the static list */ |
| 192 | |
| 193 | qsort (pst -> objfile -> global_psymbols.list + pst -> globals_offset, |
| 194 | pst -> n_global_syms, sizeof (struct partial_symbol), |
| 195 | compare_psymbols); |
| 196 | } |
| 197 | |
| 198 | /* Call sort_block_syms to sort alphabetically the symbols of one block. */ |
| 199 | |
| 200 | void |
| 201 | sort_block_syms (b) |
| 202 | register struct block *b; |
| 203 | { |
| 204 | qsort (&BLOCK_SYM (b, 0), BLOCK_NSYMS (b), |
| 205 | sizeof (struct symbol *), compare_symbols); |
| 206 | } |
| 207 | |
| 208 | /* Call sort_symtab_syms to sort alphabetically |
| 209 | the symbols of each block of one symtab. */ |
| 210 | |
| 211 | void |
| 212 | sort_symtab_syms (s) |
| 213 | register struct symtab *s; |
| 214 | { |
| 215 | register struct blockvector *bv; |
| 216 | int nbl; |
| 217 | int i; |
| 218 | register struct block *b; |
| 219 | |
| 220 | if (s == 0) |
| 221 | return; |
| 222 | bv = BLOCKVECTOR (s); |
| 223 | nbl = BLOCKVECTOR_NBLOCKS (bv); |
| 224 | for (i = 0; i < nbl; i++) |
| 225 | { |
| 226 | b = BLOCKVECTOR_BLOCK (bv, i); |
| 227 | if (BLOCK_SHOULD_SORT (b)) |
| 228 | sort_block_syms (b); |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | void |
| 233 | sort_all_symtab_syms () |
| 234 | { |
| 235 | register struct symtab *s; |
| 236 | register struct objfile *objfile; |
| 237 | |
| 238 | for (objfile = object_files; objfile != NULL; objfile = objfile -> next) |
| 239 | { |
| 240 | for (s = objfile -> symtabs; s != NULL; s = s -> next) |
| 241 | { |
| 242 | sort_symtab_syms (s); |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | /* Make a copy of the string at PTR with SIZE characters in the symbol obstack |
| 248 | (and add a null character at the end in the copy). |
| 249 | Returns the address of the copy. */ |
| 250 | |
| 251 | char * |
| 252 | obsavestring (ptr, size, obstackp) |
| 253 | char *ptr; |
| 254 | int size; |
| 255 | struct obstack *obstackp; |
| 256 | { |
| 257 | register char *p = (char *) obstack_alloc (obstackp, size + 1); |
| 258 | /* Open-coded bcopy--saves function call time. |
| 259 | These strings are usually short. */ |
| 260 | { |
| 261 | register char *p1 = ptr; |
| 262 | register char *p2 = p; |
| 263 | char *end = ptr + size; |
| 264 | while (p1 != end) |
| 265 | *p2++ = *p1++; |
| 266 | } |
| 267 | p[size] = 0; |
| 268 | return p; |
| 269 | } |
| 270 | |
| 271 | /* Concatenate strings S1, S2 and S3; return the new string. |
| 272 | Space is found in the symbol_obstack. */ |
| 273 | |
| 274 | char * |
| 275 | obconcat (obstackp, s1, s2, s3) |
| 276 | struct obstack *obstackp; |
| 277 | const char *s1, *s2, *s3; |
| 278 | { |
| 279 | register int len = strlen (s1) + strlen (s2) + strlen (s3) + 1; |
| 280 | register char *val = (char *) obstack_alloc (obstackp, len); |
| 281 | strcpy (val, s1); |
| 282 | strcat (val, s2); |
| 283 | strcat (val, s3); |
| 284 | return val; |
| 285 | } |
| 286 | |
| 287 | /* Get the symbol table that corresponds to a partial_symtab. |
| 288 | This is fast after the first time you do it. In fact, there |
| 289 | is an even faster macro PSYMTAB_TO_SYMTAB that does the fast |
| 290 | case inline. */ |
| 291 | |
| 292 | struct symtab * |
| 293 | psymtab_to_symtab (pst) |
| 294 | register struct partial_symtab *pst; |
| 295 | { |
| 296 | /* If it's been looked up before, return it. */ |
| 297 | if (pst->symtab) |
| 298 | return pst->symtab; |
| 299 | |
| 300 | /* If it has not yet been read in, read it. */ |
| 301 | if (!pst->readin) |
| 302 | { |
| 303 | (*pst->read_symtab) (pst); |
| 304 | } |
| 305 | |
| 306 | return pst->symtab; |
| 307 | } |
| 308 | |
| 309 | /* Initialize entry point information for this objfile. */ |
| 310 | |
| 311 | void |
| 312 | init_entry_point_info (objfile) |
| 313 | struct objfile *objfile; |
| 314 | { |
| 315 | /* Save startup file's range of PC addresses to help blockframe.c |
| 316 | decide where the bottom of the stack is. */ |
| 317 | |
| 318 | if (bfd_get_file_flags (objfile -> obfd) & EXEC_P) |
| 319 | { |
| 320 | /* Executable file -- record its entry point so we'll recognize |
| 321 | the startup file because it contains the entry point. */ |
| 322 | objfile -> ei.entry_point = bfd_get_start_address (objfile -> obfd); |
| 323 | } |
| 324 | else |
| 325 | { |
| 326 | /* Examination of non-executable.o files. Short-circuit this stuff. */ |
| 327 | /* ~0 will not be in any file, we hope. */ |
| 328 | objfile -> ei.entry_point = ~0; |
| 329 | /* set the startup file to be an empty range. */ |
| 330 | objfile -> ei.entry_file_lowpc = 0; |
| 331 | objfile -> ei.entry_file_highpc = 0; |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | /* Remember the lowest-addressed loadable section we've seen. |
| 336 | This function is called via bfd_map_over_sections. */ |
| 337 | |
| 338 | #if 0 /* Not used yet */ |
| 339 | static void |
| 340 | find_lowest_section (abfd, sect, obj) |
| 341 | bfd *abfd; |
| 342 | asection *sect; |
| 343 | PTR obj; |
| 344 | { |
| 345 | asection **lowest = (asection **)obj; |
| 346 | |
| 347 | if (0 == (bfd_get_section_flags (abfd, sect) & SEC_LOAD)) |
| 348 | return; |
| 349 | if (!*lowest) |
| 350 | *lowest = sect; /* First loadable section */ |
| 351 | else if (bfd_section_vma (abfd, *lowest) >= bfd_section_vma (abfd, sect)) |
| 352 | *lowest = sect; /* A lower loadable section */ |
| 353 | } |
| 354 | #endif |
| 355 | |
| 356 | /* Process a symbol file, as either the main file or as a dynamically |
| 357 | loaded file. |
| 358 | |
| 359 | NAME is the file name (which will be tilde-expanded and made |
| 360 | absolute herein) (but we don't free or modify NAME itself). |
| 361 | FROM_TTY says how verbose to be. MAINLINE specifies whether this |
| 362 | is the main symbol file, or whether it's an extra symbol file such |
| 363 | as dynamically loaded code. If !mainline, ADDR is the address |
| 364 | where the text segment was loaded. If VERBO, the caller has printed |
| 365 | a verbose message about the symbol reading (and complaints can be |
| 366 | more terse about it). */ |
| 367 | |
| 368 | void |
| 369 | syms_from_objfile (objfile, addr, mainline, verbo) |
| 370 | struct objfile *objfile; |
| 371 | CORE_ADDR addr; |
| 372 | int mainline; |
| 373 | int verbo; |
| 374 | { |
| 375 | struct section_offsets *section_offsets; |
| 376 | asection *lowest_sect; |
| 377 | |
| 378 | /* There is a distinction between having no symbol table |
| 379 | (we refuse to read the file, leaving the old set of symbols around) |
| 380 | and having no debugging symbols in your symbol table (we read |
| 381 | the file and end up with a mostly empty symbol table). |
| 382 | |
| 383 | FIXME: This strategy works correctly when the debugging symbols are |
| 384 | intermixed with "normal" symbols. However, when the debugging symbols |
| 385 | are separate, such as with ELF/DWARF, it is perfectly plausible for |
| 386 | the symbol table to be missing but still have all the DWARF info |
| 387 | intact. Thus in general it is wrong to assume that having no symbol |
| 388 | table implies no debugging information. */ |
| 389 | |
| 390 | if (!(bfd_get_file_flags (objfile -> obfd) & HAS_SYMS)) |
| 391 | return; |
| 392 | |
| 393 | init_entry_point_info (objfile); |
| 394 | find_sym_fns (objfile); |
| 395 | |
| 396 | if (mainline) |
| 397 | { |
| 398 | /* Since no error yet, throw away the old symbol table. */ |
| 399 | |
| 400 | if (symfile_objfile != NULL) |
| 401 | { |
| 402 | free_objfile (symfile_objfile); |
| 403 | symfile_objfile = NULL; |
| 404 | } |
| 405 | |
| 406 | (*objfile -> sf -> sym_new_init) (objfile); |
| 407 | } |
| 408 | |
| 409 | /* Convert addr into an offset rather than an absolute address. |
| 410 | We find the lowest address of a loaded segment in the objfile, |
| 411 | and assume that <addr> is where that got loaded. Due to historical |
| 412 | precedent, we warn if that doesn't happen to be the ".text" |
| 413 | segment. */ |
| 414 | |
| 415 | if (mainline) |
| 416 | { |
| 417 | addr = 0; /* No offset from objfile addresses. */ |
| 418 | } |
| 419 | else |
| 420 | { |
| 421 | lowest_sect = bfd_get_section_by_name (objfile->obfd, ".text"); |
| 422 | #if 0 |
| 423 | lowest_sect = 0; |
| 424 | bfd_map_over_sections (objfile->obfd, find_lowest_section, |
| 425 | (PTR) &lowest_sect); |
| 426 | #endif |
| 427 | |
| 428 | if (lowest_sect == 0) |
| 429 | warning ("no loadable sections found in added symbol-file %s", |
| 430 | objfile->name); |
| 431 | else if (0 == bfd_get_section_name (objfile->obfd, lowest_sect) |
| 432 | || 0 != strcmp(".text", |
| 433 | bfd_get_section_name (objfile->obfd, lowest_sect))) |
| 434 | warning ("Lowest section in %s is %s at 0x%x", |
| 435 | objfile->name, |
| 436 | bfd_section_name (objfile->obfd, lowest_sect), |
| 437 | bfd_section_vma (objfile->obfd, lowest_sect)); |
| 438 | |
| 439 | if (lowest_sect) |
| 440 | addr -= bfd_section_vma (objfile->obfd, lowest_sect); |
| 441 | } |
| 442 | |
| 443 | /* Initialize symbol reading routines for this objfile, allow complaints to |
| 444 | appear for this new file, and record how verbose to be, then do the |
| 445 | initial symbol reading for this file. */ |
| 446 | |
| 447 | (*objfile -> sf -> sym_init) (objfile); |
| 448 | clear_complaints (1, verbo); |
| 449 | section_offsets = (*objfile -> sf -> sym_offsets) (objfile, addr); |
| 450 | (*objfile -> sf -> sym_read) (objfile, section_offsets, mainline); |
| 451 | |
| 452 | /* Don't allow char * to have a typename (else would get caddr_t.) */ |
| 453 | /* Ditto void *. FIXME should do this for all the builtin types. */ |
| 454 | |
| 455 | TYPE_NAME (lookup_pointer_type (builtin_type_char)) = 0; |
| 456 | TYPE_NAME (lookup_pointer_type (builtin_type_void)) = 0; |
| 457 | |
| 458 | /* Mark the objfile has having had initial symbol read attempted. Note |
| 459 | that this does not mean we found any symbols... */ |
| 460 | |
| 461 | objfile -> flags |= OBJF_SYMS; |
| 462 | } |
| 463 | |
| 464 | /* Perform required actions immediately after either reading in the initial |
| 465 | symbols for a new objfile, or mapping in the symbols from a reusable |
| 466 | objfile. */ |
| 467 | |
| 468 | void |
| 469 | new_symfile_objfile (objfile, mainline, verbo) |
| 470 | struct objfile *objfile; |
| 471 | int mainline; |
| 472 | int verbo; |
| 473 | { |
| 474 | if (mainline) |
| 475 | { |
| 476 | /* OK, make it the "real" symbol file. */ |
| 477 | symfile_objfile = objfile; |
| 478 | } |
| 479 | |
| 480 | /* If we have wiped out any old symbol tables, clean up. */ |
| 481 | clear_symtab_users_once (); |
| 482 | |
| 483 | /* We're done reading the symbol file; finish off complaints. */ |
| 484 | clear_complaints (0, verbo); |
| 485 | |
| 486 | /* Fixup all the breakpoints that may have been redefined by this |
| 487 | symbol file. */ |
| 488 | |
| 489 | breakpoint_re_set (); |
| 490 | } |
| 491 | |
| 492 | /* Process a symbol file, as either the main file or as a dynamically |
| 493 | loaded file. |
| 494 | |
| 495 | NAME is the file name (which will be tilde-expanded and made |
| 496 | absolute herein) (but we don't free or modify NAME itself). |
| 497 | FROM_TTY says how verbose to be. MAINLINE specifies whether this |
| 498 | is the main symbol file, or whether it's an extra symbol file such |
| 499 | as dynamically loaded code. If !mainline, ADDR is the address |
| 500 | where the text segment was loaded. |
| 501 | |
| 502 | Upon success, returns a pointer to the objfile that was added. |
| 503 | Upon failure, jumps back to command level (never returns). */ |
| 504 | |
| 505 | struct objfile * |
| 506 | symbol_file_add (name, from_tty, addr, mainline, mapped, readnow) |
| 507 | char *name; |
| 508 | int from_tty; |
| 509 | CORE_ADDR addr; |
| 510 | int mainline; |
| 511 | int mapped; |
| 512 | int readnow; |
| 513 | { |
| 514 | struct objfile *objfile; |
| 515 | struct partial_symtab *psymtab; |
| 516 | bfd *abfd; |
| 517 | |
| 518 | /* Open a bfd for the file and then check to see if the file has a |
| 519 | symbol table. There is a distinction between having no symbol table |
| 520 | (we refuse to read the file, leaving the old set of symbols around) |
| 521 | and having no debugging symbols in the symbol table (we read the file |
| 522 | and end up with a mostly empty symbol table, but with lots of stuff in |
| 523 | the minimal symbol table). We need to make the decision about whether |
| 524 | to continue with the file before allocating and building a objfile. |
| 525 | |
| 526 | FIXME: This strategy works correctly when the debugging symbols are |
| 527 | intermixed with "normal" symbols. However, when the debugging symbols |
| 528 | are separate, such as with ELF/DWARF, it is perfectly plausible for |
| 529 | the symbol table to be missing but still have all the DWARF info |
| 530 | intact. Thus in general it is wrong to assume that having no symbol |
| 531 | table implies no debugging information. */ |
| 532 | |
| 533 | abfd = symfile_bfd_open (name); |
| 534 | if (!(bfd_get_file_flags (abfd) & HAS_SYMS)) |
| 535 | { |
| 536 | error ("%s has no symbol-table", name); |
| 537 | } |
| 538 | |
| 539 | if ((have_full_symbols () || have_partial_symbols ()) |
| 540 | && mainline |
| 541 | && from_tty |
| 542 | && !query ("Load new symbol table from \"%s\"? ", name)) |
| 543 | error ("Not confirmed."); |
| 544 | |
| 545 | /* Getting new symbols may change our opinion about what is |
| 546 | frameless. */ |
| 547 | |
| 548 | reinit_frame_cache (); |
| 549 | |
| 550 | objfile = allocate_objfile (abfd, mapped); |
| 551 | |
| 552 | /* If the objfile uses a mapped symbol file, and we have a psymtab for |
| 553 | it, then skip reading any symbols at this time. */ |
| 554 | |
| 555 | if ((objfile -> flags & OBJF_MAPPED) && (objfile -> flags & OBJF_SYMS)) |
| 556 | { |
| 557 | /* We mapped in an existing symbol table file that already has had |
| 558 | initial symbol reading performed, so we can skip that part. Notify |
| 559 | the user that instead of reading the symbols, they have been mapped. |
| 560 | */ |
| 561 | if (from_tty || info_verbose) |
| 562 | { |
| 563 | printf_filtered ("Mapped symbols for %s...", name); |
| 564 | wrap_here (""); |
| 565 | fflush (stdout); |
| 566 | } |
| 567 | init_entry_point_info (objfile); |
| 568 | find_sym_fns (objfile); |
| 569 | } |
| 570 | else |
| 571 | { |
| 572 | /* We either created a new mapped symbol table, mapped an existing |
| 573 | symbol table file which has not had initial symbol reading |
| 574 | performed, or need to read an unmapped symbol table. */ |
| 575 | if (from_tty || info_verbose) |
| 576 | { |
| 577 | printf_filtered ("Reading symbols from %s...", name); |
| 578 | wrap_here (""); |
| 579 | fflush (stdout); |
| 580 | } |
| 581 | syms_from_objfile (objfile, addr, mainline, from_tty); |
| 582 | } |
| 583 | |
| 584 | new_symfile_objfile (objfile, mainline, from_tty); |
| 585 | |
| 586 | /* We now have at least a partial symbol table. Check to see if the |
| 587 | user requested that all symbols be read on initial access via either |
| 588 | the gdb startup command line or on a per symbol file basis. Expand |
| 589 | all partial symbol tables for this objfile if so. */ |
| 590 | |
| 591 | if (readnow || readnow_symbol_files) |
| 592 | { |
| 593 | if (from_tty || info_verbose) |
| 594 | { |
| 595 | printf_filtered ("expanding to full symbols..."); |
| 596 | wrap_here (""); |
| 597 | fflush (stdout); |
| 598 | } |
| 599 | |
| 600 | for (psymtab = objfile -> psymtabs; |
| 601 | psymtab != NULL; |
| 602 | psymtab = psymtab -> next) |
| 603 | { |
| 604 | psymtab_to_symtab (psymtab); |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | if (from_tty || info_verbose) |
| 609 | { |
| 610 | printf_filtered ("done.\n"); |
| 611 | fflush (stdout); |
| 612 | } |
| 613 | |
| 614 | return (objfile); |
| 615 | } |
| 616 | |
| 617 | /* This is the symbol-file command. Read the file, analyze its symbols, |
| 618 | and add a struct symtab to a symtab list. */ |
| 619 | |
| 620 | void |
| 621 | symbol_file_command (args, from_tty) |
| 622 | char *args; |
| 623 | int from_tty; |
| 624 | { |
| 625 | char **argv; |
| 626 | char *name = NULL; |
| 627 | struct cleanup *cleanups; |
| 628 | int mapped = 0; |
| 629 | int readnow = 0; |
| 630 | |
| 631 | dont_repeat (); |
| 632 | |
| 633 | if (args == NULL) |
| 634 | { |
| 635 | if ((have_full_symbols () || have_partial_symbols ()) |
| 636 | && from_tty |
| 637 | && !query ("Discard symbol table from `%s'? ", |
| 638 | symfile_objfile -> name)) |
| 639 | error ("Not confirmed."); |
| 640 | free_all_objfiles (); |
| 641 | symfile_objfile = NULL; |
| 642 | current_source_symtab = NULL; |
| 643 | current_source_line = 0; |
| 644 | if (from_tty) |
| 645 | { |
| 646 | printf_filtered ("No symbol file now.\n"); |
| 647 | } |
| 648 | } |
| 649 | else |
| 650 | { |
| 651 | if ((argv = buildargv (args)) == NULL) |
| 652 | { |
| 653 | nomem (0); |
| 654 | } |
| 655 | cleanups = make_cleanup (freeargv, (char *) argv); |
| 656 | while (*argv != NULL) |
| 657 | { |
| 658 | if (strcmp (*argv, "-mapped") == 0) |
| 659 | { |
| 660 | mapped = 1; |
| 661 | } |
| 662 | else if (strcmp (*argv, "-readnow") == 0) |
| 663 | { |
| 664 | readnow = 1; |
| 665 | } |
| 666 | else if (**argv == '-') |
| 667 | { |
| 668 | error ("unknown option `%s'", *argv); |
| 669 | } |
| 670 | else |
| 671 | { |
| 672 | name = *argv; |
| 673 | } |
| 674 | argv++; |
| 675 | } |
| 676 | |
| 677 | if (name == NULL) |
| 678 | { |
| 679 | error ("no symbol file name was specified"); |
| 680 | } |
| 681 | else |
| 682 | { |
| 683 | symbol_file_add (name, from_tty, (CORE_ADDR)0, 1, mapped, readnow); |
| 684 | } |
| 685 | do_cleanups (cleanups); |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | /* Open file specified by NAME and hand it off to BFD for preliminary |
| 690 | analysis. Result is a newly initialized bfd *, which includes a newly |
| 691 | malloc'd` copy of NAME (tilde-expanded and made absolute). |
| 692 | In case of trouble, error() is called. */ |
| 693 | |
| 694 | static bfd * |
| 695 | symfile_bfd_open (name) |
| 696 | char *name; |
| 697 | { |
| 698 | bfd *sym_bfd; |
| 699 | int desc; |
| 700 | char *absolute_name; |
| 701 | |
| 702 | name = tilde_expand (name); /* Returns 1st new malloc'd copy */ |
| 703 | |
| 704 | /* Look down path for it, allocate 2nd new malloc'd copy. */ |
| 705 | desc = openp (getenv ("PATH"), 1, name, O_RDONLY, 0, &absolute_name); |
| 706 | if (desc < 0) |
| 707 | { |
| 708 | make_cleanup (free, name); |
| 709 | perror_with_name (name); |
| 710 | } |
| 711 | free (name); /* Free 1st new malloc'd copy */ |
| 712 | name = absolute_name; /* Keep 2nd malloc'd copy in bfd */ |
| 713 | /* It'll be freed in free_objfile(). */ |
| 714 | |
| 715 | sym_bfd = bfd_fdopenr (name, NULL, desc); |
| 716 | if (!sym_bfd) |
| 717 | { |
| 718 | close (desc); |
| 719 | make_cleanup (free, name); |
| 720 | error ("\"%s\": can't open to read symbols: %s.", name, |
| 721 | bfd_errmsg (bfd_error)); |
| 722 | } |
| 723 | |
| 724 | if (!bfd_check_format (sym_bfd, bfd_object)) |
| 725 | { |
| 726 | bfd_close (sym_bfd); /* This also closes desc */ |
| 727 | make_cleanup (free, name); |
| 728 | error ("\"%s\": can't read symbols: %s.", name, |
| 729 | bfd_errmsg (bfd_error)); |
| 730 | } |
| 731 | |
| 732 | return (sym_bfd); |
| 733 | } |
| 734 | |
| 735 | /* Link a new symtab_fns into the global symtab_fns list. Called on gdb |
| 736 | startup by the _initialize routine in each object file format reader, |
| 737 | to register information about each format the the reader is prepared |
| 738 | to handle. */ |
| 739 | |
| 740 | void |
| 741 | add_symtab_fns (sf) |
| 742 | struct sym_fns *sf; |
| 743 | { |
| 744 | sf->next = symtab_fns; |
| 745 | symtab_fns = sf; |
| 746 | } |
| 747 | |
| 748 | |
| 749 | /* Initialize to read symbols from the symbol file sym_bfd. It either |
| 750 | returns or calls error(). The result is an initialized struct sym_fns |
| 751 | in the objfile structure, that contains cached information about the |
| 752 | symbol file. */ |
| 753 | |
| 754 | static void |
| 755 | find_sym_fns (objfile) |
| 756 | struct objfile *objfile; |
| 757 | { |
| 758 | struct sym_fns *sf; |
| 759 | |
| 760 | for (sf = symtab_fns; sf != NULL; sf = sf -> next) |
| 761 | { |
| 762 | if (strncmp (bfd_get_target (objfile -> obfd), |
| 763 | sf -> sym_name, sf -> sym_namelen) == 0) |
| 764 | { |
| 765 | objfile -> sf = sf; |
| 766 | return; |
| 767 | } |
| 768 | } |
| 769 | error ("I'm sorry, Dave, I can't do that. Symbol format `%s' unknown.", |
| 770 | bfd_get_target (objfile -> obfd)); |
| 771 | } |
| 772 | \f |
| 773 | /* This function runs the load command of our current target. */ |
| 774 | |
| 775 | static void |
| 776 | load_command (arg, from_tty) |
| 777 | char *arg; |
| 778 | int from_tty; |
| 779 | { |
| 780 | target_load (arg, from_tty); |
| 781 | } |
| 782 | |
| 783 | /* This function allows the addition of incrementally linked object files. |
| 784 | It does not modify any state in the target, only in the debugger. */ |
| 785 | |
| 786 | /* ARGSUSED */ |
| 787 | static void |
| 788 | add_symbol_file_command (args, from_tty) |
| 789 | char *args; |
| 790 | int from_tty; |
| 791 | { |
| 792 | char *name = NULL; |
| 793 | CORE_ADDR text_addr; |
| 794 | char *arg; |
| 795 | int readnow = 0; |
| 796 | int mapped = 0; |
| 797 | |
| 798 | dont_repeat (); |
| 799 | |
| 800 | if (args == NULL) |
| 801 | { |
| 802 | error ("add-symbol-file takes a file name and an address"); |
| 803 | } |
| 804 | |
| 805 | /* Make a copy of the string that we can safely write into. */ |
| 806 | |
| 807 | args = strdup (args); |
| 808 | make_cleanup (free, args); |
| 809 | |
| 810 | /* Pick off any -option args and the file name. */ |
| 811 | |
| 812 | while ((*args != '\000') && (name == NULL)) |
| 813 | { |
| 814 | while (isspace (*args)) {args++;} |
| 815 | arg = args; |
| 816 | while ((*args != '\000') && !isspace (*args)) {args++;} |
| 817 | if (*args != '\000') |
| 818 | { |
| 819 | *args++ = '\000'; |
| 820 | } |
| 821 | if (*arg != '-') |
| 822 | { |
| 823 | name = arg; |
| 824 | } |
| 825 | else if (strcmp (arg, "-mapped") == 0) |
| 826 | { |
| 827 | mapped = 1; |
| 828 | } |
| 829 | else if (strcmp (arg, "-readnow") == 0) |
| 830 | { |
| 831 | readnow = 1; |
| 832 | } |
| 833 | else |
| 834 | { |
| 835 | error ("unknown option `%s'", arg); |
| 836 | } |
| 837 | } |
| 838 | |
| 839 | /* After picking off any options and the file name, args should be |
| 840 | left pointing at the remainder of the command line, which should |
| 841 | be the address expression to evaluate. */ |
| 842 | |
| 843 | if ((name == NULL) || (*args == '\000') ) |
| 844 | { |
| 845 | error ("add-symbol-file takes a file name and an address"); |
| 846 | } |
| 847 | name = tilde_expand (name); |
| 848 | make_cleanup (free, name); |
| 849 | |
| 850 | text_addr = parse_and_eval_address (args); |
| 851 | |
| 852 | if (!query ("add symbol table from file \"%s\" at text_addr = %s?\n", |
| 853 | name, local_hex_string (text_addr))) |
| 854 | error ("Not confirmed."); |
| 855 | |
| 856 | symbol_file_add (name, 0, text_addr, 0, mapped, readnow); |
| 857 | } |
| 858 | \f |
| 859 | /* Re-read symbols if a symbol-file has changed. */ |
| 860 | void |
| 861 | reread_symbols () |
| 862 | { |
| 863 | struct objfile *objfile; |
| 864 | long new_modtime; |
| 865 | int reread_one = 0; |
| 866 | struct stat new_statbuf; |
| 867 | int res; |
| 868 | |
| 869 | /* With the addition of shared libraries, this should be modified, |
| 870 | the load time should be saved in the partial symbol tables, since |
| 871 | different tables may come from different source files. FIXME. |
| 872 | This routine should then walk down each partial symbol table |
| 873 | and see if the symbol table that it originates from has been changed */ |
| 874 | |
| 875 | the_big_top: |
| 876 | for (objfile = object_files; objfile; objfile = objfile->next) { |
| 877 | if (objfile->obfd) { |
| 878 | #ifdef IBM6000_TARGET |
| 879 | /* If this object is from a shared library, then you should |
| 880 | stat on the library name, not member name. */ |
| 881 | |
| 882 | if (objfile->obfd->my_archive) |
| 883 | res = stat (objfile->obfd->my_archive->filename, &new_statbuf); |
| 884 | else |
| 885 | #endif |
| 886 | res = stat (objfile->name, &new_statbuf); |
| 887 | if (res != 0) { |
| 888 | /* FIXME, should use print_sys_errmsg but it's not filtered. */ |
| 889 | printf_filtered ("`%s' has disappeared; keeping its symbols.\n", |
| 890 | objfile->name); |
| 891 | continue; |
| 892 | } |
| 893 | new_modtime = new_statbuf.st_mtime; |
| 894 | if (new_modtime != objfile->mtime) { |
| 895 | printf_filtered ("`%s' has changed; re-reading symbols.\n", |
| 896 | objfile->name); |
| 897 | /* FIXME, this should use a different command...that would only |
| 898 | affect this objfile's symbols, and would reset objfile->mtime. |
| 899 | (objfile->mtime = new_modtime;) |
| 900 | HOWEVER, that command isn't written yet -- so call symbol_file_ |
| 901 | command, and restart the scan from the top, because it munges |
| 902 | the object_files list. */ |
| 903 | symbol_file_command (objfile->name, 0); |
| 904 | reread_one = 1; |
| 905 | goto the_big_top; /* Start over. */ |
| 906 | } |
| 907 | } |
| 908 | } |
| 909 | |
| 910 | if (reread_one) |
| 911 | breakpoint_re_set (); |
| 912 | } |
| 913 | \f |
| 914 | /* Functions to handle complaints during symbol reading. */ |
| 915 | |
| 916 | /* How many complaints about a particular thing should be printed before |
| 917 | we stop whining about it? Default is no whining at all, since so many |
| 918 | systems have ill-constructed symbol files. */ |
| 919 | |
| 920 | static unsigned stop_whining = 0; |
| 921 | |
| 922 | /* Should each complaint be self explanatory, or should we assume that |
| 923 | a series of complaints is being produced? |
| 924 | case 0: self explanatory message. |
| 925 | case 1: First message of a series that must start off with explanation. |
| 926 | case 2: Subsequent message, when user already knows we are reading |
| 927 | symbols and we can just state our piece. */ |
| 928 | |
| 929 | static int complaint_series = 0; |
| 930 | |
| 931 | /* Print a complaint about the input symbols, and link the complaint block |
| 932 | into a chain for later handling. */ |
| 933 | |
| 934 | void |
| 935 | complain (complaint, val) |
| 936 | struct complaint *complaint; |
| 937 | char *val; |
| 938 | { |
| 939 | complaint->counter++; |
| 940 | if (complaint->next == 0) { |
| 941 | complaint->next = complaint_root->next; |
| 942 | complaint_root->next = complaint; |
| 943 | } |
| 944 | if (complaint->counter > stop_whining) |
| 945 | return; |
| 946 | wrap_here (""); |
| 947 | |
| 948 | switch (complaint_series + (info_verbose << 1)) { |
| 949 | |
| 950 | /* Isolated messages, must be self-explanatory. */ |
| 951 | case 0: |
| 952 | puts_filtered ("During symbol reading, "); |
| 953 | wrap_here(""); |
| 954 | printf_filtered (complaint->message, val); |
| 955 | puts_filtered (".\n"); |
| 956 | break; |
| 957 | |
| 958 | /* First of a series, without `set verbose'. */ |
| 959 | case 1: |
| 960 | puts_filtered ("During symbol reading..."); |
| 961 | printf_filtered (complaint->message, val); |
| 962 | puts_filtered ("..."); |
| 963 | wrap_here(""); |
| 964 | complaint_series++; |
| 965 | break; |
| 966 | |
| 967 | /* Subsequent messages of a series, or messages under `set verbose'. |
| 968 | (We'll already have produced a "Reading in symbols for XXX..." message |
| 969 | and will clean up at the end with a newline.) */ |
| 970 | default: |
| 971 | printf_filtered (complaint->message, val); |
| 972 | puts_filtered ("..."); |
| 973 | wrap_here(""); |
| 974 | } |
| 975 | } |
| 976 | |
| 977 | /* Clear out all complaint counters that have ever been incremented. |
| 978 | If sym_reading is 1, be less verbose about successive complaints, |
| 979 | since the messages are appearing all together during a command that |
| 980 | reads symbols (rather than scattered around as psymtabs get fleshed |
| 981 | out into symtabs at random times). If noisy is 1, we are in a |
| 982 | noisy symbol reading command, and our caller will print enough |
| 983 | context for the user to figure it out. */ |
| 984 | |
| 985 | void |
| 986 | clear_complaints (sym_reading, noisy) |
| 987 | int sym_reading; |
| 988 | int noisy; |
| 989 | { |
| 990 | struct complaint *p; |
| 991 | |
| 992 | for (p = complaint_root->next; p != complaint_root; p = p->next) |
| 993 | p->counter = 0; |
| 994 | |
| 995 | if (!sym_reading && !noisy && complaint_series > 1) { |
| 996 | /* Terminate previous series, since caller won't. */ |
| 997 | puts_filtered ("\n"); |
| 998 | } |
| 999 | |
| 1000 | complaint_series = sym_reading? 1 + noisy: 0; |
| 1001 | } |
| 1002 | \f |
| 1003 | enum language |
| 1004 | deduce_language_from_filename (filename) |
| 1005 | char *filename; |
| 1006 | { |
| 1007 | char *c = strrchr (filename, '.'); |
| 1008 | |
| 1009 | if (!c) ; /* Get default. */ |
| 1010 | else if(!strcmp(c,".mod")) |
| 1011 | return language_m2; |
| 1012 | else if(!strcmp(c,".c")) |
| 1013 | return language_c; |
| 1014 | else if(!strcmp(c,".cc") || !strcmp(c,".C")) |
| 1015 | return language_cplus; |
| 1016 | |
| 1017 | return language_unknown; /* default */ |
| 1018 | } |
| 1019 | \f |
| 1020 | /* allocate_symtab: |
| 1021 | |
| 1022 | Allocate and partly initialize a new symbol table. Return a pointer |
| 1023 | to it. error() if no space. |
| 1024 | |
| 1025 | Caller must set these fields: |
| 1026 | LINETABLE(symtab) |
| 1027 | symtab->blockvector |
| 1028 | symtab->dirname |
| 1029 | symtab->free_code |
| 1030 | symtab->free_ptr |
| 1031 | initialize any EXTRA_SYMTAB_INFO |
| 1032 | possibly free_named_symtabs (symtab->filename); |
| 1033 | */ |
| 1034 | |
| 1035 | struct symtab * |
| 1036 | allocate_symtab (filename, objfile) |
| 1037 | char *filename; |
| 1038 | struct objfile *objfile; |
| 1039 | { |
| 1040 | register struct symtab *symtab; |
| 1041 | |
| 1042 | symtab = (struct symtab *) |
| 1043 | obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symtab)); |
| 1044 | memset (symtab, 0, sizeof (*symtab)); |
| 1045 | symtab -> filename = obsavestring (filename, strlen (filename), |
| 1046 | &objfile -> symbol_obstack); |
| 1047 | symtab -> fullname = NULL; |
| 1048 | symtab -> language = deduce_language_from_filename (filename); |
| 1049 | |
| 1050 | /* Hook it to the objfile it comes from */ |
| 1051 | |
| 1052 | symtab -> objfile = objfile; |
| 1053 | symtab -> next = objfile -> symtabs; |
| 1054 | objfile -> symtabs = symtab; |
| 1055 | |
| 1056 | #ifdef INIT_EXTRA_SYMTAB_INFO |
| 1057 | INIT_EXTRA_SYMTAB_INFO (symtab); |
| 1058 | #endif |
| 1059 | |
| 1060 | return (symtab); |
| 1061 | } |
| 1062 | |
| 1063 | struct partial_symtab * |
| 1064 | allocate_psymtab (filename, objfile) |
| 1065 | char *filename; |
| 1066 | struct objfile *objfile; |
| 1067 | { |
| 1068 | struct partial_symtab *psymtab; |
| 1069 | |
| 1070 | if (objfile -> free_psymtabs) |
| 1071 | { |
| 1072 | psymtab = objfile -> free_psymtabs; |
| 1073 | objfile -> free_psymtabs = psymtab -> next; |
| 1074 | } |
| 1075 | else |
| 1076 | psymtab = (struct partial_symtab *) |
| 1077 | obstack_alloc (&objfile -> psymbol_obstack, |
| 1078 | sizeof (struct partial_symtab)); |
| 1079 | |
| 1080 | memset (psymtab, 0, sizeof (struct partial_symtab)); |
| 1081 | psymtab -> filename = obsavestring (filename, strlen (filename), |
| 1082 | &objfile -> psymbol_obstack); |
| 1083 | psymtab -> symtab = NULL; |
| 1084 | |
| 1085 | /* Hook it to the objfile it comes from */ |
| 1086 | |
| 1087 | psymtab -> objfile = objfile; |
| 1088 | psymtab -> next = objfile -> psymtabs; |
| 1089 | objfile -> psymtabs = psymtab; |
| 1090 | |
| 1091 | return (psymtab); |
| 1092 | } |
| 1093 | |
| 1094 | \f |
| 1095 | /* clear_symtab_users_once: |
| 1096 | |
| 1097 | This function is run after symbol reading, or from a cleanup. |
| 1098 | If an old symbol table was obsoleted, the old symbol table |
| 1099 | has been blown away, but the other GDB data structures that may |
| 1100 | reference it have not yet been cleared or re-directed. (The old |
| 1101 | symtab was zapped, and the cleanup queued, in free_named_symtab() |
| 1102 | below.) |
| 1103 | |
| 1104 | This function can be queued N times as a cleanup, or called |
| 1105 | directly; it will do all the work the first time, and then will be a |
| 1106 | no-op until the next time it is queued. This works by bumping a |
| 1107 | counter at queueing time. Much later when the cleanup is run, or at |
| 1108 | the end of symbol processing (in case the cleanup is discarded), if |
| 1109 | the queued count is greater than the "done-count", we do the work |
| 1110 | and set the done-count to the queued count. If the queued count is |
| 1111 | less than or equal to the done-count, we just ignore the call. This |
| 1112 | is needed because reading a single .o file will often replace many |
| 1113 | symtabs (one per .h file, for example), and we don't want to reset |
| 1114 | the breakpoints N times in the user's face. |
| 1115 | |
| 1116 | The reason we both queue a cleanup, and call it directly after symbol |
| 1117 | reading, is because the cleanup protects us in case of errors, but is |
| 1118 | discarded if symbol reading is successful. */ |
| 1119 | |
| 1120 | static int clear_symtab_users_queued; |
| 1121 | static int clear_symtab_users_done; |
| 1122 | |
| 1123 | void |
| 1124 | clear_symtab_users_once () |
| 1125 | { |
| 1126 | /* Enforce once-per-`do_cleanups'-semantics */ |
| 1127 | if (clear_symtab_users_queued <= clear_symtab_users_done) |
| 1128 | return; |
| 1129 | clear_symtab_users_done = clear_symtab_users_queued; |
| 1130 | |
| 1131 | printf_filtered ("Resetting debugger state after updating old symbol tables\n"); |
| 1132 | |
| 1133 | /* Someday, we should do better than this, by only blowing away |
| 1134 | the things that really need to be blown. */ |
| 1135 | clear_value_history (); |
| 1136 | clear_displays (); |
| 1137 | clear_internalvars (); |
| 1138 | breakpoint_re_set (); |
| 1139 | set_default_breakpoint (0, 0, 0, 0); |
| 1140 | current_source_symtab = 0; |
| 1141 | } |
| 1142 | |
| 1143 | /* Delete the specified psymtab, and any others that reference it. */ |
| 1144 | |
| 1145 | static void |
| 1146 | cashier_psymtab (pst) |
| 1147 | struct partial_symtab *pst; |
| 1148 | { |
| 1149 | struct partial_symtab *ps, *pprev; |
| 1150 | int i; |
| 1151 | |
| 1152 | /* Find its previous psymtab in the chain */ |
| 1153 | for (ps = pst->objfile->psymtabs; ps; ps = ps->next) { |
| 1154 | if (ps == pst) |
| 1155 | break; |
| 1156 | pprev = ps; |
| 1157 | } |
| 1158 | |
| 1159 | if (ps) { |
| 1160 | /* Unhook it from the chain. */ |
| 1161 | if (ps == pst->objfile->psymtabs) |
| 1162 | pst->objfile->psymtabs = ps->next; |
| 1163 | else |
| 1164 | pprev->next = ps->next; |
| 1165 | |
| 1166 | /* FIXME, we can't conveniently deallocate the entries in the |
| 1167 | partial_symbol lists (global_psymbols/static_psymbols) that |
| 1168 | this psymtab points to. These just take up space until all |
| 1169 | the psymtabs are reclaimed. Ditto the dependencies list and |
| 1170 | filename, which are all in the psymbol_obstack. */ |
| 1171 | |
| 1172 | /* We need to cashier any psymtab that has this one as a dependency... */ |
| 1173 | again: |
| 1174 | for (ps = pst->objfile->psymtabs; ps; ps = ps->next) { |
| 1175 | for (i = 0; i < ps->number_of_dependencies; i++) { |
| 1176 | if (ps->dependencies[i] == pst) { |
| 1177 | cashier_psymtab (ps); |
| 1178 | goto again; /* Must restart, chain has been munged. */ |
| 1179 | } |
| 1180 | } |
| 1181 | } |
| 1182 | } |
| 1183 | } |
| 1184 | |
| 1185 | /* If a symtab or psymtab for filename NAME is found, free it along |
| 1186 | with any dependent breakpoints, displays, etc. |
| 1187 | Used when loading new versions of object modules with the "add-file" |
| 1188 | command. This is only called on the top-level symtab or psymtab's name; |
| 1189 | it is not called for subsidiary files such as .h files. |
| 1190 | |
| 1191 | Return value is 1 if we blew away the environment, 0 if not. |
| 1192 | FIXME. The return valu appears to never be used. |
| 1193 | |
| 1194 | FIXME. I think this is not the best way to do this. We should |
| 1195 | work on being gentler to the environment while still cleaning up |
| 1196 | all stray pointers into the freed symtab. */ |
| 1197 | |
| 1198 | int |
| 1199 | free_named_symtabs (name) |
| 1200 | char *name; |
| 1201 | { |
| 1202 | #if 0 |
| 1203 | /* FIXME: With the new method of each objfile having it's own |
| 1204 | psymtab list, this function needs serious rethinking. In particular, |
| 1205 | why was it ever necessary to toss psymtabs with specific compilation |
| 1206 | unit filenames, as opposed to all psymtabs from a particular symbol |
| 1207 | file? -- fnf |
| 1208 | Well, the answer is that some systems permit reloading of particular |
| 1209 | compilation units. We want to blow away any old info about these |
| 1210 | compilation units, regardless of which objfiles they arrived in. --gnu. */ |
| 1211 | |
| 1212 | register struct symtab *s; |
| 1213 | register struct symtab *prev; |
| 1214 | register struct partial_symtab *ps; |
| 1215 | struct blockvector *bv; |
| 1216 | int blewit = 0; |
| 1217 | |
| 1218 | /* We only wack things if the symbol-reload switch is set. */ |
| 1219 | if (!symbol_reloading) |
| 1220 | return 0; |
| 1221 | |
| 1222 | /* Some symbol formats have trouble providing file names... */ |
| 1223 | if (name == 0 || *name == '\0') |
| 1224 | return 0; |
| 1225 | |
| 1226 | /* Look for a psymtab with the specified name. */ |
| 1227 | |
| 1228 | again2: |
| 1229 | for (ps = partial_symtab_list; ps; ps = ps->next) { |
| 1230 | if (!strcmp (name, ps->filename)) { |
| 1231 | cashier_psymtab (ps); /* Blow it away...and its little dog, too. */ |
| 1232 | goto again2; /* Must restart, chain has been munged */ |
| 1233 | } |
| 1234 | } |
| 1235 | |
| 1236 | /* Look for a symtab with the specified name. */ |
| 1237 | |
| 1238 | for (s = symtab_list; s; s = s->next) |
| 1239 | { |
| 1240 | if (!strcmp (name, s->filename)) |
| 1241 | break; |
| 1242 | prev = s; |
| 1243 | } |
| 1244 | |
| 1245 | if (s) |
| 1246 | { |
| 1247 | if (s == symtab_list) |
| 1248 | symtab_list = s->next; |
| 1249 | else |
| 1250 | prev->next = s->next; |
| 1251 | |
| 1252 | /* For now, queue a delete for all breakpoints, displays, etc., whether |
| 1253 | or not they depend on the symtab being freed. This should be |
| 1254 | changed so that only those data structures affected are deleted. */ |
| 1255 | |
| 1256 | /* But don't delete anything if the symtab is empty. |
| 1257 | This test is necessary due to a bug in "dbxread.c" that |
| 1258 | causes empty symtabs to be created for N_SO symbols that |
| 1259 | contain the pathname of the object file. (This problem |
| 1260 | has been fixed in GDB 3.9x). */ |
| 1261 | |
| 1262 | bv = BLOCKVECTOR (s); |
| 1263 | if (BLOCKVECTOR_NBLOCKS (bv) > 2 |
| 1264 | || BLOCK_NSYMS (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) |
| 1265 | || BLOCK_NSYMS (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK))) |
| 1266 | { |
| 1267 | complain (&oldsyms_complaint, name); |
| 1268 | |
| 1269 | clear_symtab_users_queued++; |
| 1270 | make_cleanup (clear_symtab_users_once, 0); |
| 1271 | blewit = 1; |
| 1272 | } else { |
| 1273 | complain (&empty_symtab_complaint, name); |
| 1274 | } |
| 1275 | |
| 1276 | free_symtab (s); |
| 1277 | } |
| 1278 | else |
| 1279 | { |
| 1280 | /* It is still possible that some breakpoints will be affected |
| 1281 | even though no symtab was found, since the file might have |
| 1282 | been compiled without debugging, and hence not be associated |
| 1283 | with a symtab. In order to handle this correctly, we would need |
| 1284 | to keep a list of text address ranges for undebuggable files. |
| 1285 | For now, we do nothing, since this is a fairly obscure case. */ |
| 1286 | ; |
| 1287 | } |
| 1288 | |
| 1289 | /* FIXME, what about the minimal symbol table? */ |
| 1290 | return blewit; |
| 1291 | #else |
| 1292 | return (0); |
| 1293 | #endif |
| 1294 | } |
| 1295 | \f |
| 1296 | /* Allocate and partially fill a partial symtab. It will be |
| 1297 | completely filled at the end of the symbol list. |
| 1298 | |
| 1299 | SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR |
| 1300 | is the address relative to which its symbols are (incremental) or 0 |
| 1301 | (normal). */ |
| 1302 | |
| 1303 | |
| 1304 | struct partial_symtab * |
| 1305 | start_psymtab_common (objfile, section_offsets, |
| 1306 | filename, textlow, global_syms, static_syms) |
| 1307 | struct objfile *objfile; |
| 1308 | struct section_offsets *section_offsets; |
| 1309 | char *filename; |
| 1310 | CORE_ADDR textlow; |
| 1311 | struct partial_symbol *global_syms; |
| 1312 | struct partial_symbol *static_syms; |
| 1313 | { |
| 1314 | struct partial_symtab *psymtab; |
| 1315 | |
| 1316 | psymtab = allocate_psymtab (filename, objfile); |
| 1317 | psymtab -> section_offsets = section_offsets; |
| 1318 | psymtab -> textlow = textlow; |
| 1319 | psymtab -> texthigh = psymtab -> textlow; /* default */ |
| 1320 | psymtab -> globals_offset = global_syms - objfile -> global_psymbols.list; |
| 1321 | psymtab -> statics_offset = static_syms - objfile -> static_psymbols.list; |
| 1322 | return (psymtab); |
| 1323 | } |
| 1324 | \f |
| 1325 | /* Debugging versions of functions that are usually inline macros |
| 1326 | (see symfile.h). */ |
| 1327 | |
| 1328 | #if 0 /* Don't quite work nowadays... */ |
| 1329 | |
| 1330 | /* Add a symbol with a long value to a psymtab. |
| 1331 | Since one arg is a struct, we pass in a ptr and deref it (sigh). */ |
| 1332 | |
| 1333 | void |
| 1334 | add_psymbol_to_list (name, namelength, namespace, class, list, val) |
| 1335 | char *name; |
| 1336 | int namelength; |
| 1337 | enum namespace namespace; |
| 1338 | enum address_class class; |
| 1339 | struct psymbol_allocation_list *list; |
| 1340 | long val; |
| 1341 | { |
| 1342 | ADD_PSYMBOL_VT_TO_LIST (name, namelength, namespace, class, (*list), val, |
| 1343 | SYMBOL_VALUE); |
| 1344 | } |
| 1345 | |
| 1346 | /* Add a symbol with a CORE_ADDR value to a psymtab. */ |
| 1347 | |
| 1348 | void |
| 1349 | add_psymbol_addr_to_list (name, namelength, namespace, class, list, val) |
| 1350 | char *name; |
| 1351 | int namelength; |
| 1352 | enum namespace namespace; |
| 1353 | enum address_class class; |
| 1354 | struct psymbol_allocation_list *list; |
| 1355 | CORE_ADDR val; |
| 1356 | { |
| 1357 | ADD_PSYMBOL_VT_TO_LIST (name, namelength, namespace, class, (*list), val, |
| 1358 | SYMBOL_VALUE_ADDRESS); |
| 1359 | } |
| 1360 | |
| 1361 | #endif /* 0 */ |
| 1362 | \f |
| 1363 | void |
| 1364 | _initialize_symfile () |
| 1365 | { |
| 1366 | |
| 1367 | add_com ("symbol-file", class_files, symbol_file_command, |
| 1368 | "Load symbol table from executable file FILE.\n\ |
| 1369 | The `file' command can also load symbol tables, as well as setting the file\n\ |
| 1370 | to execute."); |
| 1371 | |
| 1372 | add_com ("add-symbol-file", class_files, add_symbol_file_command, |
| 1373 | "Load the symbols from FILE, assuming FILE has been dynamically loaded.\n\ |
| 1374 | The second argument provides the starting address of the file's text."); |
| 1375 | |
| 1376 | add_com ("load", class_files, load_command, |
| 1377 | "Dynamically load FILE into the running program, and record its symbols\n\ |
| 1378 | for access from GDB."); |
| 1379 | |
| 1380 | add_show_from_set |
| 1381 | (add_set_cmd ("complaints", class_support, var_zinteger, |
| 1382 | (char *)&stop_whining, |
| 1383 | "Set max number of complaints about incorrect symbols.", |
| 1384 | &setlist), |
| 1385 | &showlist); |
| 1386 | |
| 1387 | add_show_from_set |
| 1388 | (add_set_cmd ("symbol-reloading", class_support, var_boolean, |
| 1389 | (char *)&symbol_reloading, |
| 1390 | "Set dynamic symbol table reloading multiple times in one run.", |
| 1391 | &setlist), |
| 1392 | &showlist); |
| 1393 | |
| 1394 | } |