[memstomp] +* Tue Aug 26 2014 Jeff Law <law at redhat.com> 0.1.4-15 +- Adjust PC values in saved frame addresses t

Jeffrey Law law at fedoraproject.org
Tue Aug 26 19:26:40 UTC 2014


commit 32da7d176252406beed8bd9a02be044a54f48f11
Author: Jeff Law <law at redhat.com>
Date:   Tue Aug 26 13:26:32 2014 -0600

    +* Tue Aug 26 2014 Jeff Law <law at redhat.com> 0.1.4-15
    +- Adjust PC values in saved frame addresses to get line number
    +  associations correct (#1133815).

 memstomp-rh1133815.patch |  141 ++++++++++++++++++++++++++++++++++++++++++++++
 memstomp.spec            |    8 ++-
 2 files changed, 148 insertions(+), 1 deletions(-)
---
diff --git a/memstomp-rh1133815.patch b/memstomp-rh1133815.patch
new file mode 100644
index 0000000..0f378a7
--- /dev/null
+++ b/memstomp-rh1133815.patch
@@ -0,0 +1,141 @@
+diff -Nrup a/memstomp.c b/memstomp.c
+--- a/memstomp.c	2014-08-26 13:13:30.004485804 -0600
++++ b/memstomp.c	2014-08-26 13:17:00.450138891 -0600
+@@ -241,6 +241,16 @@ static char* generate_stacktrace(void)
+         int const n = real_backtrace(retaddr, frames_max);
+         assert(n >= 0);
+ 
++	/* Adjust the frame addresses since they point to the next
++	   instruction to execute, not the call site which may be
++	   associated with different line numbers. 
++
++	   For the cases we care about in memstomp, just subtracting
++	   1 works the vast majority of the time.  It may not work for
++	   a tail-call into an intercepted routine though.  */
++	for (int i = 0; i < n; i++)
++		retaddr[i]--;
++	    
+         char **const strings = real_backtrace_symbols(retaddr, n);
+         assert(strings);
+ 
+diff -Nrup a/testsuite/memstomp.lineinfo/linenumber.c b/testsuite/memstomp.lineinfo/linenumber.c
+--- a/testsuite/memstomp.lineinfo/linenumber.c	1969-12-31 17:00:00.000000000 -0700
++++ b/testsuite/memstomp.lineinfo/linenumber.c	2014-08-26 13:23:12.535518727 -0600
+@@ -0,0 +1,23 @@
++#define __NO_STRING_INLINES
++#include <string.h>
++
++void
++something (void)
++{
++  char a[20] = "     hello";
++  memcpy (a, a + 5, 6);
++}
++
++void
++nothing (void)
++{
++  something ();
++}
++
++int
++main (void)
++{
++  nothing ();
++  return 0;
++}
++
+diff -Nrup a/testsuite/memstomp.lineinfo/linenumber.exp b/testsuite/memstomp.lineinfo/linenumber.exp
+--- a/testsuite/memstomp.lineinfo/linenumber.exp	1969-12-31 17:00:00.000000000 -0700
++++ b/testsuite/memstomp.lineinfo/linenumber.exp	2014-08-26 13:23:12.535518727 -0600
+@@ -0,0 +1,63 @@
++# Copyright (C) 2014 Free Software Foundation, Inc.
++
++# This program is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 3 of the License, or
++# (at your option) any later version.
++#
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with GCC; see the file COPYING3.  If not see
++# <http://www.gnu.org/licenses/>.
++#
++# This was originally copied from GCC's dejagnu testing framework
++#
++# This is a hack.  If we need more of these tests we'll want to use
++# something like dj's framework so that we can mark the lines where
++# we want errors/warnings.
++#
++
++load_lib memstomp.exp
++set memstomp [find_memstomp]
++set libmemstomp [find_libmemstomp]
++
++if $tracelevel then {
++    strace $tracelevel
++}
++
++#
++# main test loop
++#
++
++proc compile-and-execute { sources } {
++  global memstomp
++  global libmemstomp
++
++  set src [lindex $sources 0]
++
++  if {[catch {exec gcc -g -fno-builtin $src} results]} {
++    fail "$src compilation $results"
++  } else {
++    pass "$src compilation $results"
++  }
++
++  catch {exec /bin/bash -c "LD_PRELOAD=$libmemstomp $memstomp -d ./a.out"} results
++  if {[regexp "linenumber.c:8" $results]} {
++    pass "$src found overlap on right line $results"
++  } else {
++    fail "$src found overlap on right line $results"
++  }
++}
++
++foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.c]] {
++    # If we're only testing specific files and this isn't one of them, skip it.
++    if ![runtest_file_p $runtests $src] then {
++        continue
++    }
++
++   compile-and-execute $src
++}
+diff -Nrup a/testsuite/memstomp.overlap/linenumber.c b/testsuite/memstomp.overlap/linenumber.c
+--- a/testsuite/memstomp.overlap/linenumber.c	1969-12-31 17:00:00.000000000 -0700
++++ b/testsuite/memstomp.overlap/linenumber.c	2014-08-26 13:17:30.057090085 -0600
+@@ -0,0 +1,23 @@
++#define __NO_STRING_INLINES
++#include <string.h>
++
++void
++something (void)
++{
++  char a[20] = "     hello";
++  memcpy (a, a + 5, 6);
++}
++
++void
++nothing (void)
++{
++  something ();
++}
++
++int
++main (void)
++{
++  nothing ();
++  return 0;
++}
++
diff --git a/memstomp.spec b/memstomp.spec
index fbc62c0..ed4a77a 100644
--- a/memstomp.spec
+++ b/memstomp.spec
@@ -1,7 +1,7 @@
 %global	githash 38573e7d
 Name:		memstomp
 Version:	0.1.4
-Release:	14%{?dist}
+Release:	15%{?dist}
 Summary:	Warns of memory argument overlaps to various functions
 Group:		Development/Debuggers
 # The entire source code is LGPLV3+ with the exception of backtrace-symbols.c which
@@ -24,6 +24,7 @@ Patch2: memstomp-rh961495.patch
 Patch3: memstomp-rh962763.patch
 Patch4: memstomp-quietmode.patch
 Patch5: memstomp-rh1093173.patch
+Patch6: memstomp-rh1133815.patch
 
 
 %description 
@@ -42,6 +43,7 @@ overlapping memory arguments to certain library calls.
 %patch3 -p1
 %patch4 -p1
 %patch5 -p1
+%patch6 -p1
 
 
 %build
@@ -61,6 +63,10 @@ make install DESTDIR=$RPM_BUILD_ROOT
 %{_mandir}/man1/memstomp.1.gz
 
 %changelog
+* Tue Aug 26 2014 Jeff Law <law at redhat.com> 0.1.4-15
+- Adjust PC values in saved frame addresses to get line number
+  associations correct (#1133815).
+
 * Sun Aug 17 2014 Fedora Release Engineering <rel-eng at lists.fedoraproject.org> - 0.1.4-14
 - Rebuilt for https://fedoraproject.org/wiki/Fedora_21_22_Mass_Rebuild
 


More information about the scm-commits mailing list