1 //===-- XRayLists.cpp - XRay automatic-attribution ------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // User-provided filters for always/never XRay instrumenting certain functions.
11 //===----------------------------------------------------------------------===//
13 #include "clang/Basic/XRayLists.h"
14 #include "clang/Basic/FileManager.h"
15 #include "clang/Basic/SourceManager.h"
16 #include "llvm/Support/SpecialCaseList.h"
18 using namespace clang
;
20 XRayFunctionFilter::XRayFunctionFilter(
21 ArrayRef
<std::string
> AlwaysInstrumentPaths
,
22 ArrayRef
<std::string
> NeverInstrumentPaths
,
23 ArrayRef
<std::string
> AttrListPaths
, SourceManager
&SM
)
24 : AlwaysInstrument(llvm::SpecialCaseList::createOrDie(
25 AlwaysInstrumentPaths
, SM
.getFileManager().getVirtualFileSystem())),
26 NeverInstrument(llvm::SpecialCaseList::createOrDie(
27 NeverInstrumentPaths
, SM
.getFileManager().getVirtualFileSystem())),
28 AttrList(llvm::SpecialCaseList::createOrDie(
29 AttrListPaths
, SM
.getFileManager().getVirtualFileSystem())),
32 XRayFunctionFilter::~XRayFunctionFilter() = default;
34 XRayFunctionFilter::ImbueAttribute
35 XRayFunctionFilter::shouldImbueFunction(StringRef FunctionName
) const {
36 // First apply the always instrument list, than if it isn't an "always" see
37 // whether it's treated as a "never" instrument function.
38 // TODO: Remove these as they're deprecated; use the AttrList exclusively.
39 if (AlwaysInstrument
->inSection("xray_always_instrument", "fun", FunctionName
,
41 AttrList
->inSection("always", "fun", FunctionName
, "arg1"))
42 return ImbueAttribute::ALWAYS_ARG1
;
43 if (AlwaysInstrument
->inSection("xray_always_instrument", "fun",
45 AttrList
->inSection("always", "fun", FunctionName
))
46 return ImbueAttribute::ALWAYS
;
48 if (NeverInstrument
->inSection("xray_never_instrument", "fun",
50 AttrList
->inSection("never", "fun", FunctionName
))
51 return ImbueAttribute::NEVER
;
53 return ImbueAttribute::NONE
;
56 XRayFunctionFilter::ImbueAttribute
57 XRayFunctionFilter::shouldImbueFunctionsInFile(StringRef Filename
,
58 StringRef Category
) const {
59 if (AlwaysInstrument
->inSection("xray_always_instrument", "src", Filename
,
61 AttrList
->inSection("always", "src", Filename
, Category
))
62 return ImbueAttribute::ALWAYS
;
63 if (NeverInstrument
->inSection("xray_never_instrument", "src", Filename
,
65 AttrList
->inSection("never", "src", Filename
, Category
))
66 return ImbueAttribute::NEVER
;
67 return ImbueAttribute::NONE
;
70 XRayFunctionFilter::ImbueAttribute
71 XRayFunctionFilter::shouldImbueLocation(SourceLocation Loc
,
72 StringRef Category
) const {
74 return ImbueAttribute::NONE
;
75 return this->shouldImbueFunctionsInFile(SM
.getFilename(SM
.getFileLoc(Loc
)),