Raise SIGTRAP rather than abort on failure.

If gdb is attached, it's convenient to be able to continue running.

Change-Id: I3bbb2634d05a08f6bad5425f71da2210dbb80cfe
Reviewed-on: https://boringssl-review.googlesource.com/5125
Reviewed-by: Adam Langley <agl@google.com>
diff --git a/crypto/test/malloc.cc b/crypto/test/malloc.cc
index 31da2c7..898f2a7 100644
--- a/crypto/test/malloc.cc
+++ b/crypto/test/malloc.cc
@@ -35,6 +35,7 @@
     !defined(OPENSSL_AARCH64) && !defined(OPENSSL_ASAN)
 
 #include <errno.h>
+#include <signal.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -46,14 +47,14 @@
 /* This file defines overrides for the standard allocation functions that allow
  * a given allocation to be made to fail for testing. If the program is run
  * with MALLOC_NUMBER_TO_FAIL set to a base-10 number then that allocation will
- * return NULL. If MALLOC_ABORT_ON_FAIL is also defined then the allocation
- * will abort() rather than return NULL.
+ * return NULL. If MALLOC_BREAK_ON_FAIL is also defined then the allocation
+ * will signal SIGTRAP rather than return NULL.
  *
  * This code is not thread safe. */
 
 static uint64_t current_malloc_count = 0;
 static uint64_t malloc_number_to_fail = 0;
-static char failure_enabled = 0, abort_on_fail = 0;
+static char failure_enabled = 0, break_on_fail = 0;
 static int in_call = 0;
 
 extern "C" {
@@ -96,7 +97,7 @@
         std::set_new_handler(cpp_new_handler);
       }
     }
-    abort_on_fail = (NULL != getenv("MALLOC_ABORT_ON_FAIL"));
+    break_on_fail = (NULL != getenv("MALLOC_BREAK_ON_FAIL"));
     init = 1;
   }
 
@@ -109,8 +110,8 @@
   should_fail = (current_malloc_count == malloc_number_to_fail);
   current_malloc_count++;
 
-  if (should_fail && abort_on_fail) {
-    abort();
+  if (should_fail && break_on_fail) {
+    raise(SIGTRAP);
   }
   return should_fail;
 }
diff --git a/ssl/test/runner/runner.go b/ssl/test/runner/runner.go
index 0895c61..b0eef42 100644
--- a/ssl/test/runner/runner.go
+++ b/ssl/test/runner/runner.go
@@ -562,7 +562,7 @@
 		shim.Env = os.Environ()
 		shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
 		if *mallocTestDebug {
-			shim.Env = append(shim.Env, "MALLOC_ABORT_ON_FAIL=1")
+			shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
 		}
 		shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
 	}