]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/tsan/rtl/tsan_flags.cc
Merge ^/head r279163 through r279308.
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / tsan / rtl / tsan_flags.cc
1 //===-- tsan_flags.cc -----------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file is a part of ThreadSanitizer (TSan), a race detector.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "sanitizer_common/sanitizer_flags.h"
15 #include "sanitizer_common/sanitizer_flag_parser.h"
16 #include "sanitizer_common/sanitizer_libc.h"
17 #include "tsan_flags.h"
18 #include "tsan_rtl.h"
19 #include "tsan_mman.h"
20
21 namespace __tsan {
22
23 Flags *flags() {
24   return &ctx->flags;
25 }
26
27 // Can be overriden in frontend.
28 #ifdef TSAN_EXTERNAL_HOOKS
29 extern "C" const char* __tsan_default_options();
30 #else
31 extern "C" SANITIZER_INTERFACE_ATTRIBUTE
32 const char *WEAK __tsan_default_options() {
33   return "";
34 }
35 #endif
36
37 void Flags::SetDefaults() {
38 #define TSAN_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
39 #include "tsan_flags.inc"
40 #undef TSAN_FLAG
41   // DDFlags
42   second_deadlock_stack = false;
43 }
44
45 void RegisterTsanFlags(FlagParser *parser, Flags *f) {
46 #define TSAN_FLAG(Type, Name, DefaultValue, Description) \
47   RegisterFlag(parser, #Name, Description, &f->Name);
48 #include "tsan_flags.inc"
49 #undef TSAN_FLAG
50 }
51
52 void InitializeFlags(Flags *f, const char *env) {
53   FlagParser parser;
54   RegisterTsanFlags(&parser, f);
55   RegisterCommonFlags(&parser);
56
57   f->SetDefaults();
58
59   SetCommonFlagsDefaults();
60   {
61     // Override some common flags defaults.
62     CommonFlags cf;
63     cf.CopyFrom(*common_flags());
64     cf.allow_addr2line = true;
65 #ifndef SANITIZER_GO
66     cf.detect_deadlocks = true;
67 #endif
68     cf.print_suppressions = false;
69     cf.stack_trace_format = "    #%n %f %S %M";
70     OverrideCommonFlags(cf);
71   }
72
73   // Let a frontend override.
74   parser.ParseString(__tsan_default_options());
75   // Override from command line.
76   parser.ParseString(env);
77
78   // Sanity check.
79   if (!f->report_bugs) {
80     f->report_thread_leaks = false;
81     f->report_destroy_locked = false;
82     f->report_signal_unsafe = false;
83   }
84
85   SetVerbosity(common_flags()->verbosity);
86
87   if (Verbosity()) ReportUnrecognizedFlags();
88
89   if (common_flags()->help) parser.PrintFlagDescriptions();
90
91   if (f->history_size < 0 || f->history_size > 7) {
92     Printf("ThreadSanitizer: incorrect value for history_size"
93            " (must be [0..7])\n");
94     Die();
95   }
96
97   if (f->io_sync < 0 || f->io_sync > 2) {
98     Printf("ThreadSanitizer: incorrect value for io_sync"
99            " (must be [0..2])\n");
100     Die();
101   }
102 }
103
104 }  // namespace __tsan