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