Path: blob/main/contrib/llvm-project/clang/lib/Basic/XRayLists.cpp
35232 views
//===-- XRayLists.cpp - XRay automatic-attribution ------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// User-provided filters for always/never XRay instrumenting certain functions.9//10//===----------------------------------------------------------------------===//1112#include "clang/Basic/XRayLists.h"13#include "clang/Basic/FileManager.h"14#include "clang/Basic/SourceManager.h"15#include "llvm/Support/SpecialCaseList.h"1617using namespace clang;1819XRayFunctionFilter::XRayFunctionFilter(20ArrayRef<std::string> AlwaysInstrumentPaths,21ArrayRef<std::string> NeverInstrumentPaths,22ArrayRef<std::string> AttrListPaths, SourceManager &SM)23: AlwaysInstrument(llvm::SpecialCaseList::createOrDie(24AlwaysInstrumentPaths, SM.getFileManager().getVirtualFileSystem())),25NeverInstrument(llvm::SpecialCaseList::createOrDie(26NeverInstrumentPaths, SM.getFileManager().getVirtualFileSystem())),27AttrList(llvm::SpecialCaseList::createOrDie(28AttrListPaths, SM.getFileManager().getVirtualFileSystem())),29SM(SM) {}3031XRayFunctionFilter::~XRayFunctionFilter() = default;3233XRayFunctionFilter::ImbueAttribute34XRayFunctionFilter::shouldImbueFunction(StringRef FunctionName) const {35// First apply the always instrument list, than if it isn't an "always" see36// whether it's treated as a "never" instrument function.37// TODO: Remove these as they're deprecated; use the AttrList exclusively.38if (AlwaysInstrument->inSection("xray_always_instrument", "fun", FunctionName,39"arg1") ||40AttrList->inSection("always", "fun", FunctionName, "arg1"))41return ImbueAttribute::ALWAYS_ARG1;42if (AlwaysInstrument->inSection("xray_always_instrument", "fun",43FunctionName) ||44AttrList->inSection("always", "fun", FunctionName))45return ImbueAttribute::ALWAYS;4647if (NeverInstrument->inSection("xray_never_instrument", "fun",48FunctionName) ||49AttrList->inSection("never", "fun", FunctionName))50return ImbueAttribute::NEVER;5152return ImbueAttribute::NONE;53}5455XRayFunctionFilter::ImbueAttribute56XRayFunctionFilter::shouldImbueFunctionsInFile(StringRef Filename,57StringRef Category) const {58if (AlwaysInstrument->inSection("xray_always_instrument", "src", Filename,59Category) ||60AttrList->inSection("always", "src", Filename, Category))61return ImbueAttribute::ALWAYS;62if (NeverInstrument->inSection("xray_never_instrument", "src", Filename,63Category) ||64AttrList->inSection("never", "src", Filename, Category))65return ImbueAttribute::NEVER;66return ImbueAttribute::NONE;67}6869XRayFunctionFilter::ImbueAttribute70XRayFunctionFilter::shouldImbueLocation(SourceLocation Loc,71StringRef Category) const {72if (!Loc.isValid())73return ImbueAttribute::NONE;74return this->shouldImbueFunctionsInFile(SM.getFilename(SM.getFileLoc(Loc)),75Category);76}777879