111
|
1 //===-- tsan_flags.cc -----------------------------------------------------===//
|
|
2 //
|
|
3 // This file is distributed under the University of Illinois Open Source
|
|
4 // License. See LICENSE.TXT for details.
|
|
5 //
|
|
6 //===----------------------------------------------------------------------===//
|
|
7 //
|
|
8 // This file is a part of ThreadSanitizer (TSan), a race detector.
|
|
9 //
|
|
10 //===----------------------------------------------------------------------===//
|
|
11
|
|
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"
|
|
16 #include "tsan_rtl.h"
|
|
17 #include "tsan_mman.h"
|
|
18 #include "ubsan/ubsan_flags.h"
|
|
19
|
|
20 namespace __tsan {
|
|
21
|
|
22 // Can be overriden in frontend.
|
|
23 #ifdef TSAN_EXTERNAL_HOOKS
|
|
24 extern "C" const char* __tsan_default_options();
|
|
25 #else
|
|
26 SANITIZER_WEAK_DEFAULT_IMPL
|
|
27 const char *__tsan_default_options() {
|
|
28 return "";
|
|
29 }
|
|
30 #endif
|
|
31
|
|
32 void Flags::SetDefaults() {
|
|
33 #define TSAN_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
|
|
34 #include "tsan_flags.inc"
|
|
35 #undef TSAN_FLAG
|
|
36 // DDFlags
|
|
37 second_deadlock_stack = false;
|
|
38 }
|
|
39
|
|
40 void RegisterTsanFlags(FlagParser *parser, Flags *f) {
|
|
41 #define TSAN_FLAG(Type, Name, DefaultValue, Description) \
|
|
42 RegisterFlag(parser, #Name, Description, &f->Name);
|
|
43 #include "tsan_flags.inc"
|
|
44 #undef TSAN_FLAG
|
|
45 // DDFlags
|
|
46 RegisterFlag(parser, "second_deadlock_stack",
|
|
47 "Report where each mutex is locked in deadlock reports",
|
|
48 &f->second_deadlock_stack);
|
|
49 }
|
|
50
|
|
51 void InitializeFlags(Flags *f, const char *env) {
|
|
52 SetCommonFlagsDefaults();
|
|
53 {
|
|
54 // Override some common flags defaults.
|
|
55 CommonFlags cf;
|
|
56 cf.CopyFrom(*common_flags());
|
|
57 cf.allow_addr2line = true;
|
|
58 if (SANITIZER_GO) {
|
|
59 // Does not work as expected for Go: runtime handles SIGABRT and crashes.
|
|
60 cf.abort_on_error = false;
|
|
61 // Go does not have mutexes.
|
|
62 } else {
|
|
63 cf.detect_deadlocks = true;
|
|
64 }
|
|
65 cf.print_suppressions = false;
|
|
66 cf.stack_trace_format = " #%n %f %S %M";
|
|
67 cf.exitcode = 66;
|
|
68 cf.intercept_tls_get_addr = true;
|
|
69 OverrideCommonFlags(cf);
|
|
70 }
|
|
71
|
|
72 f->SetDefaults();
|
|
73
|
|
74 FlagParser parser;
|
|
75 RegisterTsanFlags(&parser, f);
|
|
76 RegisterCommonFlags(&parser);
|
|
77
|
|
78 #if TSAN_CONTAINS_UBSAN
|
|
79 __ubsan::Flags *uf = __ubsan::flags();
|
|
80 uf->SetDefaults();
|
|
81
|
|
82 FlagParser ubsan_parser;
|
|
83 __ubsan::RegisterUbsanFlags(&ubsan_parser, uf);
|
|
84 RegisterCommonFlags(&ubsan_parser);
|
|
85 #endif
|
|
86
|
|
87 // Let a frontend override.
|
|
88 parser.ParseString(__tsan_default_options());
|
|
89 #if TSAN_CONTAINS_UBSAN
|
|
90 const char *ubsan_default_options = __ubsan::MaybeCallUbsanDefaultOptions();
|
|
91 ubsan_parser.ParseString(ubsan_default_options);
|
|
92 #endif
|
|
93 // Override from command line.
|
|
94 parser.ParseString(env);
|
|
95 #if TSAN_CONTAINS_UBSAN
|
|
96 ubsan_parser.ParseString(GetEnv("UBSAN_OPTIONS"));
|
|
97 #endif
|
|
98
|
|
99 // Sanity check.
|
|
100 if (!f->report_bugs) {
|
|
101 f->report_thread_leaks = false;
|
|
102 f->report_destroy_locked = false;
|
|
103 f->report_signal_unsafe = false;
|
|
104 }
|
|
105
|
|
106 InitializeCommonFlags();
|
|
107
|
|
108 if (Verbosity()) ReportUnrecognizedFlags();
|
|
109
|
|
110 if (common_flags()->help) parser.PrintFlagDescriptions();
|
|
111
|
|
112 if (f->history_size < 0 || f->history_size > 7) {
|
|
113 Printf("ThreadSanitizer: incorrect value for history_size"
|
|
114 " (must be [0..7])\n");
|
|
115 Die();
|
|
116 }
|
|
117
|
|
118 if (f->io_sync < 0 || f->io_sync > 2) {
|
|
119 Printf("ThreadSanitizer: incorrect value for io_sync"
|
|
120 " (must be [0..2])\n");
|
|
121 Die();
|
|
122 }
|
|
123 }
|
|
124
|
|
125 } // namespace __tsan
|