blob: ca337f9144062dd4f004aa178f103073b1808ed9 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- StackID.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 "lldb/Target/StackID.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
Greg Clayton59e8fc1c2010-08-30 18:11:35 +000016#include "lldb/Core/Stream.h"
17#include "lldb/Symbol/Block.h"
18#include "lldb/Symbol/Symbol.h"
19#include "lldb/Symbol/SymbolContext.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020
21using namespace lldb_private;
22
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023
Greg Clayton59e8fc1c2010-08-30 18:11:35 +000024void
25StackID::Dump (Stream *s)
26{
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000027 s->Printf("StackID (pc = 0x%16.16" PRIx64 ", cfa = 0x%16.16" PRIx64 ", symbol_scope = %p",
28 m_pc, m_cfa, static_cast<void*>(m_symbol_scope));
Greg Clayton59e8fc1c2010-08-30 18:11:35 +000029 if (m_symbol_scope)
30 {
31 SymbolContext sc;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000032
Greg Clayton59e8fc1c2010-08-30 18:11:35 +000033 m_symbol_scope->CalculateSymbolContext (&sc);
34 if (sc.block)
Daniel Malead01b2952012-11-29 21:49:15 +000035 s->Printf(" (Block {0x%8.8" PRIx64 "})", sc.block->GetID());
Greg Clayton59e8fc1c2010-08-30 18:11:35 +000036 else if (sc.symbol)
37 s->Printf(" (Symbol{0x%8.8x})", sc.symbol->GetID());
38 }
39 s->PutCString(") ");
40}
41
Chris Lattner30fdc8d2010-06-08 16:52:24 +000042bool
43lldb_private::operator== (const StackID& lhs, const StackID& rhs)
44{
Greg Clayton6dadd502010-09-02 21:44:10 +000045 if (lhs.GetCallFrameAddress() != rhs.GetCallFrameAddress())
46 return false;
47
48 SymbolContextScope *lhs_scope = lhs.GetSymbolContextScope();
49 SymbolContextScope *rhs_scope = rhs.GetSymbolContextScope();
50
51 // Only compare the PC values if both symbol context scopes are NULL
52 if (lhs_scope == NULL && rhs_scope == NULL)
53 return lhs.GetPC() == rhs.GetPC();
54
55 return lhs_scope == rhs_scope;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056}
57
58bool
59lldb_private::operator!= (const StackID& lhs, const StackID& rhs)
60{
Greg Clayton6dadd502010-09-02 21:44:10 +000061 if (lhs.GetCallFrameAddress() != rhs.GetCallFrameAddress())
62 return true;
63
64 SymbolContextScope *lhs_scope = lhs.GetSymbolContextScope();
65 SymbolContextScope *rhs_scope = rhs.GetSymbolContextScope();
66
67 if (lhs_scope == NULL && rhs_scope == NULL)
68 return lhs.GetPC() != rhs.GetPC();
69
70 return lhs_scope != rhs_scope;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000071}
72
73bool
74lldb_private::operator< (const StackID& lhs, const StackID& rhs)
75{
Greg Clayton6dadd502010-09-02 21:44:10 +000076 const lldb::addr_t lhs_cfa = lhs.GetCallFrameAddress();
77 const lldb::addr_t rhs_cfa = rhs.GetCallFrameAddress();
78
Jim Inghamb5c0d1c2012-03-01 00:50:50 +000079 // FIXME: We are assuming that the stacks grow downward in memory. That's not necessary, but true on
80 // all the machines we care about at present. If this changes, we'll have to deal with that. The ABI is the
81 // agent who knows this ordering, but the StackID has no access to the ABI. The most straightforward way
82 // to handle this is to add a "m_grows_downward" bool to the StackID, and set it in the constructor.
83 // But I'm not going to waste a bool per StackID on this till we need it.
84
Greg Clayton6dadd502010-09-02 21:44:10 +000085 if (lhs_cfa != rhs_cfa)
86 return lhs_cfa < rhs_cfa;
87
88 SymbolContextScope *lhs_scope = lhs.GetSymbolContextScope();
89 SymbolContextScope *rhs_scope = rhs.GetSymbolContextScope();
90
91 if (lhs_scope != NULL && rhs_scope != NULL)
92 {
93 // Same exact scope, lhs is not less than (younger than rhs)
94 if (lhs_scope == rhs_scope)
95 return false;
96
97 SymbolContext lhs_sc;
98 SymbolContext rhs_sc;
99 lhs_scope->CalculateSymbolContext (&lhs_sc);
100 rhs_scope->CalculateSymbolContext (&rhs_sc);
101
102 // Items with the same function can only be compared
103 if (lhs_sc.function == rhs_sc.function &&
104 lhs_sc.function != NULL && lhs_sc.block != NULL &&
105 rhs_sc.function != NULL && rhs_sc.block != NULL)
106 {
107 return rhs_sc.block->Contains (lhs_sc.block);
108 }
109 }
110 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000111}