Ignore:
Timestamp:
Aug 16, 2003, 6:59:22 PM (22 years ago)
Author:
bird
Message:

binutils v2.14 - offical sources.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/binutils/bfd/dwarf1.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* DWARF 1 find nearest line (_bfd_dwarf1_find_nearest_line).
    2    Copyright 1998, 1999, 2000 Free Software Foundation, Inc.
     2   Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
    33
    44Written by Gavin Romig-Koch of Cygnus Solutions (gavin@cygnus.com).
     
    127127#define FORM_FROM_ATTR(attr)    ((attr) & 0xF)  /* Implicitly specified */
    128128
     129static struct dwarf1_unit *alloc_dwarf1_unit
     130  PARAMS ((struct dwarf1_debug *));
     131static struct dwarf1_func *alloc_dwarf1_func
     132  PARAMS ((struct dwarf1_debug *, struct dwarf1_unit *));
     133static bfd_boolean parse_die
     134  PARAMS ((bfd *, struct die_info *, char *, char *));
     135static bfd_boolean parse_line_table
     136  PARAMS ((struct dwarf1_debug *, struct dwarf1_unit *));
     137static bfd_boolean parse_functions_in_unit
     138  PARAMS ((struct dwarf1_debug *, struct dwarf1_unit *));
     139static bfd_boolean dwarf1_unit_find_nearest_line
     140  PARAMS ((struct dwarf1_debug *, struct dwarf1_unit *, unsigned long,
     141           const char **, const char **, unsigned int *));
     142
    129143/* Return a newly allocated dwarf1_unit.  It should be cleared and
    130144   then attached into the 'stash' at 'stash->lastUnit'.  */
     
    134148  struct dwarf1_debug* stash;
    135149{
    136   struct dwarf1_unit* x =
    137     (struct dwarf1_unit*) bfd_zalloc (stash->abfd,
    138                                       sizeof (struct dwarf1_unit));
     150  bfd_size_type amt = sizeof (struct dwarf1_unit);
     151
     152  struct dwarf1_unit* x = (struct dwarf1_unit*) bfd_zalloc (stash->abfd, amt);
    139153  x->prev = stash->lastUnit;
    140154  stash->lastUnit = x;
     
    151165     struct dwarf1_unit* aUnit;
    152166{
    153   struct dwarf1_func* x =
    154     (struct dwarf1_func*) bfd_zalloc (stash->abfd,
    155                                       sizeof (struct dwarf1_func));
     167  bfd_size_type amt = sizeof (struct dwarf1_func);
     168
     169  struct dwarf1_func* x = (struct dwarf1_func*) bfd_zalloc (stash->abfd, amt);
    156170  x->prev = aUnit->func_list;
    157171  aUnit->func_list = x;
     
    165179   points to was pulled from.
    166180
    167    Return false if the die is invalidly formatted; true otherwise.  */
    168 
    169 static boolean
    170 parse_die (abfd, aDieInfo, aDiePtr)
     181   Return FALSE if the die is invalidly formatted; TRUE otherwise.  */
     182
     183static bfd_boolean
     184parse_die (abfd, aDieInfo, aDiePtr, aDiePtrEnd)
    171185     bfd* abfd;
    172186     struct die_info* aDieInfo;
    173187     char*            aDiePtr;
     188     char*            aDiePtrEnd;
    174189{
    175190  char* this_die = aDiePtr;
     
    181196  aDieInfo->length = bfd_get_32 (abfd, (bfd_byte *) xptr);
    182197  xptr += 4;
    183   if (aDieInfo->length == 0)
    184     return false;
     198  if (aDieInfo->length == 0
     199      || (this_die + aDieInfo->length) >= aDiePtrEnd)
     200    return FALSE;
    185201  if (aDieInfo->length < 6)
    186202    {
    187203      /* Just padding bytes.  */
    188204      aDieInfo->tag = TAG_padding;
    189       return true;
     205      return TRUE;
    190206    }
    191207
     
    246262    }
    247263
    248   return true;
     264  return TRUE;
    249265}
    250266
    251267/* Parse a dwarf1 line number table for 'aUnit->stmt_list_offset'
    252    into 'aUnit->linenumber_table'.  Return false if an error
    253    occurs; true otherwise.  */
    254 
    255 static boolean
     268   into 'aUnit->linenumber_table'.  Return FALSE if an error
     269   occurs; TRUE otherwise.  */
     270
     271static bfd_boolean
    256272parse_line_table (stash, aUnit)
    257273  struct dwarf1_debug* stash;
     
    264280    {
    265281      asection *msec;
    266       unsigned long size;
     282      bfd_size_type size;
    267283
    268284      msec = bfd_get_section_by_name (stash->abfd, ".line");
    269285      if (! msec)
    270         return false;
     286        return FALSE;
    271287
    272288      size = bfd_get_section_size_before_reloc (msec);
     
    274290
    275291      if (! stash->line_section)
    276         return false;
    277 
    278       if (! bfd_get_section_contents (stash->abfd, msec, stash->line_section, 0, size))
     292        return FALSE;
     293
     294      if (! bfd_get_section_contents (stash->abfd, msec, stash->line_section,
     295                                      (bfd_vma) 0, size))
    279296        {
    280297          stash->line_section = 0;
    281           return false;
     298          return FALSE;
    282299        }
    283300
     
    289306    {
    290307      unsigned long eachLine;
    291 
    292       char* tblend;
     308      char *tblend;
    293309      unsigned long base;
     310      bfd_size_type amt;
    294311
    295312      /* First comes the length.  */
     
    306323
    307324      /* Allocate an array for the entries.  */
    308       aUnit->linenumber_table = (struct linenumber *)
    309         bfd_alloc (stash->abfd,
    310                    sizeof (struct linenumber) * aUnit->line_count);
     325      amt = sizeof (struct linenumber) * aUnit->line_count;
     326      aUnit->linenumber_table = ((struct linenumber *)
     327                                 bfd_alloc (stash->abfd, amt));
    311328
    312329      for (eachLine = 0; eachLine < aUnit->line_count; eachLine++)
     
    327344    }
    328345
    329   return true;
     346  return TRUE;
    330347}
    331348
     
    333350   The first child die of 'aUnit' should be in 'aUnit->first_child',
    334351   the result is placed in 'aUnit->func_list'.
    335    Return false if error; true otherwise.  */
    336 
    337 static boolean
     352   Return FALSE if error; TRUE otherwise.  */
     353
     354static bfd_boolean
    338355parse_functions_in_unit (stash, aUnit)
    339356     struct dwarf1_debug* stash;
     
    349366        struct die_info eachDieInfo;
    350367
    351         if (! parse_die (stash->abfd, &eachDieInfo, eachDie))
    352           return false;
     368        if (! parse_die (stash->abfd, &eachDieInfo, eachDie,
     369                         stash->debug_section_end))
     370          return FALSE;
    353371
    354372        if (eachDieInfo.tag == TAG_global_subroutine
     
    371389      }
    372390
    373   return true;
     391  return TRUE;
    374392}
    375393
     
    377395   Return whether we found the line (or a function) without error.  */
    378396
    379 static boolean
     397static bfd_boolean
    380398dwarf1_unit_find_nearest_line (stash, aUnit, addr,
    381399                       filename_ptr, functionname_ptr,
     
    388406  unsigned int *linenumber_ptr;
    389407{
    390   int line_p = false;
    391   int func_p = false;
     408  int line_p = FALSE;
     409  int func_p = FALSE;
    392410
    393411  if (aUnit->low_pc <= addr && addr < aUnit->high_pc)
     
    401419            {
    402420              if (! parse_line_table (stash, aUnit))
    403                 return false;
     421                return FALSE;
    404422            }
    405423
     
    407425            {
    408426              if (! parse_functions_in_unit (stash, aUnit))
    409                 return false;
     427                return FALSE;
    410428            }
    411429
     
    417435                  *filename_ptr = aUnit->name;
    418436                  *linenumber_ptr = aUnit->linenumber_table[i].linenumber;
    419                   line_p = true;
     437                  line_p = TRUE;
    420438                  break;
    421439                }
     
    430448                {
    431449                  *functionname_ptr = eachFunc->name;
    432                   func_p = true;
     450                  func_p = TRUE;
    433451                  break;
    434452                }
     
    441459
    442460/* The DWARF 1 version of find_nearest line.
    443    Return true if the line is found without error.  */
    444 
    445 boolean
     461   Return TRUE if the line is found without error.  */
     462
     463bfd_boolean
    446464_bfd_dwarf1_find_nearest_line (abfd, section, symbols, offset,
    447465                              filename_ptr, functionname_ptr, linenumber_ptr)
     
    468486    {
    469487      asection *msec;
    470       unsigned long size;
    471 
    472       stash = elf_tdata (abfd)->dwarf1_find_line_info =
    473         (struct dwarf1_debug*) bfd_zalloc (abfd, sizeof (struct dwarf1_debug));
     488      bfd_size_type size = sizeof (struct dwarf1_debug);
     489
     490      stash = elf_tdata (abfd)->dwarf1_find_line_info
     491        = (struct dwarf1_debug *) bfd_zalloc (abfd, size);
    474492
    475493      if (! stash)
    476         return false;
     494        return FALSE;
    477495
    478496      msec = bfd_get_section_by_name (abfd, ".debug");
     
    482500             has been allocated, but contains zeros, this lets
    483501             future calls to this function fail quicker.  */
    484           return false;
     502          return FALSE;
    485503        }
    486504
     
    489507
    490508      if (! stash->debug_section)
    491         return false;
    492 
    493       if (! bfd_get_section_contents (abfd, msec, stash->debug_section, 0, size))
     509        return FALSE;
     510
     511      if (! bfd_get_section_contents (abfd, msec, stash->debug_section,
     512                                      (bfd_vma) 0, size))
    494513        {
    495514          stash->debug_section = 0;
    496           return false;
     515          return FALSE;
    497516        }
    498517
     
    506525
    507526  if (! stash->debug_section)
    508     return false;
     527    return FALSE;
    509528
    510529  /* Look at the previously parsed units to see if any contain
     
    523542      struct die_info aDieInfo;
    524543
    525       if (! parse_die (stash->abfd, &aDieInfo, stash->currentDie))
    526         return false;
     544      if (! parse_die (stash->abfd, &aDieInfo, stash->currentDie,
     545                       stash->debug_section_end))
     546        return FALSE;
    527547
    528548      if (aDieInfo.tag == TAG_compile_unit)
     
    561581    }
    562582
    563   return false;
     583  return FALSE;
    564584}
    565585
Note: See TracChangeset for help on using the changeset viewer.