2012-07-09 21:21:39 +08:00
|
|
|
//===-- sanitizer_flags.cc ------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of ThreadSanitizer/AddressSanitizer runtime.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "sanitizer_flags.h"
|
|
|
|
|
|
|
|
#include "sanitizer_common.h"
|
|
|
|
#include "sanitizer_libc.h"
|
2014-03-20 21:49:21 +08:00
|
|
|
#include "sanitizer_list.h"
|
2015-01-15 23:13:43 +08:00
|
|
|
#include "sanitizer_flag_parser.h"
|
2012-07-09 21:21:39 +08:00
|
|
|
|
|
|
|
namespace __sanitizer {
|
|
|
|
|
2014-01-31 19:20:55 +08:00
|
|
|
CommonFlags common_flags_dont_use;
|
|
|
|
|
2014-03-20 21:49:21 +08:00
|
|
|
struct FlagDescription {
|
2014-03-20 20:52:52 +08:00
|
|
|
const char *name;
|
|
|
|
const char *description;
|
2014-03-20 21:49:21 +08:00
|
|
|
FlagDescription *next;
|
2014-03-20 20:52:52 +08:00
|
|
|
};
|
|
|
|
|
2014-03-20 21:49:21 +08:00
|
|
|
IntrusiveList<FlagDescription> flag_descriptions;
|
2014-03-20 20:52:52 +08:00
|
|
|
|
2014-07-10 07:59:40 +08:00
|
|
|
// If set, the tool will install its own SEGV signal handler by default.
|
|
|
|
#ifndef SANITIZER_NEEDS_SEGV
|
|
|
|
# define SANITIZER_NEEDS_SEGV 1
|
|
|
|
#endif
|
|
|
|
|
2014-12-20 05:40:04 +08:00
|
|
|
void CommonFlags::SetDefaults() {
|
2015-01-06 10:44:05 +08:00
|
|
|
#define COMMON_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
|
|
|
|
#include "sanitizer_flags.inc"
|
|
|
|
#undef COMMON_FLAG
|
2013-11-12 21:59:08 +08:00
|
|
|
}
|
|
|
|
|
2015-01-03 05:28:37 +08:00
|
|
|
void CommonFlags::CopyFrom(const CommonFlags &other) {
|
|
|
|
internal_memcpy(this, &other, sizeof(*this));
|
|
|
|
}
|
|
|
|
|
2015-07-22 07:03:13 +08:00
|
|
|
// Copy the string from "s" to "out", replacing "%b" with the binary basename.
|
|
|
|
static void SubstituteBinaryName(const char *s, char *out, uptr out_size) {
|
|
|
|
char *out_end = out + out_size;
|
|
|
|
while (*s && out < out_end - 1) {
|
|
|
|
if (s[0] != '%' || s[1] != 'b') { *out++ = *s++; continue; }
|
2015-07-29 04:27:51 +08:00
|
|
|
const char *base = GetProcessName();
|
2015-07-22 07:03:13 +08:00
|
|
|
CHECK(base);
|
|
|
|
while (*base && out < out_end - 1)
|
|
|
|
*out++ = *base++;
|
|
|
|
s += 2; // skip "%b"
|
|
|
|
}
|
|
|
|
*out = '\0';
|
|
|
|
}
|
|
|
|
|
2015-01-16 00:26:59 +08:00
|
|
|
class FlagHandlerInclude : public FlagHandlerBase {
|
|
|
|
FlagParser *parser_;
|
2015-07-22 07:03:13 +08:00
|
|
|
bool ignore_missing_;
|
2015-01-16 00:26:59 +08:00
|
|
|
|
|
|
|
public:
|
2015-07-22 07:03:13 +08:00
|
|
|
explicit FlagHandlerInclude(FlagParser *parser, bool ignore_missing)
|
|
|
|
: parser_(parser), ignore_missing_(ignore_missing) {}
|
2015-02-12 08:36:39 +08:00
|
|
|
bool Parse(const char *value) final {
|
2015-07-22 07:03:13 +08:00
|
|
|
if (internal_strchr(value, '%')) {
|
|
|
|
char *buf = (char *)MmapOrDie(kMaxPathLength, "FlagHandlerInclude");
|
|
|
|
SubstituteBinaryName(value, buf, kMaxPathLength);
|
|
|
|
bool res = parser_->ParseFile(buf, ignore_missing_);
|
|
|
|
UnmapOrDie(buf, kMaxPathLength);
|
|
|
|
return res;
|
2015-01-16 00:26:59 +08:00
|
|
|
}
|
2015-07-22 07:03:13 +08:00
|
|
|
return parser_->ParseFile(value, ignore_missing_);
|
2015-01-16 00:26:59 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-07-22 07:03:13 +08:00
|
|
|
void RegisterIncludeFlags(FlagParser *parser, CommonFlags *cf) {
|
|
|
|
FlagHandlerInclude *fh_include = new (FlagParser::Alloc) // NOLINT
|
|
|
|
FlagHandlerInclude(parser, /*ignore_missing*/ false);
|
2015-01-20 20:19:14 +08:00
|
|
|
parser->RegisterHandler("include", fh_include,
|
|
|
|
"read more options from the given file");
|
2015-07-22 07:03:13 +08:00
|
|
|
FlagHandlerInclude *fh_include_if_exists = new (FlagParser::Alloc) // NOLINT
|
|
|
|
FlagHandlerInclude(parser, /*ignore_missing*/ true);
|
|
|
|
parser->RegisterHandler(
|
|
|
|
"include_if_exists", fh_include_if_exists,
|
|
|
|
"read more options from the given file (if it exists)");
|
2015-01-20 20:19:14 +08:00
|
|
|
}
|
|
|
|
|
2015-01-15 23:13:43 +08:00
|
|
|
void RegisterCommonFlags(FlagParser *parser, CommonFlags *cf) {
|
|
|
|
#define COMMON_FLAG(Type, Name, DefaultValue, Description) \
|
|
|
|
RegisterFlag(parser, #Name, Description, &cf->Name);
|
|
|
|
#include "sanitizer_flags.inc"
|
|
|
|
#undef COMMON_FLAG
|
2015-01-16 00:26:59 +08:00
|
|
|
|
2015-07-22 07:03:13 +08:00
|
|
|
RegisterIncludeFlags(parser, cf);
|
2012-07-09 21:21:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace __sanitizer
|