1 //===- xray-fc-account.cpp: XRay Function Call Accounting Tool ------------===//
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
7 //===----------------------------------------------------------------------===//
9 // Implementation of the helper tools dealing with XRay-generated function ids.
11 //===----------------------------------------------------------------------===//
13 #include "func-id-helper.h"
14 #include "llvm/Support/MemoryBuffer.h"
15 #include "llvm/Support/Path.h"
21 std::string
FuncIdConversionHelper::SymbolOrNumber(int32_t FuncId
) const {
22 auto CacheIt
= CachedNames
.find(FuncId
);
23 if (CacheIt
!= CachedNames
.end())
24 return CacheIt
->second
;
27 auto It
= FunctionAddresses
.find(FuncId
);
28 if (It
== FunctionAddresses
.end()) {
33 object::SectionedAddress ModuleAddress
;
34 ModuleAddress
.Address
= It
->second
;
35 // TODO: set proper section index here.
36 // object::SectionedAddress::UndefSection works for only absolute addresses.
37 ModuleAddress
.SectionIndex
= object::SectionedAddress::UndefSection
;
38 if (auto ResOrErr
= Symbolizer
.symbolizeCode(BinaryInstrMap
, ModuleAddress
)) {
40 if (DI
.FunctionName
== DILineInfo::BadString
)
41 F
<< "@(" << std::hex
<< It
->second
<< ")";
45 handleAllErrors(ResOrErr
.takeError(), [&](const ErrorInfoBase
&) {
46 F
<< "@(" << std::hex
<< It
->second
<< ")";
50 CachedNames
[FuncId
] = S
;
54 std::string
FuncIdConversionHelper::FileLineAndColumn(int32_t FuncId
) const {
55 auto It
= FunctionAddresses
.find(FuncId
);
56 if (It
== FunctionAddresses
.end())
60 object::SectionedAddress ModuleAddress
;
61 ModuleAddress
.Address
= It
->second
;
62 // TODO: set proper section index here.
63 // object::SectionedAddress::UndefSection works for only absolute addresses.
64 ModuleAddress
.SectionIndex
= object::SectionedAddress::UndefSection
;
65 auto ResOrErr
= Symbolizer
.symbolizeCode(BinaryInstrMap
, ModuleAddress
);
67 consumeError(ResOrErr
.takeError());
72 F
<< sys::path::filename(DI
.FileName
).str() << ":" << DI
.Line
<< ":"