xref: /netbsd-src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_flags.h (revision a7c257b03e4462df2b1020128fb82716512d7856)
1 //===-- sanitizer_flags.h ---------------------------------------*- C++ -*-===//
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/AddressSanitizer runtime.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef SANITIZER_FLAGS_H
15 #define SANITIZER_FLAGS_H
16 
17 #include "sanitizer_internal_defs.h"
18 
19 namespace __sanitizer {
20 
21 enum HandleSignalMode {
22   kHandleSignalNo,
23   kHandleSignalYes,
24   kHandleSignalExclusive,
25 };
26 
27 struct CommonFlags {
28 #define COMMON_FLAG(Type, Name, DefaultValue, Description) Type Name;
29 #include "sanitizer_flags.inc"
30 #undef COMMON_FLAG
31 
32   void SetDefaults();
33   void CopyFrom(const CommonFlags &other);
34 };
35 
36 // Functions to get/set global CommonFlags shared by all sanitizer runtimes:
37 extern CommonFlags common_flags_dont_use;
common_flags()38 inline const CommonFlags *common_flags() {
39   return &common_flags_dont_use;
40 }
41 
SetCommonFlagsDefaults()42 inline void SetCommonFlagsDefaults() {
43   common_flags_dont_use.SetDefaults();
44 }
45 
46 // This function can only be used to setup tool-specific overrides for
47 // CommonFlags defaults. Generally, it should only be used right after
48 // SetCommonFlagsDefaults(), but before ParseCommonFlagsFromString(), and
49 // only during the flags initialization (i.e. before they are used for
50 // the first time).
OverrideCommonFlags(const CommonFlags & cf)51 inline void OverrideCommonFlags(const CommonFlags &cf) {
52   common_flags_dont_use.CopyFrom(cf);
53 }
54 
55 void SubstituteForFlagValue(const char *s, char *out, uptr out_size);
56 
57 class FlagParser;
58 void RegisterCommonFlags(FlagParser *parser,
59                          CommonFlags *cf = &common_flags_dont_use);
60 void RegisterIncludeFlags(FlagParser *parser, CommonFlags *cf);
61 
62 // Should be called after parsing all flags. Sets up common flag values
63 // and perform initializations common to all sanitizers (e.g. setting
64 // verbosity).
65 void InitializeCommonFlags(CommonFlags *cf = &common_flags_dont_use);
66 }  // namespace __sanitizer
67 
68 #endif  // SANITIZER_FLAGS_H
69