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 20 namespace __tsan { 21 22 Flags *flags() { 23 return &CTX()->flags; 24 } 25 26 // Can be overriden in frontend. 27 #ifdef TSAN_EXTERNAL_HOOKS 28 void OverrideFlags(Flags *f); 29 #else 30 SANITIZER_INTERFACE_ATTRIBUTE 31 void WEAK OverrideFlags(Flags *f) { 32 (void)f; 33 } 34 #endif 35 36 void 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->suppress_java = false; 44 f->report_bugs = true; 45 f->report_thread_leaks = true; 46 f->report_destroy_locked = true; 47 f->report_signal_unsafe = true; 48 f->report_atomic_races = true; 49 f->force_seq_cst_atomics = false; 50 f->strip_path_prefix = ""; 51 f->suppressions = ""; 52 f->print_suppressions = false; 53 f->print_benign = false; 54 f->exitcode = 66; 55 f->log_path = "stderr"; 56 f->atexit_sleep_ms = 1000; 57 f->verbosity = 0; 58 f->profile_memory = ""; 59 f->flush_memory_ms = 0; 60 f->flush_symbolizer_ms = 5000; 61 f->stop_on_start = false; 62 f->running_on_valgrind = false; 63 f->external_symbolizer_path = ""; 64 f->history_size = kGoMode ? 1 : 2; // There are a lot of goroutines in Go. 65 f->io_sync = 1; 66 67 // Let a frontend override. 68 OverrideFlags(f); 69 70 // Override from command line. 71 ParseFlag(env, &f->enable_annotations, "enable_annotations"); 72 ParseFlag(env, &f->suppress_equal_stacks, "suppress_equal_stacks"); 73 ParseFlag(env, &f->suppress_equal_addresses, "suppress_equal_addresses"); 74 ParseFlag(env, &f->suppress_java, "suppress_java"); 75 ParseFlag(env, &f->report_bugs, "report_bugs"); 76 ParseFlag(env, &f->report_thread_leaks, "report_thread_leaks"); 77 ParseFlag(env, &f->report_destroy_locked, "report_destroy_locked"); 78 ParseFlag(env, &f->report_signal_unsafe, "report_signal_unsafe"); 79 ParseFlag(env, &f->report_atomic_races, "report_atomic_races"); 80 ParseFlag(env, &f->force_seq_cst_atomics, "force_seq_cst_atomics"); 81 ParseFlag(env, &f->strip_path_prefix, "strip_path_prefix"); 82 ParseFlag(env, &f->suppressions, "suppressions"); 83 ParseFlag(env, &f->print_suppressions, "print_suppressions"); 84 ParseFlag(env, &f->print_benign, "print_benign"); 85 ParseFlag(env, &f->exitcode, "exitcode"); 86 ParseFlag(env, &f->log_path, "log_path"); 87 ParseFlag(env, &f->atexit_sleep_ms, "atexit_sleep_ms"); 88 ParseFlag(env, &f->verbosity, "verbosity"); 89 ParseFlag(env, &f->profile_memory, "profile_memory"); 90 ParseFlag(env, &f->flush_memory_ms, "flush_memory_ms"); 91 ParseFlag(env, &f->flush_symbolizer_ms, "flush_symbolizer_ms"); 92 ParseFlag(env, &f->stop_on_start, "stop_on_start"); 93 ParseFlag(env, &f->external_symbolizer_path, "external_symbolizer_path"); 94 ParseFlag(env, &f->history_size, "history_size"); 95 ParseFlag(env, &f->io_sync, "io_sync"); 96 97 if (!f->report_bugs) { 98 f->report_thread_leaks = false; 99 f->report_destroy_locked = false; 100 f->report_signal_unsafe = false; 101 } 102 103 if (f->history_size < 0 || f->history_size > 7) { 104 Printf("ThreadSanitizer: incorrect value for history_size" 105 " (must be [0..7])\n"); 106 Die(); 107 } 108 109 if (f->io_sync < 0 || f->io_sync > 2) { 110 Printf("ThreadSanitizer: incorrect value for io_sync" 111 " (must be [0..2])\n"); 112 Die(); 113 } 114 } 115 116 } // namespace __tsan 117