From 47efc3bef9f39a0494f9957b2e5f7da33482865b Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mjw@redhat.com>
Date: Wed, 14 Jan 2015 21:38:16 +0100
Subject: [PATCH] tests: Add testfile-debug-types test case.

Test for regression fixed in commit 7c713822:
"libdw: fix offset for sig8 lookup in dwarf_formref_die"

Signed-off-by: Mark Wielaard <mjw@redhat.com>
---
 tests/ChangeLog                |   7 +++++++
 tests/Makefile.am              |   5 +++--
 tests/run-typeiter.sh          |  14 +++++++++++---
 tests/testfile-debug-types.bz2 | Bin 0 -> 3024 bytes
 tests/typeiter2.c              |   6 ++++--
 5 files changed, 25 insertions(+), 7 deletions(-)
 create mode 100755 tests/testfile-debug-types.bz2

diff --git a/tests/ChangeLog b/tests/ChangeLog
index 6dd553b..365d98d 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,10 @@
+2015-01-14  Mark Wielaard  <mjw@redhat.com>
+
+	* testfile-debug-types.bz2: New testfile.
+	* Makefile.am (EXTRA_DIST): Add testfile-debug-types.bz2.
+	* typeiter2.c (main): Print both name and offset of found form DIE.
+	* run-typeiter.s: Adjust output and add testfile-debug-types.
+
 2014-12-26  Mark Wielaard  <mjw@redhat.com>
 
 	* run-test-archive64.sh: Add nm test.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 303f783..14adebd 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,6 +1,6 @@
 ## Process this file with automake to create Makefile.in
 ##
-## Copyright (C) 1996-2014 Red Hat, Inc.
+## Copyright (C) 1996-2015 Red Hat, Inc.
 ## This file is part of elfutils.
 ##
 ## This file is free software; you can redistribute it and/or modify
@@ -280,7 +280,8 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \
 	     linkmap-cut.bz2 linkmap-cut.core.bz2 \
 	     run-aggregate-size.sh testfile-sizes1.o.bz2 testfile-sizes2.o.bz2 \
 	     testfile-sizes3.o.bz2 \
-	     run-readelf-A.sh testfileppc32attrs.o.bz2
+	     run-readelf-A.sh testfileppc32attrs.o.bz2 \
+	     testfile-debug-types.bz2
 
 if USE_VALGRIND
 valgrind_cmd='valgrind -q --error-exitcode=1 --run-libc-freeres=no'
diff --git a/tests/run-typeiter.sh b/tests/run-typeiter.sh
index 605ee2a..2687bab 100755
--- a/tests/run-typeiter.sh
+++ b/tests/run-typeiter.sh
@@ -1,5 +1,5 @@
 #! /bin/sh
-# Copyright (C) 2012 Red Hat, Inc.
+# Copyright (C) 2012, 2015 Red Hat, Inc.
 # This file is part of elfutils.
 #
 # This file is free software; you can redistribute it and/or modify
@@ -41,14 +41,22 @@
 #
 # g++ -gdwarf-4 -g -fdebug-types-section
 
-testfiles testfile59
+# echo 'struct A{ struct B {} x;};A a; A::B b;int main(){return 0;}' \
+#  | g++ -x c++  -g -fdebug-types-section -o testfile-debug-types -
+
+testfiles testfile59 testfile-debug-types
 
 testrun_compare ${abs_builddir}/typeiter testfile59 <<\EOF
 ok
 EOF
 
 testrun_compare ${abs_builddir}/typeiter2 testfile59 <<\EOF
-ok
+ok s1 [25]
+EOF
+
+testrun_compare ${abs_builddir}/typeiter2 testfile-debug-types <<\EOF
+ok A [68]
+ok B [38]
 EOF
 
 exit 0
diff --git a/tests/testfile-debug-types.bz2 b/tests/testfile-debug-types.bz2
new file mode 100755
index 0000000000000000000000000000000000000000..a41f4938cee6ad6994f716b592b9d1d09e64cdbd
GIT binary patch
diff --git a/tests/typeiter2.c b/tests/typeiter2.c
index 6ddfa38..35b6a12 100644
--- a/tests/typeiter2.c
+++ b/tests/typeiter2.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2012, 2013 Red Hat, Inc.
+/* Copyright (C) 2012, 2013, 2015 Red Hat, Inc.
    This file is part of elfutils.
 
    This file is free software; you can redistribute it and/or modify
@@ -23,6 +23,7 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <dwarf.h>
+#include <inttypes.h>
 
 int
 main (int argc, char *argv[])
@@ -71,7 +72,8 @@ main (int argc, char *argv[])
 		      if (form == NULL)
 			printf ("fail\n");
 		      else
-			printf ("ok\n");
+			printf ("ok %s [%" PRIx64 "]\n",
+				dwarf_diename (form), dwarf_dieoffset (form));
 		    }
 
 		  if (dwarf_siblingof (iter, &iter_mem) != 0)
-- 
1.8.3.1

