1 //===-- XRayLists.cpp - XRay automatic-attribution ------------------------===// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // User-provided filters for always/never XRay instrumenting certain functions. 10 // 11 //===----------------------------------------------------------------------===// 12 #include "clang/Basic/XRayLists.h" 13 14 using namespace clang; 15 16 XRayFunctionFilter::XRayFunctionFilter( 17 ArrayRef<std::string> AlwaysInstrumentPaths, 18 ArrayRef<std::string> NeverInstrumentPaths, 19 ArrayRef<std::string> AttrListPaths, SourceManager &SM) 20 : AlwaysInstrument( 21 llvm::SpecialCaseList::createOrDie(AlwaysInstrumentPaths)), 22 NeverInstrument(llvm::SpecialCaseList::createOrDie(NeverInstrumentPaths)), 23 AttrList(llvm::SpecialCaseList::createOrDie(AttrListPaths)), SM(SM) {} 24 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, 31 "arg1") || 32 AttrList->inSection("always", "fun", FunctionName, "arg1")) 33 return ImbueAttribute::ALWAYS_ARG1; 34 if (AlwaysInstrument->inSection("xray_always_instrument", "fun", 35 FunctionName) || 36 AttrList->inSection("always", "fun", FunctionName)) 37 return ImbueAttribute::ALWAYS; 38 39 if (NeverInstrument->inSection("xray_never_instrument", "fun", 40 FunctionName) || 41 AttrList->inSection("never", "fun", FunctionName)) 42 return ImbueAttribute::NEVER; 43 44 return ImbueAttribute::NONE; 45 } 46 47 XRayFunctionFilter::ImbueAttribute 48 XRayFunctionFilter::shouldImbueFunctionsInFile(StringRef Filename, 49 StringRef Category) const { 50 if (AlwaysInstrument->inSection("xray_always_instrument", "src", Filename, 51 Category) || 52 AttrList->inSection("always", "src", Filename, Category)) 53 return ImbueAttribute::ALWAYS; 54 if (NeverInstrument->inSection("xray_never_instrument", "src", Filename, 55 Category) || 56 AttrList->inSection("never", "src", Filename, Category)) 57 return ImbueAttribute::NEVER; 58 return ImbueAttribute::NONE; 59 } 60 61 XRayFunctionFilter::ImbueAttribute 62 XRayFunctionFilter::shouldImbueLocation(SourceLocation Loc, 63 StringRef Category) const { 64 if (!Loc.isValid()) 65 return ImbueAttribute::NONE; 66 return this->shouldImbueFunctionsInFile(SM.getFilename(SM.getFileLoc(Loc)), 67 Category); 68 } 69