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, |
Dean Michael Berris | 20dc6ef | 2018-04-09 04:02:09 +0000 | [diff] [blame] | 19 | ArrayRef<std::string> NeverInstrumentPaths, |
| 20 | ArrayRef<std::string> AttrListPaths, SourceManager &SM) |
Dean Michael Berris | 835832d | 2017-03-30 00:29:36 +0000 | [diff] [blame] | 21 | : AlwaysInstrument( |
| 22 | llvm::SpecialCaseList::createOrDie(AlwaysInstrumentPaths)), |
| 23 | NeverInstrument(llvm::SpecialCaseList::createOrDie(NeverInstrumentPaths)), |
Dean Michael Berris | 20dc6ef | 2018-04-09 04:02:09 +0000 | [diff] [blame] | 24 | AttrList(llvm::SpecialCaseList::createOrDie(AttrListPaths)), SM(SM) {} |
Dean Michael Berris | 835832d | 2017-03-30 00:29:36 +0000 | [diff] [blame] | 25 | |
| 26 | XRayFunctionFilter::ImbueAttribute |
| 27 | XRayFunctionFilter::shouldImbueFunction(StringRef FunctionName) const { |
| 28 | // First apply the always instrument list, than if it isn't an "always" see |
| 29 | // whether it's treated as a "never" instrument function. |
Dean Michael Berris | 20dc6ef | 2018-04-09 04:02:09 +0000 | [diff] [blame] | 30 | // TODO: Remove these as they're deprecated; use the AttrList exclusively. |
Vlad Tsyrklevich | 2eccdab | 2017-09-25 22:11:12 +0000 | [diff] [blame] | 31 | if (AlwaysInstrument->inSection("xray_always_instrument", "fun", FunctionName, |
Dean Michael Berris | 20dc6ef | 2018-04-09 04:02:09 +0000 | [diff] [blame] | 32 | "arg1") || |
| 33 | AttrList->inSection("always", "fun", FunctionName, "arg1")) |
Dean Michael Berris | 170429e | 2017-05-24 05:46:36 +0000 | [diff] [blame] | 34 | return ImbueAttribute::ALWAYS_ARG1; |
Vlad Tsyrklevich | 2eccdab | 2017-09-25 22:11:12 +0000 | [diff] [blame] | 35 | if (AlwaysInstrument->inSection("xray_always_instrument", "fun", |
Dean Michael Berris | 20dc6ef | 2018-04-09 04:02:09 +0000 | [diff] [blame] | 36 | FunctionName) || |
| 37 | AttrList->inSection("always", "fun", FunctionName)) |
Dean Michael Berris | 835832d | 2017-03-30 00:29:36 +0000 | [diff] [blame] | 38 | return ImbueAttribute::ALWAYS; |
Dean Michael Berris | 20dc6ef | 2018-04-09 04:02:09 +0000 | [diff] [blame] | 39 | |
| 40 | if (NeverInstrument->inSection("xray_never_instrument", "fun", |
| 41 | FunctionName) || |
| 42 | AttrList->inSection("never", "fun", FunctionName)) |
Dean Michael Berris | 835832d | 2017-03-30 00:29:36 +0000 | [diff] [blame] | 43 | return ImbueAttribute::NEVER; |
Dean Michael Berris | 20dc6ef | 2018-04-09 04:02:09 +0000 | [diff] [blame] | 44 | |
Dean Michael Berris | 835832d | 2017-03-30 00:29:36 +0000 | [diff] [blame] | 45 | return ImbueAttribute::NONE; |
| 46 | } |
| 47 | |
| 48 | XRayFunctionFilter::ImbueAttribute |
| 49 | XRayFunctionFilter::shouldImbueFunctionsInFile(StringRef Filename, |
| 50 | StringRef Category) const { |
Vlad Tsyrklevich | 2eccdab | 2017-09-25 22:11:12 +0000 | [diff] [blame] | 51 | if (AlwaysInstrument->inSection("xray_always_instrument", "src", Filename, |
Dean Michael Berris | 20dc6ef | 2018-04-09 04:02:09 +0000 | [diff] [blame] | 52 | Category) || |
| 53 | AttrList->inSection("always", "src", Filename, Category)) |
Dean Michael Berris | 835832d | 2017-03-30 00:29:36 +0000 | [diff] [blame] | 54 | return ImbueAttribute::ALWAYS; |
Vlad Tsyrklevich | 2eccdab | 2017-09-25 22:11:12 +0000 | [diff] [blame] | 55 | if (NeverInstrument->inSection("xray_never_instrument", "src", Filename, |
Dean Michael Berris | 20dc6ef | 2018-04-09 04:02:09 +0000 | [diff] [blame] | 56 | Category) || |
| 57 | AttrList->inSection("never", "src", Filename, Category)) |
Dean Michael Berris | 835832d | 2017-03-30 00:29:36 +0000 | [diff] [blame] | 58 | return ImbueAttribute::NEVER; |
| 59 | return ImbueAttribute::NONE; |
| 60 | } |
| 61 | |
| 62 | XRayFunctionFilter::ImbueAttribute |
| 63 | XRayFunctionFilter::shouldImbueLocation(SourceLocation Loc, |
| 64 | StringRef Category) const { |
| 65 | if (!Loc.isValid()) |
| 66 | return ImbueAttribute::NONE; |
| 67 | return this->shouldImbueFunctionsInFile(SM.getFilename(SM.getFileLoc(Loc)), |
| 68 | Category); |
| 69 | } |