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/dwarf2.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* DWARF 2 support.
    2    Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
     2   Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
    33   Free Software Foundation, Inc.
    44
     
    1414   support in dwarfread.c
    1515
    16 This file is part of BFD.
    17 
    18 This program is free software; you can redistribute it and/or modify
    19 it under the terms of the GNU General Public License as published by
    20 the Free Software Foundation; either version 2 of the License, or (at
    21 your option) any later version.
    22 
    23 This program is distributed in the hope that it will be useful, but
    24 WITHOUT ANY WARRANTY; without even the implied warranty of
    25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    26 General Public License for more details.
    27 
    28 You should have received a copy of the GNU General Public License
    29 along with this program; if not, write to the Free Software
    30 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
     16   This file is part of BFD.
     17
     18   This program is free software; you can redistribute it and/or modify
     19   it under the terms of the GNU General Public License as published by
     20   the Free Software Foundation; either version 2 of the License, or (at
     21   your option) any later version.
     22
     23   This program is distributed in the hope that it will be useful, but
     24   WITHOUT ANY WARRANTY; without even the implied warranty of
     25   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     26   General Public License for more details.
     27
     28   You should have received a copy of the GNU General Public License
     29   along with this program; if not, write to the Free Software
     30   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
    3131
    3232#include "bfd.h"
     
    4141struct line_head
    4242{
    43   unsigned int total_length;
     43  bfd_vma total_length;
    4444  unsigned short version;
    45   unsigned int prologue_length;
     45  bfd_vma prologue_length;
    4646  unsigned char minimum_instruction_length;
    4747  unsigned char default_is_stmt;
     
    9797  char* info_ptr_end;
    9898
     99  /* Pointer to the section and address of the beginning of the
     100     section.  */
     101  asection* sec;
     102  char* sec_info_ptr;
     103
     104  /* Pointer to the symbol table.  */
     105  asymbol** syms;
     106
    99107  /* Pointer to the .debug_abbrev section loaded into memory.  */
    100108  char* dwarf_abbrev_buffer;
     
    108116  /* Length of the loaded .debug_line section.  */
    109117  unsigned long dwarf_line_size;
     118
     119  /* Pointer to the .debug_str section loaded into memory.  */
     120  char* dwarf_str_buffer;
     121
     122  /* Length of the loaded .debug_str section.  */
     123  unsigned long dwarf_str_size;
    110124};
    111125
     
    144158  char* comp_dir;
    145159
    146   /* True if there is a line number table associated with this comp. unit.  */
     160  /* TRUE if there is a line number table associated with this comp. unit.  */
    147161  int stmtlist;
    148162
     
    162176  struct funcinfo* function_table;
    163177
     178  /* Pointer to dwarf2_debug structure.  */
     179  struct dwarf2_debug *stash;
     180
    164181  /* Address size for this unit - from unit header.  */
    165182  unsigned char addr_size;
     183
     184  /* Offset size for this unit - from unit header.  */
     185  unsigned char offset_size;
    166186};
     187
     188/* This data structure holds the information of an abbrev.  */
     189struct abbrev_info
     190{
     191  unsigned int number;          /* Number identifying abbrev.  */
     192  enum dwarf_tag tag;           /* DWARF tag.  */
     193  int has_children;             /* Boolean.  */
     194  unsigned int num_attrs;       /* Number of attributes.  */
     195  struct attr_abbrev *attrs;    /* An array of attribute descriptions.  */
     196  struct abbrev_info *next;     /* Next in chain.  */
     197};
     198
     199struct attr_abbrev
     200{
     201  enum dwarf_attribute name;
     202  enum dwarf_form form;
     203};
     204
     205#ifndef ABBREV_HASH_SIZE
     206#define ABBREV_HASH_SIZE 121
     207#endif
     208#ifndef ATTR_ALLOC_CHUNK
     209#define ATTR_ALLOC_CHUNK 4
     210#endif
     211
     212static unsigned int read_1_byte PARAMS ((bfd *, char *));
     213static int read_1_signed_byte PARAMS ((bfd *, char *));
     214static unsigned int read_2_bytes PARAMS ((bfd *, char *));
     215static unsigned int read_4_bytes PARAMS ((bfd *, char *));
     216static bfd_vma read_8_bytes PARAMS ((bfd *, char *));
     217static char *read_n_bytes PARAMS ((bfd *, char *, unsigned int));
     218static char *read_string PARAMS ((bfd *, char *, unsigned int *));
     219static char *read_indirect_string PARAMS ((struct comp_unit *, char *, unsigned int *));
     220static unsigned int read_unsigned_leb128
     221  PARAMS ((bfd *, char *, unsigned int *));
     222static int read_signed_leb128
     223  PARAMS ((bfd *, char *, unsigned int *));
     224static bfd_vma read_address PARAMS ((struct comp_unit *, char *));
     225static struct abbrev_info *lookup_abbrev
     226  PARAMS ((unsigned int, struct abbrev_info **));
     227static struct abbrev_info **read_abbrevs
     228  PARAMS ((bfd *, bfd_vma, struct dwarf2_debug *));
     229static char *read_attribute
     230  PARAMS ((struct attribute *, struct attr_abbrev *,
     231           struct comp_unit *, char *));
     232static char *read_attribute_value
     233  PARAMS ((struct attribute *, unsigned,
     234           struct comp_unit *, char *));
     235static void add_line_info
     236  PARAMS ((struct line_info_table *, bfd_vma, char *,
     237           unsigned int, unsigned int, int));
     238static char *concat_filename PARAMS ((struct line_info_table *, unsigned int));
     239static void arange_add PARAMS ((struct comp_unit *, bfd_vma, bfd_vma));
     240static struct line_info_table *decode_line_info
     241  PARAMS ((struct comp_unit *, struct dwarf2_debug *));
     242static bfd_boolean lookup_address_in_line_info_table
     243  PARAMS ((struct line_info_table *, bfd_vma, struct funcinfo *,
     244           const char **, unsigned int *));
     245static bfd_boolean lookup_address_in_function_table
     246  PARAMS ((struct funcinfo *, bfd_vma, struct funcinfo **, const char **));
     247static bfd_boolean scan_unit_for_functions PARAMS ((struct comp_unit *));
     248static struct comp_unit *parse_comp_unit
     249  PARAMS ((bfd *, struct dwarf2_debug *, bfd_vma, unsigned int));
     250static bfd_boolean comp_unit_contains_address
     251  PARAMS ((struct comp_unit *, bfd_vma));
     252static bfd_boolean comp_unit_find_nearest_line
     253  PARAMS ((struct comp_unit *, bfd_vma, const char **, const char **,
     254           unsigned int *, struct dwarf2_debug *));
     255static asection *find_debug_info PARAMS ((bfd *, asection *));
    167256
    168257/* VERBATIM
     
    228317#endif
    229318
    230 static unsigned int
     319static bfd_vma
    231320read_8_bytes (abfd, buf)
    232321     bfd *abfd;
     
    254343     unsigned int *bytes_read_ptr;
    255344{
    256   /* If the size of a host char is 8 bits, we can return a pointer
    257      to the string, otherwise we have to copy the string to a buffer
    258      allocated on the temporary obstack.  */
     345  /* Return a pointer to the embedded string.  */
    259346  if (*buf == '\0')
    260347    {
     
    264351
    265352  *bytes_read_ptr = strlen (buf) + 1;
     353  return buf;
     354}
     355
     356static char *
     357read_indirect_string (unit, buf, bytes_read_ptr)
     358     struct comp_unit* unit;
     359     char *buf;
     360     unsigned int *bytes_read_ptr;
     361{
     362  bfd_vma offset;
     363  struct dwarf2_debug *stash = unit->stash;
     364
     365  if (unit->offset_size == 4)
     366    offset = read_4_bytes (unit->abfd, buf);
     367  else
     368    offset = read_8_bytes (unit->abfd, buf);
     369  *bytes_read_ptr = unit->offset_size;
     370
     371  if (! stash->dwarf_str_buffer)
     372    {
     373      asection *msec;
     374      bfd *abfd = unit->abfd;
     375
     376      msec = bfd_get_section_by_name (abfd, ".debug_str");
     377      if (! msec)
     378        {
     379          (*_bfd_error_handler)
     380            (_("Dwarf Error: Can't find .debug_str section."));
     381          bfd_set_error (bfd_error_bad_value);
     382          return NULL;
     383        }
     384
     385      stash->dwarf_str_size = msec->_raw_size;
     386      stash->dwarf_str_buffer = (char*) bfd_alloc (abfd, msec->_raw_size);
     387      if (! stash->dwarf_abbrev_buffer)
     388        return NULL;
     389
     390      if (! bfd_get_section_contents (abfd, msec, stash->dwarf_str_buffer,
     391                                      (bfd_vma) 0, msec->_raw_size))
     392        return NULL;
     393    }
     394
     395  if (offset >= stash->dwarf_str_size)
     396    {
     397      (*_bfd_error_handler) (_("Dwarf Error: DW_FORM_strp offset (%lu) greater than or equal to .debug_str size (%lu)."),
     398                             (unsigned long) offset, stash->dwarf_str_size);
     399      bfd_set_error (bfd_error_bad_value);
     400      return NULL;
     401    }
     402
     403  buf = stash->dwarf_str_buffer + offset;
     404  if (*buf == '\0')
     405    return NULL;
    266406  return buf;
    267407}
     
    350490}
    351491
    352 /* This data structure holds the information of an abbrev.  */
    353 struct abbrev_info
    354 {
    355   unsigned int number;          /* Number identifying abbrev.  */
    356   enum dwarf_tag tag;           /* DWARF tag.  */
    357   int has_children;             /* Boolean.  */
    358   unsigned int num_attrs;       /* Number of attributes.  */
    359   struct attr_abbrev *attrs;    /* An array of attribute descriptions.  */
    360   struct abbrev_info *next;     /* Next in chain.  */
    361 };
    362 
    363 struct attr_abbrev
    364 {
    365   enum dwarf_attribute name;
    366   enum dwarf_form form;
    367 };
    368 
    369 #ifndef ABBREV_HASH_SIZE
    370 #define ABBREV_HASH_SIZE 121
    371 #endif
    372 #ifndef ATTR_ALLOC_CHUNK
    373 #define ATTR_ALLOC_CHUNK 4
    374 #endif
    375 
    376492/* Lookup an abbrev_info structure in the abbrev hash table.  */
    377493
     
    406522read_abbrevs (abfd, offset, stash)
    407523     bfd * abfd;
    408      unsigned int offset;
     524     bfd_vma offset;
    409525     struct dwarf2_debug *stash;
    410526{
     
    414530  unsigned int abbrev_number, bytes_read, abbrev_name;
    415531  unsigned int abbrev_form, hash_number;
     532  bfd_size_type amt;
    416533
    417534  if (! stash->dwarf_abbrev_buffer)
     
    428545
    429546      stash->dwarf_abbrev_size = msec->_raw_size;
    430       stash->dwarf_abbrev_buffer = (char*) bfd_alloc (abfd, stash->dwarf_abbrev_size);
     547      stash->dwarf_abbrev_buffer
     548        = bfd_simple_get_relocated_section_contents (abfd, msec, NULL,
     549                                                     stash->syms);
    431550      if (! stash->dwarf_abbrev_buffer)
    432551          return 0;
    433 
    434       if (! bfd_get_section_contents (abfd, msec,
    435                                       stash->dwarf_abbrev_buffer, 0,
    436                                       stash->dwarf_abbrev_size))
    437         return 0;
    438552    }
    439553
    440554  if (offset >= stash->dwarf_abbrev_size)
    441555    {
    442       (*_bfd_error_handler) (_("Dwarf Error: Abbrev offset (%u) greater than or equal to abbrev size (%u)."),
    443                              offset, stash->dwarf_abbrev_size );
     556      (*_bfd_error_handler) (_("Dwarf Error: Abbrev offset (%lu) greater than or equal to .debug_abbrev size (%lu)."),
     557                             (unsigned long) offset, stash->dwarf_abbrev_size);
    444558      bfd_set_error (bfd_error_bad_value);
    445559      return 0;
    446560    }
    447561
    448   abbrevs = (struct abbrev_info**) bfd_zalloc (abfd, sizeof (struct abbrev_info*) * ABBREV_HASH_SIZE);
     562  amt = sizeof (struct abbrev_info*) * ABBREV_HASH_SIZE;
     563  abbrevs = (struct abbrev_info**) bfd_zalloc (abfd, amt);
    449564
    450565  abbrev_ptr = stash->dwarf_abbrev_buffer + offset;
     
    455570  while (abbrev_number)
    456571    {
    457       cur_abbrev = (struct abbrev_info*)bfd_zalloc (abfd, sizeof (struct abbrev_info));
     572      amt = sizeof (struct abbrev_info);
     573      cur_abbrev = (struct abbrev_info *) bfd_zalloc (abfd, amt);
    458574
    459575      /* Read in abbrev header.  */
    460576      cur_abbrev->number = abbrev_number;
    461       cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
     577      cur_abbrev->tag = (enum dwarf_tag)
     578        read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
    462579      abbrev_ptr += bytes_read;
    463580      cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
     
    474591          if ((cur_abbrev->num_attrs % ATTR_ALLOC_CHUNK) == 0)
    475592            {
    476               cur_abbrev->attrs = (struct attr_abbrev *)
    477                 bfd_realloc (cur_abbrev->attrs,
    478                              (cur_abbrev->num_attrs + ATTR_ALLOC_CHUNK)
    479                              * sizeof (struct attr_abbrev));
     593              amt = cur_abbrev->num_attrs + ATTR_ALLOC_CHUNK;
     594              amt *= sizeof (struct attr_abbrev);
     595              cur_abbrev->attrs = ((struct attr_abbrev *)
     596                                   bfd_realloc (cur_abbrev->attrs, amt));
    480597              if (! cur_abbrev->attrs)
    481598                return 0;
    482599            }
    483600
    484           cur_abbrev->attrs[cur_abbrev->num_attrs].name = abbrev_name;
    485           cur_abbrev->attrs[cur_abbrev->num_attrs++].form = abbrev_form;
     601          cur_abbrev->attrs[cur_abbrev->num_attrs].name
     602            = (enum dwarf_attribute) abbrev_name;
     603          cur_abbrev->attrs[cur_abbrev->num_attrs++].form
     604            = (enum dwarf_form) abbrev_form;
    486605          abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
    487606          abbrev_ptr += bytes_read;
     
    495614
    496615      /* Get next abbreviation.
    497         Under Irix6 the abbreviations for a compilation unit are not
     616        Under Irix6 the abbreviations for a compilation unit are not
    498617         always properly terminated with an abbrev number of 0.
    499618         Exit loop if we encounter an abbreviation which we have
     
    513632}
    514633
    515 /* Read an attribute described by an abbreviated attribute.  */
     634/* Read an attribute value described by an attribute form.  */
    516635
    517636static char *
    518 read_attribute (attr, abbrev, unit, info_ptr)
     637read_attribute_value (attr, form, unit, info_ptr)
    519638     struct attribute   *attr;
    520      struct attr_abbrev *abbrev;
     639     unsigned form;
    521640     struct comp_unit   *unit;
    522641     char               *info_ptr;
     
    525644  unsigned int bytes_read;
    526645  struct dwarf_block *blk;
    527 
    528   attr->name = abbrev->name;
    529   attr->form = abbrev->form;
    530 
    531   switch (abbrev->form)
     646  bfd_size_type amt;
     647
     648  attr->form = (enum dwarf_form) form;
     649
     650  switch (form)
    532651    {
    533652    case DW_FORM_addr:
     653      /* FIXME: DWARF3 draft says DW_FORM_ref_addr is offset_size.  */
    534654    case DW_FORM_ref_addr:
    535655      DW_ADDR (attr) = read_address (unit, info_ptr);
     
    537657      break;
    538658    case DW_FORM_block2:
    539       blk = (struct dwarf_block *) bfd_alloc (abfd, sizeof (struct dwarf_block));
     659      amt = sizeof (struct dwarf_block);
     660      blk = (struct dwarf_block *) bfd_alloc (abfd, amt);
    540661      blk->size = read_2_bytes (abfd, info_ptr);
    541662      info_ptr += 2;
     
    545666      break;
    546667    case DW_FORM_block4:
    547       blk = (struct dwarf_block *) bfd_alloc (abfd, sizeof (struct dwarf_block));
     668      amt = sizeof (struct dwarf_block);
     669      blk = (struct dwarf_block *) bfd_alloc (abfd, amt);
    548670      blk->size = read_4_bytes (abfd, info_ptr);
    549671      info_ptr += 4;
     
    568690      info_ptr += bytes_read;
    569691      break;
     692    case DW_FORM_strp:
     693      DW_STRING (attr) = read_indirect_string (unit, info_ptr, &bytes_read);
     694      info_ptr += bytes_read;
     695      break;
    570696    case DW_FORM_block:
    571       blk = (struct dwarf_block *) bfd_alloc (abfd, sizeof (struct dwarf_block));
     697      amt = sizeof (struct dwarf_block);
     698      blk = (struct dwarf_block *) bfd_alloc (abfd, amt);
    572699      blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
    573700      info_ptr += bytes_read;
     
    577704      break;
    578705    case DW_FORM_block1:
    579       blk = (struct dwarf_block *) bfd_alloc (abfd, sizeof (struct dwarf_block));
     706      amt = sizeof (struct dwarf_block);
     707      blk = (struct dwarf_block *) bfd_alloc (abfd, amt);
    580708      blk->size = read_1_byte (abfd, info_ptr);
    581709      info_ptr += 1;
     
    620748      info_ptr += bytes_read;
    621749      break;
    622     case DW_FORM_strp:
    623750    case DW_FORM_indirect:
     751      form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
     752      info_ptr += bytes_read;
     753      info_ptr = read_attribute_value (attr, form, unit, info_ptr);
     754      break;
    624755    default:
    625       (*_bfd_error_handler) (_("Dwarf Error: Invalid or unhandled FORM value: %d."),
    626                              abbrev->form);
     756      (*_bfd_error_handler) (_("Dwarf Error: Invalid or unhandled FORM value: %u."),
     757                             form);
    627758      bfd_set_error (bfd_error_bad_value);
    628759    }
     760  return info_ptr;
     761}
     762
     763/* Read an attribute described by an abbreviated attribute.  */
     764
     765static char *
     766read_attribute (attr, abbrev, unit, info_ptr)
     767     struct attribute   *attr;
     768     struct attr_abbrev *abbrev;
     769     struct comp_unit   *unit;
     770     char               *info_ptr;
     771{
     772  attr->name = abbrev->name;
     773  info_ptr = read_attribute_value (attr, abbrev->form, unit, info_ptr);
    629774  return info_ptr;
    630775}
     
    661806  char** dirs;
    662807  struct fileinfo* files;
    663   struct line_info* last_line;
     808  struct line_info* last_line;  /* largest VMA */
     809  struct line_info* lcl_head;   /* local head; used in 'add_line_info' */
    664810};
     811
     812struct funcinfo
     813{
     814  struct funcinfo *prev_func;
     815  char* name;
     816  bfd_vma low;
     817  bfd_vma high;
     818};
     819
     820/* Adds a new entry to the line_info list in the line_info_table, ensuring
     821   that the list is sorted.  Note that the line_info list is sorted from
     822   highest to lowest VMA (with possible duplicates); that is,
     823   line_info->prev_line always accesses an equal or smaller VMA.  */
    665824
    666825static void
     
    673832     int end_sequence;
    674833{
    675   struct line_info* info = (struct line_info*)
    676     bfd_alloc (table->abfd, sizeof (struct line_info));
    677 
    678   info->prev_line = table->last_line;
    679   table->last_line = info;
    680 
     834  bfd_size_type amt = sizeof (struct line_info);
     835  struct line_info* info = (struct line_info*) bfd_alloc (table->abfd, amt);
     836
     837  /* Find the correct location for 'info'.  Normally we will receive
     838     new line_info data 1) in order and 2) with increasing VMAs.
     839     However some compilers break the rules (cf. decode_line_info) and
     840     so we include some heuristics for quickly finding the correct
     841     location for 'info'. In particular, these heuristics optimize for
     842     the common case in which the VMA sequence that we receive is a
     843     list of locally sorted VMAs such as
     844       p...z a...j  (where a < j < p < z)
     845
     846     Note: table->lcl_head is used to head an *actual* or *possible*
     847     sequence within the list (such as a...j) that is not directly
     848     headed by table->last_line
     849
     850     Note: we may receive duplicate entries from 'decode_line_info'.  */
     851
     852  while (1)
     853    if (!table->last_line
     854        || address >= table->last_line->address)
     855      {
     856        /* Normal case: add 'info' to the beginning of the list */
     857        info->prev_line = table->last_line;
     858        table->last_line = info;
     859
     860        /* lcl_head: initialize to head a *possible* sequence at the end.  */
     861        if (!table->lcl_head)
     862          table->lcl_head = info;
     863        break;
     864      }
     865    else if (!table->lcl_head->prev_line
     866             && table->lcl_head->address > address)
     867      {
     868        /* Abnormal but easy: lcl_head is 1) at the *end* of the line
     869           list and 2) the head of 'info'.  */
     870        info->prev_line = NULL;
     871        table->lcl_head->prev_line = info;
     872        break;
     873      }
     874    else if (table->lcl_head->prev_line
     875             && table->lcl_head->address > address
     876             && address >= table->lcl_head->prev_line->address)
     877      {
     878        /* Abnormal but easy: lcl_head is 1) in the *middle* of the line
     879           list and 2) the head of 'info'.  */
     880        info->prev_line = table->lcl_head->prev_line;
     881        table->lcl_head->prev_line = info;
     882        break;
     883      }
     884    else
     885      {
     886        /* Abnormal and hard: Neither 'last_line' nor 'lcl_head' are valid
     887           heads for 'info'.  Reset 'lcl_head' and repeat.  */
     888        struct line_info* li2 = table->last_line; /* always non-NULL */
     889        struct line_info* li1 = li2->prev_line;
     890
     891        while (li1)
     892          {
     893            if (li2->address > address && address >= li1->address)
     894              break;
     895
     896            li2 = li1; /* always non-NULL */
     897            li1 = li1->prev_line;
     898          }
     899        table->lcl_head = li2;
     900      }
     901
     902  /* Set member data of 'info'.  */
    681903  info->address = address;
    682   info->filename = filename;
    683904  info->line = line;
    684905  info->column = column;
    685906  info->end_sequence = end_sequence;
    686 }
     907
     908  amt = strlen (filename);
     909  if (amt)
     910    {
     911      info->filename = bfd_alloc (table->abfd, amt + 1);
     912      if (info->filename)
     913        strcpy (info->filename, filename);
     914    }
     915  else
     916    info->filename = NULL;
     917}
     918
     919/* Extract a fully qualified filename from a line info table.
     920   The returned string has been malloc'ed and it is the caller's
     921   responsibility to free it.  */
    687922
    688923static char *
     
    697932      (*_bfd_error_handler)
    698933        (_("Dwarf Error: mangled line number section (bad file number)."));
    699       return "<unknown>";
     934      return strdup ("<unknown>");
    700935    }
    701936
    702937  filename = table->files[file - 1].name;
    703   if (IS_ABSOLUTE_PATH(filename))
    704     return filename;
    705 
    706   else
     938
     939  if (! IS_ABSOLUTE_PATH (filename))
    707940    {
    708941      char* dirname = (table->files[file - 1].dir
    709942                       ? table->dirs[table->files[file - 1].dir - 1]
    710943                       : table->comp_dir);
    711       return (char*) concat (dirname, "/", filename, NULL);
    712     }
     944
     945      /* Not all tools set DW_AT_comp_dir, so dirname may be unknown.
     946         The best we can do is return the filename part.  */
     947      if (dirname != NULL)
     948        {
     949          unsigned int len = strlen (dirname) + strlen (filename) + 2;
     950          char * name;
     951
     952          name = bfd_malloc (len);
     953          if (name)
     954            sprintf (name, "%s/%s", dirname, filename);
     955          return name;
     956        }
     957    }
     958
     959  return strdup (filename);
    713960}
    714961
     
    750997
    751998  /* Need to allocate a new arange and insert it into the arange list.  */
    752   arange = bfd_zalloc (unit->abfd, sizeof (*arange));
     999  arange = (struct arange *)
     1000    bfd_zalloc (unit->abfd, (bfd_size_type) sizeof (*arange));
    7531001  arange->low = low_pc;
    7541002  arange->high = high_pc;
     
    7701018  char *line_end;
    7711019  struct line_head lh;
    772   unsigned int i, bytes_read;
     1020  unsigned int i, bytes_read, offset_size;
    7731021  char *cur_file, *cur_dir;
    7741022  unsigned char op_code, extended_op, adj_opcode;
     1023  bfd_size_type amt;
    7751024
    7761025  if (! stash->dwarf_line_buffer)
     
    7871036
    7881037      stash->dwarf_line_size = msec->_raw_size;
    789       stash->dwarf_line_buffer = (char *) bfd_alloc (abfd, stash->dwarf_line_size);
     1038      stash->dwarf_line_buffer
     1039        = bfd_simple_get_relocated_section_contents (abfd, msec, NULL,
     1040                                                     stash->syms);
    7901041      if (! stash->dwarf_line_buffer)
    7911042        return 0;
    792 
    793       if (! bfd_get_section_contents (abfd, msec,
    794                                       stash->dwarf_line_buffer, 0,
    795                                       stash->dwarf_line_size))
    796         return 0;
    797 
    798       /* FIXME: We ought to apply the relocs against this section before
    799          we process it...  */
    800     }
    801 
    802   /* Since we are using un-relocated data, it is possible to get a bad value
    803      for the line_offset.  Validate it here so that we won't get a segfault
    804      below.  */
     1043    }
     1044
     1045  /* It is possible to get a bad value for the line_offset.  Validate
     1046     it here so that we won't get a segfault below.  */
    8051047  if (unit->line_offset >= stash->dwarf_line_size)
    8061048    {
    807       (*_bfd_error_handler) (_("Dwarf Error: Line offset (%u) greater than or equal to line size (%u)."),
     1049      (*_bfd_error_handler) (_("Dwarf Error: Line offset (%lu) greater than or equal to .debug_line size (%lu)."),
    8081050                             unit->line_offset, stash->dwarf_line_size);
    8091051      bfd_set_error (bfd_error_bad_value);
     
    8111053    }
    8121054
    813   table = (struct line_info_table*) bfd_alloc (abfd,
    814                                                sizeof (struct line_info_table));
     1055  amt = sizeof (struct line_info_table);
     1056  table = (struct line_info_table*) bfd_alloc (abfd, amt);
    8151057  table->abfd = abfd;
    8161058  table->comp_dir = unit->comp_dir;
     
    8241066  table->files = NULL;
    8251067  table->last_line = NULL;
     1068  table->lcl_head = NULL;
    8261069
    8271070  line_ptr = stash->dwarf_line_buffer + unit->line_offset;
     
    8301073  lh.total_length = read_4_bytes (abfd, line_ptr);
    8311074  line_ptr += 4;
     1075  offset_size = 4;
     1076  if (lh.total_length == 0xffffffff)
     1077    {
     1078      lh.total_length = read_8_bytes (abfd, line_ptr);
     1079      line_ptr += 8;
     1080      offset_size = 8;
     1081    }
     1082  else if (lh.total_length == 0 && unit->addr_size == 8)
     1083    {
     1084      /* Handle (non-standard) 64-bit DWARF2 formats.  */
     1085      lh.total_length = read_4_bytes (abfd, line_ptr);
     1086      line_ptr += 4;
     1087      offset_size = 8;
     1088    }
    8321089  line_end = line_ptr + lh.total_length;
    8331090  lh.version = read_2_bytes (abfd, line_ptr);
    8341091  line_ptr += 2;
    835   lh.prologue_length = read_4_bytes (abfd, line_ptr);
    836   line_ptr += 4;
     1092  if (offset_size == 4)
     1093    lh.prologue_length = read_4_bytes (abfd, line_ptr);
     1094  else
     1095    lh.prologue_length = read_8_bytes (abfd, line_ptr);
     1096  line_ptr += offset_size;
    8371097  lh.minimum_instruction_length = read_1_byte (abfd, line_ptr);
    8381098  line_ptr += 1;
     
    8451105  lh.opcode_base = read_1_byte (abfd, line_ptr);
    8461106  line_ptr += 1;
    847   lh.standard_opcode_lengths = (unsigned char *)
    848     bfd_alloc (abfd, lh.opcode_base * sizeof (unsigned char));
     1107  amt = lh.opcode_base * sizeof (unsigned char);
     1108  lh.standard_opcode_lengths = (unsigned char *) bfd_alloc (abfd, amt);
    8491109
    8501110  lh.standard_opcode_lengths[0] = 1;
     
    8631123      if ((table->num_dirs % DIR_ALLOC_CHUNK) == 0)
    8641124        {
    865           table->dirs = (char **)
    866             bfd_realloc (table->dirs,
    867                          (table->num_dirs + DIR_ALLOC_CHUNK) * sizeof (char *));
     1125          amt = table->num_dirs + DIR_ALLOC_CHUNK;
     1126          amt *= sizeof (char *);
     1127          table->dirs = (char **) bfd_realloc (table->dirs, amt);
    8681128          if (! table->dirs)
    8691129            return 0;
     
    8821142      if ((table->num_files % FILE_ALLOC_CHUNK) == 0)
    8831143        {
    884           table->files = (struct fileinfo *)
    885             bfd_realloc (table->files,
    886                          (table->num_files + FILE_ALLOC_CHUNK)
    887                          * sizeof (struct fileinfo));
     1144          amt = table->num_files + FILE_ALLOC_CHUNK;
     1145          amt *= sizeof (struct fileinfo);
     1146          table->files = (struct fileinfo *) bfd_realloc (table->files, amt);
    8881147          if (! table->files)
    8891148            return 0;
     
    9101169      /* State machine registers.  */
    9111170      bfd_vma address = 0;
    912       char* filename = concat_filename (table, 1);
     1171      char * filename = concat_filename (table, 1);
    9131172      unsigned int line = 1;
    9141173      unsigned int column = 0;
    9151174      int is_stmt = lh.default_is_stmt;
    9161175      int basic_block = 0;
    917       int end_sequence = 0, need_low_pc = 1;
    918       bfd_vma low_pc = 0;
     1176      int end_sequence = 0;
     1177      /* eraxxon@alumni.rice.edu: Against the DWARF2 specs, some
     1178         compilers generate address sequences that are wildly out of
     1179         order using DW_LNE_set_address (e.g. Intel C++ 6.0 compiler
     1180         for ia64-Linux).  Thus, to determine the low and high
     1181         address, we must compare on every DW_LNS_copy, etc.  */
     1182      bfd_vma low_pc  = 0;
     1183      bfd_vma high_pc = 0;
    9191184
    9201185      /* Decode the table.  */
     
    9241189          line_ptr += 1;
    9251190
    926           switch (op_code)
     1191          if (op_code >= lh.opcode_base)
     1192            {
     1193              /* Special operand.  */
     1194              adj_opcode = op_code - lh.opcode_base;
     1195              address += (adj_opcode / lh.line_range)
     1196                * lh.minimum_instruction_length;
     1197              line += lh.line_base + (adj_opcode % lh.line_range);
     1198              /* Append row to matrix using current values.  */
     1199              add_line_info (table, address, filename, line, column, 0);
     1200              basic_block = 1;
     1201              if (low_pc == 0 || address < low_pc)
     1202                low_pc = address;
     1203              if (address > high_pc)
     1204                high_pc = address;
     1205            }
     1206          else switch (op_code)
    9271207            {
    9281208            case DW_LNS_extended_op:
    929               line_ptr += 1;    /* Ignore length.  */
     1209              /* Ignore length.  */
     1210              line_ptr += 1;
    9301211              extended_op = read_1_byte (abfd, line_ptr);
    9311212              line_ptr += 1;
     1213
    9321214              switch (extended_op)
    9331215                {
     
    9361218                  add_line_info (table, address, filename, line, column,
    9371219                                 end_sequence);
    938                   if (need_low_pc)
    939                     {
    940                       need_low_pc = 0;
    941                       low_pc = address;
    942                     }
    943                   arange_add (unit, low_pc, address);
     1220                  if (low_pc == 0 || address < low_pc)
     1221                    low_pc = address;
     1222                  if (address > high_pc)
     1223                    high_pc = address;
     1224                  arange_add (unit, low_pc, high_pc);
    9441225                  break;
    9451226                case DW_LNE_set_address:
     
    9521233                  if ((table->num_files % FILE_ALLOC_CHUNK) == 0)
    9531234                    {
    954                       table->files = (struct fileinfo *)
    955                         bfd_realloc (table->files,
    956                                      (table->num_files + FILE_ALLOC_CHUNK)
    957                                      * sizeof (struct fileinfo));
     1235                      amt = table->num_files + FILE_ALLOC_CHUNK;
     1236                      amt *= sizeof (struct fileinfo);
     1237                      table->files =
     1238                        (struct fileinfo *) bfd_realloc (table->files, amt);
    9581239                      if (! table->files)
    9591240                        return 0;
     
    9801261              add_line_info (table, address, filename, line, column, 0);
    9811262              basic_block = 0;
    982               if (need_low_pc)
    983                 {
    984                   need_low_pc = 0;
    985                   low_pc = address;
    986                 }
     1263              if (low_pc == 0 || address < low_pc)
     1264                low_pc = address;
     1265              if (address > high_pc)
     1266                high_pc = address;
    9871267              break;
    9881268            case DW_LNS_advance_pc:
     
    9991279                unsigned int file;
    10001280
    1001                 /* The file and directory tables are 0 based, the references
    1002                    are 1 based.  */
     1281                /* The file and directory tables are 0
     1282                   based, the references are 1 based.  */
    10031283                file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
    10041284                line_ptr += bytes_read;
     1285                if (filename)
     1286                  free (filename);
    10051287                filename = concat_filename (table, file);
    10061288                break;
     
    10241306              line_ptr += 2;
    10251307              break;
    1026             default:            /* Special operand.  */
    1027               adj_opcode = op_code - lh.opcode_base;
    1028               address += (adj_opcode / lh.line_range)
    1029                 * lh.minimum_instruction_length;
    1030               line += lh.line_base + (adj_opcode % lh.line_range);
    1031               /* Append row to matrix using current values.  */
    1032               add_line_info (table, address, filename, line, column, 0);
    1033               basic_block = 1;
    1034               if (need_low_pc)
    1035                 {
    1036                   need_low_pc = 0;
    1037                   low_pc = address;
    1038                 }
     1308            default:
     1309              {
     1310                int i;
     1311
     1312                /* Unknown standard opcode, ignore it.  */
     1313                for (i = 0; i < lh.standard_opcode_lengths[op_code]; i++)
     1314                  {
     1315                    (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
     1316                    line_ptr += bytes_read;
     1317                  }
     1318              }
    10391319            }
    10401320        }
     1321
     1322      if (filename)
     1323        free (filename);
    10411324    }
    10421325
     
    10441327}
    10451328
    1046 /* If ADDR is within TABLE set the output parameters and return true,
    1047    otherwise return false.  The output parameters, FILENAME_PTR and
     1329/* If ADDR is within TABLE set the output parameters and return TRUE,
     1330   otherwise return FALSE.  The output parameters, FILENAME_PTR and
    10481331   LINENUMBER_PTR, are pointers to the objects to be filled in.  */
    10491332
    1050 static boolean
    1051 lookup_address_in_line_info_table (table,
    1052                                    addr,
    1053                                    filename_ptr,
     1333static bfd_boolean
     1334lookup_address_in_line_info_table (table, addr, function, filename_ptr,
    10541335                                   linenumber_ptr)
    10551336     struct line_info_table* table;
    10561337     bfd_vma addr;
     1338     struct funcinfo *function;
    10571339     const char **filename_ptr;
    10581340     unsigned int *linenumber_ptr;
    10591341{
     1342  /* Note: table->last_line should be a descendingly sorted list. */
    10601343  struct line_info* next_line = table->last_line;
    1061   struct line_info* each_line;
     1344  struct line_info* each_line = NULL;
     1345  *filename_ptr = NULL;
    10621346
    10631347  if (!next_line)
    1064     return false;
     1348    return FALSE;
    10651349
    10661350  each_line = next_line->prev_line;
    10671351
     1352  /* Check for large addresses */
     1353  if (addr > next_line->address)
     1354    each_line = NULL; /* ensure we skip over the normal case */
     1355
     1356  /* Normal case: search the list; save  */
    10681357  while (each_line && next_line)
    10691358    {
    1070       if (!each_line->end_sequence
    1071           && addr >= each_line->address && addr < next_line->address)
    1072         {
    1073           *filename_ptr = each_line->filename;
    1074           *linenumber_ptr = each_line->line;
    1075           return true;
    1076         }
     1359      /* If we have an address match, save this info.  This allows us
     1360         to return as good as results as possible for strange debugging
     1361         info.  */
     1362      bfd_boolean addr_match = FALSE;
     1363      if (each_line->address <= addr && addr <= next_line->address)
     1364        {
     1365          addr_match = TRUE;
     1366
     1367          /* If this line appears to span functions, and addr is in the
     1368             later function, return the first line of that function instead
     1369             of the last line of the earlier one.  This check is for GCC
     1370             2.95, which emits the first line number for a function late.  */
     1371          if (function != NULL
     1372              && each_line->address < function->low
     1373              && next_line->address > function->low)
     1374            {
     1375              *filename_ptr = next_line->filename;
     1376              *linenumber_ptr = next_line->line;
     1377            }
     1378          else
     1379            {
     1380              *filename_ptr = each_line->filename;
     1381              *linenumber_ptr = each_line->line;
     1382            }
     1383        }
     1384
     1385      if (addr_match && !each_line->end_sequence)
     1386        return TRUE; /* we have definitely found what we want */
     1387
    10771388      next_line = each_line;
    10781389      each_line = each_line->prev_line;
    10791390    }
    10801391
    1081   return false;
     1392  /* At this point each_line is NULL but next_line is not.  If we found
     1393     a candidate end-of-sequence point in the loop above, we can return
     1394     that (compatibility with a bug in the Intel compiler); otherwise,
     1395     assuming that we found the containing function for this address in
     1396     this compilation unit, return the first line we have a number for
     1397     (compatibility with GCC 2.95).  */
     1398  if (*filename_ptr == NULL && function != NULL)
     1399    {
     1400      *filename_ptr = next_line->filename;
     1401      *linenumber_ptr = next_line->line;
     1402      return TRUE;
     1403    }
     1404
     1405  return FALSE;
    10821406}
    10831407
    10841408/* Function table functions.  */
    10851409
    1086 struct funcinfo
    1087 {
    1088   struct funcinfo *prev_func;
    1089   char* name;
    1090   bfd_vma low;
    1091   bfd_vma high;
    1092 };
    1093 
    1094 /* If ADDR is within TABLE, set FUNCTIONNAME_PTR, and return true.  */
    1095 
    1096 static boolean
    1097 lookup_address_in_function_table (table,
    1098                                   addr,
     1410/* If ADDR is within TABLE, set FUNCTIONNAME_PTR, and return TRUE.  */
     1411
     1412static bfd_boolean
     1413lookup_address_in_function_table (table, addr, function_ptr,
    10991414                                  functionname_ptr)
    11001415     struct funcinfo* table;
    11011416     bfd_vma addr;
     1417     struct funcinfo** function_ptr;
    11021418     const char **functionname_ptr;
    11031419{
     
    11111427        {
    11121428          *functionname_ptr = each_func->name;
    1113           return true;
    1114         }
    1115     }
    1116 
    1117   return false;
     1429          *function_ptr = each_func;
     1430          return TRUE;
     1431        }
     1432    }
     1433
     1434  return FALSE;
    11181435}
    11191436
     
    11231440   to the function table.  */
    11241441
    1125 static boolean
     1442static bfd_boolean
    11261443scan_unit_for_functions (unit)
    11271444     struct comp_unit *unit;
     
    11511468      if (! abbrev)
    11521469        {
    1153           (*_bfd_error_handler) (_("Dwarf Error: Could not find abbrev number %d."),
     1470          (*_bfd_error_handler) (_("Dwarf Error: Could not find abbrev number %u."),
    11541471                             abbrev_number);
    11551472          bfd_set_error (bfd_error_bad_value);
    1156           return false;
     1473          return FALSE;
    11571474        }
    11581475
    11591476      if (abbrev->tag == DW_TAG_subprogram)
    11601477        {
    1161           func = (struct funcinfo*) bfd_zalloc (abfd, sizeof (struct funcinfo));
     1478          bfd_size_type amt = sizeof (struct funcinfo);
     1479          func = (struct funcinfo *) bfd_zalloc (abfd, amt);
    11621480          func->prev_func = unit->function_table;
    11631481          unit->function_table = func;
     
    12171535    }
    12181536
    1219   return true;
     1537  return TRUE;
    12201538}
    12211539
     
    12241542   does not include the length field that preceeds each compilation
    12251543   unit header.  END_PTR points one past the end of this comp unit.
    1226    If ABBREV_LENGTH is 0, then the length of the abbreviation offset
    1227    is assumed to be four bytes.  Otherwise, it it is the size given.
     1544   OFFSET_SIZE is the size of DWARF2 offsets (either 4 or 8 bytes).
    12281545
    12291546   This routine does not read the whole compilation unit; only enough
     
    12311548
    12321549static struct comp_unit *
    1233 parse_comp_unit (abfd, stash, unit_length, abbrev_length)
     1550parse_comp_unit (abfd, stash, unit_length, offset_size)
    12341551     bfd* abfd;
    12351552     struct dwarf2_debug *stash;
    12361553     bfd_vma unit_length;
    1237      unsigned int abbrev_length;
     1554     unsigned int offset_size;
    12381555{
    12391556  struct comp_unit* unit;
    1240 
    1241   unsigned short version;
    1242   unsigned int abbrev_offset = 0;
    1243   unsigned char addr_size;
     1557  unsigned int version;
     1558  bfd_vma abbrev_offset = 0;
     1559  unsigned int addr_size;
    12441560  struct abbrev_info** abbrevs;
    1245 
    12461561  unsigned int abbrev_number, bytes_read, i;
    12471562  struct abbrev_info *abbrev;
    12481563  struct attribute attr;
    1249 
    12501564  char *info_ptr = stash->info_ptr;
    12511565  char *end_ptr = info_ptr + unit_length;
     1566  bfd_size_type amt;
    12521567
    12531568  version = read_2_bytes (abfd, info_ptr);
    12541569  info_ptr += 2;
    1255   BFD_ASSERT (abbrev_length == 0
    1256               || abbrev_length == 4
    1257               || abbrev_length == 8);
    1258   if (abbrev_length == 0 || abbrev_length == 4)
     1570  BFD_ASSERT (offset_size == 4 || offset_size == 8);
     1571  if (offset_size == 4)
    12591572    abbrev_offset = read_4_bytes (abfd, info_ptr);
    1260   else if (abbrev_length == 8)
     1573  else
    12611574    abbrev_offset = read_8_bytes (abfd, info_ptr);
    1262   info_ptr += abbrev_length;
     1575  info_ptr += offset_size;
    12631576  addr_size = read_1_byte (abfd, info_ptr);
    12641577  info_ptr += 1;
     
    12661579  if (version != 2)
    12671580    {
    1268       (*_bfd_error_handler) (_("Dwarf Error: found dwarf version '%hu', this reader only handles version 2 information."), version );
     1581      (*_bfd_error_handler) (_("Dwarf Error: found dwarf version '%u', this reader only handles version 2 information."), version);
    12691582      bfd_set_error (bfd_error_bad_value);
    12701583      return 0;
     
    12751588      (*_bfd_error_handler) (_("Dwarf Error: found address size '%u', this reader can not handle sizes greater than '%u'."),
    12761589                         addr_size,
    1277                          sizeof (bfd_vma));
     1590                         (unsigned int) sizeof (bfd_vma));
    12781591      bfd_set_error (bfd_error_bad_value);
    12791592      return 0;
     
    12821595  if (addr_size != 2 && addr_size != 4 && addr_size != 8)
    12831596    {
    1284       (*_bfd_error_handler) ("Dwarf Error: found address size '%u', this reader can only handle address sizes '2', '4' and '8'.", addr_size );
     1597      (*_bfd_error_handler) ("Dwarf Error: found address size '%u', this reader can only handle address sizes '2', '4' and '8'.", addr_size);
    12851598      bfd_set_error (bfd_error_bad_value);
    12861599      return 0;
     
    12961609  if (! abbrev_number)
    12971610    {
    1298       (*_bfd_error_handler) (_("Dwarf Error: Bad abbrev number: %d."),
     1611      (*_bfd_error_handler) (_("Dwarf Error: Bad abbrev number: %u."),
    12991612                         abbrev_number);
    13001613      bfd_set_error (bfd_error_bad_value);
     
    13051618  if (! abbrev)
    13061619    {
    1307       (*_bfd_error_handler) (_("Dwarf Error: Could not find abbrev number %d."),
     1620      (*_bfd_error_handler) (_("Dwarf Error: Could not find abbrev number %u."),
    13081621                         abbrev_number);
    13091622      bfd_set_error (bfd_error_bad_value);
     
    13111624    }
    13121625
    1313   unit = (struct comp_unit*) bfd_zalloc (abfd, sizeof (struct comp_unit));
     1626  amt = sizeof (struct comp_unit);
     1627  unit = (struct comp_unit*) bfd_zalloc (abfd, amt);
    13141628  unit->abfd = abfd;
    13151629  unit->addr_size = addr_size;
     1630  unit->offset_size = offset_size;
    13161631  unit->abbrevs = abbrevs;
    13171632  unit->end_ptr = end_ptr;
     1633  unit->stash = stash;
    13181634
    13191635  for (i = 0; i < abbrev->num_attrs; ++i)
     
    13671683}
    13681684
    1369 /* Return true if UNIT contains the address given by ADDR.  */
    1370 
    1371 static boolean
     1685/* Return TRUE if UNIT contains the address given by ADDR.  */
     1686
     1687static bfd_boolean
    13721688comp_unit_contains_address (unit, addr)
    13731689     struct comp_unit* unit;
     
    13771693
    13781694  if (unit->error)
    1379     return 0;
     1695    return FALSE;
    13801696
    13811697  arange = &unit->arange;
     
    13831699    {
    13841700      if (addr >= arange->low && addr < arange->high)
    1385         return 1;
     1701        return TRUE;
    13861702      arange = arange->next;
    13871703    }
    13881704  while (arange);
    13891705
    1390   return 0;
     1706  return FALSE;
    13911707}
    13921708
     
    13961712   to be filled in.
    13971713
    1398    Return true of UNIT contains ADDR, and no errors were encountered;
    1399    false otherwise.  */
    1400 
    1401 static boolean
    1402 comp_unit_find_nearest_line (unit, addr,
    1403                              filename_ptr, functionname_ptr, linenumber_ptr,
    1404                              stash)
     1714   Return TRUE if UNIT contains ADDR, and no errors were encountered;
     1715   FALSE otherwise.  */
     1716
     1717static bfd_boolean
     1718comp_unit_find_nearest_line (unit, addr, filename_ptr, functionname_ptr,
     1719                             linenumber_ptr, stash)
    14051720     struct comp_unit* unit;
    14061721     bfd_vma addr;
     
    14101725     struct dwarf2_debug *stash;
    14111726{
    1412   boolean line_p;
    1413   boolean func_p;
     1727  bfd_boolean line_p;
     1728  bfd_boolean func_p;
     1729  struct funcinfo *function;
    14141730
    14151731  if (unit->error)
    1416     return false;
     1732    return FALSE;
    14171733
    14181734  if (! unit->line_table)
     
    14211737        {
    14221738          unit->error = 1;
    1423           return false;
     1739          return FALSE;
    14241740        }
    14251741
     
    14291745        {
    14301746          unit->error = 1;
    1431           return false;
    1432         }
    1433 
    1434       if (! scan_unit_for_functions (unit))
     1747          return FALSE;
     1748        }
     1749
     1750      if (unit->first_child_die_ptr < unit->end_ptr
     1751          && ! scan_unit_for_functions (unit))
    14351752        {
    14361753          unit->error = 1;
    1437           return false;
    1438         }
    1439     }
    1440 
    1441   line_p = lookup_address_in_line_info_table (unit->line_table,
    1442                                               addr,
    1443                                               filename_ptr,
     1754          return FALSE;
     1755        }
     1756    }
     1757
     1758  function = NULL;
     1759  func_p = lookup_address_in_function_table (unit->function_table, addr,
     1760                                             &function, functionname_ptr);
     1761  line_p = lookup_address_in_line_info_table (unit->line_table, addr,
     1762                                              function, filename_ptr,
    14441763                                              linenumber_ptr);
    1445   func_p = lookup_address_in_function_table (unit->function_table,
    1446                                              addr,
    1447                                              functionname_ptr);
    14481764  return line_p || func_p;
    14491765}
    14501766
    1451 /* Locate a section in a BFD containing debugging info.  The search starts from the
    1452    section after AFTER_SEC, or from the first section in the BFD if AFTER_SEC is
    1453    NULL.  The search works by examining the names of the sections.  There are two
    1454    permissiable names.  The first is .debug_info.  This is the standard DWARF2 name.
    1455    The second is a prefix .gnu.linkonce.wi.  This is a variation on the .debug_info
    1456    section which has a checksum describing the contents appended onto the name.  This
    1457    allows the linker to identify and discard duplicate debugging sections for
    1458    different compilation units.  */
     1767/* Locate a section in a BFD containing debugging info.  The search starts
     1768   from the section after AFTER_SEC, or from the first section in the BFD if
     1769   AFTER_SEC is NULL.  The search works by examining the names of the
     1770   sections.  There are two permissiable names.  The first is .debug_info.
     1771   This is the standard DWARF2 name.  The second is a prefix .gnu.linkonce.wi.
     1772   This is a variation on the .debug_info section which has a checksum
     1773   describing the contents appended onto the name.  This allows the linker to
     1774   identify and discard duplicate debugging sections for different
     1775   compilation units.  */
    14591776#define DWARF2_DEBUG_INFO ".debug_info"
    14601777#define GNU_LINKONCE_INFO ".gnu.linkonce.wi."
     
    14861803}
    14871804
    1488 /* The DWARF2 version of find_nearest line.  Return true if the line
     1805/* The DWARF2 version of find_nearest line.  Return TRUE if the line
    14891806   is found without error.  ADDR_SIZE is the number of bytes in the
    14901807   initial .debug_info length field and in the abbreviation offset.
     
    14921809   used.  */
    14931810
    1494 boolean
     1811bfd_boolean
    14951812_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
    14961813                               filename_ptr, functionname_ptr,
    1497                                linenumber_ptr,
    1498                                addr_size, pinfo)
     1814                               linenumber_ptr, addr_size, pinfo)
    14991815     bfd *abfd;
    15001816     asection *section;
    1501      asymbol **symbols ATTRIBUTE_UNUSED;
     1817     asymbol **symbols;
    15021818     bfd_vma offset;
    15031819     const char **filename_ptr;
     
    15351851  if (! stash)
    15361852    {
    1537       unsigned long total_size;
     1853      bfd_size_type total_size;
    15381854      asection *msec;
    1539 
    1540       stash =
    1541         (struct dwarf2_debug*) bfd_zalloc (abfd, sizeof (struct dwarf2_debug));
     1855      bfd_size_type amt = sizeof (struct dwarf2_debug);
     1856
     1857      stash = (struct dwarf2_debug*) bfd_zalloc (abfd, amt);
    15421858      if (! stash)
    1543         return false;
     1859        return FALSE;
    15441860
    15451861      *pinfo = (PTR) stash;
     
    15501866           has been allocated, but contains zeros, this lets
    15511867           future calls to this function fail quicker.  */
    1552          return false;
     1868         return FALSE;
    15531869
    15541870      /* There can be more than one DWARF2 info section in a BFD these days.
    1555         Read them all in and produce one large stash.  We do this in two
     1871        Read them all in and produce one large stash.  We do this in two
    15561872         passes - in the first pass we just accumulate the section sizes.
    15571873         In the second pass we read in the section's contents.  The allows
     
    15621878      stash->info_ptr = (char *) bfd_alloc (abfd, total_size);
    15631879      if (stash->info_ptr == NULL)
    1564         return false;
     1880        return FALSE;
    15651881
    15661882      stash->info_ptr_end = stash->info_ptr;
     
    15701886           msec = find_debug_info (abfd, msec))
    15711887        {
    1572           unsigned long size;
    1573           unsigned long start;
     1888          bfd_size_type size;
     1889          bfd_size_type start;
    15741890
    15751891          size = msec->_raw_size;
     
    15791895          start = stash->info_ptr_end - stash->info_ptr;
    15801896
    1581           if (! bfd_get_section_contents (abfd, msec, stash->info_ptr + start, 0, size))
     1897          if ((bfd_simple_get_relocated_section_contents
     1898               (abfd, msec, stash->info_ptr + start, symbols)) == NULL)
    15821899            continue;
    15831900
     
    15851902        }
    15861903
    1587       BFD_ASSERT (stash->info_ptr_end = stash->info_ptr + total_size);
    1588     }
    1589 
    1590   /* FIXME: There is a problem with the contents of the
    1591      .debug_info section.  The 'low' and 'high' addresses of the
    1592      comp_units are computed by relocs against symbols in the
    1593      .text segment.  We need these addresses in order to determine
    1594      the nearest line number, and so we have to resolve the
    1595      relocs.  There is a similar problem when the .debug_line
    1596      section is processed as well (e.g., there may be relocs
    1597      against the operand of the DW_LNE_set_address operator).
    1598 
    1599      Unfortunately getting hold of the reloc information is hard...
    1600 
    1601      For now, this means that disassembling object files (as
    1602      opposed to fully executables) does not always work as well as
    1603      we would like.  */
     1904      BFD_ASSERT (stash->info_ptr_end == stash->info_ptr + total_size);
     1905
     1906      stash->sec = find_debug_info (abfd, NULL);
     1907      stash->sec_info_ptr = stash->info_ptr;
     1908      stash->syms = symbols;
     1909    }
    16041910
    16051911  /* A null info_ptr indicates that there is no dwarf2 info
    16061912     (or that an error occured while setting up the stash).  */
    16071913  if (! stash->info_ptr)
    1608     return false;
     1914    return FALSE;
    16091915
    16101916  /* Check the previously read comp. units first.  */
     
    16181924  while (stash->info_ptr < stash->info_ptr_end)
    16191925    {
    1620       struct comp_unit* each;
    16211926      bfd_vma length;
    1622       boolean found;
    1623 
    1624       if (addr_size == 4)
    1625         length = read_4_bytes (abfd, stash->info_ptr);
     1927      bfd_boolean found;
     1928      unsigned int offset_size = addr_size;
     1929
     1930      length = read_4_bytes (abfd, stash->info_ptr);
     1931      /* A 0xffffff length is the DWARF3 way of indicating we use
     1932         64-bit offsets, instead of 32-bit offsets.  */
     1933      if (length == 0xffffffff)
     1934        {
     1935          offset_size = 8;
     1936          length = read_8_bytes (abfd, stash->info_ptr + 4);
     1937          stash->info_ptr += 12;
     1938        }
     1939      /* A zero length is the IRIX way of indicating 64-bit offsets,
     1940         mostly because the 64-bit length will generally fit in 32
     1941         bits, and the endianness helps.  */
     1942      else if (length == 0)
     1943        {
     1944          offset_size = 8;
     1945          length = read_4_bytes (abfd, stash->info_ptr + 4);
     1946          stash->info_ptr += 8;
     1947        }
     1948      /* In the absence of the hints above, we assume addr_size-sized
     1949         offsets, for backward-compatibility with pre-DWARF3 64-bit
     1950         platforms.  */
     1951      else if (addr_size == 8)
     1952        {
     1953          length = read_8_bytes (abfd, stash->info_ptr);
     1954          stash->info_ptr += 8;
     1955        }
    16261956      else
    1627         length = read_8_bytes (abfd, stash->info_ptr);
    1628       stash->info_ptr += addr_size;
     1957        stash->info_ptr += 4;
    16291958
    16301959      if (length > 0)
    1631         {
    1632           each = parse_comp_unit (abfd, stash, length, addr_size);
     1960        {
     1961          each = parse_comp_unit (abfd, stash, length, offset_size);
    16331962          stash->info_ptr += length;
     1963
     1964          if ((bfd_vma) (stash->info_ptr - stash->sec_info_ptr)
     1965              == stash->sec->_raw_size)
     1966            {
     1967              stash->sec = find_debug_info (abfd, stash->sec);
     1968              stash->sec_info_ptr = stash->info_ptr;
     1969            }
    16341970
    16351971          if (each)
     
    16471983                  if (comp_unit_contains_address (each, addr))
    16481984                    return comp_unit_find_nearest_line (each, addr,
    1649                                                        filename_ptr,
    1650                                                        functionname_ptr,
    1651                                                        linenumber_ptr,
    1652                                                        stash);
     1985                                                        filename_ptr,
     1986                                                        functionname_ptr,
     1987                                                        linenumber_ptr,
     1988                                                        stash);
    16531989                }
    16541990              else
     
    16601996                                                       stash);
    16611997                  if (found)
    1662                     return true;
     1998                    return TRUE;
    16631999                }
    16642000            }
     
    16662002    }
    16672003
    1668   return false;
    1669 }
     2004  return FALSE;
     2005}
Note: See TracChangeset for help on using the changeset viewer.