Blame SOURCES/memstomp-rh1133815.patch

6c0663
diff -Nrup a/memstomp.c b/memstomp.c
6c0663
--- a/memstomp.c	2014-08-26 13:13:30.004485804 -0600
6c0663
+++ b/memstomp.c	2014-08-26 13:17:00.450138891 -0600
6c0663
@@ -241,6 +241,16 @@ static char* generate_stacktrace(void)
6c0663
         int const n = real_backtrace(retaddr, frames_max);
6c0663
         assert(n >= 0);
6c0663
 
6c0663
+	/* Adjust the frame addresses since they point to the next
6c0663
+	   instruction to execute, not the call site which may be
6c0663
+	   associated with different line numbers. 
6c0663
+
6c0663
+	   For the cases we care about in memstomp, just subtracting
6c0663
+	   1 works the vast majority of the time.  It may not work for
6c0663
+	   a tail-call into an intercepted routine though.  */
6c0663
+	for (int i = 0; i < n; i++)
6c0663
+		retaddr[i]--;
6c0663
+	    
6c0663
         char **const strings = real_backtrace_symbols(retaddr, n);
6c0663
         assert(strings);
6c0663
 
6c0663
diff -Nrup a/testsuite/lib/memstomp.exp b/testsuite/lib/memstomp.exp
6c0663
--- a/testsuite/lib/memstomp.exp	2014-08-26 13:13:29.964485869 -0600
6c0663
+++ b/testsuite/lib/memstomp.exp	2014-08-26 14:29:37.334241044 -0600
6c0663
@@ -13,3 +13,11 @@ proc find_libmemstomp {} {
6c0663
   set file [findfile $base_dir/../.libs/libmemstomp.so $base_dir/../.libs/libmemstomp.so libmemstomp.so]
6c0663
   return $file
6c0663
 }
6c0663
+
6c0663
+proc find_libmemstomp_backtrace_symbols {} {
6c0663
+  global tool_root_dir 
6c0663
+  global base_dir
6c0663
+
6c0663
+  set file [findfile $base_dir/../.libs/libmemstomp-backtrace-symbols.so $base_dir/../.libs/libmemstomp-backtrace-symbols.so libmemstomp-backtrace-symbols.so]
6c0663
+  return $file
6c0663
+}
6c0663
diff -Nrup a/testsuite/memstomp.lineinfo/linenumber.c b/testsuite/memstomp.lineinfo/linenumber.c
6c0663
--- a/testsuite/memstomp.lineinfo/linenumber.c	1969-12-31 17:00:00.000000000 -0700
6c0663
+++ b/testsuite/memstomp.lineinfo/linenumber.c	2014-08-26 13:23:12.535518727 -0600
6c0663
@@ -0,0 +1,23 @@
6c0663
+#define __NO_STRING_INLINES
6c0663
+#include <string.h>
6c0663
+
6c0663
+void
6c0663
+something (void)
6c0663
+{
6c0663
+  char a[20] = "     hello";
6c0663
+  memcpy (a, a + 5, 6);
6c0663
+}
6c0663
+
6c0663
+void
6c0663
+nothing (void)
6c0663
+{
6c0663
+  something ();
6c0663
+}
6c0663
+
6c0663
+int
6c0663
+main (void)
6c0663
+{
6c0663
+  nothing ();
6c0663
+  return 0;
6c0663
+}
6c0663
+
6c0663
diff -Nrup a/testsuite/memstomp.lineinfo/linenumber.exp b/testsuite/memstomp.lineinfo/linenumber.exp
6c0663
--- a/testsuite/memstomp.lineinfo/linenumber.exp	1969-12-31 17:00:00.000000000 -0700
6c0663
+++ b/testsuite/memstomp.lineinfo/linenumber.exp	2014-08-26 17:49:55.493353200 -0600
6c0663
@@ -0,0 +1,65 @@
6c0663
+# Copyright (C) 2014 Free Software Foundation, Inc.
6c0663
+
6c0663
+# This program is free software; you can redistribute it and/or modify
6c0663
+# it under the terms of the GNU General Public License as published by
6c0663
+# the Free Software Foundation; either version 3 of the License, or
6c0663
+# (at your option) any later version.
6c0663
+#
6c0663
+# This program is distributed in the hope that it will be useful,
6c0663
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
6c0663
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6c0663
+# GNU General Public License for more details.
6c0663
+#
6c0663
+# You should have received a copy of the GNU General Public License
6c0663
+# along with GCC; see the file COPYING3.  If not see
6c0663
+# <http://www.gnu.org/licenses/>.
6c0663
+#
6c0663
+# This was originally copied from GCC's dejagnu testing framework
6c0663
+#
6c0663
+# This is a hack.  If we need more of these tests we'll want to use
6c0663
+# something like dj's framework so that we can mark the lines where
6c0663
+# we want errors/warnings.
6c0663
+#
6c0663
+
6c0663
+load_lib memstomp.exp
6c0663
+set libmemstomp [find_libmemstomp]
6c0663
+set libmemstomp_backtrace_symbols [find_libmemstomp_backtrace_symbols]
6c0663
+
6c0663
+if $tracelevel then {
6c0663
+    strace $tracelevel
6c0663
+}
6c0663
+
6c0663
+#
6c0663
+# main test loop
6c0663
+#
6c0663
+
6c0663
+proc compile-and-execute { sources } {
6c0663
+  global libmemstomp
6c0663
+  global libmemstomp_backtrace_symbols
6c0663
+
6c0663
+  set src [lindex $sources 0]
6c0663
+
6c0663
+  if {[catch {exec gcc -g -fno-builtin $src} results]} {
6c0663
+    fail "$src compilation $results"
6c0663
+  } else {
6c0663
+    pass "$src compilation $results"
6c0663
+  }
6c0663
+
6c0663
+  # ARM's unwinder seems broken
6c0663
+  setup_xfail arm*-*-*
6c0663
+  catch {exec /bin/bash -c "LD_PRELOAD=$libmemstomp:$libmemstomp_backtrace_symbols ./a.out"} results
6c0663
+  if {[regexp "linenumber.c:8" $results]} {
6c0663
+    pass "$src found overlap on right line $results"
6c0663
+  } else {
6c0663
+    fail "$src found overlap on right line $results"
6c0663
+  }
6c0663
+}
6c0663
+
6c0663
+foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.c]] {
6c0663
+    # If we're only testing specific files and this isn't one of them, skip it.
6c0663
+    if ![runtest_file_p $runtests $src] then {
6c0663
+        continue
6c0663
+    }
6c0663
+
6c0663
+   compile-and-execute $src
6c0663
+}
6c0663
diff -Nrup a/testsuite/memstomp.overlap/linenumber.c b/testsuite/memstomp.overlap/linenumber.c
6c0663
--- a/testsuite/memstomp.overlap/linenumber.c	1969-12-31 17:00:00.000000000 -0700
6c0663
+++ b/testsuite/memstomp.overlap/linenumber.c	2014-08-26 13:17:30.057090085 -0600
6c0663
@@ -0,0 +1,23 @@
6c0663
+#define __NO_STRING_INLINES
6c0663
+#include <string.h>
6c0663
+
6c0663
+void
6c0663
+something (void)
6c0663
+{
6c0663
+  char a[20] = "     hello";
6c0663
+  memcpy (a, a + 5, 6);
6c0663
+}
6c0663
+
6c0663
+void
6c0663
+nothing (void)
6c0663
+{
6c0663
+  something ();
6c0663
+}
6c0663
+
6c0663
+int
6c0663
+main (void)
6c0663
+{
6c0663
+  nothing ();
6c0663
+  return 0;
6c0663
+}
6c0663
+