Blame SOURCES/memstomp-rh1133815.patch

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