1 //===-- sancov_flags.cc -----------------------------------------*- C++ -*-===// 2 // 3 // This file is distributed under the University of Illinois Open Source 4 // License. See LICENSE.TXT for details. 5 // 6 //===----------------------------------------------------------------------===// 7 // 8 // Sanitizer Coverage runtime flags. 9 // 10 //===----------------------------------------------------------------------===// 11 12 #include "sancov_flags.h" 13 #include "sanitizer_flag_parser.h" 14 #include "sanitizer_platform.h" 15 16 SANITIZER_INTERFACE_WEAK_DEF(const char*, __sancov_default_options, void) { 17 return ""; 18 } 19 20 using namespace __sanitizer; 21 22 namespace __sancov { 23 24 SancovFlags sancov_flags_dont_use_directly; // use via flags(); 25 26 void SancovFlags::SetDefaults() { 27 #define SANCOV_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue; 28 #include "sancov_flags.inc" 29 #undef SANCOV_FLAG 30 } 31 32 static void RegisterSancovFlags(FlagParser *parser, SancovFlags *f) { 33 #define SANCOV_FLAG(Type, Name, DefaultValue, Description) \ 34 RegisterFlag(parser, #Name, Description, &f->Name); 35 #include "sancov_flags.inc" 36 #undef SANCOV_FLAG 37 } 38 39 static const char *MaybeCallSancovDefaultOptions() { 40 return (&__sancov_default_options) ? __sancov_default_options() : ""; 41 } 42 43 void InitializeSancovFlags() { 44 SancovFlags *f = sancov_flags(); 45 f->SetDefaults(); 46 47 FlagParser parser; 48 RegisterSancovFlags(&parser, f); 49 50 parser.ParseString(MaybeCallSancovDefaultOptions()); 51 parser.ParseString(GetEnv("SANCOV_OPTIONS")); 52 53 ReportUnrecognizedFlags(); 54 if (f->help) parser.PrintFlagDescriptions(); 55 } 56 57 } // namespace __sancov 58