[llvm/Object] - Convert SectionRef::getName() to return Expected<>
[llvm-complete.git] / lib / DebugInfo / GSYM / InlineInfo.cpp
blob781c1755241d3dc835146030b9a326604dd2a6f7
1 //===- InlineInfo.cpp -------------------------------------------*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
10 #include "llvm/DebugInfo/GSYM/FileEntry.h"
11 #include "llvm/DebugInfo/GSYM/InlineInfo.h"
12 #include <algorithm>
13 #include <inttypes.h>
15 using namespace llvm;
16 using namespace gsym;
19 raw_ostream &llvm::gsym::operator<<(raw_ostream &OS, const InlineInfo &II) {
20 if (!II.isValid())
21 return OS;
22 bool First = true;
23 for (auto Range : II.Ranges) {
24 if (First)
25 First = false;
26 else
27 OS << ' ';
28 OS << Range;
30 OS << " Name = " << HEX32(II.Name) << ", CallFile = " << II.CallFile
31 << ", CallLine = " << II.CallFile << '\n';
32 for (const auto &Child : II.Children)
33 OS << Child;
34 return OS;
37 static bool getInlineStackHelper(const InlineInfo &II, uint64_t Addr,
38 std::vector<const InlineInfo *> &InlineStack) {
39 if (II.Ranges.contains(Addr)) {
40 // If this is the top level that represents the concrete function,
41 // there will be no name and we shoud clear the inline stack. Otherwise
42 // we have found an inline call stack that we need to insert.
43 if (II.Name != 0)
44 InlineStack.insert(InlineStack.begin(), &II);
45 for (const auto &Child : II.Children) {
46 if (::getInlineStackHelper(Child, Addr, InlineStack))
47 break;
49 return !InlineStack.empty();
51 return false;
54 llvm::Optional<InlineInfo::InlineArray> InlineInfo::getInlineStack(uint64_t Addr) const {
55 InlineArray Result;
56 if (getInlineStackHelper(*this, Addr, Result))
57 return Result;
58 return llvm::None;