tsan_flags.cc revision d698edc4f74a17048eef3342a9fa42b3ebba802a
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_libc.h"
16#include "tsan_flags.h"
17#include "tsan_rtl.h"
18#include "tsan_mman.h"
19
20namespace __tsan {
21
22Flags *flags() {
23  return &CTX()->flags;
24}
25
26// Can be overriden in frontend.
27#ifdef TSAN_EXTERNAL_HOOKS
28void OverrideFlags(Flags *f);
29#else
30SANITIZER_INTERFACE_ATTRIBUTE
31void WEAK OverrideFlags(Flags *f) {
32  (void)f;
33}
34#endif
35
36void InitializeFlags(Flags *f, const char *env) {
37  internal_memset(f, 0, sizeof(*f));
38
39  // Default values.
40  f->enable_annotations = true;
41  f->suppress_equal_stacks = true;
42  f->suppress_equal_addresses = true;
43  f->report_bugs = true;
44  f->report_thread_leaks = true;
45  f->report_destroy_locked = true;
46  f->report_signal_unsafe = true;
47  f->force_seq_cst_atomics = false;
48  f->strip_path_prefix = "";
49  f->suppressions = "";
50  f->exitcode = 66;
51  f->log_fileno = kStderrFd;
52  f->atexit_sleep_ms = 1000;
53  f->verbosity = 0;
54  f->profile_memory = "";
55  f->flush_memory_ms = 0;
56  f->stop_on_start = false;
57  f->running_on_valgrind = false;
58  f->external_symbolizer_path = "";
59  f->history_size = 2;
60
61#ifdef TSAN_GO
62  f->history_size = 1;  // There are a lot of goroutines.
63#endif
64
65  // Let a frontend override.
66  OverrideFlags(f);
67
68  // Override from command line.
69  ParseFlag(env, &f->enable_annotations, "enable_annotations");
70  ParseFlag(env, &f->suppress_equal_stacks, "suppress_equal_stacks");
71  ParseFlag(env, &f->suppress_equal_addresses, "suppress_equal_addresses");
72  ParseFlag(env, &f->report_bugs, "report_bugs");
73  ParseFlag(env, &f->report_thread_leaks, "report_thread_leaks");
74  ParseFlag(env, &f->report_destroy_locked, "report_destroy_locked");
75  ParseFlag(env, &f->report_signal_unsafe, "report_signal_unsafe");
76  ParseFlag(env, &f->force_seq_cst_atomics, "force_seq_cst_atomics");
77  ParseFlag(env, &f->strip_path_prefix, "strip_path_prefix");
78  ParseFlag(env, &f->suppressions, "suppressions");
79  ParseFlag(env, &f->exitcode, "exitcode");
80  ParseFlag(env, &f->log_fileno, "log_fileno");
81  ParseFlag(env, &f->atexit_sleep_ms, "atexit_sleep_ms");
82  ParseFlag(env, &f->verbosity, "verbosity");
83  ParseFlag(env, &f->profile_memory, "profile_memory");
84  ParseFlag(env, &f->flush_memory_ms, "flush_memory_ms");
85  ParseFlag(env, &f->stop_on_start, "stop_on_start");
86  ParseFlag(env, &f->external_symbolizer_path, "external_symbolizer_path");
87  ParseFlag(env, &f->history_size, "history_size");
88
89  if (!f->report_bugs) {
90    f->report_thread_leaks = false;
91    f->report_destroy_locked = false;
92    f->report_signal_unsafe = false;
93  }
94
95  if (f->history_size < 0 || f->history_size > 7) {
96    Printf("ThreadSanitizer: incorrect value for history_size"
97           " (must be [0..7])\n");
98    Die();
99  }
100}
101
102}  // namespace __tsan
103