| 1 | /* Generic symbol file reading for the GNU debugger, GDB. |
| 2 | Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996 |
| 3 | Free Software Foundation, Inc. |
| 4 | Contributed by Cygnus Support, using pieces from other GDB modules. |
| 5 | |
| 6 | This file is part of GDB. |
| 7 | |
| 8 | This program is free software; you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation; either version 2 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | This program is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with this program; if not, write to the Free Software |
| 20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
| 21 | |
| 22 | #include "defs.h" |
| 23 | #include "symtab.h" |
| 24 | #include "gdbtypes.h" |
| 25 | #include "gdbcore.h" |
| 26 | #include "frame.h" |
| 27 | #include "target.h" |
| 28 | #include "value.h" |
| 29 | #include "symfile.h" |
| 30 | #include "objfiles.h" |
| 31 | #include "gdbcmd.h" |
| 32 | #include "breakpoint.h" |
| 33 | #include "language.h" |
| 34 | #include "complaints.h" |
| 35 | #include "demangle.h" |
| 36 | #include "inferior.h" /* for write_pc */ |
| 37 | |
| 38 | #include "obstack.h" |
| 39 | #include <assert.h> |
| 40 | |
| 41 | #include <sys/types.h> |
| 42 | #include <fcntl.h> |
| 43 | #include "gdb_string.h" |
| 44 | #include "gdb_stat.h" |
| 45 | #include <ctype.h> |
| 46 | #include <time.h> |
| 47 | #ifdef HAVE_UNISTD_H |
| 48 | #include <unistd.h> |
| 49 | #endif |
| 50 | |
| 51 | #ifndef O_BINARY |
| 52 | #define O_BINARY 0 |
| 53 | #endif |
| 54 | |
| 55 | /* Global variables owned by this file */ |
| 56 | int readnow_symbol_files; /* Read full symbols immediately */ |
| 57 | |
| 58 | struct complaint oldsyms_complaint = { |
| 59 | "Replacing old symbols for `%s'", 0, 0 |
| 60 | }; |
| 61 | |
| 62 | struct complaint empty_symtab_complaint = { |
| 63 | "Empty symbol table found for `%s'", 0, 0 |
| 64 | }; |
| 65 | |
| 66 | /* External variables and functions referenced. */ |
| 67 | |
| 68 | extern int info_verbose; |
| 69 | |
| 70 | /* Functions this file defines */ |
| 71 | |
| 72 | static void |
| 73 | set_initial_language PARAMS ((void)); |
| 74 | |
| 75 | static void |
| 76 | load_command PARAMS ((char *, int)); |
| 77 | |
| 78 | static void |
| 79 | add_symbol_file_command PARAMS ((char *, int)); |
| 80 | |
| 81 | static void |
| 82 | add_shared_symbol_files_command PARAMS ((char *, int)); |
| 83 | |
| 84 | static void |
| 85 | cashier_psymtab PARAMS ((struct partial_symtab *)); |
| 86 | |
| 87 | static int |
| 88 | compare_psymbols PARAMS ((const void *, const void *)); |
| 89 | |
| 90 | static int |
| 91 | compare_symbols PARAMS ((const void *, const void *)); |
| 92 | |
| 93 | static bfd * |
| 94 | symfile_bfd_open PARAMS ((char *)); |
| 95 | |
| 96 | static void |
| 97 | find_sym_fns PARAMS ((struct objfile *)); |
| 98 | |
| 99 | /* List of all available sym_fns. On gdb startup, each object file reader |
| 100 | calls add_symtab_fns() to register information on each format it is |
| 101 | prepared to read. */ |
| 102 | |
| 103 | static struct sym_fns *symtab_fns = NULL; |
| 104 | |
| 105 | /* Flag for whether user will be reloading symbols multiple times. |
| 106 | Defaults to ON for VxWorks, otherwise OFF. */ |
| 107 | |
| 108 | #ifdef SYMBOL_RELOADING_DEFAULT |
| 109 | int symbol_reloading = SYMBOL_RELOADING_DEFAULT; |
| 110 | #else |
| 111 | int symbol_reloading = 0; |
| 112 | #endif |
| 113 | |
| 114 | /* If true, then shared library symbols will be added automatically |
| 115 | when the inferior is created, new libraries are loaded, or when |
| 116 | attaching to the inferior. This is almost always what users |
| 117 | will want to have happen; but for very large programs, the startup |
| 118 | time will be excessive, and so if this is a problem, the user can |
| 119 | clear this flag and then add the shared library symbols as needed. |
| 120 | Note that there is a potential for confusion, since if the shared |
| 121 | library symbols are not loaded, commands like "info fun" will *not* |
| 122 | report all the functions that are actually present. */ |
| 123 | |
| 124 | int auto_solib_add = 1; |
| 125 | |
| 126 | \f |
| 127 | /* Since this function is called from within qsort, in an ANSI environment |
| 128 | it must conform to the prototype for qsort, which specifies that the |
| 129 | comparison function takes two "void *" pointers. */ |
| 130 | |
| 131 | static int |
| 132 | compare_symbols (s1p, s2p) |
| 133 | const PTR s1p; |
| 134 | const PTR s2p; |
| 135 | { |
| 136 | register struct symbol **s1, **s2; |
| 137 | |
| 138 | s1 = (struct symbol **) s1p; |
| 139 | s2 = (struct symbol **) s2p; |
| 140 | |
| 141 | return (STRCMP (SYMBOL_NAME (*s1), SYMBOL_NAME (*s2))); |
| 142 | } |
| 143 | |
| 144 | /* |
| 145 | |
| 146 | LOCAL FUNCTION |
| 147 | |
| 148 | compare_psymbols -- compare two partial symbols by name |
| 149 | |
| 150 | DESCRIPTION |
| 151 | |
| 152 | Given pointers to pointers to two partial symbol table entries, |
| 153 | compare them by name and return -N, 0, or +N (ala strcmp). |
| 154 | Typically used by sorting routines like qsort(). |
| 155 | |
| 156 | NOTES |
| 157 | |
| 158 | Does direct compare of first two characters before punting |
| 159 | and passing to strcmp for longer compares. Note that the |
| 160 | original version had a bug whereby two null strings or two |
| 161 | identically named one character strings would return the |
| 162 | comparison of memory following the null byte. |
| 163 | |
| 164 | */ |
| 165 | |
| 166 | static int |
| 167 | compare_psymbols (s1p, s2p) |
| 168 | const PTR s1p; |
| 169 | const PTR s2p; |
| 170 | { |
| 171 | register char *st1 = SYMBOL_NAME (*(struct partial_symbol **) s1p); |
| 172 | register char *st2 = SYMBOL_NAME (*(struct partial_symbol **) s2p); |
| 173 | |
| 174 | if ((st1[0] - st2[0]) || !st1[0]) |
| 175 | { |
| 176 | return (st1[0] - st2[0]); |
| 177 | } |
| 178 | else if ((st1[1] - st2[1]) || !st1[1]) |
| 179 | { |
| 180 | return (st1[1] - st2[1]); |
| 181 | } |
| 182 | else |
| 183 | { |
| 184 | return (STRCMP (st1 + 2, st2 + 2)); |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | void |
| 189 | sort_pst_symbols (pst) |
| 190 | struct partial_symtab *pst; |
| 191 | { |
| 192 | /* Sort the global list; don't sort the static list */ |
| 193 | |
| 194 | qsort (pst -> objfile -> global_psymbols.list + pst -> globals_offset, |
| 195 | pst -> n_global_syms, sizeof (struct partial_symbol *), |
| 196 | compare_psymbols); |
| 197 | } |
| 198 | |
| 199 | /* Call sort_block_syms to sort alphabetically the symbols of one block. */ |
| 200 | |
| 201 | void |
| 202 | sort_block_syms (b) |
| 203 | register struct block *b; |
| 204 | { |
| 205 | qsort (&BLOCK_SYM (b, 0), BLOCK_NSYMS (b), |
| 206 | sizeof (struct symbol *), compare_symbols); |
| 207 | } |
| 208 | |
| 209 | /* Call sort_symtab_syms to sort alphabetically |
| 210 | the symbols of each block of one symtab. */ |
| 211 | |
| 212 | void |
| 213 | sort_symtab_syms (s) |
| 214 | register struct symtab *s; |
| 215 | { |
| 216 | register struct blockvector *bv; |
| 217 | int nbl; |
| 218 | int i; |
| 219 | register struct block *b; |
| 220 | |
| 221 | if (s == 0) |
| 222 | return; |
| 223 | bv = BLOCKVECTOR (s); |
| 224 | nbl = BLOCKVECTOR_NBLOCKS (bv); |
| 225 | for (i = 0; i < nbl; i++) |
| 226 | { |
| 227 | b = BLOCKVECTOR_BLOCK (bv, i); |
| 228 | if (BLOCK_SHOULD_SORT (b)) |
| 229 | sort_block_syms (b); |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | /* Make a copy of the string at PTR with SIZE characters in the symbol obstack |
| 234 | (and add a null character at the end in the copy). |
| 235 | Returns the address of the copy. */ |
| 236 | |
| 237 | char * |
| 238 | obsavestring (ptr, size, obstackp) |
| 239 | char *ptr; |
| 240 | int size; |
| 241 | struct obstack *obstackp; |
| 242 | { |
| 243 | register char *p = (char *) obstack_alloc (obstackp, size + 1); |
| 244 | /* Open-coded memcpy--saves function call time. |
| 245 | These strings are usually short. */ |
| 246 | { |
| 247 | register char *p1 = ptr; |
| 248 | register char *p2 = p; |
| 249 | char *end = ptr + size; |
| 250 | while (p1 != end) |
| 251 | *p2++ = *p1++; |
| 252 | } |
| 253 | p[size] = 0; |
| 254 | return p; |
| 255 | } |
| 256 | |
| 257 | /* Concatenate strings S1, S2 and S3; return the new string. |
| 258 | Space is found in the symbol_obstack. */ |
| 259 | |
| 260 | char * |
| 261 | obconcat (obstackp, s1, s2, s3) |
| 262 | struct obstack *obstackp; |
| 263 | const char *s1, *s2, *s3; |
| 264 | { |
| 265 | register int len = strlen (s1) + strlen (s2) + strlen (s3) + 1; |
| 266 | register char *val = (char *) obstack_alloc (obstackp, len); |
| 267 | strcpy (val, s1); |
| 268 | strcat (val, s2); |
| 269 | strcat (val, s3); |
| 270 | return val; |
| 271 | } |
| 272 | |
| 273 | /* True if we are nested inside psymtab_to_symtab. */ |
| 274 | |
| 275 | int currently_reading_symtab = 0; |
| 276 | |
| 277 | static void |
| 278 | decrement_reading_symtab (dummy) |
| 279 | void *dummy; |
| 280 | { |
| 281 | currently_reading_symtab--; |
| 282 | } |
| 283 | |
| 284 | /* Get the symbol table that corresponds to a partial_symtab. |
| 285 | This is fast after the first time you do it. In fact, there |
| 286 | is an even faster macro PSYMTAB_TO_SYMTAB that does the fast |
| 287 | case inline. */ |
| 288 | |
| 289 | struct symtab * |
| 290 | psymtab_to_symtab (pst) |
| 291 | register struct partial_symtab *pst; |
| 292 | { |
| 293 | /* If it's been looked up before, return it. */ |
| 294 | if (pst->symtab) |
| 295 | return pst->symtab; |
| 296 | |
| 297 | /* If it has not yet been read in, read it. */ |
| 298 | if (!pst->readin) |
| 299 | { |
| 300 | struct cleanup *back_to = make_cleanup (decrement_reading_symtab, NULL); |
| 301 | currently_reading_symtab++; |
| 302 | (*pst->read_symtab) (pst); |
| 303 | do_cleanups (back_to); |
| 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 | objfile -> ei.entry_point = INVALID_ENTRY_POINT; |
| 328 | } |
| 329 | objfile -> ei.entry_file_lowpc = INVALID_ENTRY_LOWPC; |
| 330 | objfile -> ei.entry_file_highpc = INVALID_ENTRY_HIGHPC; |
| 331 | objfile -> ei.entry_func_lowpc = INVALID_ENTRY_LOWPC; |
| 332 | objfile -> ei.entry_func_highpc = INVALID_ENTRY_HIGHPC; |
| 333 | objfile -> ei.main_func_lowpc = INVALID_ENTRY_LOWPC; |
| 334 | objfile -> ei.main_func_highpc = INVALID_ENTRY_HIGHPC; |
| 335 | } |
| 336 | |
| 337 | /* Get current entry point address. */ |
| 338 | |
| 339 | CORE_ADDR |
| 340 | entry_point_address() |
| 341 | { |
| 342 | return symfile_objfile ? symfile_objfile->ei.entry_point : 0; |
| 343 | } |
| 344 | |
| 345 | /* Remember the lowest-addressed loadable section we've seen. |
| 346 | This function is called via bfd_map_over_sections. |
| 347 | |
| 348 | In case of equal vmas, the section with the largest size becomes the |
| 349 | lowest-addressed loadable section. |
| 350 | |
| 351 | If the vmas and sizes are equal, the last section is considered the |
| 352 | lowest-addressed loadable section. */ |
| 353 | |
| 354 | void |
| 355 | find_lowest_section (abfd, sect, obj) |
| 356 | bfd *abfd; |
| 357 | asection *sect; |
| 358 | PTR obj; |
| 359 | { |
| 360 | asection **lowest = (asection **)obj; |
| 361 | |
| 362 | if (0 == (bfd_get_section_flags (abfd, sect) & SEC_LOAD)) |
| 363 | return; |
| 364 | if (!*lowest) |
| 365 | *lowest = sect; /* First loadable section */ |
| 366 | else if (bfd_section_vma (abfd, *lowest) > bfd_section_vma (abfd, sect)) |
| 367 | *lowest = sect; /* A lower loadable section */ |
| 368 | else if (bfd_section_vma (abfd, *lowest) == bfd_section_vma (abfd, sect) |
| 369 | && (bfd_section_size (abfd, (*lowest)) |
| 370 | <= bfd_section_size (abfd, sect))) |
| 371 | *lowest = sect; |
| 372 | } |
| 373 | |
| 374 | /* Process a symbol file, as either the main file or as a dynamically |
| 375 | loaded file. |
| 376 | |
| 377 | NAME is the file name (which will be tilde-expanded and made |
| 378 | absolute herein) (but we don't free or modify NAME itself). |
| 379 | FROM_TTY says how verbose to be. MAINLINE specifies whether this |
| 380 | is the main symbol file, or whether it's an extra symbol file such |
| 381 | as dynamically loaded code. If !mainline, ADDR is the address |
| 382 | where the text segment was loaded. If VERBO, the caller has printed |
| 383 | a verbose message about the symbol reading (and complaints can be |
| 384 | more terse about it). */ |
| 385 | |
| 386 | void |
| 387 | syms_from_objfile (objfile, addr, mainline, verbo) |
| 388 | struct objfile *objfile; |
| 389 | CORE_ADDR addr; |
| 390 | int mainline; |
| 391 | int verbo; |
| 392 | { |
| 393 | struct section_offsets *section_offsets; |
| 394 | asection *lowest_sect; |
| 395 | struct cleanup *old_chain; |
| 396 | |
| 397 | init_entry_point_info (objfile); |
| 398 | find_sym_fns (objfile); |
| 399 | |
| 400 | /* Make sure that partially constructed symbol tables will be cleaned up |
| 401 | if an error occurs during symbol reading. */ |
| 402 | old_chain = make_cleanup (free_objfile, objfile); |
| 403 | |
| 404 | if (mainline) |
| 405 | { |
| 406 | /* We will modify the main symbol table, make sure that all its users |
| 407 | will be cleaned up if an error occurs during symbol reading. */ |
| 408 | make_cleanup (clear_symtab_users, 0); |
| 409 | |
| 410 | /* Since no error yet, throw away the old symbol table. */ |
| 411 | |
| 412 | if (symfile_objfile != NULL) |
| 413 | { |
| 414 | free_objfile (symfile_objfile); |
| 415 | symfile_objfile = NULL; |
| 416 | } |
| 417 | |
| 418 | /* Currently we keep symbols from the add-symbol-file command. |
| 419 | If the user wants to get rid of them, they should do "symbol-file" |
| 420 | without arguments first. Not sure this is the best behavior |
| 421 | (PR 2207). */ |
| 422 | |
| 423 | (*objfile -> sf -> sym_new_init) (objfile); |
| 424 | } |
| 425 | |
| 426 | /* Convert addr into an offset rather than an absolute address. |
| 427 | We find the lowest address of a loaded segment in the objfile, |
| 428 | and assume that <addr> is where that got loaded. Due to historical |
| 429 | precedent, we warn if that doesn't happen to be a text segment. */ |
| 430 | |
| 431 | if (mainline) |
| 432 | { |
| 433 | addr = 0; /* No offset from objfile addresses. */ |
| 434 | } |
| 435 | else |
| 436 | { |
| 437 | lowest_sect = bfd_get_section_by_name (objfile->obfd, ".text"); |
| 438 | if (lowest_sect == NULL) |
| 439 | bfd_map_over_sections (objfile->obfd, find_lowest_section, |
| 440 | (PTR) &lowest_sect); |
| 441 | |
| 442 | if (lowest_sect == NULL) |
| 443 | warning ("no loadable sections found in added symbol-file %s", |
| 444 | objfile->name); |
| 445 | else if ((bfd_get_section_flags (objfile->obfd, lowest_sect) & SEC_CODE) |
| 446 | == 0) |
| 447 | /* FIXME-32x64--assumes bfd_vma fits in long. */ |
| 448 | warning ("Lowest section in %s is %s at 0x%lx", |
| 449 | objfile->name, |
| 450 | bfd_section_name (objfile->obfd, lowest_sect), |
| 451 | (unsigned long) bfd_section_vma (objfile->obfd, lowest_sect)); |
| 452 | |
| 453 | if (lowest_sect) |
| 454 | addr -= bfd_section_vma (objfile->obfd, lowest_sect); |
| 455 | } |
| 456 | |
| 457 | /* Initialize symbol reading routines for this objfile, allow complaints to |
| 458 | appear for this new file, and record how verbose to be, then do the |
| 459 | initial symbol reading for this file. */ |
| 460 | |
| 461 | (*objfile -> sf -> sym_init) (objfile); |
| 462 | clear_complaints (1, verbo); |
| 463 | |
| 464 | section_offsets = (*objfile -> sf -> sym_offsets) (objfile, addr); |
| 465 | objfile->section_offsets = section_offsets; |
| 466 | |
| 467 | #ifndef IBM6000_TARGET |
| 468 | /* This is a SVR4/SunOS specific hack, I think. In any event, it |
| 469 | screws RS/6000. sym_offsets should be doing this sort of thing, |
| 470 | because it knows the mapping between bfd sections and |
| 471 | section_offsets. */ |
| 472 | /* This is a hack. As far as I can tell, section offsets are not |
| 473 | target dependent. They are all set to addr with a couple of |
| 474 | exceptions. The exceptions are sysvr4 shared libraries, whose |
| 475 | offsets are kept in solib structures anyway and rs6000 xcoff |
| 476 | which handles shared libraries in a completely unique way. |
| 477 | |
| 478 | Section offsets are built similarly, except that they are built |
| 479 | by adding addr in all cases because there is no clear mapping |
| 480 | from section_offsets into actual sections. Note that solib.c |
| 481 | has a different algorythm for finding section offsets. |
| 482 | |
| 483 | These should probably all be collapsed into some target |
| 484 | independent form of shared library support. FIXME. */ |
| 485 | |
| 486 | if (addr) |
| 487 | { |
| 488 | struct obj_section *s; |
| 489 | |
| 490 | for (s = objfile->sections; s < objfile->sections_end; ++s) |
| 491 | { |
| 492 | s->addr -= s->offset; |
| 493 | s->addr += addr; |
| 494 | s->endaddr -= s->offset; |
| 495 | s->endaddr += addr; |
| 496 | s->offset += addr; |
| 497 | } |
| 498 | } |
| 499 | #endif /* not IBM6000_TARGET */ |
| 500 | |
| 501 | (*objfile -> sf -> sym_read) (objfile, section_offsets, mainline); |
| 502 | |
| 503 | if (!have_partial_symbols () && !have_full_symbols ()) |
| 504 | { |
| 505 | wrap_here (""); |
| 506 | printf_filtered ("(no debugging symbols found)..."); |
| 507 | wrap_here (""); |
| 508 | } |
| 509 | |
| 510 | /* Don't allow char * to have a typename (else would get caddr_t). |
| 511 | Ditto void *. FIXME: Check whether this is now done by all the |
| 512 | symbol readers themselves (many of them now do), and if so remove |
| 513 | it from here. */ |
| 514 | |
| 515 | TYPE_NAME (lookup_pointer_type (builtin_type_char)) = 0; |
| 516 | TYPE_NAME (lookup_pointer_type (builtin_type_void)) = 0; |
| 517 | |
| 518 | /* Mark the objfile has having had initial symbol read attempted. Note |
| 519 | that this does not mean we found any symbols... */ |
| 520 | |
| 521 | objfile -> flags |= OBJF_SYMS; |
| 522 | |
| 523 | /* Discard cleanups as symbol reading was successful. */ |
| 524 | |
| 525 | discard_cleanups (old_chain); |
| 526 | |
| 527 | /* Call this after reading in a new symbol table to give target dependant code |
| 528 | a crack at the new symbols. For instance, this could be used to update the |
| 529 | values of target-specific symbols GDB needs to keep track of (such as |
| 530 | _sigtramp, or whatever). */ |
| 531 | |
| 532 | TARGET_SYMFILE_POSTREAD (objfile); |
| 533 | } |
| 534 | |
| 535 | /* Perform required actions after either reading in the initial |
| 536 | symbols for a new objfile, or mapping in the symbols from a reusable |
| 537 | objfile. */ |
| 538 | |
| 539 | void |
| 540 | new_symfile_objfile (objfile, mainline, verbo) |
| 541 | struct objfile *objfile; |
| 542 | int mainline; |
| 543 | int verbo; |
| 544 | { |
| 545 | |
| 546 | /* If this is the main symbol file we have to clean up all users of the |
| 547 | old main symbol file. Otherwise it is sufficient to fixup all the |
| 548 | breakpoints that may have been redefined by this symbol file. */ |
| 549 | if (mainline) |
| 550 | { |
| 551 | /* OK, make it the "real" symbol file. */ |
| 552 | symfile_objfile = objfile; |
| 553 | |
| 554 | clear_symtab_users (); |
| 555 | } |
| 556 | else |
| 557 | { |
| 558 | breakpoint_re_set (); |
| 559 | } |
| 560 | |
| 561 | /* We're done reading the symbol file; finish off complaints. */ |
| 562 | clear_complaints (0, verbo); |
| 563 | } |
| 564 | |
| 565 | /* Process a symbol file, as either the main file or as a dynamically |
| 566 | loaded file. |
| 567 | |
| 568 | NAME is the file name (which will be tilde-expanded and made |
| 569 | absolute herein) (but we don't free or modify NAME itself). |
| 570 | FROM_TTY says how verbose to be. MAINLINE specifies whether this |
| 571 | is the main symbol file, or whether it's an extra symbol file such |
| 572 | as dynamically loaded code. If !mainline, ADDR is the address |
| 573 | where the text segment was loaded. |
| 574 | |
| 575 | Upon success, returns a pointer to the objfile that was added. |
| 576 | Upon failure, jumps back to command level (never returns). */ |
| 577 | |
| 578 | struct objfile * |
| 579 | symbol_file_add (name, from_tty, addr, mainline, mapped, readnow) |
| 580 | char *name; |
| 581 | int from_tty; |
| 582 | CORE_ADDR addr; |
| 583 | int mainline; |
| 584 | int mapped; |
| 585 | int readnow; |
| 586 | { |
| 587 | struct objfile *objfile; |
| 588 | struct partial_symtab *psymtab; |
| 589 | bfd *abfd; |
| 590 | |
| 591 | /* Open a bfd for the file, and give user a chance to burp if we'd be |
| 592 | interactively wiping out any existing symbols. */ |
| 593 | |
| 594 | abfd = symfile_bfd_open (name); |
| 595 | |
| 596 | if ((have_full_symbols () || have_partial_symbols ()) |
| 597 | && mainline |
| 598 | && from_tty |
| 599 | && !query ("Load new symbol table from \"%s\"? ", name)) |
| 600 | error ("Not confirmed."); |
| 601 | |
| 602 | objfile = allocate_objfile (abfd, mapped); |
| 603 | |
| 604 | /* If the objfile uses a mapped symbol file, and we have a psymtab for |
| 605 | it, then skip reading any symbols at this time. */ |
| 606 | |
| 607 | if ((objfile -> flags & OBJF_MAPPED) && (objfile -> flags & OBJF_SYMS)) |
| 608 | { |
| 609 | /* We mapped in an existing symbol table file that already has had |
| 610 | initial symbol reading performed, so we can skip that part. Notify |
| 611 | the user that instead of reading the symbols, they have been mapped. |
| 612 | */ |
| 613 | if (from_tty || info_verbose) |
| 614 | { |
| 615 | printf_filtered ("Mapped symbols for %s...", name); |
| 616 | wrap_here (""); |
| 617 | gdb_flush (gdb_stdout); |
| 618 | } |
| 619 | init_entry_point_info (objfile); |
| 620 | find_sym_fns (objfile); |
| 621 | } |
| 622 | else |
| 623 | { |
| 624 | /* We either created a new mapped symbol table, mapped an existing |
| 625 | symbol table file which has not had initial symbol reading |
| 626 | performed, or need to read an unmapped symbol table. */ |
| 627 | if (from_tty || info_verbose) |
| 628 | { |
| 629 | printf_filtered ("Reading symbols from %s...", name); |
| 630 | wrap_here (""); |
| 631 | gdb_flush (gdb_stdout); |
| 632 | } |
| 633 | syms_from_objfile (objfile, addr, mainline, from_tty); |
| 634 | } |
| 635 | |
| 636 | /* We now have at least a partial symbol table. Check to see if the |
| 637 | user requested that all symbols be read on initial access via either |
| 638 | the gdb startup command line or on a per symbol file basis. Expand |
| 639 | all partial symbol tables for this objfile if so. */ |
| 640 | |
| 641 | if (readnow || readnow_symbol_files) |
| 642 | { |
| 643 | if (from_tty || info_verbose) |
| 644 | { |
| 645 | printf_filtered ("expanding to full symbols..."); |
| 646 | wrap_here (""); |
| 647 | gdb_flush (gdb_stdout); |
| 648 | } |
| 649 | |
| 650 | for (psymtab = objfile -> psymtabs; |
| 651 | psymtab != NULL; |
| 652 | psymtab = psymtab -> next) |
| 653 | { |
| 654 | psymtab_to_symtab (psymtab); |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | if (from_tty || info_verbose) |
| 659 | { |
| 660 | printf_filtered ("done.\n"); |
| 661 | gdb_flush (gdb_stdout); |
| 662 | } |
| 663 | |
| 664 | new_symfile_objfile (objfile, mainline, from_tty); |
| 665 | |
| 666 | return (objfile); |
| 667 | } |
| 668 | |
| 669 | /* This is the symbol-file command. Read the file, analyze its |
| 670 | symbols, and add a struct symtab to a symtab list. The syntax of |
| 671 | the command is rather bizarre--(1) buildargv implements various |
| 672 | quoting conventions which are undocumented and have little or |
| 673 | nothing in common with the way things are quoted (or not quoted) |
| 674 | elsewhere in GDB, (2) options are used, which are not generally |
| 675 | used in GDB (perhaps "set mapped on", "set readnow on" would be |
| 676 | better), (3) the order of options matters, which is contrary to GNU |
| 677 | conventions (because it is confusing and inconvenient). */ |
| 678 | |
| 679 | void |
| 680 | symbol_file_command (args, from_tty) |
| 681 | char *args; |
| 682 | int from_tty; |
| 683 | { |
| 684 | char **argv; |
| 685 | char *name = NULL; |
| 686 | CORE_ADDR text_relocation = 0; /* text_relocation */ |
| 687 | struct cleanup *cleanups; |
| 688 | int mapped = 0; |
| 689 | int readnow = 0; |
| 690 | |
| 691 | dont_repeat (); |
| 692 | |
| 693 | if (args == NULL) |
| 694 | { |
| 695 | if ((have_full_symbols () || have_partial_symbols ()) |
| 696 | && from_tty |
| 697 | && !query ("Discard symbol table from `%s'? ", |
| 698 | symfile_objfile -> name)) |
| 699 | error ("Not confirmed."); |
| 700 | free_all_objfiles (); |
| 701 | symfile_objfile = NULL; |
| 702 | if (from_tty) |
| 703 | { |
| 704 | printf_unfiltered ("No symbol file now.\n"); |
| 705 | } |
| 706 | } |
| 707 | else |
| 708 | { |
| 709 | if ((argv = buildargv (args)) == NULL) |
| 710 | { |
| 711 | nomem (0); |
| 712 | } |
| 713 | cleanups = make_cleanup (freeargv, (char *) argv); |
| 714 | while (*argv != NULL) |
| 715 | { |
| 716 | if (STREQ (*argv, "-mapped")) |
| 717 | { |
| 718 | mapped = 1; |
| 719 | } |
| 720 | else if (STREQ (*argv, "-readnow")) |
| 721 | { |
| 722 | readnow = 1; |
| 723 | } |
| 724 | else if (**argv == '-') |
| 725 | { |
| 726 | error ("unknown option `%s'", *argv); |
| 727 | } |
| 728 | else |
| 729 | { |
| 730 | char *p; |
| 731 | |
| 732 | name = *argv; |
| 733 | |
| 734 | /* this is for rombug remote only, to get the text relocation by |
| 735 | using link command */ |
| 736 | p = strrchr(name, '/'); |
| 737 | if (p != NULL) p++; |
| 738 | else p = name; |
| 739 | |
| 740 | target_link(p, &text_relocation); |
| 741 | |
| 742 | if (text_relocation == (CORE_ADDR)0) |
| 743 | return; |
| 744 | else if (text_relocation == (CORE_ADDR)-1) |
| 745 | symbol_file_add (name, from_tty, (CORE_ADDR)0, 1, mapped, |
| 746 | readnow); |
| 747 | else |
| 748 | symbol_file_add (name, from_tty, (CORE_ADDR)text_relocation, |
| 749 | 0, mapped, readnow); |
| 750 | |
| 751 | /* Getting new symbols may change our opinion about what is |
| 752 | frameless. */ |
| 753 | reinit_frame_cache (); |
| 754 | |
| 755 | set_initial_language (); |
| 756 | } |
| 757 | argv++; |
| 758 | } |
| 759 | |
| 760 | if (name == NULL) |
| 761 | { |
| 762 | error ("no symbol file name was specified"); |
| 763 | } |
| 764 | do_cleanups (cleanups); |
| 765 | } |
| 766 | } |
| 767 | |
| 768 | /* Set the initial language. |
| 769 | |
| 770 | A better solution would be to record the language in the psymtab when reading |
| 771 | partial symbols, and then use it (if known) to set the language. This would |
| 772 | be a win for formats that encode the language in an easily discoverable place, |
| 773 | such as DWARF. For stabs, we can jump through hoops looking for specially |
| 774 | named symbols or try to intuit the language from the specific type of stabs |
| 775 | we find, but we can't do that until later when we read in full symbols. |
| 776 | FIXME. */ |
| 777 | |
| 778 | static void |
| 779 | set_initial_language () |
| 780 | { |
| 781 | struct partial_symtab *pst; |
| 782 | enum language lang = language_unknown; |
| 783 | |
| 784 | pst = find_main_psymtab (); |
| 785 | if (pst != NULL) |
| 786 | { |
| 787 | if (pst -> filename != NULL) |
| 788 | { |
| 789 | lang = deduce_language_from_filename (pst -> filename); |
| 790 | } |
| 791 | if (lang == language_unknown) |
| 792 | { |
| 793 | /* Make C the default language */ |
| 794 | lang = language_c; |
| 795 | } |
| 796 | set_language (lang); |
| 797 | expected_language = current_language; /* Don't warn the user */ |
| 798 | } |
| 799 | } |
| 800 | |
| 801 | /* Open file specified by NAME and hand it off to BFD for preliminary |
| 802 | analysis. Result is a newly initialized bfd *, which includes a newly |
| 803 | malloc'd` copy of NAME (tilde-expanded and made absolute). |
| 804 | In case of trouble, error() is called. */ |
| 805 | |
| 806 | static bfd * |
| 807 | symfile_bfd_open (name) |
| 808 | char *name; |
| 809 | { |
| 810 | bfd *sym_bfd; |
| 811 | int desc; |
| 812 | char *absolute_name; |
| 813 | |
| 814 | name = tilde_expand (name); /* Returns 1st new malloc'd copy */ |
| 815 | |
| 816 | /* Look down path for it, allocate 2nd new malloc'd copy. */ |
| 817 | desc = openp (getenv ("PATH"), 1, name, O_RDONLY | O_BINARY, 0, &absolute_name); |
| 818 | if (desc < 0) |
| 819 | { |
| 820 | make_cleanup (free, name); |
| 821 | perror_with_name (name); |
| 822 | } |
| 823 | free (name); /* Free 1st new malloc'd copy */ |
| 824 | name = absolute_name; /* Keep 2nd malloc'd copy in bfd */ |
| 825 | /* It'll be freed in free_objfile(). */ |
| 826 | |
| 827 | sym_bfd = bfd_fdopenr (name, gnutarget, desc); |
| 828 | if (!sym_bfd) |
| 829 | { |
| 830 | close (desc); |
| 831 | make_cleanup (free, name); |
| 832 | error ("\"%s\": can't open to read symbols: %s.", name, |
| 833 | bfd_errmsg (bfd_get_error ())); |
| 834 | } |
| 835 | sym_bfd->cacheable = true; |
| 836 | |
| 837 | if (!bfd_check_format (sym_bfd, bfd_object)) |
| 838 | { |
| 839 | /* FIXME: should be checking for errors from bfd_close (for one thing, |
| 840 | on error it does not free all the storage associated with the |
| 841 | bfd). */ |
| 842 | bfd_close (sym_bfd); /* This also closes desc */ |
| 843 | make_cleanup (free, name); |
| 844 | error ("\"%s\": can't read symbols: %s.", name, |
| 845 | bfd_errmsg (bfd_get_error ())); |
| 846 | } |
| 847 | |
| 848 | return (sym_bfd); |
| 849 | } |
| 850 | |
| 851 | /* Link a new symtab_fns into the global symtab_fns list. Called on gdb |
| 852 | startup by the _initialize routine in each object file format reader, |
| 853 | to register information about each format the the reader is prepared |
| 854 | to handle. */ |
| 855 | |
| 856 | void |
| 857 | add_symtab_fns (sf) |
| 858 | struct sym_fns *sf; |
| 859 | { |
| 860 | sf->next = symtab_fns; |
| 861 | symtab_fns = sf; |
| 862 | } |
| 863 | |
| 864 | |
| 865 | /* Initialize to read symbols from the symbol file sym_bfd. It either |
| 866 | returns or calls error(). The result is an initialized struct sym_fns |
| 867 | in the objfile structure, that contains cached information about the |
| 868 | symbol file. */ |
| 869 | |
| 870 | static void |
| 871 | find_sym_fns (objfile) |
| 872 | struct objfile *objfile; |
| 873 | { |
| 874 | struct sym_fns *sf; |
| 875 | enum bfd_flavour our_flavour = bfd_get_flavour (objfile -> obfd); |
| 876 | char *our_target = bfd_get_target (objfile -> obfd); |
| 877 | |
| 878 | /* Special kludge for RS/6000 and PowerMac. See xcoffread.c. */ |
| 879 | if (STREQ (our_target, "aixcoff-rs6000") || |
| 880 | STREQ (our_target, "xcoff-powermac")) |
| 881 | our_flavour = (enum bfd_flavour)-1; |
| 882 | |
| 883 | /* Special kludge for apollo. See dstread.c. */ |
| 884 | if (STREQN (our_target, "apollo", 6)) |
| 885 | our_flavour = (enum bfd_flavour)-2; |
| 886 | |
| 887 | for (sf = symtab_fns; sf != NULL; sf = sf -> next) |
| 888 | { |
| 889 | if (our_flavour == sf -> sym_flavour) |
| 890 | { |
| 891 | objfile -> sf = sf; |
| 892 | return; |
| 893 | } |
| 894 | } |
| 895 | error ("I'm sorry, Dave, I can't do that. Symbol format `%s' unknown.", |
| 896 | bfd_get_target (objfile -> obfd)); |
| 897 | } |
| 898 | \f |
| 899 | /* This function runs the load command of our current target. */ |
| 900 | |
| 901 | static void |
| 902 | load_command (arg, from_tty) |
| 903 | char *arg; |
| 904 | int from_tty; |
| 905 | { |
| 906 | if (arg == NULL) |
| 907 | arg = get_exec_file (1); |
| 908 | target_load (arg, from_tty); |
| 909 | } |
| 910 | |
| 911 | /* This version of "load" should be usable for any target. Currently |
| 912 | it is just used for remote targets, not inftarg.c or core files, |
| 913 | on the theory that only in that case is it useful. |
| 914 | |
| 915 | Avoiding xmodem and the like seems like a win (a) because we don't have |
| 916 | to worry about finding it, and (b) On VMS, fork() is very slow and so |
| 917 | we don't want to run a subprocess. On the other hand, I'm not sure how |
| 918 | performance compares. */ |
| 919 | void |
| 920 | generic_load (filename, from_tty) |
| 921 | char *filename; |
| 922 | int from_tty; |
| 923 | { |
| 924 | struct cleanup *old_cleanups; |
| 925 | asection *s; |
| 926 | bfd *loadfile_bfd; |
| 927 | time_t start_time, end_time; /* Start and end times of download */ |
| 928 | unsigned long data_count; /* Number of bytes transferred to memory */ |
| 929 | |
| 930 | loadfile_bfd = bfd_openr (filename, gnutarget); |
| 931 | if (loadfile_bfd == NULL) |
| 932 | { |
| 933 | perror_with_name (filename); |
| 934 | return; |
| 935 | } |
| 936 | /* FIXME: should be checking for errors from bfd_close (for one thing, |
| 937 | on error it does not free all the storage associated with the |
| 938 | bfd). */ |
| 939 | old_cleanups = make_cleanup (bfd_close, loadfile_bfd); |
| 940 | |
| 941 | if (!bfd_check_format (loadfile_bfd, bfd_object)) |
| 942 | { |
| 943 | error ("\"%s\" is not an object file: %s", filename, |
| 944 | bfd_errmsg (bfd_get_error ())); |
| 945 | } |
| 946 | |
| 947 | start_time = time (NULL); |
| 948 | |
| 949 | for (s = loadfile_bfd->sections; s; s = s->next) |
| 950 | { |
| 951 | if (s->flags & SEC_LOAD) |
| 952 | { |
| 953 | bfd_size_type size; |
| 954 | |
| 955 | size = bfd_get_section_size_before_reloc (s); |
| 956 | if (size > 0) |
| 957 | { |
| 958 | char *buffer; |
| 959 | struct cleanup *old_chain; |
| 960 | bfd_vma vma; |
| 961 | |
| 962 | data_count += size; |
| 963 | |
| 964 | buffer = xmalloc (size); |
| 965 | old_chain = make_cleanup (free, buffer); |
| 966 | |
| 967 | vma = bfd_get_section_vma (loadfile_bfd, s); |
| 968 | |
| 969 | /* Is this really necessary? I guess it gives the user something |
| 970 | to look at during a long download. */ |
| 971 | printf_filtered ("Loading section %s, size 0x%lx vma ", |
| 972 | bfd_get_section_name (loadfile_bfd, s), |
| 973 | (unsigned long) size); |
| 974 | print_address_numeric (vma, 1, gdb_stdout); |
| 975 | printf_filtered ("\n"); |
| 976 | |
| 977 | bfd_get_section_contents (loadfile_bfd, s, buffer, 0, size); |
| 978 | |
| 979 | target_write_memory (vma, buffer, size); |
| 980 | |
| 981 | do_cleanups (old_chain); |
| 982 | } |
| 983 | } |
| 984 | } |
| 985 | |
| 986 | end_time = time (NULL); |
| 987 | |
| 988 | /* We were doing this in remote-mips.c, I suspect it is right |
| 989 | for other targets too. */ |
| 990 | write_pc (loadfile_bfd->start_address); |
| 991 | |
| 992 | /* FIXME: are we supposed to call symbol_file_add or not? According to |
| 993 | a comment from remote-mips.c (where a call to symbol_file_add was |
| 994 | commented out), making the call confuses GDB if more than one file is |
| 995 | loaded in. remote-nindy.c had no call to symbol_file_add, but remote-vx.c |
| 996 | does. */ |
| 997 | |
| 998 | if (end_time != start_time) |
| 999 | printf_filtered ("Transfer rate: %d bits/sec.\n", |
| 1000 | (data_count * 8)/(end_time - start_time)); |
| 1001 | |
| 1002 | do_cleanups (old_cleanups); |
| 1003 | } |
| 1004 | |
| 1005 | /* This function allows the addition of incrementally linked object files. |
| 1006 | It does not modify any state in the target, only in the debugger. */ |
| 1007 | |
| 1008 | /* ARGSUSED */ |
| 1009 | static void |
| 1010 | add_symbol_file_command (args, from_tty) |
| 1011 | char *args; |
| 1012 | int from_tty; |
| 1013 | { |
| 1014 | char *name = NULL; |
| 1015 | CORE_ADDR text_addr; |
| 1016 | char *arg; |
| 1017 | int readnow = 0; |
| 1018 | int mapped = 0; |
| 1019 | |
| 1020 | dont_repeat (); |
| 1021 | |
| 1022 | if (args == NULL) |
| 1023 | { |
| 1024 | error ("add-symbol-file takes a file name and an address"); |
| 1025 | } |
| 1026 | |
| 1027 | /* Make a copy of the string that we can safely write into. */ |
| 1028 | |
| 1029 | args = strdup (args); |
| 1030 | make_cleanup (free, args); |
| 1031 | |
| 1032 | /* Pick off any -option args and the file name. */ |
| 1033 | |
| 1034 | while ((*args != '\000') && (name == NULL)) |
| 1035 | { |
| 1036 | while (isspace (*args)) {args++;} |
| 1037 | arg = args; |
| 1038 | while ((*args != '\000') && !isspace (*args)) {args++;} |
| 1039 | if (*args != '\000') |
| 1040 | { |
| 1041 | *args++ = '\000'; |
| 1042 | } |
| 1043 | if (*arg != '-') |
| 1044 | { |
| 1045 | name = arg; |
| 1046 | } |
| 1047 | else if (STREQ (arg, "-mapped")) |
| 1048 | { |
| 1049 | mapped = 1; |
| 1050 | } |
| 1051 | else if (STREQ (arg, "-readnow")) |
| 1052 | { |
| 1053 | readnow = 1; |
| 1054 | } |
| 1055 | else |
| 1056 | { |
| 1057 | error ("unknown option `%s'", arg); |
| 1058 | } |
| 1059 | } |
| 1060 | |
| 1061 | /* After picking off any options and the file name, args should be |
| 1062 | left pointing at the remainder of the command line, which should |
| 1063 | be the address expression to evaluate. */ |
| 1064 | |
| 1065 | if (name == NULL) |
| 1066 | { |
| 1067 | error ("add-symbol-file takes a file name"); |
| 1068 | } |
| 1069 | name = tilde_expand (name); |
| 1070 | make_cleanup (free, name); |
| 1071 | |
| 1072 | if (*args != '\000') |
| 1073 | { |
| 1074 | text_addr = parse_and_eval_address (args); |
| 1075 | } |
| 1076 | else |
| 1077 | { |
| 1078 | target_link(name, &text_addr); |
| 1079 | if (text_addr == (CORE_ADDR)-1) |
| 1080 | error("Don't know how to get text start location for this file"); |
| 1081 | } |
| 1082 | |
| 1083 | /* FIXME-32x64: Assumes text_addr fits in a long. */ |
| 1084 | if (!query ("add symbol table from file \"%s\" at text_addr = %s?\n", |
| 1085 | name, local_hex_string ((unsigned long)text_addr))) |
| 1086 | error ("Not confirmed."); |
| 1087 | |
| 1088 | symbol_file_add (name, 0, text_addr, 0, mapped, readnow); |
| 1089 | |
| 1090 | /* Getting new symbols may change our opinion about what is |
| 1091 | frameless. */ |
| 1092 | reinit_frame_cache (); |
| 1093 | } |
| 1094 | \f |
| 1095 | static void |
| 1096 | add_shared_symbol_files_command (args, from_tty) |
| 1097 | char *args; |
| 1098 | int from_tty; |
| 1099 | { |
| 1100 | #ifdef ADD_SHARED_SYMBOL_FILES |
| 1101 | ADD_SHARED_SYMBOL_FILES (args, from_tty); |
| 1102 | #else |
| 1103 | error ("This command is not available in this configuration of GDB."); |
| 1104 | #endif |
| 1105 | } |
| 1106 | \f |
| 1107 | /* Re-read symbols if a symbol-file has changed. */ |
| 1108 | void |
| 1109 | reread_symbols () |
| 1110 | { |
| 1111 | struct objfile *objfile; |
| 1112 | long new_modtime; |
| 1113 | int reread_one = 0; |
| 1114 | struct stat new_statbuf; |
| 1115 | int res; |
| 1116 | |
| 1117 | /* With the addition of shared libraries, this should be modified, |
| 1118 | the load time should be saved in the partial symbol tables, since |
| 1119 | different tables may come from different source files. FIXME. |
| 1120 | This routine should then walk down each partial symbol table |
| 1121 | and see if the symbol table that it originates from has been changed */ |
| 1122 | |
| 1123 | for (objfile = object_files; objfile; objfile = objfile->next) { |
| 1124 | if (objfile->obfd) { |
| 1125 | #ifdef IBM6000_TARGET |
| 1126 | /* If this object is from a shared library, then you should |
| 1127 | stat on the library name, not member name. */ |
| 1128 | |
| 1129 | if (objfile->obfd->my_archive) |
| 1130 | res = stat (objfile->obfd->my_archive->filename, &new_statbuf); |
| 1131 | else |
| 1132 | #endif |
| 1133 | res = stat (objfile->name, &new_statbuf); |
| 1134 | if (res != 0) { |
| 1135 | /* FIXME, should use print_sys_errmsg but it's not filtered. */ |
| 1136 | printf_filtered ("`%s' has disappeared; keeping its symbols.\n", |
| 1137 | objfile->name); |
| 1138 | continue; |
| 1139 | } |
| 1140 | new_modtime = new_statbuf.st_mtime; |
| 1141 | if (new_modtime != objfile->mtime) |
| 1142 | { |
| 1143 | struct cleanup *old_cleanups; |
| 1144 | struct section_offsets *offsets; |
| 1145 | int num_offsets; |
| 1146 | int section_offsets_size; |
| 1147 | char *obfd_filename; |
| 1148 | |
| 1149 | printf_filtered ("`%s' has changed; re-reading symbols.\n", |
| 1150 | objfile->name); |
| 1151 | |
| 1152 | /* There are various functions like symbol_file_add, |
| 1153 | symfile_bfd_open, syms_from_objfile, etc., which might |
| 1154 | appear to do what we want. But they have various other |
| 1155 | effects which we *don't* want. So we just do stuff |
| 1156 | ourselves. We don't worry about mapped files (for one thing, |
| 1157 | any mapped file will be out of date). */ |
| 1158 | |
| 1159 | /* If we get an error, blow away this objfile (not sure if |
| 1160 | that is the correct response for things like shared |
| 1161 | libraries). */ |
| 1162 | old_cleanups = make_cleanup (free_objfile, objfile); |
| 1163 | /* We need to do this whenever any symbols go away. */ |
| 1164 | make_cleanup (clear_symtab_users, 0); |
| 1165 | |
| 1166 | /* Clean up any state BFD has sitting around. We don't need |
| 1167 | to close the descriptor but BFD lacks a way of closing the |
| 1168 | BFD without closing the descriptor. */ |
| 1169 | obfd_filename = bfd_get_filename (objfile->obfd); |
| 1170 | if (!bfd_close (objfile->obfd)) |
| 1171 | error ("Can't close BFD for %s: %s", objfile->name, |
| 1172 | bfd_errmsg (bfd_get_error ())); |
| 1173 | objfile->obfd = bfd_openr (obfd_filename, gnutarget); |
| 1174 | if (objfile->obfd == NULL) |
| 1175 | error ("Can't open %s to read symbols.", objfile->name); |
| 1176 | /* bfd_openr sets cacheable to true, which is what we want. */ |
| 1177 | if (!bfd_check_format (objfile->obfd, bfd_object)) |
| 1178 | error ("Can't read symbols from %s: %s.", objfile->name, |
| 1179 | bfd_errmsg (bfd_get_error ())); |
| 1180 | |
| 1181 | /* Save the offsets, we will nuke them with the rest of the |
| 1182 | psymbol_obstack. */ |
| 1183 | num_offsets = objfile->num_sections; |
| 1184 | section_offsets_size = |
| 1185 | sizeof (struct section_offsets) |
| 1186 | + sizeof (objfile->section_offsets->offsets) * num_offsets; |
| 1187 | offsets = (struct section_offsets *) alloca (section_offsets_size); |
| 1188 | memcpy (offsets, objfile->section_offsets, section_offsets_size); |
| 1189 | |
| 1190 | /* Nuke all the state that we will re-read. Much of the following |
| 1191 | code which sets things to NULL really is necessary to tell |
| 1192 | other parts of GDB that there is nothing currently there. */ |
| 1193 | |
| 1194 | /* FIXME: Do we have to free a whole linked list, or is this |
| 1195 | enough? */ |
| 1196 | if (objfile->global_psymbols.list) |
| 1197 | mfree (objfile->md, objfile->global_psymbols.list); |
| 1198 | memset (&objfile -> global_psymbols, 0, |
| 1199 | sizeof (objfile -> global_psymbols)); |
| 1200 | if (objfile->static_psymbols.list) |
| 1201 | mfree (objfile->md, objfile->static_psymbols.list); |
| 1202 | memset (&objfile -> static_psymbols, 0, |
| 1203 | sizeof (objfile -> static_psymbols)); |
| 1204 | |
| 1205 | /* Free the obstacks for non-reusable objfiles */ |
| 1206 | obstack_free (&objfile -> psymbol_cache.cache, 0); |
| 1207 | memset (&objfile -> psymbol_cache, 0, |
| 1208 | sizeof (objfile -> psymbol_cache)); |
| 1209 | obstack_free (&objfile -> psymbol_obstack, 0); |
| 1210 | obstack_free (&objfile -> symbol_obstack, 0); |
| 1211 | obstack_free (&objfile -> type_obstack, 0); |
| 1212 | objfile->sections = NULL; |
| 1213 | objfile->symtabs = NULL; |
| 1214 | objfile->psymtabs = NULL; |
| 1215 | objfile->free_psymtabs = NULL; |
| 1216 | objfile->msymbols = NULL; |
| 1217 | objfile->minimal_symbol_count= 0; |
| 1218 | objfile->fundamental_types = NULL; |
| 1219 | if (objfile -> sf != NULL) |
| 1220 | { |
| 1221 | (*objfile -> sf -> sym_finish) (objfile); |
| 1222 | } |
| 1223 | |
| 1224 | /* We never make this a mapped file. */ |
| 1225 | objfile -> md = NULL; |
| 1226 | /* obstack_specify_allocation also initializes the obstack so |
| 1227 | it is empty. */ |
| 1228 | obstack_specify_allocation (&objfile -> psymbol_cache.cache, 0, 0, |
| 1229 | xmalloc, free); |
| 1230 | obstack_specify_allocation (&objfile -> psymbol_obstack, 0, 0, |
| 1231 | xmalloc, free); |
| 1232 | obstack_specify_allocation (&objfile -> symbol_obstack, 0, 0, |
| 1233 | xmalloc, free); |
| 1234 | obstack_specify_allocation (&objfile -> type_obstack, 0, 0, |
| 1235 | xmalloc, free); |
| 1236 | if (build_objfile_section_table (objfile)) |
| 1237 | { |
| 1238 | error ("Can't find the file sections in `%s': %s", |
| 1239 | objfile -> name, bfd_errmsg (bfd_get_error ())); |
| 1240 | } |
| 1241 | |
| 1242 | /* We use the same section offsets as from last time. I'm not |
| 1243 | sure whether that is always correct for shared libraries. */ |
| 1244 | objfile->section_offsets = (struct section_offsets *) |
| 1245 | obstack_alloc (&objfile -> psymbol_obstack, section_offsets_size); |
| 1246 | memcpy (objfile->section_offsets, offsets, section_offsets_size); |
| 1247 | objfile->num_sections = num_offsets; |
| 1248 | |
| 1249 | /* What the hell is sym_new_init for, anyway? The concept of |
| 1250 | distinguishing between the main file and additional files |
| 1251 | in this way seems rather dubious. */ |
| 1252 | if (objfile == symfile_objfile) |
| 1253 | (*objfile->sf->sym_new_init) (objfile); |
| 1254 | |
| 1255 | (*objfile->sf->sym_init) (objfile); |
| 1256 | clear_complaints (1, 1); |
| 1257 | /* The "mainline" parameter is a hideous hack; I think leaving it |
| 1258 | zero is OK since dbxread.c also does what it needs to do if |
| 1259 | objfile->global_psymbols.size is 0. */ |
| 1260 | (*objfile->sf->sym_read) (objfile, objfile->section_offsets, 0); |
| 1261 | if (!have_partial_symbols () && !have_full_symbols ()) |
| 1262 | { |
| 1263 | wrap_here (""); |
| 1264 | printf_filtered ("(no debugging symbols found)\n"); |
| 1265 | wrap_here (""); |
| 1266 | } |
| 1267 | objfile -> flags |= OBJF_SYMS; |
| 1268 | |
| 1269 | /* We're done reading the symbol file; finish off complaints. */ |
| 1270 | clear_complaints (0, 1); |
| 1271 | |
| 1272 | /* Getting new symbols may change our opinion about what is |
| 1273 | frameless. */ |
| 1274 | |
| 1275 | reinit_frame_cache (); |
| 1276 | |
| 1277 | /* Discard cleanups as symbol reading was successful. */ |
| 1278 | discard_cleanups (old_cleanups); |
| 1279 | |
| 1280 | /* If the mtime has changed between the time we set new_modtime |
| 1281 | and now, we *want* this to be out of date, so don't call stat |
| 1282 | again now. */ |
| 1283 | objfile->mtime = new_modtime; |
| 1284 | reread_one = 1; |
| 1285 | |
| 1286 | /* Call this after reading in a new symbol table to give target |
| 1287 | dependant code a crack at the new symbols. For instance, this |
| 1288 | could be used to update the values of target-specific symbols GDB |
| 1289 | needs to keep track of (such as _sigtramp, or whatever). */ |
| 1290 | |
| 1291 | TARGET_SYMFILE_POSTREAD (objfile); |
| 1292 | } |
| 1293 | } |
| 1294 | } |
| 1295 | |
| 1296 | if (reread_one) |
| 1297 | clear_symtab_users (); |
| 1298 | } |
| 1299 | |
| 1300 | \f |
| 1301 | enum language |
| 1302 | deduce_language_from_filename (filename) |
| 1303 | char *filename; |
| 1304 | { |
| 1305 | char *c; |
| 1306 | |
| 1307 | if (0 == filename) |
| 1308 | ; /* Get default */ |
| 1309 | else if (0 == (c = strrchr (filename, '.'))) |
| 1310 | ; /* Get default. */ |
| 1311 | else if (STREQ (c, ".c")) |
| 1312 | return language_c; |
| 1313 | else if (STREQ (c, ".cc") || STREQ (c, ".C") || STREQ (c, ".cxx") |
| 1314 | || STREQ (c, ".cpp") || STREQ (c, ".cp") || STREQ (c, ".c++")) |
| 1315 | return language_cplus; |
| 1316 | else if (STREQ (c, ".ch") || STREQ (c, ".c186") || STREQ (c, ".c286")) |
| 1317 | return language_chill; |
| 1318 | else if (STREQ (c, ".f") || STREQ (c, ".F")) |
| 1319 | return language_fortran; |
| 1320 | else if (STREQ (c, ".mod")) |
| 1321 | return language_m2; |
| 1322 | else if (STREQ (c, ".s") || STREQ (c, ".S")) |
| 1323 | return language_asm; |
| 1324 | |
| 1325 | return language_unknown; /* default */ |
| 1326 | } |
| 1327 | \f |
| 1328 | /* allocate_symtab: |
| 1329 | |
| 1330 | Allocate and partly initialize a new symbol table. Return a pointer |
| 1331 | to it. error() if no space. |
| 1332 | |
| 1333 | Caller must set these fields: |
| 1334 | LINETABLE(symtab) |
| 1335 | symtab->blockvector |
| 1336 | symtab->dirname |
| 1337 | symtab->free_code |
| 1338 | symtab->free_ptr |
| 1339 | initialize any EXTRA_SYMTAB_INFO |
| 1340 | possibly free_named_symtabs (symtab->filename); |
| 1341 | */ |
| 1342 | |
| 1343 | struct symtab * |
| 1344 | allocate_symtab (filename, objfile) |
| 1345 | char *filename; |
| 1346 | struct objfile *objfile; |
| 1347 | { |
| 1348 | register struct symtab *symtab; |
| 1349 | |
| 1350 | symtab = (struct symtab *) |
| 1351 | obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symtab)); |
| 1352 | memset (symtab, 0, sizeof (*symtab)); |
| 1353 | symtab -> filename = obsavestring (filename, strlen (filename), |
| 1354 | &objfile -> symbol_obstack); |
| 1355 | symtab -> fullname = NULL; |
| 1356 | symtab -> language = deduce_language_from_filename (filename); |
| 1357 | |
| 1358 | /* Hook it to the objfile it comes from */ |
| 1359 | |
| 1360 | symtab -> objfile = objfile; |
| 1361 | symtab -> next = objfile -> symtabs; |
| 1362 | objfile -> symtabs = symtab; |
| 1363 | |
| 1364 | #ifdef INIT_EXTRA_SYMTAB_INFO |
| 1365 | INIT_EXTRA_SYMTAB_INFO (symtab); |
| 1366 | #endif |
| 1367 | |
| 1368 | return (symtab); |
| 1369 | } |
| 1370 | |
| 1371 | struct partial_symtab * |
| 1372 | allocate_psymtab (filename, objfile) |
| 1373 | char *filename; |
| 1374 | struct objfile *objfile; |
| 1375 | { |
| 1376 | struct partial_symtab *psymtab; |
| 1377 | |
| 1378 | if (objfile -> free_psymtabs) |
| 1379 | { |
| 1380 | psymtab = objfile -> free_psymtabs; |
| 1381 | objfile -> free_psymtabs = psymtab -> next; |
| 1382 | } |
| 1383 | else |
| 1384 | psymtab = (struct partial_symtab *) |
| 1385 | obstack_alloc (&objfile -> psymbol_obstack, |
| 1386 | sizeof (struct partial_symtab)); |
| 1387 | |
| 1388 | memset (psymtab, 0, sizeof (struct partial_symtab)); |
| 1389 | psymtab -> filename = obsavestring (filename, strlen (filename), |
| 1390 | &objfile -> psymbol_obstack); |
| 1391 | psymtab -> symtab = NULL; |
| 1392 | |
| 1393 | /* Hook it to the objfile it comes from */ |
| 1394 | |
| 1395 | psymtab -> objfile = objfile; |
| 1396 | psymtab -> next = objfile -> psymtabs; |
| 1397 | objfile -> psymtabs = psymtab; |
| 1398 | |
| 1399 | return (psymtab); |
| 1400 | } |
| 1401 | |
| 1402 | \f |
| 1403 | /* Reset all data structures in gdb which may contain references to symbol |
| 1404 | table date. */ |
| 1405 | |
| 1406 | void |
| 1407 | clear_symtab_users () |
| 1408 | { |
| 1409 | /* Someday, we should do better than this, by only blowing away |
| 1410 | the things that really need to be blown. */ |
| 1411 | clear_value_history (); |
| 1412 | clear_displays (); |
| 1413 | clear_internalvars (); |
| 1414 | breakpoint_re_set (); |
| 1415 | set_default_breakpoint (0, 0, 0, 0); |
| 1416 | current_source_symtab = 0; |
| 1417 | current_source_line = 0; |
| 1418 | clear_pc_function_cache (); |
| 1419 | } |
| 1420 | |
| 1421 | /* clear_symtab_users_once: |
| 1422 | |
| 1423 | This function is run after symbol reading, or from a cleanup. |
| 1424 | If an old symbol table was obsoleted, the old symbol table |
| 1425 | has been blown away, but the other GDB data structures that may |
| 1426 | reference it have not yet been cleared or re-directed. (The old |
| 1427 | symtab was zapped, and the cleanup queued, in free_named_symtab() |
| 1428 | below.) |
| 1429 | |
| 1430 | This function can be queued N times as a cleanup, or called |
| 1431 | directly; it will do all the work the first time, and then will be a |
| 1432 | no-op until the next time it is queued. This works by bumping a |
| 1433 | counter at queueing time. Much later when the cleanup is run, or at |
| 1434 | the end of symbol processing (in case the cleanup is discarded), if |
| 1435 | the queued count is greater than the "done-count", we do the work |
| 1436 | and set the done-count to the queued count. If the queued count is |
| 1437 | less than or equal to the done-count, we just ignore the call. This |
| 1438 | is needed because reading a single .o file will often replace many |
| 1439 | symtabs (one per .h file, for example), and we don't want to reset |
| 1440 | the breakpoints N times in the user's face. |
| 1441 | |
| 1442 | The reason we both queue a cleanup, and call it directly after symbol |
| 1443 | reading, is because the cleanup protects us in case of errors, but is |
| 1444 | discarded if symbol reading is successful. */ |
| 1445 | |
| 1446 | #if 0 |
| 1447 | /* FIXME: As free_named_symtabs is currently a big noop this function |
| 1448 | is no longer needed. */ |
| 1449 | static void |
| 1450 | clear_symtab_users_once PARAMS ((void)); |
| 1451 | |
| 1452 | static int clear_symtab_users_queued; |
| 1453 | static int clear_symtab_users_done; |
| 1454 | |
| 1455 | static void |
| 1456 | clear_symtab_users_once () |
| 1457 | { |
| 1458 | /* Enforce once-per-`do_cleanups'-semantics */ |
| 1459 | if (clear_symtab_users_queued <= clear_symtab_users_done) |
| 1460 | return; |
| 1461 | clear_symtab_users_done = clear_symtab_users_queued; |
| 1462 | |
| 1463 | clear_symtab_users (); |
| 1464 | } |
| 1465 | #endif |
| 1466 | |
| 1467 | /* Delete the specified psymtab, and any others that reference it. */ |
| 1468 | |
| 1469 | static void |
| 1470 | cashier_psymtab (pst) |
| 1471 | struct partial_symtab *pst; |
| 1472 | { |
| 1473 | struct partial_symtab *ps, *pprev = NULL; |
| 1474 | int i; |
| 1475 | |
| 1476 | /* Find its previous psymtab in the chain */ |
| 1477 | for (ps = pst->objfile->psymtabs; ps; ps = ps->next) { |
| 1478 | if (ps == pst) |
| 1479 | break; |
| 1480 | pprev = ps; |
| 1481 | } |
| 1482 | |
| 1483 | if (ps) { |
| 1484 | /* Unhook it from the chain. */ |
| 1485 | if (ps == pst->objfile->psymtabs) |
| 1486 | pst->objfile->psymtabs = ps->next; |
| 1487 | else |
| 1488 | pprev->next = ps->next; |
| 1489 | |
| 1490 | /* FIXME, we can't conveniently deallocate the entries in the |
| 1491 | partial_symbol lists (global_psymbols/static_psymbols) that |
| 1492 | this psymtab points to. These just take up space until all |
| 1493 | the psymtabs are reclaimed. Ditto the dependencies list and |
| 1494 | filename, which are all in the psymbol_obstack. */ |
| 1495 | |
| 1496 | /* We need to cashier any psymtab that has this one as a dependency... */ |
| 1497 | again: |
| 1498 | for (ps = pst->objfile->psymtabs; ps; ps = ps->next) { |
| 1499 | for (i = 0; i < ps->number_of_dependencies; i++) { |
| 1500 | if (ps->dependencies[i] == pst) { |
| 1501 | cashier_psymtab (ps); |
| 1502 | goto again; /* Must restart, chain has been munged. */ |
| 1503 | } |
| 1504 | } |
| 1505 | } |
| 1506 | } |
| 1507 | } |
| 1508 | |
| 1509 | /* If a symtab or psymtab for filename NAME is found, free it along |
| 1510 | with any dependent breakpoints, displays, etc. |
| 1511 | Used when loading new versions of object modules with the "add-file" |
| 1512 | command. This is only called on the top-level symtab or psymtab's name; |
| 1513 | it is not called for subsidiary files such as .h files. |
| 1514 | |
| 1515 | Return value is 1 if we blew away the environment, 0 if not. |
| 1516 | FIXME. The return valu appears to never be used. |
| 1517 | |
| 1518 | FIXME. I think this is not the best way to do this. We should |
| 1519 | work on being gentler to the environment while still cleaning up |
| 1520 | all stray pointers into the freed symtab. */ |
| 1521 | |
| 1522 | int |
| 1523 | free_named_symtabs (name) |
| 1524 | char *name; |
| 1525 | { |
| 1526 | #if 0 |
| 1527 | /* FIXME: With the new method of each objfile having it's own |
| 1528 | psymtab list, this function needs serious rethinking. In particular, |
| 1529 | why was it ever necessary to toss psymtabs with specific compilation |
| 1530 | unit filenames, as opposed to all psymtabs from a particular symbol |
| 1531 | file? -- fnf |
| 1532 | Well, the answer is that some systems permit reloading of particular |
| 1533 | compilation units. We want to blow away any old info about these |
| 1534 | compilation units, regardless of which objfiles they arrived in. --gnu. */ |
| 1535 | |
| 1536 | register struct symtab *s; |
| 1537 | register struct symtab *prev; |
| 1538 | register struct partial_symtab *ps; |
| 1539 | struct blockvector *bv; |
| 1540 | int blewit = 0; |
| 1541 | |
| 1542 | /* We only wack things if the symbol-reload switch is set. */ |
| 1543 | if (!symbol_reloading) |
| 1544 | return 0; |
| 1545 | |
| 1546 | /* Some symbol formats have trouble providing file names... */ |
| 1547 | if (name == 0 || *name == '\0') |
| 1548 | return 0; |
| 1549 | |
| 1550 | /* Look for a psymtab with the specified name. */ |
| 1551 | |
| 1552 | again2: |
| 1553 | for (ps = partial_symtab_list; ps; ps = ps->next) { |
| 1554 | if (STREQ (name, ps->filename)) { |
| 1555 | cashier_psymtab (ps); /* Blow it away...and its little dog, too. */ |
| 1556 | goto again2; /* Must restart, chain has been munged */ |
| 1557 | } |
| 1558 | } |
| 1559 | |
| 1560 | /* Look for a symtab with the specified name. */ |
| 1561 | |
| 1562 | for (s = symtab_list; s; s = s->next) |
| 1563 | { |
| 1564 | if (STREQ (name, s->filename)) |
| 1565 | break; |
| 1566 | prev = s; |
| 1567 | } |
| 1568 | |
| 1569 | if (s) |
| 1570 | { |
| 1571 | if (s == symtab_list) |
| 1572 | symtab_list = s->next; |
| 1573 | else |
| 1574 | prev->next = s->next; |
| 1575 | |
| 1576 | /* For now, queue a delete for all breakpoints, displays, etc., whether |
| 1577 | or not they depend on the symtab being freed. This should be |
| 1578 | changed so that only those data structures affected are deleted. */ |
| 1579 | |
| 1580 | /* But don't delete anything if the symtab is empty. |
| 1581 | This test is necessary due to a bug in "dbxread.c" that |
| 1582 | causes empty symtabs to be created for N_SO symbols that |
| 1583 | contain the pathname of the object file. (This problem |
| 1584 | has been fixed in GDB 3.9x). */ |
| 1585 | |
| 1586 | bv = BLOCKVECTOR (s); |
| 1587 | if (BLOCKVECTOR_NBLOCKS (bv) > 2 |
| 1588 | || BLOCK_NSYMS (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) |
| 1589 | || BLOCK_NSYMS (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK))) |
| 1590 | { |
| 1591 | complain (&oldsyms_complaint, name); |
| 1592 | |
| 1593 | clear_symtab_users_queued++; |
| 1594 | make_cleanup (clear_symtab_users_once, 0); |
| 1595 | blewit = 1; |
| 1596 | } else { |
| 1597 | complain (&empty_symtab_complaint, name); |
| 1598 | } |
| 1599 | |
| 1600 | free_symtab (s); |
| 1601 | } |
| 1602 | else |
| 1603 | { |
| 1604 | /* It is still possible that some breakpoints will be affected |
| 1605 | even though no symtab was found, since the file might have |
| 1606 | been compiled without debugging, and hence not be associated |
| 1607 | with a symtab. In order to handle this correctly, we would need |
| 1608 | to keep a list of text address ranges for undebuggable files. |
| 1609 | For now, we do nothing, since this is a fairly obscure case. */ |
| 1610 | ; |
| 1611 | } |
| 1612 | |
| 1613 | /* FIXME, what about the minimal symbol table? */ |
| 1614 | return blewit; |
| 1615 | #else |
| 1616 | return (0); |
| 1617 | #endif |
| 1618 | } |
| 1619 | \f |
| 1620 | /* Allocate and partially fill a partial symtab. It will be |
| 1621 | completely filled at the end of the symbol list. |
| 1622 | |
| 1623 | SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR |
| 1624 | is the address relative to which its symbols are (incremental) or 0 |
| 1625 | (normal). */ |
| 1626 | |
| 1627 | |
| 1628 | struct partial_symtab * |
| 1629 | start_psymtab_common (objfile, section_offsets, |
| 1630 | filename, textlow, global_syms, static_syms) |
| 1631 | struct objfile *objfile; |
| 1632 | struct section_offsets *section_offsets; |
| 1633 | char *filename; |
| 1634 | CORE_ADDR textlow; |
| 1635 | struct partial_symbol **global_syms; |
| 1636 | struct partial_symbol **static_syms; |
| 1637 | { |
| 1638 | struct partial_symtab *psymtab; |
| 1639 | |
| 1640 | psymtab = allocate_psymtab (filename, objfile); |
| 1641 | psymtab -> section_offsets = section_offsets; |
| 1642 | psymtab -> textlow = textlow; |
| 1643 | psymtab -> texthigh = psymtab -> textlow; /* default */ |
| 1644 | psymtab -> globals_offset = global_syms - objfile -> global_psymbols.list; |
| 1645 | psymtab -> statics_offset = static_syms - objfile -> static_psymbols.list; |
| 1646 | return (psymtab); |
| 1647 | } |
| 1648 | \f |
| 1649 | /* Debugging versions of functions that are usually inline macros |
| 1650 | (see symfile.h). */ |
| 1651 | |
| 1652 | #if !INLINE_ADD_PSYMBOL |
| 1653 | |
| 1654 | /* Add a symbol with a long value to a psymtab. |
| 1655 | Since one arg is a struct, we pass in a ptr and deref it (sigh). */ |
| 1656 | |
| 1657 | void |
| 1658 | add_psymbol_to_list (name, namelength, namespace, class, list, val, language, |
| 1659 | objfile) |
| 1660 | char *name; |
| 1661 | int namelength; |
| 1662 | namespace_enum namespace; |
| 1663 | enum address_class class; |
| 1664 | struct psymbol_allocation_list *list; |
| 1665 | long val; |
| 1666 | enum language language; |
| 1667 | struct objfile *objfile; |
| 1668 | { |
| 1669 | register struct partial_symbol *psym; |
| 1670 | char *buf = alloca (namelength + 1); |
| 1671 | struct partial_symbol psymbol; |
| 1672 | |
| 1673 | /* Create local copy of the partial symbol */ |
| 1674 | memcpy (buf, name, namelength); |
| 1675 | buf[namelength] = '\0'; |
| 1676 | SYMBOL_NAME (&psymbol) = bcache (buf, namelength + 1, &objfile->psymbol_cache); |
| 1677 | SYMBOL_VALUE (&psymbol) = val; |
| 1678 | SYMBOL_SECTION (&psymbol) = 0; |
| 1679 | SYMBOL_LANGUAGE (&psymbol) = language; |
| 1680 | PSYMBOL_NAMESPACE (&psymbol) = namespace; |
| 1681 | PSYMBOL_CLASS (&psymbol) = class; |
| 1682 | SYMBOL_INIT_LANGUAGE_SPECIFIC (&psymbol, language); |
| 1683 | |
| 1684 | /* Stash the partial symbol away in the cache */ |
| 1685 | psym = bcache (&psymbol, sizeof (struct partial_symbol), &objfile->psymbol_cache); |
| 1686 | |
| 1687 | /* Save pointer to partial symbol in psymtab, growing symtab if needed. */ |
| 1688 | if (list->next >= list->list + list->size) |
| 1689 | { |
| 1690 | extend_psymbol_list (list, objfile); |
| 1691 | } |
| 1692 | *list->next++ = psym; |
| 1693 | OBJSTAT (objfile, n_psyms++); |
| 1694 | } |
| 1695 | |
| 1696 | /* Add a symbol with a CORE_ADDR value to a psymtab. */ |
| 1697 | |
| 1698 | void |
| 1699 | add_psymbol_addr_to_list (name, namelength, namespace, class, list, val, |
| 1700 | language, objfile) |
| 1701 | char *name; |
| 1702 | int namelength; |
| 1703 | namespace_enum namespace; |
| 1704 | enum address_class class; |
| 1705 | struct psymbol_allocation_list *list; |
| 1706 | CORE_ADDR val; |
| 1707 | enum language language; |
| 1708 | struct objfile *objfile; |
| 1709 | { |
| 1710 | register struct partial_symbol *psym; |
| 1711 | char *buf = alloca (namelength + 1); |
| 1712 | struct partial_symbol psymbol; |
| 1713 | |
| 1714 | /* Create local copy of the partial symbol */ |
| 1715 | memcpy (buf, name, namelength); |
| 1716 | buf[namelength] = '\0'; |
| 1717 | SYMBOL_NAME (&psymbol) = bcache (buf, namelength + 1, &objfile->psymbol_cache); |
| 1718 | SYMBOL_VALUE_ADDRESS (&psymbol) = val; |
| 1719 | SYMBOL_SECTION (&psymbol) = 0; |
| 1720 | SYMBOL_LANGUAGE (&psymbol) = language; |
| 1721 | PSYMBOL_NAMESPACE (&psymbol) = namespace; |
| 1722 | PSYMBOL_CLASS (&psymbol) = class; |
| 1723 | SYMBOL_INIT_LANGUAGE_SPECIFIC (&psymbol, language); |
| 1724 | |
| 1725 | /* Stash the partial symbol away in the cache */ |
| 1726 | psym = bcache (&psymbol, sizeof (struct partial_symbol), &objfile->psymbol_cache); |
| 1727 | |
| 1728 | /* Save pointer to partial symbol in psymtab, growing symtab if needed. */ |
| 1729 | if (list->next >= list->list + list->size) |
| 1730 | { |
| 1731 | extend_psymbol_list (list, objfile); |
| 1732 | } |
| 1733 | *list->next++ = psym; |
| 1734 | OBJSTAT (objfile, n_psyms++); |
| 1735 | } |
| 1736 | |
| 1737 | #endif /* !INLINE_ADD_PSYMBOL */ |
| 1738 | |
| 1739 | /* Initialize storage for partial symbols. */ |
| 1740 | |
| 1741 | void |
| 1742 | init_psymbol_list (objfile, total_symbols) |
| 1743 | struct objfile *objfile; |
| 1744 | int total_symbols; |
| 1745 | { |
| 1746 | /* Free any previously allocated psymbol lists. */ |
| 1747 | |
| 1748 | if (objfile -> global_psymbols.list) |
| 1749 | { |
| 1750 | mfree (objfile -> md, (PTR)objfile -> global_psymbols.list); |
| 1751 | } |
| 1752 | if (objfile -> static_psymbols.list) |
| 1753 | { |
| 1754 | mfree (objfile -> md, (PTR)objfile -> static_psymbols.list); |
| 1755 | } |
| 1756 | |
| 1757 | /* Current best guess is that approximately a twentieth |
| 1758 | of the total symbols (in a debugging file) are global or static |
| 1759 | oriented symbols */ |
| 1760 | |
| 1761 | objfile -> global_psymbols.size = total_symbols / 10; |
| 1762 | objfile -> static_psymbols.size = total_symbols / 10; |
| 1763 | objfile -> global_psymbols.next = |
| 1764 | objfile -> global_psymbols.list = (struct partial_symbol **) |
| 1765 | xmmalloc (objfile -> md, objfile -> global_psymbols.size |
| 1766 | * sizeof (struct partial_symbol *)); |
| 1767 | objfile -> static_psymbols.next = |
| 1768 | objfile -> static_psymbols.list = (struct partial_symbol **) |
| 1769 | xmmalloc (objfile -> md, objfile -> static_psymbols.size |
| 1770 | * sizeof (struct partial_symbol *)); |
| 1771 | } |
| 1772 | \f |
| 1773 | void |
| 1774 | _initialize_symfile () |
| 1775 | { |
| 1776 | struct cmd_list_element *c; |
| 1777 | |
| 1778 | c = add_cmd ("symbol-file", class_files, symbol_file_command, |
| 1779 | "Load symbol table from executable file FILE.\n\ |
| 1780 | The `file' command can also load symbol tables, as well as setting the file\n\ |
| 1781 | to execute.", &cmdlist); |
| 1782 | c->completer = filename_completer; |
| 1783 | |
| 1784 | c = add_cmd ("add-symbol-file", class_files, add_symbol_file_command, |
| 1785 | "Usage: add-symbol-file FILE ADDR\n\ |
| 1786 | Load the symbols from FILE, assuming FILE has been dynamically loaded.\n\ |
| 1787 | ADDR is the starting address of the file's text.", |
| 1788 | &cmdlist); |
| 1789 | c->completer = filename_completer; |
| 1790 | |
| 1791 | c = add_cmd ("add-shared-symbol-files", class_files, |
| 1792 | add_shared_symbol_files_command, |
| 1793 | "Load the symbols from shared objects in the dynamic linker's link map.", |
| 1794 | &cmdlist); |
| 1795 | c = add_alias_cmd ("assf", "add-shared-symbol-files", class_files, 1, |
| 1796 | &cmdlist); |
| 1797 | |
| 1798 | c = add_cmd ("load", class_files, load_command, |
| 1799 | "Dynamically load FILE into the running program, and record its symbols\n\ |
| 1800 | for access from GDB.", &cmdlist); |
| 1801 | c->completer = filename_completer; |
| 1802 | |
| 1803 | add_show_from_set |
| 1804 | (add_set_cmd ("symbol-reloading", class_support, var_boolean, |
| 1805 | (char *)&symbol_reloading, |
| 1806 | "Set dynamic symbol table reloading multiple times in one run.", |
| 1807 | &setlist), |
| 1808 | &showlist); |
| 1809 | |
| 1810 | } |