Subversion Repositories Kolibri OS

Rev

Rev 5197 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5197 Rev 6324
Line 1... Line 1...
1
/* DWARF 2 support.
1
/* DWARF 2 support.
2
   Copyright 1994-2013 Free Software Foundation, Inc.
2
   Copyright (C) 1994-2015 Free Software Foundation, Inc.
Line 3... Line 3...
3
 
3
 
4
   Adapted from gdb/dwarf2read.c by Gavin Koch of Cygnus Solutions
4
   Adapted from gdb/dwarf2read.c by Gavin Koch of Cygnus Solutions
Line 5... Line 5...
5
   (gavin@cygnus.com).
5
   (gavin@cygnus.com).
Line 154... Line 154...
154
     address in an inlined function, preserve a pointer into the
154
     address in an inlined function, preserve a pointer into the
155
     calling chain for subsequent calls to bfd_find_inliner_info to
155
     calling chain for subsequent calls to bfd_find_inliner_info to
156
     use. */
156
     use. */
157
  struct funcinfo *inliner_chain;
157
  struct funcinfo *inliner_chain;
Line -... Line 158...
-
 
158
 
-
 
159
  /* Section VMAs at the time the stash was built.  */
-
 
160
  bfd_vma *sec_vma;
158
 
161
 
159
  /* Number of sections whose VMA we must adjust.  */
162
  /* Number of sections whose VMA we must adjust.  */
Line 160... Line 163...
160
  unsigned int adjusted_section_count;
163
  int adjusted_section_count;
161
 
164
 
Line 162... Line 165...
162
  /* Array of sections with adjusted VMA.  */
165
  /* Array of sections with adjusted VMA.  */
Line 217... Line 220...
217
  char *name;
220
  char *name;
Line 218... Line 221...
218
 
221
 
219
  /* The abbrev hash table.  */
222
  /* The abbrev hash table.  */
Line -... Line 223...
-
 
223
  struct abbrev_info **abbrevs;
-
 
224
 
-
 
225
  /* DW_AT_language.  */
220
  struct abbrev_info **abbrevs;
226
  int lang;
221
 
227
 
Line 222... Line 228...
222
  /* Note that an error was found by comp_unit_find_nearest_line.  */
228
  /* Note that an error was found by comp_unit_find_nearest_line.  */
223
  int error;
229
  int error;
Line 548... Line 554...
548
    }
554
    }
Line 549... Line 555...
549
 
555
 
550
  return TRUE;
556
  return TRUE;
Line 551... Line -...
551
}
-
 
552
 
-
 
553
/* VERBATIM
-
 
554
   The following function up to the END VERBATIM mark are
-
 
555
   copied directly from dwarf2read.c.  */
557
}
Line 556... Line 558...
556
 
558
 
557
/* Read dwarf information from a buffer.  */
559
/* Read dwarf information from a buffer.  */
558
 
560
 
-
 
561
static unsigned int
-
 
562
read_1_byte (bfd *abfd ATTRIBUTE_UNUSED, bfd_byte *buf, bfd_byte *end)
559
static unsigned int
563
{
560
read_1_byte (bfd *abfd ATTRIBUTE_UNUSED, bfd_byte *buf)
564
  if (buf + 1 > end)
Line 561... Line 565...
561
{
565
    return 0;
562
  return bfd_get_8 (abfd, buf);
566
  return bfd_get_8 (abfd, buf);
563
}
567
}
-
 
568
 
-
 
569
static int
564
 
570
read_1_signed_byte (bfd *abfd ATTRIBUTE_UNUSED, bfd_byte *buf, bfd_byte *end)
565
static int
571
{
Line 566... Line 572...
566
read_1_signed_byte (bfd *abfd ATTRIBUTE_UNUSED, bfd_byte *buf)
572
  if (buf + 1 > end)
567
{
573
    return 0;
568
  return bfd_get_signed_8 (abfd, buf);
574
  return bfd_get_signed_8 (abfd, buf);
-
 
575
}
-
 
576
 
569
}
577
static unsigned int
570
 
578
read_2_bytes (bfd *abfd, bfd_byte *buf, bfd_byte *end)
Line 571... Line 579...
571
static unsigned int
579
{
572
read_2_bytes (bfd *abfd, bfd_byte *buf)
580
  if (buf + 2 > end)
573
{
581
    return 0;
-
 
582
  return bfd_get_16 (abfd, buf);
-
 
583
}
574
  return bfd_get_16 (abfd, buf);
584
 
575
}
585
static unsigned int
Line 576... Line 586...
576
 
586
read_4_bytes (bfd *abfd, bfd_byte *buf, bfd_byte *end)
577
static unsigned int
587
{
578
read_4_bytes (bfd *abfd, bfd_byte *buf)
588
  if (buf + 4 > end)
-
 
589
    return 0;
-
 
590
  return bfd_get_32 (abfd, buf);
579
{
591
}
580
  return bfd_get_32 (abfd, buf);
592
 
Line 581... Line 593...
581
}
593
static bfd_uint64_t
582
 
594
read_8_bytes (bfd *abfd, bfd_byte *buf, bfd_byte *end)
583
static bfd_uint64_t
595
{
-
 
596
  if (buf + 8 > end)
584
read_8_bytes (bfd *abfd, bfd_byte *buf)
597
    return 0;
585
{
598
  return bfd_get_64 (abfd, buf);
-
 
599
}
-
 
600
 
586
  return bfd_get_64 (abfd, buf);
601
static bfd_byte *
587
}
602
read_n_bytes (bfd *abfd ATTRIBUTE_UNUSED,
Line -... Line 603...
-
 
603
	      bfd_byte *buf,
-
 
604
	      bfd_byte *end,
-
 
605
	      unsigned int size ATTRIBUTE_UNUSED)
-
 
606
{
-
 
607
  if (buf + size > end)
-
 
608
    return NULL;
588
 
609
  return buf;
589
static bfd_byte *
610
}
590
read_n_bytes (bfd *abfd ATTRIBUTE_UNUSED,
611
 
-
 
612
/* Scans a NUL terminated string starting at BUF, returning a pointer to it.
591
	      bfd_byte *buf,
613
   Returns the number of characters in the string, *including* the NUL byte,
592
	      unsigned int size ATTRIBUTE_UNUSED)
614
   in BYTES_READ_PTR.  This value is set even if the function fails.  Bytes
-
 
615
   at or beyond BUF_END will not be read.  Returns NULL if there was a
-
 
616
   problem, or if the string is empty.  */
-
 
617
 
-
 
618
static char *
593
{
619
read_string (bfd *          abfd ATTRIBUTE_UNUSED,
594
  return buf;
620
	     bfd_byte *     buf,
-
 
621
	     bfd_byte *     buf_end,
Line 595... Line 622...
595
}
622
	     unsigned int * bytes_read_ptr)
596
 
623
{
597
static char *
624
  bfd_byte *str = buf;
598
read_string (bfd *abfd ATTRIBUTE_UNUSED,
625
 
599
	     bfd_byte *buf,
626
  if (buf >= buf_end)
Line -... Line 627...
-
 
627
    {
-
 
628
      * bytes_read_ptr = 0;
-
 
629
      return NULL;
-
 
630
    }
-
 
631
 
-
 
632
  if (*str == '\0')
-
 
633
    {
600
	     unsigned int *bytes_read_ptr)
634
      * bytes_read_ptr = 1;
601
{
635
      return NULL;
602
  /* Return a pointer to the embedded string.  */
636
    }
Line -... Line 637...
-
 
637
 
-
 
638
  while (buf < buf_end)
-
 
639
    if (* buf ++ == 0)
-
 
640
      {
-
 
641
	* bytes_read_ptr = buf - str;
-
 
642
	return (char *) str;
603
  char *str = (char *) buf;
643
      }
Line 604... Line 644...
604
 
644
 
605
  if (*str == '\0')
645
  * bytes_read_ptr = buf - str;
606
    {
646
  return NULL;
-
 
647
}
607
      *bytes_read_ptr = 1;
648
 
608
      return NULL;
649
/* Reads an offset from BUF and then locates the string at this offset
609
    }
650
   inside the debug string section.  Returns a pointer to the string.
610
 
651
   Returns the number of bytes read from BUF, *not* the length of the string,
611
  *bytes_read_ptr = strlen (str) + 1;
652
   in BYTES_READ_PTR.  This value is set even if the function fails.  Bytes
Line -... Line 653...
-
 
653
   at or beyond BUF_END will not be read from BUF.  Returns NULL if there was
-
 
654
   a problem, or if the string is empty.  Does not check for NUL termination
-
 
655
   of the string.  */
-
 
656
 
-
 
657
static char *
-
 
658
read_indirect_string (struct comp_unit * unit,
612
  return str;
659
		      bfd_byte *         buf,
613
}
660
		      bfd_byte *         buf_end,
614
 
661
		      unsigned int *     bytes_read_ptr)
615
/* END VERBATIM */
662
{
Line 616... Line 663...
616
 
663
  bfd_uint64_t offset;
Line 617... Line 664...
617
static char *
664
  struct dwarf2_debug *stash = unit->stash;
618
read_indirect_string (struct comp_unit * unit,
665
  char *str;
619
		      bfd_byte *         buf,
666
 
620
		      unsigned int *     bytes_read_ptr)
667
  if (buf + unit->offset_size > buf_end)
Line -... Line 668...
-
 
668
    {
-
 
669
      * bytes_read_ptr = 0;
621
{
670
      return NULL;
622
  bfd_uint64_t offset;
671
    }
623
  struct dwarf2_debug *stash = unit->stash;
672
 
624
  char *str;
673
  if (unit->offset_size == 4)
625
 
674
    offset = read_4_bytes (unit->abfd, buf, buf_end);
Line 626... Line 675...
626
  if (unit->offset_size == 4)
675
  else
627
    offset = read_4_bytes (unit->abfd, buf);
676
    offset = read_8_bytes (unit->abfd, buf, buf_end);
628
  else
677
 
Line 629... Line 678...
629
    offset = read_8_bytes (unit->abfd, buf);
678
  *bytes_read_ptr = unit->offset_size;
630
 
679
 
631
  *bytes_read_ptr = unit->offset_size;
680
  if (! read_section (unit->abfd, &stash->debug_sections[debug_str],
-
 
681
                      stash->syms, offset,
632
 
682
		      &stash->dwarf_str_buffer, &stash->dwarf_str_size))
633
  if (! read_section (unit->abfd, &stash->debug_sections[debug_str],
683
    return NULL;
634
                      stash->syms, offset,
684
 
635
		      &stash->dwarf_str_buffer, &stash->dwarf_str_size))
685
  if (offset >= stash->dwarf_str_size)
636
    return NULL;
686
    return NULL;
Line -... Line 687...
-
 
687
  str = (char *) stash->dwarf_str_buffer + offset;
-
 
688
  if (*str == '\0')
-
 
689
    return NULL;
-
 
690
  return str;
-
 
691
}
-
 
692
 
637
 
693
/* Like read_indirect_string but uses a .debug_str located in
638
  str = (char *) stash->dwarf_str_buffer + offset;
694
   an alternate file pointed to by the .gnu_debugaltlink section.
639
  if (*str == '\0')
695
   Used to impement DW_FORM_GNU_strp_alt.  */
640
    return NULL;
696
 
Line 641... Line 697...
641
  return str;
697
static char *
Line 642... Line 698...
642
}
698
read_alt_indirect_string (struct comp_unit * unit,
643
 
699
			  bfd_byte *         buf,
Line 688... Line 744...
688
		      offset,
744
		      offset,
689
		      &stash->alt_dwarf_str_buffer,
745
		      &stash->alt_dwarf_str_buffer,
690
		      &stash->alt_dwarf_str_size))
746
		      &stash->alt_dwarf_str_size))
691
    return NULL;
747
    return NULL;
Line -... Line 748...
-
 
748
 
-
 
749
  if (offset >= stash->alt_dwarf_str_size)
692
 
750
    return NULL;
693
  str = (char *) stash->alt_dwarf_str_buffer + offset;
751
  str = (char *) stash->alt_dwarf_str_buffer + offset;
694
  if (*str == '\0')
752
  if (*str == '\0')
Line 695... Line 753...
695
    return NULL;
753
    return NULL;
Line 734... Line 792...
734
		      offset,
792
		      offset,
735
		      &stash->alt_dwarf_info_buffer,
793
		      &stash->alt_dwarf_info_buffer,
736
		      &stash->alt_dwarf_info_size))
794
		      &stash->alt_dwarf_info_size))
737
    return NULL;
795
    return NULL;
Line -... Line 796...
-
 
796
 
-
 
797
  if (offset >= stash->alt_dwarf_info_size)
738
 
798
    return NULL;
739
  return stash->alt_dwarf_info_buffer + offset;
799
  return stash->alt_dwarf_info_buffer + offset;
Line 740... Line 800...
740
}
800
}
741
 
801
 
742
static bfd_uint64_t
802
static bfd_uint64_t
-
 
803
read_address (struct comp_unit *unit, bfd_byte *buf, bfd_byte * buf_end)
-
 
804
{
-
 
805
  int signed_vma = 0;
743
read_address (struct comp_unit *unit, bfd_byte *buf)
806
 
-
 
807
  if (bfd_get_flavour (unit->abfd) == bfd_target_elf_flavour)
-
 
808
    signed_vma = get_elf_backend_data (unit->abfd)->sign_extend_vma;
-
 
809
 
Line 744... Line 810...
744
{
810
  if (buf + unit->addr_size > buf_end)
745
  int signed_vma = get_elf_backend_data (unit->abfd)->sign_extend_vma;
811
    return 0;
746
 
812
 
747
  if (signed_vma)
813
  if (signed_vma)
Line 804... Line 870...
804
static struct abbrev_info**
870
static struct abbrev_info**
805
read_abbrevs (bfd *abfd, bfd_uint64_t offset, struct dwarf2_debug *stash)
871
read_abbrevs (bfd *abfd, bfd_uint64_t offset, struct dwarf2_debug *stash)
806
{
872
{
807
  struct abbrev_info **abbrevs;
873
  struct abbrev_info **abbrevs;
808
  bfd_byte *abbrev_ptr;
874
  bfd_byte *abbrev_ptr;
-
 
875
  bfd_byte *abbrev_end;
809
  struct abbrev_info *cur_abbrev;
876
  struct abbrev_info *cur_abbrev;
810
  unsigned int abbrev_number, bytes_read, abbrev_name;
877
  unsigned int abbrev_number, bytes_read, abbrev_name;
811
  unsigned int abbrev_form, hash_number;
878
  unsigned int abbrev_form, hash_number;
812
  bfd_size_type amt;
879
  bfd_size_type amt;
Line 813... Line 880...
813
 
880
 
814
  if (! read_section (abfd, &stash->debug_sections[debug_abbrev],
881
  if (! read_section (abfd, &stash->debug_sections[debug_abbrev],
815
                      stash->syms, offset,
882
                      stash->syms, offset,
816
		      &stash->dwarf_abbrev_buffer, &stash->dwarf_abbrev_size))
883
		      &stash->dwarf_abbrev_buffer, &stash->dwarf_abbrev_size))
Line -... Line 884...
-
 
884
    return NULL;
-
 
885
 
-
 
886
  if (offset >= stash->dwarf_abbrev_size)
817
    return NULL;
887
    return NULL;
818
 
888
 
819
  amt = sizeof (struct abbrev_info*) * ABBREV_HASH_SIZE;
889
  amt = sizeof (struct abbrev_info*) * ABBREV_HASH_SIZE;
820
  abbrevs = (struct abbrev_info **) bfd_zalloc (abfd, amt);
890
  abbrevs = (struct abbrev_info **) bfd_zalloc (abfd, amt);
Line 821... Line 891...
821
  if (abbrevs == NULL)
891
  if (abbrevs == NULL)
-
 
892
    return NULL;
822
    return NULL;
893
 
823
 
894
  abbrev_ptr = stash->dwarf_abbrev_buffer + offset;
Line 824... Line 895...
824
  abbrev_ptr = stash->dwarf_abbrev_buffer + offset;
895
  abbrev_end = stash->dwarf_abbrev_buffer + stash->dwarf_abbrev_size;
825
  abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
896
  abbrev_number = safe_read_leb128 (abfd, abbrev_ptr, &bytes_read, FALSE, abbrev_end);
826
  abbrev_ptr += bytes_read;
897
  abbrev_ptr += bytes_read;
Line 834... Line 905...
834
	return NULL;
905
	return NULL;
Line 835... Line 906...
835
 
906
 
836
      /* Read in abbrev header.  */
907
      /* Read in abbrev header.  */
837
      cur_abbrev->number = abbrev_number;
908
      cur_abbrev->number = abbrev_number;
838
      cur_abbrev->tag = (enum dwarf_tag)
909
      cur_abbrev->tag = (enum dwarf_tag)
839
	read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
910
	safe_read_leb128 (abfd, abbrev_ptr, &bytes_read, FALSE, abbrev_end);
840
      abbrev_ptr += bytes_read;
911
      abbrev_ptr += bytes_read;
841
      cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
912
      cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr, abbrev_end);
Line 842... Line 913...
842
      abbrev_ptr += 1;
913
      abbrev_ptr += 1;
843
 
914
 
844
      /* Now read in declarations.  */
915
      /* Now read in declarations.  */
845
      abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
916
      abbrev_name = safe_read_leb128 (abfd, abbrev_ptr, &bytes_read, FALSE, abbrev_end);
846
      abbrev_ptr += bytes_read;
917
      abbrev_ptr += bytes_read;
Line 847... Line 918...
847
      abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
918
      abbrev_form = safe_read_leb128 (abfd, abbrev_ptr, &bytes_read, FALSE, abbrev_end);
848
      abbrev_ptr += bytes_read;
919
      abbrev_ptr += bytes_read;
849
 
920
 
Line 877... Line 948...
877
 
948
 
878
	  cur_abbrev->attrs[cur_abbrev->num_attrs].name
949
	  cur_abbrev->attrs[cur_abbrev->num_attrs].name
879
	    = (enum dwarf_attribute) abbrev_name;
950
	    = (enum dwarf_attribute) abbrev_name;
880
	  cur_abbrev->attrs[cur_abbrev->num_attrs++].form
951
	  cur_abbrev->attrs[cur_abbrev->num_attrs++].form
881
	    = (enum dwarf_form) abbrev_form;
952
	    = (enum dwarf_form) abbrev_form;
882
	  abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
953
	  abbrev_name = safe_read_leb128 (abfd, abbrev_ptr, &bytes_read, FALSE, abbrev_end);
883
	  abbrev_ptr += bytes_read;
954
	  abbrev_ptr += bytes_read;
884
	  abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
955
	  abbrev_form = safe_read_leb128 (abfd, abbrev_ptr, &bytes_read, FALSE, abbrev_end);
885
	  abbrev_ptr += bytes_read;
956
	  abbrev_ptr += bytes_read;
Line 886... Line 957...
886
	}
957
	}
887
 
958
 
Line 897... Line 968...
897
	 for the next compile unit) or if the end of the abbreviation
968
	 for the next compile unit) or if the end of the abbreviation
898
	 table is reached.  */
969
	 table is reached.  */
899
      if ((unsigned int) (abbrev_ptr - stash->dwarf_abbrev_buffer)
970
      if ((unsigned int) (abbrev_ptr - stash->dwarf_abbrev_buffer)
900
	  >= stash->dwarf_abbrev_size)
971
	  >= stash->dwarf_abbrev_size)
901
	break;
972
	break;
902
      abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
973
      abbrev_number = safe_read_leb128 (abfd, abbrev_ptr, &bytes_read, FALSE, abbrev_end);
903
      abbrev_ptr += bytes_read;
974
      abbrev_ptr += bytes_read;
904
      if (lookup_abbrev (abbrev_number,abbrevs) != NULL)
975
      if (lookup_abbrev (abbrev_number, abbrevs) != NULL)
905
	break;
976
	break;
906
    }
977
    }
Line 907... Line 978...
907
 
978
 
908
  return abbrevs;
979
  return abbrevs;
Line -... Line 980...
-
 
980
}
-
 
981
 
-
 
982
/* Returns true if the form is one which has a string value.  */
-
 
983
 
-
 
984
static inline bfd_boolean
-
 
985
is_str_attr (enum dwarf_form form)
-
 
986
{
-
 
987
  return form == DW_FORM_string || form == DW_FORM_strp || form == DW_FORM_GNU_strp_alt;
909
}
988
}
-
 
989
 
-
 
990
/* Read and fill in the value of attribute ATTR as described by FORM.
Line 910... Line 991...
910
 
991
   Read data starting from INFO_PTR, but never at or beyond INFO_PTR_END.
911
/* Read an attribute value described by an attribute form.  */
992
   Returns an updated INFO_PTR taking into account the amount of data read.  */
912
 
993
 
913
static bfd_byte *
994
static bfd_byte *
914
read_attribute_value (struct attribute *attr,
995
read_attribute_value (struct attribute *  attr,
-
 
996
		      unsigned form,
915
		      unsigned form,
997
		      struct comp_unit *  unit,
916
		      struct comp_unit *unit,
998
		      bfd_byte *          info_ptr,
917
		      bfd_byte *info_ptr)
999
		      bfd_byte *          info_ptr_end)
918
{
1000
{
919
  bfd *abfd = unit->abfd;
1001
  bfd *abfd = unit->abfd;
Line -... Line 1002...
-
 
1002
  unsigned int bytes_read;
-
 
1003
  struct dwarf_block *blk;
-
 
1004
  bfd_size_type amt;
-
 
1005
 
-
 
1006
  if (info_ptr >= info_ptr_end)
-
 
1007
    {
-
 
1008
      (*_bfd_error_handler) (_("Dwarf Error: Info pointer extends beyond end of attributes"));
920
  unsigned int bytes_read;
1009
      bfd_set_error (bfd_error_bad_value);
Line 921... Line 1010...
921
  struct dwarf_block *blk;
1010
      return info_ptr;
922
  bfd_size_type amt;
1011
    }
923
 
1012
 
924
  attr->form = (enum dwarf_form) form;
1013
  attr->form = (enum dwarf_form) form;
925
 
1014
 
926
  switch (form)
1015
  switch (form)
927
    {
1016
    {
928
    case DW_FORM_ref_addr:
1017
    case DW_FORM_ref_addr:
929
      /* DW_FORM_ref_addr is an address in DWARF2, and an offset in
1018
      /* DW_FORM_ref_addr is an address in DWARF2, and an offset in
930
	 DWARF3.  */
1019
	 DWARF3.  */
931
      if (unit->version == 3 || unit->version == 4)
1020
      if (unit->version == 3 || unit->version == 4)
932
	{
1021
	{
933
	  if (unit->offset_size == 4)
1022
	  if (unit->offset_size == 4)
934
	    attr->u.val = read_4_bytes (unit->abfd, info_ptr);
1023
	    attr->u.val = read_4_bytes (unit->abfd, info_ptr, info_ptr_end);
935
	  else
1024
	  else
936
	    attr->u.val = read_8_bytes (unit->abfd, info_ptr);
1025
	    attr->u.val = read_8_bytes (unit->abfd, info_ptr, info_ptr_end);
937
	  info_ptr += unit->offset_size;
1026
	  info_ptr += unit->offset_size;
938
	  break;
1027
	  break;
939
	}
1028
	}
940
      /* FALLTHROUGH */
1029
      /* FALLTHROUGH */
941
    case DW_FORM_addr:
1030
    case DW_FORM_addr:
942
      attr->u.val = read_address (unit, info_ptr);
1031
      attr->u.val = read_address (unit, info_ptr, info_ptr_end);
943
      info_ptr += unit->addr_size;
1032
      info_ptr += unit->addr_size;
944
      break;
1033
      break;
945
    case DW_FORM_GNU_ref_alt:
1034
    case DW_FORM_GNU_ref_alt:
946
    case DW_FORM_sec_offset:
1035
    case DW_FORM_sec_offset:
947
      if (unit->offset_size == 4)
1036
      if (unit->offset_size == 4)
948
	attr->u.val = read_4_bytes (unit->abfd, info_ptr);
1037
	attr->u.val = read_4_bytes (unit->abfd, info_ptr, info_ptr_end);
949
      else
1038
      else
950
	attr->u.val = read_8_bytes (unit->abfd, info_ptr);
1039
	attr->u.val = read_8_bytes (unit->abfd, info_ptr, info_ptr_end);
951
      info_ptr += unit->offset_size;
1040
      info_ptr += unit->offset_size;
952
      break;
1041
      break;
953
    case DW_FORM_block2:
1042
    case DW_FORM_block2:
954
      amt = sizeof (struct dwarf_block);
1043
      amt = sizeof (struct dwarf_block);
955
      blk = (struct dwarf_block *) bfd_alloc (abfd, amt);
1044
      blk = (struct dwarf_block *) bfd_alloc (abfd, amt);
956
      if (blk == NULL)
1045
      if (blk == NULL)
957
	return NULL;
1046
	return NULL;
958
      blk->size = read_2_bytes (abfd, info_ptr);
1047
      blk->size = read_2_bytes (abfd, info_ptr, info_ptr_end);
959
      info_ptr += 2;
1048
      info_ptr += 2;
960
      blk->data = read_n_bytes (abfd, info_ptr, blk->size);
1049
      blk->data = read_n_bytes (abfd, info_ptr, info_ptr_end, blk->size);
961
      info_ptr += blk->size;
1050
      info_ptr += blk->size;
962
      attr->u.blk = blk;
1051
      attr->u.blk = blk;
963
      break;
1052
      break;
964
    case DW_FORM_block4:
1053
    case DW_FORM_block4:
965
      amt = sizeof (struct dwarf_block);
1054
      amt = sizeof (struct dwarf_block);
966
      blk = (struct dwarf_block *) bfd_alloc (abfd, amt);
1055
      blk = (struct dwarf_block *) bfd_alloc (abfd, amt);
967
      if (blk == NULL)
1056
      if (blk == NULL)
968
	return NULL;
1057
	return NULL;
969
      blk->size = read_4_bytes (abfd, info_ptr);
1058
      blk->size = read_4_bytes (abfd, info_ptr, info_ptr_end);
970
      info_ptr += 4;
1059
      info_ptr += 4;
971
      blk->data = read_n_bytes (abfd, info_ptr, blk->size);
1060
      blk->data = read_n_bytes (abfd, info_ptr, info_ptr_end, blk->size);
972
      info_ptr += blk->size;
1061
      info_ptr += blk->size;
973
      attr->u.blk = blk;
1062
      attr->u.blk = blk;
974
      break;
1063
      break;
975
    case DW_FORM_data2:
1064
    case DW_FORM_data2:
976
      attr->u.val = read_2_bytes (abfd, info_ptr);
1065
      attr->u.val = read_2_bytes (abfd, info_ptr, info_ptr_end);
977
      info_ptr += 2;
1066
      info_ptr += 2;
978
      break;
1067
      break;
979
    case DW_FORM_data4:
1068
    case DW_FORM_data4:
980
      attr->u.val = read_4_bytes (abfd, info_ptr);
1069
      attr->u.val = read_4_bytes (abfd, info_ptr, info_ptr_end);
981
      info_ptr += 4;
1070
      info_ptr += 4;
982
      break;
1071
      break;
983
    case DW_FORM_data8:
1072
    case DW_FORM_data8:
984
      attr->u.val = read_8_bytes (abfd, info_ptr);
1073
      attr->u.val = read_8_bytes (abfd, info_ptr, info_ptr_end);
985
      info_ptr += 8;
1074
      info_ptr += 8;
986
      break;
1075
      break;
987
    case DW_FORM_string:
1076
    case DW_FORM_string:
988
      attr->u.str = read_string (abfd, info_ptr, &bytes_read);
1077
      attr->u.str = read_string (abfd, info_ptr, info_ptr_end, &bytes_read);
989
      info_ptr += bytes_read;
1078
      info_ptr += bytes_read;
990
      break;
1079
      break;
991
    case DW_FORM_strp:
1080
    case DW_FORM_strp:
992
      attr->u.str = read_indirect_string (unit, info_ptr, &bytes_read);
1081
      attr->u.str = read_indirect_string (unit, info_ptr, info_ptr_end, &bytes_read);
993
      info_ptr += bytes_read;
1082
      info_ptr += bytes_read;
994
      break;
1083
      break;
995
    case DW_FORM_GNU_strp_alt:
1084
    case DW_FORM_GNU_strp_alt:
996
      attr->u.str = read_alt_indirect_string (unit, info_ptr, &bytes_read);
1085
      attr->u.str = read_alt_indirect_string (unit, info_ptr, info_ptr_end, &bytes_read);
997
      info_ptr += bytes_read;
1086
      info_ptr += bytes_read;
998
      break;
1087
      break;
999
    case DW_FORM_exprloc:
1088
    case DW_FORM_exprloc:
1000
    case DW_FORM_block:
1089
    case DW_FORM_block:
1001
      amt = sizeof (struct dwarf_block);
1090
      amt = sizeof (struct dwarf_block);
1002
      blk = (struct dwarf_block *) bfd_alloc (abfd, amt);
1091
      blk = (struct dwarf_block *) bfd_alloc (abfd, amt);
1003
      if (blk == NULL)
1092
      if (blk == NULL)
1004
	return NULL;
1093
	return NULL;
1005
      blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
1094
      blk->size = safe_read_leb128 (abfd, info_ptr, &bytes_read, FALSE, info_ptr_end);
1006
      info_ptr += bytes_read;
1095
      info_ptr += bytes_read;
1007
      blk->data = read_n_bytes (abfd, info_ptr, blk->size);
1096
      blk->data = read_n_bytes (abfd, info_ptr, info_ptr_end, blk->size);
1008
      info_ptr += blk->size;
1097
      info_ptr += blk->size;
1009
      attr->u.blk = blk;
1098
      attr->u.blk = blk;
1010
      break;
1099
      break;
1011
    case DW_FORM_block1:
1100
    case DW_FORM_block1:
1012
      amt = sizeof (struct dwarf_block);
1101
      amt = sizeof (struct dwarf_block);
1013
      blk = (struct dwarf_block *) bfd_alloc (abfd, amt);
1102
      blk = (struct dwarf_block *) bfd_alloc (abfd, amt);
1014
      if (blk == NULL)
1103
      if (blk == NULL)
1015
	return NULL;
1104
	return NULL;
1016
      blk->size = read_1_byte (abfd, info_ptr);
1105
      blk->size = read_1_byte (abfd, info_ptr, info_ptr_end);
1017
      info_ptr += 1;
1106
      info_ptr += 1;
1018
      blk->data = read_n_bytes (abfd, info_ptr, blk->size);
1107
      blk->data = read_n_bytes (abfd, info_ptr, info_ptr_end, blk->size);
1019
      info_ptr += blk->size;
1108
      info_ptr += blk->size;
1020
      attr->u.blk = blk;
1109
      attr->u.blk = blk;
1021
      break;
1110
      break;
1022
    case DW_FORM_data1:
1111
    case DW_FORM_data1:
1023
      attr->u.val = read_1_byte (abfd, info_ptr);
1112
      attr->u.val = read_1_byte (abfd, info_ptr, info_ptr_end);
1024
      info_ptr += 1;
1113
      info_ptr += 1;
1025
      break;
1114
      break;
1026
    case DW_FORM_flag:
1115
    case DW_FORM_flag:
1027
      attr->u.val = read_1_byte (abfd, info_ptr);
1116
      attr->u.val = read_1_byte (abfd, info_ptr, info_ptr_end);
1028
      info_ptr += 1;
1117
      info_ptr += 1;
1029
      break;
1118
      break;
1030
    case DW_FORM_flag_present:
1119
    case DW_FORM_flag_present:
1031
      attr->u.val = 1;
1120
      attr->u.val = 1;
1032
      break;
1121
      break;
1033
    case DW_FORM_sdata:
1122
    case DW_FORM_sdata:
1034
      attr->u.sval = read_signed_leb128 (abfd, info_ptr, &bytes_read);
1123
      attr->u.sval = safe_read_leb128 (abfd, info_ptr, &bytes_read, TRUE, info_ptr_end);
1035
      info_ptr += bytes_read;
1124
      info_ptr += bytes_read;
1036
      break;
1125
      break;
1037
    case DW_FORM_udata:
1126
    case DW_FORM_udata:
1038
      attr->u.val = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
1127
      attr->u.val = safe_read_leb128 (abfd, info_ptr, &bytes_read, FALSE, info_ptr_end);
1039
      info_ptr += bytes_read;
1128
      info_ptr += bytes_read;
1040
      break;
1129
      break;
1041
    case DW_FORM_ref1:
1130
    case DW_FORM_ref1:
1042
      attr->u.val = read_1_byte (abfd, info_ptr);
1131
      attr->u.val = read_1_byte (abfd, info_ptr, info_ptr_end);
1043
      info_ptr += 1;
1132
      info_ptr += 1;
1044
      break;
1133
      break;
1045
    case DW_FORM_ref2:
1134
    case DW_FORM_ref2:
1046
      attr->u.val = read_2_bytes (abfd, info_ptr);
1135
      attr->u.val = read_2_bytes (abfd, info_ptr, info_ptr_end);
1047
      info_ptr += 2;
1136
      info_ptr += 2;
1048
      break;
1137
      break;
1049
    case DW_FORM_ref4:
1138
    case DW_FORM_ref4:
1050
      attr->u.val = read_4_bytes (abfd, info_ptr);
1139
      attr->u.val = read_4_bytes (abfd, info_ptr, info_ptr_end);
1051
      info_ptr += 4;
1140
      info_ptr += 4;
1052
      break;
1141
      break;
1053
    case DW_FORM_ref8:
1142
    case DW_FORM_ref8:
1054
      attr->u.val = read_8_bytes (abfd, info_ptr);
1143
      attr->u.val = read_8_bytes (abfd, info_ptr, info_ptr_end);
1055
      info_ptr += 8;
1144
      info_ptr += 8;
1056
      break;
1145
      break;
1057
    case DW_FORM_ref_sig8:
1146
    case DW_FORM_ref_sig8:
1058
      attr->u.val = read_8_bytes (abfd, info_ptr);
1147
      attr->u.val = read_8_bytes (abfd, info_ptr, info_ptr_end);
1059
      info_ptr += 8;
1148
      info_ptr += 8;
1060
      break;
1149
      break;
1061
    case DW_FORM_ref_udata:
1150
    case DW_FORM_ref_udata:
1062
      attr->u.val = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
1151
      attr->u.val = safe_read_leb128 (abfd, info_ptr, &bytes_read, FALSE, info_ptr_end);
1063
      info_ptr += bytes_read;
1152
      info_ptr += bytes_read;
1064
      break;
1153
      break;
1065
    case DW_FORM_indirect:
1154
    case DW_FORM_indirect:
1066
      form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
1155
      form = safe_read_leb128 (abfd, info_ptr, &bytes_read, FALSE, info_ptr_end);
1067
      info_ptr += bytes_read;
1156
      info_ptr += bytes_read;
1068
      info_ptr = read_attribute_value (attr, form, unit, info_ptr);
1157
      info_ptr = read_attribute_value (attr, form, unit, info_ptr, info_ptr_end);
Line 1080... Line 1169...
1080
 
1169
 
1081
static bfd_byte *
1170
static bfd_byte *
1082
read_attribute (struct attribute *attr,
1171
read_attribute (struct attribute *    attr,
1083
		struct attr_abbrev *abbrev,
1172
		struct attr_abbrev *  abbrev,
1084
		struct comp_unit *unit,
1173
		struct comp_unit *    unit,
-
 
1174
		bfd_byte *            info_ptr,
1085
		bfd_byte *info_ptr)
1175
		bfd_byte *            info_ptr_end)
1086
{
1176
{
1087
  attr->name = abbrev->name;
1177
  attr->name = abbrev->name;
1088
  info_ptr = read_attribute_value (attr, abbrev->form, unit, info_ptr);
1178
  info_ptr = read_attribute_value (attr, abbrev->form, unit, info_ptr, info_ptr_end);
1089
  return info_ptr;
1179
  return info_ptr;
Line -... Line 1180...
-
 
1180
}
-
 
1181
 
-
 
1182
/* Return whether DW_AT_name will return the same as DW_AT_linkage_name
-
 
1183
   for a function.  */
-
 
1184
 
-
 
1185
static bfd_boolean
-
 
1186
non_mangled (int lang)
-
 
1187
{
-
 
1188
  switch (lang)
-
 
1189
    {
-
 
1190
    default:
-
 
1191
      return FALSE;
-
 
1192
 
-
 
1193
    case DW_LANG_C89:
-
 
1194
    case DW_LANG_C:
-
 
1195
    case DW_LANG_Ada83:
-
 
1196
    case DW_LANG_Cobol74:
-
 
1197
    case DW_LANG_Cobol85:
-
 
1198
    case DW_LANG_Fortran77:
-
 
1199
    case DW_LANG_Pascal83:
-
 
1200
    case DW_LANG_C99:
-
 
1201
    case DW_LANG_Ada95:
-
 
1202
    case DW_LANG_PLI:
-
 
1203
    case DW_LANG_UPC:
-
 
1204
    case DW_LANG_C11:
-
 
1205
      return TRUE;
-
 
1206
    }
1090
}
1207
}
Line 1091... Line 1208...
1091
 
1208
 
1092
/* Source line information table routines.  */
1209
/* Source line information table routines.  */
Line 1145... Line 1262...
1145
  struct funcinfo *prev_func;
1262
  struct funcinfo *prev_func;
1146
  /* Pointer to function one scope higher.  */
1263
  /* Pointer to function one scope higher.  */
1147
  struct funcinfo *caller_func;
1264
  struct funcinfo *caller_func;
1148
  /* Source location file name where caller_func inlines this func.  */
1265
  /* Source location file name where caller_func inlines this func.  */
1149
  char *caller_file;
1266
  char *caller_file;
1150
  /* Source location line number where caller_func inlines this func.  */
-
 
1151
  int caller_line;
-
 
1152
  /* Source location file name.  */
1267
  /* Source location file name.  */
1153
  char *file;
1268
  char *file;
-
 
1269
  /* Source location line number where caller_func inlines this func.  */
-
 
1270
  int caller_line;
1154
  /* Source location line number.  */
1271
  /* Source location line number.  */
1155
  int line;
1272
  int line;
1156
  int tag;
1273
  int tag;
-
 
1274
  bfd_boolean is_linkage;
1157
  char *name;
1275
  const char *name;
1158
  struct arange arange;
1276
  struct arange arange;
1159
  /* Where the symbol is defined.  */
1277
  /* Where the symbol is defined.  */
1160
  asection *sec;
1278
  asection *sec;
1161
};
1279
};
Line 1340... Line 1458...
1340
      char *dir_name = NULL;
1458
      char *dir_name = NULL;
1341
      char *subdir_name = NULL;
1459
      char *subdir_name = NULL;
1342
      char *name;
1460
      char *name;
1343
      size_t len;
1461
      size_t len;
Line 1344... Line 1462...
1344
 
1462
 
-
 
1463
      if (table->files[file - 1].dir
-
 
1464
	  /* PR 17512: file: 0317e960.  */
-
 
1465
	  && table->files[file - 1].dir <= table->num_dirs
-
 
1466
	  /* PR 17512: file: 7f3d2e4b.  */
1345
      if (table->files[file - 1].dir)
1467
	  && table->dirs != NULL)
Line 1346... Line 1468...
1346
	subdir_name = table->dirs[table->files[file - 1].dir - 1];
1468
	subdir_name = table->dirs[table->files[file - 1].dir - 1];
1347
 
1469
 
Line 1561... Line 1683...
1561
  table->num_sequences = 0;
1683
  table->num_sequences = 0;
1562
  table->sequences = NULL;
1684
  table->sequences = NULL;
Line 1563... Line 1685...
1563
 
1685
 
Line -... Line 1686...
-
 
1686
  table->lcl_head = NULL;
-
 
1687
 
-
 
1688
  if (stash->dwarf_line_size < 16)
-
 
1689
    {
-
 
1690
      (*_bfd_error_handler)
-
 
1691
	(_("Dwarf Error: Line info section is too small (%ld)"),
-
 
1692
	 (long) stash->dwarf_line_size);
-
 
1693
      bfd_set_error (bfd_error_bad_value);
1564
  table->lcl_head = NULL;
1694
      return NULL;
-
 
1695
    }
Line 1565... Line 1696...
1565
 
1696
  line_ptr = stash->dwarf_line_buffer + unit->line_offset;
1566
  line_ptr = stash->dwarf_line_buffer + unit->line_offset;
1697
  line_end = stash->dwarf_line_buffer + stash->dwarf_line_size;
1567
 
1698
 
1568
  /* Read in the prologue.  */
1699
  /* Read in the prologue.  */
1569
  lh.total_length = read_4_bytes (abfd, line_ptr);
1700
  lh.total_length = read_4_bytes (abfd, line_ptr, line_end);
1570
  line_ptr += 4;
1701
  line_ptr += 4;
1571
  offset_size = 4;
1702
  offset_size = 4;
1572
  if (lh.total_length == 0xffffffff)
1703
  if (lh.total_length == 0xffffffff)
1573
    {
1704
    {
1574
      lh.total_length = read_8_bytes (abfd, line_ptr);
1705
      lh.total_length = read_8_bytes (abfd, line_ptr, line_end);
1575
      line_ptr += 8;
1706
      line_ptr += 8;
1576
      offset_size = 8;
1707
      offset_size = 8;
1577
    }
1708
    }
1578
  else if (lh.total_length == 0 && unit->addr_size == 8)
1709
  else if (lh.total_length == 0 && unit->addr_size == 8)
1579
    {
1710
    {
1580
      /* Handle (non-standard) 64-bit DWARF2 formats.  */
1711
      /* Handle (non-standard) 64-bit DWARF2 formats.  */
1581
      lh.total_length = read_4_bytes (abfd, line_ptr);
1712
      lh.total_length = read_4_bytes (abfd, line_ptr, line_end);
-
 
1713
      line_ptr += 4;
-
 
1714
      offset_size = 8;
-
 
1715
    }
-
 
1716
 
-
 
1717
  if (lh.total_length > stash->dwarf_line_size)
-
 
1718
    {
-
 
1719
      (*_bfd_error_handler)
-
 
1720
	(_("Dwarf Error: Line info data is bigger (0x%lx) than the section (0x%lx)"),
-
 
1721
	 (long) lh.total_length, (long) stash->dwarf_line_size);
-
 
1722
      bfd_set_error (bfd_error_bad_value);
1582
      line_ptr += 4;
1723
      return NULL;
-
 
1724
    }
1583
      offset_size = 8;
1725
 
1584
    }
1726
  line_end = line_ptr + lh.total_length;
1585
  line_end = line_ptr + lh.total_length;
1727
 
1586
  lh.version = read_2_bytes (abfd, line_ptr);
1728
  lh.version = read_2_bytes (abfd, line_ptr, line_end);
1587
  if (lh.version < 2 || lh.version > 4)
1729
  if (lh.version < 2 || lh.version > 4)
1588
    {
1730
    {
1589
      (*_bfd_error_handler)
1731
      (*_bfd_error_handler)
1590
	(_("Dwarf Error: Unhandled .debug_line version %d."), lh.version);
1732
	(_("Dwarf Error: Unhandled .debug_line version %d."), lh.version);
1591
      bfd_set_error (bfd_error_bad_value);
1733
      bfd_set_error (bfd_error_bad_value);
-
 
1734
      return NULL;
-
 
1735
    }
-
 
1736
  line_ptr += 2;
-
 
1737
 
-
 
1738
  if (line_ptr + offset_size + (lh.version >=4 ? 6 : 5) >= line_end)
-
 
1739
    {
-
 
1740
      (*_bfd_error_handler)
-
 
1741
	(_("Dwarf Error: Ran out of room reading prologue"));
-
 
1742
      bfd_set_error (bfd_error_bad_value);
1592
      return NULL;
1743
      return NULL;
1593
    }
1744
    }
1594
  line_ptr += 2;
1745
 
1595
  if (offset_size == 4)
1746
  if (offset_size == 4)
1596
    lh.prologue_length = read_4_bytes (abfd, line_ptr);
1747
    lh.prologue_length = read_4_bytes (abfd, line_ptr, line_end);
-
 
1748
  else
1597
  else
1749
    lh.prologue_length = read_8_bytes (abfd, line_ptr, line_end);
1598
    lh.prologue_length = read_8_bytes (abfd, line_ptr);
1750
  line_ptr += offset_size;
-
 
1751
 
1599
  line_ptr += offset_size;
1752
  lh.minimum_instruction_length = read_1_byte (abfd, line_ptr, line_end);
1600
  lh.minimum_instruction_length = read_1_byte (abfd, line_ptr);
1753
  line_ptr += 1;
1601
  line_ptr += 1;
1754
 
1602
  if (lh.version >= 4)
1755
  if (lh.version >= 4)
1603
    {
1756
    {
1604
      lh.maximum_ops_per_insn = read_1_byte (abfd, line_ptr);
1757
      lh.maximum_ops_per_insn = read_1_byte (abfd, line_ptr, line_end);
1605
      line_ptr += 1;
1758
      line_ptr += 1;
-
 
1759
    }
1606
    }
1760
  else
1607
  else
1761
    lh.maximum_ops_per_insn = 1;
1608
    lh.maximum_ops_per_insn = 1;
1762
 
1609
  if (lh.maximum_ops_per_insn == 0)
1763
  if (lh.maximum_ops_per_insn == 0)
1610
    {
1764
    {
1611
      (*_bfd_error_handler)
1765
      (*_bfd_error_handler)
1612
	(_("Dwarf Error: Invalid maximum operations per instruction."));
1766
	(_("Dwarf Error: Invalid maximum operations per instruction."));
-
 
1767
      bfd_set_error (bfd_error_bad_value);
1613
      bfd_set_error (bfd_error_bad_value);
1768
      return NULL;
1614
      return NULL;
1769
    }
-
 
1770
 
1615
    }
1771
  lh.default_is_stmt = read_1_byte (abfd, line_ptr, line_end);
1616
  lh.default_is_stmt = read_1_byte (abfd, line_ptr);
1772
  line_ptr += 1;
-
 
1773
 
1617
  line_ptr += 1;
1774
  lh.line_base = read_1_signed_byte (abfd, line_ptr, line_end);
1618
  lh.line_base = read_1_signed_byte (abfd, line_ptr);
1775
  line_ptr += 1;
-
 
1776
 
1619
  line_ptr += 1;
1777
  lh.line_range = read_1_byte (abfd, line_ptr, line_end);
1620
  lh.line_range = read_1_byte (abfd, line_ptr);
1778
  line_ptr += 1;
-
 
1779
 
-
 
1780
  lh.opcode_base = read_1_byte (abfd, line_ptr, line_end);
-
 
1781
  line_ptr += 1;
-
 
1782
 
-
 
1783
  if (line_ptr + (lh.opcode_base - 1) >= line_end)
-
 
1784
    {
-
 
1785
      (*_bfd_error_handler) (_("Dwarf Error: Ran out of room reading opcodes"));
-
 
1786
      bfd_set_error (bfd_error_bad_value);
1621
  line_ptr += 1;
1787
      return NULL;
1622
  lh.opcode_base = read_1_byte (abfd, line_ptr);
1788
    }
Line 1623... Line 1789...
1623
  line_ptr += 1;
1789
 
Line 1624... Line 1790...
1624
  amt = lh.opcode_base * sizeof (unsigned char);
1790
  amt = lh.opcode_base * sizeof (unsigned char);
1625
  lh.standard_opcode_lengths = (unsigned char *) bfd_alloc (abfd, amt);
1791
  lh.standard_opcode_lengths = (unsigned char *) bfd_alloc (abfd, amt);
1626
 
1792
 
1627
  lh.standard_opcode_lengths[0] = 1;
1793
  lh.standard_opcode_lengths[0] = 1;
1628
 
1794
 
Line 1629... Line 1795...
1629
  for (i = 1; i < lh.opcode_base; ++i)
1795
  for (i = 1; i < lh.opcode_base; ++i)
1630
    {
1796
    {
1631
      lh.standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
1797
      lh.standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr, line_end);
1632
      line_ptr += 1;
1798
      line_ptr += 1;
Line 1633... Line 1799...
1633
    }
1799
    }
1634
 
1800
 
Line 1654... Line 1820...
1654
    }
1820
    }
Line 1655... Line 1821...
1655
 
1821
 
Line 1656... Line 1822...
1656
  line_ptr += bytes_read;
1822
  line_ptr += bytes_read;
1657
 
1823
 
1658
  /* Read file name table.  */
1824
  /* Read file name table.  */
1659
  while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL)
1825
  while ((cur_file = read_string (abfd, line_ptr, line_end, &bytes_read)) != NULL)
Line 1660... Line 1826...
1660
    {
1826
    {
1661
      line_ptr += bytes_read;
1827
      line_ptr += bytes_read;
Line 1673... Line 1839...
1673
	  table->files = tmp;
1839
	  table->files = tmp;
1674
	}
1840
	}
Line 1675... Line 1841...
1675
 
1841
 
1676
      table->files[table->num_files].name = cur_file;
1842
      table->files[table->num_files].name = cur_file;
1677
      table->files[table->num_files].dir =
1843
      table->files[table->num_files].dir =
1678
	read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
1844
	safe_read_leb128 (abfd, line_ptr, &bytes_read, FALSE, line_end);
1679
      line_ptr += bytes_read;
-
 
1680
      table->files[table->num_files].time =
1845
      line_ptr += bytes_read;
1681
	read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
1846
      table->files[table->num_files].time = safe_read_leb128 (abfd, line_ptr, &bytes_read, FALSE, line_end);
1682
      line_ptr += bytes_read;
-
 
1683
      table->files[table->num_files].size =
1847
      line_ptr += bytes_read;
1684
	read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
1848
      table->files[table->num_files].size = safe_read_leb128 (abfd, line_ptr, &bytes_read, FALSE, line_end);
1685
      line_ptr += bytes_read;
1849
      line_ptr += bytes_read;
1686
      table->num_files++;
1850
      table->num_files++;
Line 1687... Line 1851...
1687
    }
1851
    }
Line 1709... Line 1873...
1709
      bfd_vma high_pc = 0;
1873
      bfd_vma high_pc = 0;
Line 1710... Line 1874...
1710
 
1874
 
1711
      /* Decode the table.  */
1875
      /* Decode the table.  */
1712
      while (! end_sequence)
1876
      while (! end_sequence)
1713
	{
1877
	{
1714
	  op_code = read_1_byte (abfd, line_ptr);
1878
	  op_code = read_1_byte (abfd, line_ptr, line_end);
Line 1715... Line 1879...
1715
	  line_ptr += 1;
1879
	  line_ptr += 1;
1716
 
1880
 
1717
	  if (op_code >= lh.opcode_base)
1881
	  if (op_code >= lh.opcode_base)
1718
	    {
1882
	    {
-
 
1883
	      /* Special operand.  */
-
 
1884
	      adj_opcode = op_code - lh.opcode_base;
1719
	      /* Special operand.  */
1885
	      if (lh.line_range == 0)
1720
	      adj_opcode = op_code - lh.opcode_base;
1886
		goto line_fail;
1721
	      if (lh.maximum_ops_per_insn == 1)
1887
	      if (lh.maximum_ops_per_insn == 1)
1722
		address += (adj_opcode / lh.line_range
1888
		address += (adj_opcode / lh.line_range
1723
			    * lh.minimum_instruction_length);
1889
			    * lh.minimum_instruction_length);
Line 1741... Line 1907...
1741
		high_pc = address;
1907
		high_pc = address;
1742
	    }
1908
	    }
1743
	  else switch (op_code)
1909
	  else switch (op_code)
1744
	    {
1910
	    {
1745
	    case DW_LNS_extended_op:
1911
	    case DW_LNS_extended_op:
1746
	      exop_len = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
1912
	      exop_len = safe_read_leb128 (abfd, line_ptr, &bytes_read, FALSE, line_end);
1747
	      line_ptr += bytes_read;
1913
	      line_ptr += bytes_read;
1748
	      extended_op = read_1_byte (abfd, line_ptr);
1914
	      extended_op = read_1_byte (abfd, line_ptr, line_end);
1749
	      line_ptr += 1;
1915
	      line_ptr += 1;
Line 1750... Line 1916...
1750
 
1916
 
1751
	      switch (extended_op)
1917
	      switch (extended_op)
1752
		{
1918
		{
Line 1762... Line 1928...
1762
		    high_pc = address;
1928
		    high_pc = address;
1763
		  if (!arange_add (unit, &unit->arange, low_pc, high_pc))
1929
		  if (!arange_add (unit, &unit->arange, low_pc, high_pc))
1764
		    goto line_fail;
1930
		    goto line_fail;
1765
		  break;
1931
		  break;
1766
		case DW_LNE_set_address:
1932
		case DW_LNE_set_address:
1767
		  address = read_address (unit, line_ptr);
1933
		  address = read_address (unit, line_ptr, line_end);
1768
		  op_index = 0;
1934
		  op_index = 0;
1769
		  line_ptr += unit->addr_size;
1935
		  line_ptr += unit->addr_size;
1770
		  break;
1936
		  break;
1771
		case DW_LNE_define_file:
1937
		case DW_LNE_define_file:
1772
		  cur_file = read_string (abfd, line_ptr, &bytes_read);
1938
		  cur_file = read_string (abfd, line_ptr, line_end, &bytes_read);
1773
		  line_ptr += bytes_read;
1939
		  line_ptr += bytes_read;
1774
		  if ((table->num_files % FILE_ALLOC_CHUNK) == 0)
1940
		  if ((table->num_files % FILE_ALLOC_CHUNK) == 0)
1775
		    {
1941
		    {
1776
		      struct fileinfo *tmp;
1942
		      struct fileinfo *tmp;
Line 1782... Line 1948...
1782
			goto line_fail;
1948
			goto line_fail;
1783
		      table->files = tmp;
1949
		      table->files = tmp;
1784
		    }
1950
		    }
1785
		  table->files[table->num_files].name = cur_file;
1951
		  table->files[table->num_files].name = cur_file;
1786
		  table->files[table->num_files].dir =
1952
		  table->files[table->num_files].dir =
1787
		    read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
1953
		    safe_read_leb128 (abfd, line_ptr, &bytes_read, FALSE, line_end);
1788
		  line_ptr += bytes_read;
1954
		  line_ptr += bytes_read;
1789
		  table->files[table->num_files].time =
1955
		  table->files[table->num_files].time =
1790
		    read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
1956
		    safe_read_leb128 (abfd, line_ptr, &bytes_read, FALSE, line_end);
1791
		  line_ptr += bytes_read;
1957
		  line_ptr += bytes_read;
1792
		  table->files[table->num_files].size =
1958
		  table->files[table->num_files].size =
1793
		    read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
1959
		    safe_read_leb128 (abfd, line_ptr, &bytes_read, FALSE, line_end);
1794
		  line_ptr += bytes_read;
1960
		  line_ptr += bytes_read;
1795
		  table->num_files++;
1961
		  table->num_files++;
1796
		  break;
1962
		  break;
1797
		case DW_LNE_set_discriminator:
1963
		case DW_LNE_set_discriminator:
1798
		  discriminator =
1964
		  discriminator =
1799
                      read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
1965
		    safe_read_leb128 (abfd, line_ptr, &bytes_read, FALSE, line_end);
1800
		  line_ptr += bytes_read;
1966
		  line_ptr += bytes_read;
1801
		  break;
1967
		  break;
1802
		case DW_LNE_HP_source_file_correlation:
1968
		case DW_LNE_HP_source_file_correlation:
1803
		  line_ptr += exop_len - 1;
1969
		  line_ptr += exop_len - 1;
1804
		  break;
1970
		  break;
Line 1823... Line 1989...
1823
		high_pc = address;
1989
		high_pc = address;
1824
	      break;
1990
	      break;
1825
	    case DW_LNS_advance_pc:
1991
	    case DW_LNS_advance_pc:
1826
	      if (lh.maximum_ops_per_insn == 1)
1992
	      if (lh.maximum_ops_per_insn == 1)
1827
		address += (lh.minimum_instruction_length
1993
		address += (lh.minimum_instruction_length
1828
			    * read_unsigned_leb128 (abfd, line_ptr,
1994
			    * safe_read_leb128 (abfd, line_ptr, &bytes_read,
1829
						    &bytes_read));
1995
						FALSE, line_end));
1830
	      else
1996
	      else
1831
		{
1997
		{
1832
		  bfd_vma adjust = read_unsigned_leb128 (abfd, line_ptr,
1998
		  bfd_vma adjust = safe_read_leb128 (abfd, line_ptr, &bytes_read,
1833
							 &bytes_read);
1999
						     FALSE, line_end);
1834
		  address = ((op_index + adjust) / lh.maximum_ops_per_insn
2000
		  address = ((op_index + adjust) / lh.maximum_ops_per_insn
1835
			     * lh.minimum_instruction_length);
2001
			     * lh.minimum_instruction_length);
1836
		  op_index = (op_index + adjust) % lh.maximum_ops_per_insn;
2002
		  op_index = (op_index + adjust) % lh.maximum_ops_per_insn;
1837
		}
2003
		}
1838
	      line_ptr += bytes_read;
2004
	      line_ptr += bytes_read;
1839
	      break;
2005
	      break;
1840
	    case DW_LNS_advance_line:
2006
	    case DW_LNS_advance_line:
1841
	      line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
2007
	      line += safe_read_leb128 (abfd, line_ptr, &bytes_read, TRUE, line_end);
1842
	      line_ptr += bytes_read;
2008
	      line_ptr += bytes_read;
1843
	      break;
2009
	      break;
1844
	    case DW_LNS_set_file:
2010
	    case DW_LNS_set_file:
1845
	      {
2011
	      {
1846
		unsigned int file;
2012
		unsigned int file;
Line 1847... Line 2013...
1847
 
2013
 
1848
		/* The file and directory tables are 0
2014
		/* The file and directory tables are 0
1849
		   based, the references are 1 based.  */
2015
		   based, the references are 1 based.  */
1850
		file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
2016
		file = safe_read_leb128 (abfd, line_ptr, &bytes_read, FALSE, line_end);
1851
		line_ptr += bytes_read;
2017
		line_ptr += bytes_read;
1852
		if (filename)
2018
		if (filename)
1853
		  free (filename);
2019
		  free (filename);
1854
		filename = concat_filename (table, file);
2020
		filename = concat_filename (table, file);
1855
		break;
2021
		break;
1856
	      }
2022
	      }
1857
	    case DW_LNS_set_column:
2023
	    case DW_LNS_set_column:
1858
	      column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
2024
	      column = safe_read_leb128 (abfd, line_ptr, &bytes_read, FALSE, line_end);
1859
	      line_ptr += bytes_read;
2025
	      line_ptr += bytes_read;
1860
	      break;
2026
	      break;
1861
	    case DW_LNS_negate_stmt:
2027
	    case DW_LNS_negate_stmt:
1862
	      is_stmt = (!is_stmt);
2028
	      is_stmt = (!is_stmt);
Line 1875... Line 2041...
1875
				 / lh.maximum_ops_per_insn));
2041
				 / lh.maximum_ops_per_insn));
1876
		  op_index = (op_index + adjust) % lh.maximum_ops_per_insn;
2042
		  op_index = (op_index + adjust) % lh.maximum_ops_per_insn;
1877
		}
2043
		}
1878
	      break;
2044
	      break;
1879
	    case DW_LNS_fixed_advance_pc:
2045
	    case DW_LNS_fixed_advance_pc:
1880
	      address += read_2_bytes (abfd, line_ptr);
2046
	      address += read_2_bytes (abfd, line_ptr, line_end);
1881
	      op_index = 0;
2047
	      op_index = 0;
1882
	      line_ptr += 2;
2048
	      line_ptr += 2;
1883
	      break;
2049
	      break;
1884
	    default:
2050
	    default:
1885
	      /* Unknown standard opcode, ignore it.  */
2051
	      /* Unknown standard opcode, ignore it.  */
1886
	      for (i = 0; i < lh.standard_opcode_lengths[op_code]; i++)
2052
	      for (i = 0; i < lh.standard_opcode_lengths[op_code]; i++)
1887
		{
2053
		{
1888
		  (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
2054
		  (void) safe_read_leb128 (abfd, line_ptr, &bytes_read, FALSE, line_end);
1889
		  line_ptr += bytes_read;
2055
		  line_ptr += bytes_read;
1890
		}
2056
		}
1891
	      break;
2057
	      break;
1892
	    }
2058
	    }
1893
	}
2059
	}
Line 1907... Line 2073...
1907
  if (table->dirs != NULL)
2073
  if (table->dirs != NULL)
1908
    free (table->dirs);
2074
    free (table->dirs);
1909
  return NULL;
2075
  return NULL;
1910
}
2076
}
Line 1911... Line 2077...
1911
 
2077
 
-
 
2078
/* If ADDR is within TABLE set the output parameters and return the
1912
/* If ADDR is within TABLE set the output parameters and return TRUE,
2079
   range of addresses covered by the entry used to fill them out.
-
 
2080
   Otherwise set * FILENAME_PTR to NULL and return 0.
1913
   otherwise return FALSE.  The output parameters, FILENAME_PTR and
2081
   The parameters FILENAME_PTR, LINENUMBER_PTR and DISCRIMINATOR_PTR
Line 1914... Line 2082...
1914
   LINENUMBER_PTR, are pointers to the objects to be filled in.  */
2082
   are pointers to the objects to be filled in.  */
1915
 
2083
 
1916
static bfd_boolean
2084
static bfd_vma
1917
lookup_address_in_line_info_table (struct line_info_table *table,
2085
lookup_address_in_line_info_table (struct line_info_table *table,
1918
				   bfd_vma addr,
2086
				   bfd_vma addr,
1919
				   const char **filename_ptr,
2087
				   const char **filename_ptr,
Line 1953... Line 2121...
1953
        {
2121
        {
1954
          *filename_ptr = each_line->filename;
2122
          *filename_ptr = each_line->filename;
1955
          *linenumber_ptr = each_line->line;
2123
          *linenumber_ptr = each_line->line;
1956
          if (discriminator_ptr)
2124
          if (discriminator_ptr)
1957
            *discriminator_ptr = each_line->discriminator;
2125
            *discriminator_ptr = each_line->discriminator;
1958
          return TRUE;
2126
	  return seq->last_line->address - seq->low_pc;
1959
        }
2127
        }
1960
    }
2128
    }
Line 1961... Line 2129...
1961
 
2129
 
1962
  *filename_ptr = NULL;
2130
  *filename_ptr = NULL;
1963
  return FALSE;
2131
  return 0;
Line 1964... Line 2132...
1964
}
2132
}
Line 1965... Line 2133...
1965
 
2133
 
Line 1974... Line 2142...
1974
		       &stash->dwarf_ranges_buffer, &stash->dwarf_ranges_size);
2142
		       &stash->dwarf_ranges_buffer, &stash->dwarf_ranges_size);
1975
}
2143
}
Line 1976... Line 2144...
1976
 
2144
 
Line 1977... Line 2145...
1977
/* Function table functions.  */
2145
/* Function table functions.  */
1978
 
2146
 
1979
/* If ADDR is within TABLE, set FUNCTIONNAME_PTR, and return TRUE.
2147
/* If ADDR is within UNIT's function tables, set FUNCTION_PTR, and return
1980
   Note that we need to find the function that has the smallest
2148
   TRUE.  Note that we need to find the function that has the smallest range
Line 1981... Line 2149...
1981
   range that contains ADDR, to handle inlined functions without
2149
   that contains ADDR, to handle inlined functions without depending upon
1982
   depending upon them being ordered in TABLE by increasing range. */
2150
   them being ordered in TABLE by increasing range.  */
1983
 
2151
 
1984
static bfd_boolean
2152
static bfd_boolean
1985
lookup_address_in_function_table (struct comp_unit *unit,
-
 
1986
				  bfd_vma addr,
2153
lookup_address_in_function_table (struct comp_unit *unit,
1987
				  struct funcinfo **function_ptr,
2154
				  bfd_vma addr,
1988
				  const char **functionname_ptr)
2155
				  struct funcinfo **function_ptr)
-
 
2156
{
1989
{
2157
  struct funcinfo* each_func;
Line 1990... Line 2158...
1990
  struct funcinfo* each_func;
2158
  struct funcinfo* best_fit = NULL;
1991
  struct funcinfo* best_fit = NULL;
2159
  bfd_vma best_fit_len = 0;
1992
  struct arange *arange;
2160
  struct arange *arange;
Line 2000... Line 2168...
2000
	   arange = arange->next)
2168
	   arange = arange->next)
2001
	{
2169
	{
2002
	  if (addr >= arange->low && addr < arange->high)
2170
	  if (addr >= arange->low && addr < arange->high)
2003
	    {
2171
	    {
2004
	      if (!best_fit
2172
	      if (!best_fit
2005
		  || (arange->high - arange->low
2173
		  || arange->high - arange->low < best_fit_len)
2006
		      < best_fit->arange.high - best_fit->arange.low))
-
 
-
 
2174
		{
2007
		best_fit = each_func;
2175
		best_fit = each_func;
-
 
2176
		  best_fit_len = arange->high - arange->low;
-
 
2177
		}
2008
	    }
2178
	    }
2009
	}
2179
	}
2010
    }
2180
    }
Line 2011... Line 2181...
2011
 
2181
 
2012
  if (best_fit)
2182
  if (best_fit)
2013
    {
-
 
2014
      *functionname_ptr = best_fit->name;
2183
    {
2015
      *function_ptr = best_fit;
2184
      *function_ptr = best_fit;
2016
      return TRUE;
2185
      return TRUE;
2017
    }
-
 
2018
  else
-
 
2019
    {
2186
    }
2020
      return FALSE;
2187
      return FALSE;
2021
    }
-
 
Line 2022... Line 2188...
2022
}
2188
}
2023
 
2189
 
Line 2024... Line 2190...
2024
/* If SYM at ADDR is within function table of UNIT, set FILENAME_PTR
2190
/* If SYM at ADDR is within function table of UNIT, set FILENAME_PTR
Line 2031... Line 2197...
2031
				 const char **filename_ptr,
2197
				 const char **filename_ptr,
2032
				 unsigned int *linenumber_ptr)
2198
				 unsigned int *linenumber_ptr)
2033
{
2199
{
2034
  struct funcinfo* each_func;
2200
  struct funcinfo* each_func;
2035
  struct funcinfo* best_fit = NULL;
2201
  struct funcinfo* best_fit = NULL;
-
 
2202
  bfd_vma best_fit_len = 0;
2036
  struct arange *arange;
2203
  struct arange *arange;
2037
  const char *name = bfd_asymbol_name (sym);
2204
  const char *name = bfd_asymbol_name (sym);
2038
  asection *sec = bfd_get_section (sym);
2205
  asection *sec = bfd_get_section (sym);
Line 2039... Line 2206...
2039
 
2206
 
Line 2049... Line 2216...
2049
	      && addr >= arange->low
2216
	      && addr >= arange->low
2050
	      && addr < arange->high
2217
	      && addr < arange->high
2051
	      && each_func->name
2218
	      && each_func->name
2052
	      && strcmp (name, each_func->name) == 0
2219
	      && strcmp (name, each_func->name) == 0
2053
	      && (!best_fit
2220
	      && (!best_fit
2054
		  || (arange->high - arange->low
2221
		  || arange->high - arange->low < best_fit_len))
2055
		      < best_fit->arange.high - best_fit->arange.low)))
2222
	    {
2056
	    best_fit = each_func;
2223
	    best_fit = each_func;
-
 
2224
	      best_fit_len = arange->high - arange->low;
-
 
2225
	    }
2057
	}
2226
	}
2058
    }
2227
    }
Line 2059... Line 2228...
2059
 
2228
 
2060
  if (best_fit)
2229
  if (best_fit)
Line 2104... Line 2273...
2104
    return FALSE;
2273
    return FALSE;
2105
}
2274
}
Line 2106... Line 2275...
2106
 
2275
 
2107
static char *
2276
static char *
2108
find_abstract_instance_name (struct comp_unit *unit,
2277
find_abstract_instance_name (struct comp_unit *unit,
-
 
2278
			     struct attribute *attr_ptr,
2109
			     struct attribute *attr_ptr)
2279
			     bfd_boolean *is_linkage)
2110
{
2280
{
2111
  bfd *abfd = unit->abfd;
2281
  bfd *abfd = unit->abfd;
-
 
2282
  bfd_byte *info_ptr;
2112
  bfd_byte *info_ptr;
2283
  bfd_byte *info_ptr_end;
2113
  unsigned int abbrev_number, bytes_read, i;
2284
  unsigned int abbrev_number, bytes_read, i;
2114
  struct abbrev_info *abbrev;
2285
  struct abbrev_info *abbrev;
2115
  bfd_uint64_t die_ref = attr_ptr->u.val;
2286
  bfd_uint64_t die_ref = attr_ptr->u.val;
2116
  struct attribute attr;
2287
  struct attribute attr;
Line 2124... Line 2295...
2124
	 any relocations should be resolved already.  */
2295
	 any relocations should be resolved already.  */
2125
      if (!die_ref)
2296
      if (!die_ref)
2126
	abort ();
2297
	abort ();
Line 2127... Line 2298...
2127
 
2298
 
-
 
2299
      info_ptr = unit->sec_info_ptr + die_ref;
-
 
2300
      info_ptr_end = unit->end_ptr;
-
 
2301
 
-
 
2302
      /* Now find the CU containing this pointer.  */
-
 
2303
      if (info_ptr >= unit->info_ptr_unit && info_ptr < unit->end_ptr)
-
 
2304
	;
-
 
2305
      else
-
 
2306
	{
-
 
2307
	  /* Check other CUs to see if they contain the abbrev.  */
-
 
2308
	  struct comp_unit * u;
-
 
2309
 
-
 
2310
	  for (u = unit->prev_unit; u != NULL; u = u->prev_unit)
-
 
2311
	    if (info_ptr >= u->info_ptr_unit && info_ptr < u->end_ptr)
-
 
2312
	      break;
-
 
2313
 
-
 
2314
	  if (u == NULL)
-
 
2315
	    for (u = unit->next_unit; u != NULL; u = u->next_unit)
-
 
2316
	      if (info_ptr >= u->info_ptr_unit && info_ptr < u->end_ptr)
-
 
2317
		break;
-
 
2318
 
-
 
2319
	  if (u)
-
 
2320
	    unit = u;
-
 
2321
	  /* else FIXME: What do we do now ?  */
2128
      info_ptr = unit->sec_info_ptr + die_ref;
2322
	}
2129
    }
2323
    }
2130
  else if (attr_ptr->form == DW_FORM_GNU_ref_alt)
2324
  else if (attr_ptr->form == DW_FORM_GNU_ref_alt)
2131
    {
2325
    {
2132
      info_ptr = read_alt_indirect_ref (unit, die_ref);
2326
      info_ptr = read_alt_indirect_ref (unit, die_ref);
2133
      if (info_ptr == NULL)
2327
      if (info_ptr == NULL)
2134
	{
2328
	{
2135
	  (*_bfd_error_handler)
2329
	  (*_bfd_error_handler)
2136
	    (_("Dwarf Error: Unable to read alt ref %u."), die_ref);
2330
	    (_("Dwarf Error: Unable to read alt ref %u."), die_ref);
2137
	  bfd_set_error (bfd_error_bad_value);
2331
	  bfd_set_error (bfd_error_bad_value);
2138
	  return name;
2332
	  return NULL;
-
 
2333
	}
-
 
2334
      info_ptr_end = unit->stash->alt_dwarf_info_buffer + unit->stash->alt_dwarf_info_size;
-
 
2335
 
-
 
2336
      /* FIXME: Do we need to locate the correct CU, in a similar
2139
	}
2337
	 fashion to the code in the DW_FORM_ref_addr case above ?  */
2140
    }
2338
    }
-
 
2339
  else
2141
  else
2340
    {
-
 
2341
    info_ptr = unit->info_ptr_unit + die_ref;
-
 
2342
      info_ptr_end = unit->end_ptr;
Line 2142... Line 2343...
2142
    info_ptr = unit->info_ptr_unit + die_ref;
2343
    }
2143
 
2344
 
Line 2144... Line 2345...
2144
  abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2345
  abbrev_number = safe_read_leb128 (abfd, info_ptr, &bytes_read, FALSE, info_ptr_end);
2145
  info_ptr += bytes_read;
2346
  info_ptr += bytes_read;
2146
 
2347
 
Line 2156... Line 2357...
2156
      else
2357
      else
2157
	{
2358
	{
2158
	  for (i = 0; i < abbrev->num_attrs; ++i)
2359
	  for (i = 0; i < abbrev->num_attrs; ++i)
2159
	    {
2360
	    {
2160
	      info_ptr = read_attribute (&attr, &abbrev->attrs[i], unit,
2361
	      info_ptr = read_attribute (&attr, &abbrev->attrs[i], unit,
2161
					 info_ptr);
2362
					 info_ptr, info_ptr_end);
2162
	      if (info_ptr == NULL)
2363
	      if (info_ptr == NULL)
2163
		break;
2364
		break;
2164
	      switch (attr.name)
2365
	      switch (attr.name)
2165
		{
2366
		{
2166
		case DW_AT_name:
2367
		case DW_AT_name:
2167
		  /* Prefer DW_AT_MIPS_linkage_name or DW_AT_linkage_name
2368
		  /* Prefer DW_AT_MIPS_linkage_name or DW_AT_linkage_name
2168
		     over DW_AT_name.  */
2369
		     over DW_AT_name.  */
2169
		  if (name == NULL)
2370
		  if (name == NULL && is_str_attr (attr.form))
-
 
2371
		    {
2170
		    name = attr.u.str;
2372
		    name = attr.u.str;
-
 
2373
		      if (non_mangled (unit->lang))
-
 
2374
			*is_linkage = TRUE;
-
 
2375
		    }
2171
		  break;
2376
		  break;
2172
		case DW_AT_specification:
2377
		case DW_AT_specification:
2173
		  name = find_abstract_instance_name (unit, &attr);
2378
		  name = find_abstract_instance_name (unit, &attr, is_linkage);
2174
		  break;
2379
		  break;
2175
		case DW_AT_linkage_name:
2380
		case DW_AT_linkage_name:
2176
		case DW_AT_MIPS_linkage_name:
2381
		case DW_AT_MIPS_linkage_name:
-
 
2382
		  /* PR 16949:  Corrupt debug info can place
-
 
2383
		     non-string forms into these attributes.  */
-
 
2384
		  if (is_str_attr (attr.form))
-
 
2385
		    {
2177
		  name = attr.u.str;
2386
		  name = attr.u.str;
-
 
2387
		      *is_linkage = TRUE;
-
 
2388
		    }
2178
		  break;
2389
		  break;
2179
		default:
2390
		default:
2180
		  break;
2391
		  break;
2181
		}
2392
		}
2182
	    }
2393
	    }
Line 2188... Line 2399...
2188
static bfd_boolean
2399
static bfd_boolean
2189
read_rangelist (struct comp_unit *unit, struct arange *arange,
2400
read_rangelist (struct comp_unit *unit, struct arange *arange,
2190
		bfd_uint64_t offset)
2401
		bfd_uint64_t offset)
2191
{
2402
{
2192
  bfd_byte *ranges_ptr;
2403
  bfd_byte *ranges_ptr;
-
 
2404
  bfd_byte *ranges_end;
2193
  bfd_vma base_address = unit->base_address;
2405
  bfd_vma base_address = unit->base_address;
Line 2194... Line 2406...
2194
 
2406
 
2195
  if (! unit->stash->dwarf_ranges_buffer)
2407
  if (! unit->stash->dwarf_ranges_buffer)
2196
    {
2408
    {
2197
      if (! read_debug_ranges (unit))
2409
      if (! read_debug_ranges (unit))
2198
	return FALSE;
2410
	return FALSE;
-
 
2411
    }
2199
    }
2412
 
-
 
2413
  ranges_ptr = unit->stash->dwarf_ranges_buffer + offset;
-
 
2414
  if (ranges_ptr < unit->stash->dwarf_ranges_buffer)
-
 
2415
    return FALSE;
Line 2200... Line 2416...
2200
  ranges_ptr = unit->stash->dwarf_ranges_buffer + offset;
2416
  ranges_end = unit->stash->dwarf_ranges_buffer + unit->stash->dwarf_ranges_size;
2201
 
2417
 
2202
  for (;;)
2418
  for (;;)
2203
    {
2419
    {
Line -... Line 2420...
-
 
2420
      bfd_vma low_pc;
-
 
2421
      bfd_vma high_pc;
-
 
2422
 
-
 
2423
      /* PR 17512: file: 62cada7d.  */
2204
      bfd_vma low_pc;
2424
      if (ranges_ptr + 2 * unit->addr_size > ranges_end)
2205
      bfd_vma high_pc;
2425
	return FALSE;
2206
 
2426
 
2207
      low_pc = read_address (unit, ranges_ptr);
2427
      low_pc = read_address (unit, ranges_ptr, ranges_end);
Line 2208... Line 2428...
2208
      ranges_ptr += unit->addr_size;
2428
      ranges_ptr += unit->addr_size;
2209
      high_pc = read_address (unit, ranges_ptr);
2429
      high_pc = read_address (unit, ranges_ptr, ranges_end);
2210
      ranges_ptr += unit->addr_size;
2430
      ranges_ptr += unit->addr_size;
Line 2231... Line 2451...
2231
static bfd_boolean
2451
static bfd_boolean
2232
scan_unit_for_symbols (struct comp_unit *unit)
2452
scan_unit_for_symbols (struct comp_unit *unit)
2233
{
2453
{
2234
  bfd *abfd = unit->abfd;
2454
  bfd *abfd = unit->abfd;
2235
  bfd_byte *info_ptr = unit->first_child_die_ptr;
2455
  bfd_byte *info_ptr = unit->first_child_die_ptr;
-
 
2456
  bfd_byte *info_ptr_end = unit->stash->info_ptr_end;
2236
  int nesting_level = 1;
2457
  int nesting_level = 1;
2237
  struct funcinfo **nested_funcs;
2458
  struct funcinfo **nested_funcs;
2238
  int nested_funcs_size;
2459
  int nested_funcs_size;
Line 2239... Line 2460...
2239
 
2460
 
Line 2255... Line 2476...
2255
      struct varinfo *var;
2476
      struct varinfo *var;
2256
      bfd_vma low_pc = 0;
2477
      bfd_vma low_pc = 0;
2257
      bfd_vma high_pc = 0;
2478
      bfd_vma high_pc = 0;
2258
      bfd_boolean high_pc_relative = FALSE;
2479
      bfd_boolean high_pc_relative = FALSE;
Line -... Line 2480...
-
 
2480
 
-
 
2481
      /* PR 17512: file: 9f405d9d.  */
-
 
2482
      if (info_ptr >= info_ptr_end)
-
 
2483
	goto fail;
2259
 
2484
 
2260
      abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2485
      abbrev_number = safe_read_leb128 (abfd, info_ptr, &bytes_read, FALSE, info_ptr_end);
Line 2261... Line 2486...
2261
      info_ptr += bytes_read;
2486
      info_ptr += bytes_read;
2262
 
2487
 
2263
      if (! abbrev_number)
2488
      if (! abbrev_number)
Line 2319... Line 2544...
2319
	  nested_funcs[nesting_level] = 0;
2544
	  nested_funcs[nesting_level] = 0;
2320
	}
2545
	}
Line 2321... Line 2546...
2321
 
2546
 
2322
      for (i = 0; i < abbrev->num_attrs; ++i)
2547
      for (i = 0; i < abbrev->num_attrs; ++i)
2323
	{
2548
	{
2324
	  info_ptr = read_attribute (&attr, &abbrev->attrs[i], unit, info_ptr);
2549
	  info_ptr = read_attribute (&attr, &abbrev->attrs[i], unit, info_ptr, info_ptr_end);
2325
	  if (info_ptr == NULL)
2550
	  if (info_ptr == NULL)
Line 2326... Line 2551...
2326
	    goto fail;
2551
	    goto fail;
2327
 
2552
 
Line 2338... Line 2563...
2338
		  func->caller_line = attr.u.val;
2563
		  func->caller_line = attr.u.val;
2339
		  break;
2564
		  break;
Line 2340... Line 2565...
2340
 
2565
 
2341
		case DW_AT_abstract_origin:
2566
		case DW_AT_abstract_origin:
2342
		case DW_AT_specification:
2567
		case DW_AT_specification:
-
 
2568
		  func->name = find_abstract_instance_name (unit, &attr,
2343
		  func->name = find_abstract_instance_name (unit, &attr);
2569
							    &func->is_linkage);
Line 2344... Line 2570...
2344
		  break;
2570
		  break;
2345
 
2571
 
2346
		case DW_AT_name:
2572
		case DW_AT_name:
2347
		  /* Prefer DW_AT_MIPS_linkage_name or DW_AT_linkage_name
2573
		  /* Prefer DW_AT_MIPS_linkage_name or DW_AT_linkage_name
-
 
2574
		     over DW_AT_name.  */
2348
		     over DW_AT_name.  */
2575
		  if (func->name == NULL && is_str_attr (attr.form))
-
 
2576
		    {
-
 
2577
		    func->name = attr.u.str;
-
 
2578
		      if (non_mangled (unit->lang))
2349
		  if (func->name == NULL)
2579
			func->is_linkage = TRUE;
Line 2350... Line 2580...
2350
		    func->name = attr.u.str;
2580
		    }
2351
		  break;
2581
		  break;
-
 
2582
 
-
 
2583
		case DW_AT_linkage_name:
-
 
2584
		case DW_AT_MIPS_linkage_name:
-
 
2585
		  /* PR 16949:  Corrupt debug info can place
2352
 
2586
		     non-string forms into these attributes.  */
-
 
2587
		  if (is_str_attr (attr.form))
-
 
2588
		    {
2353
		case DW_AT_linkage_name:
2589
		  func->name = attr.u.str;
Line 2354... Line 2590...
2354
		case DW_AT_MIPS_linkage_name:
2590
		      func->is_linkage = TRUE;
2355
		  func->name = attr.u.str;
2591
		    }
2356
		  break;
2592
		  break;
Line 2506... Line 2742...
2506
  bfd_vma low_pc = 0;
2742
  bfd_vma low_pc = 0;
2507
  bfd_vma high_pc = 0;
2743
  bfd_vma high_pc = 0;
2508
  bfd *abfd = stash->bfd_ptr;
2744
  bfd *abfd = stash->bfd_ptr;
2509
  bfd_boolean high_pc_relative = FALSE;
2745
  bfd_boolean high_pc_relative = FALSE;
Line 2510... Line 2746...
2510
 
2746
 
2511
  version = read_2_bytes (abfd, info_ptr);
2747
  version = read_2_bytes (abfd, info_ptr, end_ptr);
2512
  info_ptr += 2;
2748
  info_ptr += 2;
2513
  BFD_ASSERT (offset_size == 4 || offset_size == 8);
2749
  BFD_ASSERT (offset_size == 4 || offset_size == 8);
2514
  if (offset_size == 4)
2750
  if (offset_size == 4)
2515
    abbrev_offset = read_4_bytes (abfd, info_ptr);
2751
    abbrev_offset = read_4_bytes (abfd, info_ptr, end_ptr);
2516
  else
2752
  else
2517
    abbrev_offset = read_8_bytes (abfd, info_ptr);
2753
    abbrev_offset = read_8_bytes (abfd, info_ptr, end_ptr);
2518
  info_ptr += offset_size;
2754
  info_ptr += offset_size;
2519
  addr_size = read_1_byte (abfd, info_ptr);
2755
  addr_size = read_1_byte (abfd, info_ptr, end_ptr);
Line 2520... Line 2756...
2520
  info_ptr += 1;
2756
  info_ptr += 1;
2521
 
2757
 
2522
  if (version != 2 && version != 3 && version != 4)
2758
  if (version != 2 && version != 3 && version != 4)
Line 2551... Line 2787...
2551
  /* Read the abbrevs for this compilation unit into a table.  */
2787
  /* Read the abbrevs for this compilation unit into a table.  */
2552
  abbrevs = read_abbrevs (abfd, abbrev_offset, stash);
2788
  abbrevs = read_abbrevs (abfd, abbrev_offset, stash);
2553
  if (! abbrevs)
2789
  if (! abbrevs)
2554
    return 0;
2790
    return 0;
Line 2555... Line 2791...
2555
 
2791
 
2556
  abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2792
  abbrev_number = safe_read_leb128 (abfd, info_ptr, &bytes_read, FALSE, end_ptr);
2557
  info_ptr += bytes_read;
2793
  info_ptr += bytes_read;
2558
  if (! abbrev_number)
2794
  if (! abbrev_number)
2559
    {
2795
    {
2560
      (*_bfd_error_handler) (_("Dwarf Error: Bad abbrev number: %u."),
2796
      (*_bfd_error_handler) (_("Dwarf Error: Bad abbrev number: %u."),
Line 2586... Line 2822...
2586
  unit->info_ptr_unit = info_ptr_unit;
2822
  unit->info_ptr_unit = info_ptr_unit;
2587
  unit->sec_info_ptr = stash->sec_info_ptr;
2823
  unit->sec_info_ptr = stash->sec_info_ptr;
Line 2588... Line 2824...
2588
 
2824
 
2589
  for (i = 0; i < abbrev->num_attrs; ++i)
2825
  for (i = 0; i < abbrev->num_attrs; ++i)
2590
    {
2826
    {
2591
      info_ptr = read_attribute (&attr, &abbrev->attrs[i], unit, info_ptr);
2827
      info_ptr = read_attribute (&attr, &abbrev->attrs[i], unit, info_ptr, end_ptr);
2592
      if (info_ptr == NULL)
2828
      if (info_ptr == NULL)
Line 2593... Line 2829...
2593
	return NULL;
2829
	return NULL;
2594
 
2830
 
Line 2625... Line 2861...
2625
	  break;
2861
	  break;
Line 2626... Line 2862...
2626
 
2862
 
2627
	case DW_AT_comp_dir:
2863
	case DW_AT_comp_dir:
2628
	  {
2864
	  {
-
 
2865
	    char *comp_dir = attr.u.str;
-
 
2866
 
-
 
2867
	    /* PR 17512: file: 1fe726be.  */
-
 
2868
	    if (! is_str_attr (attr.form))
-
 
2869
	      {
-
 
2870
		(*_bfd_error_handler)
-
 
2871
		  (_("Dwarf Error: DW_AT_comp_dir attribute encountered with a non-string form."));
-
 
2872
		comp_dir = NULL;
-
 
2873
	      }
2629
	    char *comp_dir = attr.u.str;
2874
 
2630
	    if (comp_dir)
2875
	    if (comp_dir)
2631
	      {
2876
	      {
2632
		/* Irix 6.2 native cc prepends .: to the compilation
2877
		/* Irix 6.2 native cc prepends .: to the compilation
2633
		   directory, get rid of it.  */
2878
		   directory, get rid of it.  */
Line 2638... Line 2883...
2638
	      }
2883
	      }
2639
	    unit->comp_dir = comp_dir;
2884
	    unit->comp_dir = comp_dir;
2640
	    break;
2885
	    break;
2641
	  }
2886
	  }
Line -... Line 2887...
-
 
2887
 
-
 
2888
	case DW_AT_language:
-
 
2889
	  unit->lang = attr.u.val;
-
 
2890
	  break;
2642
 
2891
 
2643
	default:
2892
	default:
2644
	  break;
2893
	  break;
2645
	}
2894
	}
2646
    }
2895
    }
Line 2682... Line 2931...
2682
  return FALSE;
2931
  return FALSE;
2683
}
2932
}
Line 2684... Line 2933...
2684
 
2933
 
2685
/* If UNIT contains ADDR, set the output parameters to the values for
2934
/* If UNIT contains ADDR, set the output parameters to the values for
2686
   the line containing ADDR.  The output parameters, FILENAME_PTR,
2935
   the line containing ADDR.  The output parameters, FILENAME_PTR,
2687
   FUNCTIONNAME_PTR, and LINENUMBER_PTR, are pointers to the objects
2936
   FUNCTION_PTR, and LINENUMBER_PTR, are pointers to the objects
Line 2688... Line 2937...
2688
   to be filled in.
2937
   to be filled in.
2689
 
2938
 
Line 2690... Line 2939...
2690
   Return TRUE if UNIT contains ADDR, and no errors were encountered;
2939
   Returns the range of addresses covered by the entry that was used
2691
   FALSE otherwise.  */
2940
   to fill in *LINENUMBER_PTR or 0 if it was not filled in.  */
2692
 
2941
 
2693
static bfd_boolean
2942
static bfd_vma
2694
comp_unit_find_nearest_line (struct comp_unit *unit,
2943
comp_unit_find_nearest_line (struct comp_unit *unit,
2695
			     bfd_vma addr,
2944
			     bfd_vma addr,
2696
			     const char **filename_ptr,
2945
			     const char **filename_ptr,
2697
			     const char **functionname_ptr,
2946
			     struct funcinfo **function_ptr,
2698
			     unsigned int *linenumber_ptr,
2947
			     unsigned int *linenumber_ptr,
2699
			     unsigned int *discriminator_ptr,
-
 
2700
			     struct dwarf2_debug *stash)
2948
			     unsigned int *discriminator_ptr,
2701
{
-
 
Line 2702... Line 2949...
2702
  bfd_boolean line_p;
2949
			     struct dwarf2_debug *stash)
2703
  bfd_boolean func_p;
2950
{
Line 2704... Line 2951...
2704
  struct funcinfo *function;
2951
  bfd_boolean func_p;
Line 2728... Line 2975...
2728
	  unit->error = 1;
2975
	  unit->error = 1;
2729
	  return FALSE;
2976
	  return FALSE;
2730
	}
2977
	}
2731
    }
2978
    }
Line 2732... Line 2979...
2732
 
2979
 
2733
  function = NULL;
2980
  *function_ptr = NULL;
2734
  func_p = lookup_address_in_function_table (unit, addr,
-
 
2735
					     &function, functionname_ptr);
2981
  func_p = lookup_address_in_function_table (unit, addr, function_ptr);
2736
  if (func_p && (function->tag == DW_TAG_inlined_subroutine))
2982
  if (func_p && (*function_ptr)->tag == DW_TAG_inlined_subroutine)
-
 
2983
    stash->inliner_chain = *function_ptr;
2737
    stash->inliner_chain = function;
2984
 
2738
  line_p = lookup_address_in_line_info_table (unit->line_table, addr,
2985
  return lookup_address_in_line_info_table (unit->line_table, addr,
2739
					      filename_ptr,
2986
					      filename_ptr,
2740
					      linenumber_ptr,
2987
					      linenumber_ptr,
2741
					      discriminator_ptr);
-
 
2742
  return line_p || func_p;
2988
					      discriminator_ptr);
Line 2743... Line 2989...
2743
}
2989
}
2744
 
2990
 
2745
/* Check to see if line info is already decoded in a comp_unit.
2991
/* Check to see if line info is already decoded in a comp_unit.
Line 2960... Line 3206...
2960
    }
3206
    }
Line 2961... Line 3207...
2961
 
3207
 
2962
  return NULL;
3208
  return NULL;
Line -... Line 3209...
-
 
3209
}
-
 
3210
 
-
 
3211
/* Transfer VMAs from object file to separate debug file.  */
-
 
3212
 
-
 
3213
static void
-
 
3214
set_debug_vma (bfd *orig_bfd, bfd *debug_bfd)
-
 
3215
{
-
 
3216
  asection *s, *d;
-
 
3217
 
-
 
3218
  for (s = orig_bfd->sections, d = debug_bfd->sections;
-
 
3219
       s != NULL && d != NULL;
-
 
3220
       s = s->next, d = d->next)
-
 
3221
    {
-
 
3222
      if ((d->flags & SEC_DEBUGGING) != 0)
-
 
3223
	break;
-
 
3224
      /* ??? Assumes 1-1 correspondence between sections in the
-
 
3225
	 two files.  */
-
 
3226
      if (strcmp (s->name, d->name) == 0)
-
 
3227
	{
-
 
3228
	  d->output_section = s->output_section;
-
 
3229
	  d->output_offset = s->output_offset;
-
 
3230
	  d->vma = s->vma;
-
 
3231
	}
-
 
3232
    }
2963
}
3233
}
Line 2964... Line 3234...
2964
 
3234
 
2965
/* Unset vmas for adjusted sections in STASH.  */
3235
/* Unset vmas for adjusted sections in STASH.  */
2966
 
3236
 
2967
static void
3237
static void
2968
unset_sections (struct dwarf2_debug *stash)
3238
unset_sections (struct dwarf2_debug *stash)
Line 2969... Line 3239...
2969
{
3239
{
2970
  unsigned int i;
3240
  int i;
2971
  struct adjusted_section *p;
3241
  struct adjusted_section *p;
2972
 
3242
 
2973
  i = stash->adjusted_section_count;
3243
  i = stash->adjusted_section_count;
Line 2974... Line 3244...
2974
  p = stash->adjusted_sections;
3244
  p = stash->adjusted_sections;
-
 
3245
  for (; i > 0; i--, p++)
-
 
3246
    p->section->vma = 0;
-
 
3247
}
-
 
3248
 
-
 
3249
/* Set VMAs for allocated and .debug_info sections in ORIG_BFD, a
-
 
3250
   relocatable object file.  VMAs are normally all zero in relocatable
-
 
3251
   object files, so if we want to distinguish locations in sections by
2975
  for (; i > 0; i--, p++)
3252
   address we need to set VMAs so the sections do not overlap.  We
Line 2976... Line 3253...
2976
    p->section->vma = 0;
3253
   also set VMA on .debug_info so that when we have multiple
2977
}
3254
   .debug_info sections (or the linkonce variant) they also do not
2978
 
3255
   overlap.  The multiple .debug_info sections make up a single
-
 
3256
   logical section.  ??? We should probably do the same for other
2979
/* Set unique VMAs for loadable and DWARF sections in ABFD and save
3257
   debug sections.  */
2980
   VMAs in STASH for unset_sections.  */
3258
 
-
 
3259
static bfd_boolean
Line 2981... Line 3260...
2981
 
3260
place_sections (bfd *orig_bfd, struct dwarf2_debug *stash)
2982
static bfd_boolean
3261
{
2983
place_sections (bfd *abfd, struct dwarf2_debug *stash)
3262
  bfd *abfd;
2984
{
3263
  struct adjusted_section *p;
2985
  struct adjusted_section *p;
3264
  int i;
2986
  unsigned int i;
3265
  const char *debug_info_name;
-
 
3266
 
2987
 
3267
  if (stash->adjusted_section_count != 0)
2988
  if (stash->adjusted_section_count != 0)
-
 
2989
    {
-
 
2990
      i = stash->adjusted_section_count;
-
 
2991
      p = stash->adjusted_sections;
-
 
2992
      for (; i > 0; i--, p++)
-
 
2993
	p->section->vma = p->adj_vma;
-
 
Line 2994... Line 3268...
2994
    }
3268
    {
2995
  else
3269
      i = stash->adjusted_section_count;
-
 
3270
      p = stash->adjusted_sections;
-
 
3271
      for (; i > 0; i--, p++)
-
 
3272
	p->section->vma = p->adj_vma;
-
 
3273
      return TRUE;
-
 
3274
    }
2996
    {
3275
 
2997
      asection *sect;
3276
  debug_info_name = stash->debug_sections[debug_info].uncompressed_name;
2998
      bfd_vma last_vma = 0, last_dwarf = 0;
-
 
2999
      bfd_size_type amt;
3277
  i = 0;
Line -... Line 3278...
-
 
3278
  abfd = orig_bfd;
-
 
3279
  while (1)
-
 
3280
    {
3000
      const char *debug_info_name;
3281
      asection *sect;
3001
 
3282
 
Line 3002... Line -...
3002
      debug_info_name = stash->debug_sections[debug_info].uncompressed_name;
-
 
3003
      i = 0;
-
 
3004
      for (sect = abfd->sections; sect != NULL; sect = sect->next)
-
 
3005
	{
3283
      for (sect = abfd->sections; sect != NULL; sect = sect->next)
3006
	  bfd_size_type sz;
-
 
3007
	  int is_debug_info;
3284
	{
3008
 
-
 
3009
	  if (sect->vma != 0)
-
 
3010
	    continue;
-
 
3011
 
-
 
3012
	  /* We need to adjust the VMAs of any .debug_info sections.
-
 
3013
	     Skip compressed ones, since no relocations could target
-
 
Line 3014... Line 3285...
3014
	     them - they should not appear in object files anyway.  */
3285
	  int is_debug_info;
3015
	  if (strcmp (sect->name, debug_info_name) == 0)
3286
 
3016
	    is_debug_info = 1;
3287
	  if ((sect->output_section != NULL
Line 3017... Line 3288...
3017
	  else if (CONST_STRNEQ (sect->name, GNU_LINKONCE_INFO))
3288
	       && sect->output_section != sect
3018
	    is_debug_info = 1;
3289
	       && (sect->flags & SEC_DEBUGGING) == 0)
-
 
3290
	      || sect->vma != 0)
-
 
3291
	    continue;
-
 
3292
 
-
 
3293
	  is_debug_info = (strcmp (sect->name, debug_info_name) == 0
Line -... Line 3294...
-
 
3294
			   || CONST_STRNEQ (sect->name, GNU_LINKONCE_INFO));
-
 
3295
 
-
 
3296
	  if (!((sect->flags & SEC_ALLOC) != 0 && abfd == orig_bfd)
-
 
3297
	      && !is_debug_info)
-
 
3298
	    continue;
3019
	  else
3299
 
-
 
3300
	  i++;
3020
	    is_debug_info = 0;
3301
	}
3021
 
3302
      if (abfd == stash->bfd_ptr)
3022
	  if (!is_debug_info && (sect->flags & SEC_LOAD) == 0)
3303
	break;
Line 3023... Line 3304...
3023
	    continue;
3304
      abfd = stash->bfd_ptr;
3024
 
3305
    }
Line -... Line 3306...
-
 
3306
 
-
 
3307
  if (i <= 1)
-
 
3308
    stash->adjusted_section_count = -1;
-
 
3309
  else
-
 
3310
    {
3025
	  sz = sect->rawsize ? sect->rawsize : sect->size;
3311
      bfd_vma last_vma = 0, last_dwarf = 0;
3026
	  if (sz == 0)
3312
      bfd_size_type amt = i * sizeof (struct adjusted_section);
3027
	    continue;
3313
 
3028
 
3314
      p = (struct adjusted_section *) bfd_malloc (amt);
Line -... Line 3315...
-
 
3315
      if (p == NULL)
-
 
3316
	return FALSE;
-
 
3317
 
3029
	  i++;
3318
      stash->adjusted_sections = p;
3030
	}
3319
      stash->adjusted_section_count = i;
Line 3031... Line -...
3031
 
-
 
3032
      amt = i * sizeof (struct adjusted_section);
-
 
3033
      p = (struct adjusted_section *) bfd_alloc (abfd, amt);
-
 
3034
      if (! p)
3320
 
3035
	return FALSE;
-
 
3036
 
3321
      abfd = orig_bfd;
3037
      stash->adjusted_sections = p;
-
 
3038
      stash->adjusted_section_count = i;
-
 
3039
 
-
 
Line 3040... Line 3322...
3040
      for (sect = abfd->sections; sect != NULL; sect = sect->next)
3322
      while (1)
-
 
3323
	{
3041
	{
3324
	  asection *sect;
Line 3042... Line 3325...
3042
	  bfd_size_type sz;
3325
 
3043
	  int is_debug_info;
-
 
3044
 
-
 
Line 3045... Line -...
3045
	  if (sect->vma != 0)
-
 
3046
	    continue;
3326
      for (sect = abfd->sections; sect != NULL; sect = sect->next)
3047
 
3327
	{
3048
	  /* We need to adjust the VMAs of any .debug_info sections.
3328
	  bfd_size_type sz;
3049
	     Skip compressed ones, since no relocations could target
3329
	  int is_debug_info;
3050
	     them - they should not appear in object files anyway.  */
3330
 
3051
	  if (strcmp (sect->name, debug_info_name) == 0)
3331
	      if ((sect->output_section != NULL
3052
	    is_debug_info = 1;
3332
		   && sect->output_section != sect
3053
	  else if (CONST_STRNEQ (sect->name, GNU_LINKONCE_INFO))
3333
		   && (sect->flags & SEC_DEBUGGING) == 0)
3054
	    is_debug_info = 1;
3334
		  || sect->vma != 0)
3055
	  else
3335
	    continue;
3056
	    is_debug_info = 0;
3336
 
3057
 
3337
	      is_debug_info = (strcmp (sect->name, debug_info_name) == 0
3058
	  if (!is_debug_info && (sect->flags & SEC_LOAD) == 0)
3338
			       || CONST_STRNEQ (sect->name, GNU_LINKONCE_INFO));
3059
	    continue;
3339
 
3060
 
3340
	      if (!((sect->flags & SEC_ALLOC) != 0 && abfd == orig_bfd)
3061
	  sz = sect->rawsize ? sect->rawsize : sect->size;
3341
		  && !is_debug_info)
3062
	  if (sz == 0)
-
 
3063
	    continue;
-
 
Line -... Line 3342...
-
 
3342
	    continue;
3064
 
3343
 
3065
	  p->section = sect;
-
 
3066
	  if (is_debug_info)
3344
	  sz = sect->rawsize ? sect->rawsize : sect->size;
3067
	    {
3345
 
-
 
3346
	  if (is_debug_info)
-
 
3347
	    {
-
 
3348
	      BFD_ASSERT (sect->alignment_power == 0);
-
 
3349
	      sect->vma = last_dwarf;
3068
	      BFD_ASSERT (sect->alignment_power == 0);
3350
	      last_dwarf += sz;
Line -... Line 3351...
-
 
3351
	    }
-
 
3352
	      else
-
 
3353
	    {
3069
	      sect->vma = last_dwarf;
3354
	      /* Align the new address to the current section
3070
	      last_dwarf += sz;
3355
		 alignment.  */
Line 3071... Line 3356...
3071
	    }
3356
	      last_vma = ((last_vma
3072
	  else if (last_vma != 0)
3357
			       + ~(-((bfd_vma) 1 << sect->alignment_power)))
Line 3104... Line 3389...
3104
			   const char **filename_ptr,
3389
			   const char **filename_ptr,
3105
			   unsigned int *linenumber_ptr)
3390
			   unsigned int *linenumber_ptr)
3106
{
3391
{
3107
  struct funcinfo* each_func;
3392
  struct funcinfo* each_func;
3108
  struct funcinfo* best_fit = NULL;
3393
  struct funcinfo* best_fit = NULL;
-
 
3394
  bfd_vma best_fit_len = 0;
3109
  struct info_list_node *node;
3395
  struct info_list_node *node;
3110
  struct arange *arange;
3396
  struct arange *arange;
3111
  const char *name = bfd_asymbol_name (sym);
3397
  const char *name = bfd_asymbol_name (sym);
3112
  asection *sec = bfd_get_section (sym);
3398
  asection *sec = bfd_get_section (sym);
Line 3122... Line 3408...
3122
	{
3408
	{
3123
	  if ((!each_func->sec || each_func->sec == sec)
3409
	  if ((!each_func->sec || each_func->sec == sec)
3124
	      && addr >= arange->low
3410
	      && addr >= arange->low
3125
	      && addr < arange->high
3411
	      && addr < arange->high
3126
	      && (!best_fit
3412
	      && (!best_fit
3127
		  || (arange->high - arange->low
3413
		  || arange->high - arange->low < best_fit_len))
3128
		      < best_fit->arange.high - best_fit->arange.low)))
3414
	    {
3129
	    best_fit = each_func;
3415
	    best_fit = each_func;
-
 
3416
	      best_fit_len = arange->high - arange->low;
-
 
3417
	    }
3130
	}
3418
	}
3131
    }
3419
    }
Line 3132... Line 3420...
3132
 
3420
 
3133
  if (best_fit)
3421
  if (best_fit)
Line 3314... Line 3602...
3314
				      filename_ptr, linenumber_ptr);
3602
				      filename_ptr, linenumber_ptr);
3315
  return info_hash_lookup_varinfo (stash->varinfo_hash_table, sym, addr,
3603
  return info_hash_lookup_varinfo (stash->varinfo_hash_table, sym, addr,
3316
				   filename_ptr, linenumber_ptr);
3604
				   filename_ptr, linenumber_ptr);
3317
}
3605
}
Line -... Line 3606...
-
 
3606
 
-
 
3607
/* Save current section VMAs.  */
-
 
3608
 
-
 
3609
static bfd_boolean
-
 
3610
save_section_vma (const bfd *abfd, struct dwarf2_debug *stash)
-
 
3611
{
-
 
3612
  asection *s;
-
 
3613
  unsigned int i;
-
 
3614
 
-
 
3615
  if (abfd->section_count == 0)
-
 
3616
    return TRUE;
-
 
3617
  stash->sec_vma = bfd_malloc (sizeof (*stash->sec_vma) * abfd->section_count);
-
 
3618
  if (stash->sec_vma == NULL)
-
 
3619
    return FALSE;
-
 
3620
  for (i = 0, s = abfd->sections; i < abfd->section_count; i++, s = s->next)
-
 
3621
    {
-
 
3622
      if (s->output_section != NULL)
-
 
3623
	stash->sec_vma[i] = s->output_section->vma + s->output_offset;
-
 
3624
      else
-
 
3625
	stash->sec_vma[i] = s->vma;
-
 
3626
    }
-
 
3627
  return TRUE;
-
 
3628
}
-
 
3629
 
-
 
3630
/* Compare current section VMAs against those at the time the stash
-
 
3631
   was created.  If find_nearest_line is used in linker warnings or
-
 
3632
   errors early in the link process, the debug info stash will be
-
 
3633
   invalid for later calls.  This is because we relocate debug info
-
 
3634
   sections, so the stashed section contents depend on symbol values,
-
 
3635
   which in turn depend on section VMAs.  */
-
 
3636
 
-
 
3637
static bfd_boolean
-
 
3638
section_vma_same (const bfd *abfd, const struct dwarf2_debug *stash)
-
 
3639
{
-
 
3640
  asection *s;
-
 
3641
  unsigned int i;
-
 
3642
 
-
 
3643
  for (i = 0, s = abfd->sections; i < abfd->section_count; i++, s = s->next)
-
 
3644
    {
-
 
3645
      bfd_vma vma;
-
 
3646
 
-
 
3647
      if (s->output_section != NULL)
-
 
3648
	vma = s->output_section->vma + s->output_offset;
-
 
3649
      else
-
 
3650
	vma = s->vma;
-
 
3651
      if (vma != stash->sec_vma[i])
-
 
3652
	return FALSE;
-
 
3653
    }
-
 
3654
  return TRUE;
-
 
3655
}
3318
 
3656
 
3319
/* Read debug information from DEBUG_BFD when DEBUG_BFD is specified.
3657
/* Read debug information from DEBUG_BFD when DEBUG_BFD is specified.
3320
   If DEBUG_BFD is not specified, we read debug information from ABFD
3658
   If DEBUG_BFD is not specified, we read debug information from ABFD
3321
   or its gnu_debuglink. The results will be stored in PINFO.
3659
   or its gnu_debuglink. The results will be stored in PINFO.
Line 3322... Line 3660...
3322
   The function returns TRUE iff debug information is ready.  */
3660
   The function returns TRUE iff debug information is ready.  */
3323
 
3661
 
3324
bfd_boolean
3662
bfd_boolean
3325
_bfd_dwarf2_slurp_debug_info (bfd *abfd, bfd *debug_bfd,
3663
_bfd_dwarf2_slurp_debug_info (bfd *abfd, bfd *debug_bfd,
3326
                              const struct dwarf_debug_section *debug_sections,
3664
                              const struct dwarf_debug_section *debug_sections,
-
 
3665
                              asymbol **symbols,
3327
                              asymbol **symbols,
3666
			      void **pinfo,
3328
                              void **pinfo)
3667
			      bfd_boolean do_place)
3329
{
3668
{
3330
  bfd_size_type amt = sizeof (struct dwarf2_debug);
3669
  bfd_size_type amt = sizeof (struct dwarf2_debug);
3331
  bfd_size_type total_size;
3670
  bfd_size_type total_size;
Line 3332... Line 3671...
3332
  asection *msec;
3671
  asection *msec;
-
 
3672
  struct dwarf2_debug *stash = (struct dwarf2_debug *) *pinfo;
-
 
3673
 
3333
  struct dwarf2_debug *stash = (struct dwarf2_debug *) *pinfo;
3674
  if (stash != NULL)
-
 
3675
    {
-
 
3676
      if (section_vma_same (abfd, stash))
-
 
3677
    return TRUE;
-
 
3678
      _bfd_dwarf2_cleanup_debug_info (abfd, pinfo);
3334
 
3679
      memset (stash, 0, amt);
3335
  if (stash != NULL)
3680
    }
3336
    return TRUE;
3681
  else
3337
 
3682
    {
-
 
3683
  stash = (struct dwarf2_debug *) bfd_zalloc (abfd, amt);
3338
  stash = (struct dwarf2_debug *) bfd_zalloc (abfd, amt);
3684
  if (! stash)
3339
  if (! stash)
3685
    return FALSE;
-
 
3686
    }
-
 
3687
  stash->debug_sections = debug_sections;
Line 3340... Line 3688...
3340
    return FALSE;
3688
  stash->syms = symbols;
Line 3341... Line 3689...
3341
  stash->debug_sections = debug_sections;
3689
  if (!save_section_vma (abfd, stash))
3342
  stash->syms = symbols;
3690
    return FALSE;
Line 3359... Line 3707...
3359
	return FALSE;
3707
	return FALSE;
Line 3360... Line 3708...
3360
 
3708
 
3361
      if ((debug_bfd = bfd_openr (debug_filename, NULL)) == NULL
3709
      if ((debug_bfd = bfd_openr (debug_filename, NULL)) == NULL
3362
	  || ! bfd_check_format (debug_bfd, bfd_object)
3710
	  || ! bfd_check_format (debug_bfd, bfd_object)
3363
	  || (msec = find_debug_info (debug_bfd,
3711
	  || (msec = find_debug_info (debug_bfd,
-
 
3712
				      debug_sections, NULL)) == NULL
3364
				      debug_sections, NULL)) == NULL)
3713
	  || !bfd_generic_link_read_symbols (debug_bfd))
3365
	{
3714
	{
3366
	  if (debug_bfd)
3715
	  if (debug_bfd)
3367
	    bfd_close (debug_bfd);
3716
	    bfd_close (debug_bfd);
3368
	  /* FIXME: Should we report our failure to follow the debuglink ?  */
3717
	  /* FIXME: Should we report our failure to follow the debuglink ?  */
3369
	  free (debug_filename);
3718
	  free (debug_filename);
3370
	  return FALSE;
3719
	  return FALSE;
-
 
3720
	}
-
 
3721
 
-
 
3722
      symbols = bfd_get_outsymbols (debug_bfd);
3371
	}
3723
      stash->syms = symbols;
3372
      stash->close_on_cleanup = TRUE;
3724
      stash->close_on_cleanup = TRUE;
3373
    }
3725
    }
Line -... Line 3726...
-
 
3726
  stash->bfd_ptr = debug_bfd;
-
 
3727
 
-
 
3728
  if (do_place
-
 
3729
      && !place_sections (abfd, stash))
3374
  stash->bfd_ptr = debug_bfd;
3730
    return FALSE;
3375
 
3731
 
3376
  /* There can be more than one DWARF2 info section in a BFD these
3732
  /* There can be more than one DWARF2 info section in a BFD these
3377
     days.  First handle the easy case when there's only one.  If
3733
     days.  First handle the easy case when there's only one.  If
3378
     there's more than one, try case two: none of the sections is
3734
     there's more than one, try case two: none of the sections is
Line 3430... Line 3786...
3430
  stash->sec = find_debug_info (debug_bfd, debug_sections, NULL);
3786
  stash->sec = find_debug_info (debug_bfd, debug_sections, NULL);
3431
  stash->sec_info_ptr = stash->info_ptr;
3787
  stash->sec_info_ptr = stash->info_ptr;
3432
  return TRUE;
3788
  return TRUE;
3433
}
3789
}
Line -... Line 3790...
-
 
3790
 
-
 
3791
/* Scan the debug information in PINFO looking for a DW_TAG_subprogram
-
 
3792
   abbrev with a DW_AT_low_pc attached to it.  Then lookup that same
-
 
3793
   symbol in SYMBOLS and return the difference between the low_pc and
-
 
3794
   the symbol's address.  Returns 0 if no suitable symbol could be found.  */
-
 
3795
 
-
 
3796
bfd_signed_vma
-
 
3797
_bfd_dwarf2_find_symbol_bias (asymbol ** symbols, void ** pinfo)
-
 
3798
{
-
 
3799
  struct dwarf2_debug *stash;
-
 
3800
  struct comp_unit * unit;
-
 
3801
 
-
 
3802
  stash = (struct dwarf2_debug *) *pinfo;
-
 
3803
 
-
 
3804
  if (stash == NULL)
-
 
3805
    return 0;
-
 
3806
 
-
 
3807
  for (unit = stash->all_comp_units; unit; unit = unit->next_unit)
-
 
3808
    {
-
 
3809
      struct funcinfo * func;
-
 
3810
 
-
 
3811
      if (unit->function_table == NULL)
-
 
3812
	{
-
 
3813
	  if (unit->line_table == NULL)
-
 
3814
	    unit->line_table = decode_line_info (unit, stash);
-
 
3815
	  if (unit->line_table != NULL)
-
 
3816
	    scan_unit_for_symbols (unit);
-
 
3817
	}
-
 
3818
 
-
 
3819
      for (func = unit->function_table; func != NULL; func = func->prev_func)
-
 
3820
	if (func->name && func->arange.low)
-
 
3821
	  {
-
 
3822
	    asymbol ** psym;
-
 
3823
 
-
 
3824
	    /* FIXME: Do we need to scan the aranges looking for the lowest pc value ?  */
-
 
3825
 
-
 
3826
	    for (psym = symbols; * psym != NULL; psym++)
-
 
3827
	      {
-
 
3828
		asymbol * sym = * psym;
-
 
3829
 
-
 
3830
		if (sym->flags & BSF_FUNCTION
-
 
3831
		    && sym->section != NULL
-
 
3832
		    && strcmp (sym->name, func->name) == 0)
-
 
3833
		  return ((bfd_signed_vma) func->arange.low) -
-
 
3834
		    ((bfd_signed_vma) (sym->value + sym->section->vma));
-
 
3835
	      }
-
 
3836
	  }
-
 
3837
    }
-
 
3838
 
-
 
3839
  return 0;
-
 
3840
}
3434
 
3841
 
3435
/* Find the source code location of SYMBOL.  If SYMBOL is NULL
3842
/* Find the source code location of SYMBOL.  If SYMBOL is NULL
3436
   then find the nearest source code location corresponding to
3843
   then find the nearest source code location corresponding to
3437
   the address SECTION + OFFSET.
3844
   the address SECTION + OFFSET.
3438
   Returns TRUE if the line is found without error and fills in
3845
   Returns TRUE if the line is found without error and fills in
Line 3442... Line 3849...
3442
   DEBUG_SECTIONS contains the name of the dwarf debug sections.
3849
   DEBUG_SECTIONS contains the name of the dwarf debug sections.
3443
   ADDR_SIZE is the number of bytes in the initial .debug_info length
3850
   ADDR_SIZE is the number of bytes in the initial .debug_info length
3444
   field and in the abbreviation offset, or zero to indicate that the
3851
   field and in the abbreviation offset, or zero to indicate that the
3445
   default value should be used.  */
3852
   default value should be used.  */
Line 3446... Line 3853...
3446
 
3853
 
3447
static bfd_boolean
3854
bfd_boolean
3448
find_line (bfd *abfd,
3855
_bfd_dwarf2_find_nearest_line (bfd *abfd,
-
 
3856
			       asymbol **symbols,
3449
           const struct dwarf_debug_section *debug_sections,
3857
			       asymbol *symbol,
3450
	   asection *section,
3858
	   asection *section,
3451
	   bfd_vma offset,
-
 
3452
	   asymbol *symbol,
-
 
3453
	   asymbol **symbols,
3859
	   bfd_vma offset,
3454
	   const char **filename_ptr,
3860
	   const char **filename_ptr,
3455
	   const char **functionname_ptr,
3861
	   const char **functionname_ptr,
3456
	   unsigned int *linenumber_ptr,
3862
	   unsigned int *linenumber_ptr,
-
 
3863
	   unsigned int *discriminator_ptr,
3457
	   unsigned int *discriminator_ptr,
3864
			       const struct dwarf_debug_section *debug_sections,
3458
	   unsigned int addr_size,
3865
	   unsigned int addr_size,
3459
	   void **pinfo)
3866
	   void **pinfo)
3460
{
3867
{
3461
  /* Read each compilation unit from the section .debug_info, and check
3868
  /* Read each compilation unit from the section .debug_info, and check
Line 3468... Line 3875...
3468
     previously read units before reading more.  */
3875
     previously read units before reading more.  */
3469
  struct dwarf2_debug *stash;
3876
  struct dwarf2_debug *stash;
3470
  /* What address are we looking for?  */
3877
  /* What address are we looking for?  */
3471
  bfd_vma addr;
3878
  bfd_vma addr;
3472
  struct comp_unit* each;
3879
  struct comp_unit* each;
-
 
3880
  struct funcinfo *function = NULL;
3473
  bfd_vma found = FALSE;
3881
  bfd_boolean found = FALSE;
3474
  bfd_boolean do_line;
3882
  bfd_boolean do_line;
Line 3475... Line 3883...
3475
 
3883
 
3476
  *filename_ptr = NULL;
3884
  *filename_ptr = NULL;
3477
  if (functionname_ptr != NULL)
3885
  if (functionname_ptr != NULL)
3478
    *functionname_ptr = NULL;
3886
    *functionname_ptr = NULL;
3479
  *linenumber_ptr = 0;
3887
  *linenumber_ptr = 0;
3480
  if (discriminator_ptr)
3888
  if (discriminator_ptr)
Line 3481... Line 3889...
3481
    *discriminator_ptr = 0;
3889
    *discriminator_ptr = 0;
3482
 
3890
 
-
 
3891
  if (! _bfd_dwarf2_slurp_debug_info (abfd, NULL, debug_sections,
3483
  if (! _bfd_dwarf2_slurp_debug_info (abfd, NULL,
3892
				      symbols, pinfo,
Line 3484... Line 3893...
3484
				      debug_sections, symbols, pinfo))
3893
				      (abfd->flags & (EXEC_P | DYNAMIC)) == 0))
Line 3485... Line -...
3485
    return FALSE;
-
 
3486
 
-
 
3487
  stash = (struct dwarf2_debug *) *pinfo;
-
 
3488
 
-
 
3489
  /* In a relocatable file, 2 functions may have the same address.
-
 
3490
     We change the section vma so that they won't overlap.  */
-
 
3491
  if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0)
-
 
3492
    {
-
 
3493
      if (! place_sections (abfd, stash))
3894
    return FALSE;
3494
	return FALSE;
-
 
3495
    }
-
 
3496
 
-
 
3497
  do_line = (section == NULL
3895
 
3498
	     && offset == 0
3896
  stash = (struct dwarf2_debug *) *pinfo;
3499
	     && functionname_ptr == NULL
3897
 
3500
	     && symbol != NULL);
3898
  do_line = symbol != NULL;
-
 
3899
  if (do_line)
3501
  if (do_line)
3900
    {
3502
    {
-
 
3503
      addr = symbol->value;
-
 
3504
      section = bfd_get_section (symbol);
-
 
3505
    }
-
 
3506
  else if (section != NULL
3901
      BFD_ASSERT (section == NULL && offset == 0 && functionname_ptr == NULL);
-
 
3902
      section = bfd_get_section (symbol);
-
 
3903
      addr = symbol->value;
3507
	   && functionname_ptr != NULL
3904
    }
-
 
3905
  else
Line 3508... Line 3906...
3508
	   && symbol == NULL)
3906
    {
3509
    addr = offset;
3907
      BFD_ASSERT (section != NULL && functionname_ptr != NULL);
3510
  else
3908
    addr = offset;
3511
    abort ();
3909
    }
Line 3558... Line 3956...
3558
	      }
3956
	      }
3559
	}
3957
	}
3560
    }
3958
    }
3561
  else
3959
  else
3562
    {
3960
    {
-
 
3961
      bfd_vma min_range = (bfd_vma) -1;
-
 
3962
      const char * local_filename = NULL;
-
 
3963
      struct funcinfo *local_function = NULL;
-
 
3964
      unsigned int local_linenumber = 0;
-
 
3965
      unsigned int local_discriminator = 0;
-
 
3966
 
3563
      for (each = stash->all_comp_units; each; each = each->next_unit)
3967
      for (each = stash->all_comp_units; each; each = each->next_unit)
3564
	{
3968
	{
-
 
3969
	  bfd_vma range = (bfd_vma) -1;
-
 
3970
 
3565
	  found = ((each->arange.high == 0
3971
	  found = ((each->arange.high == 0
3566
		    || comp_unit_contains_address (each, addr))
3972
		    || comp_unit_contains_address (each, addr))
3567
		   && comp_unit_find_nearest_line (each, addr,
3973
		   && (range = comp_unit_find_nearest_line (each, addr,
3568
						   filename_ptr,
3974
							    & local_filename,
3569
						   functionname_ptr,
3975
							    & local_function,
3570
						   linenumber_ptr,
3976
							    & local_linenumber,
3571
						   discriminator_ptr,
3977
							    & local_discriminator,
3572
						   stash));
3978
							    stash)) != 0);
3573
	  if (found)
3979
	  if (found)
-
 
3980
	    {
-
 
3981
	      /* PRs 15935 15994: Bogus debug information may have provided us
-
 
3982
		 with an erroneous match.  We attempt to counter this by
-
 
3983
		 selecting the match that has the smallest address range
-
 
3984
		 associated with it.  (We are assuming that corrupt debug info
-
 
3985
		 will tend to result in extra large address ranges rather than
-
 
3986
		 extra small ranges).
-
 
3987
 
-
 
3988
		 This does mean that we scan through all of the CUs associated
-
 
3989
		 with the bfd each time this function is called.  But this does
-
 
3990
		 have the benefit of producing consistent results every time the
-
 
3991
		 function is called.  */
-
 
3992
	      if (range <= min_range)
-
 
3993
		{
-
 
3994
		  if (filename_ptr && local_filename)
-
 
3995
		    * filename_ptr = local_filename;
-
 
3996
		  if (local_function)
-
 
3997
		    function = local_function;
-
 
3998
		  if (discriminator_ptr && local_discriminator)
-
 
3999
		    * discriminator_ptr = local_discriminator;
-
 
4000
		  if (local_linenumber)
-
 
4001
		    * linenumber_ptr = local_linenumber;
-
 
4002
		  min_range = range;
-
 
4003
		}
-
 
4004
	    }
-
 
4005
	}
-
 
4006
 
-
 
4007
      if (* linenumber_ptr)
-
 
4008
	{
-
 
4009
	  found = TRUE;
3574
	    goto done;
4010
	    goto done;
3575
	}
4011
	}
3576
    }
4012
    }
Line 3577... Line 4013...
3577
 
4013
 
Line 3587... Line 4023...
3587
    {
4023
    {
3588
      bfd_vma length;
4024
      bfd_vma length;
3589
      unsigned int offset_size = addr_size;
4025
      unsigned int offset_size = addr_size;
3590
      bfd_byte *info_ptr_unit = stash->info_ptr;
4026
      bfd_byte *info_ptr_unit = stash->info_ptr;
Line 3591... Line 4027...
3591
 
4027
 
3592
      length = read_4_bytes (stash->bfd_ptr, stash->info_ptr);
4028
      length = read_4_bytes (stash->bfd_ptr, stash->info_ptr, stash->info_ptr_end);
3593
      /* A 0xffffff length is the DWARF3 way of indicating
4029
      /* A 0xffffff length is the DWARF3 way of indicating
3594
	 we use 64-bit offsets, instead of 32-bit offsets.  */
4030
	 we use 64-bit offsets, instead of 32-bit offsets.  */
3595
      if (length == 0xffffffff)
4031
      if (length == 0xffffffff)
3596
	{
4032
	{
3597
	  offset_size = 8;
4033
	  offset_size = 8;
3598
	  length = read_8_bytes (stash->bfd_ptr, stash->info_ptr + 4);
4034
	  length = read_8_bytes (stash->bfd_ptr, stash->info_ptr + 4, stash->info_ptr_end);
3599
	  stash->info_ptr += 12;
4035
	  stash->info_ptr += 12;
3600
	}
4036
	}
3601
      /* A zero length is the IRIX way of indicating 64-bit offsets,
4037
      /* A zero length is the IRIX way of indicating 64-bit offsets,
3602
	 mostly because the 64-bit length will generally fit in 32
4038
	 mostly because the 64-bit length will generally fit in 32
3603
	 bits, and the endianness helps.  */
4039
	 bits, and the endianness helps.  */
3604
      else if (length == 0)
4040
      else if (length == 0)
3605
	{
4041
	{
3606
	  offset_size = 8;
4042
	  offset_size = 8;
3607
	  length = read_4_bytes (stash->bfd_ptr, stash->info_ptr + 4);
4043
	  length = read_4_bytes (stash->bfd_ptr, stash->info_ptr + 4, stash->info_ptr_end);
3608
	  stash->info_ptr += 8;
4044
	  stash->info_ptr += 8;
3609
	}
4045
	}
3610
      /* In the absence of the hints above, we assume 32-bit DWARF2
4046
      /* In the absence of the hints above, we assume 32-bit DWARF2
3611
	 offsets even for targets with 64-bit addresses, because:
4047
	 offsets even for targets with 64-bit addresses, because:
Line 3624... Line 4060...
3624
      else
4060
      else
3625
	stash->info_ptr += 4;
4061
	stash->info_ptr += 4;
Line 3626... Line 4062...
3626
 
4062
 
3627
      if (length > 0)
4063
      if (length > 0)
-
 
4064
	{
-
 
4065
	  bfd_byte * new_ptr;
3628
	{
4066
 
3629
	  each = parse_comp_unit (stash, length, info_ptr_unit,
4067
	  each = parse_comp_unit (stash, length, info_ptr_unit,
3630
				  offset_size);
4068
				  offset_size);
3631
	  if (!each)
4069
	  if (!each)
3632
	    /* The dwarf information is damaged, don't trust it any
4070
	    /* The dwarf information is damaged, don't trust it any
3633
	       more.  */
4071
	       more.  */
-
 
4072
	    break;
-
 
4073
 
-
 
4074
	  new_ptr = stash->info_ptr + length;
-
 
4075
	  /* PR 17512: file: 1500698c.  */
-
 
4076
	  if (new_ptr < stash->info_ptr)
-
 
4077
	    {
-
 
4078
	      /* A corrupt length value - do not trust the info any more.  */
-
 
4079
	      found = FALSE;
-
 
4080
	      break;
-
 
4081
	    }
3634
	    break;
4082
	  else
Line 3635... Line 4083...
3635
	  stash->info_ptr += length;
4083
	    stash->info_ptr = new_ptr;
3636
 
4084
 
3637
	  if (stash->all_comp_units)
4085
	  if (stash->all_comp_units)
3638
	    stash->all_comp_units->prev_unit = each;
4086
	    stash->all_comp_units->prev_unit = each;
Line 3658... Line 4106...
3658
	  else
4106
	  else
3659
	    found = ((each->arange.high == 0
4107
	    found = ((each->arange.high == 0
3660
		      || comp_unit_contains_address (each, addr))
4108
		      || comp_unit_contains_address (each, addr))
3661
		     && comp_unit_find_nearest_line (each, addr,
4109
		     && comp_unit_find_nearest_line (each, addr,
3662
						     filename_ptr,
4110
						     filename_ptr,
3663
						     functionname_ptr,
4111
						     &function,
3664
						     linenumber_ptr,
4112
						     linenumber_ptr,
3665
						     discriminator_ptr,
4113
						     discriminator_ptr,
3666
						     stash));
4114
						     stash) != 0);
Line 3667... Line 4115...
3667
 
4115
 
3668
	  if ((bfd_vma) (stash->info_ptr - stash->sec_info_ptr)
4116
	  if ((bfd_vma) (stash->info_ptr - stash->sec_info_ptr)
3669
	      == stash->sec->size)
4117
	      == stash->sec->size)
3670
	    {
4118
	    {
Line 3677... Line 4125...
3677
	    goto done;
4125
	    goto done;
3678
	}
4126
	}
3679
    }
4127
    }
Line 3680... Line 4128...
3680
 
4128
 
-
 
4129
 done:
-
 
4130
  if (function)
3681
 done:
4131
    {
-
 
4132
      if (!function->is_linkage)
-
 
4133
	{
3682
  if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0)
4134
	  asymbol *fun;
Line -... Line 4135...
-
 
4135
	  bfd_vma sec_vma;
-
 
4136
 
-
 
4137
	  fun = _bfd_elf_find_function (abfd, symbols, section, offset,
-
 
4138
					*filename_ptr ? NULL : filename_ptr,
-
 
4139
					functionname_ptr);
-
 
4140
	  sec_vma = section->vma;
3683
    unset_sections (stash);
4141
	  if (section->output_section != NULL)
-
 
4142
	    sec_vma = section->output_section->vma + section->output_offset;
-
 
4143
	  if (fun != NULL
-
 
4144
	      && fun->value + sec_vma == function->arange.low)
-
 
4145
	    function->name = *functionname_ptr;
-
 
4146
	  /* Even if we didn't find a linkage name, say that we have
3684
 
4147
	     to stop a repeated search of symbols.  */
3685
  return found;
-
 
3686
}
-
 
3687
 
-
 
3688
/* The DWARF2 version of find_nearest_line.
-
 
3689
   Return TRUE if the line is found without error.  */
-
 
3690
 
-
 
3691
bfd_boolean
-
 
3692
_bfd_dwarf2_find_nearest_line (bfd *abfd,
-
 
3693
                               const struct dwarf_debug_section *debug_sections,
-
 
3694
			       asection *section,
-
 
3695
			       asymbol **symbols,
-
 
3696
			       bfd_vma offset,
4148
	  function->is_linkage = TRUE;
3697
			       const char **filename_ptr,
-
 
3698
			       const char **functionname_ptr,
-
 
3699
			       unsigned int *linenumber_ptr,
-
 
3700
                               unsigned int *discriminator_ptr,
-
 
3701
			       unsigned int addr_size,
-
 
3702
			       void **pinfo)
-
 
3703
{
-
 
3704
  return find_line (abfd, debug_sections, section, offset, NULL, symbols,
-
 
3705
                    filename_ptr, functionname_ptr, linenumber_ptr,
4149
	}
-
 
4150
      *functionname_ptr = function->name;
-
 
4151
    }
Line 3706... Line -...
3706
                    discriminator_ptr, addr_size, pinfo);
-
 
3707
}
-
 
3708
 
-
 
3709
/* The DWARF2 version of find_line.
-
 
3710
   Return TRUE if the line is found without error.  */
-
 
3711
 
-
 
3712
bfd_boolean
-
 
3713
_bfd_dwarf2_find_line (bfd *abfd,
-
 
3714
		       asymbol **symbols,
-
 
3715
		       asymbol *symbol,
-
 
3716
		       const char **filename_ptr,
-
 
3717
		       unsigned int *linenumber_ptr,
4152
  if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0)
3718
                       unsigned int *discriminator_ptr,
-
 
3719
		       unsigned int addr_size,
-
 
3720
		       void **pinfo)
-
 
3721
{
-
 
3722
  return find_line (abfd, dwarf_debug_sections, NULL, 0, symbol, symbols,
4153
    unset_sections (stash);
Line 3723... Line 4154...
3723
                    filename_ptr, NULL, linenumber_ptr, discriminator_ptr,
4154
 
3724
                    addr_size, pinfo);
4155
  return found;
3725
}
4156
}
Line 3826... Line 4257...
3826
    bfd_close (stash->bfd_ptr);
4257
    bfd_close (stash->bfd_ptr);
3827
  if (stash->alt_dwarf_str_buffer)
4258
  if (stash->alt_dwarf_str_buffer)
3828
    free (stash->alt_dwarf_str_buffer);
4259
    free (stash->alt_dwarf_str_buffer);
3829
  if (stash->alt_dwarf_info_buffer)
4260
  if (stash->alt_dwarf_info_buffer)
3830
    free (stash->alt_dwarf_info_buffer);
4261
    free (stash->alt_dwarf_info_buffer);
-
 
4262
  if (stash->sec_vma)
-
 
4263
    free (stash->sec_vma);
-
 
4264
  if (stash->adjusted_sections)
-
 
4265
    free (stash->adjusted_sections);
3831
  if (stash->alt_bfd_ptr)
4266
  if (stash->alt_bfd_ptr)
3832
    bfd_close (stash->alt_bfd_ptr);
4267
    bfd_close (stash->alt_bfd_ptr);
3833
}
4268
}
-
 
4269
 
-
 
4270
/* Find the function to a particular section and offset,
-
 
4271
   for error reporting.  */
-
 
4272
 
-
 
4273
asymbol *
-
 
4274
_bfd_elf_find_function (bfd *abfd,
-
 
4275
			asymbol **symbols,
-
 
4276
			asection *section,
-
 
4277
			bfd_vma offset,
-
 
4278
			const char **filename_ptr,
-
 
4279
			const char **functionname_ptr)
-
 
4280
{
-
 
4281
  struct elf_find_function_cache
-
 
4282
  {
-
 
4283
    asection *last_section;
-
 
4284
    asymbol *func;
-
 
4285
    const char *filename;
-
 
4286
    bfd_size_type func_size;
-
 
4287
  } *cache;
-
 
4288
 
-
 
4289
  if (symbols == NULL)
-
 
4290
    return NULL;
-
 
4291
 
-
 
4292
  if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
-
 
4293
    return NULL;
-
 
4294
 
-
 
4295
  cache = elf_tdata (abfd)->elf_find_function_cache;
-
 
4296
  if (cache == NULL)
-
 
4297
    {
-
 
4298
      cache = bfd_zalloc (abfd, sizeof (*cache));
-
 
4299
      elf_tdata (abfd)->elf_find_function_cache = cache;
-
 
4300
      if (cache == NULL)
-
 
4301
	return NULL;
-
 
4302
    }
-
 
4303
  if (cache->last_section != section
-
 
4304
      || cache->func == NULL
-
 
4305
      || offset < cache->func->value
-
 
4306
      || offset >= cache->func->value + cache->func_size)
-
 
4307
    {
-
 
4308
      asymbol *file;
-
 
4309
      bfd_vma low_func;
-
 
4310
      asymbol **p;
-
 
4311
      /* ??? Given multiple file symbols, it is impossible to reliably
-
 
4312
	 choose the right file name for global symbols.  File symbols are
-
 
4313
	 local symbols, and thus all file symbols must sort before any
-
 
4314
	 global symbols.  The ELF spec may be interpreted to say that a
-
 
4315
	 file symbol must sort before other local symbols, but currently
-
 
4316
	 ld -r doesn't do this.  So, for ld -r output, it is possible to
-
 
4317
	 make a better choice of file name for local symbols by ignoring
-
 
4318
	 file symbols appearing after a given local symbol.  */
-
 
4319
      enum { nothing_seen, symbol_seen, file_after_symbol_seen } state;
-
 
4320
      const struct elf_backend_data *bed = get_elf_backend_data (abfd);
-
 
4321
 
-
 
4322
      file = NULL;
-
 
4323
      low_func = 0;
-
 
4324
      state = nothing_seen;
-
 
4325
      cache->filename = NULL;
-
 
4326
      cache->func = NULL;
-
 
4327
      cache->func_size = 0;
-
 
4328
      cache->last_section = section;
-
 
4329
 
-
 
4330
      for (p = symbols; *p != NULL; p++)
-
 
4331
	{
-
 
4332
	  asymbol *sym = *p;
-
 
4333
	  bfd_vma code_off;
-
 
4334
	  bfd_size_type size;
-
 
4335
 
-
 
4336
	  if ((sym->flags & BSF_FILE) != 0)
-
 
4337
	    {
-
 
4338
	      file = sym;
-
 
4339
	      if (state == symbol_seen)
-
 
4340
		state = file_after_symbol_seen;
-
 
4341
	      continue;
-
 
4342
	    }
-
 
4343
 
-
 
4344
	  size = bed->maybe_function_sym (sym, section, &code_off);
-
 
4345
	  if (size != 0
-
 
4346
	      && code_off <= offset
-
 
4347
	      && (code_off > low_func
-
 
4348
		  || (code_off == low_func
-
 
4349
		      && size > cache->func_size)))
-
 
4350
	    {
-
 
4351
	      cache->func = sym;
-
 
4352
	      cache->func_size = size;
-
 
4353
	      cache->filename = NULL;
-
 
4354
	      low_func = code_off;
-
 
4355
	      if (file != NULL
-
 
4356
		  && ((sym->flags & BSF_LOCAL) != 0
-
 
4357
		      || state != file_after_symbol_seen))
-
 
4358
		cache->filename = bfd_asymbol_name (file);
-
 
4359
	    }
-
 
4360
	  if (state == nothing_seen)
-
 
4361
	    state = symbol_seen;
-
 
4362
	}
-
 
4363
    }
-
 
4364
 
-
 
4365
  if (cache->func == NULL)
-
 
4366
    return NULL;
-
 
4367
 
-
 
4368
  if (filename_ptr)
-
 
4369
    *filename_ptr = cache->filename;
-
 
4370
  if (functionname_ptr)
-
 
4371
    *functionname_ptr = bfd_asymbol_name (cache->func);
-
 
4372
 
-
 
4373
  return cache->func;
-
 
4374
}