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