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)
20 : AlwaysInstrument(llvm::SpecialCaseList::createOrDie(
21 AlwaysInstrumentPaths, SM.getFileManager().getVirtualFileSystem())),
22 NeverInstrument(llvm::SpecialCaseList::createOrDie(
23 NeverInstrumentPaths, SM.getFileManager().getVirtualFileSystem())),
24 AttrList(llvm::SpecialCaseList::createOrDie(
25 AttrListPaths, SM.getFileManager().getVirtualFileSystem())),
28 XRayFunctionFilter::ImbueAttribute
29 XRayFunctionFilter::shouldImbueFunction(StringRef FunctionName) const {
30 // First apply the always instrument list, than if it isn't an "always" see
31 // whether it's treated as a "never" instrument function.
32 // TODO: Remove these as they're deprecated; use the AttrList exclusively.
33 if (AlwaysInstrument->inSection("xray_always_instrument", "fun", FunctionName,
35 AttrList->inSection("always", "fun", FunctionName, "arg1"))
36 return ImbueAttribute::ALWAYS_ARG1;
37 if (AlwaysInstrument->inSection("xray_always_instrument", "fun",
39 AttrList->inSection("always", "fun", FunctionName))
40 return ImbueAttribute::ALWAYS;
42 if (NeverInstrument->inSection("xray_never_instrument", "fun",
44 AttrList->inSection("never", "fun", FunctionName))
45 return ImbueAttribute::NEVER;
47 return ImbueAttribute::NONE;
50 XRayFunctionFilter::ImbueAttribute
51 XRayFunctionFilter::shouldImbueFunctionsInFile(StringRef Filename,
52 StringRef Category) const {
53 if (AlwaysInstrument->inSection("xray_always_instrument", "src", Filename,
55 AttrList->inSection("always", "src", Filename, Category))
56 return ImbueAttribute::ALWAYS;
57 if (NeverInstrument->inSection("xray_never_instrument", "src", Filename,
59 AttrList->inSection("never", "src", Filename, Category))
60 return ImbueAttribute::NEVER;
61 return ImbueAttribute::NONE;
64 XRayFunctionFilter::ImbueAttribute
65 XRayFunctionFilter::shouldImbueLocation(SourceLocation Loc,
66 StringRef Category) const {
68 return ImbueAttribute::NONE;
69 return this->shouldImbueFunctionsInFile(SM.getFilename(SM.getFileLoc(Loc)),