]>
git.proxmox.com Git - rustc.git/blob - src/compiler-rt/lib/sanitizer_common/sanitizer_flag_parser.h
1 //===-- sanitizer_flag_parser.h ---------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file is a part of ThreadSanitizer/AddressSanitizer runtime.
12 //===----------------------------------------------------------------------===//
14 #ifndef SANITIZER_FLAG_REGISTRY_H
15 #define SANITIZER_FLAG_REGISTRY_H
17 #include "sanitizer_internal_defs.h"
18 #include "sanitizer_libc.h"
19 #include "sanitizer_common.h"
21 namespace __sanitizer
{
23 class FlagHandlerBase
{
25 virtual bool Parse(const char *value
) { return false; }
29 class FlagHandler
: public FlagHandlerBase
{
33 explicit FlagHandler(T
*t
) : t_(t
) {}
34 bool Parse(const char *value
) final
;
38 inline bool FlagHandler
<bool>::Parse(const char *value
) {
39 if (internal_strcmp(value
, "0") == 0 ||
40 internal_strcmp(value
, "no") == 0 ||
41 internal_strcmp(value
, "false") == 0) {
45 if (internal_strcmp(value
, "1") == 0 ||
46 internal_strcmp(value
, "yes") == 0 ||
47 internal_strcmp(value
, "true") == 0) {
51 Printf("ERROR: Invalid value for bool option: '%s'\n", value
);
56 inline bool FlagHandler
<const char *>::Parse(const char *value
) {
57 *t_
= internal_strdup(value
);
62 inline bool FlagHandler
<int>::Parse(const char *value
) {
64 *t_
= internal_simple_strtoll(value
, &value_end
, 10);
65 bool ok
= *value_end
== 0;
66 if (!ok
) Printf("ERROR: Invalid value for int option: '%s'\n", value
);
71 inline bool FlagHandler
<uptr
>::Parse(const char *value
) {
73 *t_
= internal_simple_strtoll(value
, &value_end
, 10);
74 bool ok
= *value_end
== 0;
75 if (!ok
) Printf("ERROR: Invalid value for uptr option: '%s'\n", value
);
80 static const int kMaxFlags
= 200;
84 FlagHandlerBase
*handler
;
93 void RegisterHandler(const char *name
, FlagHandlerBase
*handler
,
95 void ParseString(const char *s
);
96 bool ParseFile(const char *path
, bool ignore_missing
);
97 void PrintFlagDescriptions();
99 static LowLevelAllocator Alloc
;
102 void fatal_error(const char *err
);
103 bool is_space(char c
);
104 void skip_whitespace();
107 bool run_handler(const char *name
, const char *value
);
108 char *ll_strndup(const char *s
, uptr n
);
111 template <typename T
>
112 static void RegisterFlag(FlagParser
*parser
, const char *name
, const char *desc
,
114 FlagHandler
<T
> *fh
= new (FlagParser::Alloc
) FlagHandler
<T
>(var
); // NOLINT
115 parser
->RegisterHandler(name
, fh
, desc
);
118 void ReportUnrecognizedFlags();
120 } // namespace __sanitizer
122 #endif // SANITIZER_FLAG_REGISTRY_H