2003-10-10 Elena Zannoni <ezannoni@redhat.com>
[deliverable/binutils-gdb.git] / bfd / dwarf1.c
index 80fc242d38110f51a4fff225483a6f4fbb54de7a..1047ebfc2e997775956577f724afbbee0f224e98 100644 (file)
@@ -1,5 +1,5 @@
 /* DWARF 1 find nearest line (_bfd_dwarf1_find_nearest_line).
-   Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+   Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
 
 Written by Gavin Romig-Koch of Cygnus Solutions (gavin@cygnus.com).
 
@@ -126,15 +126,17 @@ struct linenumber {
 /* Find the form of an attr, from the attr field.  */
 #define FORM_FROM_ATTR(attr)   ((attr) & 0xF)  /* Implicitly specified */
 
-static struct dwarf1_unit *alloc_dwarf1_unit PARAMS ((struct dwarf1_debug *));
+static struct dwarf1_unit *alloc_dwarf1_unit
+  PARAMS ((struct dwarf1_debug *));
 static struct dwarf1_func *alloc_dwarf1_func
   PARAMS ((struct dwarf1_debug *, struct dwarf1_unit *));
-static boolean parse_die PARAMS ((bfd *, struct die_info *, char *));
-static boolean parse_line_table
+static bfd_boolean parse_die
+  PARAMS ((bfd *, struct die_info *, char *, char *));
+static bfd_boolean parse_line_table
   PARAMS ((struct dwarf1_debug *, struct dwarf1_unit *));
-static boolean parse_functions_in_unit
+static bfd_boolean parse_functions_in_unit
   PARAMS ((struct dwarf1_debug *, struct dwarf1_unit *));
-static boolean dwarf1_unit_find_nearest_line
+static bfd_boolean dwarf1_unit_find_nearest_line
   PARAMS ((struct dwarf1_debug *, struct dwarf1_unit *, unsigned long,
           const char **, const char **, unsigned int *));
 
@@ -145,9 +147,9 @@ static struct dwarf1_unit*
 alloc_dwarf1_unit (stash)
   struct dwarf1_debug* stash;
 {
-  struct dwarf1_unit* x =
-    (struct dwarf1_unit*) bfd_zalloc (stash->abfd,
-                                     sizeof (struct dwarf1_unit));
+  bfd_size_type amt = sizeof (struct dwarf1_unit);
+
+  struct dwarf1_unit* x = (struct dwarf1_unit*) bfd_zalloc (stash->abfd, amt);
   x->prev = stash->lastUnit;
   stash->lastUnit = x;
 
@@ -162,9 +164,9 @@ alloc_dwarf1_func (stash, aUnit)
      struct dwarf1_debug* stash;
      struct dwarf1_unit* aUnit;
 {
-  struct dwarf1_func* x =
-    (struct dwarf1_func*) bfd_zalloc (stash->abfd,
-                                     sizeof (struct dwarf1_func));
+  bfd_size_type amt = sizeof (struct dwarf1_func);
+
+  struct dwarf1_func* x = (struct dwarf1_func*) bfd_zalloc (stash->abfd, amt);
   x->prev = aUnit->func_list;
   aUnit->func_list = x;
 
@@ -176,13 +178,14 @@ alloc_dwarf1_func (stash, aUnit)
    'abfd' must be the bfd from which the section that 'aDiePtr'
    points to was pulled from.
 
-   Return false if the die is invalidly formatted; true otherwise.  */
+   Return FALSE if the die is invalidly formatted; TRUE otherwise.  */
 
-static boolean
-parse_die (abfd, aDieInfo, aDiePtr)
+static bfd_boolean
+parse_die (abfd, aDieInfo, aDiePtr, aDiePtrEnd)
      bfd* abfd;
      struct die_info* aDieInfo;
      char*            aDiePtr;
+     char*            aDiePtrEnd;
 {
   char* this_die = aDiePtr;
   char* xptr = this_die;
@@ -192,13 +195,14 @@ parse_die (abfd, aDieInfo, aDiePtr)
   /* First comes the length.  */
   aDieInfo->length = bfd_get_32 (abfd, (bfd_byte *) xptr);
   xptr += 4;
-  if (aDieInfo->length == 0)
-    return false;
+  if (aDieInfo->length == 0
+      || (this_die + aDieInfo->length) >= aDiePtrEnd)
+    return FALSE;
   if (aDieInfo->length < 6)
     {
       /* Just padding bytes.  */
       aDieInfo->tag = TAG_padding;
-      return true;
+      return TRUE;
     }
 
   /* Then the tag.  */
@@ -257,14 +261,14 @@ parse_die (abfd, aDieInfo, aDiePtr)
        }
     }
 
-  return true;
+  return TRUE;
 }
 
 /* Parse a dwarf1 line number table for 'aUnit->stmt_list_offset'
-   into 'aUnit->linenumber_table'.  Return false if an error
-   occurs; true otherwise.  */
+   into 'aUnit->linenumber_table'.  Return FALSE if an error
+   occurs; TRUE otherwise.  */
 
-static boolean
+static bfd_boolean
 parse_line_table (stash, aUnit)
   struct dwarf1_debug* stash;
   struct dwarf1_unit* aUnit;
@@ -275,22 +279,23 @@ parse_line_table (stash, aUnit)
   if (stash->line_section == 0)
     {
       asection *msec;
-      unsigned long size;
+      bfd_size_type size;
 
       msec = bfd_get_section_by_name (stash->abfd, ".line");
       if (! msec)
-       return false;
+       return FALSE;
 
       size = bfd_get_section_size_before_reloc (msec);
       stash->line_section = (char *) bfd_alloc (stash->abfd, size);
 
       if (! stash->line_section)
-       return false;
+       return FALSE;
 
-      if (! bfd_get_section_contents (stash->abfd, msec, stash->line_section, 0, size))
+      if (! bfd_get_section_contents (stash->abfd, msec, stash->line_section,
+                                     (bfd_vma) 0, size))
        {
          stash->line_section = 0;
-         return false;
+         return FALSE;
        }
 
       stash->line_section_end = stash->line_section + size;
@@ -300,9 +305,9 @@ parse_line_table (stash, aUnit)
   if (xptr < stash->line_section_end)
     {
       unsigned long eachLine;
-
-      char* tblend;
+      char *tblend;
       unsigned long base;
+      bfd_size_type amt;
 
       /* First comes the length.  */
       tblend = bfd_get_32 (stash->abfd, (bfd_byte *) xptr) + xptr;
@@ -317,9 +322,9 @@ parse_line_table (stash, aUnit)
       aUnit->line_count = (tblend - xptr) / 10;
 
       /* Allocate an array for the entries.  */
-      aUnit->linenumber_table = (struct linenumber *)
-       bfd_alloc (stash->abfd,
-                  sizeof (struct linenumber) * aUnit->line_count);
+      amt = sizeof (struct linenumber) * aUnit->line_count;
+      aUnit->linenumber_table = ((struct linenumber *)
+                                bfd_alloc (stash->abfd, amt));
 
       for (eachLine = 0; eachLine < aUnit->line_count; eachLine++)
        {
@@ -338,15 +343,15 @@ parse_line_table (stash, aUnit)
        }
     }
 
-  return true;
+  return TRUE;
 }
 
 /* Parse each function die in a compilation unit 'aUnit'.
    The first child die of 'aUnit' should be in 'aUnit->first_child',
    the result is placed in 'aUnit->func_list'.
-   Return false if error; true otherwise.  */
+   Return FALSE if error; TRUE otherwise.  */
 
-static boolean
+static bfd_boolean
 parse_functions_in_unit (stash, aUnit)
      struct dwarf1_debug* stash;
      struct dwarf1_unit* aUnit;
@@ -360,8 +365,9 @@ parse_functions_in_unit (stash, aUnit)
       {
        struct die_info eachDieInfo;
 
-       if (! parse_die (stash->abfd, &eachDieInfo, eachDie))
-         return false;
+       if (! parse_die (stash->abfd, &eachDieInfo, eachDie,
+                        stash->debug_section_end))
+         return FALSE;
 
        if (eachDieInfo.tag == TAG_global_subroutine
            || eachDieInfo.tag == TAG_subroutine
@@ -382,13 +388,13 @@ parse_functions_in_unit (stash, aUnit)
          break;
       }
 
-  return true;
+  return TRUE;
 }
 
 /* Find the nearest line to 'addr' in 'aUnit'.
    Return whether we found the line (or a function) without error.  */
 
-static boolean
+static bfd_boolean
 dwarf1_unit_find_nearest_line (stash, aUnit, addr,
                       filename_ptr, functionname_ptr,
                       linenumber_ptr)
@@ -399,8 +405,8 @@ dwarf1_unit_find_nearest_line (stash, aUnit, addr,
   const char **functionname_ptr;
   unsigned int *linenumber_ptr;
 {
-  int line_p = false;
-  int func_p = false;
+  int line_p = FALSE;
+  int func_p = FALSE;
 
   if (aUnit->low_pc <= addr && addr < aUnit->high_pc)
     {
@@ -412,13 +418,13 @@ dwarf1_unit_find_nearest_line (stash, aUnit, addr,
          if (! aUnit->linenumber_table)
            {
              if (! parse_line_table (stash, aUnit))
-               return false;
+               return FALSE;
            }
 
          if (! aUnit->func_list)
            {
              if (! parse_functions_in_unit (stash, aUnit))
-               return false;
+               return FALSE;
            }
 
          for (i = 0; i < aUnit->line_count; i++)
@@ -428,7 +434,7 @@ dwarf1_unit_find_nearest_line (stash, aUnit, addr,
                {
                  *filename_ptr = aUnit->name;
                  *linenumber_ptr = aUnit->linenumber_table[i].linenumber;
-                 line_p = true;
+                 line_p = TRUE;
                  break;
                }
            }
@@ -441,7 +447,7 @@ dwarf1_unit_find_nearest_line (stash, aUnit, addr,
                  && addr < eachFunc->high_pc)
                {
                  *functionname_ptr = eachFunc->name;
-                 func_p = true;
+                 func_p = TRUE;
                  break;
                }
            }
@@ -452,9 +458,9 @@ dwarf1_unit_find_nearest_line (stash, aUnit, addr,
 }
 
 /* The DWARF 1 version of find_nearest line.
-   Return true if the line is found without error.  */
+   Return TRUE if the line is found without error.  */
 
-boolean
+bfd_boolean
 _bfd_dwarf1_find_nearest_line (abfd, section, symbols, offset,
                               filename_ptr, functionname_ptr, linenumber_ptr)
      bfd *abfd;
@@ -479,13 +485,13 @@ _bfd_dwarf1_find_nearest_line (abfd, section, symbols, offset,
   if (! stash)
     {
       asection *msec;
-      unsigned long size;
+      bfd_size_type size = sizeof (struct dwarf1_debug);
 
-      stash = elf_tdata (abfd)->dwarf1_find_line_info =
-       (struct dwarf1_debug*) bfd_zalloc (abfd, sizeof (struct dwarf1_debug));
+      stash = elf_tdata (abfd)->dwarf1_find_line_info
+       = (struct dwarf1_debug *) bfd_zalloc (abfd, size);
 
       if (! stash)
-       return false;
+       return FALSE;
 
       msec = bfd_get_section_by_name (abfd, ".debug");
       if (! msec)
@@ -493,19 +499,20 @@ _bfd_dwarf1_find_nearest_line (abfd, section, symbols, offset,
          /* No dwarf1 info.  Note that at this point the stash
             has been allocated, but contains zeros, this lets
             future calls to this function fail quicker.  */
-         return false;
+         return FALSE;
        }
 
       size = bfd_get_section_size_before_reloc (msec);
       stash->debug_section = (char *) bfd_alloc (abfd, size);
 
       if (! stash->debug_section)
-       return false;
+       return FALSE;
 
-      if (! bfd_get_section_contents (abfd, msec, stash->debug_section, 0, size))
+      if (! bfd_get_section_contents (abfd, msec, stash->debug_section,
+                                     (bfd_vma) 0, size))
        {
          stash->debug_section = 0;
-         return false;
+         return FALSE;
        }
 
       stash->debug_section_end = stash->debug_section + size;
@@ -517,7 +524,7 @@ _bfd_dwarf1_find_nearest_line (abfd, section, symbols, offset,
      or that an error occured while setting up the stash.  */
 
   if (! stash->debug_section)
-    return false;
+    return FALSE;
 
   /* Look at the previously parsed units to see if any contain
      the addr.  */
@@ -534,8 +541,9 @@ _bfd_dwarf1_find_nearest_line (abfd, section, symbols, offset,
     {
       struct die_info aDieInfo;
 
-      if (! parse_die (stash->abfd, &aDieInfo, stash->currentDie))
-       return false;
+      if (! parse_die (stash->abfd, &aDieInfo, stash->currentDie,
+                      stash->debug_section_end))
+       return FALSE;
 
       if (aDieInfo.tag == TAG_compile_unit)
        {
@@ -572,7 +580,7 @@ _bfd_dwarf1_find_nearest_line (abfd, section, symbols, offset,
        stash->currentDie += aDieInfo.length;
     }
 
-  return false;
+  return FALSE;
 }
 
 /* EOF */
This page took 0.029323 seconds and 4 git commands to generate.