| 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 | static 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 | /* Process a symbol file, as either the main file or as a dynamically |
| 336 | loaded file. |
| 337 | |
| 338 | NAME is the file name (which will be tilde-expanded and made |
| 339 | absolute herein) (but we don't free or modify NAME itself). |
| 340 | FROM_TTY says how verbose to be. MAINLINE specifies whether this |
| 341 | is the main symbol file, or whether it's an extra symbol file such |
| 342 | as dynamically loaded code. If !mainline, ADDR is the address |
| 343 | where the text segment was loaded. If VERBO, the caller has printed |
| 344 | a verbose message about the symbol reading (and complaints can be |
| 345 | more terse about it). */ |
| 346 | |
| 347 | void |
| 348 | syms_from_objfile (objfile, addr, mainline, verbo) |
| 349 | struct objfile *objfile; |
| 350 | CORE_ADDR addr; |
| 351 | int mainline; |
| 352 | int verbo; |
| 353 | { |
| 354 | asection *text_sect; |
| 355 | |
| 356 | /* There is a distinction between having no symbol table |
| 357 | (we refuse to read the file, leaving the old set of symbols around) |
| 358 | and having no debugging symbols in your symbol table (we read |
| 359 | the file and end up with a mostly empty symbol table). |
| 360 | |
| 361 | FIXME: This strategy works correctly when the debugging symbols are |
| 362 | intermixed with "normal" symbols. However, when the debugging symbols |
| 363 | are separate, such as with ELF/DWARF, it is perfectly plausible for |
| 364 | the symbol table to be missing but still have all the DWARF info |
| 365 | intact. Thus in general it is wrong to assume that having no symbol |
| 366 | table implies no debugging information. */ |
| 367 | |
| 368 | if (!(bfd_get_file_flags (objfile -> obfd) & HAS_SYMS)) |
| 369 | return; |
| 370 | |
| 371 | init_entry_point_info (objfile); |
| 372 | find_sym_fns (objfile); |
| 373 | |
| 374 | if (mainline) |
| 375 | { |
| 376 | /* Since no error yet, throw away the old symbol table. */ |
| 377 | |
| 378 | if (symfile_objfile != NULL) |
| 379 | { |
| 380 | free_objfile (symfile_objfile); |
| 381 | symfile_objfile = NULL; |
| 382 | } |
| 383 | |
| 384 | (*objfile -> sf -> sym_new_init) (objfile); |
| 385 | |
| 386 | /* For mainline, caller didn't know the specified address of the |
| 387 | text section. We fix that here. */ |
| 388 | |
| 389 | text_sect = bfd_get_section_by_name (objfile -> obfd, ".text"); |
| 390 | addr = bfd_section_vma (objfile -> obfd, text_sect); |
| 391 | } |
| 392 | |
| 393 | /* Initialize symbol reading routines for this objfile, allow complaints to |
| 394 | appear for this new file, and record how verbose to be, then do the |
| 395 | initial symbol reading for this file. */ |
| 396 | |
| 397 | (*objfile -> sf -> sym_init) (objfile); |
| 398 | clear_complaints (1, verbo); |
| 399 | (*objfile -> sf -> sym_read) (objfile, addr, mainline); |
| 400 | |
| 401 | /* Don't allow char * to have a typename (else would get caddr_t.) */ |
| 402 | /* Ditto void *. FIXME should do this for all the builtin types. */ |
| 403 | |
| 404 | TYPE_NAME (lookup_pointer_type (builtin_type_char)) = 0; |
| 405 | TYPE_NAME (lookup_pointer_type (builtin_type_void)) = 0; |
| 406 | |
| 407 | /* Mark the objfile has having had initial symbol read attempted. Note |
| 408 | that this does not mean we found any symbols... */ |
| 409 | |
| 410 | objfile -> flags |= OBJF_SYMS; |
| 411 | } |
| 412 | |
| 413 | /* Perform required actions immediately after either reading in the initial |
| 414 | symbols for a new objfile, or mapping in the symbols from a reusable |
| 415 | objfile. */ |
| 416 | |
| 417 | void |
| 418 | new_symfile_objfile (objfile, mainline, verbo) |
| 419 | struct objfile *objfile; |
| 420 | int mainline; |
| 421 | int verbo; |
| 422 | { |
| 423 | if (mainline) |
| 424 | { |
| 425 | /* OK, make it the "real" symbol file. */ |
| 426 | symfile_objfile = objfile; |
| 427 | } |
| 428 | |
| 429 | /* If we have wiped out any old symbol tables, clean up. */ |
| 430 | clear_symtab_users_once (); |
| 431 | |
| 432 | /* We're done reading the symbol file; finish off complaints. */ |
| 433 | clear_complaints (0, verbo); |
| 434 | |
| 435 | /* Fixup all the breakpoints that may have been redefined by this |
| 436 | symbol file. */ |
| 437 | |
| 438 | breakpoint_re_set (); |
| 439 | } |
| 440 | |
| 441 | /* Process a symbol file, as either the main file or as a dynamically |
| 442 | loaded file. |
| 443 | |
| 444 | NAME is the file name (which will be tilde-expanded and made |
| 445 | absolute herein) (but we don't free or modify NAME itself). |
| 446 | FROM_TTY says how verbose to be. MAINLINE specifies whether this |
| 447 | is the main symbol file, or whether it's an extra symbol file such |
| 448 | as dynamically loaded code. If !mainline, ADDR is the address |
| 449 | where the text segment was loaded. |
| 450 | |
| 451 | Upon success, returns a pointer to the objfile that was added. |
| 452 | Upon failure, jumps back to command level (never returns). */ |
| 453 | |
| 454 | struct objfile * |
| 455 | symbol_file_add (name, from_tty, addr, mainline, mapped, readnow) |
| 456 | char *name; |
| 457 | int from_tty; |
| 458 | CORE_ADDR addr; |
| 459 | int mainline; |
| 460 | int mapped; |
| 461 | int readnow; |
| 462 | { |
| 463 | struct objfile *objfile; |
| 464 | struct partial_symtab *psymtab; |
| 465 | bfd *abfd; |
| 466 | |
| 467 | /* Open a bfd for the file and then check to see if the file has a |
| 468 | symbol table. There is a distinction between having no symbol table |
| 469 | (we refuse to read the file, leaving the old set of symbols around) |
| 470 | and having no debugging symbols in the symbol table (we read the file |
| 471 | and end up with a mostly empty symbol table, but with lots of stuff in |
| 472 | the minimal symbol table). We need to make the decision about whether |
| 473 | to continue with the file before allocating and building a objfile. |
| 474 | |
| 475 | FIXME: This strategy works correctly when the debugging symbols are |
| 476 | intermixed with "normal" symbols. However, when the debugging symbols |
| 477 | are separate, such as with ELF/DWARF, it is perfectly plausible for |
| 478 | the symbol table to be missing but still have all the DWARF info |
| 479 | intact. Thus in general it is wrong to assume that having no symbol |
| 480 | table implies no debugging information. */ |
| 481 | |
| 482 | abfd = symfile_bfd_open (name); |
| 483 | if (!(bfd_get_file_flags (abfd) & HAS_SYMS)) |
| 484 | { |
| 485 | error ("%s has no symbol-table", name); |
| 486 | } |
| 487 | |
| 488 | if ((have_full_symbols () || have_partial_symbols ()) |
| 489 | && mainline |
| 490 | && from_tty |
| 491 | && !query ("Load new symbol table from \"%s\"? ", name)) |
| 492 | error ("Not confirmed."); |
| 493 | |
| 494 | objfile = allocate_objfile (abfd, mapped); |
| 495 | |
| 496 | /* If the objfile uses a mapped symbol file, and we have a psymtab for |
| 497 | it, then skip reading any symbols at this time. */ |
| 498 | |
| 499 | if ((objfile -> flags & OBJF_MAPPED) && (objfile -> flags & OBJF_SYMS)) |
| 500 | { |
| 501 | /* We mapped in an existing symbol table file that already has had |
| 502 | initial symbol reading performed, so we can skip that part. Notify |
| 503 | the user that instead of reading the symbols, they have been mapped. |
| 504 | */ |
| 505 | if (from_tty || info_verbose) |
| 506 | { |
| 507 | printf_filtered ("Mapped symbols for %s...", name); |
| 508 | wrap_here (""); |
| 509 | fflush (stdout); |
| 510 | } |
| 511 | init_entry_point_info (objfile); |
| 512 | find_sym_fns (objfile); |
| 513 | } |
| 514 | else |
| 515 | { |
| 516 | /* We either created a new mapped symbol table, mapped an existing |
| 517 | symbol table file which has not had initial symbol reading |
| 518 | performed, or need to read an unmapped symbol table. */ |
| 519 | if (from_tty || info_verbose) |
| 520 | { |
| 521 | printf_filtered ("Reading symbols from %s...", name); |
| 522 | wrap_here (""); |
| 523 | fflush (stdout); |
| 524 | } |
| 525 | syms_from_objfile (objfile, addr, mainline, from_tty); |
| 526 | } |
| 527 | |
| 528 | new_symfile_objfile (objfile, mainline, from_tty); |
| 529 | |
| 530 | /* We now have at least a partial symbol table. Check to see if the |
| 531 | user requested that all symbols be read on initial access via either |
| 532 | the gdb startup command line or on a per symbol file basis. Expand |
| 533 | all partial symbol tables for this objfile if so. */ |
| 534 | |
| 535 | if (readnow || readnow_symbol_files) |
| 536 | { |
| 537 | if (from_tty || info_verbose) |
| 538 | { |
| 539 | printf_filtered ("expanding to full symbols..."); |
| 540 | wrap_here (""); |
| 541 | fflush (stdout); |
| 542 | } |
| 543 | |
| 544 | for (psymtab = objfile -> psymtabs; |
| 545 | psymtab != NULL; |
| 546 | psymtab = psymtab -> next) |
| 547 | { |
| 548 | (void) psymtab_to_symtab (psymtab); |
| 549 | } |
| 550 | } |
| 551 | |
| 552 | if (from_tty || info_verbose) |
| 553 | { |
| 554 | printf_filtered ("done.\n"); |
| 555 | fflush (stdout); |
| 556 | } |
| 557 | |
| 558 | return (objfile); |
| 559 | } |
| 560 | |
| 561 | /* This is the symbol-file command. Read the file, analyze its symbols, |
| 562 | and add a struct symtab to a symtab list. */ |
| 563 | |
| 564 | void |
| 565 | symbol_file_command (args, from_tty) |
| 566 | char *args; |
| 567 | int from_tty; |
| 568 | { |
| 569 | char **argv; |
| 570 | char *name = NULL; |
| 571 | struct cleanup *cleanups; |
| 572 | int mapped = 0; |
| 573 | int readnow = 0; |
| 574 | |
| 575 | dont_repeat (); |
| 576 | |
| 577 | if (args == NULL) |
| 578 | { |
| 579 | if ((have_full_symbols () || have_partial_symbols ()) |
| 580 | && from_tty |
| 581 | && !query ("Discard symbol table from `%s'? ", |
| 582 | symfile_objfile -> name)) |
| 583 | error ("Not confirmed."); |
| 584 | free_all_objfiles (); |
| 585 | symfile_objfile = NULL; |
| 586 | if (from_tty) |
| 587 | { |
| 588 | printf ("No symbol file now.\n"); |
| 589 | } |
| 590 | } |
| 591 | else |
| 592 | { |
| 593 | if ((argv = buildargv (args)) == NULL) |
| 594 | { |
| 595 | nomem (0); |
| 596 | } |
| 597 | cleanups = make_cleanup (freeargv, (char *) argv); |
| 598 | while (*argv != NULL) |
| 599 | { |
| 600 | if (strcmp (*argv, "-mapped") == 0) |
| 601 | { |
| 602 | mapped = 1; |
| 603 | } |
| 604 | else if (strcmp (*argv, "-readnow") == 0) |
| 605 | { |
| 606 | readnow = 1; |
| 607 | } |
| 608 | else if (**argv == '-') |
| 609 | { |
| 610 | error ("unknown option `%s'", *argv); |
| 611 | } |
| 612 | else |
| 613 | { |
| 614 | name = *argv; |
| 615 | } |
| 616 | argv++; |
| 617 | } |
| 618 | |
| 619 | if (name == NULL) |
| 620 | { |
| 621 | error ("no symbol file name was specified"); |
| 622 | } |
| 623 | else |
| 624 | { |
| 625 | /* Getting new symbols may change our opinion about what is |
| 626 | frameless. */ |
| 627 | reinit_frame_cache (); |
| 628 | (void) symbol_file_add (name, from_tty, (CORE_ADDR)0, 1, |
| 629 | mapped, readnow); |
| 630 | } |
| 631 | do_cleanups (cleanups); |
| 632 | } |
| 633 | } |
| 634 | |
| 635 | /* Open file specified by NAME and hand it off to BFD for preliminary |
| 636 | analysis. Result is a newly initialized bfd *, which includes a newly |
| 637 | malloc'd` copy of NAME (tilde-expanded and made absolute). |
| 638 | In case of trouble, error() is called. */ |
| 639 | |
| 640 | static bfd * |
| 641 | symfile_bfd_open (name) |
| 642 | char *name; |
| 643 | { |
| 644 | bfd *sym_bfd; |
| 645 | int desc; |
| 646 | char *absolute_name; |
| 647 | |
| 648 | name = tilde_expand (name); /* Returns 1st new malloc'd copy */ |
| 649 | |
| 650 | /* Look down path for it, allocate 2nd new malloc'd copy. */ |
| 651 | desc = openp (getenv ("PATH"), 1, name, O_RDONLY, 0, &absolute_name); |
| 652 | if (desc < 0) |
| 653 | { |
| 654 | make_cleanup (free, name); |
| 655 | perror_with_name (name); |
| 656 | } |
| 657 | free (name); /* Free 1st new malloc'd copy */ |
| 658 | name = absolute_name; /* Keep 2nd malloc'd copy in bfd */ |
| 659 | /* It'll be freed in free_objfile(). */ |
| 660 | |
| 661 | sym_bfd = bfd_fdopenr (name, NULL, desc); |
| 662 | if (!sym_bfd) |
| 663 | { |
| 664 | close (desc); |
| 665 | make_cleanup (free, name); |
| 666 | error ("\"%s\": can't open to read symbols: %s.", name, |
| 667 | bfd_errmsg (bfd_error)); |
| 668 | } |
| 669 | |
| 670 | if (!bfd_check_format (sym_bfd, bfd_object)) |
| 671 | { |
| 672 | bfd_close (sym_bfd); /* This also closes desc */ |
| 673 | make_cleanup (free, name); |
| 674 | error ("\"%s\": can't read symbols: %s.", name, |
| 675 | bfd_errmsg (bfd_error)); |
| 676 | } |
| 677 | |
| 678 | return (sym_bfd); |
| 679 | } |
| 680 | |
| 681 | /* Link a new symtab_fns into the global symtab_fns list. Called on gdb |
| 682 | startup by the _initialize routine in each object file format reader, |
| 683 | to register information about each format the the reader is prepared |
| 684 | to handle. */ |
| 685 | |
| 686 | void |
| 687 | add_symtab_fns (sf) |
| 688 | struct sym_fns *sf; |
| 689 | { |
| 690 | sf->next = symtab_fns; |
| 691 | symtab_fns = sf; |
| 692 | } |
| 693 | |
| 694 | |
| 695 | /* Initialize to read symbols from the symbol file sym_bfd. It either |
| 696 | returns or calls error(). The result is an initialized struct sym_fns |
| 697 | in the objfile structure, that contains cached information about the |
| 698 | symbol file. */ |
| 699 | |
| 700 | static void |
| 701 | find_sym_fns (objfile) |
| 702 | struct objfile *objfile; |
| 703 | { |
| 704 | struct sym_fns *sf; |
| 705 | |
| 706 | for (sf = symtab_fns; sf != NULL; sf = sf -> next) |
| 707 | { |
| 708 | if (strncmp (bfd_get_target (objfile -> obfd), |
| 709 | sf -> sym_name, sf -> sym_namelen) == 0) |
| 710 | { |
| 711 | objfile -> sf = sf; |
| 712 | return; |
| 713 | } |
| 714 | } |
| 715 | error ("I'm sorry, Dave, I can't do that. Symbol format `%s' unknown.", |
| 716 | bfd_get_target (objfile -> obfd)); |
| 717 | } |
| 718 | \f |
| 719 | /* This function runs the load command of our current target. */ |
| 720 | |
| 721 | static void |
| 722 | load_command (arg, from_tty) |
| 723 | char *arg; |
| 724 | int from_tty; |
| 725 | { |
| 726 | target_load (arg, from_tty); |
| 727 | } |
| 728 | |
| 729 | /* This function allows the addition of incrementally linked object files. |
| 730 | It does not modify any state in the target, only in the debugger. */ |
| 731 | |
| 732 | /* ARGSUSED */ |
| 733 | static void |
| 734 | add_symbol_file_command (args, from_tty) |
| 735 | char *args; |
| 736 | int from_tty; |
| 737 | { |
| 738 | char *name = NULL; |
| 739 | CORE_ADDR text_addr; |
| 740 | char *arg; |
| 741 | int readnow = 0; |
| 742 | int mapped = 0; |
| 743 | |
| 744 | dont_repeat (); |
| 745 | |
| 746 | if (args == NULL) |
| 747 | { |
| 748 | error ("add-symbol-file takes a file name and an address"); |
| 749 | } |
| 750 | |
| 751 | /* Make a copy of the string that we can safely write into. */ |
| 752 | |
| 753 | args = strdup (args); |
| 754 | make_cleanup (free, args); |
| 755 | |
| 756 | /* Pick off any -option args and the file name. */ |
| 757 | |
| 758 | while ((*args != '\000') && (name == NULL)) |
| 759 | { |
| 760 | while (isspace (*args)) {args++;} |
| 761 | arg = args; |
| 762 | while ((*args != '\000') && !isspace (*args)) {args++;} |
| 763 | if (*args != '\000') |
| 764 | { |
| 765 | *args++ = '\000'; |
| 766 | } |
| 767 | if (*arg != '-') |
| 768 | { |
| 769 | name = arg; |
| 770 | } |
| 771 | else if (strcmp (arg, "-mapped") == 0) |
| 772 | { |
| 773 | mapped = 1; |
| 774 | } |
| 775 | else if (strcmp (arg, "-readnow") == 0) |
| 776 | { |
| 777 | readnow = 1; |
| 778 | } |
| 779 | else |
| 780 | { |
| 781 | error ("unknown option `%s'", arg); |
| 782 | } |
| 783 | } |
| 784 | |
| 785 | /* After picking off any options and the file name, args should be |
| 786 | left pointing at the remainder of the command line, which should |
| 787 | be the address expression to evaluate. */ |
| 788 | |
| 789 | if ((name == NULL) || (*args == '\000') ) |
| 790 | { |
| 791 | error ("add-symbol-file takes a file name and an address"); |
| 792 | } |
| 793 | name = tilde_expand (name); |
| 794 | make_cleanup (free, name); |
| 795 | |
| 796 | text_addr = parse_and_eval_address (args); |
| 797 | |
| 798 | if (!query ("add symbol table from file \"%s\" at text_addr = %s?\n", |
| 799 | name, local_hex_string (text_addr))) |
| 800 | error ("Not confirmed."); |
| 801 | |
| 802 | /* Getting new symbols may change our opinion about what is |
| 803 | frameless. */ |
| 804 | |
| 805 | reinit_frame_cache (); |
| 806 | |
| 807 | (void) symbol_file_add (name, 0, text_addr, 0, mapped, readnow); |
| 808 | } |
| 809 | \f |
| 810 | /* Re-read symbols if a symbol-file has changed. */ |
| 811 | void |
| 812 | reread_symbols () |
| 813 | { |
| 814 | struct objfile *objfile; |
| 815 | long new_modtime; |
| 816 | int reread_one = 0; |
| 817 | struct stat new_statbuf; |
| 818 | int res; |
| 819 | |
| 820 | /* With the addition of shared libraries, this should be modified, |
| 821 | the load time should be saved in the partial symbol tables, since |
| 822 | different tables may come from different source files. FIXME. |
| 823 | This routine should then walk down each partial symbol table |
| 824 | and see if the symbol table that it originates from has been changed */ |
| 825 | |
| 826 | the_big_top: |
| 827 | for (objfile = object_files; objfile; objfile = objfile->next) { |
| 828 | if (objfile->obfd) { |
| 829 | #ifdef IBM6000_TARGET |
| 830 | /* If this object is from a shared library, then you should |
| 831 | stat on the library name, not member name. */ |
| 832 | |
| 833 | if (objfile->obfd->my_archive) |
| 834 | res = stat (objfile->obfd->my_archive->filename, &new_statbuf); |
| 835 | else |
| 836 | #endif |
| 837 | res = stat (objfile->name, &new_statbuf); |
| 838 | if (res != 0) { |
| 839 | /* FIXME, should use print_sys_errmsg but it's not filtered. */ |
| 840 | printf_filtered ("`%s' has disappeared; keeping its symbols.\n", |
| 841 | objfile->name); |
| 842 | continue; |
| 843 | } |
| 844 | new_modtime = new_statbuf.st_mtime; |
| 845 | if (new_modtime != objfile->mtime) { |
| 846 | printf_filtered ("`%s' has changed; re-reading symbols.\n", |
| 847 | objfile->name); |
| 848 | /* FIXME, this should use a different command...that would only |
| 849 | affect this objfile's symbols, and would reset objfile->mtime. |
| 850 | (objfile->mtime = new_modtime;) |
| 851 | HOWEVER, that command isn't written yet -- so call symbol_file_ |
| 852 | command, and restart the scan from the top, because it munges |
| 853 | the object_files list. */ |
| 854 | symbol_file_command (objfile->name, 0); |
| 855 | reread_one = 1; |
| 856 | goto the_big_top; /* Start over. */ |
| 857 | } |
| 858 | } |
| 859 | } |
| 860 | |
| 861 | if (reread_one) |
| 862 | breakpoint_re_set (); |
| 863 | } |
| 864 | \f |
| 865 | /* Functions to handle complaints during symbol reading. */ |
| 866 | |
| 867 | /* How many complaints about a particular thing should be printed before |
| 868 | we stop whining about it? Default is no whining at all, since so many |
| 869 | systems have ill-constructed symbol files. */ |
| 870 | |
| 871 | static unsigned stop_whining = 0; |
| 872 | |
| 873 | /* Should each complaint be self explanatory, or should we assume that |
| 874 | a series of complaints is being produced? |
| 875 | case 0: self explanatory message. |
| 876 | case 1: First message of a series that must start off with explanation. |
| 877 | case 2: Subsequent message, when user already knows we are reading |
| 878 | symbols and we can just state our piece. */ |
| 879 | |
| 880 | static int complaint_series = 0; |
| 881 | |
| 882 | /* Print a complaint about the input symbols, and link the complaint block |
| 883 | into a chain for later handling. */ |
| 884 | |
| 885 | void |
| 886 | complain (complaint, val) |
| 887 | struct complaint *complaint; |
| 888 | char *val; |
| 889 | { |
| 890 | complaint->counter++; |
| 891 | if (complaint->next == 0) { |
| 892 | complaint->next = complaint_root->next; |
| 893 | complaint_root->next = complaint; |
| 894 | } |
| 895 | if (complaint->counter > stop_whining) |
| 896 | return; |
| 897 | wrap_here (""); |
| 898 | |
| 899 | switch (complaint_series + (info_verbose << 1)) { |
| 900 | |
| 901 | /* Isolated messages, must be self-explanatory. */ |
| 902 | case 0: |
| 903 | puts_filtered ("During symbol reading, "); |
| 904 | wrap_here(""); |
| 905 | printf_filtered (complaint->message, val); |
| 906 | puts_filtered (".\n"); |
| 907 | break; |
| 908 | |
| 909 | /* First of a series, without `set verbose'. */ |
| 910 | case 1: |
| 911 | puts_filtered ("During symbol reading..."); |
| 912 | printf_filtered (complaint->message, val); |
| 913 | puts_filtered ("..."); |
| 914 | wrap_here(""); |
| 915 | complaint_series++; |
| 916 | break; |
| 917 | |
| 918 | /* Subsequent messages of a series, or messages under `set verbose'. |
| 919 | (We'll already have produced a "Reading in symbols for XXX..." message |
| 920 | and will clean up at the end with a newline.) */ |
| 921 | default: |
| 922 | printf_filtered (complaint->message, val); |
| 923 | puts_filtered ("..."); |
| 924 | wrap_here(""); |
| 925 | } |
| 926 | } |
| 927 | |
| 928 | /* Clear out all complaint counters that have ever been incremented. |
| 929 | If sym_reading is 1, be less verbose about successive complaints, |
| 930 | since the messages are appearing all together during a command that |
| 931 | reads symbols (rather than scattered around as psymtabs get fleshed |
| 932 | out into symtabs at random times). If noisy is 1, we are in a |
| 933 | noisy symbol reading command, and our caller will print enough |
| 934 | context for the user to figure it out. */ |
| 935 | |
| 936 | void |
| 937 | clear_complaints (sym_reading, noisy) |
| 938 | int sym_reading; |
| 939 | int noisy; |
| 940 | { |
| 941 | struct complaint *p; |
| 942 | |
| 943 | for (p = complaint_root->next; p != complaint_root; p = p->next) |
| 944 | p->counter = 0; |
| 945 | |
| 946 | if (!sym_reading && !noisy && complaint_series > 1) { |
| 947 | /* Terminate previous series, since caller won't. */ |
| 948 | puts_filtered ("\n"); |
| 949 | } |
| 950 | |
| 951 | complaint_series = sym_reading? 1 + noisy: 0; |
| 952 | } |
| 953 | \f |
| 954 | enum language |
| 955 | deduce_language_from_filename (filename) |
| 956 | char *filename; |
| 957 | { |
| 958 | char *c = strrchr (filename, '.'); |
| 959 | |
| 960 | if (!c) ; /* Get default. */ |
| 961 | else if(!strcmp(c,".mod")) |
| 962 | return language_m2; |
| 963 | else if(!strcmp(c,".c")) |
| 964 | return language_c; |
| 965 | else if(!strcmp(c,".cc") || !strcmp(c,".C")) |
| 966 | return language_cplus; |
| 967 | |
| 968 | return language_unknown; /* default */ |
| 969 | } |
| 970 | \f |
| 971 | /* allocate_symtab: |
| 972 | |
| 973 | Allocate and partly initialize a new symbol table. Return a pointer |
| 974 | to it. error() if no space. |
| 975 | |
| 976 | Caller must set these fields: |
| 977 | LINETABLE(symtab) |
| 978 | symtab->blockvector |
| 979 | symtab->dirname |
| 980 | symtab->free_code |
| 981 | symtab->free_ptr |
| 982 | initialize any EXTRA_SYMTAB_INFO |
| 983 | possibly free_named_symtabs (symtab->filename); |
| 984 | */ |
| 985 | |
| 986 | struct symtab * |
| 987 | allocate_symtab (filename, objfile) |
| 988 | char *filename; |
| 989 | struct objfile *objfile; |
| 990 | { |
| 991 | register struct symtab *symtab; |
| 992 | |
| 993 | symtab = (struct symtab *) |
| 994 | obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symtab)); |
| 995 | (void) memset (symtab, 0, sizeof (*symtab)); |
| 996 | symtab -> filename = obsavestring (filename, strlen (filename), |
| 997 | &objfile -> symbol_obstack); |
| 998 | symtab -> fullname = NULL; |
| 999 | symtab -> language = deduce_language_from_filename (filename); |
| 1000 | |
| 1001 | /* Hook it to the objfile it comes from */ |
| 1002 | |
| 1003 | symtab -> objfile = objfile; |
| 1004 | symtab -> next = objfile -> symtabs; |
| 1005 | objfile -> symtabs = symtab; |
| 1006 | |
| 1007 | #ifdef INIT_EXTRA_SYMTAB_INFO |
| 1008 | INIT_EXTRA_SYMTAB_INFO (symtab); |
| 1009 | #endif |
| 1010 | |
| 1011 | return (symtab); |
| 1012 | } |
| 1013 | |
| 1014 | struct partial_symtab * |
| 1015 | allocate_psymtab (filename, objfile) |
| 1016 | char *filename; |
| 1017 | struct objfile *objfile; |
| 1018 | { |
| 1019 | struct partial_symtab *psymtab; |
| 1020 | |
| 1021 | if (objfile -> free_psymtabs) |
| 1022 | { |
| 1023 | psymtab = objfile -> free_psymtabs; |
| 1024 | objfile -> free_psymtabs = psymtab -> next; |
| 1025 | } |
| 1026 | else |
| 1027 | psymtab = (struct partial_symtab *) |
| 1028 | obstack_alloc (&objfile -> psymbol_obstack, |
| 1029 | sizeof (struct partial_symtab)); |
| 1030 | |
| 1031 | (void) memset (psymtab, 0, sizeof (struct partial_symtab)); |
| 1032 | psymtab -> filename = obsavestring (filename, strlen (filename), |
| 1033 | &objfile -> psymbol_obstack); |
| 1034 | psymtab -> symtab = NULL; |
| 1035 | |
| 1036 | /* Hook it to the objfile it comes from */ |
| 1037 | |
| 1038 | psymtab -> objfile = objfile; |
| 1039 | psymtab -> next = objfile -> psymtabs; |
| 1040 | objfile -> psymtabs = psymtab; |
| 1041 | |
| 1042 | return (psymtab); |
| 1043 | } |
| 1044 | |
| 1045 | \f |
| 1046 | /* clear_symtab_users_once: |
| 1047 | |
| 1048 | This function is run after symbol reading, or from a cleanup. |
| 1049 | If an old symbol table was obsoleted, the old symbol table |
| 1050 | has been blown away, but the other GDB data structures that may |
| 1051 | reference it have not yet been cleared or re-directed. (The old |
| 1052 | symtab was zapped, and the cleanup queued, in free_named_symtab() |
| 1053 | below.) |
| 1054 | |
| 1055 | This function can be queued N times as a cleanup, or called |
| 1056 | directly; it will do all the work the first time, and then will be a |
| 1057 | no-op until the next time it is queued. This works by bumping a |
| 1058 | counter at queueing time. Much later when the cleanup is run, or at |
| 1059 | the end of symbol processing (in case the cleanup is discarded), if |
| 1060 | the queued count is greater than the "done-count", we do the work |
| 1061 | and set the done-count to the queued count. If the queued count is |
| 1062 | less than or equal to the done-count, we just ignore the call. This |
| 1063 | is needed because reading a single .o file will often replace many |
| 1064 | symtabs (one per .h file, for example), and we don't want to reset |
| 1065 | the breakpoints N times in the user's face. |
| 1066 | |
| 1067 | The reason we both queue a cleanup, and call it directly after symbol |
| 1068 | reading, is because the cleanup protects us in case of errors, but is |
| 1069 | discarded if symbol reading is successful. */ |
| 1070 | |
| 1071 | static int clear_symtab_users_queued; |
| 1072 | static int clear_symtab_users_done; |
| 1073 | |
| 1074 | static void |
| 1075 | clear_symtab_users_once () |
| 1076 | { |
| 1077 | /* Enforce once-per-`do_cleanups'-semantics */ |
| 1078 | if (clear_symtab_users_queued <= clear_symtab_users_done) |
| 1079 | return; |
| 1080 | clear_symtab_users_done = clear_symtab_users_queued; |
| 1081 | |
| 1082 | printf ("Resetting debugger state after updating old symbol tables\n"); |
| 1083 | |
| 1084 | /* Someday, we should do better than this, by only blowing away |
| 1085 | the things that really need to be blown. */ |
| 1086 | clear_value_history (); |
| 1087 | clear_displays (); |
| 1088 | clear_internalvars (); |
| 1089 | breakpoint_re_set (); |
| 1090 | set_default_breakpoint (0, 0, 0, 0); |
| 1091 | current_source_symtab = 0; |
| 1092 | } |
| 1093 | |
| 1094 | /* Delete the specified psymtab, and any others that reference it. */ |
| 1095 | |
| 1096 | static void |
| 1097 | cashier_psymtab (pst) |
| 1098 | struct partial_symtab *pst; |
| 1099 | { |
| 1100 | struct partial_symtab *ps, *pprev; |
| 1101 | int i; |
| 1102 | |
| 1103 | /* Find its previous psymtab in the chain */ |
| 1104 | for (ps = pst->objfile->psymtabs; ps; ps = ps->next) { |
| 1105 | if (ps == pst) |
| 1106 | break; |
| 1107 | pprev = ps; |
| 1108 | } |
| 1109 | |
| 1110 | if (ps) { |
| 1111 | /* Unhook it from the chain. */ |
| 1112 | if (ps == pst->objfile->psymtabs) |
| 1113 | pst->objfile->psymtabs = ps->next; |
| 1114 | else |
| 1115 | pprev->next = ps->next; |
| 1116 | |
| 1117 | /* FIXME, we can't conveniently deallocate the entries in the |
| 1118 | partial_symbol lists (global_psymbols/static_psymbols) that |
| 1119 | this psymtab points to. These just take up space until all |
| 1120 | the psymtabs are reclaimed. Ditto the dependencies list and |
| 1121 | filename, which are all in the psymbol_obstack. */ |
| 1122 | |
| 1123 | /* We need to cashier any psymtab that has this one as a dependency... */ |
| 1124 | again: |
| 1125 | for (ps = pst->objfile->psymtabs; ps; ps = ps->next) { |
| 1126 | for (i = 0; i < ps->number_of_dependencies; i++) { |
| 1127 | if (ps->dependencies[i] == pst) { |
| 1128 | cashier_psymtab (ps); |
| 1129 | goto again; /* Must restart, chain has been munged. */ |
| 1130 | } |
| 1131 | } |
| 1132 | } |
| 1133 | } |
| 1134 | } |
| 1135 | |
| 1136 | /* If a symtab or psymtab for filename NAME is found, free it along |
| 1137 | with any dependent breakpoints, displays, etc. |
| 1138 | Used when loading new versions of object modules with the "add-file" |
| 1139 | command. This is only called on the top-level symtab or psymtab's name; |
| 1140 | it is not called for subsidiary files such as .h files. |
| 1141 | |
| 1142 | Return value is 1 if we blew away the environment, 0 if not. |
| 1143 | FIXME. The return valu appears to never be used. |
| 1144 | |
| 1145 | FIXME. I think this is not the best way to do this. We should |
| 1146 | work on being gentler to the environment while still cleaning up |
| 1147 | all stray pointers into the freed symtab. */ |
| 1148 | |
| 1149 | int |
| 1150 | free_named_symtabs (name) |
| 1151 | char *name; |
| 1152 | { |
| 1153 | #if 0 |
| 1154 | /* FIXME: With the new method of each objfile having it's own |
| 1155 | psymtab list, this function needs serious rethinking. In particular, |
| 1156 | why was it ever necessary to toss psymtabs with specific compilation |
| 1157 | unit filenames, as opposed to all psymtabs from a particular symbol |
| 1158 | file? -- fnf |
| 1159 | Well, the answer is that some systems permit reloading of particular |
| 1160 | compilation units. We want to blow away any old info about these |
| 1161 | compilation units, regardless of which objfiles they arrived in. --gnu. */ |
| 1162 | |
| 1163 | register struct symtab *s; |
| 1164 | register struct symtab *prev; |
| 1165 | register struct partial_symtab *ps; |
| 1166 | struct blockvector *bv; |
| 1167 | int blewit = 0; |
| 1168 | |
| 1169 | /* We only wack things if the symbol-reload switch is set. */ |
| 1170 | if (!symbol_reloading) |
| 1171 | return 0; |
| 1172 | |
| 1173 | /* Some symbol formats have trouble providing file names... */ |
| 1174 | if (name == 0 || *name == '\0') |
| 1175 | return 0; |
| 1176 | |
| 1177 | /* Look for a psymtab with the specified name. */ |
| 1178 | |
| 1179 | again2: |
| 1180 | for (ps = partial_symtab_list; ps; ps = ps->next) { |
| 1181 | if (!strcmp (name, ps->filename)) { |
| 1182 | cashier_psymtab (ps); /* Blow it away...and its little dog, too. */ |
| 1183 | goto again2; /* Must restart, chain has been munged */ |
| 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | /* Look for a symtab with the specified name. */ |
| 1188 | |
| 1189 | for (s = symtab_list; s; s = s->next) |
| 1190 | { |
| 1191 | if (!strcmp (name, s->filename)) |
| 1192 | break; |
| 1193 | prev = s; |
| 1194 | } |
| 1195 | |
| 1196 | if (s) |
| 1197 | { |
| 1198 | if (s == symtab_list) |
| 1199 | symtab_list = s->next; |
| 1200 | else |
| 1201 | prev->next = s->next; |
| 1202 | |
| 1203 | /* For now, queue a delete for all breakpoints, displays, etc., whether |
| 1204 | or not they depend on the symtab being freed. This should be |
| 1205 | changed so that only those data structures affected are deleted. */ |
| 1206 | |
| 1207 | /* But don't delete anything if the symtab is empty. |
| 1208 | This test is necessary due to a bug in "dbxread.c" that |
| 1209 | causes empty symtabs to be created for N_SO symbols that |
| 1210 | contain the pathname of the object file. (This problem |
| 1211 | has been fixed in GDB 3.9x). */ |
| 1212 | |
| 1213 | bv = BLOCKVECTOR (s); |
| 1214 | if (BLOCKVECTOR_NBLOCKS (bv) > 2 |
| 1215 | || BLOCK_NSYMS (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) |
| 1216 | || BLOCK_NSYMS (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK))) |
| 1217 | { |
| 1218 | complain (&oldsyms_complaint, name); |
| 1219 | |
| 1220 | clear_symtab_users_queued++; |
| 1221 | make_cleanup (clear_symtab_users_once, 0); |
| 1222 | blewit = 1; |
| 1223 | } else { |
| 1224 | complain (&empty_symtab_complaint, name); |
| 1225 | } |
| 1226 | |
| 1227 | free_symtab (s); |
| 1228 | } |
| 1229 | else |
| 1230 | { |
| 1231 | /* It is still possible that some breakpoints will be affected |
| 1232 | even though no symtab was found, since the file might have |
| 1233 | been compiled without debugging, and hence not be associated |
| 1234 | with a symtab. In order to handle this correctly, we would need |
| 1235 | to keep a list of text address ranges for undebuggable files. |
| 1236 | For now, we do nothing, since this is a fairly obscure case. */ |
| 1237 | ; |
| 1238 | } |
| 1239 | |
| 1240 | /* FIXME, what about the minimal symbol table? */ |
| 1241 | return blewit; |
| 1242 | #else |
| 1243 | return (0); |
| 1244 | #endif |
| 1245 | } |
| 1246 | \f |
| 1247 | /* Allocate and partially fill a partial symtab. It will be |
| 1248 | completely filled at the end of the symbol list. |
| 1249 | |
| 1250 | SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR |
| 1251 | is the address relative to which its symbols are (incremental) or 0 |
| 1252 | (normal). */ |
| 1253 | |
| 1254 | |
| 1255 | struct partial_symtab * |
| 1256 | start_psymtab_common (objfile, addr, |
| 1257 | filename, textlow, global_syms, static_syms) |
| 1258 | struct objfile *objfile; |
| 1259 | CORE_ADDR addr; |
| 1260 | char *filename; |
| 1261 | CORE_ADDR textlow; |
| 1262 | struct partial_symbol *global_syms; |
| 1263 | struct partial_symbol *static_syms; |
| 1264 | { |
| 1265 | struct partial_symtab *psymtab; |
| 1266 | |
| 1267 | psymtab = allocate_psymtab (filename, objfile); |
| 1268 | psymtab -> addr = addr; |
| 1269 | psymtab -> textlow = textlow; |
| 1270 | psymtab -> texthigh = psymtab -> textlow; /* default */ |
| 1271 | psymtab -> globals_offset = global_syms - objfile -> global_psymbols.list; |
| 1272 | psymtab -> statics_offset = static_syms - objfile -> static_psymbols.list; |
| 1273 | return (psymtab); |
| 1274 | } |
| 1275 | \f |
| 1276 | /* Debugging versions of functions that are usually inline macros |
| 1277 | (see symfile.h). */ |
| 1278 | |
| 1279 | #if 0 /* Don't quite work nowadays... */ |
| 1280 | |
| 1281 | /* Add a symbol with a long value to a psymtab. |
| 1282 | Since one arg is a struct, we pass in a ptr and deref it (sigh). */ |
| 1283 | |
| 1284 | void |
| 1285 | add_psymbol_to_list (name, namelength, namespace, class, list, val) |
| 1286 | char *name; |
| 1287 | int namelength; |
| 1288 | enum namespace namespace; |
| 1289 | enum address_class class; |
| 1290 | struct psymbol_allocation_list *list; |
| 1291 | long val; |
| 1292 | { |
| 1293 | ADD_PSYMBOL_VT_TO_LIST (name, namelength, namespace, class, (*list), val, |
| 1294 | SYMBOL_VALUE); |
| 1295 | } |
| 1296 | |
| 1297 | /* Add a symbol with a CORE_ADDR value to a psymtab. */ |
| 1298 | |
| 1299 | void |
| 1300 | add_psymbol_addr_to_list (name, namelength, namespace, class, list, val) |
| 1301 | char *name; |
| 1302 | int namelength; |
| 1303 | enum namespace namespace; |
| 1304 | enum address_class class; |
| 1305 | struct psymbol_allocation_list *list; |
| 1306 | CORE_ADDR val; |
| 1307 | { |
| 1308 | ADD_PSYMBOL_VT_TO_LIST (name, namelength, namespace, class, (*list), val, |
| 1309 | SYMBOL_VALUE_ADDRESS); |
| 1310 | } |
| 1311 | |
| 1312 | #endif /* 0 */ |
| 1313 | \f |
| 1314 | void |
| 1315 | _initialize_symfile () |
| 1316 | { |
| 1317 | |
| 1318 | add_com ("symbol-file", class_files, symbol_file_command, |
| 1319 | "Load symbol table from executable file FILE.\n\ |
| 1320 | The `file' command can also load symbol tables, as well as setting the file\n\ |
| 1321 | to execute."); |
| 1322 | |
| 1323 | add_com ("add-symbol-file", class_files, add_symbol_file_command, |
| 1324 | "Load the symbols from FILE, assuming FILE has been dynamically loaded.\n\ |
| 1325 | The second argument provides the starting address of the file's text."); |
| 1326 | |
| 1327 | add_com ("load", class_files, load_command, |
| 1328 | "Dynamically load FILE into the running program, and record its symbols\n\ |
| 1329 | for access from GDB."); |
| 1330 | |
| 1331 | add_show_from_set |
| 1332 | (add_set_cmd ("complaints", class_support, var_zinteger, |
| 1333 | (char *)&stop_whining, |
| 1334 | "Set max number of complaints about incorrect symbols.", |
| 1335 | &setlist), |
| 1336 | &showlist); |
| 1337 | |
| 1338 | add_show_from_set |
| 1339 | (add_set_cmd ("symbol-reloading", class_support, var_boolean, |
| 1340 | (char *)&symbol_reloading, |
| 1341 | "Set dynamic symbol table reloading multiple times in one run.", |
| 1342 | &setlist), |
| 1343 | &showlist); |
| 1344 | |
| 1345 | } |