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