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