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 | ||
77636dea FF |
55 | int (*ui_load_progress_hook) PARAMS ((char *, unsigned long)); |
56 | ||
30875e1c | 57 | /* Global variables owned by this file */ |
80d68b1d | 58 | int readnow_symbol_files; /* Read full symbols immediately */ |
d47d5315 | 59 | |
51b80b00 FF |
60 | struct complaint oldsyms_complaint = { |
61 | "Replacing old symbols for `%s'", 0, 0 | |
62 | }; | |
63 | ||
64 | struct complaint empty_symtab_complaint = { | |
65 | "Empty symbol table found for `%s'", 0, 0 | |
66 | }; | |
67 | ||
30875e1c | 68 | /* External variables and functions referenced. */ |
bd5635a1 | 69 | |
30875e1c | 70 | extern int info_verbose; |
bd5635a1 | 71 | |
72158e71 SS |
72 | extern void report_transfer_performance PARAMS ((unsigned long, |
73 | time_t, time_t)); | |
74 | ||
bd5635a1 | 75 | /* Functions this file defines */ |
7d9884b9 | 76 | |
40b647e9 FF |
77 | #if 0 |
78 | static int simple_read_overlay_region_table PARAMS ((void)); | |
79 | static void simple_free_overlay_region_table PARAMS ((void)); | |
80 | #endif | |
81 | ||
72158e71 | 82 | static void set_initial_language PARAMS ((void)); |
e58de8a2 | 83 | |
72158e71 | 84 | static void load_command PARAMS ((char *, int)); |
30875e1c | 85 | |
72158e71 | 86 | static void add_symbol_file_command PARAMS ((char *, int)); |
30875e1c | 87 | |
72158e71 | 88 | static void add_shared_symbol_files_command PARAMS ((char *, int)); |
f3806e3b | 89 | |
72158e71 | 90 | static void cashier_psymtab PARAMS ((struct partial_symtab *)); |
bd5635a1 | 91 | |
72158e71 | 92 | static int compare_psymbols PARAMS ((const void *, const void *)); |
bd5635a1 | 93 | |
72158e71 | 94 | static int compare_symbols PARAMS ((const void *, const void *)); |
30875e1c | 95 | |
72158e71 | 96 | static bfd *symfile_bfd_open PARAMS ((char *)); |
30875e1c | 97 | |
72158e71 | 98 | static void find_sym_fns PARAMS ((struct objfile *)); |
30875e1c | 99 | |
b607efe7 FF |
100 | static void decrement_reading_symtab PARAMS ((void *)); |
101 | ||
80d68b1d FF |
102 | /* List of all available sym_fns. On gdb startup, each object file reader |
103 | calls add_symtab_fns() to register information on each format it is | |
104 | prepared to read. */ | |
bd5635a1 | 105 | |
80d68b1d | 106 | static struct sym_fns *symtab_fns = NULL; |
bd5635a1 | 107 | |
61a7292f SG |
108 | /* Flag for whether user will be reloading symbols multiple times. |
109 | Defaults to ON for VxWorks, otherwise OFF. */ | |
110 | ||
111 | #ifdef SYMBOL_RELOADING_DEFAULT | |
112 | int symbol_reloading = SYMBOL_RELOADING_DEFAULT; | |
113 | #else | |
114 | int symbol_reloading = 0; | |
115 | #endif | |
116 | ||
dee7a11c | 117 | /* If true, then shared library symbols will be added automatically |
f1d39876 FF |
118 | when the inferior is created, new libraries are loaded, or when |
119 | attaching to the inferior. This is almost always what users | |
dee7a11c FF |
120 | will want to have happen; but for very large programs, the startup |
121 | time will be excessive, and so if this is a problem, the user can | |
122 | clear this flag and then add the shared library symbols as needed. | |
123 | Note that there is a potential for confusion, since if the shared | |
124 | library symbols are not loaded, commands like "info fun" will *not* | |
125 | report all the functions that are actually present. */ | |
126 | ||
f1d39876 | 127 | int auto_solib_add = 1; |
dee7a11c | 128 | |
bd5635a1 | 129 | \f |
ade40d31 | 130 | /* Since this function is called from within qsort, in an ANSI environment |
30875e1c SG |
131 | it must conform to the prototype for qsort, which specifies that the |
132 | comparison function takes two "void *" pointers. */ | |
bd5635a1 RP |
133 | |
134 | static int | |
30875e1c SG |
135 | compare_symbols (s1p, s2p) |
136 | const PTR s1p; | |
137 | const PTR s2p; | |
bd5635a1 | 138 | { |
30875e1c | 139 | register struct symbol **s1, **s2; |
bd5635a1 | 140 | |
30875e1c SG |
141 | s1 = (struct symbol **) s1p; |
142 | s2 = (struct symbol **) s2p; | |
143 | ||
ade40d31 | 144 | return (STRCMP (SYMBOL_NAME (*s1), SYMBOL_NAME (*s2))); |
bd5635a1 RP |
145 | } |
146 | ||
30875e1c SG |
147 | /* |
148 | ||
149 | LOCAL FUNCTION | |
150 | ||
151 | compare_psymbols -- compare two partial symbols by name | |
152 | ||
153 | DESCRIPTION | |
154 | ||
2ad5709f FF |
155 | Given pointers to pointers to two partial symbol table entries, |
156 | compare them by name and return -N, 0, or +N (ala strcmp). | |
157 | Typically used by sorting routines like qsort(). | |
30875e1c SG |
158 | |
159 | NOTES | |
160 | ||
161 | Does direct compare of first two characters before punting | |
162 | and passing to strcmp for longer compares. Note that the | |
163 | original version had a bug whereby two null strings or two | |
164 | identically named one character strings would return the | |
165 | comparison of memory following the null byte. | |
166 | ||
167 | */ | |
168 | ||
169 | static int | |
170 | compare_psymbols (s1p, s2p) | |
171 | const PTR s1p; | |
172 | const PTR s2p; | |
173 | { | |
2ad5709f FF |
174 | register char *st1 = SYMBOL_NAME (*(struct partial_symbol **) s1p); |
175 | register char *st2 = SYMBOL_NAME (*(struct partial_symbol **) s2p); | |
30875e1c SG |
176 | |
177 | if ((st1[0] - st2[0]) || !st1[0]) | |
178 | { | |
179 | return (st1[0] - st2[0]); | |
180 | } | |
181 | else if ((st1[1] - st2[1]) || !st1[1]) | |
182 | { | |
183 | return (st1[1] - st2[1]); | |
184 | } | |
185 | else | |
186 | { | |
2e4964ad | 187 | return (STRCMP (st1 + 2, st2 + 2)); |
30875e1c SG |
188 | } |
189 | } | |
190 | ||
191 | void | |
192 | sort_pst_symbols (pst) | |
193 | struct partial_symtab *pst; | |
194 | { | |
195 | /* Sort the global list; don't sort the static list */ | |
196 | ||
197 | qsort (pst -> objfile -> global_psymbols.list + pst -> globals_offset, | |
2ad5709f | 198 | pst -> n_global_syms, sizeof (struct partial_symbol *), |
30875e1c SG |
199 | compare_psymbols); |
200 | } | |
201 | ||
bd5635a1 RP |
202 | /* Call sort_block_syms to sort alphabetically the symbols of one block. */ |
203 | ||
204 | void | |
205 | sort_block_syms (b) | |
206 | register struct block *b; | |
207 | { | |
208 | qsort (&BLOCK_SYM (b, 0), BLOCK_NSYMS (b), | |
209 | sizeof (struct symbol *), compare_symbols); | |
210 | } | |
211 | ||
212 | /* Call sort_symtab_syms to sort alphabetically | |
213 | the symbols of each block of one symtab. */ | |
214 | ||
215 | void | |
216 | sort_symtab_syms (s) | |
217 | register struct symtab *s; | |
218 | { | |
c9bd6710 JG |
219 | register struct blockvector *bv; |
220 | int nbl; | |
bd5635a1 RP |
221 | int i; |
222 | register struct block *b; | |
223 | ||
c9bd6710 JG |
224 | if (s == 0) |
225 | return; | |
226 | bv = BLOCKVECTOR (s); | |
227 | nbl = BLOCKVECTOR_NBLOCKS (bv); | |
bd5635a1 RP |
228 | for (i = 0; i < nbl; i++) |
229 | { | |
230 | b = BLOCKVECTOR_BLOCK (bv, i); | |
231 | if (BLOCK_SHOULD_SORT (b)) | |
232 | sort_block_syms (b); | |
233 | } | |
234 | } | |
235 | ||
ace4b8d7 FF |
236 | /* Make a null terminated copy of the string at PTR with SIZE characters in |
237 | the obstack pointed to by OBSTACKP . Returns the address of the copy. | |
238 | Note that the string at PTR does not have to be null terminated, I.E. it | |
239 | may be part of a larger string and we are only saving a substring. */ | |
bd5635a1 RP |
240 | |
241 | char * | |
30875e1c | 242 | obsavestring (ptr, size, obstackp) |
bd5635a1 RP |
243 | char *ptr; |
244 | int size; | |
30875e1c | 245 | struct obstack *obstackp; |
bd5635a1 | 246 | { |
30875e1c | 247 | register char *p = (char *) obstack_alloc (obstackp, size + 1); |
ace4b8d7 FF |
248 | /* Open-coded memcpy--saves function call time. These strings are usually |
249 | short. FIXME: Is this really still true with a compiler that can | |
250 | inline memcpy? */ | |
bd5635a1 RP |
251 | { |
252 | register char *p1 = ptr; | |
253 | register char *p2 = p; | |
254 | char *end = ptr + size; | |
255 | while (p1 != end) | |
256 | *p2++ = *p1++; | |
257 | } | |
258 | p[size] = 0; | |
259 | return p; | |
260 | } | |
261 | ||
ace4b8d7 FF |
262 | /* Concatenate strings S1, S2 and S3; return the new string. Space is found |
263 | in the obstack pointed to by OBSTACKP. */ | |
bd5635a1 RP |
264 | |
265 | char * | |
30875e1c SG |
266 | obconcat (obstackp, s1, s2, s3) |
267 | struct obstack *obstackp; | |
268 | const char *s1, *s2, *s3; | |
bd5635a1 RP |
269 | { |
270 | register int len = strlen (s1) + strlen (s2) + strlen (s3) + 1; | |
30875e1c | 271 | register char *val = (char *) obstack_alloc (obstackp, len); |
bd5635a1 RP |
272 | strcpy (val, s1); |
273 | strcat (val, s2); | |
274 | strcat (val, s3); | |
275 | return val; | |
276 | } | |
bd5635a1 | 277 | |
7ef89313 PB |
278 | /* True if we are nested inside psymtab_to_symtab. */ |
279 | ||
280 | int currently_reading_symtab = 0; | |
281 | ||
b52cac6b | 282 | static void |
7ef89313 PB |
283 | decrement_reading_symtab (dummy) |
284 | void *dummy; | |
285 | { | |
286 | currently_reading_symtab--; | |
287 | } | |
288 | ||
bd5635a1 RP |
289 | /* Get the symbol table that corresponds to a partial_symtab. |
290 | This is fast after the first time you do it. In fact, there | |
291 | is an even faster macro PSYMTAB_TO_SYMTAB that does the fast | |
292 | case inline. */ | |
293 | ||
294 | struct symtab * | |
295 | psymtab_to_symtab (pst) | |
296 | register struct partial_symtab *pst; | |
297 | { | |
bd5635a1 RP |
298 | /* If it's been looked up before, return it. */ |
299 | if (pst->symtab) | |
300 | return pst->symtab; | |
301 | ||
302 | /* If it has not yet been read in, read it. */ | |
303 | if (!pst->readin) | |
304 | { | |
7ef89313 PB |
305 | struct cleanup *back_to = make_cleanup (decrement_reading_symtab, NULL); |
306 | currently_reading_symtab++; | |
bd5635a1 | 307 | (*pst->read_symtab) (pst); |
7ef89313 | 308 | do_cleanups (back_to); |
bd5635a1 RP |
309 | } |
310 | ||
61a7292f | 311 | return pst->symtab; |
bd5635a1 RP |
312 | } |
313 | ||
bf349b77 FF |
314 | /* Initialize entry point information for this objfile. */ |
315 | ||
316 | void | |
317 | init_entry_point_info (objfile) | |
318 | struct objfile *objfile; | |
319 | { | |
320 | /* Save startup file's range of PC addresses to help blockframe.c | |
321 | decide where the bottom of the stack is. */ | |
322 | ||
323 | if (bfd_get_file_flags (objfile -> obfd) & EXEC_P) | |
324 | { | |
325 | /* Executable file -- record its entry point so we'll recognize | |
326 | the startup file because it contains the entry point. */ | |
327 | objfile -> ei.entry_point = bfd_get_start_address (objfile -> obfd); | |
328 | } | |
329 | else | |
330 | { | |
331 | /* Examination of non-executable.o files. Short-circuit this stuff. */ | |
f3806e3b | 332 | objfile -> ei.entry_point = INVALID_ENTRY_POINT; |
bf349b77 | 333 | } |
dee7a11c FF |
334 | objfile -> ei.entry_file_lowpc = INVALID_ENTRY_LOWPC; |
335 | objfile -> ei.entry_file_highpc = INVALID_ENTRY_HIGHPC; | |
336 | objfile -> ei.entry_func_lowpc = INVALID_ENTRY_LOWPC; | |
337 | objfile -> ei.entry_func_highpc = INVALID_ENTRY_HIGHPC; | |
338 | objfile -> ei.main_func_lowpc = INVALID_ENTRY_LOWPC; | |
339 | objfile -> ei.main_func_highpc = INVALID_ENTRY_HIGHPC; | |
bf349b77 FF |
340 | } |
341 | ||
4d57c599 JK |
342 | /* Get current entry point address. */ |
343 | ||
344 | CORE_ADDR | |
345 | entry_point_address() | |
346 | { | |
347 | return symfile_objfile ? symfile_objfile->ei.entry_point : 0; | |
348 | } | |
349 | ||
a8e033f2 | 350 | /* Remember the lowest-addressed loadable section we've seen. |
1a494973 C |
351 | This function is called via bfd_map_over_sections. |
352 | ||
353 | In case of equal vmas, the section with the largest size becomes the | |
354 | lowest-addressed loadable section. | |
355 | ||
356 | If the vmas and sizes are equal, the last section is considered the | |
357 | lowest-addressed loadable section. */ | |
a8e033f2 | 358 | |
464c6c5f | 359 | void |
a8e033f2 SG |
360 | find_lowest_section (abfd, sect, obj) |
361 | bfd *abfd; | |
362 | asection *sect; | |
363 | PTR obj; | |
364 | { | |
365 | asection **lowest = (asection **)obj; | |
366 | ||
367 | if (0 == (bfd_get_section_flags (abfd, sect) & SEC_LOAD)) | |
368 | return; | |
369 | if (!*lowest) | |
370 | *lowest = sect; /* First loadable section */ | |
1a494973 | 371 | else if (bfd_section_vma (abfd, *lowest) > bfd_section_vma (abfd, sect)) |
a8e033f2 | 372 | *lowest = sect; /* A lower loadable section */ |
1a494973 C |
373 | else if (bfd_section_vma (abfd, *lowest) == bfd_section_vma (abfd, sect) |
374 | && (bfd_section_size (abfd, (*lowest)) | |
375 | <= bfd_section_size (abfd, sect))) | |
376 | *lowest = sect; | |
a8e033f2 | 377 | } |
a8e033f2 | 378 | |
e74acce4 MA |
379 | /* Parse the user's idea of an offset for dynamic linking, into our idea |
380 | of how to represent it for fast symbol reading. This is the default | |
381 | version of the sym_fns.sym_offsets function for symbol readers that | |
382 | don't need to do anything special. It allocates a section_offsets table | |
383 | for the objectfile OBJFILE and stuffs ADDR into all of the offsets. */ | |
384 | ||
385 | struct section_offsets * | |
386 | default_symfile_offsets (objfile, addr) | |
387 | struct objfile *objfile; | |
388 | CORE_ADDR addr; | |
389 | { | |
390 | struct section_offsets *section_offsets; | |
391 | int i; | |
392 | ||
393 | objfile->num_sections = SECT_OFF_MAX; | |
394 | section_offsets = (struct section_offsets *) | |
395 | obstack_alloc (&objfile -> psymbol_obstack, SIZEOF_SECTION_OFFSETS); | |
396 | ||
397 | for (i = 0; i < SECT_OFF_MAX; i++) | |
398 | ANOFFSET (section_offsets, i) = addr; | |
399 | ||
400 | return section_offsets; | |
401 | } | |
402 | ||
403 | ||
bd5635a1 RP |
404 | /* Process a symbol file, as either the main file or as a dynamically |
405 | loaded file. | |
406 | ||
b3fdaf3d JK |
407 | NAME is the file name (which will be tilde-expanded and made |
408 | absolute herein) (but we don't free or modify NAME itself). | |
409 | FROM_TTY says how verbose to be. MAINLINE specifies whether this | |
410 | is the main symbol file, or whether it's an extra symbol file such | |
411 | as dynamically loaded code. If !mainline, ADDR is the address | |
4369a140 JG |
412 | where the text segment was loaded. If VERBO, the caller has printed |
413 | a verbose message about the symbol reading (and complaints can be | |
414 | more terse about it). */ | |
bd5635a1 RP |
415 | |
416 | void | |
4369a140 | 417 | syms_from_objfile (objfile, addr, mainline, verbo) |
7d9884b9 | 418 | struct objfile *objfile; |
bd5635a1 RP |
419 | CORE_ADDR addr; |
420 | int mainline; | |
4369a140 | 421 | int verbo; |
bd5635a1 | 422 | { |
a8e033f2 SG |
423 | struct section_offsets *section_offsets; |
424 | asection *lowest_sect; | |
ade40d31 | 425 | struct cleanup *old_chain; |
bd5635a1 | 426 | |
bf349b77 | 427 | init_entry_point_info (objfile); |
80d68b1d | 428 | find_sym_fns (objfile); |
bd5635a1 | 429 | |
ade40d31 RP |
430 | /* Make sure that partially constructed symbol tables will be cleaned up |
431 | if an error occurs during symbol reading. */ | |
432 | old_chain = make_cleanup (free_objfile, objfile); | |
433 | ||
bd5635a1 RP |
434 | if (mainline) |
435 | { | |
ade40d31 RP |
436 | /* We will modify the main symbol table, make sure that all its users |
437 | will be cleaned up if an error occurs during symbol reading. */ | |
438 | make_cleanup (clear_symtab_users, 0); | |
439 | ||
bd5635a1 RP |
440 | /* Since no error yet, throw away the old symbol table. */ |
441 | ||
80d68b1d FF |
442 | if (symfile_objfile != NULL) |
443 | { | |
444 | free_objfile (symfile_objfile); | |
445 | symfile_objfile = NULL; | |
446 | } | |
bd5635a1 | 447 | |
f6c4bf1a JK |
448 | /* Currently we keep symbols from the add-symbol-file command. |
449 | If the user wants to get rid of them, they should do "symbol-file" | |
450 | without arguments first. Not sure this is the best behavior | |
451 | (PR 2207). */ | |
452 | ||
80d68b1d | 453 | (*objfile -> sf -> sym_new_init) (objfile); |
a8e033f2 | 454 | } |
bd5635a1 | 455 | |
a8e033f2 SG |
456 | /* Convert addr into an offset rather than an absolute address. |
457 | We find the lowest address of a loaded segment in the objfile, | |
458 | and assume that <addr> is where that got loaded. Due to historical | |
1a494973 | 459 | precedent, we warn if that doesn't happen to be a text segment. */ |
80d68b1d | 460 | |
a8e033f2 SG |
461 | if (mainline) |
462 | { | |
463 | addr = 0; /* No offset from objfile addresses. */ | |
464 | } | |
465 | else | |
466 | { | |
467 | lowest_sect = bfd_get_section_by_name (objfile->obfd, ".text"); | |
1a494973 C |
468 | if (lowest_sect == NULL) |
469 | bfd_map_over_sections (objfile->obfd, find_lowest_section, | |
470 | (PTR) &lowest_sect); | |
a8e033f2 | 471 | |
1a494973 | 472 | if (lowest_sect == NULL) |
a8e033f2 SG |
473 | warning ("no loadable sections found in added symbol-file %s", |
474 | objfile->name); | |
1a494973 C |
475 | else if ((bfd_get_section_flags (objfile->obfd, lowest_sect) & SEC_CODE) |
476 | == 0) | |
c4a081e1 | 477 | /* FIXME-32x64--assumes bfd_vma fits in long. */ |
4d57c599 | 478 | warning ("Lowest section in %s is %s at 0x%lx", |
a8e033f2 SG |
479 | objfile->name, |
480 | bfd_section_name (objfile->obfd, lowest_sect), | |
4d57c599 | 481 | (unsigned long) bfd_section_vma (objfile->obfd, lowest_sect)); |
a8e033f2 SG |
482 | |
483 | if (lowest_sect) | |
484 | addr -= bfd_section_vma (objfile->obfd, lowest_sect); | |
bd5635a1 RP |
485 | } |
486 | ||
80d68b1d FF |
487 | /* Initialize symbol reading routines for this objfile, allow complaints to |
488 | appear for this new file, and record how verbose to be, then do the | |
489 | initial symbol reading for this file. */ | |
4369a140 | 490 | |
80d68b1d FF |
491 | (*objfile -> sf -> sym_init) (objfile); |
492 | clear_complaints (1, verbo); | |
2093fe68 | 493 | |
a8e033f2 | 494 | section_offsets = (*objfile -> sf -> sym_offsets) (objfile, addr); |
2093fe68 RP |
495 | objfile->section_offsets = section_offsets; |
496 | ||
4365c36c JK |
497 | #ifndef IBM6000_TARGET |
498 | /* This is a SVR4/SunOS specific hack, I think. In any event, it | |
499 | screws RS/6000. sym_offsets should be doing this sort of thing, | |
500 | because it knows the mapping between bfd sections and | |
501 | section_offsets. */ | |
5aefc1ca FF |
502 | /* This is a hack. As far as I can tell, section offsets are not |
503 | target dependent. They are all set to addr with a couple of | |
504 | exceptions. The exceptions are sysvr4 shared libraries, whose | |
505 | offsets are kept in solib structures anyway and rs6000 xcoff | |
506 | which handles shared libraries in a completely unique way. | |
507 | ||
508 | Section offsets are built similarly, except that they are built | |
509 | by adding addr in all cases because there is no clear mapping | |
510 | from section_offsets into actual sections. Note that solib.c | |
511 | has a different algorythm for finding section offsets. | |
512 | ||
513 | These should probably all be collapsed into some target | |
514 | independent form of shared library support. FIXME. */ | |
515 | ||
516 | if (addr) | |
517 | { | |
518 | struct obj_section *s; | |
519 | ||
520 | for (s = objfile->sections; s < objfile->sections_end; ++s) | |
521 | { | |
522 | s->addr -= s->offset; | |
523 | s->addr += addr; | |
524 | s->endaddr -= s->offset; | |
525 | s->endaddr += addr; | |
526 | s->offset += addr; | |
527 | } | |
528 | } | |
4365c36c | 529 | #endif /* not IBM6000_TARGET */ |
5aefc1ca | 530 | |
a8e033f2 | 531 | (*objfile -> sf -> sym_read) (objfile, section_offsets, mainline); |
bd5635a1 | 532 | |
f3806e3b PS |
533 | if (!have_partial_symbols () && !have_full_symbols ()) |
534 | { | |
535 | wrap_here (""); | |
536 | printf_filtered ("(no debugging symbols found)..."); | |
537 | wrap_here (""); | |
538 | } | |
539 | ||
4d57c599 JK |
540 | /* Don't allow char * to have a typename (else would get caddr_t). |
541 | Ditto void *. FIXME: Check whether this is now done by all the | |
542 | symbol readers themselves (many of them now do), and if so remove | |
543 | it from here. */ | |
bd5635a1 RP |
544 | |
545 | TYPE_NAME (lookup_pointer_type (builtin_type_char)) = 0; | |
546 | TYPE_NAME (lookup_pointer_type (builtin_type_void)) = 0; | |
547 | ||
9342ecb9 JG |
548 | /* Mark the objfile has having had initial symbol read attempted. Note |
549 | that this does not mean we found any symbols... */ | |
550 | ||
551 | objfile -> flags |= OBJF_SYMS; | |
ade40d31 RP |
552 | |
553 | /* Discard cleanups as symbol reading was successful. */ | |
554 | ||
555 | discard_cleanups (old_chain); | |
dee7a11c FF |
556 | |
557 | /* Call this after reading in a new symbol table to give target dependant code | |
558 | a crack at the new symbols. For instance, this could be used to update the | |
559 | values of target-specific symbols GDB needs to keep track of (such as | |
560 | _sigtramp, or whatever). */ | |
561 | ||
562 | TARGET_SYMFILE_POSTREAD (objfile); | |
9342ecb9 JG |
563 | } |
564 | ||
ade40d31 | 565 | /* Perform required actions after either reading in the initial |
9342ecb9 JG |
566 | symbols for a new objfile, or mapping in the symbols from a reusable |
567 | objfile. */ | |
568 | ||
569 | void | |
570 | new_symfile_objfile (objfile, mainline, verbo) | |
571 | struct objfile *objfile; | |
572 | int mainline; | |
573 | int verbo; | |
574 | { | |
ade40d31 RP |
575 | |
576 | /* If this is the main symbol file we have to clean up all users of the | |
577 | old main symbol file. Otherwise it is sufficient to fixup all the | |
578 | breakpoints that may have been redefined by this symbol file. */ | |
bd5635a1 RP |
579 | if (mainline) |
580 | { | |
581 | /* OK, make it the "real" symbol file. */ | |
7d9884b9 | 582 | symfile_objfile = objfile; |
bd5635a1 | 583 | |
ade40d31 RP |
584 | clear_symtab_users (); |
585 | } | |
586 | else | |
587 | { | |
588 | breakpoint_re_set (); | |
589 | } | |
4369a140 JG |
590 | |
591 | /* We're done reading the symbol file; finish off complaints. */ | |
80d68b1d | 592 | clear_complaints (0, verbo); |
30875e1c | 593 | } |
d47d5315 JG |
594 | |
595 | /* Process a symbol file, as either the main file or as a dynamically | |
596 | loaded file. | |
597 | ||
598 | NAME is the file name (which will be tilde-expanded and made | |
599 | absolute herein) (but we don't free or modify NAME itself). | |
600 | FROM_TTY says how verbose to be. MAINLINE specifies whether this | |
601 | is the main symbol file, or whether it's an extra symbol file such | |
602 | as dynamically loaded code. If !mainline, ADDR is the address | |
30875e1c | 603 | where the text segment was loaded. |
d47d5315 | 604 | |
30875e1c SG |
605 | Upon success, returns a pointer to the objfile that was added. |
606 | Upon failure, jumps back to command level (never returns). */ | |
607 | ||
608 | struct objfile * | |
b0246b3b | 609 | symbol_file_add (name, from_tty, addr, mainline, mapped, readnow) |
d47d5315 JG |
610 | char *name; |
611 | int from_tty; | |
612 | CORE_ADDR addr; | |
613 | int mainline; | |
318bf84f | 614 | int mapped; |
b0246b3b | 615 | int readnow; |
d47d5315 | 616 | { |
7d9884b9 | 617 | struct objfile *objfile; |
b0246b3b | 618 | struct partial_symtab *psymtab; |
80d68b1d | 619 | bfd *abfd; |
d47d5315 | 620 | |
2093fe68 RP |
621 | /* Open a bfd for the file, and give user a chance to burp if we'd be |
622 | interactively wiping out any existing symbols. */ | |
80d68b1d FF |
623 | |
624 | abfd = symfile_bfd_open (name); | |
d47d5315 | 625 | |
80d68b1d FF |
626 | if ((have_full_symbols () || have_partial_symbols ()) |
627 | && mainline | |
628 | && from_tty | |
629 | && !query ("Load new symbol table from \"%s\"? ", name)) | |
630 | error ("Not confirmed."); | |
a8e033f2 | 631 | |
80d68b1d FF |
632 | objfile = allocate_objfile (abfd, mapped); |
633 | ||
318bf84f FF |
634 | /* If the objfile uses a mapped symbol file, and we have a psymtab for |
635 | it, then skip reading any symbols at this time. */ | |
d47d5315 | 636 | |
bf349b77 | 637 | if ((objfile -> flags & OBJF_MAPPED) && (objfile -> flags & OBJF_SYMS)) |
d47d5315 | 638 | { |
80d68b1d | 639 | /* We mapped in an existing symbol table file that already has had |
bf349b77 FF |
640 | initial symbol reading performed, so we can skip that part. Notify |
641 | the user that instead of reading the symbols, they have been mapped. | |
642 | */ | |
318bf84f FF |
643 | if (from_tty || info_verbose) |
644 | { | |
80d68b1d FF |
645 | printf_filtered ("Mapped symbols for %s...", name); |
646 | wrap_here (""); | |
199b2450 | 647 | gdb_flush (gdb_stdout); |
318bf84f | 648 | } |
9342ecb9 JG |
649 | init_entry_point_info (objfile); |
650 | find_sym_fns (objfile); | |
d47d5315 | 651 | } |
318bf84f | 652 | else |
bd5635a1 | 653 | { |
80d68b1d | 654 | /* We either created a new mapped symbol table, mapped an existing |
bf349b77 FF |
655 | symbol table file which has not had initial symbol reading |
656 | performed, or need to read an unmapped symbol table. */ | |
318bf84f FF |
657 | if (from_tty || info_verbose) |
658 | { | |
659 | printf_filtered ("Reading symbols from %s...", name); | |
660 | wrap_here (""); | |
199b2450 | 661 | gdb_flush (gdb_stdout); |
318bf84f | 662 | } |
318bf84f | 663 | syms_from_objfile (objfile, addr, mainline, from_tty); |
80d68b1d FF |
664 | } |
665 | ||
666 | /* We now have at least a partial symbol table. Check to see if the | |
667 | user requested that all symbols be read on initial access via either | |
668 | the gdb startup command line or on a per symbol file basis. Expand | |
669 | all partial symbol tables for this objfile if so. */ | |
b0246b3b | 670 | |
bf349b77 | 671 | if (readnow || readnow_symbol_files) |
80d68b1d | 672 | { |
318bf84f FF |
673 | if (from_tty || info_verbose) |
674 | { | |
80d68b1d FF |
675 | printf_filtered ("expanding to full symbols..."); |
676 | wrap_here (""); | |
199b2450 | 677 | gdb_flush (gdb_stdout); |
318bf84f | 678 | } |
80d68b1d FF |
679 | |
680 | for (psymtab = objfile -> psymtabs; | |
681 | psymtab != NULL; | |
682 | psymtab = psymtab -> next) | |
683 | { | |
4ed3a9ea | 684 | psymtab_to_symtab (psymtab); |
80d68b1d FF |
685 | } |
686 | } | |
687 | ||
688 | if (from_tty || info_verbose) | |
689 | { | |
690 | printf_filtered ("done.\n"); | |
199b2450 | 691 | gdb_flush (gdb_stdout); |
bd5635a1 | 692 | } |
80d68b1d | 693 | |
ade40d31 | 694 | new_symfile_objfile (objfile, mainline, from_tty); |
ade40d31 | 695 | |
012be3ce DP |
696 | target_new_objfile (objfile); |
697 | ||
30875e1c | 698 | return (objfile); |
bd5635a1 RP |
699 | } |
700 | ||
2e6784a8 SG |
701 | /* This is the symbol-file command. Read the file, analyze its |
702 | symbols, and add a struct symtab to a symtab list. The syntax of | |
703 | the command is rather bizarre--(1) buildargv implements various | |
704 | quoting conventions which are undocumented and have little or | |
705 | nothing in common with the way things are quoted (or not quoted) | |
706 | elsewhere in GDB, (2) options are used, which are not generally | |
707 | used in GDB (perhaps "set mapped on", "set readnow on" would be | |
708 | better), (3) the order of options matters, which is contrary to GNU | |
709 | conventions (because it is confusing and inconvenient). */ | |
bd5635a1 RP |
710 | |
711 | void | |
30875e1c SG |
712 | symbol_file_command (args, from_tty) |
713 | char *args; | |
bd5635a1 RP |
714 | int from_tty; |
715 | { | |
30875e1c | 716 | char **argv; |
b0246b3b | 717 | char *name = NULL; |
25200748 | 718 | CORE_ADDR text_relocation = 0; /* text_relocation */ |
30875e1c | 719 | struct cleanup *cleanups; |
318bf84f | 720 | int mapped = 0; |
30875e1c | 721 | int readnow = 0; |
bd5635a1 RP |
722 | |
723 | dont_repeat (); | |
724 | ||
30875e1c | 725 | if (args == NULL) |
bd5635a1 | 726 | { |
cba0d141 JG |
727 | if ((have_full_symbols () || have_partial_symbols ()) |
728 | && from_tty | |
729 | && !query ("Discard symbol table from `%s'? ", | |
730 | symfile_objfile -> name)) | |
731 | error ("Not confirmed."); | |
732 | free_all_objfiles (); | |
30875e1c | 733 | symfile_objfile = NULL; |
9342ecb9 JG |
734 | if (from_tty) |
735 | { | |
199b2450 | 736 | printf_unfiltered ("No symbol file now.\n"); |
9342ecb9 | 737 | } |
bd5635a1 | 738 | } |
30875e1c SG |
739 | else |
740 | { | |
741 | if ((argv = buildargv (args)) == NULL) | |
742 | { | |
318bf84f | 743 | nomem (0); |
30875e1c SG |
744 | } |
745 | cleanups = make_cleanup (freeargv, (char *) argv); | |
b0246b3b | 746 | while (*argv != NULL) |
30875e1c | 747 | { |
2e4964ad | 748 | if (STREQ (*argv, "-mapped")) |
30875e1c | 749 | { |
318bf84f | 750 | mapped = 1; |
30875e1c | 751 | } |
2e4964ad | 752 | else if (STREQ (*argv, "-readnow")) |
30875e1c SG |
753 | { |
754 | readnow = 1; | |
755 | } | |
b0246b3b FF |
756 | else if (**argv == '-') |
757 | { | |
758 | error ("unknown option `%s'", *argv); | |
759 | } | |
760 | else | |
761 | { | |
d9389f37 KH |
762 | char *p; |
763 | ||
764 | name = *argv; | |
765 | ||
766 | /* this is for rombug remote only, to get the text relocation by | |
767 | using link command */ | |
768 | p = strrchr(name, '/'); | |
769 | if (p != NULL) p++; | |
770 | else p = name; | |
771 | ||
772 | target_link(p, &text_relocation); | |
773 | ||
774 | if (text_relocation == (CORE_ADDR)0) | |
775 | return; | |
776 | else if (text_relocation == (CORE_ADDR)-1) | |
d5412302 JK |
777 | symbol_file_add (name, from_tty, (CORE_ADDR)0, 1, mapped, |
778 | readnow); | |
d9389f37 | 779 | else |
d5412302 JK |
780 | symbol_file_add (name, from_tty, (CORE_ADDR)text_relocation, |
781 | 0, mapped, readnow); | |
76212295 PS |
782 | |
783 | /* Getting new symbols may change our opinion about what is | |
784 | frameless. */ | |
785 | reinit_frame_cache (); | |
786 | ||
d9389f37 | 787 | set_initial_language (); |
b0246b3b FF |
788 | } |
789 | argv++; | |
30875e1c | 790 | } |
2403f49b | 791 | |
b0246b3b FF |
792 | if (name == NULL) |
793 | { | |
794 | error ("no symbol file name was specified"); | |
795 | } | |
30875e1c SG |
796 | do_cleanups (cleanups); |
797 | } | |
bd5635a1 RP |
798 | } |
799 | ||
e58de8a2 FF |
800 | /* Set the initial language. |
801 | ||
802 | A better solution would be to record the language in the psymtab when reading | |
803 | partial symbols, and then use it (if known) to set the language. This would | |
804 | be a win for formats that encode the language in an easily discoverable place, | |
805 | such as DWARF. For stabs, we can jump through hoops looking for specially | |
806 | named symbols or try to intuit the language from the specific type of stabs | |
807 | we find, but we can't do that until later when we read in full symbols. | |
808 | FIXME. */ | |
809 | ||
810 | static void | |
811 | set_initial_language () | |
812 | { | |
813 | struct partial_symtab *pst; | |
814 | enum language lang = language_unknown; | |
815 | ||
816 | pst = find_main_psymtab (); | |
817 | if (pst != NULL) | |
818 | { | |
819 | if (pst -> filename != NULL) | |
820 | { | |
821 | lang = deduce_language_from_filename (pst -> filename); | |
822 | } | |
823 | if (lang == language_unknown) | |
824 | { | |
825 | /* Make C the default language */ | |
826 | lang = language_c; | |
827 | } | |
828 | set_language (lang); | |
829 | expected_language = current_language; /* Don't warn the user */ | |
830 | } | |
831 | } | |
832 | ||
b0246b3b FF |
833 | /* Open file specified by NAME and hand it off to BFD for preliminary |
834 | analysis. Result is a newly initialized bfd *, which includes a newly | |
835 | malloc'd` copy of NAME (tilde-expanded and made absolute). | |
7d9884b9 | 836 | In case of trouble, error() is called. */ |
bd5635a1 | 837 | |
b0246b3b FF |
838 | static bfd * |
839 | symfile_bfd_open (name) | |
bd5635a1 RP |
840 | char *name; |
841 | { | |
842 | bfd *sym_bfd; | |
843 | int desc; | |
844 | char *absolute_name; | |
845 | ||
7d9884b9 | 846 | name = tilde_expand (name); /* Returns 1st new malloc'd copy */ |
bd5635a1 | 847 | |
7d9884b9 | 848 | /* Look down path for it, allocate 2nd new malloc'd copy. */ |
2093fe68 | 849 | desc = openp (getenv ("PATH"), 1, name, O_RDONLY | O_BINARY, 0, &absolute_name); |
40b647e9 | 850 | #if defined(__GO32__) || defined(_WIN32) |
3f17fed8 GN |
851 | if (desc < 0) |
852 | { | |
853 | char *exename = alloca (strlen (name) + 5); | |
854 | strcat (strcpy (exename, name), ".exe"); | |
855 | desc = openp (getenv ("PATH"), 1, exename, O_RDONLY | O_BINARY, | |
856 | 0, &absolute_name); | |
857 | } | |
858 | #endif | |
b0246b3b FF |
859 | if (desc < 0) |
860 | { | |
861 | make_cleanup (free, name); | |
862 | perror_with_name (name); | |
863 | } | |
7d9884b9 | 864 | free (name); /* Free 1st new malloc'd copy */ |
30875e1c | 865 | name = absolute_name; /* Keep 2nd malloc'd copy in bfd */ |
346168a2 | 866 | /* It'll be freed in free_objfile(). */ |
bd5635a1 | 867 | |
ade40d31 | 868 | sym_bfd = bfd_fdopenr (name, gnutarget, desc); |
bd5635a1 RP |
869 | if (!sym_bfd) |
870 | { | |
871 | close (desc); | |
7d9884b9 | 872 | make_cleanup (free, name); |
b0246b3b | 873 | error ("\"%s\": can't open to read symbols: %s.", name, |
c4a081e1 | 874 | bfd_errmsg (bfd_get_error ())); |
bd5635a1 | 875 | } |
e58de8a2 | 876 | sym_bfd->cacheable = true; |
bd5635a1 | 877 | |
b0246b3b FF |
878 | if (!bfd_check_format (sym_bfd, bfd_object)) |
879 | { | |
1a494973 C |
880 | /* FIXME: should be checking for errors from bfd_close (for one thing, |
881 | on error it does not free all the storage associated with the | |
882 | bfd). */ | |
b0246b3b FF |
883 | bfd_close (sym_bfd); /* This also closes desc */ |
884 | make_cleanup (free, name); | |
885 | error ("\"%s\": can't read symbols: %s.", name, | |
c4a081e1 | 886 | bfd_errmsg (bfd_get_error ())); |
b0246b3b | 887 | } |
7d9884b9 | 888 | |
b0246b3b | 889 | return (sym_bfd); |
7d9884b9 JG |
890 | } |
891 | ||
80d68b1d FF |
892 | /* Link a new symtab_fns into the global symtab_fns list. Called on gdb |
893 | startup by the _initialize routine in each object file format reader, | |
894 | to register information about each format the the reader is prepared | |
895 | to handle. */ | |
bd5635a1 RP |
896 | |
897 | void | |
898 | add_symtab_fns (sf) | |
899 | struct sym_fns *sf; | |
900 | { | |
901 | sf->next = symtab_fns; | |
902 | symtab_fns = sf; | |
903 | } | |
904 | ||
905 | ||
906 | /* Initialize to read symbols from the symbol file sym_bfd. It either | |
80d68b1d FF |
907 | returns or calls error(). The result is an initialized struct sym_fns |
908 | in the objfile structure, that contains cached information about the | |
909 | symbol file. */ | |
bd5635a1 | 910 | |
80d68b1d FF |
911 | static void |
912 | find_sym_fns (objfile) | |
7d9884b9 | 913 | struct objfile *objfile; |
bd5635a1 | 914 | { |
ac88ca20 | 915 | struct sym_fns *sf; |
0eed42de | 916 | enum bfd_flavour our_flavour = bfd_get_flavour (objfile -> obfd); |
c4a081e1 | 917 | char *our_target = bfd_get_target (objfile -> obfd); |
0eed42de | 918 | |
1750a5ef SC |
919 | /* Special kludge for RS/6000 and PowerMac. See xcoffread.c. */ |
920 | if (STREQ (our_target, "aixcoff-rs6000") || | |
921 | STREQ (our_target, "xcoff-powermac")) | |
0eed42de | 922 | our_flavour = (enum bfd_flavour)-1; |
bd5635a1 | 923 | |
c4a081e1 DM |
924 | /* Special kludge for apollo. See dstread.c. */ |
925 | if (STREQN (our_target, "apollo", 6)) | |
926 | our_flavour = (enum bfd_flavour)-2; | |
927 | ||
80d68b1d | 928 | for (sf = symtab_fns; sf != NULL; sf = sf -> next) |
bd5635a1 | 929 | { |
0eed42de | 930 | if (our_flavour == sf -> sym_flavour) |
bd5635a1 | 931 | { |
80d68b1d FF |
932 | objfile -> sf = sf; |
933 | return; | |
bd5635a1 RP |
934 | } |
935 | } | |
c9bd6710 | 936 | error ("I'm sorry, Dave, I can't do that. Symbol format `%s' unknown.", |
b0246b3b | 937 | bfd_get_target (objfile -> obfd)); |
bd5635a1 RP |
938 | } |
939 | \f | |
940 | /* This function runs the load command of our current target. */ | |
941 | ||
30875e1c | 942 | static void |
bd5635a1 RP |
943 | load_command (arg, from_tty) |
944 | char *arg; | |
945 | int from_tty; | |
946 | { | |
f3806e3b PS |
947 | if (arg == NULL) |
948 | arg = get_exec_file (1); | |
bd5635a1 RP |
949 | target_load (arg, from_tty); |
950 | } | |
951 | ||
ade40d31 RP |
952 | /* This version of "load" should be usable for any target. Currently |
953 | it is just used for remote targets, not inftarg.c or core files, | |
954 | on the theory that only in that case is it useful. | |
955 | ||
956 | Avoiding xmodem and the like seems like a win (a) because we don't have | |
957 | to worry about finding it, and (b) On VMS, fork() is very slow and so | |
958 | we don't want to run a subprocess. On the other hand, I'm not sure how | |
959 | performance compares. */ | |
960 | void | |
961 | generic_load (filename, from_tty) | |
962 | char *filename; | |
963 | int from_tty; | |
964 | { | |
965 | struct cleanup *old_cleanups; | |
966 | asection *s; | |
c4a081e1 | 967 | bfd *loadfile_bfd; |
b52cac6b | 968 | time_t start_time, end_time; /* Start and end times of download */ |
67c1413d | 969 | unsigned long data_count = 0; /* Number of bytes transferred to memory */ |
012be3ce DP |
970 | int n; |
971 | unsigned long load_offset = 0; /* offset to add to vma for each section */ | |
972 | char buf[128]; | |
973 | ||
974 | /* enable user to specify address for downloading as 2nd arg to load */ | |
b607efe7 | 975 | n = sscanf(filename, "%s 0x%lx", buf, &load_offset); |
012be3ce DP |
976 | if (n > 1 ) |
977 | filename = buf; | |
978 | else | |
979 | load_offset = 0; | |
c4a081e1 | 980 | |
c4a081e1 | 981 | loadfile_bfd = bfd_openr (filename, gnutarget); |
ade40d31 RP |
982 | if (loadfile_bfd == NULL) |
983 | { | |
984 | perror_with_name (filename); | |
985 | return; | |
986 | } | |
1a494973 C |
987 | /* FIXME: should be checking for errors from bfd_close (for one thing, |
988 | on error it does not free all the storage associated with the | |
989 | bfd). */ | |
ade40d31 RP |
990 | old_cleanups = make_cleanup (bfd_close, loadfile_bfd); |
991 | ||
992 | if (!bfd_check_format (loadfile_bfd, bfd_object)) | |
993 | { | |
994 | error ("\"%s\" is not an object file: %s", filename, | |
c4a081e1 | 995 | bfd_errmsg (bfd_get_error ())); |
ade40d31 RP |
996 | } |
997 | ||
b52cac6b FF |
998 | start_time = time (NULL); |
999 | ||
ade40d31 RP |
1000 | for (s = loadfile_bfd->sections; s; s = s->next) |
1001 | { | |
1002 | if (s->flags & SEC_LOAD) | |
77636dea FF |
1003 | { |
1004 | bfd_size_type size; | |
1005 | ||
1006 | size = bfd_get_section_size_before_reloc (s); | |
1007 | if (size > 0) | |
1008 | { | |
1009 | char *buffer; | |
1010 | struct cleanup *old_chain; | |
1011 | bfd_vma lma; | |
1012 | unsigned long l = size / 100; | |
1013 | int err; | |
1014 | char *sect; | |
1015 | unsigned long sent; | |
1016 | unsigned long len; | |
1017 | ||
1018 | l = l > 100 ? l : 100; | |
1019 | data_count += size; | |
1020 | ||
1021 | buffer = xmalloc (size); | |
1022 | old_chain = make_cleanup (free, buffer); | |
1023 | ||
1024 | lma = s->lma; | |
1025 | lma += load_offset; | |
1026 | ||
1027 | /* Is this really necessary? I guess it gives the user something | |
1028 | to look at during a long download. */ | |
1029 | printf_filtered ("Loading section %s, size 0x%lx lma ", | |
1030 | bfd_get_section_name (loadfile_bfd, s), | |
1031 | (unsigned long) size); | |
1032 | print_address_numeric (lma, 1, gdb_stdout); | |
1033 | printf_filtered ("\n"); | |
1034 | ||
1035 | bfd_get_section_contents (loadfile_bfd, s, buffer, 0, size); | |
1036 | ||
1037 | sect = bfd_get_section_name (loadfile_bfd, s); | |
1038 | sent = 0; | |
1039 | do | |
1040 | { | |
1041 | len = (size - sent) < l ? (size - sent) : l; | |
1042 | sent += len; | |
1043 | err = target_write_memory (lma, buffer, len); | |
1044 | if (ui_load_progress_hook) | |
1045 | if (ui_load_progress_hook (sect, sent)) | |
1046 | error ("Canceled the download"); | |
1047 | lma += len; | |
1048 | buffer += len; | |
1049 | } | |
1050 | while (err == 0 && sent < size); | |
1051 | ||
1052 | if (err != 0) | |
1053 | error ("Memory access error while loading section %s.", | |
1054 | bfd_get_section_name (loadfile_bfd, s)); | |
1055 | ||
1056 | do_cleanups (old_chain); | |
1057 | } | |
1058 | } | |
ade40d31 RP |
1059 | } |
1060 | ||
b52cac6b FF |
1061 | end_time = time (NULL); |
1062 | ||
012be3ce DP |
1063 | printf_filtered ("Start address 0x%lx\n", loadfile_bfd->start_address); |
1064 | ||
ade40d31 RP |
1065 | /* We were doing this in remote-mips.c, I suspect it is right |
1066 | for other targets too. */ | |
1067 | write_pc (loadfile_bfd->start_address); | |
1068 | ||
1069 | /* FIXME: are we supposed to call symbol_file_add or not? According to | |
1070 | a comment from remote-mips.c (where a call to symbol_file_add was | |
1071 | commented out), making the call confuses GDB if more than one file is | |
1072 | loaded in. remote-nindy.c had no call to symbol_file_add, but remote-vx.c | |
1073 | does. */ | |
1074 | ||
72158e71 | 1075 | report_transfer_performance (data_count, start_time, end_time); |
b52cac6b | 1076 | |
ade40d31 RP |
1077 | do_cleanups (old_cleanups); |
1078 | } | |
1079 | ||
72158e71 SS |
1080 | /* Report how fast the transfer went. */ |
1081 | ||
1082 | void | |
1083 | report_transfer_performance (data_count, start_time, end_time) | |
1084 | unsigned long data_count; | |
1085 | time_t start_time, end_time; | |
1086 | { | |
1087 | printf_filtered ("Transfer rate: "); | |
1088 | if (end_time != start_time) | |
1089 | printf_filtered ("%d bits/sec", | |
1090 | (data_count * 8) / (end_time - start_time)); | |
1091 | else | |
1092 | printf_filtered ("%d bits in <1 sec", (data_count * 8)); | |
1093 | printf_filtered (".\n"); | |
1094 | } | |
1095 | ||
61a7292f SG |
1096 | /* This function allows the addition of incrementally linked object files. |
1097 | It does not modify any state in the target, only in the debugger. */ | |
bd5635a1 | 1098 | |
e1ce8aa5 | 1099 | /* ARGSUSED */ |
30875e1c | 1100 | static void |
b0246b3b FF |
1101 | add_symbol_file_command (args, from_tty) |
1102 | char *args; | |
bd5635a1 RP |
1103 | int from_tty; |
1104 | { | |
b0246b3b | 1105 | char *name = NULL; |
bd5635a1 | 1106 | CORE_ADDR text_addr; |
b0246b3b | 1107 | char *arg; |
ac88ca20 JG |
1108 | int readnow = 0; |
1109 | int mapped = 0; | |
bd5635a1 | 1110 | |
b0246b3b | 1111 | dont_repeat (); |
61a7292f | 1112 | |
b0246b3b FF |
1113 | if (args == NULL) |
1114 | { | |
1115 | error ("add-symbol-file takes a file name and an address"); | |
1116 | } | |
bd5635a1 | 1117 | |
b0246b3b | 1118 | /* Make a copy of the string that we can safely write into. */ |
bd5635a1 | 1119 | |
b0246b3b FF |
1120 | args = strdup (args); |
1121 | make_cleanup (free, args); | |
1122 | ||
1123 | /* Pick off any -option args and the file name. */ | |
1124 | ||
1125 | while ((*args != '\000') && (name == NULL)) | |
1126 | { | |
1127 | while (isspace (*args)) {args++;} | |
1128 | arg = args; | |
1129 | while ((*args != '\000') && !isspace (*args)) {args++;} | |
1130 | if (*args != '\000') | |
1131 | { | |
1132 | *args++ = '\000'; | |
1133 | } | |
1134 | if (*arg != '-') | |
1135 | { | |
1136 | name = arg; | |
1137 | } | |
2e4964ad | 1138 | else if (STREQ (arg, "-mapped")) |
b0246b3b FF |
1139 | { |
1140 | mapped = 1; | |
1141 | } | |
2e4964ad | 1142 | else if (STREQ (arg, "-readnow")) |
b0246b3b FF |
1143 | { |
1144 | readnow = 1; | |
1145 | } | |
1146 | else | |
1147 | { | |
1148 | error ("unknown option `%s'", arg); | |
1149 | } | |
1150 | } | |
bd5635a1 | 1151 | |
b0246b3b FF |
1152 | /* After picking off any options and the file name, args should be |
1153 | left pointing at the remainder of the command line, which should | |
1154 | be the address expression to evaluate. */ | |
bd5635a1 | 1155 | |
1340861c | 1156 | if (name == NULL) |
b0246b3b | 1157 | { |
1340861c | 1158 | error ("add-symbol-file takes a file name"); |
b0246b3b FF |
1159 | } |
1160 | name = tilde_expand (name); | |
1161 | make_cleanup (free, name); | |
bd5635a1 | 1162 | |
1340861c KH |
1163 | if (*args != '\000') |
1164 | { | |
1165 | text_addr = parse_and_eval_address (args); | |
1166 | } | |
1167 | else | |
1168 | { | |
1169 | target_link(name, &text_addr); | |
1170 | if (text_addr == (CORE_ADDR)-1) | |
1171 | error("Don't know how to get text start location for this file"); | |
1172 | } | |
bd5635a1 | 1173 | |
c4a081e1 | 1174 | /* FIXME-32x64: Assumes text_addr fits in a long. */ |
d8ce1326 | 1175 | if (!query ("add symbol table from file \"%s\" at text_addr = %s?\n", |
4d57c599 | 1176 | name, local_hex_string ((unsigned long)text_addr))) |
bd5635a1 RP |
1177 | error ("Not confirmed."); |
1178 | ||
4ed3a9ea | 1179 | symbol_file_add (name, 0, text_addr, 0, mapped, readnow); |
76212295 PS |
1180 | |
1181 | /* Getting new symbols may change our opinion about what is | |
1182 | frameless. */ | |
1183 | reinit_frame_cache (); | |
bd5635a1 RP |
1184 | } |
1185 | \f | |
f3806e3b PS |
1186 | static void |
1187 | add_shared_symbol_files_command (args, from_tty) | |
1188 | char *args; | |
1189 | int from_tty; | |
1190 | { | |
1191 | #ifdef ADD_SHARED_SYMBOL_FILES | |
1192 | ADD_SHARED_SYMBOL_FILES (args, from_tty); | |
1193 | #else | |
1194 | error ("This command is not available in this configuration of GDB."); | |
1195 | #endif | |
1196 | } | |
1197 | \f | |
7d9884b9 | 1198 | /* Re-read symbols if a symbol-file has changed. */ |
bd5635a1 RP |
1199 | void |
1200 | reread_symbols () | |
1201 | { | |
7d9884b9 JG |
1202 | struct objfile *objfile; |
1203 | long new_modtime; | |
1204 | int reread_one = 0; | |
cba0d141 JG |
1205 | struct stat new_statbuf; |
1206 | int res; | |
bd5635a1 RP |
1207 | |
1208 | /* With the addition of shared libraries, this should be modified, | |
1209 | the load time should be saved in the partial symbol tables, since | |
1210 | different tables may come from different source files. FIXME. | |
1211 | This routine should then walk down each partial symbol table | |
30875e1c | 1212 | and see if the symbol table that it originates from has been changed */ |
bd5635a1 | 1213 | |
7d9884b9 JG |
1214 | for (objfile = object_files; objfile; objfile = objfile->next) { |
1215 | if (objfile->obfd) { | |
1eeba686 | 1216 | #ifdef IBM6000_TARGET |
318bf84f FF |
1217 | /* If this object is from a shared library, then you should |
1218 | stat on the library name, not member name. */ | |
1219 | ||
1220 | if (objfile->obfd->my_archive) | |
1221 | res = stat (objfile->obfd->my_archive->filename, &new_statbuf); | |
1222 | else | |
1223 | #endif | |
cba0d141 JG |
1224 | res = stat (objfile->name, &new_statbuf); |
1225 | if (res != 0) { | |
1226 | /* FIXME, should use print_sys_errmsg but it's not filtered. */ | |
1227 | printf_filtered ("`%s' has disappeared; keeping its symbols.\n", | |
1228 | objfile->name); | |
1229 | continue; | |
1230 | } | |
1231 | new_modtime = new_statbuf.st_mtime; | |
4d57c599 JK |
1232 | if (new_modtime != objfile->mtime) |
1233 | { | |
1234 | struct cleanup *old_cleanups; | |
1235 | struct section_offsets *offsets; | |
1236 | int num_offsets; | |
1237 | int section_offsets_size; | |
76212295 | 1238 | char *obfd_filename; |
4d57c599 JK |
1239 | |
1240 | printf_filtered ("`%s' has changed; re-reading symbols.\n", | |
1241 | objfile->name); | |
1242 | ||
1243 | /* There are various functions like symbol_file_add, | |
1244 | symfile_bfd_open, syms_from_objfile, etc., which might | |
1245 | appear to do what we want. But they have various other | |
1246 | effects which we *don't* want. So we just do stuff | |
1247 | ourselves. We don't worry about mapped files (for one thing, | |
1248 | any mapped file will be out of date). */ | |
1249 | ||
1250 | /* If we get an error, blow away this objfile (not sure if | |
1251 | that is the correct response for things like shared | |
1252 | libraries). */ | |
1253 | old_cleanups = make_cleanup (free_objfile, objfile); | |
1254 | /* We need to do this whenever any symbols go away. */ | |
1255 | make_cleanup (clear_symtab_users, 0); | |
1256 | ||
1257 | /* Clean up any state BFD has sitting around. We don't need | |
1258 | to close the descriptor but BFD lacks a way of closing the | |
1259 | BFD without closing the descriptor. */ | |
76212295 | 1260 | obfd_filename = bfd_get_filename (objfile->obfd); |
4d57c599 | 1261 | if (!bfd_close (objfile->obfd)) |
1a494973 C |
1262 | error ("Can't close BFD for %s: %s", objfile->name, |
1263 | bfd_errmsg (bfd_get_error ())); | |
76212295 | 1264 | objfile->obfd = bfd_openr (obfd_filename, gnutarget); |
4d57c599 JK |
1265 | if (objfile->obfd == NULL) |
1266 | error ("Can't open %s to read symbols.", objfile->name); | |
1267 | /* bfd_openr sets cacheable to true, which is what we want. */ | |
1268 | if (!bfd_check_format (objfile->obfd, bfd_object)) | |
1269 | error ("Can't read symbols from %s: %s.", objfile->name, | |
c4a081e1 | 1270 | bfd_errmsg (bfd_get_error ())); |
4d57c599 JK |
1271 | |
1272 | /* Save the offsets, we will nuke them with the rest of the | |
1273 | psymbol_obstack. */ | |
1274 | num_offsets = objfile->num_sections; | |
1275 | section_offsets_size = | |
1276 | sizeof (struct section_offsets) | |
1277 | + sizeof (objfile->section_offsets->offsets) * num_offsets; | |
1278 | offsets = (struct section_offsets *) alloca (section_offsets_size); | |
1279 | memcpy (offsets, objfile->section_offsets, section_offsets_size); | |
1280 | ||
1281 | /* Nuke all the state that we will re-read. Much of the following | |
1282 | code which sets things to NULL really is necessary to tell | |
1283 | other parts of GDB that there is nothing currently there. */ | |
1284 | ||
1285 | /* FIXME: Do we have to free a whole linked list, or is this | |
1286 | enough? */ | |
1287 | if (objfile->global_psymbols.list) | |
1288 | mfree (objfile->md, objfile->global_psymbols.list); | |
b52cac6b FF |
1289 | memset (&objfile -> global_psymbols, 0, |
1290 | sizeof (objfile -> global_psymbols)); | |
4d57c599 JK |
1291 | if (objfile->static_psymbols.list) |
1292 | mfree (objfile->md, objfile->static_psymbols.list); | |
b52cac6b FF |
1293 | memset (&objfile -> static_psymbols, 0, |
1294 | sizeof (objfile -> static_psymbols)); | |
4d57c599 JK |
1295 | |
1296 | /* Free the obstacks for non-reusable objfiles */ | |
2ad5709f | 1297 | obstack_free (&objfile -> psymbol_cache.cache, 0); |
b52cac6b FF |
1298 | memset (&objfile -> psymbol_cache, 0, |
1299 | sizeof (objfile -> psymbol_cache)); | |
4d57c599 JK |
1300 | obstack_free (&objfile -> psymbol_obstack, 0); |
1301 | obstack_free (&objfile -> symbol_obstack, 0); | |
1302 | obstack_free (&objfile -> type_obstack, 0); | |
1303 | objfile->sections = NULL; | |
1304 | objfile->symtabs = NULL; | |
1305 | objfile->psymtabs = NULL; | |
1306 | objfile->free_psymtabs = NULL; | |
1307 | objfile->msymbols = NULL; | |
1308 | objfile->minimal_symbol_count= 0; | |
1309 | objfile->fundamental_types = NULL; | |
1310 | if (objfile -> sf != NULL) | |
1311 | { | |
1312 | (*objfile -> sf -> sym_finish) (objfile); | |
1313 | } | |
1314 | ||
1315 | /* We never make this a mapped file. */ | |
1316 | objfile -> md = NULL; | |
1317 | /* obstack_specify_allocation also initializes the obstack so | |
1318 | it is empty. */ | |
2ad5709f FF |
1319 | obstack_specify_allocation (&objfile -> psymbol_cache.cache, 0, 0, |
1320 | xmalloc, free); | |
4d57c599 JK |
1321 | obstack_specify_allocation (&objfile -> psymbol_obstack, 0, 0, |
1322 | xmalloc, free); | |
1323 | obstack_specify_allocation (&objfile -> symbol_obstack, 0, 0, | |
1324 | xmalloc, free); | |
1325 | obstack_specify_allocation (&objfile -> type_obstack, 0, 0, | |
1326 | xmalloc, free); | |
1327 | if (build_objfile_section_table (objfile)) | |
1328 | { | |
1329 | error ("Can't find the file sections in `%s': %s", | |
c4a081e1 | 1330 | objfile -> name, bfd_errmsg (bfd_get_error ())); |
4d57c599 JK |
1331 | } |
1332 | ||
1333 | /* We use the same section offsets as from last time. I'm not | |
1334 | sure whether that is always correct for shared libraries. */ | |
1335 | objfile->section_offsets = (struct section_offsets *) | |
1336 | obstack_alloc (&objfile -> psymbol_obstack, section_offsets_size); | |
1337 | memcpy (objfile->section_offsets, offsets, section_offsets_size); | |
1338 | objfile->num_sections = num_offsets; | |
1339 | ||
1340 | /* What the hell is sym_new_init for, anyway? The concept of | |
1341 | distinguishing between the main file and additional files | |
1342 | in this way seems rather dubious. */ | |
1343 | if (objfile == symfile_objfile) | |
1344 | (*objfile->sf->sym_new_init) (objfile); | |
1345 | ||
1346 | (*objfile->sf->sym_init) (objfile); | |
1347 | clear_complaints (1, 1); | |
1348 | /* The "mainline" parameter is a hideous hack; I think leaving it | |
1349 | zero is OK since dbxread.c also does what it needs to do if | |
1350 | objfile->global_psymbols.size is 0. */ | |
1351 | (*objfile->sf->sym_read) (objfile, objfile->section_offsets, 0); | |
f3806e3b PS |
1352 | if (!have_partial_symbols () && !have_full_symbols ()) |
1353 | { | |
1354 | wrap_here (""); | |
1355 | printf_filtered ("(no debugging symbols found)\n"); | |
1356 | wrap_here (""); | |
1357 | } | |
4d57c599 JK |
1358 | objfile -> flags |= OBJF_SYMS; |
1359 | ||
1360 | /* We're done reading the symbol file; finish off complaints. */ | |
1361 | clear_complaints (0, 1); | |
1362 | ||
1363 | /* Getting new symbols may change our opinion about what is | |
1364 | frameless. */ | |
1365 | ||
1366 | reinit_frame_cache (); | |
1367 | ||
1368 | /* Discard cleanups as symbol reading was successful. */ | |
1369 | discard_cleanups (old_cleanups); | |
1370 | ||
1371 | /* If the mtime has changed between the time we set new_modtime | |
1372 | and now, we *want* this to be out of date, so don't call stat | |
1373 | again now. */ | |
1374 | objfile->mtime = new_modtime; | |
1375 | reread_one = 1; | |
dee7a11c FF |
1376 | |
1377 | /* Call this after reading in a new symbol table to give target | |
1378 | dependant code a crack at the new symbols. For instance, this | |
1379 | could be used to update the values of target-specific symbols GDB | |
1380 | needs to keep track of (such as _sigtramp, or whatever). */ | |
1381 | ||
1382 | TARGET_SYMFILE_POSTREAD (objfile); | |
4d57c599 | 1383 | } |
bd5635a1 | 1384 | } |
7d9884b9 JG |
1385 | } |
1386 | ||
1387 | if (reread_one) | |
4d57c599 | 1388 | clear_symtab_users (); |
bd5635a1 | 1389 | } |
bd5635a1 | 1390 | |
bd5635a1 | 1391 | \f |
7d9884b9 JG |
1392 | enum language |
1393 | deduce_language_from_filename (filename) | |
1394 | char *filename; | |
1395 | { | |
2093fe68 | 1396 | char *c; |
7d9884b9 | 1397 | |
2093fe68 RP |
1398 | if (0 == filename) |
1399 | ; /* Get default */ | |
1400 | else if (0 == (c = strrchr (filename, '.'))) | |
1401 | ; /* Get default. */ | |
f3806e3b | 1402 | else if (STREQ (c, ".c")) |
2093fe68 | 1403 | return language_c; |
f3806e3b | 1404 | else if (STREQ (c, ".cc") || STREQ (c, ".C") || STREQ (c, ".cxx") |
1a494973 | 1405 | || STREQ (c, ".cpp") || STREQ (c, ".cp") || STREQ (c, ".c++")) |
2093fe68 | 1406 | return language_cplus; |
40b647e9 FF |
1407 | else if (STREQ (c, ".java")) |
1408 | return language_java; | |
f3806e3b | 1409 | else if (STREQ (c, ".ch") || STREQ (c, ".c186") || STREQ (c, ".c286")) |
2093fe68 | 1410 | return language_chill; |
76212295 PS |
1411 | else if (STREQ (c, ".f") || STREQ (c, ".F")) |
1412 | return language_fortran; | |
f3806e3b PS |
1413 | else if (STREQ (c, ".mod")) |
1414 | return language_m2; | |
1415 | else if (STREQ (c, ".s") || STREQ (c, ".S")) | |
1416 | return language_asm; | |
7d9884b9 JG |
1417 | |
1418 | return language_unknown; /* default */ | |
1419 | } | |
1420 | \f | |
d8ce1326 JG |
1421 | /* allocate_symtab: |
1422 | ||
1423 | Allocate and partly initialize a new symbol table. Return a pointer | |
1424 | to it. error() if no space. | |
1425 | ||
1426 | Caller must set these fields: | |
1427 | LINETABLE(symtab) | |
1428 | symtab->blockvector | |
d8ce1326 JG |
1429 | symtab->dirname |
1430 | symtab->free_code | |
1431 | symtab->free_ptr | |
1432 | initialize any EXTRA_SYMTAB_INFO | |
1433 | possibly free_named_symtabs (symtab->filename); | |
d8ce1326 JG |
1434 | */ |
1435 | ||
1436 | struct symtab * | |
30875e1c SG |
1437 | allocate_symtab (filename, objfile) |
1438 | char *filename; | |
1439 | struct objfile *objfile; | |
d8ce1326 JG |
1440 | { |
1441 | register struct symtab *symtab; | |
d8ce1326 | 1442 | |
30875e1c SG |
1443 | symtab = (struct symtab *) |
1444 | obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symtab)); | |
4ed3a9ea | 1445 | memset (symtab, 0, sizeof (*symtab)); |
30875e1c SG |
1446 | symtab -> filename = obsavestring (filename, strlen (filename), |
1447 | &objfile -> symbol_obstack); | |
1448 | symtab -> fullname = NULL; | |
1449 | symtab -> language = deduce_language_from_filename (filename); | |
77636dea FF |
1450 | symtab -> debugformat = obsavestring ("unknown", 7, |
1451 | &objfile -> symbol_obstack); | |
d8ce1326 | 1452 | |
7d9884b9 | 1453 | /* Hook it to the objfile it comes from */ |
30875e1c SG |
1454 | |
1455 | symtab -> objfile = objfile; | |
1456 | symtab -> next = objfile -> symtabs; | |
1457 | objfile -> symtabs = symtab; | |
7d9884b9 JG |
1458 | |
1459 | #ifdef INIT_EXTRA_SYMTAB_INFO | |
30875e1c | 1460 | INIT_EXTRA_SYMTAB_INFO (symtab); |
7d9884b9 | 1461 | #endif |
d8ce1326 | 1462 | |
30875e1c | 1463 | return (symtab); |
d8ce1326 | 1464 | } |
30875e1c SG |
1465 | |
1466 | struct partial_symtab * | |
1467 | allocate_psymtab (filename, objfile) | |
1468 | char *filename; | |
1469 | struct objfile *objfile; | |
1470 | { | |
1471 | struct partial_symtab *psymtab; | |
1472 | ||
cba0d141 JG |
1473 | if (objfile -> free_psymtabs) |
1474 | { | |
1475 | psymtab = objfile -> free_psymtabs; | |
1476 | objfile -> free_psymtabs = psymtab -> next; | |
1477 | } | |
1478 | else | |
1479 | psymtab = (struct partial_symtab *) | |
1480 | obstack_alloc (&objfile -> psymbol_obstack, | |
1481 | sizeof (struct partial_symtab)); | |
1482 | ||
4ed3a9ea | 1483 | memset (psymtab, 0, sizeof (struct partial_symtab)); |
30875e1c SG |
1484 | psymtab -> filename = obsavestring (filename, strlen (filename), |
1485 | &objfile -> psymbol_obstack); | |
1486 | psymtab -> symtab = NULL; | |
1487 | ||
77636dea FF |
1488 | /* Prepend it to the psymtab list for the objfile it belongs to. |
1489 | Psymtabs are searched in most recent inserted -> least recent | |
1490 | inserted order. */ | |
30875e1c SG |
1491 | |
1492 | psymtab -> objfile = objfile; | |
1493 | psymtab -> next = objfile -> psymtabs; | |
1494 | objfile -> psymtabs = psymtab; | |
77636dea FF |
1495 | #if 0 |
1496 | { | |
1497 | struct partial_symtab **prev_pst; | |
1498 | psymtab -> objfile = objfile; | |
1499 | psymtab -> next = NULL; | |
1500 | prev_pst = &(objfile -> psymtabs); | |
1501 | while ((*prev_pst) != NULL) | |
1502 | prev_pst = &((*prev_pst) -> next); | |
1503 | (*prev_pst) = psymtab; | |
1504 | } | |
1505 | #endif | |
30875e1c SG |
1506 | |
1507 | return (psymtab); | |
1508 | } | |
1509 | ||
77636dea FF |
1510 | void |
1511 | discard_psymtab (pst) | |
1512 | struct partial_symtab *pst; | |
1513 | { | |
1514 | struct partial_symtab **prev_pst; | |
1515 | ||
1516 | /* From dbxread.c: | |
1517 | Empty psymtabs happen as a result of header files which don't | |
1518 | have any symbols in them. There can be a lot of them. But this | |
1519 | check is wrong, in that a psymtab with N_SLINE entries but | |
1520 | nothing else is not empty, but we don't realize that. Fixing | |
1521 | that without slowing things down might be tricky. */ | |
1522 | ||
1523 | /* First, snip it out of the psymtab chain */ | |
1524 | ||
1525 | prev_pst = &(pst->objfile->psymtabs); | |
1526 | while ((*prev_pst) != pst) | |
1527 | prev_pst = &((*prev_pst)->next); | |
1528 | (*prev_pst) = pst->next; | |
1529 | ||
1530 | /* Next, put it on a free list for recycling */ | |
1531 | ||
1532 | pst->next = pst->objfile->free_psymtabs; | |
1533 | pst->objfile->free_psymtabs = pst; | |
1534 | } | |
1535 | ||
d8ce1326 | 1536 | \f |
ade40d31 | 1537 | /* Reset all data structures in gdb which may contain references to symbol |
40b647e9 | 1538 | table data. */ |
ade40d31 RP |
1539 | |
1540 | void | |
1541 | clear_symtab_users () | |
1542 | { | |
1543 | /* Someday, we should do better than this, by only blowing away | |
1544 | the things that really need to be blown. */ | |
1545 | clear_value_history (); | |
1546 | clear_displays (); | |
1547 | clear_internalvars (); | |
1548 | breakpoint_re_set (); | |
1549 | set_default_breakpoint (0, 0, 0, 0); | |
1550 | current_source_symtab = 0; | |
1551 | current_source_line = 0; | |
4d57c599 | 1552 | clear_pc_function_cache (); |
012be3ce | 1553 | target_new_objfile (NULL); |
ade40d31 RP |
1554 | } |
1555 | ||
9d199712 JG |
1556 | /* clear_symtab_users_once: |
1557 | ||
1558 | This function is run after symbol reading, or from a cleanup. | |
1559 | If an old symbol table was obsoleted, the old symbol table | |
1560 | has been blown away, but the other GDB data structures that may | |
1561 | reference it have not yet been cleared or re-directed. (The old | |
1562 | symtab was zapped, and the cleanup queued, in free_named_symtab() | |
1563 | below.) | |
1564 | ||
1565 | This function can be queued N times as a cleanup, or called | |
1566 | directly; it will do all the work the first time, and then will be a | |
1567 | no-op until the next time it is queued. This works by bumping a | |
1568 | counter at queueing time. Much later when the cleanup is run, or at | |
1569 | the end of symbol processing (in case the cleanup is discarded), if | |
1570 | the queued count is greater than the "done-count", we do the work | |
1571 | and set the done-count to the queued count. If the queued count is | |
1572 | less than or equal to the done-count, we just ignore the call. This | |
1573 | is needed because reading a single .o file will often replace many | |
1574 | symtabs (one per .h file, for example), and we don't want to reset | |
1575 | the breakpoints N times in the user's face. | |
1576 | ||
1577 | The reason we both queue a cleanup, and call it directly after symbol | |
1578 | reading, is because the cleanup protects us in case of errors, but is | |
1579 | discarded if symbol reading is successful. */ | |
1580 | ||
ade40d31 | 1581 | #if 0 |
996ccb30 JK |
1582 | /* FIXME: As free_named_symtabs is currently a big noop this function |
1583 | is no longer needed. */ | |
ade40d31 RP |
1584 | static void |
1585 | clear_symtab_users_once PARAMS ((void)); | |
1586 | ||
9d199712 JG |
1587 | static int clear_symtab_users_queued; |
1588 | static int clear_symtab_users_done; | |
1589 | ||
ade40d31 | 1590 | static void |
9d199712 JG |
1591 | clear_symtab_users_once () |
1592 | { | |
1593 | /* Enforce once-per-`do_cleanups'-semantics */ | |
1594 | if (clear_symtab_users_queued <= clear_symtab_users_done) | |
1595 | return; | |
1596 | clear_symtab_users_done = clear_symtab_users_queued; | |
1597 | ||
ade40d31 | 1598 | clear_symtab_users (); |
9d199712 | 1599 | } |
ade40d31 | 1600 | #endif |
9d199712 JG |
1601 | |
1602 | /* Delete the specified psymtab, and any others that reference it. */ | |
1603 | ||
e1ce8aa5 | 1604 | static void |
9d199712 JG |
1605 | cashier_psymtab (pst) |
1606 | struct partial_symtab *pst; | |
1607 | { | |
46c28185 | 1608 | struct partial_symtab *ps, *pprev = NULL; |
9d199712 JG |
1609 | int i; |
1610 | ||
1611 | /* Find its previous psymtab in the chain */ | |
30875e1c | 1612 | for (ps = pst->objfile->psymtabs; ps; ps = ps->next) { |
9d199712 JG |
1613 | if (ps == pst) |
1614 | break; | |
1615 | pprev = ps; | |
1616 | } | |
1617 | ||
1618 | if (ps) { | |
1619 | /* Unhook it from the chain. */ | |
30875e1c SG |
1620 | if (ps == pst->objfile->psymtabs) |
1621 | pst->objfile->psymtabs = ps->next; | |
9d199712 JG |
1622 | else |
1623 | pprev->next = ps->next; | |
1624 | ||
1625 | /* FIXME, we can't conveniently deallocate the entries in the | |
1626 | partial_symbol lists (global_psymbols/static_psymbols) that | |
1627 | this psymtab points to. These just take up space until all | |
1628 | the psymtabs are reclaimed. Ditto the dependencies list and | |
1629 | filename, which are all in the psymbol_obstack. */ | |
1630 | ||
1631 | /* We need to cashier any psymtab that has this one as a dependency... */ | |
1632 | again: | |
30875e1c | 1633 | for (ps = pst->objfile->psymtabs; ps; ps = ps->next) { |
9d199712 JG |
1634 | for (i = 0; i < ps->number_of_dependencies; i++) { |
1635 | if (ps->dependencies[i] == pst) { | |
1636 | cashier_psymtab (ps); | |
1637 | goto again; /* Must restart, chain has been munged. */ | |
1638 | } | |
1639 | } | |
1640 | } | |
1641 | } | |
1642 | } | |
1643 | ||
1644 | /* If a symtab or psymtab for filename NAME is found, free it along | |
1645 | with any dependent breakpoints, displays, etc. | |
1646 | Used when loading new versions of object modules with the "add-file" | |
1647 | command. This is only called on the top-level symtab or psymtab's name; | |
1648 | it is not called for subsidiary files such as .h files. | |
1649 | ||
1650 | Return value is 1 if we blew away the environment, 0 if not. | |
30875e1c | 1651 | FIXME. The return valu appears to never be used. |
9d199712 JG |
1652 | |
1653 | FIXME. I think this is not the best way to do this. We should | |
1654 | work on being gentler to the environment while still cleaning up | |
1655 | all stray pointers into the freed symtab. */ | |
1656 | ||
1657 | int | |
1658 | free_named_symtabs (name) | |
1659 | char *name; | |
1660 | { | |
30875e1c SG |
1661 | #if 0 |
1662 | /* FIXME: With the new method of each objfile having it's own | |
1663 | psymtab list, this function needs serious rethinking. In particular, | |
1664 | why was it ever necessary to toss psymtabs with specific compilation | |
1665 | unit filenames, as opposed to all psymtabs from a particular symbol | |
ac88ca20 JG |
1666 | file? -- fnf |
1667 | Well, the answer is that some systems permit reloading of particular | |
1668 | compilation units. We want to blow away any old info about these | |
1669 | compilation units, regardless of which objfiles they arrived in. --gnu. */ | |
1670 | ||
1671 | register struct symtab *s; | |
1672 | register struct symtab *prev; | |
1673 | register struct partial_symtab *ps; | |
1674 | struct blockvector *bv; | |
1675 | int blewit = 0; | |
30875e1c | 1676 | |
61a7292f SG |
1677 | /* We only wack things if the symbol-reload switch is set. */ |
1678 | if (!symbol_reloading) | |
1679 | return 0; | |
1680 | ||
d11c44f1 JG |
1681 | /* Some symbol formats have trouble providing file names... */ |
1682 | if (name == 0 || *name == '\0') | |
1683 | return 0; | |
1684 | ||
9d199712 JG |
1685 | /* Look for a psymtab with the specified name. */ |
1686 | ||
1687 | again2: | |
1688 | for (ps = partial_symtab_list; ps; ps = ps->next) { | |
2e4964ad | 1689 | if (STREQ (name, ps->filename)) { |
9d199712 JG |
1690 | cashier_psymtab (ps); /* Blow it away...and its little dog, too. */ |
1691 | goto again2; /* Must restart, chain has been munged */ | |
1692 | } | |
1693 | } | |
1694 | ||
1695 | /* Look for a symtab with the specified name. */ | |
1696 | ||
1697 | for (s = symtab_list; s; s = s->next) | |
1698 | { | |
2e4964ad | 1699 | if (STREQ (name, s->filename)) |
9d199712 JG |
1700 | break; |
1701 | prev = s; | |
1702 | } | |
1703 | ||
1704 | if (s) | |
1705 | { | |
1706 | if (s == symtab_list) | |
1707 | symtab_list = s->next; | |
1708 | else | |
1709 | prev->next = s->next; | |
1710 | ||
1711 | /* For now, queue a delete for all breakpoints, displays, etc., whether | |
1712 | or not they depend on the symtab being freed. This should be | |
1713 | changed so that only those data structures affected are deleted. */ | |
1714 | ||
1715 | /* But don't delete anything if the symtab is empty. | |
1716 | This test is necessary due to a bug in "dbxread.c" that | |
1717 | causes empty symtabs to be created for N_SO symbols that | |
1718 | contain the pathname of the object file. (This problem | |
1719 | has been fixed in GDB 3.9x). */ | |
1720 | ||
c9bd6710 JG |
1721 | bv = BLOCKVECTOR (s); |
1722 | if (BLOCKVECTOR_NBLOCKS (bv) > 2 | |
9d199712 JG |
1723 | || BLOCK_NSYMS (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) |
1724 | || BLOCK_NSYMS (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK))) | |
1725 | { | |
1726 | complain (&oldsyms_complaint, name); | |
1727 | ||
1728 | clear_symtab_users_queued++; | |
1729 | make_cleanup (clear_symtab_users_once, 0); | |
1730 | blewit = 1; | |
1731 | } else { | |
1732 | complain (&empty_symtab_complaint, name); | |
1733 | } | |
1734 | ||
1735 | free_symtab (s); | |
1736 | } | |
1737 | else | |
d8ce1326 JG |
1738 | { |
1739 | /* It is still possible that some breakpoints will be affected | |
1740 | even though no symtab was found, since the file might have | |
1741 | been compiled without debugging, and hence not be associated | |
1742 | with a symtab. In order to handle this correctly, we would need | |
1743 | to keep a list of text address ranges for undebuggable files. | |
1744 | For now, we do nothing, since this is a fairly obscure case. */ | |
1745 | ; | |
1746 | } | |
9d199712 | 1747 | |
30875e1c | 1748 | /* FIXME, what about the minimal symbol table? */ |
9d199712 | 1749 | return blewit; |
30875e1c SG |
1750 | #else |
1751 | return (0); | |
1752 | #endif | |
9d199712 JG |
1753 | } |
1754 | \f | |
d4ea2aba PB |
1755 | /* Allocate and partially fill a partial symtab. It will be |
1756 | completely filled at the end of the symbol list. | |
1757 | ||
1758 | SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR | |
1759 | is the address relative to which its symbols are (incremental) or 0 | |
1760 | (normal). */ | |
1761 | ||
1762 | ||
1763 | struct partial_symtab * | |
a8e033f2 | 1764 | start_psymtab_common (objfile, section_offsets, |
d4ea2aba PB |
1765 | filename, textlow, global_syms, static_syms) |
1766 | struct objfile *objfile; | |
a8e033f2 | 1767 | struct section_offsets *section_offsets; |
d4ea2aba PB |
1768 | char *filename; |
1769 | CORE_ADDR textlow; | |
2ad5709f FF |
1770 | struct partial_symbol **global_syms; |
1771 | struct partial_symbol **static_syms; | |
d4ea2aba | 1772 | { |
30875e1c SG |
1773 | struct partial_symtab *psymtab; |
1774 | ||
1775 | psymtab = allocate_psymtab (filename, objfile); | |
a8e033f2 | 1776 | psymtab -> section_offsets = section_offsets; |
30875e1c SG |
1777 | psymtab -> textlow = textlow; |
1778 | psymtab -> texthigh = psymtab -> textlow; /* default */ | |
1779 | psymtab -> globals_offset = global_syms - objfile -> global_psymbols.list; | |
1780 | psymtab -> statics_offset = static_syms - objfile -> static_psymbols.list; | |
1781 | return (psymtab); | |
7d9884b9 | 1782 | } |
9342ecb9 | 1783 | \f |
9342ecb9 JG |
1784 | /* Add a symbol with a long value to a psymtab. |
1785 | Since one arg is a struct, we pass in a ptr and deref it (sigh). */ | |
1786 | ||
1787 | void | |
012be3ce DP |
1788 | add_psymbol_to_list (name, namelength, namespace, class, list, val, coreaddr, |
1789 | language, objfile) | |
9342ecb9 JG |
1790 | char *name; |
1791 | int namelength; | |
1750a5ef | 1792 | namespace_enum namespace; |
9342ecb9 JG |
1793 | enum address_class class; |
1794 | struct psymbol_allocation_list *list; | |
012be3ce DP |
1795 | long val; /* Value as a long */ |
1796 | CORE_ADDR coreaddr; /* Value as a CORE_ADDR */ | |
2e4964ad FF |
1797 | enum language language; |
1798 | struct objfile *objfile; | |
9342ecb9 | 1799 | { |
2e4964ad | 1800 | register struct partial_symbol *psym; |
2ad5709f | 1801 | char *buf = alloca (namelength + 1); |
012be3ce DP |
1802 | /* psymbol is static so that there will be no uninitialized gaps in the |
1803 | structure which might contain random data, causing cache misses in | |
1804 | bcache. */ | |
1805 | static struct partial_symbol psymbol; | |
2ad5709f FF |
1806 | |
1807 | /* Create local copy of the partial symbol */ | |
1808 | memcpy (buf, name, namelength); | |
1809 | buf[namelength] = '\0'; | |
1810 | SYMBOL_NAME (&psymbol) = bcache (buf, namelength + 1, &objfile->psymbol_cache); | |
012be3ce DP |
1811 | /* val and coreaddr are mutually exclusive, one of them *will* be zero */ |
1812 | if (val != 0) | |
2e4964ad | 1813 | { |
012be3ce DP |
1814 | SYMBOL_VALUE (&psymbol) = val; |
1815 | } | |
1816 | else | |
1817 | { | |
1818 | SYMBOL_VALUE_ADDRESS (&psymbol) = coreaddr; | |
2e4964ad | 1819 | } |
2ad5709f FF |
1820 | SYMBOL_SECTION (&psymbol) = 0; |
1821 | SYMBOL_LANGUAGE (&psymbol) = language; | |
1822 | PSYMBOL_NAMESPACE (&psymbol) = namespace; | |
1823 | PSYMBOL_CLASS (&psymbol) = class; | |
1824 | SYMBOL_INIT_LANGUAGE_SPECIFIC (&psymbol, language); | |
1825 | ||
1826 | /* Stash the partial symbol away in the cache */ | |
1827 | psym = bcache (&psymbol, sizeof (struct partial_symbol), &objfile->psymbol_cache); | |
1828 | ||
1829 | /* Save pointer to partial symbol in psymtab, growing symtab if needed. */ | |
2e4964ad FF |
1830 | if (list->next >= list->list + list->size) |
1831 | { | |
2ad5709f | 1832 | extend_psymbol_list (list, objfile); |
2e4964ad | 1833 | } |
2ad5709f | 1834 | *list->next++ = psym; |
f1d39876 | 1835 | OBJSTAT (objfile, n_psyms++); |
9342ecb9 | 1836 | } |
7d9884b9 | 1837 | |
1a494973 C |
1838 | /* Initialize storage for partial symbols. */ |
1839 | ||
1840 | void | |
1841 | init_psymbol_list (objfile, total_symbols) | |
1842 | struct objfile *objfile; | |
1843 | int total_symbols; | |
1844 | { | |
1845 | /* Free any previously allocated psymbol lists. */ | |
1846 | ||
1847 | if (objfile -> global_psymbols.list) | |
1848 | { | |
1849 | mfree (objfile -> md, (PTR)objfile -> global_psymbols.list); | |
1850 | } | |
1851 | if (objfile -> static_psymbols.list) | |
1852 | { | |
1853 | mfree (objfile -> md, (PTR)objfile -> static_psymbols.list); | |
1854 | } | |
1855 | ||
1856 | /* Current best guess is that approximately a twentieth | |
1857 | of the total symbols (in a debugging file) are global or static | |
1858 | oriented symbols */ | |
1859 | ||
1860 | objfile -> global_psymbols.size = total_symbols / 10; | |
1861 | objfile -> static_psymbols.size = total_symbols / 10; | |
77636dea FF |
1862 | |
1863 | if (objfile -> global_psymbols.size > 0) | |
1864 | { | |
1865 | objfile -> global_psymbols.next = | |
1866 | objfile -> global_psymbols.list = (struct partial_symbol **) | |
1867 | xmmalloc (objfile -> md, (objfile -> global_psymbols.size | |
1868 | * sizeof (struct partial_symbol *))); | |
1869 | } | |
1870 | if (objfile -> static_psymbols.size > 0) | |
1871 | { | |
1872 | objfile -> static_psymbols.next = | |
1873 | objfile -> static_psymbols.list = (struct partial_symbol **) | |
1874 | xmmalloc (objfile -> md, (objfile -> static_psymbols.size | |
1875 | * sizeof (struct partial_symbol *))); | |
1876 | } | |
1a494973 | 1877 | } |
40b647e9 FF |
1878 | |
1879 | /* OVERLAYS: | |
1880 | The following code implements an abstraction for debugging overlay sections. | |
1881 | ||
1882 | The target model is as follows: | |
1883 | 1) The gnu linker will permit multiple sections to be mapped into the | |
1884 | same VMA, each with its own unique LMA (or load address). | |
1885 | 2) It is assumed that some runtime mechanism exists for mapping the | |
1886 | sections, one by one, from the load address into the VMA address. | |
1887 | 3) This code provides a mechanism for gdb to keep track of which | |
1888 | sections should be considered to be mapped from the VMA to the LMA. | |
1889 | This information is used for symbol lookup, and memory read/write. | |
1890 | For instance, if a section has been mapped then its contents | |
1891 | should be read from the VMA, otherwise from the LMA. | |
1892 | ||
1893 | Two levels of debugger support for overlays are available. One is | |
1894 | "manual", in which the debugger relies on the user to tell it which | |
1895 | overlays are currently mapped. This level of support is | |
1896 | implemented entirely in the core debugger, and the information about | |
1897 | whether a section is mapped is kept in the objfile->obj_section table. | |
1898 | ||
1899 | The second level of support is "automatic", and is only available if | |
1900 | the target-specific code provides functionality to read the target's | |
1901 | overlay mapping table, and translate its contents for the debugger | |
1902 | (by updating the mapped state information in the obj_section tables). | |
1903 | ||
1904 | The interface is as follows: | |
1905 | User commands: | |
1906 | overlay map <name> -- tell gdb to consider this section mapped | |
1907 | overlay unmap <name> -- tell gdb to consider this section unmapped | |
1908 | overlay list -- list the sections that GDB thinks are mapped | |
1909 | overlay read-target -- get the target's state of what's mapped | |
1910 | overlay off/manual/auto -- set overlay debugging state | |
1911 | Functional interface: | |
1912 | find_pc_mapped_section(pc): if the pc is in the range of a mapped | |
1913 | section, return that section. | |
1914 | find_pc_overlay(pc): find any overlay section that contains | |
1915 | the pc, either in its VMA or its LMA | |
1916 | overlay_is_mapped(sect): true if overlay is marked as mapped | |
1917 | section_is_overlay(sect): true if section's VMA != LMA | |
1918 | pc_in_mapped_range(pc,sec): true if pc belongs to section's VMA | |
1919 | pc_in_unmapped_range(...): true if pc belongs to section's LMA | |
1920 | overlay_mapped_address(...): map an address from section's LMA to VMA | |
1921 | overlay_unmapped_address(...): map an address from section's VMA to LMA | |
1922 | symbol_overlayed_address(...): Return a "current" address for symbol: | |
1923 | either in VMA or LMA depending on whether | |
1924 | the symbol's section is currently mapped | |
1925 | */ | |
1926 | ||
1927 | /* Overlay debugging state: */ | |
1928 | ||
1929 | int overlay_debugging = 0; /* 0 == off, 1 == manual, -1 == auto */ | |
1930 | int overlay_cache_invalid = 0; /* True if need to refresh mapped state */ | |
1931 | ||
1932 | /* Target vector for refreshing overlay mapped state */ | |
1933 | static void simple_overlay_update PARAMS ((struct obj_section *)); | |
1934 | void (*target_overlay_update) PARAMS ((struct obj_section *)) | |
1935 | = simple_overlay_update; | |
1936 | ||
1937 | /* Function: section_is_overlay (SECTION) | |
1938 | Returns true if SECTION has VMA not equal to LMA, ie. | |
1939 | SECTION is loaded at an address different from where it will "run". */ | |
1940 | ||
1941 | int | |
1942 | section_is_overlay (section) | |
1943 | asection *section; | |
1944 | { | |
1945 | if (overlay_debugging) | |
1946 | if (section && section->lma != 0 && | |
1947 | section->vma != section->lma) | |
1948 | return 1; | |
1949 | ||
1950 | return 0; | |
1951 | } | |
1952 | ||
1953 | /* Function: overlay_invalidate_all (void) | |
1954 | Invalidate the mapped state of all overlay sections (mark it as stale). */ | |
1955 | ||
1956 | static void | |
1957 | overlay_invalidate_all () | |
1958 | { | |
1959 | struct objfile *objfile; | |
1960 | struct obj_section *sect; | |
1961 | ||
1962 | ALL_OBJSECTIONS (objfile, sect) | |
1963 | if (section_is_overlay (sect->the_bfd_section)) | |
1964 | sect->ovly_mapped = -1; | |
1965 | } | |
1966 | ||
1967 | /* Function: overlay_is_mapped (SECTION) | |
1968 | Returns true if section is an overlay, and is currently mapped. | |
1969 | Private: public access is thru function section_is_mapped. | |
1970 | ||
1971 | Access to the ovly_mapped flag is restricted to this function, so | |
1972 | that we can do automatic update. If the global flag | |
1973 | OVERLAY_CACHE_INVALID is set (by wait_for_inferior), then call | |
1974 | overlay_invalidate_all. If the mapped state of the particular | |
1975 | section is stale, then call TARGET_OVERLAY_UPDATE to refresh it. */ | |
1976 | ||
1977 | static int | |
1978 | overlay_is_mapped (osect) | |
1979 | struct obj_section *osect; | |
1980 | { | |
1981 | if (osect == 0 || !section_is_overlay (osect->the_bfd_section)) | |
1982 | return 0; | |
1983 | ||
1984 | switch (overlay_debugging) | |
1985 | { | |
1986 | default: | |
1987 | case 0: return 0; /* overlay debugging off */ | |
1988 | case -1: /* overlay debugging automatic */ | |
1989 | /* Unles there is a target_overlay_update function, | |
1990 | there's really nothing useful to do here (can't really go auto) */ | |
1991 | if (target_overlay_update) | |
1992 | { | |
1993 | if (overlay_cache_invalid) | |
1994 | { | |
1995 | overlay_invalidate_all (); | |
1996 | overlay_cache_invalid = 0; | |
1997 | } | |
1998 | if (osect->ovly_mapped == -1) | |
1999 | (*target_overlay_update) (osect); | |
2000 | } | |
2001 | /* fall thru to manual case */ | |
2002 | case 1: /* overlay debugging manual */ | |
2003 | return osect->ovly_mapped == 1; | |
2004 | } | |
2005 | } | |
2006 | ||
2007 | /* Function: section_is_mapped | |
2008 | Returns true if section is an overlay, and is currently mapped. */ | |
2009 | ||
2010 | int | |
2011 | section_is_mapped (section) | |
2012 | asection *section; | |
2013 | { | |
2014 | struct objfile *objfile; | |
2015 | struct obj_section *osect; | |
2016 | ||
2017 | if (overlay_debugging) | |
2018 | if (section && section_is_overlay (section)) | |
2019 | ALL_OBJSECTIONS (objfile, osect) | |
2020 | if (osect->the_bfd_section == section) | |
2021 | return overlay_is_mapped (osect); | |
2022 | ||
2023 | return 0; | |
2024 | } | |
2025 | ||
2026 | /* Function: pc_in_unmapped_range | |
2027 | If PC falls into the lma range of SECTION, return true, else false. */ | |
2028 | ||
2029 | CORE_ADDR | |
2030 | pc_in_unmapped_range (pc, section) | |
2031 | CORE_ADDR pc; | |
2032 | asection *section; | |
2033 | { | |
2034 | int size; | |
2035 | ||
2036 | if (overlay_debugging) | |
2037 | if (section && section_is_overlay (section)) | |
2038 | { | |
2039 | size = bfd_get_section_size_before_reloc (section); | |
2040 | if (section->lma <= pc && pc < section->lma + size) | |
2041 | return 1; | |
2042 | } | |
2043 | return 0; | |
2044 | } | |
2045 | ||
2046 | /* Function: pc_in_mapped_range | |
2047 | If PC falls into the vma range of SECTION, return true, else false. */ | |
2048 | ||
2049 | CORE_ADDR | |
2050 | pc_in_mapped_range (pc, section) | |
2051 | CORE_ADDR pc; | |
2052 | asection *section; | |
2053 | { | |
2054 | int size; | |
2055 | ||
2056 | if (overlay_debugging) | |
2057 | if (section && section_is_overlay (section)) | |
2058 | { | |
2059 | size = bfd_get_section_size_before_reloc (section); | |
2060 | if (section->vma <= pc && pc < section->vma + size) | |
2061 | return 1; | |
2062 | } | |
2063 | return 0; | |
2064 | } | |
2065 | ||
2066 | /* Function: overlay_unmapped_address (PC, SECTION) | |
2067 | Returns the address corresponding to PC in the unmapped (load) range. | |
2068 | May be the same as PC. */ | |
2069 | ||
2070 | CORE_ADDR | |
2071 | overlay_unmapped_address (pc, section) | |
2072 | CORE_ADDR pc; | |
2073 | asection *section; | |
2074 | { | |
2075 | if (overlay_debugging) | |
2076 | if (section && section_is_overlay (section) && | |
2077 | pc_in_mapped_range (pc, section)) | |
2078 | return pc + section->lma - section->vma; | |
2079 | ||
2080 | return pc; | |
2081 | } | |
2082 | ||
2083 | /* Function: overlay_mapped_address (PC, SECTION) | |
2084 | Returns the address corresponding to PC in the mapped (runtime) range. | |
2085 | May be the same as PC. */ | |
2086 | ||
2087 | CORE_ADDR | |
2088 | overlay_mapped_address (pc, section) | |
2089 | CORE_ADDR pc; | |
2090 | asection *section; | |
2091 | { | |
2092 | if (overlay_debugging) | |
2093 | if (section && section_is_overlay (section) && | |
2094 | pc_in_unmapped_range (pc, section)) | |
2095 | return pc + section->vma - section->lma; | |
2096 | ||
2097 | return pc; | |
2098 | } | |
2099 | ||
2100 | ||
2101 | /* Function: symbol_overlayed_address | |
2102 | Return one of two addresses (relative to the VMA or to the LMA), | |
2103 | depending on whether the section is mapped or not. */ | |
2104 | ||
2105 | CORE_ADDR | |
2106 | symbol_overlayed_address (address, section) | |
2107 | CORE_ADDR address; | |
2108 | asection *section; | |
2109 | { | |
2110 | if (overlay_debugging) | |
2111 | { | |
2112 | /* If the symbol has no section, just return its regular address. */ | |
2113 | if (section == 0) | |
2114 | return address; | |
2115 | /* If the symbol's section is not an overlay, just return its address */ | |
2116 | if (!section_is_overlay (section)) | |
2117 | return address; | |
2118 | /* If the symbol's section is mapped, just return its address */ | |
2119 | if (section_is_mapped (section)) | |
2120 | return address; | |
2121 | /* | |
2122 | * HOWEVER: if the symbol is in an overlay section which is NOT mapped, | |
2123 | * then return its LOADED address rather than its vma address!! | |
2124 | */ | |
2125 | return overlay_unmapped_address (address, section); | |
2126 | } | |
2127 | return address; | |
2128 | } | |
2129 | ||
2130 | /* Function: find_pc_overlay (PC) | |
2131 | Return the best-match overlay section for PC: | |
2132 | If PC matches a mapped overlay section's VMA, return that section. | |
2133 | Else if PC matches an unmapped section's VMA, return that section. | |
2134 | Else if PC matches an unmapped section's LMA, return that section. */ | |
2135 | ||
2136 | asection * | |
2137 | find_pc_overlay (pc) | |
2138 | CORE_ADDR pc; | |
2139 | { | |
2140 | struct objfile *objfile; | |
2141 | struct obj_section *osect, *best_match = NULL; | |
2142 | ||
2143 | if (overlay_debugging) | |
2144 | ALL_OBJSECTIONS (objfile, osect) | |
2145 | if (section_is_overlay (osect->the_bfd_section)) | |
2146 | { | |
2147 | if (pc_in_mapped_range (pc, osect->the_bfd_section)) | |
2148 | { | |
2149 | if (overlay_is_mapped (osect)) | |
2150 | return osect->the_bfd_section; | |
2151 | else | |
2152 | best_match = osect; | |
2153 | } | |
2154 | else if (pc_in_unmapped_range (pc, osect->the_bfd_section)) | |
2155 | best_match = osect; | |
2156 | } | |
2157 | return best_match ? best_match->the_bfd_section : NULL; | |
2158 | } | |
2159 | ||
2160 | /* Function: find_pc_mapped_section (PC) | |
2161 | If PC falls into the VMA address range of an overlay section that is | |
2162 | currently marked as MAPPED, return that section. Else return NULL. */ | |
2163 | ||
2164 | asection * | |
2165 | find_pc_mapped_section (pc) | |
2166 | CORE_ADDR pc; | |
2167 | { | |
2168 | struct objfile *objfile; | |
2169 | struct obj_section *osect; | |
2170 | ||
2171 | if (overlay_debugging) | |
2172 | ALL_OBJSECTIONS (objfile, osect) | |
2173 | if (pc_in_mapped_range (pc, osect->the_bfd_section) && | |
2174 | overlay_is_mapped (osect)) | |
2175 | return osect->the_bfd_section; | |
2176 | ||
2177 | return NULL; | |
2178 | } | |
2179 | ||
2180 | /* Function: list_overlays_command | |
2181 | Print a list of mapped sections and their PC ranges */ | |
2182 | ||
2183 | void | |
2184 | list_overlays_command (args, from_tty) | |
2185 | char *args; | |
2186 | int from_tty; | |
2187 | { | |
2188 | int nmapped = 0; | |
2189 | struct objfile *objfile; | |
2190 | struct obj_section *osect; | |
2191 | ||
2192 | if (overlay_debugging) | |
2193 | ALL_OBJSECTIONS (objfile, osect) | |
2194 | if (overlay_is_mapped (osect)) | |
2195 | { | |
2196 | const char *name; | |
2197 | bfd_vma lma, vma; | |
2198 | int size; | |
2199 | ||
2200 | vma = bfd_section_vma (objfile->obfd, osect->the_bfd_section); | |
2201 | lma = bfd_section_lma (objfile->obfd, osect->the_bfd_section); | |
2202 | size = bfd_get_section_size_before_reloc (osect->the_bfd_section); | |
2203 | name = bfd_section_name (objfile->obfd, osect->the_bfd_section); | |
2204 | printf_filtered ("Section %s, loaded at %08x - %08x, ", | |
2205 | name, lma, lma + size); | |
2206 | printf_filtered ("mapped at %08x - %08x\n", | |
2207 | vma, vma + size); | |
2208 | nmapped ++; | |
2209 | } | |
2210 | if (nmapped == 0) | |
2211 | printf_filtered ("No sections are mapped.\n"); | |
2212 | } | |
2213 | ||
2214 | /* Function: map_overlay_command | |
2215 | Mark the named section as mapped (ie. residing at its VMA address). */ | |
2216 | ||
2217 | void | |
2218 | map_overlay_command (args, from_tty) | |
2219 | char *args; | |
2220 | int from_tty; | |
2221 | { | |
2222 | struct objfile *objfile, *objfile2; | |
2223 | struct obj_section *sec, *sec2; | |
2224 | asection *bfdsec; | |
2225 | ||
2226 | if (!overlay_debugging) | |
2227 | error ("Overlay debugging not enabled. Use the 'OVERLAY ON' command."); | |
2228 | ||
2229 | if (args == 0 || *args == 0) | |
2230 | error ("Argument required: name of an overlay section"); | |
2231 | ||
2232 | /* First, find a section matching the user supplied argument */ | |
2233 | ALL_OBJSECTIONS (objfile, sec) | |
2234 | if (!strcmp (bfd_section_name (objfile->obfd, sec->the_bfd_section), args)) | |
2235 | { | |
2236 | /* Now, check to see if the section is an overlay. */ | |
2237 | bfdsec = sec->the_bfd_section; | |
2238 | if (!section_is_overlay (bfdsec)) | |
2239 | continue; /* not an overlay section */ | |
2240 | ||
2241 | /* Mark the overlay as "mapped" */ | |
2242 | sec->ovly_mapped = 1; | |
2243 | ||
2244 | /* Next, make a pass and unmap any sections that are | |
2245 | overlapped by this new section: */ | |
2246 | ALL_OBJSECTIONS (objfile2, sec2) | |
2247 | if (sec2->ovly_mapped && | |
2248 | sec != sec2 && | |
2249 | sec->the_bfd_section != sec2->the_bfd_section && | |
2250 | (pc_in_mapped_range (sec2->addr, sec->the_bfd_section) || | |
2251 | pc_in_mapped_range (sec2->endaddr, sec->the_bfd_section))) | |
2252 | { | |
2253 | if (info_verbose) | |
2254 | printf_filtered ("Note: section %s unmapped by overlap\n", | |
2255 | bfd_section_name (objfile->obfd, | |
2256 | sec2->the_bfd_section)); | |
2257 | sec2->ovly_mapped = 0; /* sec2 overlaps sec: unmap sec2 */ | |
2258 | } | |
2259 | return; | |
2260 | } | |
2261 | error ("No overlay section called %s", args); | |
2262 | } | |
2263 | ||
2264 | /* Function: unmap_overlay_command | |
2265 | Mark the overlay section as unmapped | |
2266 | (ie. resident in its LMA address range, rather than the VMA range). */ | |
2267 | ||
2268 | void | |
2269 | unmap_overlay_command (args, from_tty) | |
2270 | char *args; | |
2271 | int from_tty; | |
2272 | { | |
2273 | struct objfile *objfile; | |
2274 | struct obj_section *sec; | |
2275 | ||
2276 | if (!overlay_debugging) | |
2277 | error ("Overlay debugging not enabled. Use the 'OVERLAY ON' command."); | |
2278 | ||
2279 | if (args == 0 || *args == 0) | |
2280 | error ("Argument required: name of an overlay section"); | |
2281 | ||
2282 | /* First, find a section matching the user supplied argument */ | |
2283 | ALL_OBJSECTIONS (objfile, sec) | |
2284 | if (!strcmp (bfd_section_name (objfile->obfd, sec->the_bfd_section), args)) | |
2285 | { | |
2286 | if (!sec->ovly_mapped) | |
2287 | error ("Section %s is not mapped", args); | |
2288 | sec->ovly_mapped = 0; | |
2289 | return; | |
2290 | } | |
2291 | error ("No overlay section called %s", args); | |
2292 | } | |
2293 | ||
2294 | /* Function: overlay_auto_command | |
2295 | A utility command to turn on overlay debugging. | |
2296 | Possibly this should be done via a set/show command. */ | |
2297 | ||
2298 | static void | |
2299 | overlay_auto_command (args, from_tty) | |
2300 | { | |
2301 | overlay_debugging = -1; | |
2302 | if (info_verbose) | |
2303 | printf_filtered ("Automatic overlay debugging enabled."); | |
2304 | } | |
2305 | ||
2306 | /* Function: overlay_manual_command | |
2307 | A utility command to turn on overlay debugging. | |
2308 | Possibly this should be done via a set/show command. */ | |
2309 | ||
2310 | static void | |
2311 | overlay_manual_command (args, from_tty) | |
2312 | { | |
2313 | overlay_debugging = 1; | |
2314 | if (info_verbose) | |
2315 | printf_filtered ("Overlay debugging enabled."); | |
2316 | } | |
2317 | ||
2318 | /* Function: overlay_off_command | |
2319 | A utility command to turn on overlay debugging. | |
2320 | Possibly this should be done via a set/show command. */ | |
2321 | ||
2322 | static void | |
2323 | overlay_off_command (args, from_tty) | |
2324 | { | |
2325 | overlay_debugging = 0; | |
2326 | if (info_verbose) | |
2327 | printf_filtered ("Overlay debugging disabled."); | |
2328 | } | |
2329 | ||
2330 | static void | |
2331 | overlay_load_command (args, from_tty) | |
2332 | { | |
2333 | if (target_overlay_update) | |
2334 | (*target_overlay_update) (NULL); | |
2335 | else | |
2336 | error ("This target does not know how to read its overlay state."); | |
2337 | } | |
2338 | ||
2339 | /* Function: overlay_command | |
2340 | A place-holder for a mis-typed command */ | |
2341 | ||
2342 | /* Command list chain containing all defined "overlay" subcommands. */ | |
2343 | struct cmd_list_element *overlaylist; | |
2344 | ||
2345 | static void | |
2346 | overlay_command (args, from_tty) | |
2347 | char *args; | |
2348 | int from_tty; | |
2349 | { | |
2350 | printf_unfiltered | |
2351 | ("\"overlay\" must be followed by the name of an overlay command.\n"); | |
2352 | help_list (overlaylist, "overlay ", -1, gdb_stdout); | |
2353 | } | |
2354 | ||
2355 | ||
2356 | /* Target Overlays for the "Simplest" overlay manager: | |
2357 | ||
2358 | This is GDB's default target overlay layer. It works with the | |
2359 | minimal overlay manager supplied as an example by Cygnus. The | |
2360 | entry point is via a function pointer "target_overlay_update", | |
2361 | so targets that use a different runtime overlay manager can | |
2362 | substitute their own overlay_update function and take over the | |
2363 | function pointer. | |
2364 | ||
2365 | The overlay_update function pokes around in the target's data structures | |
2366 | to see what overlays are mapped, and updates GDB's overlay mapping with | |
2367 | this information. | |
2368 | ||
2369 | In this simple implementation, the target data structures are as follows: | |
2370 | unsigned _novlys; /# number of overlay sections #/ | |
2371 | unsigned _ovly_table[_novlys][4] = { | |
2372 | {VMA, SIZE, LMA, MAPPED}, /# one entry per overlay section #/ | |
2373 | {..., ..., ..., ...}, | |
2374 | } | |
2375 | unsigned _novly_regions; /# number of overlay regions #/ | |
2376 | unsigned _ovly_region_table[_novly_regions][3] = { | |
2377 | {VMA, SIZE, MAPPED_TO_LMA}, /# one entry per overlay region #/ | |
2378 | {..., ..., ...}, | |
2379 | } | |
2380 | These functions will attempt to update GDB's mappedness state in the | |
2381 | symbol section table, based on the target's mappedness state. | |
2382 | ||
2383 | To do this, we keep a cached copy of the target's _ovly_table, and | |
2384 | attempt to detect when the cached copy is invalidated. The main | |
2385 | entry point is "simple_overlay_update(SECT), which looks up SECT in | |
2386 | the cached table and re-reads only the entry for that section from | |
2387 | the target (whenever possible). | |
2388 | */ | |
2389 | ||
2390 | /* Cached, dynamically allocated copies of the target data structures: */ | |
2391 | static unsigned (*cache_ovly_table)[4] = 0; | |
2392 | #if 0 | |
2393 | static unsigned (*cache_ovly_region_table)[3] = 0; | |
2394 | #endif | |
2395 | static unsigned cache_novlys = 0; | |
2396 | #if 0 | |
2397 | static unsigned cache_novly_regions = 0; | |
2398 | #endif | |
2399 | static CORE_ADDR cache_ovly_table_base = 0; | |
2400 | #if 0 | |
2401 | static CORE_ADDR cache_ovly_region_table_base = 0; | |
2402 | #endif | |
2403 | enum ovly_index { VMA, SIZE, LMA, MAPPED}; | |
2404 | #define TARGET_INT_BYTES (TARGET_INT_BIT / TARGET_CHAR_BIT) | |
2405 | ||
2406 | /* Throw away the cached copy of _ovly_table */ | |
2407 | static void | |
2408 | simple_free_overlay_table () | |
2409 | { | |
2410 | if (cache_ovly_table) | |
2411 | free(cache_ovly_table); | |
2412 | cache_novlys = 0; | |
2413 | cache_ovly_table = NULL; | |
2414 | cache_ovly_table_base = 0; | |
2415 | } | |
2416 | ||
2417 | #if 0 | |
2418 | /* Throw away the cached copy of _ovly_region_table */ | |
2419 | static void | |
2420 | simple_free_overlay_region_table () | |
2421 | { | |
2422 | if (cache_ovly_region_table) | |
2423 | free(cache_ovly_region_table); | |
2424 | cache_novly_regions = 0; | |
2425 | cache_ovly_region_table = NULL; | |
2426 | cache_ovly_region_table_base = 0; | |
2427 | } | |
2428 | #endif | |
2429 | ||
2430 | /* Read an array of ints from the target into a local buffer. | |
2431 | Convert to host order. int LEN is number of ints */ | |
2432 | static void | |
2433 | read_target_int_array (memaddr, myaddr, len) | |
2434 | CORE_ADDR memaddr; | |
2435 | unsigned int *myaddr; | |
2436 | int len; | |
2437 | { | |
2438 | char *buf = alloca (len * TARGET_INT_BYTES); | |
2439 | int i; | |
2440 | ||
2441 | read_memory (memaddr, buf, len * TARGET_INT_BYTES); | |
2442 | for (i = 0; i < len; i++) | |
2443 | myaddr[i] = extract_unsigned_integer (TARGET_INT_BYTES * i + buf, | |
2444 | TARGET_INT_BYTES); | |
2445 | } | |
2446 | ||
2447 | /* Find and grab a copy of the target _ovly_table | |
2448 | (and _novlys, which is needed for the table's size) */ | |
2449 | static int | |
2450 | simple_read_overlay_table () | |
2451 | { | |
2452 | struct minimal_symbol *msym; | |
2453 | ||
2454 | simple_free_overlay_table (); | |
2455 | msym = lookup_minimal_symbol ("_novlys", 0, 0); | |
2456 | if (msym != NULL) | |
2457 | cache_novlys = read_memory_integer (SYMBOL_VALUE_ADDRESS (msym), 4); | |
2458 | else | |
2459 | return 0; /* failure */ | |
2460 | cache_ovly_table = (void *) xmalloc (cache_novlys * sizeof(*cache_ovly_table)); | |
2461 | if (cache_ovly_table != NULL) | |
2462 | { | |
2463 | msym = lookup_minimal_symbol ("_ovly_table", 0, 0); | |
2464 | if (msym != NULL) | |
2465 | { | |
2466 | cache_ovly_table_base = SYMBOL_VALUE_ADDRESS (msym); | |
2467 | read_target_int_array (cache_ovly_table_base, | |
2468 | (int *) cache_ovly_table, | |
2469 | cache_novlys * 4); | |
2470 | } | |
2471 | else | |
2472 | return 0; /* failure */ | |
2473 | } | |
2474 | else | |
2475 | return 0; /* failure */ | |
2476 | return 1; /* SUCCESS */ | |
2477 | } | |
2478 | ||
2479 | #if 0 | |
2480 | /* Find and grab a copy of the target _ovly_region_table | |
2481 | (and _novly_regions, which is needed for the table's size) */ | |
2482 | static int | |
2483 | simple_read_overlay_region_table () | |
2484 | { | |
2485 | struct minimal_symbol *msym; | |
2486 | ||
2487 | simple_free_overlay_region_table (); | |
2488 | msym = lookup_minimal_symbol ("_novly_regions", 0, 0); | |
2489 | if (msym != NULL) | |
2490 | cache_novly_regions = read_memory_integer (SYMBOL_VALUE_ADDRESS (msym), 4); | |
2491 | else | |
2492 | return 0; /* failure */ | |
2493 | cache_ovly_region_table = (void *) xmalloc (cache_novly_regions * 12); | |
2494 | if (cache_ovly_region_table != NULL) | |
2495 | { | |
2496 | msym = lookup_minimal_symbol ("_ovly_region_table", 0, 0); | |
2497 | if (msym != NULL) | |
2498 | { | |
2499 | cache_ovly_region_table_base = SYMBOL_VALUE_ADDRESS (msym); | |
2500 | read_target_int_array (cache_ovly_region_table_base, | |
2501 | (int *) cache_ovly_region_table, | |
2502 | cache_novly_regions * 3); | |
2503 | } | |
2504 | else | |
2505 | return 0; /* failure */ | |
2506 | } | |
2507 | else | |
2508 | return 0; /* failure */ | |
2509 | return 1; /* SUCCESS */ | |
2510 | } | |
2511 | #endif | |
2512 | ||
2513 | /* Function: simple_overlay_update_1 | |
2514 | A helper function for simple_overlay_update. Assuming a cached copy | |
2515 | of _ovly_table exists, look through it to find an entry whose vma, | |
2516 | lma and size match those of OSECT. Re-read the entry and make sure | |
2517 | it still matches OSECT (else the table may no longer be valid). | |
2518 | Set OSECT's mapped state to match the entry. Return: 1 for | |
2519 | success, 0 for failure. */ | |
2520 | ||
2521 | static int | |
2522 | simple_overlay_update_1 (osect) | |
2523 | struct obj_section *osect; | |
2524 | { | |
2525 | int i, size; | |
2526 | ||
2527 | size = bfd_get_section_size_before_reloc (osect->the_bfd_section); | |
2528 | for (i = 0; i < cache_novlys; i++) | |
2529 | if (cache_ovly_table[i][VMA] == osect->the_bfd_section->vma && | |
77636dea FF |
2530 | cache_ovly_table[i][LMA] == osect->the_bfd_section->lma /* && |
2531 | cache_ovly_table[i][SIZE] == size */) | |
40b647e9 FF |
2532 | { |
2533 | read_target_int_array (cache_ovly_table_base + i * TARGET_INT_BYTES, | |
2534 | (int *) &cache_ovly_table[i], 4); | |
2535 | if (cache_ovly_table[i][VMA] == osect->the_bfd_section->vma && | |
77636dea FF |
2536 | cache_ovly_table[i][LMA] == osect->the_bfd_section->lma /* && |
2537 | cache_ovly_table[i][SIZE] == size */) | |
40b647e9 FF |
2538 | { |
2539 | osect->ovly_mapped = cache_ovly_table[i][MAPPED]; | |
2540 | return 1; | |
2541 | } | |
2542 | else /* Warning! Warning! Target's ovly table has changed! */ | |
2543 | return 0; | |
2544 | } | |
2545 | return 0; | |
2546 | } | |
2547 | ||
2548 | /* Function: simple_overlay_update | |
2549 | If OSECT is NULL, then update all sections' mapped state | |
2550 | (after re-reading the entire target _ovly_table). | |
2551 | If OSECT is non-NULL, then try to find a matching entry in the | |
2552 | cached ovly_table and update only OSECT's mapped state. | |
2553 | If a cached entry can't be found or the cache isn't valid, then | |
2554 | re-read the entire cache, and go ahead and update all sections. */ | |
2555 | ||
2556 | static void | |
2557 | simple_overlay_update (osect) | |
2558 | struct obj_section *osect; | |
2559 | { | |
2560 | struct objfile *objfile; | |
2561 | ||
2562 | /* Were we given an osect to look up? NULL means do all of them. */ | |
2563 | if (osect) | |
2564 | /* Have we got a cached copy of the target's overlay table? */ | |
2565 | if (cache_ovly_table != NULL) | |
2566 | /* Does its cached location match what's currently in the symtab? */ | |
2567 | if (cache_ovly_table_base == | |
2568 | SYMBOL_VALUE_ADDRESS (lookup_minimal_symbol ("_ovly_table", 0, 0))) | |
2569 | /* Then go ahead and try to look up this single section in the cache */ | |
2570 | if (simple_overlay_update_1 (osect)) | |
2571 | /* Found it! We're done. */ | |
2572 | return; | |
2573 | ||
2574 | /* Cached table no good: need to read the entire table anew. | |
2575 | Or else we want all the sections, in which case it's actually | |
2576 | more efficient to read the whole table in one block anyway. */ | |
2577 | ||
2578 | if (simple_read_overlay_table () == 0) /* read failed? No table? */ | |
2579 | { | |
2580 | warning ("Failed to read the target overlay mapping table."); | |
2581 | return; | |
2582 | } | |
2583 | /* Now may as well update all sections, even if only one was requested. */ | |
2584 | ALL_OBJSECTIONS (objfile, osect) | |
2585 | if (section_is_overlay (osect->the_bfd_section)) | |
2586 | { | |
2587 | int i, size; | |
2588 | ||
2589 | size = bfd_get_section_size_before_reloc (osect->the_bfd_section); | |
2590 | for (i = 0; i < cache_novlys; i++) | |
2591 | if (cache_ovly_table[i][VMA] == osect->the_bfd_section->vma && | |
77636dea FF |
2592 | cache_ovly_table[i][LMA] == osect->the_bfd_section->lma /* && |
2593 | cache_ovly_table[i][SIZE] == size */) | |
40b647e9 FF |
2594 | { /* obj_section matches i'th entry in ovly_table */ |
2595 | osect->ovly_mapped = cache_ovly_table[i][MAPPED]; | |
2596 | break; /* finished with inner for loop: break out */ | |
2597 | } | |
2598 | } | |
2599 | } | |
2600 | ||
2601 | ||
bd5635a1 RP |
2602 | void |
2603 | _initialize_symfile () | |
2604 | { | |
ade40d31 RP |
2605 | struct cmd_list_element *c; |
2606 | ||
2607 | c = add_cmd ("symbol-file", class_files, symbol_file_command, | |
30875e1c | 2608 | "Load symbol table from executable file FILE.\n\ |
bd5635a1 | 2609 | The `file' command can also load symbol tables, as well as setting the file\n\ |
ade40d31 RP |
2610 | to execute.", &cmdlist); |
2611 | c->completer = filename_completer; | |
bd5635a1 | 2612 | |
ade40d31 | 2613 | c = add_cmd ("add-symbol-file", class_files, add_symbol_file_command, |
f3806e3b PS |
2614 | "Usage: add-symbol-file FILE ADDR\n\ |
2615 | Load the symbols from FILE, assuming FILE has been dynamically loaded.\n\ | |
2616 | ADDR is the starting address of the file's text.", | |
ade40d31 RP |
2617 | &cmdlist); |
2618 | c->completer = filename_completer; | |
bd5635a1 | 2619 | |
f3806e3b PS |
2620 | c = add_cmd ("add-shared-symbol-files", class_files, |
2621 | add_shared_symbol_files_command, | |
2622 | "Load the symbols from shared objects in the dynamic linker's link map.", | |
2623 | &cmdlist); | |
2624 | c = add_alias_cmd ("assf", "add-shared-symbol-files", class_files, 1, | |
2625 | &cmdlist); | |
2626 | ||
ade40d31 | 2627 | c = add_cmd ("load", class_files, load_command, |
bd5635a1 | 2628 | "Dynamically load FILE into the running program, and record its symbols\n\ |
ade40d31 RP |
2629 | for access from GDB.", &cmdlist); |
2630 | c->completer = filename_completer; | |
bd5635a1 | 2631 | |
61a7292f SG |
2632 | add_show_from_set |
2633 | (add_set_cmd ("symbol-reloading", class_support, var_boolean, | |
2634 | (char *)&symbol_reloading, | |
2635 | "Set dynamic symbol table reloading multiple times in one run.", | |
2636 | &setlist), | |
2637 | &showlist); | |
2638 | ||
40b647e9 FF |
2639 | add_prefix_cmd ("overlay", class_support, overlay_command, |
2640 | "Commands for debugging overlays.", &overlaylist, | |
2641 | "overlay ", 0, &cmdlist); | |
2642 | ||
2643 | add_com_alias ("ovly", "overlay", class_alias, 1); | |
2644 | add_com_alias ("ov", "overlay", class_alias, 1); | |
2645 | ||
2646 | add_cmd ("map-overlay", class_support, map_overlay_command, | |
2647 | "Assert that an overlay section is mapped.", &overlaylist); | |
2648 | ||
2649 | add_cmd ("unmap-overlay", class_support, unmap_overlay_command, | |
2650 | "Assert that an overlay section is unmapped.", &overlaylist); | |
2651 | ||
2652 | add_cmd ("list-overlays", class_support, list_overlays_command, | |
2653 | "List mappings of overlay sections.", &overlaylist); | |
2654 | ||
2655 | add_cmd ("manual", class_support, overlay_manual_command, | |
2656 | "Enable overlay debugging.", &overlaylist); | |
2657 | add_cmd ("off", class_support, overlay_off_command, | |
2658 | "Disable overlay debugging.", &overlaylist); | |
2659 | add_cmd ("auto", class_support, overlay_auto_command, | |
2660 | "Enable automatic overlay debugging.", &overlaylist); | |
2661 | add_cmd ("load-target", class_support, overlay_load_command, | |
2662 | "Read the overlay mapping state from the target.", &overlaylist); | |
bd5635a1 | 2663 | } |