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