[PATCH] libdw: Don't crash on invalid die in dwarf_dieoffset.

2018-05-31 Thread Mark Wielaard
Add explicit test in get-units-invalid for dwarf_cuoffset and
dwarf_dieoffset.

Signed-off-by: Mark Wielaard 
---
 libdw/ChangeLog   |  4 
 libdw/dwarf_dieoffset.c   |  2 +-
 tests/ChangeLog   |  5 +
 tests/get-units-invalid.c | 14 +-
 4 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index c304a3b..61bf14f 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,7 @@
+2018-05-31  Mark Wielaard  
+
+   * dwarf_dieoffset.c: Check die->cu != NULL.
+
 2018-05-30  Mark Wielaard  
 
* libdw/dwarf_getsrclines.c (read_srclines): Change ndir and
diff --git a/libdw/dwarf_dieoffset.c b/libdw/dwarf_dieoffset.c
index 8028f6d..c869ecd 100644
--- a/libdw/dwarf_dieoffset.c
+++ b/libdw/dwarf_dieoffset.c
@@ -38,7 +38,7 @@
 Dwarf_Off
 dwarf_dieoffset (Dwarf_Die *die)
 {
-  return (die == NULL
+  return ((die == NULL || die->cu == NULL)
  ? ~0ul
  : (Dwarf_Off) (die->addr - die->cu->startp + die->cu->start));
 }
diff --git a/tests/ChangeLog b/tests/ChangeLog
index b656bee..521df52 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,8 @@
+2018-05-31  Mark Wielaard  
+
+   * get-units-invalid.c (main): Check dwarf_cuoffset and
+   dwarf_dieoffset.
+
 2018-05-29  Mark Wielaard  
 
* dwarf-die-addr-die.c (check_dbg): Also check subdies, split or
diff --git a/tests/get-units-invalid.c b/tests/get-units-invalid.c
index 58b32c0..ba0f818 100644
--- a/tests/get-units-invalid.c
+++ b/tests/get-units-invalid.c
@@ -83,7 +83,19 @@ main (int argc, char *argv[])
  if (dwarf_ranges (&subdie, 0, &base, &start, &end) != -1)
{
  printf ("Should NOT have a ranges: %s\n",
- dwarf_diename (&result));
+ dwarf_diename (&subdie));
+ return -1;
+   }
+ if (dwarf_cuoffset (&subdie) != (Dwarf_Off) -1)
+   {
+ printf ("Should NOT have a cuoffset: %s\n",
+ dwarf_diename (&subdie));
+ return -1;
+   }
+ if (dwarf_dieoffset (&subdie) != (Dwarf_Off) -1)
+   {
+ printf ("Should NOT have a die offset: %s\n",
+ dwarf_diename (&subdie));
  return -1;
}
}
-- 
1.8.3.1



[PATCH] tests: Run run-low_high_pc.sh testcase on split dwarf files.

2018-05-31 Thread Mark Wielaard
Test that the low high pc attributes can be properly resolved also
in split dwarf setups.

Signed-off-by: Mark Wielaard 
---
 tests/ChangeLog  |  9 +
 tests/low_high_pc.c  | 28 ++--
 tests/run-low_high_pc.sh | 15 +++
 3 files changed, 46 insertions(+), 6 deletions(-)

diff --git a/tests/ChangeLog b/tests/ChangeLog
index 521df52..c03db54 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,5 +1,14 @@
 2018-05-31  Mark Wielaard  
 
+   * low_high_pc.c (handle_die): Handle NULL name. Print offset and
+   name of die.
+   (main): Check if the cu DIE is a skeleton, then get and handle
+   the split subdie.
+   * run-low-high-pc.sh: Run on testfile-splitdwarf-4 and
+   testfile-splitdwarf-5. Run on all selftest files.
+
+2018-05-31  Mark Wielaard  
+
* get-units-invalid.c (main): Check dwarf_cuoffset and
dwarf_dieoffset.
 
diff --git a/tests/low_high_pc.c b/tests/low_high_pc.c
index d0f4302..5c6b343 100644
--- a/tests/low_high_pc.c
+++ b/tests/low_high_pc.c
@@ -1,5 +1,5 @@
 /* Test program for dwarf_lowpc and dwarf_highpc
-   Copyright (C) 2012 Red Hat, Inc.
+   Copyright (C) 2012, 2018 Red Hat, Inc.
This file is part of elfutils.
 
This file is free software; you can redistribute it and/or modify
@@ -55,7 +55,9 @@ handle_die (Dwarf_Die *die, void *arg)
 
   const char *name = dwarf_diename (die);
   if (name == NULL)
-fail (off, "", "die without a name");
+name = "";
+
+  printf ("[%" PRIx64 "] %s\n", off, name);
 
   Dwarf_Addr lowpc = 0;
   Dwarf_Addr highpc = 0;
@@ -101,9 +103,31 @@ main (int argc, char *argv[])
   a.file = dwarf_diename (a.cu);
   handle_die (a.cu, &a);
   dwarf_getfuncs (a.cu, &handle_die, &a, 0);
+
+  uint8_t unit_type;
+  Dwarf_Die subdie;
+  if (dwarf_cu_info (a.cu->cu, NULL, &unit_type, NULL, &subdie,
+NULL, NULL, NULL) != 0)
+   {
+ Dwarf_Off off = dwarf_dieoffset (a.cu);
+ fail (off, "dwarf_cu_info", dwarf_errmsg (-1));
+   }
+
+  if (unit_type == DW_UT_skeleton)
+   {
+ const char *name = dwarf_diename (&subdie) ?: "";
+ printf ("Following split subdie: %s\n", name);
+ struct args b = a;
+ b.cu = &subdie;
+ handle_die (b.cu, &b);
+ dwarf_getfuncs (b.cu, &handle_die, &b, 0);
+ printf ("Done subdie: %s\n", name);
+   }
 }
 
   dwfl_end (a.dwfl);
 
+  printf ("\n");
+
   return result;
 }
diff --git a/tests/run-low_high_pc.sh b/tests/run-low_high_pc.sh
index ab5f2c3..41ec420 100755
--- a/tests/run-low_high_pc.sh
+++ b/tests/run-low_high_pc.sh
@@ -1,5 +1,5 @@
 #! /bin/sh
-# Copyright (C) 2005 Red Hat, Inc.
+# Copyright (C) 2005, 2018 Red Hat, Inc.
 # This file is part of elfutils.
 #
 # This file is free software; you can redistribute it and/or modify
@@ -27,8 +27,15 @@ testfiles testfile_low_high_pc
 
 testrun ${abs_builddir}/low_high_pc -e ./testfile_low_high_pc
 testrun ${abs_builddir}/low_high_pc -e ${abs_builddir}/low_high_pc
-testrun ${abs_builddir}/low_high_pc -e ${abs_top_builddir}/src/strip
-testrun ${abs_builddir}/low_high_pc -e ${abs_top_builddir}/src/strip.o
-testrun ${abs_builddir}/low_high_pc -e ${abs_top_builddir}/libelf/libelf.so
+
+# see tests/testfile-dwarf-45.source
+testfiles testfile-splitdwarf-4 testfile-splitdwarf-5
+testfiles testfile-hello4.dwo testfile-hello5.dwo
+testfiles testfile-world4.dwo testfile-world5.dwo
+
+testrun ${abs_builddir}/low_high_pc -e testfile-splitdwarf-4
+testrun ${abs_builddir}/low_high_pc -e testfile-splitdwarf-5
+
+testrun_on_self ${abs_builddir}/low_high_pc -e
 
 exit 0
-- 
1.8.3.1



Re: [PATCH] readelf: Fix regression with multiple files and implicit debug_info reading.

2018-05-31 Thread Mark Wielaard
On Tue, 2018-05-29 at 09:57 +0200, Mark Wielaard wrote:
> Commit 314e9d7d "readelf: Handle .debug_info first if any other debug
> section needs it" introduced a regression when handling multiple files.
> The implicit and explicit printing of debuginfo weren't reset and so
> the second file would not show (or scan) the .debug_info section when
> needed.
> 
> Fix by resetting the implicit and explicit section printing flags.
> Add a testcase that prints the .debug_loc section for two files and
> check that the CUs are resolved.

Pushed to master.


[PATCH] tests: Split self_test_files into an exe, lib and obj list.

2018-05-31 Thread Mark Wielaard
Introduce testrun_on_self_exe and testrun_on_self_lib.
Some tests cannot handle (unrelocated) ET_REL object files.
run-get-units-split.sh and run-unit-info.sh only handle executables
and shared libraries. This allows running the whole testsuite on an
elfutils build done with CFLAGS="-gdwarf-4 -gsplit-dwarf -O2".

Signed-off-by: Mark Wielaard 
---
 tests/ChangeLog  | 10 ++
 tests/run-get-units-split.sh |  5 +++--
 tests/run-unit-info.sh   |  5 +++--
 tests/test-subr.sh   | 39 +--
 4 files changed, 53 insertions(+), 6 deletions(-)

diff --git a/tests/ChangeLog b/tests/ChangeLog
index c03db54..1c1ef4e 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,5 +1,15 @@
 2018-05-31  Mark Wielaard  
 
+   * test-subr.sh (self_test_files): Split into self_test_files_exe,
+   self_test_files_lib and self_test_obj.
+   (testrun_on_self_exe): New function.
+   (testrun_on_self_lib): Likewise.
+   * run-get-units-split.sh: Replace testrun_on_self with
+   testrun_on_self_exe and testrun_on_self_lib.
+   * run-unit-info.sh: Likewise.
+
+2018-05-31  Mark Wielaard  
+
* low_high_pc.c (handle_die): Handle NULL name. Print offset and
name of die.
(main): Check if the cu DIE is a skeleton, then get and handle
diff --git a/tests/run-get-units-split.sh b/tests/run-get-units-split.sh
index 7b13694..7a43c67 100755
--- a/tests/run-get-units-split.sh
+++ b/tests/run-get-units-split.sh
@@ -59,7 +59,8 @@ Found a skeleton unit, with split die: world.c
 
 EOF
 
-# Self test
-testrun_on_self ${abs_builddir}/get-units-split
+# Self test (Not on obj files since those need relocation first).
+testrun_on_self_exe ${abs_builddir}/get-units-split
+testrun_on_self_lib ${abs_builddir}/get-units-split
 
 exit 0
diff --git a/tests/run-unit-info.sh b/tests/run-unit-info.sh
index f4ce427..328fe78 100755
--- a/tests/run-unit-info.sh
+++ b/tests/run-unit-info.sh
@@ -74,7 +74,8 @@ Iterate no info, compare recorded info with dwarf_cu_info.
 
 EOF
 
-# Self test
-testrun_on_self ${abs_builddir}/unit-info
+# Self test (not on obj files, since those need relocation first).
+testrun_on_self_exe ${abs_builddir}/unit-info
+testrun_on_self_lib ${abs_builddir}/unit-info
 
 exit 0
diff --git a/tests/test-subr.sh b/tests/test-subr.sh
index a765db6..ff60076 100644
--- a/tests/test-subr.sh
+++ b/tests/test-subr.sh
@@ -115,16 +115,25 @@ program_transform()
   echo "$*" | sed "${program_transform_name}"
 }
 
-self_test_files=`echo ${abs_top_builddir}/src/addr2line \
+self_test_files_exe=`echo ${abs_top_builddir}/src/addr2line \
 ${abs_top_builddir}/src/elfcmp ${abs_top_builddir}/src/elflint \
 ${abs_top_builddir}/src/nm ${abs_top_builddir}/src/objdump \
 ${abs_top_builddir}/src/readelf \
-${abs_top_builddir}/src/size.o ${abs_top_builddir}/src/strip.o \
 ${abs_top_builddir}/libelf/libelf.so \
 ${abs_top_builddir}/libdw/libdw.so \
 ${abs_top_builddir}/backends/libebl_i386.so \
 ${abs_top_builddir}/backends/libebl_x86_64.so`
 
+self_test_files_lib=`echo ${abs_top_builddir}/libelf/libelf.so \
+${abs_top_builddir}/libdw/libdw.so \
+${abs_top_builddir}/backends/libebl_i386.so \
+${abs_top_builddir}/backends/libebl_x86_64.so`
+
+self_test_files_obj=`echo ${abs_top_builddir}/src/size.o \
+${abs_top_builddir}/src/strip.o`
+
+self_test_files="$self_test_files_exe $self_test_files_lib 
$self_test_files_obj"
+
 # Provide a command to run on all self-test files with testrun.
 testrun_on_self()
 {
@@ -139,6 +148,32 @@ testrun_on_self()
   if test $exit_status != 0; then exit $exit_status; fi
 }
 
+testrun_on_self_exe()
+{
+  exit_status=0
+
+  for file in $self_test_files_exe; do
+  testrun $* $file \
+ || { echo "*** failure in $* $file"; exit_status=1; }
+  done
+
+  # Only exit if something failed
+  if test $exit_status != 0; then exit $exit_status; fi
+}
+
+testrun_on_self_lib()
+{
+  exit_status=0
+
+  for file in $self_test_files_lib; do
+  testrun $* $file \
+ || { echo "*** failure in $* $file"; exit_status=1; }
+  done
+
+  # Only exit if something failed
+  if test $exit_status != 0; then exit $exit_status; fi
+}
+
 # Compress the files first. Compress both debug sections and symtab.
 testrun_on_self_compressed()
 {
-- 
1.8.3.1



Re: [PATCH] readelf, libdw: Add GNU DebugFission .debug_loc support.

2018-05-31 Thread Mark Wielaard
On Tue, 2018-05-29 at 12:08 +0200, Mark Wielaard wrote:
> GNU DebugFission .debug_loc location lists uses the .debug_loc section
> in the split dwarf .dwo file. The encoding is a mix of old style DWARF
> .debug_loc and new style .debug_loclists.

Pushed to master.


Re: [PATCH] libdw: Handle split Dwarf Dies in dwarf_die_addr_die.

2018-05-31 Thread Mark Wielaard
On Wed, 2018-05-30 at 00:11 +0200, Mark Wielaard wrote:
> On Tue, 2018-05-29 at 23:57 +0200, Mark Wielaard wrote:
> > dwarf_die_addr_die can be used to turn an Dwarf_Die addr back into a
> > full Dwarf_Die, just given the original Dwarf debug handle. This now
> > also works for Dwarf_Dies which originated from a split Dwarf. Whenever
> > a split Dwarf_CU is found the Dwarf it originated from is registered
> > with the Dwarf that the skeleton Dwarf_CU came from. All registered
> > split Dwarfs are then searched by dwarf_die_addr_die if the addr didn't
> > match the main Dwarf or the alt Dwarf.
> > 
> > One limitation in this implementation is that only DIEs that come from
> > the main .debug_info in the .dwo are supported. Theoretically there could
> > also be DIEs in an .debug_type or from other/multiple (comdat) sections.
> > 
> > New tests are added for dwarf-4, dwarf-5, split-dwarf-4, split-dwarf-5
> > and version 4 and 5 dwo files.
> 
> And clearly I hadn't done a make distcheck because then I would have
> known that valgrind would warn about leaking the new search tree.

Pushed to master, including the tdestoy fix for the leak.


Re: [PATCH] libdw: Don't crash on invalid die in dwarf_dieoffset.

2018-05-31 Thread Mark Wielaard
On Thu, May 31, 2018 at 01:02:44PM +0200, Mark Wielaard wrote:
> Add explicit test in get-units-invalid for dwarf_cuoffset and
> dwarf_dieoffset.

And that test caught another bug on 32bit systems!

>  Dwarf_Off
>  dwarf_dieoffset (Dwarf_Die *die)
>  {
> -  return (die == NULL
> +  return ((die == NULL || die->cu == NULL)
> ? ~0ul
> : (Dwarf_Off) (die->addr - die->cu->startp + die->cu->start));

Note that ~0ul != (Dwarf_Off) -1 on 32bit systems.
So error detection was always broken.

The reason we didn't notice before was because we had a similar bug
in eu-readelf...

I am checking in the attached patch which fixes both.
>From aa02fb9028abcadaa18440b86b1ed085e029956c Mon Sep 17 00:00:00 2001
From: Mark Wielaard 
Date: Thu, 31 May 2018 13:01:39 +0200
Subject: [PATCH] libdw: Don't crash on invalid die in dwarf_dieoffset.

Add explicit test in get-units-invalid for dwarf_cuoffset and
dwarf_dieoffset. Make sure dwarf_dieoffset returns (Dwarf_Off) -1
on failure.

Signed-off-by: Mark Wielaard 
---
 libdw/ChangeLog   |  5 +
 libdw/dwarf_dieoffset.c   |  4 ++--
 src/ChangeLog |  4 
 src/readelf.c |  2 +-
 tests/ChangeLog   |  5 +
 tests/get-units-invalid.c | 14 +-
 6 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 5a33d9c..38b45ba 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,8 @@
+2018-05-31  Mark Wielaard  
+
+	* dwarf_dieoffset.c: Check die->cu != NULL. Return -1, not ~0ul
+	on failure.
+
 2018-05-29  Mark Wielaard  
 
 	* dwarf_cuoffset.c (dwarf_cuoffset): Check die->cu is not NULL.
diff --git a/libdw/dwarf_dieoffset.c b/libdw/dwarf_dieoffset.c
index 8028f6d..3a8e2cb 100644
--- a/libdw/dwarf_dieoffset.c
+++ b/libdw/dwarf_dieoffset.c
@@ -38,8 +38,8 @@
 Dwarf_Off
 dwarf_dieoffset (Dwarf_Die *die)
 {
-  return (die == NULL
-	  ? ~0ul
+  return ((die == NULL || die->cu == NULL)
+	  ? (Dwarf_Off) -1
 	  : (Dwarf_Off) (die->addr - die->cu->startp + die->cu->start));
 }
 INTDEF(dwarf_dieoffset)
diff --git a/src/ChangeLog b/src/ChangeLog
index f424fb7..03ed5aa 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,7 @@
+2018-05-31  Mark Wielaard  
+
+	* readelf.c (print_debug_units): Check offset against -1 not ~0ul.
+
 2018-05-29  Mark Wielaard  
 
 	* readelf.c (print_debug_loc_section): Handle GNU DebugFission list
diff --git a/src/readelf.c b/src/readelf.c
index 2ccbea5..470a94e 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -7588,7 +7588,7 @@ print_debug_units (Dwfl_Module *dwflmod,
   do
 {
   Dwarf_Off offset = dwarf_dieoffset (&dies[level]);
-  if (unlikely (offset == ~0ul))
+  if (unlikely (offset == (Dwarf_Off) -1))
 	{
 	  if (!silent)
 	error (0, 0, gettext ("cannot get DIE offset: %s"),
diff --git a/tests/ChangeLog b/tests/ChangeLog
index b656bee..521df52 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,8 @@
+2018-05-31  Mark Wielaard  
+
+	* get-units-invalid.c (main): Check dwarf_cuoffset and
+	dwarf_dieoffset.
+
 2018-05-29  Mark Wielaard  
 
 	* dwarf-die-addr-die.c (check_dbg): Also check subdies, split or
diff --git a/tests/get-units-invalid.c b/tests/get-units-invalid.c
index 58b32c0..ba0f818 100644
--- a/tests/get-units-invalid.c
+++ b/tests/get-units-invalid.c
@@ -83,7 +83,19 @@ main (int argc, char *argv[])
 	  if (dwarf_ranges (&subdie, 0, &base, &start, &end) != -1)
 		{
 		  printf ("Should NOT have a ranges: %s\n",
-			  dwarf_diename (&result));
+			  dwarf_diename (&subdie));
+		  return -1;
+		}
+	  if (dwarf_cuoffset (&subdie) != (Dwarf_Off) -1)
+		{
+		  printf ("Should NOT have a cuoffset: %s\n",
+			  dwarf_diename (&subdie));
+		  return -1;
+		}
+	  if (dwarf_dieoffset (&subdie) != (Dwarf_Off) -1)
+		{
+		  printf ("Should NOT have a die offset: %s\n",
+			  dwarf_diename (&subdie));
 		  return -1;
 		}
 	}
-- 
1.8.3.1



[Bug tools/23247] Segfault in 0.171 RC1 release candidate

2018-05-31 Thread mark at klomp dot org
https://sourceware.org/bugzilla/show_bug.cgi?id=23247

Mark Wielaard  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |FIXED

--- Comment #4 from Mark Wielaard  ---
commit 84acd2365d4775b93aed5e5970b34db05ea5d547
Author: Mark Wielaard 
Date:   Wed May 30 11:54:31 2018 +0200

readelf: Use correct listptr when looking up next loc for locview attr.

We were using loclistsptr instead of locsptr in print_debug_loc_section.

https://sourceware.org/bugzilla/show_bug.cgi?id=23247

Signed-off-by: Mark Wielaard 

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Re: [PATCH] readelf: Use correct listptr when looking up next loc for locview attr.

2018-05-31 Thread Mark Wielaard
On Wed, May 30, 2018 at 12:04:48PM +0200, Mark Wielaard wrote:
> We were using loclistsptr instead of locsptr in print_debug_loc_section.
> 
> https://sourceware.org/bugzilla/show_bug.cgi?id=23247

Pushed to master.


[Bug tools/23248] armv7l: dwarf_getsrclines.c:362:37: error: argument 1 value '4294967288' exceeds maximum object size 2147483647 [-Werror=alloc-size-larger-than=]

2018-05-31 Thread mark at klomp dot org
https://sourceware.org/bugzilla/show_bug.cgi?id=23248

Mark Wielaard  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |FIXED

--- Comment #4 from Mark Wielaard  ---
commit 3a5bbc919873fc8adee7345dd7dec585eb4d2547 (wildebeest/buildbot,
origin/master, origin/HEAD, master, buildbot)
Author: Mark Wielaard 
Date:   Wed May 30 15:51:12 2018 +0200

libdw: Fix overflow warning on 32bit systems with GCC8 in
dwarf_getsrclines.

ndirs is read from the debug data and should be size checked before use.

https://sourceware.org/bugzilla/show_bug.cgi?id=23248

Signed-off-by: Mark Wielaard 

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Re: [PATCH] libdw: Fix overflow warning on 32bit systems with GCC8 in dwarf_getsrclines.

2018-05-31 Thread Mark Wielaard
On Wed, May 30, 2018 at 03:54:52PM +0200, Mark Wielaard wrote:
> ndirs is read from the debug data and should be size checked before use.
> 
> https://sourceware.org/bugzilla/show_bug.cgi?id=23248

Pushed to master.


[PATCH] readelf: Deal with combined normal and split dwarf DebugFission .debug_loc.

2018-05-31 Thread Mark Wielaard
Normal and split dwarf from GNU DebugFission look the same, but should
be treated competely separtely. When having a file with both skeletons
and real compile units only note the secoffsets into the real .debug_loc
in readelf. Otherwise or known_locslistptr will get confused.

Add a testfile that combines an normal -gdwarf-4 object with a
-gsplit-dwarf object. libdw already got this right, but add a
run-varlocs.sh test to make sure.

Signed-off-by: Mark Wielaard 
---
 src/ChangeLog   |   5 +
 src/readelf.c   |  14 +-
 tests/ChangeLog |  10 +
 tests/Makefile.am   |   2 +
 tests/run-readelf-loc.sh| 289 
 tests/run-varlocs.sh|  42 
 tests/splitdwarf4-not-split4.dwo.bz2| Bin 0 -> 931 bytes
 tests/testfile-splitdwarf4-not-split4.debug.bz2 | Bin 0 -> 2230 bytes
 8 files changed, 359 insertions(+), 3 deletions(-)
 create mode 100644 tests/splitdwarf4-not-split4.dwo.bz2
 create mode 100755 tests/testfile-splitdwarf4-not-split4.debug.bz2

diff --git a/src/ChangeLog b/src/ChangeLog
index 95f8a72..55e735b 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,10 @@
 2018-05-31  Mark Wielaard  
 
+   * readelf.c (attr_callback): Only register section_loc when not
+   looking at a split dwarf from a skeleton.
+
+2018-05-31  Mark Wielaard  
+
* readelf.c (print_debug_units): Print the dwo name and id when
unable to find a .dwo file.
 
diff --git a/src/readelf.c b/src/readelf.c
index 8d85dc8..e2d9c69 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -7077,9 +7077,17 @@ attr_callback (Dwarf_Attribute *attrp, void *arg)
  {
bool nlpt;
if (cbargs->cu->version < 5)
- nlpt = notice_listptr (section_loc, &known_locsptr,
-cbargs->addrsize, cbargs->offset_size,
-cbargs->cu, num, attr);
+ {
+   if (! cbargs->is_split)
+ {
+   nlpt = notice_listptr (section_loc, &known_locsptr,
+  cbargs->addrsize,
+  cbargs->offset_size,
+  cbargs->cu, num, attr);
+ }
+   else
+ nlpt = true;
+ }
else
  {
/* Only register for a real section offset.  Otherwise
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 1c1ef4e..04b6e75 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,5 +1,15 @@
 2018-05-31  Mark Wielaard  
 
+   * splitdwarf4-not-split4.dwo.bz2: New test file.
+   * testfile-splitdwarf4-not-split4.debug.bz2: Likewise.
+   * run-readelf-loc.sh: Add test for splitdwarf4-not-split4.dwo
+   and testfile-splitdwarf4-not-split4.debug.
+   * run-varlocs.sh: Test testfile-splitdwarf4-not-split4.debug.
+   * Makefile.am (EXTRA_DIST): Add splitdwarf4-not-split4.dwo.bz2
+   and testfile-splitdwarf4-not-split4.debug.bz2.
+
+2018-05-31  Mark Wielaard  
+
* test-subr.sh (self_test_files): Split into self_test_files_exe,
self_test_files_lib and self_test_obj.
(testrun_on_self_exe): New function.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index e935410..28ba9f7 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -238,6 +238,8 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \
 testfile-macros-0xff.bz2 \
 run-readelf-macro.sh testfilemacro.bz2 \
 run-readelf-loc.sh testfileloc.bz2 \
+splitdwarf4-not-split4.dwo.bz2 \
+testfile-splitdwarf4-not-split4.debug.bz2 \
 run-readelf-ranges.sh \
 run-readelf-aranges.sh run-readelf-line.sh testfilefoobarbaz.bz2 \
 testfile-ppc64-min-instr.bz2 \
diff --git a/tests/run-readelf-loc.sh b/tests/run-readelf-loc.sh
index 484db46..bf676f2 100755
--- a/tests/run-readelf-loc.sh
+++ b/tests/run-readelf-loc.sh
@@ -868,4 +868,293 @@ DWARF section [ 3] '.debug_loc.dwo' at offset 0x225:
[ 0] reg5
 EOF
 
+# Partial dwarf-4 and partial GNU DebugFission split-dwarf.
+#
+# = popcount.c =
+#
+# int popcount (unsigned char u)
+# {
+#   int c = 0;
+#   while (u != 0)
+# {
+#   if ((u & 1) == 1)
+# c++;
+#   u >>= 1;
+# }
+#   return c;
+# }
+#
+# = splitdwarf4-not-split4.c =
+#
+# extern int popcount (unsigned char);
+#
+# int main (int argc, char **argv)
+# {
+#   int i;
+#   int p = argc;
+#   for (i = 0; i < argc;  ++i)
+# p += popcount (argv[i][0]);
+#   i += p;
+#   return i;
+# }
+#
+# gcc -gdwarf-4 -O2 -c popcount.c
+# gcc -gdwarf-4 -gsplit-dwarf -O2 -c splitdwarf4-not-split4.c
+# gcc -o testfile-splitdwarf4-not-split4 splitdwarf4-not-split4.o popcount.o
+# eu-strip -f testfile-splitdwarf4-not-sp

[PATCH] readelf: Fix .debug_types printing with implicit section_info.

2018-05-31 Thread Mark Wielaard
Commit 314e9d7d "readelf: Handle .debug_info first if any other debug
section needs it" disabled section_info printing if it was already
handled. But section_types was an alias for section_info. So unless
section_info was explicitly printed, .debug_types wasn't.

Make section_types its own thing to print .debug_types and make
section_info imply section_types. Add a testcase to make sure
.debug_types is now printed.

Signed-off-by: Mark Wielaard 
---
 src/ChangeLog  |   9 
 src/readelf.c  |  16 +++---
 tests/ChangeLog|   6 +++
 tests/Makefile.am  |   2 +
 tests/run-readelf-types.sh | 122 +
 5 files changed, 149 insertions(+), 6 deletions(-)
 create mode 100755 tests/run-readelf-types.sh

diff --git a/src/ChangeLog b/src/ChangeLog
index 55e735b..fc41892 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,14 @@
 2018-05-31  Mark Wielaard  
 
+   * readelf.c (enum section_e): Make section_types not an alias of
+   section_info.
+   (section_all): Add section_types.
+   (parse_opt): Add both section_info and section_types for "info"
+   and "info+".
+   (print_debug_units): Don't be silent for debug_types.
+
+2018-05-31  Mark Wielaard  
+
* readelf.c (attr_callback): Only register section_loc when not
looking at a split dwarf from a skeleton.
 
diff --git a/src/readelf.c b/src/readelf.c
index e2d9c69..78e3cd7 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -237,8 +237,7 @@ static enum section_e
   section_abbrev = 1,  /* .debug_abbrev  */
   section_aranges = 2, /* .debug_aranges  */
   section_frame = 4,   /* .debug_frame or .eh_frame & al.  */
-  section_info = 8,/* .debug_info, .debug_types  */
-  section_types = section_info,
+  section_info = 8,/* .debug_info, (implies .debug_types)  */
   section_line = 16,   /* .debug_line  */
   section_loc = 32,/* .debug_loc  */
   section_pubnames = 64,   /* .debug_pubnames  */
@@ -248,12 +247,13 @@ static enum section_e
   section_exception = 1024,/* .eh_frame & al.  */
   section_gdb_index = 2048,/* .gdb_index  */
   section_macro = 4096,/* .debug_macro  */
-  section_addr = 8192,
+  section_addr = 8192, /* .debug_addr  */
+  section_types = 16384,   /* .debug_types (implied by .debug_info)  */
   section_all = (section_abbrev | section_aranges | section_frame
 | section_info | section_line | section_loc
 | section_pubnames | section_str | section_macinfo
 | section_ranges | section_exception | section_gdb_index
-| section_macro | section_addr)
+| section_macro | section_addr | section_types)
 } print_debug_sections, implicit_debug_sections;
 
 /* Select hex dumping of sections.  */
@@ -463,10 +463,14 @@ parse_opt (int key, char *arg,
   else if (strcmp (arg, "frame") == 0 || strcmp (arg, "frames") == 0)
print_debug_sections |= section_frame;
   else if (strcmp (arg, "info") == 0)
-   print_debug_sections |= section_info;
+   {
+ print_debug_sections |= section_info;
+ print_debug_sections |= section_types;
+   }
   else if (strcmp (arg, "info+") == 0)
{
  print_debug_sections |= section_info;
+ print_debug_sections |= section_types;
  show_split_units = true;
}
   else if (strcmp (arg, "loc") == 0)
@@ -7448,7 +7452,7 @@ print_debug_units (Dwfl_Module *dwflmod,
   Elf_Scn *scn, GElf_Shdr *shdr,
   Dwarf *dbg, bool debug_types)
 {
-  const bool silent = !(print_debug_sections & section_info);
+  const bool silent = !(print_debug_sections & section_info) && !debug_types;
   const char *secname = section_name (ebl, ehdr, shdr);
 
   if (!silent)
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 04b6e75..e3599b2 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,5 +1,11 @@
 2018-05-31  Mark Wielaard  
 
+   * run-readelf-types.sh: New test.
+   * Makefile.am (TESTS): Add run-readelf-types.sh.
+   (EXTRA_DIST): Likewise.
+
+2018-05-31  Mark Wielaard  
+
* splitdwarf4-not-split4.dwo.bz2: New test file.
* testfile-splitdwarf4-not-split4.debug.bz2: Likewise.
* run-readelf-loc.sh: Add test for splitdwarf4-not-split4.dwo
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 28ba9f7..b45ecdc 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -131,6 +131,7 @@ TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile 
test-nlist \
run-backtrace-demangle.sh run-stack-d-test.sh run-stack-i-test.sh \
run-stack-demangled-test.sh run-readelf-zx.sh run-readelf-zp.sh \
run-readelf-addr.sh run-readelf-str.sh \
+   run-readelf-types.sh \
run-readelf-dwz-multi.sh run-allfcts-multi.sh run-deleted.sh \
run-linkmap-cut.sh run-aggregate-size.sh run-p