]> Git Repo - binutils.git/blob - gdb/objfiles.c
* corelow.c (core_detach): Call reinit_frame_cache.
[binutils.git] / gdb / objfiles.c
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
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
20
21 /* This file contains support routines for creating, manipulating, and
22    destroying objfile structures. */
23
24 #include "defs.h"
25 #include "bfd.h"                /* Binary File Description */
26 #include "symtab.h"
27 #include "symfile.h"
28 #include "objfiles.h"
29 #include "gdb-stabs.h"
30 #include "target.h"
31
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 #include <fcntl.h>
35 #include <obstack.h>
36
37 /* Prototypes for local functions */
38
39 #if !defined(NO_MMALLOC) && defined(HAVE_MMAP)
40
41 static int
42 open_existing_mapped_file PARAMS ((char *, long, int));
43
44 static int
45 open_mapped_file PARAMS ((char *filename, long mtime, int mapped));
46
47 static CORE_ADDR
48 map_to_address PARAMS ((void));
49
50 #endif  /* !defined(NO_MMALLOC) && defined(HAVE_MMAP) */
51
52 /* Message to be printed before the error message, when an error occurs.  */
53
54 extern char *error_pre_print;
55
56 /* Externally visible variables that are owned by this module.
57    See declarations in objfile.h for more info. */
58
59 struct objfile *object_files;           /* Linked list of all objfiles */
60 struct objfile *current_objfile;        /* For symbol file being read in */
61 struct objfile *symfile_objfile;        /* Main symbol table loaded from */
62
63 int mapped_symbol_files;                /* Try to use mapped symbol files */
64
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
69 static void
70 add_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;
86   section.objfile = objfile;
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));
91   objfile->sections_end = (struct obj_section *) (((unsigned long) objfile->sections_end) + 1);
92 }
93
94 /* Builds a section table for OBJFILE.
95    Returns 0 if OK, 1 on error.  */
96
97 static int
98 build_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);
106   objfile->sections = (struct obj_section *)
107     obstack_finish (&objfile->psymbol_obstack);
108   objfile->sections_end = objfile->sections + (unsigned long) objfile->sections_end;
109   return(0);
110 }
111
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. */
116
117 struct objfile *
118 allocate_objfile (abfd, mapped)
119      bfd *abfd;
120      int mapped;
121 {
122   struct objfile *objfile = NULL;
123   int fd;
124   void *md;
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
140   fd = open_mapped_file (bfd_get_filename (abfd), bfd_get_mtime (abfd),
141                          mapped);
142   if (fd >= 0)
143     {
144       if (((mapto = map_to_address ()) == 0) ||
145           ((md = mmalloc_attach (fd, (void *) mapto)) == NULL))
146         {
147           close (fd);
148         }
149       else if ((objfile = (struct objfile *) mmalloc_getkey (md, 0)) != NULL)
150         {
151           /* Update memory corruption handler function addresses. */
152           init_malloc (md);
153           objfile -> md = md;
154           objfile -> mmfd = fd;
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);
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;
166         }
167       else
168         {
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);
172           objfile = (struct objfile *) xmmalloc (md, sizeof (struct objfile));
173           memset (objfile, 0, sizeof (struct objfile));
174           objfile -> md = md;
175           objfile -> mmfd = fd;
176           objfile -> flags |= OBJF_MAPPED;
177           mmalloc_setkey (objfile -> md, 0, objfile);
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);
187         }
188     }
189
190   if (mapped && (objfile == NULL))
191     {
192       warning ("symbol table for '%s' will not be mapped",
193                bfd_get_filename (abfd));
194     }
195
196 #else   /* defined(NO_MMALLOC) || !defined(HAVE_MMAP) */
197
198   if (mapped)
199     {
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;
207     }
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)
216     {
217       objfile = (struct objfile *) xmalloc (sizeof (struct objfile));
218       memset (objfile, 0, sizeof (struct objfile));
219       objfile -> md = NULL;
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);
226     }
227
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. */
231
232   objfile -> obfd = abfd;
233   if (objfile -> name != NULL)
234     {
235       mfree (objfile -> md, objfile -> name);
236     }
237   objfile -> name = mstrsave (objfile -> md, bfd_get_filename (abfd));
238   objfile -> mtime = bfd_get_mtime (abfd);
239
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
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
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
269 void
270 unlink_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
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
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
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. */
302
303 void
304 free_objfile (objfile)
305      struct objfile *objfile;
306 {
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. */
315
316   if (objfile -> sf != NULL)
317     {
318       (*objfile -> sf -> sym_finish) (objfile);
319     }
320
321   /* We always close the bfd. */
322
323   if (objfile -> obfd != NULL)
324     {
325       char *name = bfd_get_filename (objfile->obfd);
326       bfd_close (objfile -> obfd);
327       free (name);
328     }
329
330   /* Remove it from the chain of all objfiles. */
331
332   unlink_objfile (objfile);
333
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      
341 #if defined (CLEAR_SOLIB)
342   CLEAR_SOLIB ();
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   }
351 #endif
352   clear_pc_function_cache ();
353
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. */
358
359 #if !defined(NO_MMALLOC) && defined(HAVE_MMAP)
360
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);
367       objfile = NULL;
368       close (mmfd);
369     }
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)
377     {
378       if (objfile -> name != NULL)
379         {
380           mfree (objfile -> md, objfile -> name);
381         }
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);
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);
391       objfile = NULL;
392     }
393 }
394
395
396 /* Free all the object files at once and clean up their users.  */
397
398 void
399 free_all_objfiles ()
400 {
401   struct objfile *objfile, *temp;
402
403   ALL_OBJFILES_SAFE (objfile, temp)
404     {
405       free_objfile (objfile);
406     }
407   clear_symtab_users ();
408 }
409 \f
410 /* Relocate OBJFILE to NEW_OFFSETS.  There should be OBJFILE->NUM_SECTIONS
411    entries in new_offsets.  */
412 void
413 objfile_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
486   {
487     struct partial_symtab *p;
488
489     ALL_OBJFILE_PSYMTABS (objfile, p)
490       {
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.  */
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
515   {
516     struct minimal_symbol *msym;
517     ALL_OBJFILE_MSYMBOLS (objfile, msym)
518       if (SYMBOL_SECTION (msym) >= 0)
519         SYMBOL_VALUE_ADDRESS (msym) += ANOFFSET (delta, SYMBOL_SECTION (msym));
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
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
533 int
534 have_partial_symbols ()
535 {
536   struct objfile *ofp;
537
538   ALL_OBJFILES (ofp)
539     {
540       if (ofp -> psymtabs != NULL)
541         {
542           return 1;
543         }
544     }
545   return 0;
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
552 int
553 have_full_symbols ()
554 {
555   struct objfile *ofp;
556
557   ALL_OBJFILES (ofp)
558     {
559       if (ofp -> symtabs != NULL)
560         {
561           return 1;
562         }
563     }
564   return 0;
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
571 int
572 have_minimal_symbols ()
573 {
574   struct objfile *ofp;
575
576   ALL_OBJFILES (ofp)
577     {
578       if (ofp -> msymbols != NULL)
579         {
580           return 1;
581         }
582     }
583   return 0;
584 }
585
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
607 static int
608 open_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             {
622               warning ("mapped symbol file `%s' is out of date, ignored it",
623                        symsfilename);
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
638 /* Look for a mapped symbol file that corresponds to FILENAME and is more
639    recent than MTIME.  If MAPPED is nonzero, the user has asked that gdb
640    use a mapped symbol file for this file, so create a new one if one does
641    not currently exist.
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
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).  */
661
662 static int
663 open_mapped_file (filename, mtime, mapped)
664      char *filename;
665      long mtime;
666      int mapped;
667 {
668   int fd;
669   char *symsfilename;
670
671   /* First try to open an existing file in the current directory, and
672      then try the directory where the symbol file is located. */
673
674   symsfilename = concat ("./", basename (filename), ".syms", (char *) NULL);
675   if ((fd = open_existing_mapped_file (symsfilename, mtime, mapped)) < 0)
676     {
677       free (symsfilename);
678       symsfilename = concat (filename, ".syms", (char *) NULL);
679       fd = open_existing_mapped_file (symsfilename, mtime, mapped);
680     }
681
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.
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
691   if ((fd < 0) && mapped)
692     {
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         }
704     }
705
706   free (symsfilename);
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
735 static CORE_ADDR
736 map_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 }
754
755 #endif  /* !defined(NO_MMALLOC) && defined(HAVE_MMAP) */
756
757 /* Returns a section whose range includes PC or NULL if none found. */
758
759 struct obj_section *
760 find_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)
770         return(s);
771
772   return(NULL);
773 }
This page took 0.073557 seconds and 4 git commands to generate.