Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- 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 Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 16 | #include "lldb/Core/Stream.h" |
| 17 | #include "lldb/Symbol/Block.h" |
| 18 | #include "lldb/Symbol/Symbol.h" |
| 19 | #include "lldb/Symbol/SymbolContext.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 20 | |
| 21 | using namespace lldb_private; |
| 22 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 23 | |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 24 | void |
| 25 | StackID::Dump (Stream *s) |
| 26 | { |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 27 | s->Printf("StackID (pc = 0x%16.16" PRIx64 ", cfa = 0x%16.16" PRIx64 ", symbol_scope = %p", (uint64_t)m_pc, (uint64_t)m_cfa, m_symbol_scope); |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 28 | if (m_symbol_scope) |
| 29 | { |
| 30 | SymbolContext sc; |
| 31 | |
| 32 | m_symbol_scope->CalculateSymbolContext (&sc); |
| 33 | if (sc.block) |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 34 | s->Printf(" (Block {0x%8.8" PRIx64 "})", sc.block->GetID()); |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 35 | else if (sc.symbol) |
| 36 | s->Printf(" (Symbol{0x%8.8x})", sc.symbol->GetID()); |
| 37 | } |
| 38 | s->PutCString(") "); |
| 39 | } |
| 40 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 41 | bool |
| 42 | lldb_private::operator== (const StackID& lhs, const StackID& rhs) |
| 43 | { |
Greg Clayton | 72b7158 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 44 | if (lhs.GetCallFrameAddress() != rhs.GetCallFrameAddress()) |
| 45 | return false; |
| 46 | |
| 47 | SymbolContextScope *lhs_scope = lhs.GetSymbolContextScope(); |
| 48 | SymbolContextScope *rhs_scope = rhs.GetSymbolContextScope(); |
| 49 | |
| 50 | // Only compare the PC values if both symbol context scopes are NULL |
| 51 | if (lhs_scope == NULL && rhs_scope == NULL) |
| 52 | return lhs.GetPC() == rhs.GetPC(); |
| 53 | |
| 54 | return lhs_scope == rhs_scope; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | bool |
| 58 | lldb_private::operator!= (const StackID& lhs, const StackID& rhs) |
| 59 | { |
Greg Clayton | 72b7158 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 60 | if (lhs.GetCallFrameAddress() != rhs.GetCallFrameAddress()) |
| 61 | return true; |
| 62 | |
| 63 | SymbolContextScope *lhs_scope = lhs.GetSymbolContextScope(); |
| 64 | SymbolContextScope *rhs_scope = rhs.GetSymbolContextScope(); |
| 65 | |
| 66 | if (lhs_scope == NULL && rhs_scope == NULL) |
| 67 | return lhs.GetPC() != rhs.GetPC(); |
| 68 | |
| 69 | return lhs_scope != rhs_scope; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | bool |
| 73 | lldb_private::operator< (const StackID& lhs, const StackID& rhs) |
| 74 | { |
Greg Clayton | 72b7158 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 75 | const lldb::addr_t lhs_cfa = lhs.GetCallFrameAddress(); |
| 76 | const lldb::addr_t rhs_cfa = rhs.GetCallFrameAddress(); |
| 77 | |
Jim Ingham | 441e3b9 | 2012-03-01 00:50:50 +0000 | [diff] [blame] | 78 | // FIXME: We are assuming that the stacks grow downward in memory. That's not necessary, but true on |
| 79 | // all the machines we care about at present. If this changes, we'll have to deal with that. The ABI is the |
| 80 | // agent who knows this ordering, but the StackID has no access to the ABI. The most straightforward way |
| 81 | // to handle this is to add a "m_grows_downward" bool to the StackID, and set it in the constructor. |
| 82 | // But I'm not going to waste a bool per StackID on this till we need it. |
| 83 | |
Greg Clayton | 72b7158 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 84 | if (lhs_cfa != rhs_cfa) |
| 85 | return lhs_cfa < rhs_cfa; |
| 86 | |
| 87 | SymbolContextScope *lhs_scope = lhs.GetSymbolContextScope(); |
| 88 | SymbolContextScope *rhs_scope = rhs.GetSymbolContextScope(); |
| 89 | |
| 90 | if (lhs_scope != NULL && rhs_scope != NULL) |
| 91 | { |
| 92 | // Same exact scope, lhs is not less than (younger than rhs) |
| 93 | if (lhs_scope == rhs_scope) |
| 94 | return false; |
| 95 | |
| 96 | SymbolContext lhs_sc; |
| 97 | SymbolContext rhs_sc; |
| 98 | lhs_scope->CalculateSymbolContext (&lhs_sc); |
| 99 | rhs_scope->CalculateSymbolContext (&rhs_sc); |
| 100 | |
| 101 | // Items with the same function can only be compared |
| 102 | if (lhs_sc.function == rhs_sc.function && |
| 103 | lhs_sc.function != NULL && lhs_sc.block != NULL && |
| 104 | rhs_sc.function != NULL && rhs_sc.block != NULL) |
| 105 | { |
| 106 | return rhs_sc.block->Contains (lhs_sc.block); |
| 107 | } |
| 108 | } |
| 109 | return false; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 110 | } |