Blame SOURCES/memstomp-rh1133815.patch

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