Alexey Samsonov | 603c4be | 2012-06-04 13:55:19 +0000 | [diff] [blame] | 1 | //===-- tsan_flags.cc -----------------------------------------------------===// |
Kostya Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 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 | |
Alexey Samsonov | f3be706 | 2012-07-09 13:21:39 +0000 | [diff] [blame] | 14 | #include "sanitizer_common/sanitizer_flags.h" |
Alexey Samsonov | 230c3be | 2012-06-06 09:26:25 +0000 | [diff] [blame] | 15 | #include "sanitizer_common/sanitizer_libc.h" |
Kostya Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 16 | #include "tsan_flags.h" |
| 17 | #include "tsan_rtl.h" |
| 18 | #include "tsan_mman.h" |
| 19 | |
| 20 | namespace __tsan { |
| 21 | |
Kostya Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 22 | Flags *flags() { |
| 23 | return &CTX()->flags; |
| 24 | } |
| 25 | |
| 26 | // Can be overriden in frontend. |
Dmitry Vyukov | 87dbdf5 | 2012-07-25 14:30:51 +0000 | [diff] [blame] | 27 | #ifdef TSAN_EXTERNAL_HOOKS |
| 28 | void OverrideFlags(Flags *f); |
| 29 | #else |
Alexey Samsonov | 9a46c3b | 2012-09-13 13:34:09 +0000 | [diff] [blame] | 30 | SANITIZER_INTERFACE_ATTRIBUTE |
Kostya Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 31 | void WEAK OverrideFlags(Flags *f) { |
| 32 | (void)f; |
| 33 | } |
Dmitry Vyukov | 87dbdf5 | 2012-07-25 14:30:51 +0000 | [diff] [blame] | 34 | #endif |
Kostya Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 35 | |
| 36 | void InitializeFlags(Flags *f, const char *env) { |
Dmitry Vyukov | d51a1a1 | 2012-06-27 21:00:23 +0000 | [diff] [blame] | 37 | internal_memset(f, 0, sizeof(*f)); |
Kostya Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 38 | |
| 39 | // Default values. |
| 40 | f->enable_annotations = true; |
| 41 | f->suppress_equal_stacks = true; |
| 42 | f->suppress_equal_addresses = true; |
Dmitry Vyukov | 543b94a | 2012-11-30 17:45:53 +0000 | [diff] [blame] | 43 | f->suppress_java = false; |
Dmitry Vyukov | 8a32677 | 2012-11-07 16:14:12 +0000 | [diff] [blame] | 44 | f->report_bugs = true; |
Kostya Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 45 | f->report_thread_leaks = true; |
Dmitry Vyukov | fd51390 | 2012-08-16 15:12:35 +0000 | [diff] [blame] | 46 | f->report_destroy_locked = true; |
Kostya Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 47 | f->report_signal_unsafe = true; |
Dmitry Vyukov | ddbe2be | 2013-02-01 10:06:56 +0000 | [diff] [blame] | 48 | f->report_atomic_races = true; |
Kostya Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 49 | f->force_seq_cst_atomics = false; |
Dmitry Vyukov | b7b6b1c | 2012-05-17 15:00:27 +0000 | [diff] [blame] | 50 | f->suppressions = ""; |
Dmitry Vyukov | f754eb5 | 2013-03-27 17:59:57 +0000 | [diff] [blame] | 51 | f->print_suppressions = false; |
Dmitry Vyukov | 0fd908c | 2013-03-28 16:21:19 +0000 | [diff] [blame] | 52 | f->print_benign = false; |
Kostya Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 53 | f->exitcode = 66; |
Dmitry Vyukov | dbac0a4 | 2013-08-13 15:33:00 +0000 | [diff] [blame] | 54 | f->halt_on_error = false; |
Kostya Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 55 | f->atexit_sleep_ms = 1000; |
| 56 | f->verbosity = 0; |
Dmitry Vyukov | 2612773 | 2012-05-22 11:33:03 +0000 | [diff] [blame] | 57 | f->profile_memory = ""; |
Dmitry Vyukov | adfb650 | 2012-05-22 18:07:45 +0000 | [diff] [blame] | 58 | f->flush_memory_ms = 0; |
Dmitry Vyukov | f63dde3 | 2013-03-21 13:01:50 +0000 | [diff] [blame] | 59 | f->flush_symbolizer_ms = 5000; |
Dmitry Vyukov | 92b5479 | 2013-10-03 17:14:35 +0000 | [diff] [blame] | 60 | f->memory_limit_mb = 0; |
Dmitry Vyukov | adfb650 | 2012-05-22 18:07:45 +0000 | [diff] [blame] | 61 | f->stop_on_start = false; |
Dmitry Vyukov | 24567d4 | 2012-05-24 09:24:45 +0000 | [diff] [blame] | 62 | f->running_on_valgrind = false; |
Dmitry Vyukov | 3fb70e3 | 2012-11-28 13:01:32 +0000 | [diff] [blame] | 63 | f->history_size = kGoMode ? 1 : 2; // There are a lot of goroutines in Go. |
Dmitry Vyukov | e3178e8 | 2012-12-18 12:20:55 +0000 | [diff] [blame] | 64 | f->io_sync = 1; |
Dmitry Vyukov | 24567d4 | 2012-05-24 09:24:45 +0000 | [diff] [blame] | 65 | |
Kostya Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 66 | // Let a frontend override. |
| 67 | OverrideFlags(f); |
| 68 | |
| 69 | // Override from command line. |
Alexey Samsonov | f3be706 | 2012-07-09 13:21:39 +0000 | [diff] [blame] | 70 | ParseFlag(env, &f->enable_annotations, "enable_annotations"); |
| 71 | ParseFlag(env, &f->suppress_equal_stacks, "suppress_equal_stacks"); |
| 72 | ParseFlag(env, &f->suppress_equal_addresses, "suppress_equal_addresses"); |
Dmitry Vyukov | 543b94a | 2012-11-30 17:45:53 +0000 | [diff] [blame] | 73 | ParseFlag(env, &f->suppress_java, "suppress_java"); |
Dmitry Vyukov | 8a32677 | 2012-11-07 16:14:12 +0000 | [diff] [blame] | 74 | ParseFlag(env, &f->report_bugs, "report_bugs"); |
Alexey Samsonov | f3be706 | 2012-07-09 13:21:39 +0000 | [diff] [blame] | 75 | ParseFlag(env, &f->report_thread_leaks, "report_thread_leaks"); |
Dmitry Vyukov | fd51390 | 2012-08-16 15:12:35 +0000 | [diff] [blame] | 76 | ParseFlag(env, &f->report_destroy_locked, "report_destroy_locked"); |
Alexey Samsonov | f3be706 | 2012-07-09 13:21:39 +0000 | [diff] [blame] | 77 | ParseFlag(env, &f->report_signal_unsafe, "report_signal_unsafe"); |
Dmitry Vyukov | ddbe2be | 2013-02-01 10:06:56 +0000 | [diff] [blame] | 78 | ParseFlag(env, &f->report_atomic_races, "report_atomic_races"); |
Alexey Samsonov | f3be706 | 2012-07-09 13:21:39 +0000 | [diff] [blame] | 79 | ParseFlag(env, &f->force_seq_cst_atomics, "force_seq_cst_atomics"); |
Alexey Samsonov | f3be706 | 2012-07-09 13:21:39 +0000 | [diff] [blame] | 80 | ParseFlag(env, &f->suppressions, "suppressions"); |
Dmitry Vyukov | f754eb5 | 2013-03-27 17:59:57 +0000 | [diff] [blame] | 81 | ParseFlag(env, &f->print_suppressions, "print_suppressions"); |
Dmitry Vyukov | 0fd908c | 2013-03-28 16:21:19 +0000 | [diff] [blame] | 82 | ParseFlag(env, &f->print_benign, "print_benign"); |
Alexey Samsonov | f3be706 | 2012-07-09 13:21:39 +0000 | [diff] [blame] | 83 | ParseFlag(env, &f->exitcode, "exitcode"); |
Dmitry Vyukov | dbac0a4 | 2013-08-13 15:33:00 +0000 | [diff] [blame] | 84 | ParseFlag(env, &f->halt_on_error, "halt_on_error"); |
Alexey Samsonov | f3be706 | 2012-07-09 13:21:39 +0000 | [diff] [blame] | 85 | ParseFlag(env, &f->atexit_sleep_ms, "atexit_sleep_ms"); |
| 86 | ParseFlag(env, &f->verbosity, "verbosity"); |
| 87 | ParseFlag(env, &f->profile_memory, "profile_memory"); |
| 88 | ParseFlag(env, &f->flush_memory_ms, "flush_memory_ms"); |
Dmitry Vyukov | f63dde3 | 2013-03-21 13:01:50 +0000 | [diff] [blame] | 89 | ParseFlag(env, &f->flush_symbolizer_ms, "flush_symbolizer_ms"); |
Dmitry Vyukov | 92b5479 | 2013-10-03 17:14:35 +0000 | [diff] [blame] | 90 | ParseFlag(env, &f->memory_limit_mb, "memory_limit_mb"); |
Alexey Samsonov | f3be706 | 2012-07-09 13:21:39 +0000 | [diff] [blame] | 91 | ParseFlag(env, &f->stop_on_start, "stop_on_start"); |
Dmitry Vyukov | d698edc | 2012-11-28 12:19:50 +0000 | [diff] [blame] | 92 | ParseFlag(env, &f->history_size, "history_size"); |
Dmitry Vyukov | e3178e8 | 2012-12-18 12:20:55 +0000 | [diff] [blame] | 93 | ParseFlag(env, &f->io_sync, "io_sync"); |
Dmitry Vyukov | 8a32677 | 2012-11-07 16:14:12 +0000 | [diff] [blame] | 94 | |
| 95 | if (!f->report_bugs) { |
| 96 | f->report_thread_leaks = false; |
| 97 | f->report_destroy_locked = false; |
| 98 | f->report_signal_unsafe = false; |
| 99 | } |
Dmitry Vyukov | d698edc | 2012-11-28 12:19:50 +0000 | [diff] [blame] | 100 | |
| 101 | if (f->history_size < 0 || f->history_size > 7) { |
| 102 | Printf("ThreadSanitizer: incorrect value for history_size" |
| 103 | " (must be [0..7])\n"); |
| 104 | Die(); |
| 105 | } |
Dmitry Vyukov | e3178e8 | 2012-12-18 12:20:55 +0000 | [diff] [blame] | 106 | |
| 107 | if (f->io_sync < 0 || f->io_sync > 2) { |
| 108 | Printf("ThreadSanitizer: incorrect value for io_sync" |
| 109 | " (must be [0..2])\n"); |
| 110 | Die(); |
| 111 | } |
Dmitry Vyukov | c78773e | 2013-09-27 02:31:23 +0000 | [diff] [blame] | 112 | |
Dmitry Vyukov | b48c2b2 | 2013-10-15 12:25:29 +0000 | [diff] [blame^] | 113 | *common_flags() = *f; |
| 114 | ParseCommonFlagsFromString("strip_path_prefix="); |
| 115 | ParseCommonFlagsFromString("log_path=stderr"); |
| 116 | ParseCommonFlagsFromString("external_symbolizer_path="); |
| 117 | ParseCommonFlagsFromString("allocator_may_return_null=0"); |
| 118 | ParseCommonFlagsFromString(env); |
| 119 | *static_cast<CommonFlags*>(f) = *common_flags(); |
Kostya Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | } // namespace __tsan |