1 --- gdb-5.0.93/gdb/dwarf2read.c.dwarfpatch Thu Jul 5 12:45:48 2001
2 +++ gdb-5.0.93/gdb/dwarf2read.c Mon Nov 12 14:43:15 2001
6 #include "gdb_string.h"
7 +#include "gdb_assert.h"
10 #ifndef DWARF2_REG_TO_REGNUM
12 static char *dwarf_info_buffer;
13 static char *dwarf_abbrev_buffer;
14 static char *dwarf_line_buffer;
15 +static char *dwarf_str_buffer;
17 /* A zeroed version of a partial die for initialization purposes. */
18 static struct partial_die_info zeroed_partial_die;
20 /* Pointer to start of dwarf line buffer for the objfile. */
22 char *dwarf_line_buffer;
24 + /* Pointer to start of dwarf string buffer for the objfile. */
26 + char *dwarf_str_buffer;
28 + /* Size of dwarf string section for the objfile. */
30 + unsigned int dwarf_str_size;
33 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
35 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
36 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
37 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
38 +#define DWARF_STR_BUFFER(p) (PST_PRIVATE(p)->dwarf_str_buffer)
39 +#define DWARF_STR_SIZE(p) (PST_PRIVATE(p)->dwarf_str_size)
41 /* Maintain an array of referenced fundamental types for the current
42 compilation unit being read. For DWARF version 1, we have to construct
45 static char *read_string (bfd *, char *, unsigned int *);
47 +static char *read_indirect_string (bfd *, char *, const struct comp_unit_head *,
50 static unsigned long read_unsigned_leb128 (bfd *, char *, unsigned int *);
52 static long read_signed_leb128 (bfd *, char *, unsigned int *);
54 dwarf2_has_info (bfd *abfd)
56 dwarf_info_offset = dwarf_abbrev_offset = dwarf_line_offset = 0;
57 + dwarf_str_offset = 0;
58 bfd_map_over_sections (abfd, dwarf2_locate_sections, NULL);
59 if (dwarf_info_offset && dwarf_abbrev_offset)
65 + if (dwarf_str_offset)
66 + dwarf_str_buffer = dwarf2_read_section (objfile,
70 + dwarf_str_buffer = NULL;
72 if (mainline || objfile->global_psymbols.size == 0 ||
73 objfile->static_psymbols.size == 0)
76 DWARF_ABBREV_BUFFER (pst) = dwarf_abbrev_buffer;
77 DWARF_ABBREV_SIZE (pst) = dwarf_abbrev_size;
78 DWARF_LINE_BUFFER (pst) = dwarf_line_buffer;
79 + DWARF_STR_BUFFER (pst) = dwarf_str_buffer;
80 + DWARF_STR_SIZE (pst) = dwarf_str_size;
81 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
83 /* Store the function that reads in the rest of the symbol table */
85 dwarf_abbrev_buffer = DWARF_ABBREV_BUFFER (pst);
86 dwarf_abbrev_size = DWARF_ABBREV_SIZE (pst);
87 dwarf_line_buffer = DWARF_LINE_BUFFER (pst);
88 + dwarf_str_buffer = DWARF_STR_BUFFER (pst);
89 + dwarf_str_size = DWARF_STR_SIZE (pst);
90 baseaddr = ANOFFSET (pst->section_offsets, SECT_OFF_TEXT (objfile));
91 cu_header_offset = offset;
92 info_ptr = dwarf_info_buffer + offset;
93 @@ -3358,6 +3385,11 @@
94 DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read);
95 info_ptr += bytes_read;
98 + DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
100 + info_ptr += bytes_read;
103 blk = dwarf_alloc_block ();
104 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
105 @@ -3410,7 +3442,6 @@
106 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
107 info_ptr += bytes_read;
110 case DW_FORM_indirect:
112 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
113 @@ -3600,20 +3631,8 @@
114 /* If the size of a host char is 8 bits, we can return a pointer
115 to the buffer, otherwise we have to copy the data to a buffer
116 allocated on the temporary obstack. */
117 -#if HOST_CHAR_BIT == 8
118 + gdb_assert (HOST_CHAR_BIT == 8);
124 - ret = obstack_alloc (&dwarf2_tmp_obstack, size);
125 - for (i = 0; i < size; ++i)
127 - ret[i] = bfd_get_8 (abfd, (bfd_byte *) buf);
135 @@ -3622,7 +3641,7 @@
136 /* If the size of a host char is 8 bits, we can return a pointer
137 to the string, otherwise we have to copy the string to a buffer
138 allocated on the temporary obstack. */
139 -#if HOST_CHAR_BIT == 8
140 + gdb_assert (HOST_CHAR_BIT == 8);
144 @@ -3630,25 +3649,30 @@
146 *bytes_read_ptr = strlen (buf) + 1;
150 - unsigned int i = 0;
154 +read_indirect_string (bfd *abfd, char *buf,
155 + const struct comp_unit_head *cu_header,
156 + unsigned int *bytes_read_ptr)
158 + LONGEST str_offset = read_offset (abfd, buf, cu_header,
159 + (int *) bytes_read_ptr);
161 - while ((byte = bfd_get_8 (abfd, (bfd_byte *) buf)) != 0)
162 + if (dwarf_str_buffer == NULL)
164 - obstack_1grow (&dwarf2_tmp_obstack, byte);
167 + error ("DW_FORM_strp used without .debug_str section");
171 + if (str_offset >= dwarf_str_size)
173 - *bytes_read_ptr = 1;
174 + error ("DW_FORM_strp pointing outside of .debug_str section");
177 - obstack_1grow (&dwarf2_tmp_obstack, '\0');
178 - *bytes_read_ptr = i + 1;
179 - return obstack_finish (&dwarf2_tmp_obstack);
181 + gdb_assert (HOST_CHAR_BIT == 8);
182 + if (dwarf_str_buffer[str_offset] == '\0')
184 + return dwarf_str_buffer + str_offset;
188 @@ -5552,6 +5576,7 @@
189 fprintf (stderr, "constant: %ld", DW_UNSND (&die->attrs[i]));
193 fprintf (stderr, "string: \"%s\"",
194 DW_STRING (&die->attrs[i])
195 ? DW_STRING (&die->attrs[i]) : "");
196 @@ -5562,8 +5587,6 @@
198 fprintf (stderr, "flag: FALSE");
200 - case DW_FORM_strp: /* we do not support separate string
202 case DW_FORM_indirect: /* we do not handle indirect yet */
204 fprintf (stderr, "unsupported attribute form: %d.",