Added -f/--fork option to test inheritance of disable_debugger().

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33329 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2009-09-28 02:51:56 +00:00
parent fd09bcb070
commit 23338ed551

View File

@ -1,15 +1,18 @@
/*
* Copyright 2005-2008, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2005-2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#undef NDEBUG
#include <assert.h>
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <OS.h>
@ -22,6 +25,7 @@ static const char *kUsage =
"\n"
"Options:\n"
" -d - call disable_debugger() first\n"
" -f, --fork - fork() and continue in the child\n"
" -h, --help - print this info text\n"
" --multi - crash in multiple threads\n"
" --signal - crash in a signal handler\n"
@ -126,7 +130,8 @@ struct Options {
inThread(false),
multipleThreads(false),
inSignalHandler(false),
disableDebugger(false)
disableDebugger(false),
fork(false)
{
}
@ -135,6 +140,7 @@ struct Options {
bool multipleThreads;
bool inSignalHandler;
bool disableDebugger;
bool fork;
};
static Options sOptions;
@ -207,6 +213,8 @@ main(int argc, const char* const* argv)
print_usage_and_exit(false);
} else if (strcmp(arg, "-d") == 0) {
sOptions.disableDebugger = true;
} else if (strcmp(arg, "-f") == 0 || strcmp(arg, "--fork") == 0) {
sOptions.fork = true;
} else if (strcmp(arg, "--multi") == 0) {
sOptions.inThread = true;
sOptions.multipleThreads = true;
@ -232,6 +240,21 @@ main(int argc, const char* const* argv)
if (sOptions.disableDebugger)
disable_debugger(true);
if (sOptions.fork) {
pid_t child = fork();
if (child < 0) {
fprintf(stderr, "fork() failed: %s\n", strerror(errno));
exit(1);
}
if (child > 0) {
// the parent exits
exit(1);
}
// the child continues...
}
if (sOptions.inThread) {
thread_id thread = spawn_thread(crashing_thread, "crashing thread",
B_NORMAL_PRIORITY, NULL);