summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortom <tom@a5019735-40e9-0310-863c-91ae7b9d1cf9>2010-04-28 08:09:30 +0000
committertom <tom@a5019735-40e9-0310-863c-91ae7b9d1cf9>2010-04-28 08:09:30 +0000
commitfba428cd266b8a39db641c5fd9523daa8939bed0 (patch)
tree37ee76a1aa55acaa119eeae908ee76e623471a98
parent0fe1d4c134ba889ff5e0a3b1b4dc8f36e610ca97 (diff)
Add some basic DWARF4 support. Based on patch from Jakub Jelinek
but with support for VLIW architectures with multiple opcodes per instruction removed. Fixes #233595. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11106 a5019735-40e9-0310-863c-91ae7b9d1cf9
-rw-r--r--coregrind/m_debuginfo/d3basics.c15
-rw-r--r--coregrind/m_debuginfo/priv_d3basics.h20
-rw-r--r--coregrind/m_debuginfo/readdwarf.c78
-rw-r--r--coregrind/m_debuginfo/readdwarf3.c111
4 files changed, 200 insertions, 24 deletions
diff --git a/coregrind/m_debuginfo/d3basics.c b/coregrind/m_debuginfo/d3basics.c
index e4d4ed1c..160ec2db 100644
--- a/coregrind/m_debuginfo/d3basics.c
+++ b/coregrind/m_debuginfo/d3basics.c
@@ -124,6 +124,10 @@ HChar* ML_(pp_DW_TAG) ( DW_TAG tag )
case DW_TAG_imported_unit: return "DW_TAG_imported_unit";
case DW_TAG_condition: return "DW_TAG_condition";
case DW_TAG_shared_type: return "DW_TAG_shared_type";
+ /* DWARF 4. */
+ case DW_TAG_type_unit: return "DW_TAG_type_unit";
+ case DW_TAG_rvalue_reference_type: return "DW_TAG_rvalue_reference_type";
+ case DW_TAG_template_alias: return "DW_TAG_template_alias";
/* SGI/MIPS Extensions. */
case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop";
/* HP extensions. See:
@@ -172,6 +176,10 @@ HChar* ML_(pp_DW_FORM) ( DW_FORM form )
case DW_FORM_ref8: return "DW_FORM_ref8";
case DW_FORM_ref_udata: return "DW_FORM_ref_udata";
case DW_FORM_indirect: return "DW_FORM_indirect";
+ case DW_FORM_sec_offset:return "DW_FORM_sec_offset";
+ case DW_FORM_exprloc: return "DW_FORM_exprloc";
+ case DW_FORM_flag_present:return "DW_FORM_flag_present";
+ case DW_FORM_ref_sig8: return "DW_FORM_ref_sig8";
default: return "DW_FORM_???";
}
}
@@ -269,6 +277,13 @@ HChar* ML_(pp_DW_AT) ( DW_AT attr )
case DW_AT_elemental: return "DW_AT_elemental";
case DW_AT_pure: return "DW_AT_pure";
case DW_AT_recursive: return "DW_AT_recursive";
+ /* DWARF 4 values. */
+ case DW_AT_signature: return "DW_AT_signature";
+ case DW_AT_main_subprogram: return "DW_AT_main_subprogram";
+ case DW_AT_data_bit_offset: return "DW_AT_data_bit_offset";
+ case DW_AT_const_expr: return "DW_AT_const_expr";
+ case DW_AT_enum_class: return "DW_AT_enum_class";
+ case DW_AT_linkage_name: return "DW_AT_linkage_name";
/* SGI/MIPS extensions. */
/* case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde"; */
/* DW_AT_MIPS_fde == DW_AT_HP_unmodifiable */
diff --git a/coregrind/m_debuginfo/priv_d3basics.h b/coregrind/m_debuginfo/priv_d3basics.h
index 81f46ef9..f14f178f 100644
--- a/coregrind/m_debuginfo/priv_d3basics.h
+++ b/coregrind/m_debuginfo/priv_d3basics.h
@@ -104,6 +104,10 @@ typedef enum
DW_TAG_imported_unit = 0x3d,
DW_TAG_condition = 0x3f,
DW_TAG_shared_type = 0x40,
+ /* DWARF 4. */
+ DW_TAG_type_unit = 0x41,
+ DW_TAG_rvalue_reference_type = 0x42,
+ DW_TAG_template_alias = 0x43,
/* SGI/MIPS Extensions. */
DW_TAG_MIPS_loop = 0x4081,
/* HP extensions. See: ftp://ftp.hp.com/pub/lang/tools/WDB/wdb-4.0.tar.gz . */
@@ -158,6 +162,8 @@ typedef enum dwarf_source_language
DW_LANG_ObjC_plus_plus = 0x0011,
DW_LANG_UPC = 0x0012,
DW_LANG_D = 0x0013,
+ /* DWARF 4. */
+ DW_LANG_Python = 0x0014,
/* MIPS. */
DW_LANG_Mips_Assembler = 0x8001,
/* UPC. */
@@ -188,7 +194,12 @@ typedef enum
DW_FORM_ref4 = 0x13,
DW_FORM_ref8 = 0x14,
DW_FORM_ref_udata = 0x15,
- DW_FORM_indirect = 0x16
+ DW_FORM_indirect = 0x16,
+ /* DWARF 4 values. */
+ DW_FORM_sec_offset = 0x17,
+ DW_FORM_exprloc = 0x18,
+ DW_FORM_flag_present = 0x19,
+ DW_FORM_ref_sig8 = 0x20
}
DW_FORM;
@@ -285,6 +296,13 @@ typedef enum
DW_AT_elemental = 0x66,
DW_AT_pure = 0x67,
DW_AT_recursive = 0x68,
+ /* DWARF 4 values. */
+ DW_AT_signature = 0x69,
+ DW_AT_main_subprogram = 0x6a,
+ DW_AT_data_bit_offset = 0x6b,
+ DW_AT_const_expr = 0x6c,
+ DW_AT_enum_class = 0x6d,
+ DW_AT_linkage_name = 0x6e,
/* SGI/MIPS extensions. */
DW_AT_MIPS_fde = 0x2001,
DW_AT_MIPS_loop_begin = 0x2002,
diff --git a/coregrind/m_debuginfo/readdwarf.c b/coregrind/m_debuginfo/readdwarf.c
index d4204806..8c353854 100644
--- a/coregrind/m_debuginfo/readdwarf.c
+++ b/coregrind/m_debuginfo/readdwarf.c
@@ -1,6 +1,6 @@
/*--------------------------------------------------------------------*/
-/*--- Read DWARF1/2/3 debug info. readdwarf.c ---*/
+/*--- Read DWARF1/2/3/4 debug info. readdwarf.c ---*/
/*--------------------------------------------------------------------*/
/*
@@ -139,6 +139,7 @@ typedef struct
UShort li_version;
ULong li_header_length;
UChar li_min_insn_length;
+ UChar li_max_ops_per_insn;
UChar li_default_is_stmt;
Int li_line_base;
UChar li_line_range;
@@ -182,7 +183,8 @@ enum dwarf_line_number_x_ops
{
DW_LNE_end_sequence = 1,
DW_LNE_set_address = 2,
- DW_LNE_define_file = 3
+ DW_LNE_define_file = 3,
+ DW_LNE_set_discriminator = 4
};
typedef struct
@@ -199,7 +201,7 @@ typedef struct
UInt column;
Int is_stmt;
Int basic_block;
- Int end_sequence;
+ UChar end_sequence;
} LineSMR;
@@ -411,6 +413,11 @@ Word process_extended_line_op( struct _DebugInfo* di,
VG_(printf)(" DWARF2-line: set_address\n");
break;
+ case DW_LNE_set_discriminator:
+ read_leb128 (data, & bytes_read, 0);
+ data += bytes_read;
+ break;
+
default:
if (di->ddump_line)
VG_(printf)("process_extended_line_op:default\n");
@@ -513,9 +520,9 @@ void read_dwarf2_lineblock ( struct _DebugInfo* di,
VG_(printf)(" DWARF Version: %d\n",
(Int)info.li_version);
- if (info.li_version != 2 && info.li_version != 3) {
+ if (info.li_version != 2 && info.li_version != 3 && info.li_version != 4) {
ML_(symerr)(di, True,
- "Only DWARF version 2 and 3 line info "
+ "Only DWARF version 2, 3 and 4 line info "
"is currently supported.");
goto out;
}
@@ -533,6 +540,26 @@ void read_dwarf2_lineblock ( struct _DebugInfo* di,
VG_(printf)(" Minimum Instruction Length: %d\n",
(Int)info.li_min_insn_length);
+ /* We only support machines with one opcode per instruction
+ for now. If we ever want to support VLIW machines there is
+ code to handle multiple opcodes per instruction in the
+ patch attached to BZ#233595.
+ */
+ if (info.li_version >= 4) {
+ info.li_max_ops_per_insn = * ((UChar *)external);
+ if (info.li_max_ops_per_insn != 1) {
+ ML_(symerr)(di, True,
+ "Invalid Maximum Ops Per Insn in line info.");
+ goto out;
+ }
+ external += 1;
+ if (di->ddump_line)
+ VG_(printf)(" Maximum Ops Per Insn: %d\n",
+ (Int)info.li_max_ops_per_insn);
+ } else {
+ info.li_max_ops_per_insn = 1;
+ }
+
info.li_default_is_stmt = * ((UChar *)external);
external += 1;
if (di->ddump_line)
@@ -714,7 +741,7 @@ void read_dwarf2_lineblock ( struct _DebugInfo* di,
Int advAddr;
op_code -= info.li_opcode_base;
- adv = (op_code / info.li_line_range)
+ adv = (op_code / info.li_line_range)
* info.li_min_insn_length;
advAddr = adv;
state_machine_regs.address += adv;
@@ -800,7 +827,7 @@ void read_dwarf2_lineblock ( struct _DebugInfo* di,
break;
case DW_LNS_advance_pc:
- adv = info.li_min_insn_length
+ adv = info.li_min_insn_length
* read_leb128 (data, & bytes_read, 0);
data += bytes_read;
state_machine_regs.address += adv;
@@ -979,7 +1006,7 @@ void read_unitinfo_dwarf2( /*OUT*/UnitInfo* ui,
blklen = read_initial_length_field( p, &ui->dw64 );
p += ui->dw64 ? 12 : 4;
- /* version should be 2 */
+ /* version should be 2, 3 or 4 */
ver = *((UShort*)p);
p += 2;
@@ -1049,6 +1076,9 @@ void read_unitinfo_dwarf2( /*OUT*/UnitInfo* ui,
classes) use FORM_data8, not FORM_data4. Also,
FORM_ref_addr and FORM_strp are 64-bit values, not 32-bit
values. */
+ /* TJH 27 Apr 10: in DWARF 4 lineptr (and loclistptr,macptr,
+ rangelistptr classes) use FORM_sec_offset which is 64 bits
+ in 64 bit DWARF and 32 bits in 32 bit DWARF. */
switch( form ) {
/* Those cases extract the data properly */
case 0x05: /* FORM_data2 */ cval = *((UShort*)p); p +=2; break;
@@ -1066,7 +1096,11 @@ void read_unitinfo_dwarf2( /*OUT*/UnitInfo* ui,
case 0x08: /* FORM_string */ sval = (Char*)p;
p += VG_(strlen)((Char*)p) + 1; break;
case 0x0b: /* FORM_data1 */ cval = *p; p++; break;
-
+ case 0x17: /* FORM_sec_offset */if (ui->dw64) {
+ cval = *((ULong*)p); p += 8;
+ } else {
+ cval = *((UInt*)p); p += 4;
+ }; break;
/* TODO : Following ones just skip data - implement if you need */
case 0x01: /* FORM_addr */ p += addr_size; break;
case 0x03: /* FORM_block2 */ p += *((UShort*)p) + 2; break;
@@ -1085,7 +1119,10 @@ void read_unitinfo_dwarf2( /*OUT*/UnitInfo* ui,
case 0x13: /* FORM_ref4 */ p += 4; break;
case 0x14: /* FORM_ref8 */ p += 8; break;
case 0x15: /* FORM_ref_udata */ read_leb128U( &p ); break;
-
+ case 0x18: /* FORM_exprloc */ p += read_leb128U( &p ); break;
+ case 0x19: /* FORM_flag_present */break;
+ case 0x20: /* FORM_ref_sig8 */ p += 8; break;
+
default:
VG_(printf)( "### unhandled dwarf2 abbrev form code 0x%x\n", form );
break;
@@ -1163,9 +1200,9 @@ void ML_(read_debuginfo_dwarf3)
/* version should be 2 */
ver = *((UShort*)( block_img + blklen_len ));
- if ( ver != 2 && ver != 3 ) {
+ if ( ver != 2 && ver != 3 && ver != 4 ) {
ML_(symerr)( di, True,
- "Ignoring non-Dwarf2/3 block in .debug_info" );
+ "Ignoring non-Dwarf2/3/4 block in .debug_info" );
continue;
}
@@ -3705,8 +3742,8 @@ void ML_(read_callframe_info_dwarf3)
VG_(printf)("cie.version = %d\n", (Int)cie_version);
if (di->ddump_frames)
VG_(printf)(" Version: %d\n", (Int)cie_version);
- if (cie_version != 1 && cie_version != 3) {
- how = "unexpected CIE version (not 1 nor 3)";
+ if (cie_version != 1 && cie_version != 3 && cie_version != 4) {
+ how = "unexpected CIE version (not 1 nor 3 nor 4)";
goto bad;
}
@@ -3722,6 +3759,19 @@ void ML_(read_callframe_info_dwarf3)
cie_augmentation += 2;
}
+ if (cie_version >= 4) {
+ if (read_UChar(data) != sizeof(Addr)) {
+ how = "unexpected address size";
+ goto bad;
+ }
+ data += sizeof(UChar);
+ if (read_UChar(data) != 0) {
+ how = "unexpected non-zero segment size";
+ goto bad;
+ }
+ data += sizeof(UChar);
+ }
+
the_CIEs[this_CIE].code_a_f = read_leb128( data, &nbytes, 0);
data += nbytes;
if (di->trace_cfi)
diff --git a/coregrind/m_debuginfo/readdwarf3.c b/coregrind/m_debuginfo/readdwarf3.c
index e9ec841d..45263200 100644
--- a/coregrind/m_debuginfo/readdwarf3.c
+++ b/coregrind/m_debuginfo/readdwarf3.c
@@ -1,6 +1,6 @@
/*--------------------------------------------------------------------*/
-/*--- Read DWARF3 ".debug_info" sections (DIE trees). ---*/
+/*--- Read DWARF3/4 ".debug_info" sections (DIE trees). ---*/
/*--- readdwarf3.c ---*/
/*--------------------------------------------------------------------*/
@@ -387,7 +387,7 @@ typedef
void (*barf)( HChar* ) __attribute__((noreturn));
/* Is this 64-bit DWARF ? */
Bool is_dw64;
- /* Which DWARF version ? (2 or 3) */
+ /* Which DWARF version ? (2, 3 or 4) */
UShort version;
/* Length of this Compilation Unit, as stated in the
.unit_length :: InitialLength field of the CU Header.
@@ -805,8 +805,8 @@ void parse_CU_Header ( /*OUT*/CUConst* cc,
/* version */
cc->version = get_UShort( c );
- if (cc->version != 2 && cc->version != 3)
- cc->barf( "parse_CU_Header: is neither DWARF2 nor DWARF3" );
+ if (cc->version != 2 && cc->version != 3 && cc->version != 4)
+ cc->barf( "parse_CU_Header: is neither DWARF2 nor DWARF3 nor DWARF4" );
TRACE_D3(" Version: %d\n", (Int)cc->version );
/* debug_abbrev_offset */
@@ -984,11 +984,21 @@ void get_Form_contents ( /*OUT*/ULong* cts,
*ctsSzB = 8;
TRACE_D3("%llu", *cts);
break;
+ case DW_FORM_sec_offset:
+ *cts = (ULong)get_Dwarfish_UWord( c, cc->is_dw64 );
+ *ctsSzB = cc->is_dw64 ? 8 : 4;
+ TRACE_D3("%llu", *cts);
+ break;
case DW_FORM_sdata:
*cts = (ULong)(Long)get_SLEB128(c);
*ctsSzB = 8;
TRACE_D3("%lld", (Long)*cts);
break;
+ case DW_FORM_udata:
+ *cts = (ULong)(Long)get_ULEB128(c);
+ *ctsSzB = 8;
+ TRACE_D3("%llu", (Long)*cts);
+ break;
case DW_FORM_addr:
/* note, this is a hack. DW_FORM_addr is defined as getting
a word the size of the target machine as defined by the
@@ -1055,6 +1065,22 @@ void get_Form_contents ( /*OUT*/ULong* cts,
*ctsMemSzB = 1 + (ULong)VG_(strlen)(str);
break;
}
+ case DW_FORM_ref1: {
+ UChar u8 = get_UChar(c);
+ UWord res = cc->cu_start_offset + (UWord)u8;
+ *cts = (ULong)res;
+ *ctsSzB = sizeof(UWord);
+ TRACE_D3("<%lx>", res);
+ break;
+ }
+ case DW_FORM_ref2: {
+ UShort u16 = get_UShort(c);
+ UWord res = cc->cu_start_offset + (UWord)u16;
+ *cts = (ULong)res;
+ *ctsSzB = sizeof(UWord);
+ TRACE_D3("<%lx>", res);
+ break;
+ }
case DW_FORM_ref4: {
UInt u32 = get_UInt(c);
UWord res = cc->cu_start_offset + (UWord)u32;
@@ -1063,6 +1089,22 @@ void get_Form_contents ( /*OUT*/ULong* cts,
TRACE_D3("<%lx>", res);
break;
}
+ case DW_FORM_ref8: {
+ ULong u64 = get_ULong(c);
+ UWord res = cc->cu_start_offset + (UWord)u64;
+ *cts = (ULong)res;
+ *ctsSzB = sizeof(UWord);
+ TRACE_D3("<%lx>", res);
+ break;
+ }
+ case DW_FORM_ref_udata: {
+ ULong u64 = get_ULEB128(c);
+ UWord res = cc->cu_start_offset + (UWord)u64;
+ *cts = (ULong)res;
+ *ctsSzB = sizeof(UWord);
+ TRACE_D3("<%lx>", res);
+ break;
+ }
case DW_FORM_flag: {
UChar u8 = get_UChar(c);
TRACE_D3("%u", (UInt)u8);
@@ -1070,6 +1112,11 @@ void get_Form_contents ( /*OUT*/ULong* cts,
*ctsSzB = 1;
break;
}
+ case DW_FORM_flag_present:
+ TRACE_D3("1");
+ *cts = 1;
+ *ctsSzB = 1;
+ break;
case DW_FORM_block1: {
ULong u64b;
ULong u64 = (ULong)get_UChar(c);
@@ -1096,6 +1143,50 @@ void get_Form_contents ( /*OUT*/ULong* cts,
*ctsMemSzB = (UWord)u64;
break;
}
+ case DW_FORM_block4: {
+ ULong u64b;
+ ULong u64 = (ULong)get_UInt(c);
+ UChar* block = get_address_of_Cursor(c);
+ TRACE_D3("%llu byte block: ", u64);
+ for (u64b = u64; u64b > 0; u64b--) {
+ UChar u8 = get_UChar(c);
+ TRACE_D3("%x ", (UInt)u8);
+ }
+ *cts = (ULong)(UWord)block;
+ *ctsMemSzB = (UWord)u64;
+ break;
+ }
+ case DW_FORM_exprloc:
+ case DW_FORM_block: {
+ ULong u64b;
+ ULong u64 = (ULong)get_ULEB128(c);
+ UChar* block = get_address_of_Cursor(c);
+ TRACE_D3("%llu byte block: ", u64);
+ for (u64b = u64; u64b > 0; u64b--) {
+ UChar u8 = get_UChar(c);
+ TRACE_D3("%x ", (UInt)u8);
+ }
+ *cts = (ULong)(UWord)block;
+ *ctsMemSzB = (UWord)u64;
+ break;
+ }
+ case DW_FORM_ref_sig8: {
+ ULong u64b;
+ UChar* block = get_address_of_Cursor(c);
+ TRACE_D3("8 byte signature: ");
+ for (u64b = 8; u64b > 0; u64b--) {
+ UChar u8 = get_UChar(c);
+ TRACE_D3("%x ", (UInt)u8);
+ }
+ *cts = (ULong)(UWord)block;
+ *ctsMemSzB = 8;
+ break;
+ }
+ case DW_FORM_indirect:
+ get_Form_contents (cts, ctsSzB, ctsMemSzB, cc, c, td3,
+ (DW_FORM)get_ULEB128(c));
+ return;
+
default:
VG_(printf)(
"get_Form_contents: unhandled %d (%s) at <%lx>\n",
@@ -1322,11 +1413,13 @@ void read_filename_table( /*MOD*/D3VarParser* parser,
get_Initial_Length( &is_dw64, &c,
"read_filename_table: invalid initial-length field" );
version = get_UShort( &c );
- if (version != 2 && version != 3)
- cc->barf("read_filename_table: Only DWARF version 2 and 3 line info "
+ if (version != 2 && version != 3 && version != 4)
+ cc->barf("read_filename_table: Only DWARF version 2, 3 and 4 line info "
"is currently supported.");
/*header_length = (ULong)*/ get_Dwarfish_UWord( &c, is_dw64 );
/*minimum_instruction_length = */ get_UChar( &c );
+ if (version >= 4)
+ /*maximum_operations_per_insn = */ get_UChar( &c );
/*default_is_stmt = */ get_UChar( &c );
/*line_base = (Char)*/ get_UChar( &c );
/*line_range = */ get_UChar( &c );
@@ -2025,7 +2118,7 @@ static void parse_type_DIE ( /*MOD*/XArray* /* of TyEnt */ tyents,
case DW_LANG_C89: case DW_LANG_C:
case DW_LANG_C_plus_plus: case DW_LANG_ObjC:
case DW_LANG_ObjC_plus_plus: case DW_LANG_UPC:
- case DW_LANG_Upc:
+ case DW_LANG_Upc: case DW_LANG_C99:
parser->language = 'C'; break;
case DW_LANG_Fortran77: case DW_LANG_Fortran90:
case DW_LANG_Fortran95:
@@ -2033,8 +2126,8 @@ static void parse_type_DIE ( /*MOD*/XArray* /* of TyEnt */ tyents,
case DW_LANG_Ada83: case DW_LANG_Cobol74:
case DW_LANG_Cobol85: case DW_LANG_Pascal83:
case DW_LANG_Modula2: case DW_LANG_Java:
- case DW_LANG_C99: case DW_LANG_Ada95:
- case DW_LANG_PLI: case DW_LANG_D:
+ case DW_LANG_Ada95: case DW_LANG_PLI:
+ case DW_LANG_D: case DW_LANG_Python:
case DW_LANG_Mips_Assembler:
parser->language = '?'; break;
default: