kunit: improved sigsegv stack trace printing

Sacrificed the control of printing stack trace within the crash handler
in the test runner for getting a better stack trace; this is still not
ideal, but much better than before.

Change-Id: I9b58ed736733895aa3ededc3829637c4271d91c1
Signed-off-by: Brendan Higgins <brendanhiggins@google.com>
diff --git a/arch/um/kernel/trap.c b/arch/um/kernel/trap.c
index bf90e67..b4f09ff 100644
--- a/arch/um/kernel/trap.c
+++ b/arch/um/kernel/trap.c
@@ -226,8 +226,17 @@
 		current->thread.segv_regs = container_of(regs, struct pt_regs, regs);
 
 	catcher = current->thread.fault_catcher;
-	if (catcher && current->thread.is_running_test)
+	if (catcher && current->thread.is_running_test) {
+		/*
+		 * TODO(b/77223210): Right now we don't have a way to store a
+		 * copy of the stack, or a copy of information from the stack,
+		 * so we need to print it now; otherwise, the stack will be
+		 * destroyed by segv_run_catcher which works by popping off
+		 * stack frames.
+		 */
+		show_stack(NULL, NULL);
 		segv_run_catcher(catcher, (void *) address);
+	}
 	else if (!is_user && (address >= start_vm) && (address < end_vm)) {
 		flush_tlb_kernel_vm();
 		goto out;
diff --git a/test/test.c b/test/test.c
index c471c378..4855d18b 100644
--- a/test/test.c
+++ b/test/test.c
@@ -158,12 +158,17 @@
 				   struct test_module *module,
 				   struct test_case *test_case)
 {
-	test_err(test, "%s crashed", test_case->name);
 	/*
-	 * TODO(brendanhiggins@google.com): This prints the stack trace up
-	 * through this frame, not up to the frame that caused the crash.
+	 * TODO(brendanhiggins@google.com): Right now we don't have a way to
+	 * store a copy of the stack, or a copy of information from the stack,
+	 * so we need to print it in the "trap" handler; otherwise, the stack
+	 * will be destroyed when it returns to us by popping off the
+	 * appropriate stack frames (see longjmp).
+	 *
+	 * Ideally we would print the stack trace here, but we do not have the
+	 * ability to do so with meaningful information at this time.
 	 */
-	show_stack(NULL, NULL);
+	test_err(test, "%s crashed", test_case->name);
 
 	test_case_internal_cleanup(test);
 }