libdw: Initialize ranges_base, add invalid DWARF test and fix expected output.
authorMark Wielaard <mark@klomp.org>
Thu, 24 May 2018 13:20:25 +0000 (15:20 +0200)
committerMark Wielaard <mark@klomp.org>
Thu, 24 May 2018 13:20:25 +0000 (15:20 +0200)
We never initialized the CU ranges_base, which meant we didn't actually
calculate it correctly. This caused bad ranges on some DIEs. The expected
output in the testcase was wrong. We also crashed on invalid dwarf.

Signed-off-by: Mark Wielaard <mark@klomp.org>
libdw/ChangeLog
libdw/dwarf_ranges.c
libdw/libdw_findcu.c
tests/ChangeLog
tests/get-units-invalid.c
tests/run-all-dwarf-ranges.sh

index 4db0f5c..c302628 100644 (file)
@@ -1,3 +1,8 @@
+2018-05-24  Mark Wielaard  <mark@klomp.org>
+
+       * dwarf_ranges.c (dwarf_ranges): Check for NULL cu.
+       * libdw_findcu.c (__libdw_intern_next_unit): Initialize ranges_base.
+
 2018-05-18  Mark Wielaard  <mark@klomp.org>
 
        * dwarf_formudata.c (__libdw_formptr): Handle the special case
index b0450cf..52a61ee 100644 (file)
@@ -123,6 +123,12 @@ dwarf_ranges (Dwarf_Die *die, ptrdiff_t offset, Dwarf_Addr *basep,
   /* We have to look for a noncontiguous range.  */
   size_t secidx = IDX_debug_ranges;
   Dwarf_CU *cu = die->cu;
+  if (cu == NULL)
+    {
+      __libdw_seterrno (DWARF_E_INVALID_DWARF);
+      return -1;
+    }
+
   const Elf_Data *d = cu->dbg->sectiondata[secidx];
   if (d == NULL && cu->unit_type == DW_UT_split_compile)
     {
index d22ddae..83c2eb1 100644 (file)
@@ -121,6 +121,7 @@ __libdw_intern_next_unit (Dwarf *dbg, bool debug_types)
   newp->base_address = (Dwarf_Addr) -1;
   newp->addr_base = (Dwarf_Off) -1;
   newp->str_off_base = (Dwarf_Off) -1;
+  newp->ranges_base = (Dwarf_Off) -1;
 
   newp->startp = data->d_buf + newp->start;
   newp->endp = data->d_buf + newp->end;
index a021a01..86bcf9d 100644 (file)
@@ -1,6 +1,11 @@
+2018-05-24  Mark Wielaard  <mark@klomp.org>
+
+       * get-units-invalid.c (main): Add check for invalid dwarf_ranges.
+       * run-all-dwarf-ranges.sh: Correct expected output.
+
 2018-05-18  Mark Wielaard  <mark@klomp.org>
 
-       * tests/Makefiles.am (check_PROGRAMS): Add all-dwarf-ranges.
+       * Makefiles.am (check_PROGRAMS): Add all-dwarf-ranges.
        (TESTS): Add run-all-dwarf-ranges.sh.
        (EXTRA_DIST): Add run-all-dwarf-ranges.sh,
        testfilesplitranges4.debug.bz2, testfile-ranges-hello.dwo.bz2
index 9ec16ee..58b32c0 100644 (file)
@@ -79,6 +79,13 @@ main (int argc, char *argv[])
                          dwarf_diename (&result));
                  return -1;
                }
+             Dwarf_Addr base, start, end;
+             if (dwarf_ranges (&subdie, 0, &base, &start, &end) != -1)
+               {
+                 printf ("Should NOT have a ranges: %s\n",
+                         dwarf_diename (&result));
+                 return -1;
+               }
            }
          else if (unit_type == DW_UT_type)
            printf ("subdie: %s\n", dwarf_diename (&subdie));
index 0bd641b..ba5528d 100755 (executable)
@@ -37,11 +37,12 @@ die: world.c (11)
  400500..400567
 
 die: happy (1d)
- 8009e0..8009ff
- 8008e0..8008f7
+ 40051c..400526
+ 400530..400534
+ 400535..40053f
 
 die: sad (1d)
- 400530..400534
+ 40051c..400526
  400535..40053f
 
 EOF