2018-05-02 02:43:17 +02:00
|
|
|
//===- xray-fc-account.cpp: XRay Function Call Accounting Tool ------------===//
|
2017-01-10 03:38:11 +01:00
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-01-10 03:38:11 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Implementation of the helper tools dealing with XRay-generated function ids.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "func-id-helper.h"
|
|
|
|
#include "llvm/Support/Path.h"
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace xray;
|
|
|
|
|
|
|
|
std::string FuncIdConversionHelper::SymbolOrNumber(int32_t FuncId) const {
|
2018-03-01 02:59:24 +01:00
|
|
|
auto CacheIt = CachedNames.find(FuncId);
|
|
|
|
if (CacheIt != CachedNames.end())
|
|
|
|
return CacheIt->second;
|
|
|
|
|
2017-01-10 03:38:11 +01:00
|
|
|
std::ostringstream F;
|
|
|
|
auto It = FunctionAddresses.find(FuncId);
|
|
|
|
if (It == FunctionAddresses.end()) {
|
|
|
|
F << "#" << FuncId;
|
|
|
|
return F.str();
|
|
|
|
}
|
|
|
|
|
2019-02-27 14:17:36 +01:00
|
|
|
object::SectionedAddress ModuleAddress;
|
|
|
|
ModuleAddress.Address = It->second;
|
|
|
|
// TODO: set proper section index here.
|
|
|
|
// object::SectionedAddress::UndefSection works for only absolute addresses.
|
|
|
|
ModuleAddress.SectionIndex = object::SectionedAddress::UndefSection;
|
|
|
|
if (auto ResOrErr = Symbolizer.symbolizeCode(BinaryInstrMap, ModuleAddress)) {
|
2017-01-10 03:38:11 +01:00
|
|
|
auto &DI = *ResOrErr;
|
2019-08-05 10:52:28 +02:00
|
|
|
if (DI.FunctionName == "<invalid>")
|
2017-01-10 03:38:11 +01:00
|
|
|
F << "@(" << std::hex << It->second << ")";
|
|
|
|
else
|
|
|
|
F << DI.FunctionName;
|
|
|
|
} else
|
|
|
|
handleAllErrors(ResOrErr.takeError(), [&](const ErrorInfoBase &) {
|
|
|
|
F << "@(" << std::hex << It->second << ")";
|
|
|
|
});
|
|
|
|
|
2018-03-01 02:59:24 +01:00
|
|
|
auto S = F.str();
|
|
|
|
CachedNames[FuncId] = S;
|
|
|
|
return S;
|
2017-01-10 03:38:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string FuncIdConversionHelper::FileLineAndColumn(int32_t FuncId) const {
|
|
|
|
auto It = FunctionAddresses.find(FuncId);
|
|
|
|
if (It == FunctionAddresses.end())
|
|
|
|
return "(unknown)";
|
|
|
|
|
|
|
|
std::ostringstream F;
|
2019-02-27 14:17:36 +01:00
|
|
|
object::SectionedAddress ModuleAddress;
|
|
|
|
ModuleAddress.Address = It->second;
|
|
|
|
// TODO: set proper section index here.
|
|
|
|
// object::SectionedAddress::UndefSection works for only absolute addresses.
|
|
|
|
ModuleAddress.SectionIndex = object::SectionedAddress::UndefSection;
|
|
|
|
auto ResOrErr = Symbolizer.symbolizeCode(BinaryInstrMap, ModuleAddress);
|
2017-01-10 03:38:11 +01:00
|
|
|
if (!ResOrErr) {
|
|
|
|
consumeError(ResOrErr.takeError());
|
|
|
|
return "(unknown)";
|
|
|
|
}
|
|
|
|
|
|
|
|
auto &DI = *ResOrErr;
|
|
|
|
F << sys::path::filename(DI.FileName).str() << ":" << DI.Line << ":"
|
|
|
|
<< DI.Column;
|
|
|
|
|
|
|
|
return F.str();
|
|
|
|
}
|