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>
This commit is contained in:
David Benjamin 2015-06-12 18:23:47 -04:00 committed by Adam Langley
parent 7c803a65d5
commit 184494dfcc
2 changed files with 8 additions and 7 deletions

View File

@ -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 @@ static int should_fail_allocation() {
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 @@ static int should_fail_allocation() {
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;
}

View File

@ -562,7 +562,7 @@ func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
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")
}