]>
Commit | Line | Data |
---|---|---|
866e32ad KS |
1 | //===-- ubsan_flags.cc ----------------------------------------------------===// |
2 | // | |
3 | // This file is distributed under the University of Illinois Open Source | |
4 | // License. See LICENSE.TXT for details. | |
5 | // | |
6 | //===----------------------------------------------------------------------===// | |
7 | // | |
8 | // Runtime flags for UndefinedBehaviorSanitizer. | |
9 | // | |
10 | //===----------------------------------------------------------------------===// | |
11 | ||
12 | #include "ubsan_flags.h" | |
13 | #include "sanitizer_common/sanitizer_common.h" | |
14 | #include "sanitizer_common/sanitizer_flags.h" | |
15 | ||
16 | namespace __ubsan { | |
17 | ||
18 | static const char *MaybeCallUbsanDefaultOptions() { | |
19 | return (&__ubsan_default_options) ? __ubsan_default_options() : ""; | |
20 | } | |
21 | ||
22 | void InitializeCommonFlags() { | |
23 | CommonFlags *cf = common_flags(); | |
24 | SetCommonFlagsDefaults(cf); | |
25 | cf->print_summary = false; | |
26 | // Override from user-specified string. | |
27 | ParseCommonFlagsFromString(cf, MaybeCallUbsanDefaultOptions()); | |
28 | // Override from environment variable. | |
29 | ParseCommonFlagsFromString(cf, GetEnv("UBSAN_OPTIONS")); | |
30 | } | |
31 | ||
32 | Flags ubsan_flags; | |
33 | ||
34 | static void ParseFlagsFromString(Flags *f, const char *str) { | |
35 | if (!str) | |
36 | return; | |
37 | ParseFlag(str, &f->halt_on_error, "halt_on_error", | |
38 | "Crash the program after printing the first error report"); | |
39 | ParseFlag(str, &f->print_stacktrace, "print_stacktrace", | |
40 | "Include full stacktrace into an error report"); | |
41 | } | |
42 | ||
43 | void InitializeFlags() { | |
44 | Flags *f = flags(); | |
45 | // Default values. | |
46 | f->halt_on_error = false; | |
47 | f->print_stacktrace = false; | |
48 | // Override from user-specified string. | |
49 | ParseFlagsFromString(f, MaybeCallUbsanDefaultOptions()); | |
50 | // Override from environment variable. | |
51 | ParseFlagsFromString(f, GetEnv("UBSAN_OPTIONS")); | |
52 | } | |
53 | ||
54 | } // namespace __ubsan | |
55 | ||
56 | #if !SANITIZER_SUPPORTS_WEAK_HOOKS | |
57 | extern "C" { | |
58 | SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE | |
59 | const char *__ubsan_default_options() { return ""; } | |
60 | } // extern "C" | |
61 | #endif |