]> sourceware.org Git - valgrind.git/commitdiff
read properly unit headers depending on dwarf5 unit_type
authorLuboš Luňák <l.lunak@centrum.cz>
Tue, 19 Apr 2022 08:58:44 +0000 (10:58 +0200)
committerMark Wielaard <mark@klomp.org>
Thu, 9 Jun 2022 20:36:30 +0000 (22:36 +0200)
There may be additional fields that need to be skipped over, otherwise
further reading will interpret these incorrectly.

coregrind/m_debuginfo/readdwarf.c
coregrind/m_debuginfo/readdwarf3.c

index 39a2946870042057d863b688d292e20c97c4d2ef..56cef9a5f435b1fd5c46d5c7360299427527556f 100644 (file)
@@ -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)); 
 
index 5489f8d135c3b71ce74921380e24750e2ee43510..1453ebbdbc90fe67c0230a4d37ba953891d9ae1f 100644 (file)
@@ -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
This page took 2.201653 seconds and 5 git commands to generate.