This is the mail archive of the
binutils@sourceware.cygnus.com
mailing list for the binutils project.
Patch 2 to readelf.c
- To: binutils at sourceware dot cygnus dot com
- Subject: Patch 2 to readelf.c
- From: Jason Merrill <jason at cygnus dot com>
- Date: Thu, 6 Apr 2000 17:13:38 -0700
This patch allows us to match up DIE references and DIE definitions;
previously we could only do that for the first compilation unit, at
offset 0.
2000-04-03 Jason Merrill <jason@casey.cygnus.com>
* readelf.c (read_and_display_attr): Add CU offset to references.
(display_debug_info): Pass it in.
Index: readelf.c
===================================================================
RCS file: /cvs/src/src/binutils/readelf.c,v
retrieving revision 1.46
diff -c -p -r1.46 readelf.c
*** readelf.c 2000/03/30 23:37:22 1.46
--- readelf.c 2000/04/07 00:10:32
*************** static char * get_FORM_name
*** 209,215 ****
static void free_abbrevs PARAMS ((void));
static void add_abbrev PARAMS ((unsigned long, unsigned long, int));
static void add_abbrev_attr PARAMS ((unsigned long, unsigned long));
! static unsigned char * read_and_display_attr PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long));
static unsigned char * display_block PARAMS ((unsigned char *, unsigned long));
static void decode_location_expression PARAMS ((unsigned char *, unsigned int));
static void request_dump PARAMS ((unsigned int, char));
--- 209,215 ----
static void free_abbrevs PARAMS ((void));
static void add_abbrev PARAMS ((unsigned long, unsigned long, int));
static void add_abbrev_attr PARAMS ((unsigned long, unsigned long));
! static unsigned char * read_and_display_attr PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long, unsigned long));
static unsigned char * display_block PARAMS ((unsigned char *, unsigned long));
static void decode_location_expression PARAMS ((unsigned char *, unsigned int));
static void request_dump PARAMS ((unsigned int, char));
*************** decode_location_expression (data, pointe
*** 5945,5980 ****
static unsigned char *
! read_and_display_attr (attribute, form, data, pointer_size)
unsigned long attribute;
unsigned long form;
unsigned char * data;
unsigned long pointer_size;
{
unsigned long uvalue = 0;
unsigned char * block_start = NULL;
int bytes_read;
- int is_ref = 0;
printf (" %-18s:", get_AT_name (attribute));
switch (form)
{
case DW_FORM_ref_addr:
- case DW_FORM_ref1:
- case DW_FORM_ref2:
- case DW_FORM_ref4:
- case DW_FORM_ref8:
- case DW_FORM_ref_udata:
- is_ref = 1;
- }
-
- switch (form)
- {
- case DW_FORM_ref_addr:
case DW_FORM_addr:
uvalue = byte_get (data, pointer_size);
- printf (is_ref ? " <%lx>" : " %#lx", uvalue);
data += pointer_size;
break;
--- 5945,5968 ----
static unsigned char *
! read_and_display_attr (attribute, form, data, cu_offset, pointer_size)
unsigned long attribute;
unsigned long form;
unsigned char * data;
+ unsigned long cu_offset;
unsigned long pointer_size;
{
unsigned long uvalue = 0;
unsigned char * block_start = NULL;
int bytes_read;
printf (" %-18s:", get_AT_name (attribute));
switch (form)
{
case DW_FORM_ref_addr:
case DW_FORM_addr:
uvalue = byte_get (data, pointer_size);
data += pointer_size;
break;
*************** read_and_display_attr (attribute, form,
*** 5982,6004 ****
case DW_FORM_flag:
case DW_FORM_data1:
uvalue = byte_get (data ++, 1);
- printf (is_ref ? " <%lx>" : " %ld", uvalue);
break;
case DW_FORM_ref2:
case DW_FORM_data2:
uvalue = byte_get (data, 2);
data += 2;
- printf (is_ref ? " <%lx>" : " %ld", uvalue);
break;
case DW_FORM_ref4:
case DW_FORM_data4:
uvalue = byte_get (data, 4);
data += 4;
- printf (is_ref ? " <%lx>" : " %ld", uvalue);
break;
case DW_FORM_ref8:
case DW_FORM_data8:
uvalue = byte_get (data, 4);
--- 5970,6026 ----
case DW_FORM_flag:
case DW_FORM_data1:
uvalue = byte_get (data ++, 1);
break;
case DW_FORM_ref2:
case DW_FORM_data2:
uvalue = byte_get (data, 2);
data += 2;
break;
case DW_FORM_ref4:
case DW_FORM_data4:
uvalue = byte_get (data, 4);
data += 4;
break;
+ case DW_FORM_sdata:
+ uvalue = read_leb128 (data, & bytes_read, 1);
+ data += bytes_read;
+ break;
+
+ case DW_FORM_ref_udata:
+ case DW_FORM_udata:
+ uvalue = read_leb128 (data, & bytes_read, 0);
+ data += bytes_read;
+ break;
+ }
+
+ switch (form)
+ {
+ case DW_FORM_ref_addr:
+ printf (" <#%lx>", uvalue);
+ break;
+
+ case DW_FORM_ref1:
+ case DW_FORM_ref2:
+ case DW_FORM_ref4:
+ case DW_FORM_ref_udata:
+ printf (" <%lx>", uvalue + cu_offset);
+ break;
+
+ case DW_FORM_addr:
+ printf (" %#lx", uvalue);
+
+ case DW_FORM_flag:
+ case DW_FORM_data1:
+ case DW_FORM_data2:
+ case DW_FORM_data4:
+ case DW_FORM_sdata:
+ case DW_FORM_udata:
+ printf (" %ld", uvalue);
+ break;
+
case DW_FORM_ref8:
case DW_FORM_data8:
uvalue = byte_get (data, 4);
*************** read_and_display_attr (attribute, form,
*** 6012,6030 ****
data += strlen (data) + 1;
break;
- case DW_FORM_sdata:
- uvalue = read_leb128 (data, & bytes_read, 1);
- data += bytes_read;
- printf (" %ld", (long) uvalue);
- break;
-
- case DW_FORM_ref_udata:
- case DW_FORM_udata:
- uvalue = read_leb128 (data, & bytes_read, 0);
- data += bytes_read;
- printf (is_ref ? " <%lx>" : " %ld", uvalue);
- break;
-
case DW_FORM_block:
uvalue = read_leb128 (data, & bytes_read, 0);
block_start = data + bytes_read;
--- 6034,6039 ----
*************** display_debug_info (section, start, file
*** 6215,6220 ****
--- 6225,6231 ----
unsigned char * tags;
int i;
int level;
+ unsigned long cu_offset;
external = (DWARF2_External_CompUnit *) start;
*************** display_debug_info (section, start, file
*** 6224,6229 ****
--- 6235,6241 ----
compunit.cu_pointer_size = BYTE_GET (external->cu_pointer_size);
tags = start + sizeof (* external);
+ cu_offset = start - section_begin;
start += compunit.cu_length + sizeof (external->cu_length);
if (compunit.cu_version != 2)
*************** display_debug_info (section, start, file
*** 6309,6315 ****
for (attr = entry->first_attr; attr; attr = attr->next)
tags = read_and_display_attr (attr->attribute,
attr->form,
! tags,
compunit.cu_pointer_size);
if (entry->children)
--- 6321,6327 ----
for (attr = entry->first_attr; attr; attr = attr->next)
tags = read_and_display_attr (attr->attribute,
attr->form,
! tags, cu_offset,
compunit.cu_pointer_size);
if (entry->children)