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 //===----------------------------------------------------------------------===//
12 #include "clang/Basic/XRayLists.h"
14 using namespace clang;
16 XRayFunctionFilter::XRayFunctionFilter(
17 ArrayRef<std::string> AlwaysInstrumentPaths,
18 ArrayRef<std::string> NeverInstrumentPaths,
19 ArrayRef<std::string> AttrListPaths, SourceManager &SM)
21 llvm::SpecialCaseList::createOrDie(AlwaysInstrumentPaths)),
22 NeverInstrument(llvm::SpecialCaseList::createOrDie(NeverInstrumentPaths)),
23 AttrList(llvm::SpecialCaseList::createOrDie(AttrListPaths)), SM(SM) {}
25 XRayFunctionFilter::ImbueAttribute
26 XRayFunctionFilter::shouldImbueFunction(StringRef FunctionName) const {
27 // First apply the always instrument list, than if it isn't an "always" see
28 // whether it's treated as a "never" instrument function.
29 // TODO: Remove these as they're deprecated; use the AttrList exclusively.
30 if (AlwaysInstrument->inSection("xray_always_instrument", "fun", FunctionName,
32 AttrList->inSection("always", "fun", FunctionName, "arg1"))
33 return ImbueAttribute::ALWAYS_ARG1;
34 if (AlwaysInstrument->inSection("xray_always_instrument", "fun",
36 AttrList->inSection("always", "fun", FunctionName))
37 return ImbueAttribute::ALWAYS;
39 if (NeverInstrument->inSection("xray_never_instrument", "fun",
41 AttrList->inSection("never", "fun", FunctionName))
42 return ImbueAttribute::NEVER;
44 return ImbueAttribute::NONE;
47 XRayFunctionFilter::ImbueAttribute
48 XRayFunctionFilter::shouldImbueFunctionsInFile(StringRef Filename,
49 StringRef Category) const {
50 if (AlwaysInstrument->inSection("xray_always_instrument", "src", Filename,
52 AttrList->inSection("always", "src", Filename, Category))
53 return ImbueAttribute::ALWAYS;
54 if (NeverInstrument->inSection("xray_never_instrument", "src", Filename,
56 AttrList->inSection("never", "src", Filename, Category))
57 return ImbueAttribute::NEVER;
58 return ImbueAttribute::NONE;
61 XRayFunctionFilter::ImbueAttribute
62 XRayFunctionFilter::shouldImbueLocation(SourceLocation Loc,
63 StringRef Category) const {
65 return ImbueAttribute::NONE;
66 return this->shouldImbueFunctionsInFile(SM.getFilename(SM.getFileLoc(Loc)),