]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/xray/xray_flags.cc
Merge compiler-rt r291274.
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / xray / xray_flags.cc
1 //===-- xray_flags.cc -------------------------------------------*- 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 XRay, a dynamic runtime instrumentation system.
11 //
12 // XRay flag parsing logic.
13 //===----------------------------------------------------------------------===//
14
15 #include "xray_flags.h"
16 #include "sanitizer_common/sanitizer_common.h"
17 #include "sanitizer_common/sanitizer_flag_parser.h"
18 #include "sanitizer_common/sanitizer_libc.h"
19 #include "xray_defs.h"
20
21 using namespace __sanitizer;
22
23 namespace __xray {
24
25 Flags xray_flags_dont_use_directly; // use via flags().
26
27 void Flags::SetDefaults() XRAY_NEVER_INSTRUMENT {
28 #define XRAY_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
29 #include "xray_flags.inc"
30 #undef XRAY_FLAG
31 }
32
33 static void RegisterXRayFlags(FlagParser *P, Flags *F) XRAY_NEVER_INSTRUMENT {
34 #define XRAY_FLAG(Type, Name, DefaultValue, Description)                       \
35   RegisterFlag(P, #Name, Description, &F->Name);
36 #include "xray_flags.inc"
37 #undef XRAY_FLAG
38 }
39
40 void InitializeFlags() XRAY_NEVER_INSTRUMENT {
41   SetCommonFlagsDefaults();
42   auto *F = flags();
43   F->SetDefaults();
44
45   FlagParser XRayParser;
46   RegisterXRayFlags(&XRayParser, F);
47   RegisterCommonFlags(&XRayParser);
48
49   // Override from command line.
50   XRayParser.ParseString(GetEnv("XRAY_OPTIONS"));
51
52   InitializeCommonFlags();
53
54   if (Verbosity())
55     ReportUnrecognizedFlags();
56
57   if (common_flags()->help) {
58     XRayParser.PrintFlagDescriptions();
59   }
60 }
61
62 } // namespace __xray