2012-06-04 21:55:19 +08:00
|
|
|
//===-- tsan_flags.cc -----------------------------------------------------===//
|
2012-05-10 21:48:04 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of ThreadSanitizer (TSan), a race detector.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-07-09 21:21:39 +08:00
|
|
|
#include "sanitizer_common/sanitizer_flags.h"
|
2012-06-06 17:26:25 +08:00
|
|
|
#include "sanitizer_common/sanitizer_libc.h"
|
2012-05-10 21:48:04 +08:00
|
|
|
#include "tsan_flags.h"
|
|
|
|
#include "tsan_rtl.h"
|
|
|
|
#include "tsan_mman.h"
|
|
|
|
|
|
|
|
namespace __tsan {
|
|
|
|
|
|
|
|
Flags *flags() {
|
2014-03-20 18:36:20 +08:00
|
|
|
return &ctx->flags;
|
2012-05-10 21:48:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Can be overriden in frontend.
|
2012-07-25 22:30:51 +08:00
|
|
|
#ifdef TSAN_EXTERNAL_HOOKS
|
2013-10-15 23:58:11 +08:00
|
|
|
extern "C" const char* __tsan_default_options();
|
2012-07-25 22:30:51 +08:00
|
|
|
#else
|
2014-02-04 16:46:09 +08:00
|
|
|
extern "C" SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
const char *WEAK __tsan_default_options() {
|
2013-10-15 23:58:11 +08:00
|
|
|
return "";
|
|
|
|
}
|
2012-07-25 22:30:51 +08:00
|
|
|
#endif
|
2012-05-10 21:48:04 +08:00
|
|
|
|
2013-10-15 23:58:11 +08:00
|
|
|
static void ParseFlags(Flags *f, const char *env) {
|
2014-03-20 20:52:52 +08:00
|
|
|
ParseFlag(env, &f->enable_annotations, "enable_annotations", "");
|
|
|
|
ParseFlag(env, &f->suppress_equal_stacks, "suppress_equal_stacks", "");
|
|
|
|
ParseFlag(env, &f->suppress_equal_addresses, "suppress_equal_addresses", "");
|
|
|
|
ParseFlag(env, &f->report_bugs, "report_bugs", "");
|
|
|
|
ParseFlag(env, &f->report_thread_leaks, "report_thread_leaks", "");
|
|
|
|
ParseFlag(env, &f->report_destroy_locked, "report_destroy_locked", "");
|
2014-04-25 15:42:55 +08:00
|
|
|
ParseFlag(env, &f->report_mutex_bugs, "report_mutex_bugs", "");
|
2014-03-20 20:52:52 +08:00
|
|
|
ParseFlag(env, &f->report_signal_unsafe, "report_signal_unsafe", "");
|
|
|
|
ParseFlag(env, &f->report_atomic_races, "report_atomic_races", "");
|
|
|
|
ParseFlag(env, &f->force_seq_cst_atomics, "force_seq_cst_atomics", "");
|
|
|
|
ParseFlag(env, &f->print_benign, "print_benign", "");
|
|
|
|
ParseFlag(env, &f->exitcode, "exitcode", "");
|
|
|
|
ParseFlag(env, &f->halt_on_error, "halt_on_error", "");
|
|
|
|
ParseFlag(env, &f->atexit_sleep_ms, "atexit_sleep_ms", "");
|
|
|
|
ParseFlag(env, &f->profile_memory, "profile_memory", "");
|
|
|
|
ParseFlag(env, &f->flush_memory_ms, "flush_memory_ms", "");
|
|
|
|
ParseFlag(env, &f->flush_symbolizer_ms, "flush_symbolizer_ms", "");
|
|
|
|
ParseFlag(env, &f->memory_limit_mb, "memory_limit_mb", "");
|
|
|
|
ParseFlag(env, &f->stop_on_start, "stop_on_start", "");
|
|
|
|
ParseFlag(env, &f->running_on_valgrind, "running_on_valgrind", "");
|
|
|
|
ParseFlag(env, &f->history_size, "history_size", "");
|
|
|
|
ParseFlag(env, &f->io_sync, "io_sync", "");
|
|
|
|
ParseFlag(env, &f->die_after_fork, "die_after_fork", "");
|
2014-03-18 21:13:47 +08:00
|
|
|
|
|
|
|
// DDFlags
|
2014-03-20 20:52:52 +08:00
|
|
|
ParseFlag(env, &f->second_deadlock_stack, "second_deadlock_stack", "");
|
2013-10-15 23:58:11 +08:00
|
|
|
}
|
|
|
|
|
2012-05-10 21:48:04 +08:00
|
|
|
void InitializeFlags(Flags *f, const char *env) {
|
2012-06-28 05:00:23 +08:00
|
|
|
internal_memset(f, 0, sizeof(*f));
|
2012-05-10 21:48:04 +08:00
|
|
|
|
|
|
|
// Default values.
|
|
|
|
f->enable_annotations = true;
|
|
|
|
f->suppress_equal_stacks = true;
|
|
|
|
f->suppress_equal_addresses = true;
|
2012-11-08 00:14:12 +08:00
|
|
|
f->report_bugs = true;
|
2012-05-10 21:48:04 +08:00
|
|
|
f->report_thread_leaks = true;
|
2012-08-16 23:12:35 +08:00
|
|
|
f->report_destroy_locked = true;
|
2014-04-25 15:42:55 +08:00
|
|
|
f->report_mutex_bugs = true;
|
2012-05-10 21:48:04 +08:00
|
|
|
f->report_signal_unsafe = true;
|
2013-02-01 18:06:56 +08:00
|
|
|
f->report_atomic_races = true;
|
2012-05-10 21:48:04 +08:00
|
|
|
f->force_seq_cst_atomics = false;
|
2013-03-29 00:21:19 +08:00
|
|
|
f->print_benign = false;
|
2012-05-10 21:48:04 +08:00
|
|
|
f->exitcode = 66;
|
2013-08-13 23:33:00 +08:00
|
|
|
f->halt_on_error = false;
|
2012-05-10 21:48:04 +08:00
|
|
|
f->atexit_sleep_ms = 1000;
|
2012-05-22 19:33:03 +08:00
|
|
|
f->profile_memory = "";
|
2012-05-23 02:07:45 +08:00
|
|
|
f->flush_memory_ms = 0;
|
2013-03-21 21:01:50 +08:00
|
|
|
f->flush_symbolizer_ms = 5000;
|
2013-10-04 01:14:35 +08:00
|
|
|
f->memory_limit_mb = 0;
|
2012-05-23 02:07:45 +08:00
|
|
|
f->stop_on_start = false;
|
2012-05-24 17:24:45 +08:00
|
|
|
f->running_on_valgrind = false;
|
2012-11-28 21:01:32 +08:00
|
|
|
f->history_size = kGoMode ? 1 : 2; // There are a lot of goroutines in Go.
|
2012-12-18 20:20:55 +08:00
|
|
|
f->io_sync = 1;
|
2014-01-24 20:33:35 +08:00
|
|
|
f->die_after_fork = true;
|
2012-05-24 17:24:45 +08:00
|
|
|
|
2014-03-18 21:13:47 +08:00
|
|
|
// DDFlags
|
|
|
|
f->second_deadlock_stack = false;
|
|
|
|
|
2014-09-11 07:08:06 +08:00
|
|
|
CommonFlags *cf = common_flags();
|
|
|
|
SetCommonFlagsDefaults(cf);
|
2014-02-12 16:29:42 +08:00
|
|
|
// Override some common flags defaults.
|
2014-09-11 07:08:06 +08:00
|
|
|
cf->allow_addr2line = true;
|
|
|
|
cf->detect_deadlocks = true;
|
|
|
|
cf->print_suppressions = false;
|
2014-11-07 02:43:45 +08:00
|
|
|
cf->stack_trace_format = " #%n %f %S %M";
|
2013-10-15 21:28:51 +08:00
|
|
|
|
2012-05-10 21:48:04 +08:00
|
|
|
// Let a frontend override.
|
2013-10-15 23:58:11 +08:00
|
|
|
ParseFlags(f, __tsan_default_options());
|
2014-09-11 07:08:06 +08:00
|
|
|
ParseCommonFlagsFromString(cf, __tsan_default_options());
|
2012-05-10 21:48:04 +08:00
|
|
|
// Override from command line.
|
2013-10-15 23:58:11 +08:00
|
|
|
ParseFlags(f, env);
|
2014-09-11 07:08:06 +08:00
|
|
|
ParseCommonFlagsFromString(cf, env);
|
2012-11-08 00:14:12 +08:00
|
|
|
|
2013-11-12 21:59:08 +08:00
|
|
|
// Sanity check.
|
2012-11-08 00:14:12 +08:00
|
|
|
if (!f->report_bugs) {
|
|
|
|
f->report_thread_leaks = false;
|
|
|
|
f->report_destroy_locked = false;
|
|
|
|
f->report_signal_unsafe = false;
|
|
|
|
}
|
2012-11-28 20:19:50 +08:00
|
|
|
|
2014-09-11 07:08:06 +08:00
|
|
|
if (cf->help) PrintFlagDescriptions();
|
2014-03-20 20:52:52 +08:00
|
|
|
|
2012-11-28 20:19:50 +08:00
|
|
|
if (f->history_size < 0 || f->history_size > 7) {
|
|
|
|
Printf("ThreadSanitizer: incorrect value for history_size"
|
|
|
|
" (must be [0..7])\n");
|
|
|
|
Die();
|
|
|
|
}
|
2012-12-18 20:20:55 +08:00
|
|
|
|
|
|
|
if (f->io_sync < 0 || f->io_sync > 2) {
|
|
|
|
Printf("ThreadSanitizer: incorrect value for io_sync"
|
|
|
|
" (must be [0..2])\n");
|
|
|
|
Die();
|
|
|
|
}
|
2012-05-10 21:48:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace __tsan
|