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; |
| 48 | f->force_seq_cst_atomics = false; |
Dmitry Vyukov | b7b6b1c | 2012-05-17 15:00:27 +0000 | [diff] [blame] | 49 | f->strip_path_prefix = ""; |
| 50 | f->suppressions = ""; |
Kostya Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 51 | f->exitcode = 66; |
Dmitry Vyukov | cec6068 | 2012-11-28 12:56:52 +0000 | [diff] [blame] | 52 | f->log_path = "stderr"; |
Kostya Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 53 | f->atexit_sleep_ms = 1000; |
| 54 | f->verbosity = 0; |
Dmitry Vyukov | 2612773 | 2012-05-22 11:33:03 +0000 | [diff] [blame] | 55 | f->profile_memory = ""; |
Dmitry Vyukov | adfb650 | 2012-05-22 18:07:45 +0000 | [diff] [blame] | 56 | f->flush_memory_ms = 0; |
| 57 | f->stop_on_start = false; |
Dmitry Vyukov | 24567d4 | 2012-05-24 09:24:45 +0000 | [diff] [blame] | 58 | f->running_on_valgrind = false; |
Alexey Samsonov | 8cc1f81 | 2012-09-06 08:48:43 +0000 | [diff] [blame] | 59 | f->external_symbolizer_path = ""; |
Dmitry Vyukov | 3fb70e3 | 2012-11-28 13:01:32 +0000 | [diff] [blame] | 60 | f->history_size = kGoMode ? 1 : 2; // There are a lot of goroutines in Go. |
Dmitry Vyukov | 24567d4 | 2012-05-24 09:24:45 +0000 | [diff] [blame] | 61 | |
Kostya Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 62 | // Let a frontend override. |
| 63 | OverrideFlags(f); |
| 64 | |
| 65 | // Override from command line. |
Alexey Samsonov | f3be706 | 2012-07-09 13:21:39 +0000 | [diff] [blame] | 66 | 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 Vyukov | 543b94a | 2012-11-30 17:45:53 +0000 | [diff] [blame^] | 69 | ParseFlag(env, &f->suppress_java, "suppress_java"); |
Dmitry Vyukov | 8a32677 | 2012-11-07 16:14:12 +0000 | [diff] [blame] | 70 | ParseFlag(env, &f->report_bugs, "report_bugs"); |
Alexey Samsonov | f3be706 | 2012-07-09 13:21:39 +0000 | [diff] [blame] | 71 | ParseFlag(env, &f->report_thread_leaks, "report_thread_leaks"); |
Dmitry Vyukov | fd51390 | 2012-08-16 15:12:35 +0000 | [diff] [blame] | 72 | ParseFlag(env, &f->report_destroy_locked, "report_destroy_locked"); |
Alexey Samsonov | f3be706 | 2012-07-09 13:21:39 +0000 | [diff] [blame] | 73 | 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 Vyukov | cec6068 | 2012-11-28 12:56:52 +0000 | [diff] [blame] | 78 | ParseFlag(env, &f->log_path, "log_path"); |
Alexey Samsonov | f3be706 | 2012-07-09 13:21:39 +0000 | [diff] [blame] | 79 | 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 Samsonov | 8cc1f81 | 2012-09-06 08:48:43 +0000 | [diff] [blame] | 84 | ParseFlag(env, &f->external_symbolizer_path, "external_symbolizer_path"); |
Dmitry Vyukov | d698edc | 2012-11-28 12:19:50 +0000 | [diff] [blame] | 85 | ParseFlag(env, &f->history_size, "history_size"); |
Dmitry Vyukov | 8a32677 | 2012-11-07 16:14:12 +0000 | [diff] [blame] | 86 | |
| 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 Vyukov | d698edc | 2012-11-28 12:19:50 +0000 | [diff] [blame] | 92 | |
| 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 Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | } // namespace __tsan |