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