]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/llvm-xray/func-id-helper.cc
Merge llvm, clang, lld and lldb release_40 branch r292009. Also update
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / llvm-xray / func-id-helper.cc
1 //===- xray-fc-account.cc - XRay Function Call Accounting Tool ------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Implementation of the helper tools dealing with XRay-generated function ids.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "func-id-helper.h"
15 #include "llvm/Support/Path.h"
16 #include <sstream>
17
18 using namespace llvm;
19 using namespace xray;
20
21 std::string FuncIdConversionHelper::SymbolOrNumber(int32_t FuncId) const {
22   std::ostringstream F;
23   auto It = FunctionAddresses.find(FuncId);
24   if (It == FunctionAddresses.end()) {
25     F << "#" << FuncId;
26     return F.str();
27   }
28
29   if (auto ResOrErr = Symbolizer.symbolizeCode(BinaryInstrMap, It->second)) {
30     auto &DI = *ResOrErr;
31     if (DI.FunctionName == "<invalid>")
32       F << "@(" << std::hex << It->second << ")";
33     else
34       F << DI.FunctionName;
35   } else
36     handleAllErrors(ResOrErr.takeError(), [&](const ErrorInfoBase &) {
37       F << "@(" << std::hex << It->second << ")";
38     });
39
40   return F.str();
41 }
42
43 std::string FuncIdConversionHelper::FileLineAndColumn(int32_t FuncId) const {
44   auto It = FunctionAddresses.find(FuncId);
45   if (It == FunctionAddresses.end())
46     return "(unknown)";
47
48   std::ostringstream F;
49   auto ResOrErr = Symbolizer.symbolizeCode(BinaryInstrMap, It->second);
50   if (!ResOrErr) {
51     consumeError(ResOrErr.takeError());
52     return "(unknown)";
53   }
54
55   auto &DI = *ResOrErr;
56   F << sys::path::filename(DI.FileName).str() << ":" << DI.Line << ":"
57     << DI.Column;
58
59   return F.str();
60 }