XRayLists.cpp 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #include "clang/Basic/FileManager.h"
  14. #include "clang/Basic/SourceManager.h"
  15. #include "llvm/Support/SpecialCaseList.h"
  16. using namespace clang;
  17. XRayFunctionFilter::XRayFunctionFilter(
  18. ArrayRef<std::string> AlwaysInstrumentPaths,
  19. ArrayRef<std::string> NeverInstrumentPaths,
  20. ArrayRef<std::string> AttrListPaths, SourceManager &SM)
  21. : AlwaysInstrument(llvm::SpecialCaseList::createOrDie(
  22. AlwaysInstrumentPaths, SM.getFileManager().getVirtualFileSystem())),
  23. NeverInstrument(llvm::SpecialCaseList::createOrDie(
  24. NeverInstrumentPaths, SM.getFileManager().getVirtualFileSystem())),
  25. AttrList(llvm::SpecialCaseList::createOrDie(
  26. AttrListPaths, SM.getFileManager().getVirtualFileSystem())),
  27. SM(SM) {}
  28. XRayFunctionFilter::~XRayFunctionFilter() = default;
  29. XRayFunctionFilter::ImbueAttribute
  30. XRayFunctionFilter::shouldImbueFunction(StringRef FunctionName) const {
  31. // First apply the always instrument list, than if it isn't an "always" see
  32. // whether it's treated as a "never" instrument function.
  33. // TODO: Remove these as they're deprecated; use the AttrList exclusively.
  34. if (AlwaysInstrument->inSection("xray_always_instrument", "fun", FunctionName,
  35. "arg1") ||
  36. AttrList->inSection("always", "fun", FunctionName, "arg1"))
  37. return ImbueAttribute::ALWAYS_ARG1;
  38. if (AlwaysInstrument->inSection("xray_always_instrument", "fun",
  39. FunctionName) ||
  40. AttrList->inSection("always", "fun", FunctionName))
  41. return ImbueAttribute::ALWAYS;
  42. if (NeverInstrument->inSection("xray_never_instrument", "fun",
  43. FunctionName) ||
  44. AttrList->inSection("never", "fun", FunctionName))
  45. return ImbueAttribute::NEVER;
  46. return ImbueAttribute::NONE;
  47. }
  48. XRayFunctionFilter::ImbueAttribute
  49. XRayFunctionFilter::shouldImbueFunctionsInFile(StringRef Filename,
  50. StringRef Category) const {
  51. if (AlwaysInstrument->inSection("xray_always_instrument", "src", Filename,
  52. Category) ||
  53. AttrList->inSection("always", "src", Filename, Category))
  54. return ImbueAttribute::ALWAYS;
  55. if (NeverInstrument->inSection("xray_never_instrument", "src", Filename,
  56. Category) ||
  57. AttrList->inSection("never", "src", Filename, Category))
  58. return ImbueAttribute::NEVER;
  59. return ImbueAttribute::NONE;
  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. }