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