]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
dwarflint: Fail low-level cases if toplevel CU DIE has wrong tag
authorPetr Machata <pmachata@redhat.com>
Mon, 7 Mar 2011 16:30:15 +0000 (17:30 +0100)
committerPetr Machata <pmachata@redhat.com>
Mon, 7 Mar 2011 16:30:15 +0000 (17:30 +0100)
dwarflint/check_debug_info.cc
dwarflint/tests/garbage-2.bz2 [new file with mode: 0644]
dwarflint/tests/run-bad.sh

index c65ee832adb25891f565d55db662a924f3b003ea..6672c8c8dcb0f19ee986eba31ecd7dee5fac0444 100644 (file)
@@ -497,6 +497,8 @@ namespace
 
   /*
     Returns:
+    -2 in case of error that we have to note and return, but for now
+       we can carry on
     -1 in case of error
     +0 in case of no error, but the chain only consisted of a
        terminating zero die.
@@ -522,6 +524,7 @@ namespace
     struct abbrev *abbrev = NULL;
     struct where where = WHERE (sec_info, NULL);
     unsigned long die_count = 0;
+    int retval = 0;
 
     struct value_check_cb_ctx cb_ctx = {
       ctx, &where, cu,
@@ -622,9 +625,12 @@ namespace
                << "toplevel DIE chain contains more than one DIE."
                << std::endl;
            else if (!is_cudie)
-             wr_error (cu->head->where)
-               << "toplevel DIE must be either compile_unit or partial_unit."
-               << std::endl;
+             {
+               wr_error (cu->head->where)
+                 << "toplevel DIE must be either compile_unit or partial_unit."
+                 << std::endl;
+               retval = -2;
+             }
          }
 
        addr_record_add (&cu->die_addrs, cu->head->offset + die_off);
@@ -914,6 +920,8 @@ namespace
                                     pc_coverage, need_rangesp, level + 1);
            if (st == -1)
              return -1;
+           else if (st == -2)
+             retval = -2;
            else if (st == 0)
              wr_message (mc_impact_3 | mc_acc_suboptimal | mc_die_rel,
                          &where,
@@ -926,7 +934,10 @@ namespace
        << "this DIE should have had its sibling at " << pri::hex (sibling_addr)
        << ", but the DIE chain ended." << std::endl;
 
-    return got_die ? 1 : 0;
+    if (retval != 0)
+      return retval;
+    else
+      return got_die ? 1 : 0;
   }
 }
 
diff --git a/dwarflint/tests/garbage-2.bz2 b/dwarflint/tests/garbage-2.bz2
new file mode 100644 (file)
index 0000000..3cd5619
Binary files /dev/null and b/dwarflint/tests/garbage-2.bz2 differ
index 5dd6495660836b488cfd6d28830849ea951b8c3a..871fe551c88a0ff954102b7a93fe0481588390ff 100755 (executable)
@@ -27,7 +27,7 @@
 
 srcdir=$srcdir/tests
 
-testfiles hello.bad-1 hello.bad-3 garbage-1
+testfiles hello.bad-1 hello.bad-3 garbage-1 garbage-2
 
 testrun_compare ./dwarflint hello.bad-1 <<EOF
 error: .debug_info: DIE 0x83: abbrev section at 0x0 doesn't contain code 83.
@@ -46,3 +46,7 @@ error: Broken ELF: offset out of range.
 error: .debug_abbrev: data not found.
 error: .debug_info: data not found.
 EOF
+
+testrun_compare ./dwarflint garbage-2 <<EOF
+error: .debug_info: CU 0: toplevel DIE must be either compile_unit or partial_unit.
+EOF