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"
|
2015-01-15 23:13:43 +08:00
|
|
|
#include "sanitizer_common/sanitizer_flag_parser.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
|
|
|
|
2015-01-07 08:38:00 +08:00
|
|
|
void Flags::SetDefaults() {
|
|
|
|
#define TSAN_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
|
|
|
|
#include "tsan_flags.inc"
|
|
|
|
#undef TSAN_FLAG
|
|
|
|
// DDFlags
|
|
|
|
second_deadlock_stack = false;
|
|
|
|
}
|
2014-03-18 21:13:47 +08:00
|
|
|
|
2015-01-15 23:13:43 +08:00
|
|
|
void RegisterTsanFlags(FlagParser *parser, Flags *f) {
|
|
|
|
#define TSAN_FLAG(Type, Name, DefaultValue, Description) \
|
|
|
|
RegisterFlag(parser, #Name, Description, &f->Name);
|
2015-01-07 08:38:00 +08:00
|
|
|
#include "tsan_flags.inc"
|
|
|
|
#undef TSAN_FLAG
|
2013-10-15 23:58:11 +08:00
|
|
|
}
|
|
|
|
|
2012-05-10 21:48:04 +08:00
|
|
|
void InitializeFlags(Flags *f, const char *env) {
|
2015-01-15 23:13:43 +08:00
|
|
|
FlagParser parser;
|
|
|
|
RegisterTsanFlags(&parser, f);
|
|
|
|
RegisterCommonFlags(&parser);
|
|
|
|
|
2015-01-07 08:38:00 +08:00
|
|
|
f->SetDefaults();
|
2014-03-18 21:13:47 +08:00
|
|
|
|
2014-12-20 05:40:04 +08:00
|
|
|
SetCommonFlagsDefaults();
|
2015-01-03 05:28:37 +08:00
|
|
|
{
|
|
|
|
// Override some common flags defaults.
|
|
|
|
CommonFlags cf;
|
|
|
|
cf.CopyFrom(*common_flags());
|
|
|
|
cf.allow_addr2line = true;
|
|
|
|
cf.detect_deadlocks = true;
|
|
|
|
cf.print_suppressions = false;
|
|
|
|
cf.stack_trace_format = " #%n %f %S %M";
|
|
|
|
OverrideCommonFlags(cf);
|
|
|
|
}
|
2013-10-15 21:28:51 +08:00
|
|
|
|
2012-05-10 21:48:04 +08:00
|
|
|
// Let a frontend override.
|
2015-01-15 23:13:43 +08:00
|
|
|
parser.ParseString(__tsan_default_options());
|
2012-05-10 21:48:04 +08:00
|
|
|
// Override from command line.
|
2015-01-15 23:13:43 +08:00
|
|
|
parser.ParseString(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
|
|
|
|
2015-01-19 20:22:57 +08:00
|
|
|
if (common_flags()->verbosity) ReportUnrecognizedFlags();
|
|
|
|
|
|
|
|
if (common_flags()->help) parser.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
|