From: Luboš Luňák Date: Tue, 19 Apr 2022 08:58:44 +0000 (+0200) Subject: read properly unit headers depending on dwarf5 unit_type X-Git-Tag: VALGRIND_3_20_0~44 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=61ddbc1fc395c787192e569d8f2238f713bdfd8e;p=thirdparty%2Fvalgrind.git read properly unit headers depending on dwarf5 unit_type There may be additional fields that need to be skipped over, otherwise further reading will interpret these incorrectly. --- diff --git a/coregrind/m_debuginfo/readdwarf.c b/coregrind/m_debuginfo/readdwarf.c index 39a2946870..56cef9a5f4 100644 --- a/coregrind/m_debuginfo/readdwarf.c +++ b/coregrind/m_debuginfo/readdwarf.c @@ -1056,6 +1056,7 @@ void read_unitinfo_dwarf2( /*OUT*/UnitInfo* ui, UShort ver; UChar addr_size = 0; + UChar unit_type = 0; DiCursor p = unitblock_img; DiCursor end_img; DiCursor abbrev_img; @@ -1073,7 +1074,7 @@ void read_unitinfo_dwarf2( /*OUT*/UnitInfo* ui, if (ver >= 5) /* unit_type for DWARF5 */ - /* unit_type = */ ML_(cur_step_UChar)(&p); + unit_type = ML_(cur_step_UChar)(&p); else /* get offset in abbrev */ atoffs = ui->dw64 ? ML_(cur_step_ULong)(&p) @@ -1082,11 +1083,33 @@ void read_unitinfo_dwarf2( /*OUT*/UnitInfo* ui, /* Address size */ addr_size = ML_(cur_step_UChar)(&p); - if (ver >= 5) + if (ver >= 5) { /* get offset in abbrev */ atoffs = ui->dw64 ? ML_(cur_step_ULong)(&p) : (ULong)(ML_(cur_step_UInt)(&p)); + /* read any extra fields */ + switch(unit_type) { + case DW_UT_compile: + case DW_UT_partial: + break; + case DW_UT_skeleton: + case DW_UT_split_compile: + /* dwo_id = */ ML_(cur_step_ULong)(&p); + break; + case DW_UT_type: + case DW_UT_split_type: + /* type_signature = */ ML_(cur_step_ULong)(&p); + /* type_offset = */ ui->dw64 ? ML_(cur_step_ULong)(&p) + : (ULong)(ML_(cur_step_UInt)(&p)); + break; + default: + VG_(printf)( "### unhandled dwarf2 unit_type code 0x%x\n", + unit_type ); + break; + } + } + /* End of this block */ end_img = ML_(cur_plus)(unitblock_img, blklen + (ui->dw64 ? 12 : 4)); diff --git a/coregrind/m_debuginfo/readdwarf3.c b/coregrind/m_debuginfo/readdwarf3.c index 5489f8d135..1453ebbdbc 100644 --- a/coregrind/m_debuginfo/readdwarf3.c +++ b/coregrind/m_debuginfo/readdwarf3.c @@ -1200,11 +1200,17 @@ void parse_CU_Header ( /*OUT*/CUConst* cc, cc->is_type_unit = type_unit; cc->is_alt_info = alt_info; - if (type_unit || (cc->version >= 5 && unit_type == DW_UT_type)) { + if (type_unit || (cc->version >= 5 && (unit_type == DW_UT_type + || unit_type == DW_UT_split_type))) { cc->type_signature = get_ULong( c ); cc->type_offset = get_Dwarfish_UWord( c, cc->is_dw64 ); } + if (cc->version >= 5 && (unit_type == DW_UT_skeleton + || unit_type == DW_UT_split_compile)) { + /* dwo_id = */ get_ULong( c ); + } + /* Set up cc->debug_abbv to point to the relevant table for this CU. Set its .szB so that at least we can't read off the end of the debug_abbrev section -- potentially (and quite likely) too