]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/llvm/lib/DebugInfo/GSYM/InlineInfo.cpp
MFV r356163,r356197:
[FreeBSD/FreeBSD.git] / contrib / llvm-project / llvm / lib / DebugInfo / GSYM / InlineInfo.cpp
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 //===----------------------------------------------------------------------===//
9
10 #include "llvm/DebugInfo/GSYM/FileEntry.h"
11 #include "llvm/DebugInfo/GSYM/InlineInfo.h"
12 #include <algorithm>
13 #include <inttypes.h>
14
15 using namespace llvm;
16 using namespace gsym;
17
18
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;
29   }
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;
35 }
36
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;
48     }
49     return !InlineStack.empty();
50   }
51   return false;
52 }
53
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;
59 }