Module Name:    src
Committed By:   joerg
Date:           Thu Jul  4 23:53:13 UTC 2013

Modified Files:
        src/tests/lib/libexecinfo: Makefile t_backtrace.c

Log Message:
Use conditional calls to vfork() to prevent the compiler from inlining
the intermediate stack frames. Mark the __start frame as optional.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libexecinfo/Makefile
cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libexecinfo/t_backtrace.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libexecinfo/Makefile
diff -u src/tests/lib/libexecinfo/Makefile:1.2 src/tests/lib/libexecinfo/Makefile:1.3
--- src/tests/lib/libexecinfo/Makefile:1.2	Sun May 27 22:57:24 2012
+++ src/tests/lib/libexecinfo/Makefile	Thu Jul  4 23:53:13 2013
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.2 2012/05/27 22:57:24 martin Exp $
+# $NetBSD: Makefile,v 1.3 2013/07/04 23:53:13 joerg Exp $
 
 .include <bsd.own.mk>
 
@@ -8,6 +8,5 @@ TESTS_C+=	t_backtrace
 
 LDADD+=		-lexecinfo -lelf
 DPADD+=		${LIBEXECINFO} ${LIBELF}
-DBG=-O0		# prevent inlining, nothing else helps.
 
 .include <bsd.test.mk>

Index: src/tests/lib/libexecinfo/t_backtrace.c
diff -u src/tests/lib/libexecinfo/t_backtrace.c:1.6 src/tests/lib/libexecinfo/t_backtrace.c:1.7
--- src/tests/lib/libexecinfo/t_backtrace.c:1.6	Thu Jun  6 17:40:09 2013
+++ src/tests/lib/libexecinfo/t_backtrace.c	Thu Jul  4 23:53:13 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_backtrace.c,v 1.6 2013/06/06 17:40:09 joerg Exp $	*/
+/*	$NetBSD: t_backtrace.c,v 1.7 2013/07/04 23:53:13 joerg Exp $	*/
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -29,29 +29,36 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_backtrace.c,v 1.6 2013/06/06 17:40:09 joerg Exp $");
+__RCSID("$NetBSD: t_backtrace.c,v 1.7 2013/07/04 23:53:13 joerg Exp $");
 
 #include <atf-c.h>
 #include <atf-c/config.h>
 #include <string.h>
 #include <stdlib.h>
 #include <execinfo.h>
+#include <unistd.h>
 
 #ifndef __arraycount
 #define __arraycount(a) (sizeof(a) / sizeof(a[0]))
 #endif
 
-static void __attribute__((__noinline__))
+volatile int prevent_inline;
+
+static void
 myfunc3(size_t ncalls)
 {
 	static const char *top[] = { "myfunc", "atfu_backtrace_fmt_basic_body",
 	    "atf_tc_run", "atf_tp_run", "atf_tp_main", "main", "___start" };
-	static bool optional_frame[] = { false, false, false, true, false, false, false };
+	static bool optional_frame[] = { false, false, false, true, false,
+	    false, true };
 	size_t j, nptrs, min_frames, max_frames;
 	void *buffer[ncalls + 10];
 	char **strings;
 	__CTASSERT(__arraycount(top) == __arraycount(optional_frame));
 
+	if (prevent_inline)
+		vfork();
+
 	min_frames = 0;
 	max_frames = 0;
 	for (j = 0; j < __arraycount(optional_frame); ++j) {
@@ -83,24 +90,33 @@ myfunc3(size_t ncalls)
 	free(strings);
 }
 
-static void __attribute__((__noinline__))
+static void
 myfunc2(size_t ncalls)
 {
+	if (prevent_inline)
+		vfork();
+
 	myfunc3(ncalls);
 }
 
-static void __attribute__((__noinline__))
+static void
 myfunc1(size_t origcalls, size_t ncalls)
 {
+	if (prevent_inline)
+		vfork();
+
 	if (ncalls > 1)
 		myfunc1(origcalls, ncalls - 1);
 	else
 		myfunc2(origcalls);
 }
 
-static void __attribute__((__noinline__))
+static void
 myfunc(size_t ncalls)
 {
+	if (prevent_inline)
+		vfork();
+
 	myfunc1(ncalls, ncalls);
 }
 

Reply via email to