Dean Michael Berris | 835832d | 2017-03-30 00:29:36 +0000 | [diff] [blame] | 1 | //===--- XRayFunctionFilter.cpp - XRay automatic-attribution --------------===// |
| 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 | // User-provided filters for always/never XRay instrumenting certain functions. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | #include "clang/Basic/XRayLists.h" |
| 14 | |
| 15 | using namespace clang; |
| 16 | |
| 17 | XRayFunctionFilter::XRayFunctionFilter( |
| 18 | ArrayRef<std::string> AlwaysInstrumentPaths, |
| 19 | ArrayRef<std::string> NeverInstrumentPaths, SourceManager &SM) |
| 20 | : AlwaysInstrument( |
| 21 | llvm::SpecialCaseList::createOrDie(AlwaysInstrumentPaths)), |
| 22 | NeverInstrument(llvm::SpecialCaseList::createOrDie(NeverInstrumentPaths)), |
| 23 | 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. |
Vlad Tsyrklevich | 2eccdab | 2017-09-25 22:11:12 +0000 | [diff] [blame] | 29 | if (AlwaysInstrument->inSection("xray_always_instrument", "fun", FunctionName, |
| 30 | "arg1")) |
Dean Michael Berris | 170429e | 2017-05-24 05:46:36 +0000 | [diff] [blame] | 31 | return ImbueAttribute::ALWAYS_ARG1; |
Vlad Tsyrklevich | 2eccdab | 2017-09-25 22:11:12 +0000 | [diff] [blame] | 32 | if (AlwaysInstrument->inSection("xray_always_instrument", "fun", |
| 33 | FunctionName)) |
Dean Michael Berris | 835832d | 2017-03-30 00:29:36 +0000 | [diff] [blame] | 34 | return ImbueAttribute::ALWAYS; |
Vlad Tsyrklevich | 2eccdab | 2017-09-25 22:11:12 +0000 | [diff] [blame] | 35 | if (NeverInstrument->inSection("xray_never_instrument", "fun", FunctionName)) |
Dean Michael Berris | 835832d | 2017-03-30 00:29:36 +0000 | [diff] [blame] | 36 | return ImbueAttribute::NEVER; |
| 37 | return ImbueAttribute::NONE; |
| 38 | } |
| 39 | |
| 40 | XRayFunctionFilter::ImbueAttribute |
| 41 | XRayFunctionFilter::shouldImbueFunctionsInFile(StringRef Filename, |
| 42 | StringRef Category) const { |
Vlad Tsyrklevich | 2eccdab | 2017-09-25 22:11:12 +0000 | [diff] [blame] | 43 | if (AlwaysInstrument->inSection("xray_always_instrument", "src", Filename, |
| 44 | Category)) |
Dean Michael Berris | 835832d | 2017-03-30 00:29:36 +0000 | [diff] [blame] | 45 | return ImbueAttribute::ALWAYS; |
Vlad Tsyrklevich | 2eccdab | 2017-09-25 22:11:12 +0000 | [diff] [blame] | 46 | if (NeverInstrument->inSection("xray_never_instrument", "src", Filename, |
| 47 | Category)) |
Dean Michael Berris | 835832d | 2017-03-30 00:29:36 +0000 | [diff] [blame] | 48 | return ImbueAttribute::NEVER; |
| 49 | return ImbueAttribute::NONE; |
| 50 | } |
| 51 | |
| 52 | XRayFunctionFilter::ImbueAttribute |
| 53 | XRayFunctionFilter::shouldImbueLocation(SourceLocation Loc, |
| 54 | StringRef Category) const { |
| 55 | if (!Loc.isValid()) |
| 56 | return ImbueAttribute::NONE; |
| 57 | return this->shouldImbueFunctionsInFile(SM.getFilename(SM.getFileLoc(Loc)), |
| 58 | Category); |
| 59 | } |