1 //===-- tsan_flags.cc -----------------------------------------------------===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // This file is a part of ThreadSanitizer (TSan), a race detector.
10 //===----------------------------------------------------------------------===//
12 #include "sanitizer_common/sanitizer_flags.h"
13 #include "sanitizer_common/sanitizer_flag_parser.h"
14 #include "sanitizer_common/sanitizer_libc.h"
15 #include "tsan_flags.h"
17 #include "tsan_mman.h"
18 #include "ubsan/ubsan_flags.h"
26 // Can be overriden in frontend.
27 #ifdef TSAN_EXTERNAL_HOOKS
28 extern "C" const char* __tsan_default_options();
30 SANITIZER_WEAK_DEFAULT_IMPL
31 const char *__tsan_default_options() {
36 void Flags::SetDefaults() {
37 #define TSAN_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
38 #include "tsan_flags.inc"
41 second_deadlock_stack
= false;
44 void RegisterTsanFlags(FlagParser
*parser
, Flags
*f
) {
45 #define TSAN_FLAG(Type, Name, DefaultValue, Description) \
46 RegisterFlag(parser, #Name, Description, &f->Name);
47 #include "tsan_flags.inc"
50 RegisterFlag(parser
, "second_deadlock_stack",
51 "Report where each mutex is locked in deadlock reports",
52 &f
->second_deadlock_stack
);
55 void InitializeFlags(Flags
*f
, const char *env
) {
56 SetCommonFlagsDefaults();
58 // Override some common flags defaults.
60 cf
.CopyFrom(*common_flags());
61 cf
.allow_addr2line
= true;
63 // Does not work as expected for Go: runtime handles SIGABRT and crashes.
64 cf
.abort_on_error
= false;
65 // Go does not have mutexes.
67 cf
.detect_deadlocks
= true;
69 cf
.print_suppressions
= false;
70 cf
.stack_trace_format
= " #%n %f %S %M";
72 cf
.intercept_tls_get_addr
= true;
73 OverrideCommonFlags(cf
);
79 RegisterTsanFlags(&parser
, f
);
80 RegisterCommonFlags(&parser
);
82 #if TSAN_CONTAINS_UBSAN
83 __ubsan::Flags
*uf
= __ubsan::flags();
86 FlagParser ubsan_parser
;
87 __ubsan::RegisterUbsanFlags(&ubsan_parser
, uf
);
88 RegisterCommonFlags(&ubsan_parser
);
91 // Let a frontend override.
92 parser
.ParseString(__tsan_default_options());
93 #if TSAN_CONTAINS_UBSAN
94 const char *ubsan_default_options
= __ubsan::MaybeCallUbsanDefaultOptions();
95 ubsan_parser
.ParseString(ubsan_default_options
);
97 // Override from command line.
98 parser
.ParseString(env
);
99 #if TSAN_CONTAINS_UBSAN
100 ubsan_parser
.ParseString(GetEnv("UBSAN_OPTIONS"));
104 if (!f
->report_bugs
) {
105 f
->report_thread_leaks
= false;
106 f
->report_destroy_locked
= false;
107 f
->report_signal_unsafe
= false;
110 InitializeCommonFlags();
112 if (Verbosity()) ReportUnrecognizedFlags();
114 if (common_flags()->help
) parser
.PrintFlagDescriptions();
116 if (f
->history_size
< 0 || f
->history_size
> 7) {
117 Printf("ThreadSanitizer: incorrect value for history_size"
118 " (must be [0..7])\n");
122 if (f
->io_sync
< 0 || f
->io_sync
> 2) {
123 Printf("ThreadSanitizer: incorrect value for io_sync"
124 " (must be [0..2])\n");
129 } // namespace __tsan