1 //===-- StackID.cpp ---------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Target/StackID.h"
11 #include "lldb/Symbol/Block.h"
12 #include "lldb/Symbol/Symbol.h"
13 #include "lldb/Symbol/SymbolContext.h"
14 #include "lldb/Utility/Stream.h"
16 using namespace lldb_private;
18 void StackID::Dump(Stream *s) {
19 s->Printf("StackID (pc = 0x%16.16" PRIx64 ", cfa = 0x%16.16" PRIx64
20 ", symbol_scope = %p",
21 m_pc, m_cfa, static_cast<void *>(m_symbol_scope));
25 m_symbol_scope->CalculateSymbolContext(&sc);
27 s->Printf(" (Block {0x%8.8" PRIx64 "})", sc.block->GetID());
29 s->Printf(" (Symbol{0x%8.8x})", sc.symbol->GetID());
34 bool lldb_private::operator==(const StackID &lhs, const StackID &rhs) {
35 if (lhs.GetCallFrameAddress() != rhs.GetCallFrameAddress())
38 SymbolContextScope *lhs_scope = lhs.GetSymbolContextScope();
39 SymbolContextScope *rhs_scope = rhs.GetSymbolContextScope();
41 // Only compare the PC values if both symbol context scopes are nullptr
42 if (lhs_scope == nullptr && rhs_scope == nullptr)
43 return lhs.GetPC() == rhs.GetPC();
45 return lhs_scope == rhs_scope;
48 bool lldb_private::operator!=(const StackID &lhs, const StackID &rhs) {
49 if (lhs.GetCallFrameAddress() != rhs.GetCallFrameAddress())
52 SymbolContextScope *lhs_scope = lhs.GetSymbolContextScope();
53 SymbolContextScope *rhs_scope = rhs.GetSymbolContextScope();
55 if (lhs_scope == nullptr && rhs_scope == nullptr)
56 return lhs.GetPC() != rhs.GetPC();
58 return lhs_scope != rhs_scope;
61 bool lldb_private::operator<(const StackID &lhs, const StackID &rhs) {
62 const lldb::addr_t lhs_cfa = lhs.GetCallFrameAddress();
63 const lldb::addr_t rhs_cfa = rhs.GetCallFrameAddress();
65 // FIXME: We are assuming that the stacks grow downward in memory. That's not
66 // necessary, but true on
67 // all the machines we care about at present. If this changes, we'll have to
68 // deal with that. The ABI is the agent who knows this ordering, but the
69 // StackID has no access to the ABI. The most straightforward way to handle
70 // this is to add a "m_grows_downward" bool to the StackID, and set it in the
71 // constructor. But I'm not going to waste a bool per StackID on this till we
74 if (lhs_cfa != rhs_cfa)
75 return lhs_cfa < rhs_cfa;
77 SymbolContextScope *lhs_scope = lhs.GetSymbolContextScope();
78 SymbolContextScope *rhs_scope = rhs.GetSymbolContextScope();
80 if (lhs_scope != nullptr && rhs_scope != nullptr) {
81 // Same exact scope, lhs is not less than (younger than rhs)
82 if (lhs_scope == rhs_scope)
87 lhs_scope->CalculateSymbolContext(&lhs_sc);
88 rhs_scope->CalculateSymbolContext(&rhs_sc);
90 // Items with the same function can only be compared
91 if (lhs_sc.function == rhs_sc.function && lhs_sc.function != nullptr &&
92 lhs_sc.block != nullptr && rhs_sc.function != nullptr &&
93 rhs_sc.block != nullptr) {
94 return rhs_sc.block->Contains(lhs_sc.block);