This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
FYI: DW_FORM_ref_addr -vs- DWARF 3
- From: Tom Tromey <tromey at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Thu, 04 Mar 2010 14:59:52 -0700
- Subject: FYI: DW_FORM_ref_addr -vs- DWARF 3
- Reply-to: tromey at redhat dot com
I'm checking this in. I will probably push it into 7.1 as well; let me
know what you think of this.
DWARF 3 changed DW_FORM_ref_addr to use an offset-sized value instead of
an address-sized value. GDB does not cope with this, which can cause
crashes. For a real-life example:
https://bugzilla.redhat.com/show_bug.cgi?id=552619
I found this in the archives, after writing my patch:
http://sourceware.org/ml/gdb-patches/2006-06/msg00286.html
I guess it was never reviewed? I dunno. Anyway, I prefer my patch.
Built and regression tested on x86-64 (compile farm).
I also verified it before- and after- on the test program I have.
Tom
2010-03-04 Tom Tromey <tromey@redhat.com>
* dwarf2read.c (skip_one_die) <DW_FORM_ref_addr>: Use offset size
in DWARF 3 and later.
(read_attribute_value) <DW_FORM_ref_addr>: Likewise.
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index a05c946..b2558f0 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -2881,8 +2881,15 @@ skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
skip_attribute:
switch (form)
{
- case DW_FORM_addr:
case DW_FORM_ref_addr:
+ /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
+ and later it is offset sized. */
+ if (cu->header.version == 2)
+ info_ptr += cu->header.addr_size;
+ else
+ info_ptr += cu->header.offset_size;
+ break;
+ case DW_FORM_addr:
info_ptr += cu->header.addr_size;
break;
case DW_FORM_data1:
@@ -7016,8 +7023,14 @@ read_attribute_value (struct attribute *attr, unsigned form,
attr->form = form;
switch (form)
{
- case DW_FORM_addr:
case DW_FORM_ref_addr:
+ if (cu->header.version == 2)
+ DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
+ else
+ DW_ADDR (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read);
+ info_ptr += bytes_read;
+ break;
+ case DW_FORM_addr:
DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
info_ptr += bytes_read;
break;