* breakpoint.h (struct bp_location): Change type of section
[deliverable/binutils-gdb.git] / gdb / symfile.c
index 8d22005eda6a7363abab072ff20e864b77b40c5c..d067d2be536b0caafbb89e1abe6d9a688570cfc3 100644 (file)
@@ -111,8 +111,6 @@ static void decrement_reading_symtab (void *);
 
 static void overlay_invalidate_all (void);
 
-static int overlay_is_mapped (struct obj_section *);
-
 void list_overlays_command (char *, int);
 
 void map_overlay_command (char *, int);
@@ -3253,7 +3251,7 @@ init_psymbol_list (struct objfile *objfile, int total_symbols)
    section, return that section.
    find_pc_overlay(pc):       find any overlay section that contains
    the pc, either in its VMA or its LMA
-   overlay_is_mapped(sect):       true if overlay is marked as mapped
+   section_is_mapped(sect):       true if overlay is marked as mapped
    section_is_overlay(sect):      true if section's VMA != LMA
    pc_in_mapped_range(pc,sec):    true if pc belongs to section's VMA
    pc_in_unmapped_range(...):     true if pc belongs to section's LMA
@@ -3275,14 +3273,18 @@ int overlay_cache_invalid = 0;  /* True if need to refresh mapped state */
    SECTION is loaded at an address different from where it will "run".  */
 
 int
-section_is_overlay (asection *section)
+section_is_overlay (struct obj_section *section)
 {
-  /* FIXME: need bfd *, so we can use bfd_section_lma methods. */
-
-  if (overlay_debugging)
-    if (section && section->lma != 0 &&
-       section->vma != section->lma)
-      return 1;
+  if (overlay_debugging && section)
+    {
+      bfd *abfd = section->objfile->obfd;
+      asection *bfd_section = section->the_bfd_section;
+  
+      if (bfd_section_lma (abfd, bfd_section) != 0
+         && bfd_section_lma (abfd, bfd_section)
+            != bfd_section_vma (abfd, bfd_section))
+       return 1;
+    }
 
   return 0;
 }
@@ -3297,13 +3299,12 @@ overlay_invalidate_all (void)
   struct obj_section *sect;
 
   ALL_OBJSECTIONS (objfile, sect)
-    if (section_is_overlay (sect->the_bfd_section))
-    sect->ovly_mapped = -1;
+    if (section_is_overlay (sect))
+      sect->ovly_mapped = -1;
 }
 
-/* Function: overlay_is_mapped (SECTION)
+/* Function: section_is_mapped (SECTION)
    Returns true if section is an overlay, and is currently mapped.
-   Private: public access is thru function section_is_mapped.
 
    Access to the ovly_mapped flag is restricted to this function, so
    that we can do automatic update.  If the global flag
@@ -3311,10 +3312,10 @@ overlay_invalidate_all (void)
    overlay_invalidate_all.  If the mapped state of the particular
    section is stale, then call TARGET_OVERLAY_UPDATE to refresh it.  */
 
-static int
-overlay_is_mapped (struct obj_section *osect)
+int
+section_is_mapped (struct obj_section *osect)
 {
-  if (osect == 0 || !section_is_overlay (osect->the_bfd_section))
+  if (osect == 0 || !section_is_overlay (osect))
     return 0;
 
   switch (overlay_debugging)
@@ -3341,41 +3342,26 @@ overlay_is_mapped (struct obj_section *osect)
     }
 }
 
-/* Function: section_is_mapped
-   Returns true if section is an overlay, and is currently mapped.  */
-
-int
-section_is_mapped (asection *section)
-{
-  struct objfile *objfile;
-  struct obj_section *osect;
-
-  if (overlay_debugging)
-    if (section && section_is_overlay (section))
-      ALL_OBJSECTIONS (objfile, osect)
-       if (osect->the_bfd_section == section)
-       return overlay_is_mapped (osect);
-
-  return 0;
-}
-
 /* Function: pc_in_unmapped_range
    If PC falls into the lma range of SECTION, return true, else false.  */
 
 CORE_ADDR
-pc_in_unmapped_range (CORE_ADDR pc, asection *section)
+pc_in_unmapped_range (CORE_ADDR pc, struct obj_section *section)
 {
-  /* FIXME: need bfd *, so we can use bfd_section_lma methods. */
+  if (section_is_overlay (section))
+    {
+      bfd *abfd = section->objfile->obfd;
+      asection *bfd_section = section->the_bfd_section;
 
-  int size;
+      /* We assume the LMA is relocated by the same offset as the VMA.  */
+      bfd_vma size = bfd_get_section_size (bfd_section);
+      CORE_ADDR offset = obj_section_offset (section);
+
+      if (bfd_get_section_lma (abfd, bfd_section) + offset <= pc
+         && pc < bfd_get_section_lma (abfd, bfd_section) + offset + size)
+       return 1;
+    }
 
-  if (overlay_debugging)
-    if (section && section_is_overlay (section))
-      {
-       size = bfd_get_section_size (section);
-       if (section->lma <= pc && pc < section->lma + size)
-         return 1;
-      }
   return 0;
 }
 
@@ -3383,19 +3369,15 @@ pc_in_unmapped_range (CORE_ADDR pc, asection *section)
    If PC falls into the vma range of SECTION, return true, else false.  */
 
 CORE_ADDR
-pc_in_mapped_range (CORE_ADDR pc, asection *section)
+pc_in_mapped_range (CORE_ADDR pc, struct obj_section *section)
 {
-  /* FIXME: need bfd *, so we can use bfd_section_vma methods. */
-
-  int size;
+  if (section_is_overlay (section))
+    {
+      if (obj_section_addr (section) <= pc
+         && pc < obj_section_endaddr (section))
+       return 1;
+    }
 
-  if (overlay_debugging)
-    if (section && section_is_overlay (section))
-      {
-       size = bfd_get_section_size (section);
-       if (section->vma <= pc && pc < section->vma + size)
-         return 1;
-      }
   return 0;
 }
 
@@ -3403,14 +3385,12 @@ pc_in_mapped_range (CORE_ADDR pc, asection *section)
 /* Return true if the mapped ranges of sections A and B overlap, false
    otherwise.  */
 static int
-sections_overlap (asection *a, asection *b)
+sections_overlap (struct obj_section *a, struct obj_section *b)
 {
-  /* FIXME: need bfd *, so we can use bfd_section_vma methods. */
-
-  CORE_ADDR a_start = a->vma;
-  CORE_ADDR a_end = a->vma + bfd_get_section_size (a);
-  CORE_ADDR b_start = b->vma;
-  CORE_ADDR b_end = b->vma + bfd_get_section_size (b);
+  CORE_ADDR a_start = obj_section_addr (a);
+  CORE_ADDR a_end = obj_section_endaddr (a);
+  CORE_ADDR b_start = obj_section_addr (b);
+  CORE_ADDR b_end = obj_section_endaddr (b);
 
   return (a_start < b_end && b_start < a_end);
 }
@@ -3420,14 +3400,16 @@ sections_overlap (asection *a, asection *b)
    May be the same as PC.  */
 
 CORE_ADDR
-overlay_unmapped_address (CORE_ADDR pc, asection *section)
+overlay_unmapped_address (CORE_ADDR pc, struct obj_section *section)
 {
-  /* FIXME: need bfd *, so we can use bfd_section_lma methods. */
+  if (section_is_overlay (section) && pc_in_mapped_range (pc, section))
+    {
+      bfd *abfd = section->objfile->obfd;
+      asection *bfd_section = section->the_bfd_section;
 
-  if (overlay_debugging)
-    if (section && section_is_overlay (section) &&
-       pc_in_mapped_range (pc, section))
-      return pc + section->lma - section->vma;
+      return pc + bfd_section_lma (abfd, bfd_section)
+               - bfd_section_vma (abfd, bfd_section);
+    }
 
   return pc;
 }
@@ -3437,14 +3419,16 @@ overlay_unmapped_address (CORE_ADDR pc, asection *section)
    May be the same as PC.  */
 
 CORE_ADDR
-overlay_mapped_address (CORE_ADDR pc, asection *section)
+overlay_mapped_address (CORE_ADDR pc, struct obj_section *section)
 {
-  /* FIXME: need bfd *, so we can use bfd_section_vma methods. */
+  if (section_is_overlay (section) && pc_in_unmapped_range (pc, section))
+    {
+      bfd *abfd = section->objfile->obfd;
+      asection *bfd_section = section->the_bfd_section;
 
-  if (overlay_debugging)
-    if (section && section_is_overlay (section) &&
-       pc_in_unmapped_range (pc, section))
-      return pc + section->vma - section->lma;
+      return pc + bfd_section_vma (abfd, bfd_section)
+               - bfd_section_lma (abfd, bfd_section);
+    }
 
   return pc;
 }
@@ -3455,7 +3439,7 @@ overlay_mapped_address (CORE_ADDR pc, asection *section)
    depending on whether the section is mapped or not.  */
 
 CORE_ADDR
-symbol_overlayed_address (CORE_ADDR address, asection *section)
+symbol_overlayed_address (CORE_ADDR address, struct obj_section *section)
 {
   if (overlay_debugging)
     {
@@ -3483,7 +3467,7 @@ symbol_overlayed_address (CORE_ADDR address, asection *section)
    Else if PC matches an unmapped section's VMA, return that section.
    Else if PC matches an unmapped section's LMA, return that section.  */
 
-asection *
+struct obj_section *
 find_pc_overlay (CORE_ADDR pc)
 {
   struct objfile *objfile;
@@ -3491,26 +3475,26 @@ find_pc_overlay (CORE_ADDR pc)
 
   if (overlay_debugging)
     ALL_OBJSECTIONS (objfile, osect)
-      if (section_is_overlay (osect->the_bfd_section))
+      if (section_is_overlay (osect))
       {
-       if (pc_in_mapped_range (pc, osect->the_bfd_section))
+       if (pc_in_mapped_range (pc, osect))
          {
-           if (overlay_is_mapped (osect))
-             return osect->the_bfd_section;
+           if (section_is_mapped (osect))
+             return osect;
            else
              best_match = osect;
          }
-       else if (pc_in_unmapped_range (pc, osect->the_bfd_section))
+       else if (pc_in_unmapped_range (pc, osect))
          best_match = osect;
       }
-  return best_match ? best_match->the_bfd_section : NULL;
+  return best_match;
 }
 
 /* Function: find_pc_mapped_section (PC)
    If PC falls into the VMA address range of an overlay section that is
    currently marked as MAPPED, return that section.  Else return NULL.  */
 
-asection *
+struct obj_section *
 find_pc_mapped_section (CORE_ADDR pc)
 {
   struct objfile *objfile;
@@ -3518,9 +3502,8 @@ find_pc_mapped_section (CORE_ADDR pc)
 
   if (overlay_debugging)
     ALL_OBJSECTIONS (objfile, osect)
-      if (pc_in_mapped_range (pc, osect->the_bfd_section) &&
-         overlay_is_mapped (osect))
-      return osect->the_bfd_section;
+      if (pc_in_mapped_range (pc, osect) && section_is_mapped (osect))
+       return osect;
 
   return NULL;
 }
@@ -3537,7 +3520,7 @@ list_overlays_command (char *args, int from_tty)
 
   if (overlay_debugging)
     ALL_OBJSECTIONS (objfile, osect)
-      if (overlay_is_mapped (osect))
+      if (section_is_mapped (osect))
       {
        const char *name;
        bfd_vma lma, vma;
@@ -3572,7 +3555,6 @@ map_overlay_command (char *args, int from_tty)
 {
   struct objfile *objfile, *objfile2;
   struct obj_section *sec, *sec2;
-  asection *bfdsec;
 
   if (!overlay_debugging)
     error (_("\
@@ -3587,8 +3569,7 @@ the 'overlay manual' command."));
     if (!strcmp (bfd_section_name (objfile->obfd, sec->the_bfd_section), args))
     {
       /* Now, check to see if the section is an overlay. */
-      bfdsec = sec->the_bfd_section;
-      if (!section_is_overlay (bfdsec))
+      if (!section_is_overlay (sec))
        continue;               /* not an overlay section */
 
       /* Mark the overlay as "mapped" */
@@ -3597,11 +3578,7 @@ the 'overlay manual' command."));
       /* Next, make a pass and unmap any sections that are
          overlapped by this new section: */
       ALL_OBJSECTIONS (objfile2, sec2)
-       if (sec2->ovly_mapped
-            && sec != sec2
-            && sec->the_bfd_section != sec2->the_bfd_section
-            && sections_overlap (sec->the_bfd_section,
-                                 sec2->the_bfd_section))
+       if (sec2->ovly_mapped && sec != sec2 && sections_overlap (sec, sec2))
        {
          if (info_verbose)
            printf_unfiltered (_("Note: section %s unmapped by overlap\n"),
@@ -3941,7 +3918,7 @@ simple_overlay_update (struct obj_section *osect)
 
   /* Now may as well update all sections, even if only one was requested. */
   ALL_OBJSECTIONS (objfile, osect)
-    if (section_is_overlay (osect->the_bfd_section))
+    if (section_is_overlay (osect))
     {
       int i, size;
       bfd *obfd = osect->objfile->obfd;
This page took 0.02961 seconds and 4 git commands to generate.