diff options
| author | Kostya Kortchinsky <kostyak@google.com> | 2019-04-09 14:57:25 +0000 |
|---|---|---|
| committer | Kostya Kortchinsky <kostyak@google.com> | 2019-04-09 14:57:25 +0000 |
| commit | 7e2b15382c270ff868fb48c93dd1f125c543d289 (patch) | |
| tree | 68eae557e9b80a04ed1d83ff558927e55c018294 /compiler-rt/lib/scudo/standalone/flags_parser.h | |
| parent | d5173f5acf42d4bcf0cd9ef7a1aac27245a44c20 (diff) | |
| download | bcm5719-llvm-7e2b15382c270ff868fb48c93dd1f125c543d289.tar.gz bcm5719-llvm-7e2b15382c270ff868fb48c93dd1f125c543d289.zip | |
[scudo][standalone] Add flags & related parsers
Summary:
As with other Sanitizers, and the current version of Scudo, we can
provide flags in differents way: at compile time, through a weak
function, through an environment variable.
This change adds support for the configuration flags, and the string
parsers. Those are fairly similar to the sanitizer_common way of doing
things.
Reviewers: morehouse, hctim, vitalybuka
Reviewed By: morehouse, vitalybuka
Subscribers: mgorny, delcypher, jdoerfert, #sanitizers, llvm-commits
Tags: #llvm, #sanitizers
Differential Revision: https://reviews.llvm.org/D59597
llvm-svn: 358011
Diffstat (limited to 'compiler-rt/lib/scudo/standalone/flags_parser.h')
| -rw-r--r-- | compiler-rt/lib/scudo/standalone/flags_parser.h | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/compiler-rt/lib/scudo/standalone/flags_parser.h b/compiler-rt/lib/scudo/standalone/flags_parser.h new file mode 100644 index 00000000000..d65bff7e785 --- /dev/null +++ b/compiler-rt/lib/scudo/standalone/flags_parser.h @@ -0,0 +1,56 @@ +//===-- flags_parser.h ------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef SCUDO_FLAGS_PARSER_H_ +#define SCUDO_FLAGS_PARSER_H_ + +#include "report.h" +#include "string_utils.h" + +#include <stddef.h> +#include <stdlib.h> + +namespace scudo { + +enum class FlagType : u8 { + FT_bool, + FT_int, +}; + +class FlagParser { +public: + void registerFlag(const char *Name, const char *Desc, FlagType Type, + void *Var); + void parseString(const char *S); + void printFlagDescriptions(); + +private: + static const u32 MaxFlags = 12; + struct Flag { + const char *Name; + const char *Desc; + FlagType Type; + void *Var; + } Flags[MaxFlags]; + + u32 NumberOfFlags = 0; + const char *Buffer = nullptr; + uptr Pos = 0; + + void reportFatalError(const char *Error); + void skipWhitespace(); + void parseFlags(); + void parseFlag(); + bool runHandler(const char *Name, const char *Value); +}; + +void reportUnrecognizedFlags(); + +} // namespace scudo + +#endif // SCUDO_FLAGS_PARSER_H_ |

