aboutsummaryrefslogtreecommitdiff
path: root/gdb/dwarf2read.c
diff options
context:
space:
mode:
authorDoug Evans <dje@google.com>2012-05-22 18:45:22 +0000
committerDoug Evans <dje@google.com>2012-05-22 18:45:22 +0000
commitf664829eae5325405ce4e7f064c7be02352ce1f6 (patch)
tree2cbd8db92d387d8f924b1c6f0fed4e2977ff7e22 /gdb/dwarf2read.c
parentdfc8a1a28522a59bb4d3fc39a843b32469c6f7d5 (diff)
downloadgdb-f664829eae5325405ce4e7f064c7be02352ce1f6.zip
gdb-f664829eae5325405ce4e7f064c7be02352ce1f6.tar.gz
gdb-f664829eae5325405ce4e7f064c7be02352ce1f6.tar.bz2
* dwarf2-frame.c (struct dwarf2_cie): Make initial_instructions, end
"const gdb_byte *". (struct dwarf2_fde): Make instructions, end "const gdb_byte *". (execute_cfa_program): Update to match API of leb128 functions. (read_1_byte, read_4_bytes, read_8_bytes): Make buf parameter "const gdb_byte *". (read_unsigned_leb128, read_signed_leb128): Delete. (read_initial_length): Change type of buf argument to "const gdb_byte *". (read_encoded_value): Update to match API of leb128 functions. (decode_frame_entry): Change result to "const gdb_byte *", and similarly for "start" parameter. (decode_frame_entry_1): Ditto. Use new leb128 reader functions. (dwarf2_build_frame_info): Change local frame_ptr to "const gdb_byte *". * dwarf2expr.c (safe_read_uleb128, safe_read_sleb128): Replaces read_uleb128, read_sleb128. All callers updated. (safe_skip_leb128): New function. (dwarf_block_to_dwarf_reg): Update to match API of leb128 functions. Call gdb_read_uleb128, gdb_skip_leb128 instead of read_uleb128. (dwarf_block_to_dwarf_reg_deref): Update to match API of leb128 functions. Call gdb_read_uleb128, gdb_read_sleb128 instead of read_uleb128, read_sleb128. (dwarf_block_to_fb_offset, dwarf_block_to_sp_offset): Ditto. (execute_stack_op): Update to match API of leb128 functions. * dwarf2expr.h: #include "leb128.h". (read_uleb128, read_sleb128): Delete. (gdb_read_uleb128, gdb_read_sleb128, gdb_skip_leb128): New functions. (safe_read_uleb128, safe_read_sleb128, safe_skip_leb128): Declare. * dwarf2loc.c (debug_loc_kind): New enum. (decode_debug_loc_addresses): New function. (decode_debug_loc_dwo_addresses): New function. (dwarf2_find_location_expression): Rewrite. (dwarf2_compile_expr_to_ax): Update to match API of leb128 functions. (locexpr_describe_location_piece): Ditto. (disassemble_dwarf_expression): Ditto. (locexpr_describe_location_1): Ditto. (loclist_describe_location): Rewrite. * dwarf2loc.h (dwarf2_loclist_baton): New member "from_dwo". * dwarf2read.c (die_reader_specs): New member "buffer_end". (dwarf2_section_buffer_overflow_complaint): Renamed from dwarf2_macros_too_long_complaint. All callers updated. (skip_leb128): Delete. (init_cu_die_reader): Initialize reader->buffer_end. (skip_one_die): Replace call to skip_leb128 with safe_skip_leb128. (skip_form_bytes): New arg buffer_end. All callers updated. Replace call to skip_leb128 with gdb_skip_leb128. (skip_unknown_opcode): New arg mac_end. All callers updated. (fill_in_loclist_baton): Initialize baton->from_dwo.
Diffstat (limited to 'gdb/dwarf2read.c')
-rw-r--r--gdb/dwarf2read.c57
1 files changed, 27 insertions, 30 deletions
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 6ddf236..b590134 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -606,6 +606,9 @@ struct die_reader_specs
/* die_section->buffer. */
gdb_byte *buffer;
+
+ /* The end of the buffer. */
+ const gdb_byte *buffer_end;
};
/* Type of function passed to init_cutu_and_read_dies, et.al. */
@@ -968,11 +971,13 @@ dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2,
}
static void
-dwarf2_macros_too_long_complaint (struct dwarf2_section_info *section)
+dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info *section)
{
complaint (&symfile_complaints,
- _("macro info runs off end of `%s' section"),
- section->asection->name);
+ _("debug info runs off end of %s section"
+ " [in module %s]"),
+ section->asection->name,
+ bfd_get_filename (section->asection->owner));
}
static void
@@ -1104,8 +1109,6 @@ static CORE_ADDR read_addr_index_from_leb128 (struct dwarf2_cu *, gdb_byte *,
static char *read_str_index (const struct die_reader_specs *reader,
struct dwarf2_cu *cu, ULONGEST str_index);
-static gdb_byte *skip_leb128 (bfd *, gdb_byte *);
-
static void set_cu_language (unsigned int, struct dwarf2_cu *);
static struct attribute *dwarf2_attr (struct die_info *, unsigned int,
@@ -3656,6 +3659,7 @@ init_cu_die_reader (struct die_reader_specs *reader,
reader->dwo_file = dwo_file;
reader->die_section = section;
reader->buffer = section->buffer;
+ reader->buffer_end = section->buffer + section->size;
}
/* Find the base address of the compilation unit for range lists and
@@ -5034,6 +5038,8 @@ skip_one_die (const struct die_reader_specs *reader, gdb_byte *info_ptr,
bfd *abfd = reader->abfd;
struct dwarf2_cu *cu = reader->cu;
gdb_byte *buffer = reader->buffer;
+ const gdb_byte *buffer_end = reader->buffer_end;
+ gdb_byte *start_info_ptr = info_ptr;
unsigned int form, i;
for (i = 0; i < abbrev->num_attrs; i++)
@@ -5112,7 +5118,7 @@ skip_one_die (const struct die_reader_specs *reader, gdb_byte *info_ptr,
case DW_FORM_ref_udata:
case DW_FORM_GNU_addr_index:
case DW_FORM_GNU_str_index:
- info_ptr = skip_leb128 (abfd, info_ptr);
+ info_ptr = (gdb_byte *) safe_skip_leb128 (info_ptr, buffer_end);
break;
case DW_FORM_indirect:
form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
@@ -12273,22 +12279,6 @@ read_str_index (const struct die_reader_specs *reader,
return (char *) (sections->str.buffer + str_offset);
}
-/* Return a pointer to just past the end of an LEB128 number in BUF. */
-
-static gdb_byte *
-skip_leb128 (bfd *abfd, gdb_byte *buf)
-{
- int byte;
-
- while (1)
- {
- byte = bfd_get_8 (abfd, buf);
- buf++;
- if ((byte & 128) == 0)
- return buf;
- }
-}
-
/* Return the length of an LEB128 number in BUF. */
static int
@@ -15783,7 +15773,7 @@ parse_macro_definition (struct macro_source_file *file, int line,
Returns the new pointer. */
static gdb_byte *
-skip_form_bytes (bfd *abfd, gdb_byte *bytes,
+skip_form_bytes (bfd *abfd, gdb_byte *bytes, gdb_byte *buffer_end,
enum dwarf_form form,
unsigned int offset_size,
struct dwarf2_section_info *section)
@@ -15838,7 +15828,12 @@ skip_form_bytes (bfd *abfd, gdb_byte *bytes,
case DW_FORM_udata:
case DW_FORM_GNU_addr_index:
case DW_FORM_GNU_str_index:
- bytes = skip_leb128 (abfd, bytes);
+ bytes = (gdb_byte *) gdb_skip_leb128 (bytes, buffer_end);
+ if (bytes == NULL)
+ {
+ dwarf2_section_buffer_overflow_complaint (section);
+ return NULL;
+ }
break;
default:
@@ -15862,7 +15857,7 @@ skip_form_bytes (bfd *abfd, gdb_byte *bytes,
static gdb_byte *
skip_unknown_opcode (unsigned int opcode,
gdb_byte **opcode_definitions,
- gdb_byte *mac_ptr,
+ gdb_byte *mac_ptr, gdb_byte *mac_end,
bfd *abfd,
unsigned int offset_size,
struct dwarf2_section_info *section)
@@ -15885,7 +15880,8 @@ skip_unknown_opcode (unsigned int opcode,
for (i = 0; i < arg; ++i)
{
- mac_ptr = skip_form_bytes (abfd, mac_ptr, defn[i], offset_size, section);
+ mac_ptr = skip_form_bytes (abfd, mac_ptr, mac_end, defn[i], offset_size,
+ section);
if (mac_ptr == NULL)
{
/* skip_form_bytes already issued the complaint. */
@@ -15996,7 +15992,7 @@ dwarf_decode_macro_bytes (bfd *abfd, gdb_byte *mac_ptr, gdb_byte *mac_end,
/* Do we at least have room for a macinfo type byte? */
if (mac_ptr >= mac_end)
{
- dwarf2_macros_too_long_complaint (section);
+ dwarf2_section_buffer_overflow_complaint (section);
break;
}
@@ -16123,7 +16119,7 @@ dwarf_decode_macro_bytes (bfd *abfd, gdb_byte *mac_ptr, gdb_byte *mac_end,
/* Do we at least have room for a macinfo type byte? */
if (mac_ptr >= mac_end)
{
- dwarf2_macros_too_long_complaint (section);
+ dwarf2_section_buffer_overflow_complaint (section);
return;
}
@@ -16191,7 +16187,7 @@ dwarf_decode_macro_bytes (bfd *abfd, gdb_byte *mac_ptr, gdb_byte *mac_end,
default:
mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions,
- mac_ptr, abfd, offset_size,
+ mac_ptr, mac_end, abfd, offset_size,
section);
if (mac_ptr == NULL)
return;
@@ -16334,7 +16330,7 @@ dwarf_decode_macros (struct line_header *lh, unsigned int offset,
default:
mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions,
- mac_ptr, abfd, offset_size,
+ mac_ptr, mac_end, abfd, offset_size,
section);
if (mac_ptr == NULL)
return;
@@ -16450,6 +16446,7 @@ fill_in_loclist_baton (struct dwarf2_cu *cu,
baton->size = section->size - DW_UNSND (attr);
baton->data = section->buffer + DW_UNSND (attr);
baton->base_address = cu->base_address;
+ baton->from_dwo = cu->dwo_unit != NULL;
}
static void