* breakpoint.c, breakpoint.h (breakpoint_init_inferior): New function
[deliverable/binutils-gdb.git] / gdb / objfiles.c
CommitLineData
1ab3bf1b
JG
1/* GDB routines for manipulating objfiles.
2 Copyright 1992 Free Software Foundation, Inc.
3 Contributed by Cygnus Support, using pieces from other GDB modules.
4
5This file is part of GDB.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21/* This file contains support routines for creating, manipulating, and
22 destroying objfile structures. */
23
1ab3bf1b
JG
24#include "defs.h"
25#include "bfd.h" /* Binary File Description */
26#include "symtab.h"
27#include "symfile.h"
5e2e79f8 28#include "objfiles.h"
610a7e74 29#include "gdb-stabs.h"
c5198d93 30#include "target.h"
1ab3bf1b 31
318bf84f
FF
32#include <sys/types.h>
33#include <sys/stat.h>
34#include <fcntl.h>
1ab3bf1b
JG
35#include <obstack.h>
36
318bf84f
FF
37/* Prototypes for local functions */
38
1867b3be
FF
39#if !defined(NO_MMALLOC) && defined(HAVE_MMAP)
40
41static int
42open_existing_mapped_file PARAMS ((char *, long, int));
43
318bf84f 44static int
b0246b3b 45open_mapped_file PARAMS ((char *filename, long mtime, int mapped));
318bf84f
FF
46
47static CORE_ADDR
48map_to_address PARAMS ((void));
49
1867b3be
FF
50#endif /* !defined(NO_MMALLOC) && defined(HAVE_MMAP) */
51
52/* Message to be printed before the error message, when an error occurs. */
53
54extern char *error_pre_print;
55
5e2e79f8
FF
56/* Externally visible variables that are owned by this module.
57 See declarations in objfile.h for more info. */
1ab3bf1b
JG
58
59struct objfile *object_files; /* Linked list of all objfiles */
5e2e79f8
FF
60struct objfile *current_objfile; /* For symbol file being read in */
61struct objfile *symfile_objfile; /* Main symbol table loaded from */
62
318bf84f 63int mapped_symbol_files; /* Try to use mapped symbol files */
1ab3bf1b 64
73d0fc78
RP
65/* Locate all mappable sections of a BFD file.
66 objfile_p_char is a char * to get it through
67 bfd_map_over_sections; we cast it back to its proper type. */
68
69static void
70add_to_objfile_sections (abfd, asect, objfile_p_char)
71 bfd *abfd;
72 sec_ptr asect;
73 PTR objfile_p_char;
74{
75 struct objfile *objfile = (struct objfile *) objfile_p_char;
76 struct obj_section section;
77 flagword aflag;
78
79 aflag = bfd_get_section_flags (abfd, asect);
80 /* FIXME, we need to handle BSS segment here...it alloc's but doesn't load */
81 if (!(aflag & SEC_LOAD))
82 return;
83 if (0 == bfd_section_size (abfd, asect))
84 return;
85 section.offset = 0;
4365c36c 86 section.objfile = objfile;
73d0fc78
RP
87 section.sec_ptr = asect;
88 section.addr = bfd_section_vma (abfd, asect);
89 section.endaddr = section.addr + bfd_section_size (abfd, asect);
90 obstack_grow (&objfile->psymbol_obstack, &section, sizeof(section));
5573d7d4 91 objfile->sections_end = (struct obj_section *) (((unsigned long) objfile->sections_end) + 1);
73d0fc78
RP
92}
93
94/* Builds a section table for OBJFILE.
95 Returns 0 if OK, 1 on error. */
96
97static int
98build_objfile_section_table (objfile)
99 struct objfile *objfile;
100{
101 if (objfile->sections)
102 abort();
103
104 objfile->sections_end = 0;
105 bfd_map_over_sections (objfile->obfd, add_to_objfile_sections, (char *)objfile);
ccd87bf2
JK
106 objfile->sections = (struct obj_section *)
107 obstack_finish (&objfile->psymbol_obstack);
5573d7d4 108 objfile->sections_end = objfile->sections + (unsigned long) objfile->sections_end;
73d0fc78
RP
109 return(0);
110}
111
b0246b3b
FF
112/* Given a pointer to an initialized bfd (ABFD) and a flag that indicates
113 whether or not an objfile is to be mapped (MAPPED), allocate a new objfile
114 struct, fill it in as best we can, link it into the list of all known
115 objfiles, and return a pointer to the new objfile struct. */
1ab3bf1b
JG
116
117struct objfile *
b0246b3b 118allocate_objfile (abfd, mapped)
1ab3bf1b 119 bfd *abfd;
318bf84f 120 int mapped;
1ab3bf1b 121{
318bf84f
FF
122 struct objfile *objfile = NULL;
123 int fd;
77fe3f84 124 PTR md;
318bf84f
FF
125 CORE_ADDR mapto;
126
127 mapped |= mapped_symbol_files;
128
129#if !defined(NO_MMALLOC) && defined(HAVE_MMAP)
130
131 /* If we can support mapped symbol files, try to open/reopen the mapped file
132 that corresponds to the file from which we wish to read symbols. If the
133 objfile is to be mapped, we must malloc the structure itself using the
134 mmap version, and arrange that all memory allocation for the objfile uses
135 the mmap routines. If we are reusing an existing mapped file, from which
136 we get our objfile pointer, we have to make sure that we update the
137 pointers to the alloc/free functions in the obstack, in case these
138 functions have moved within the current gdb. */
139
b0246b3b
FF
140 fd = open_mapped_file (bfd_get_filename (abfd), bfd_get_mtime (abfd),
141 mapped);
318bf84f
FF
142 if (fd >= 0)
143 {
b0246b3b 144 if (((mapto = map_to_address ()) == 0) ||
77fe3f84 145 ((md = mmalloc_attach (fd, (PTR) mapto)) == NULL))
318bf84f 146 {
4ed3a9ea 147 close (fd);
318bf84f
FF
148 }
149 else if ((objfile = (struct objfile *) mmalloc_getkey (md, 0)) != NULL)
150 {
3624c875
FF
151 /* Update memory corruption handler function addresses. */
152 init_malloc (md);
318bf84f 153 objfile -> md = md;
2d6d969c 154 objfile -> mmfd = fd;
318bf84f
FF
155 /* Update pointers to functions to *our* copies */
156 obstack_chunkfun (&objfile -> psymbol_obstack, xmmalloc);
157 obstack_freefun (&objfile -> psymbol_obstack, mfree);
158 obstack_chunkfun (&objfile -> symbol_obstack, xmmalloc);
159 obstack_freefun (&objfile -> symbol_obstack, mfree);
160 obstack_chunkfun (&objfile -> type_obstack, xmmalloc);
161 obstack_freefun (&objfile -> type_obstack, mfree);
6c316cfd
FF
162 /* If already in objfile list, unlink it. */
163 unlink_objfile (objfile);
164 /* Forget things specific to a particular gdb, may have changed. */
165 objfile -> sf = NULL;
318bf84f
FF
166 }
167 else
168 {
3624c875
FF
169 /* Set up to detect internal memory corruption. MUST be done before
170 the first malloc. See comments in init_malloc() and mmcheck(). */
171 init_malloc (md);
318bf84f 172 objfile = (struct objfile *) xmmalloc (md, sizeof (struct objfile));
4ed3a9ea 173 memset (objfile, 0, sizeof (struct objfile));
318bf84f 174 objfile -> md = md;
2d6d969c 175 objfile -> mmfd = fd;
318bf84f
FF
176 objfile -> flags |= OBJF_MAPPED;
177 mmalloc_setkey (objfile -> md, 0, objfile);
cd46ffad
FF
178 obstack_specify_allocation_with_arg (&objfile -> psymbol_obstack,
179 0, 0, xmmalloc, mfree,
180 objfile -> md);
181 obstack_specify_allocation_with_arg (&objfile -> symbol_obstack,
182 0, 0, xmmalloc, mfree,
183 objfile -> md);
184 obstack_specify_allocation_with_arg (&objfile -> type_obstack,
185 0, 0, xmmalloc, mfree,
186 objfile -> md);
318bf84f
FF
187 }
188 }
189
190 if (mapped && (objfile == NULL))
191 {
b0246b3b
FF
192 warning ("symbol table for '%s' will not be mapped",
193 bfd_get_filename (abfd));
318bf84f 194 }
1ab3bf1b 195
318bf84f 196#else /* defined(NO_MMALLOC) || !defined(HAVE_MMAP) */
1ab3bf1b 197
318bf84f 198 if (mapped)
1ab3bf1b 199 {
318bf84f
FF
200 warning ("this version of gdb does not support mapped symbol tables.");
201
202 /* Turn off the global flag so we don't try to do mapped symbol tables
203 any more, which shuts up gdb unless the user specifically gives the
204 "mapped" keyword again. */
205
206 mapped_symbol_files = 0;
1ab3bf1b 207 }
318bf84f
FF
208
209#endif /* !defined(NO_MMALLOC) && defined(HAVE_MMAP) */
210
211 /* If we don't support mapped symbol files, didn't ask for the file to be
212 mapped, or failed to open the mapped file for some reason, then revert
213 back to an unmapped objfile. */
214
215 if (objfile == NULL)
1ab3bf1b
JG
216 {
217 objfile = (struct objfile *) xmalloc (sizeof (struct objfile));
4ed3a9ea 218 memset (objfile, 0, sizeof (struct objfile));
318bf84f 219 objfile -> md = NULL;
cd46ffad
FF
220 obstack_specify_allocation (&objfile -> psymbol_obstack, 0, 0, xmalloc,
221 free);
222 obstack_specify_allocation (&objfile -> symbol_obstack, 0, 0, xmalloc,
223 free);
224 obstack_specify_allocation (&objfile -> type_obstack, 0, 0, xmalloc,
225 free);
1ab3bf1b
JG
226 }
227
b0246b3b
FF
228 /* Update the per-objfile information that comes from the bfd, ensuring
229 that any data that is reference is saved in the per-objfile data
230 region. */
1ab3bf1b
JG
231
232 objfile -> obfd = abfd;
2d6d969c
FF
233 if (objfile -> name != NULL)
234 {
235 mfree (objfile -> md, objfile -> name);
236 }
b0246b3b 237 objfile -> name = mstrsave (objfile -> md, bfd_get_filename (abfd));
1ab3bf1b
JG
238 objfile -> mtime = bfd_get_mtime (abfd);
239
73d0fc78
RP
240 /* Build section table. */
241
242 if (build_objfile_section_table (objfile))
243 {
244 error ("Can't find the file sections in `%s': %s",
245 objfile -> name, bfd_errmsg (bfd_error));
246 }
247
1ab3bf1b
JG
248 /* Push this file onto the head of the linked list of other such files. */
249
250 objfile -> next = object_files;
251 object_files = objfile;
252
253 return (objfile);
254}
255
6c316cfd
FF
256/* Unlink OBJFILE from the list of known objfiles, if it is found in the
257 list.
258
259 It is not a bug, or error, to call this function if OBJFILE is not known
260 to be in the current list. This is done in the case of mapped objfiles,
261 for example, just to ensure that the mapped objfile doesn't appear twice
262 in the list. Since the list is threaded, linking in a mapped objfile
263 twice would create a circular list.
264
265 If OBJFILE turns out to be in the list, we zap it's NEXT pointer after
266 unlinking it, just to ensure that we have completely severed any linkages
267 between the OBJFILE and the list. */
268
269void
270unlink_objfile (objfile)
271 struct objfile *objfile;
272{
273 struct objfile** objpp;
274
275 for (objpp = &object_files; *objpp != NULL; objpp = &((*objpp) -> next))
276 {
277 if (*objpp == objfile)
278 {
279 *objpp = (*objpp) -> next;
280 objfile -> next = NULL;
281 break;
282 }
283 }
284}
285
1ab3bf1b
JG
286
287/* Destroy an objfile and all the symtabs and psymtabs under it. Note
288 that as much as possible is allocated on the symbol_obstack and
80d68b1d
FF
289 psymbol_obstack, so that the memory can be efficiently freed.
290
291 Things which we do NOT free because they are not in malloc'd memory
292 or not in memory specific to the objfile include:
293
294 objfile -> sf
295
2d6d969c
FF
296 FIXME: If the objfile is using reusable symbol information (via mmalloc),
297 then we need to take into account the fact that more than one process
298 may be using the symbol information at the same time (when mmalloc is
299 extended to support cooperative locking). When more than one process
300 is using the mapped symbol info, we need to be more careful about when
301 we free objects in the reusable area. */
1ab3bf1b
JG
302
303void
304free_objfile (objfile)
305 struct objfile *objfile;
306{
2d6d969c
FF
307 int mmfd;
308
309 /* First do any symbol file specific actions required when we are
310 finished with a particular symbol file. Note that if the objfile
311 is using reusable symbol information (via mmalloc) then each of
312 these routines is responsible for doing the correct thing, either
313 freeing things which are valid only during this particular gdb
314 execution, or leaving them to be reused during the next one. */
1ab3bf1b 315
80d68b1d
FF
316 if (objfile -> sf != NULL)
317 {
318 (*objfile -> sf -> sym_finish) (objfile);
319 }
2d6d969c
FF
320
321 /* We always close the bfd. */
322
80d68b1d 323 if (objfile -> obfd != NULL)
1ab3bf1b 324 {
346168a2 325 char *name = bfd_get_filename (objfile->obfd);
1ab3bf1b 326 bfd_close (objfile -> obfd);
346168a2 327 free (name);
1ab3bf1b
JG
328 }
329
2d6d969c 330 /* Remove it from the chain of all objfiles. */
1ab3bf1b 331
6c316cfd 332 unlink_objfile (objfile);
1ab3bf1b 333
1ab3bf1b
JG
334 /* Before the symbol table code was redone to make it easier to
335 selectively load and remove information particular to a specific
336 linkage unit, gdb used to do these things whenever the monolithic
337 symbol table was blown away. How much still needs to be done
338 is unknown, but we play it safe for now and keep each action until
339 it is shown to be no longer needed. */
340
1ab3bf1b
JG
341#if defined (CLEAR_SOLIB)
342 CLEAR_SOLIB ();
c5198d93
JK
343 /* CLEAR_SOLIB closes the bfd's for any shared libraries. But
344 the to_sections for a core file might refer to those bfd's. So
345 detach any core file. */
346 {
347 struct target_ops *t = find_core_target ();
348 if (t != NULL)
349 (t->to_detach) (NULL, 0);
350 }
1ab3bf1b
JG
351#endif
352 clear_pc_function_cache ();
353
2d6d969c
FF
354 /* The last thing we do is free the objfile struct itself for the
355 non-reusable case, or detach from the mapped file for the reusable
356 case. Note that the mmalloc_detach or the mfree is the last thing
357 we can do with this objfile. */
1ab3bf1b 358
55b3ef9a
FF
359#if !defined(NO_MMALLOC) && defined(HAVE_MMAP)
360
2d6d969c
FF
361 if (objfile -> flags & OBJF_MAPPED)
362 {
363 /* Remember the fd so we can close it. We can't close it before
364 doing the detach, and after the detach the objfile is gone. */
365 mmfd = objfile -> mmfd;
366 mmalloc_detach (objfile -> md);
55b3ef9a 367 objfile = NULL;
4ed3a9ea 368 close (mmfd);
2d6d969c 369 }
55b3ef9a
FF
370
371#endif /* !defined(NO_MMALLOC) && defined(HAVE_MMAP) */
372
373 /* If we still have an objfile, then either we don't support reusable
374 objfiles or this one was not reusable. So free it normally. */
375
376 if (objfile != NULL)
2d6d969c
FF
377 {
378 if (objfile -> name != NULL)
379 {
380 mfree (objfile -> md, objfile -> name);
381 }
346168a2
JG
382 if (objfile->global_psymbols.list)
383 mfree (objfile->md, objfile->global_psymbols.list);
384 if (objfile->static_psymbols.list)
385 mfree (objfile->md, objfile->static_psymbols.list);
2d6d969c
FF
386 /* Free the obstacks for non-reusable objfiles */
387 obstack_free (&objfile -> psymbol_obstack, 0);
388 obstack_free (&objfile -> symbol_obstack, 0);
389 obstack_free (&objfile -> type_obstack, 0);
390 mfree (objfile -> md, objfile);
55b3ef9a 391 objfile = NULL;
2d6d969c 392 }
1ab3bf1b
JG
393}
394
cba0d141 395
0eb22669 396/* Free all the object files at once and clean up their users. */
cba0d141
JG
397
398void
399free_all_objfiles ()
400{
401 struct objfile *objfile, *temp;
402
403 ALL_OBJFILES_SAFE (objfile, temp)
404 {
405 free_objfile (objfile);
406 }
0eb22669 407 clear_symtab_users ();
cba0d141 408}
3c02636b
JK
409\f
410/* Relocate OBJFILE to NEW_OFFSETS. There should be OBJFILE->NUM_SECTIONS
411 entries in new_offsets. */
412void
413objfile_relocate (objfile, new_offsets)
414 struct objfile *objfile;
415 struct section_offsets *new_offsets;
416{
417 struct section_offsets *delta = (struct section_offsets *) alloca
418 (sizeof (struct section_offsets)
419 + objfile->num_sections * sizeof (delta->offsets));
420
421 {
422 int i;
423 int something_changed = 0;
424 for (i = 0; i < objfile->num_sections; ++i)
425 {
426 ANOFFSET (delta, i) =
427 ANOFFSET (new_offsets, i) - ANOFFSET (objfile->section_offsets, i);
428 if (ANOFFSET (delta, i) != 0)
429 something_changed = 1;
430 }
431 if (!something_changed)
432 return;
433 }
434
435 /* OK, get all the symtabs. */
436 {
437 struct symtab *s;
438
439 for (s = objfile->symtabs; s; s = s->next)
440 {
441 struct linetable *l;
442 struct blockvector *bv;
443 int i;
444
445 /* First the line table. */
446 l = LINETABLE (s);
447 if (l)
448 {
449 for (i = 0; i < l->nitems; ++i)
450 l->item[i].pc += ANOFFSET (delta, s->block_line_section);
451 }
452
453 /* Don't relocate a shared blockvector more than once. */
454 if (!s->primary)
455 continue;
456
457 bv = BLOCKVECTOR (s);
458 for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); ++i)
459 {
460 struct block *b;
461 int j;
462
463 b = BLOCKVECTOR_BLOCK (bv, i);
464 BLOCK_START (b) += ANOFFSET (delta, s->block_line_section);
465 BLOCK_END (b) += ANOFFSET (delta, s->block_line_section);
466
467 for (j = 0; j < BLOCK_NSYMS (b); ++j)
468 {
469 struct symbol *sym = BLOCK_SYM (b, j);
470 /* The RS6000 code from which this was taken skipped
471 any symbols in STRUCT_NAMESPACE or UNDEF_NAMESPACE.
472 But I'm leaving out that test, on the theory that
473 they can't possibly pass the tests below. */
474 if ((SYMBOL_CLASS (sym) == LOC_LABEL
475 || SYMBOL_CLASS (sym) == LOC_STATIC)
476 && SYMBOL_SECTION (sym) >= 0)
477 {
478 SYMBOL_VALUE_ADDRESS (sym) +=
479 ANOFFSET (delta, SYMBOL_SECTION (sym));
480 }
481 }
482 }
483 }
484 }
485
610a7e74
ILT
486 {
487 struct partial_symtab *p;
488
489 ALL_OBJFILE_PSYMTABS (objfile, p)
490 {
804506f6
JK
491 /* FIXME: specific to symbol readers which use gdb-stabs.h.
492 We can only get away with it since objfile_relocate is only
493 used on XCOFF, which lacks psymtabs, and for gdb-stabs.h
494 targets. */
610a7e74
ILT
495 p->textlow += ANOFFSET (delta, SECT_OFF_TEXT);
496 p->texthigh += ANOFFSET (delta, SECT_OFF_TEXT);
497 }
498 }
499
500 {
501 struct partial_symbol *psym;
502
503 for (psym = objfile->global_psymbols.list;
504 psym < objfile->global_psymbols.next;
505 psym++)
506 if (SYMBOL_SECTION (psym) >= 0)
507 SYMBOL_VALUE_ADDRESS (psym) += ANOFFSET (delta, SYMBOL_SECTION (psym));
508 for (psym = objfile->static_psymbols.list;
509 psym < objfile->static_psymbols.next;
510 psym++)
511 if (SYMBOL_SECTION (psym) >= 0)
512 SYMBOL_VALUE_ADDRESS (psym) += ANOFFSET (delta, SYMBOL_SECTION (psym));
513 }
514
3c02636b
JK
515 {
516 struct minimal_symbol *msym;
517 ALL_OBJFILE_MSYMBOLS (objfile, msym)
610a7e74
ILT
518 if (SYMBOL_SECTION (msym) >= 0)
519 SYMBOL_VALUE_ADDRESS (msym) += ANOFFSET (delta, SYMBOL_SECTION (msym));
3c02636b
JK
520 }
521
522 {
523 int i;
524 for (i = 0; i < objfile->num_sections; ++i)
525 ANOFFSET (objfile->section_offsets, i) = ANOFFSET (new_offsets, i);
526 }
527}
528\f
1ab3bf1b
JG
529/* Many places in gdb want to test just to see if we have any partial
530 symbols available. This function returns zero if none are currently
531 available, nonzero otherwise. */
532
533int
534have_partial_symbols ()
535{
536 struct objfile *ofp;
1ab3bf1b 537
84ffdec2 538 ALL_OBJFILES (ofp)
1ab3bf1b
JG
539 {
540 if (ofp -> psymtabs != NULL)
541 {
84ffdec2 542 return 1;
1ab3bf1b
JG
543 }
544 }
84ffdec2 545 return 0;
1ab3bf1b
JG
546}
547
548/* Many places in gdb want to test just to see if we have any full
549 symbols available. This function returns zero if none are currently
550 available, nonzero otherwise. */
551
552int
553have_full_symbols ()
554{
555 struct objfile *ofp;
1ab3bf1b 556
84ffdec2 557 ALL_OBJFILES (ofp)
1ab3bf1b
JG
558 {
559 if (ofp -> symtabs != NULL)
560 {
84ffdec2 561 return 1;
1ab3bf1b
JG
562 }
563 }
84ffdec2 564 return 0;
1ab3bf1b
JG
565}
566
567/* Many places in gdb want to test just to see if we have any minimal
568 symbols available. This function returns zero if none are currently
569 available, nonzero otherwise. */
570
571int
572have_minimal_symbols ()
573{
574 struct objfile *ofp;
1ab3bf1b 575
84ffdec2 576 ALL_OBJFILES (ofp)
1ab3bf1b
JG
577 {
578 if (ofp -> msymbols != NULL)
579 {
84ffdec2 580 return 1;
1ab3bf1b
JG
581 }
582 }
84ffdec2 583 return 0;
1ab3bf1b
JG
584}
585
1867b3be
FF
586#if !defined(NO_MMALLOC) && defined(HAVE_MMAP)
587
588/* Given the name of a mapped symbol file in SYMSFILENAME, and the timestamp
589 of the corresponding symbol file in MTIME, try to open an existing file
590 with the name SYMSFILENAME and verify it is more recent than the base
591 file by checking it's timestamp against MTIME.
592
593 If SYMSFILENAME does not exist (or can't be stat'd), simply returns -1.
594
595 If SYMSFILENAME does exist, but is out of date, we check to see if the
596 user has specified creation of a mapped file. If so, we don't issue
597 any warning message because we will be creating a new mapped file anyway,
598 overwriting the old one. If not, then we issue a warning message so that
599 the user will know why we aren't using this existing mapped symbol file.
600 In either case, we return -1.
601
602 If SYMSFILENAME does exist and is not out of date, but can't be opened for
603 some reason, then prints an appropriate system error message and returns -1.
604
605 Otherwise, returns the open file descriptor. */
606
607static int
608open_existing_mapped_file (symsfilename, mtime, mapped)
609 char *symsfilename;
610 long mtime;
611 int mapped;
612{
613 int fd = -1;
614 struct stat sbuf;
615
616 if (stat (symsfilename, &sbuf) == 0)
617 {
618 if (sbuf.st_mtime < mtime)
619 {
620 if (!mapped)
621 {
a679650f
FF
622 warning ("mapped symbol file `%s' is out of date, ignored it",
623 symsfilename);
1867b3be
FF
624 }
625 }
626 else if ((fd = open (symsfilename, O_RDWR)) < 0)
627 {
628 if (error_pre_print)
629 {
630 printf (error_pre_print);
631 }
632 print_sys_errmsg (symsfilename, errno);
633 }
634 }
635 return (fd);
636}
637
b0246b3b 638/* Look for a mapped symbol file that corresponds to FILENAME and is more
318bf84f 639 recent than MTIME. If MAPPED is nonzero, the user has asked that gdb
b0246b3b
FF
640 use a mapped symbol file for this file, so create a new one if one does
641 not currently exist.
318bf84f
FF
642
643 If found, then return an open file descriptor for the file, otherwise
644 return -1.
645
646 This routine is responsible for implementing the policy that generates
647 the name of the mapped symbol file from the name of a file containing
1867b3be
FF
648 symbols that gdb would like to read. Currently this policy is to append
649 ".syms" to the name of the file.
650
651 This routine is also responsible for implementing the policy that
652 determines where the mapped symbol file is found (the search path).
653 This policy is that when reading an existing mapped file, a file of
654 the correct name in the current directory takes precedence over a
655 file of the correct name in the same directory as the symbol file.
656 When creating a new mapped file, it is always created in the current
657 directory. This helps to minimize the chances of a user unknowingly
658 creating big mapped files in places like /bin and /usr/local/bin, and
659 allows a local copy to override a manually installed global copy (in
660 /bin for example). */
318bf84f
FF
661
662static int
b0246b3b
FF
663open_mapped_file (filename, mtime, mapped)
664 char *filename;
318bf84f
FF
665 long mtime;
666 int mapped;
667{
668 int fd;
1867b3be 669 char *symsfilename;
318bf84f 670
1867b3be
FF
671 /* First try to open an existing file in the current directory, and
672 then try the directory where the symbol file is located. */
318bf84f 673
1867b3be
FF
674 symsfilename = concat ("./", basename (filename), ".syms", (char *) NULL);
675 if ((fd = open_existing_mapped_file (symsfilename, mtime, mapped)) < 0)
318bf84f 676 {
1867b3be
FF
677 free (symsfilename);
678 symsfilename = concat (filename, ".syms", (char *) NULL);
679 fd = open_existing_mapped_file (symsfilename, mtime, mapped);
318bf84f
FF
680 }
681
1867b3be
FF
682 /* If we don't have an open file by now, then either the file does not
683 already exist, or the base file has changed since it was created. In
684 either case, if the user has specified use of a mapped file, then
685 create a new mapped file, truncating any existing one. If we can't
686 create one, print a system error message saying why we can't.
318bf84f
FF
687
688 By default the file is rw for everyone, with the user's umask taking
689 care of turning off the permissions the user wants off. */
690
1867b3be 691 if ((fd < 0) && mapped)
318bf84f 692 {
1867b3be
FF
693 free (symsfilename);
694 symsfilename = concat ("./", basename (filename), ".syms",
695 (char *) NULL);
696 if ((fd = open (symsfilename, O_RDWR | O_CREAT | O_TRUNC, 0666)) < 0)
697 {
698 if (error_pre_print)
699 {
700 printf (error_pre_print);
701 }
702 print_sys_errmsg (symsfilename, errno);
703 }
318bf84f
FF
704 }
705
1867b3be 706 free (symsfilename);
318bf84f
FF
707 return (fd);
708}
709
710/* Return the base address at which we would like the next objfile's
711 mapped data to start.
712
713 For now, we use the kludge that the configuration specifies a base
714 address to which it is safe to map the first mmalloc heap, and an
715 increment to add to this address for each successive heap. There are
716 a lot of issues to deal with here to make this work reasonably, including:
717
718 Avoid memory collisions with existing mapped address spaces
719
720 Reclaim address spaces when their mmalloc heaps are unmapped
721
722 When mmalloc heaps are shared between processes they have to be
723 mapped at the same addresses in each
724
725 Once created, a mmalloc heap that is to be mapped back in must be
726 mapped at the original address. I.E. each objfile will expect to
727 be remapped at it's original address. This becomes a problem if
728 the desired address is already in use.
729
730 etc, etc, etc.
731
732 */
733
734
735static CORE_ADDR
736map_to_address ()
737{
738
739#if defined(MMAP_BASE_ADDRESS) && defined (MMAP_INCREMENT)
740
741 static CORE_ADDR next = MMAP_BASE_ADDRESS;
742 CORE_ADDR mapto = next;
743
744 next += MMAP_INCREMENT;
745 return (mapto);
746
747#else
748
749 return (0);
750
751#endif
752
753}
1867b3be
FF
754
755#endif /* !defined(NO_MMALLOC) && defined(HAVE_MMAP) */
73d0fc78
RP
756
757/* Returns a section whose range includes PC or NULL if none found. */
758
4365c36c 759struct obj_section *
73d0fc78
RP
760find_pc_section(pc)
761 CORE_ADDR pc;
762{
763 struct obj_section *s;
764 struct objfile *objfile;
765
766 ALL_OBJFILES (objfile)
767 for (s = objfile->sections; s < objfile->sections_end; ++s)
768 if (s->addr <= pc
769 && pc < s->endaddr)
4365c36c 770 return(s);
73d0fc78
RP
771
772 return(NULL);
773}
This page took 0.140151 seconds and 4 git commands to generate.