blob: 25c370f034ad914043c894f91624ed25716d02c0 [file] [log] [blame]
Alexey Samsonov603c4be2012-06-04 13:55:19 +00001//===-- tsan_flags.cc -----------------------------------------------------===//
Kostya Serebryany7ac41482012-05-10 13:48:04 +00002//
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
Alexey Samsonovf3be7062012-07-09 13:21:39 +000014#include "sanitizer_common/sanitizer_flags.h"
Alexey Samsonov230c3be2012-06-06 09:26:25 +000015#include "sanitizer_common/sanitizer_libc.h"
Kostya Serebryany7ac41482012-05-10 13:48:04 +000016#include "tsan_flags.h"
17#include "tsan_rtl.h"
18#include "tsan_mman.h"
19
20namespace __tsan {
21
Kostya Serebryany7ac41482012-05-10 13:48:04 +000022Flags *flags() {
23 return &CTX()->flags;
24}
25
26// Can be overriden in frontend.
Dmitry Vyukov87dbdf52012-07-25 14:30:51 +000027#ifdef TSAN_EXTERNAL_HOOKS
28void OverrideFlags(Flags *f);
29#else
Alexey Samsonov9a46c3b2012-09-13 13:34:09 +000030SANITIZER_INTERFACE_ATTRIBUTE
Kostya Serebryany7ac41482012-05-10 13:48:04 +000031void WEAK OverrideFlags(Flags *f) {
32 (void)f;
33}
Dmitry Vyukov87dbdf52012-07-25 14:30:51 +000034#endif
Kostya Serebryany7ac41482012-05-10 13:48:04 +000035
36void InitializeFlags(Flags *f, const char *env) {
Dmitry Vyukovd51a1a12012-06-27 21:00:23 +000037 internal_memset(f, 0, sizeof(*f));
Kostya Serebryany7ac41482012-05-10 13:48:04 +000038
39 // Default values.
40 f->enable_annotations = true;
41 f->suppress_equal_stacks = true;
42 f->suppress_equal_addresses = true;
Dmitry Vyukov543b94a2012-11-30 17:45:53 +000043 f->suppress_java = false;
Dmitry Vyukov8a326772012-11-07 16:14:12 +000044 f->report_bugs = true;
Kostya Serebryany7ac41482012-05-10 13:48:04 +000045 f->report_thread_leaks = true;
Dmitry Vyukovfd513902012-08-16 15:12:35 +000046 f->report_destroy_locked = true;
Kostya Serebryany7ac41482012-05-10 13:48:04 +000047 f->report_signal_unsafe = true;
48 f->force_seq_cst_atomics = false;
Dmitry Vyukovb7b6b1c2012-05-17 15:00:27 +000049 f->strip_path_prefix = "";
50 f->suppressions = "";
Kostya Serebryany7ac41482012-05-10 13:48:04 +000051 f->exitcode = 66;
Dmitry Vyukovcec60682012-11-28 12:56:52 +000052 f->log_path = "stderr";
Kostya Serebryany7ac41482012-05-10 13:48:04 +000053 f->atexit_sleep_ms = 1000;
54 f->verbosity = 0;
Dmitry Vyukov26127732012-05-22 11:33:03 +000055 f->profile_memory = "";
Dmitry Vyukovadfb6502012-05-22 18:07:45 +000056 f->flush_memory_ms = 0;
57 f->stop_on_start = false;
Dmitry Vyukov24567d42012-05-24 09:24:45 +000058 f->running_on_valgrind = false;
Alexey Samsonov8cc1f812012-09-06 08:48:43 +000059 f->external_symbolizer_path = "";
Dmitry Vyukov3fb70e32012-11-28 13:01:32 +000060 f->history_size = kGoMode ? 1 : 2; // There are a lot of goroutines in Go.
Dmitry Vyukov24567d42012-05-24 09:24:45 +000061
Kostya Serebryany7ac41482012-05-10 13:48:04 +000062 // Let a frontend override.
63 OverrideFlags(f);
64
65 // Override from command line.
Alexey Samsonovf3be7062012-07-09 13:21:39 +000066 ParseFlag(env, &f->enable_annotations, "enable_annotations");
67 ParseFlag(env, &f->suppress_equal_stacks, "suppress_equal_stacks");
68 ParseFlag(env, &f->suppress_equal_addresses, "suppress_equal_addresses");
Dmitry Vyukov543b94a2012-11-30 17:45:53 +000069 ParseFlag(env, &f->suppress_java, "suppress_java");
Dmitry Vyukov8a326772012-11-07 16:14:12 +000070 ParseFlag(env, &f->report_bugs, "report_bugs");
Alexey Samsonovf3be7062012-07-09 13:21:39 +000071 ParseFlag(env, &f->report_thread_leaks, "report_thread_leaks");
Dmitry Vyukovfd513902012-08-16 15:12:35 +000072 ParseFlag(env, &f->report_destroy_locked, "report_destroy_locked");
Alexey Samsonovf3be7062012-07-09 13:21:39 +000073 ParseFlag(env, &f->report_signal_unsafe, "report_signal_unsafe");
74 ParseFlag(env, &f->force_seq_cst_atomics, "force_seq_cst_atomics");
75 ParseFlag(env, &f->strip_path_prefix, "strip_path_prefix");
76 ParseFlag(env, &f->suppressions, "suppressions");
77 ParseFlag(env, &f->exitcode, "exitcode");
Dmitry Vyukovcec60682012-11-28 12:56:52 +000078 ParseFlag(env, &f->log_path, "log_path");
Alexey Samsonovf3be7062012-07-09 13:21:39 +000079 ParseFlag(env, &f->atexit_sleep_ms, "atexit_sleep_ms");
80 ParseFlag(env, &f->verbosity, "verbosity");
81 ParseFlag(env, &f->profile_memory, "profile_memory");
82 ParseFlag(env, &f->flush_memory_ms, "flush_memory_ms");
83 ParseFlag(env, &f->stop_on_start, "stop_on_start");
Alexey Samsonov8cc1f812012-09-06 08:48:43 +000084 ParseFlag(env, &f->external_symbolizer_path, "external_symbolizer_path");
Dmitry Vyukovd698edc2012-11-28 12:19:50 +000085 ParseFlag(env, &f->history_size, "history_size");
Dmitry Vyukov8a326772012-11-07 16:14:12 +000086
87 if (!f->report_bugs) {
88 f->report_thread_leaks = false;
89 f->report_destroy_locked = false;
90 f->report_signal_unsafe = false;
91 }
Dmitry Vyukovd698edc2012-11-28 12:19:50 +000092
93 if (f->history_size < 0 || f->history_size > 7) {
94 Printf("ThreadSanitizer: incorrect value for history_size"
95 " (must be [0..7])\n");
96 Die();
97 }
Kostya Serebryany7ac41482012-05-10 13:48:04 +000098}
99
100} // namespace __tsan