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