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