/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Basic/XRayLists.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | |
13 | | #include "clang/Basic/XRayLists.h" |
14 | | #include "clang/Basic/FileManager.h" |
15 | | #include "clang/Basic/SourceManager.h" |
16 | | #include "llvm/Support/SpecialCaseList.h" |
17 | | |
18 | | using namespace clang; |
19 | | |
20 | | XRayFunctionFilter::XRayFunctionFilter( |
21 | | ArrayRef<std::string> AlwaysInstrumentPaths, |
22 | | ArrayRef<std::string> NeverInstrumentPaths, |
23 | | ArrayRef<std::string> AttrListPaths, SourceManager &SM) |
24 | | : AlwaysInstrument(llvm::SpecialCaseList::createOrDie( |
25 | | AlwaysInstrumentPaths, SM.getFileManager().getVirtualFileSystem())), |
26 | | NeverInstrument(llvm::SpecialCaseList::createOrDie( |
27 | | NeverInstrumentPaths, SM.getFileManager().getVirtualFileSystem())), |
28 | | AttrList(llvm::SpecialCaseList::createOrDie( |
29 | | AttrListPaths, SM.getFileManager().getVirtualFileSystem())), |
30 | 96.6k | SM(SM) {} |
31 | | |
32 | 91.5k | XRayFunctionFilter::~XRayFunctionFilter() = default; |
33 | | |
34 | | XRayFunctionFilter::ImbueAttribute |
35 | 23 | XRayFunctionFilter::shouldImbueFunction(StringRef FunctionName) const { |
36 | | // First apply the always instrument list, than if it isn't an "always" see |
37 | | // whether it's treated as a "never" instrument function. |
38 | | // TODO: Remove these as they're deprecated; use the AttrList exclusively. |
39 | 23 | if (AlwaysInstrument->inSection("xray_always_instrument", "fun", FunctionName, |
40 | 23 | "arg1") || |
41 | 23 | AttrList->inSection("always", "fun", FunctionName, "arg1")22 ) |
42 | 2 | return ImbueAttribute::ALWAYS_ARG1; |
43 | 21 | if (AlwaysInstrument->inSection("xray_always_instrument", "fun", |
44 | 21 | FunctionName) || |
45 | 21 | AttrList->inSection("always", "fun", FunctionName)) |
46 | 1 | return ImbueAttribute::ALWAYS; |
47 | | |
48 | 20 | if (NeverInstrument->inSection("xray_never_instrument", "fun", |
49 | 20 | FunctionName) || |
50 | 20 | AttrList->inSection("never", "fun", FunctionName)) |
51 | 1 | return ImbueAttribute::NEVER; |
52 | | |
53 | 19 | return ImbueAttribute::NONE; |
54 | 20 | } |
55 | | |
56 | | XRayFunctionFilter::ImbueAttribute |
57 | | XRayFunctionFilter::shouldImbueFunctionsInFile(StringRef Filename, |
58 | 29 | StringRef Category) const { |
59 | 29 | if (AlwaysInstrument->inSection("xray_always_instrument", "src", Filename, |
60 | 29 | Category) || |
61 | 29 | AttrList->inSection("always", "src", Filename, Category)27 ) |
62 | 4 | return ImbueAttribute::ALWAYS; |
63 | 25 | if (NeverInstrument->inSection("xray_never_instrument", "src", Filename, |
64 | 25 | Category) || |
65 | 25 | AttrList->inSection("never", "src", Filename, Category)23 ) |
66 | 4 | return ImbueAttribute::NEVER; |
67 | 21 | return ImbueAttribute::NONE; |
68 | 25 | } |
69 | | |
70 | | XRayFunctionFilter::ImbueAttribute |
71 | | XRayFunctionFilter::shouldImbueLocation(SourceLocation Loc, |
72 | 29 | StringRef Category) const { |
73 | 29 | if (!Loc.isValid()) |
74 | 0 | return ImbueAttribute::NONE; |
75 | 29 | return this->shouldImbueFunctionsInFile(SM.getFilename(SM.getFileLoc(Loc)), |
76 | 29 | Category); |
77 | 29 | } |