Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- SBBlock.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/API/SBBlock.h" |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 11 | #include "lldb/API/SBFileSpec.h" |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 12 | #include "lldb/API/SBStream.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 13 | #include "lldb/Symbol/Block.h" |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 14 | #include "lldb/Symbol/Function.h" |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 15 | #include "lldb/Symbol/SymbolContext.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 16 | |
| 17 | using namespace lldb; |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 18 | using namespace lldb_private; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | |
| 20 | |
| 21 | SBBlock::SBBlock () : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 22 | m_opaque_ptr (NULL) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 23 | { |
| 24 | } |
| 25 | |
| 26 | SBBlock::SBBlock (lldb_private::Block *lldb_object_ptr) : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 27 | m_opaque_ptr (lldb_object_ptr) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 28 | { |
| 29 | } |
| 30 | |
Greg Clayton | 538eb82 | 2010-11-05 23:17:00 +0000 | [diff] [blame] | 31 | SBBlock::SBBlock(const SBBlock &rhs) : |
| 32 | m_opaque_ptr (rhs.m_opaque_ptr) |
| 33 | { |
| 34 | } |
| 35 | |
| 36 | const SBBlock & |
| 37 | SBBlock::operator = (const SBBlock &rhs) |
| 38 | { |
| 39 | m_opaque_ptr = rhs.m_opaque_ptr; |
| 40 | return *this; |
| 41 | } |
| 42 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 43 | SBBlock::~SBBlock () |
| 44 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 45 | m_opaque_ptr = NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | bool |
| 49 | SBBlock::IsValid () const |
| 50 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 51 | return m_opaque_ptr != NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 54 | bool |
| 55 | SBBlock::IsInlined () const |
| 56 | { |
| 57 | if (m_opaque_ptr) |
| 58 | return m_opaque_ptr->GetInlinedFunctionInfo () != NULL; |
| 59 | return false; |
| 60 | } |
| 61 | |
| 62 | const char * |
| 63 | SBBlock::GetInlinedName () const |
| 64 | { |
| 65 | if (m_opaque_ptr) |
| 66 | { |
| 67 | const InlineFunctionInfo* inlined_info = m_opaque_ptr->GetInlinedFunctionInfo (); |
| 68 | if (inlined_info) |
| 69 | return inlined_info->GetName().AsCString (NULL); |
| 70 | } |
| 71 | return NULL; |
| 72 | } |
| 73 | |
| 74 | SBFileSpec |
| 75 | SBBlock::GetInlinedCallSiteFile () const |
| 76 | { |
| 77 | SBFileSpec sb_file; |
| 78 | if (m_opaque_ptr) |
| 79 | { |
| 80 | const InlineFunctionInfo* inlined_info = m_opaque_ptr->GetInlinedFunctionInfo (); |
| 81 | if (inlined_info) |
| 82 | sb_file.SetFileSpec (inlined_info->GetCallSite().GetFile()); |
| 83 | } |
| 84 | return sb_file; |
| 85 | } |
| 86 | |
| 87 | uint32_t |
| 88 | SBBlock::GetInlinedCallSiteLine () const |
| 89 | { |
| 90 | if (m_opaque_ptr) |
| 91 | { |
| 92 | const InlineFunctionInfo* inlined_info = m_opaque_ptr->GetInlinedFunctionInfo (); |
| 93 | if (inlined_info) |
| 94 | return inlined_info->GetCallSite().GetLine(); |
| 95 | } |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | uint32_t |
| 100 | SBBlock::GetInlinedCallSiteColumn () const |
| 101 | { |
| 102 | if (m_opaque_ptr) |
| 103 | { |
| 104 | const InlineFunctionInfo* inlined_info = m_opaque_ptr->GetInlinedFunctionInfo (); |
| 105 | if (inlined_info) |
| 106 | return inlined_info->GetCallSite().GetColumn(); |
| 107 | } |
| 108 | return 0; |
| 109 | } |
| 110 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 111 | void |
| 112 | SBBlock::AppendVariables (bool can_create, bool get_parent_variables, lldb_private::VariableList *var_list) |
| 113 | { |
| 114 | if (IsValid()) |
| 115 | { |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 116 | bool show_inline = true; |
| 117 | m_opaque_ptr->AppendVariables (can_create, get_parent_variables, show_inline, var_list); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 118 | } |
| 119 | } |
| 120 | |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 121 | SBBlock |
| 122 | SBBlock::GetParent () |
| 123 | { |
| 124 | SBBlock sb_block; |
| 125 | if (m_opaque_ptr) |
| 126 | sb_block.m_opaque_ptr = m_opaque_ptr->GetParent(); |
| 127 | return sb_block; |
| 128 | } |
| 129 | |
| 130 | SBBlock |
| 131 | SBBlock::GetSibling () |
| 132 | { |
| 133 | SBBlock sb_block; |
| 134 | if (m_opaque_ptr) |
| 135 | sb_block.m_opaque_ptr = m_opaque_ptr->GetSibling(); |
| 136 | return sb_block; |
| 137 | } |
| 138 | |
| 139 | SBBlock |
| 140 | SBBlock::GetFirstChild () |
| 141 | { |
| 142 | SBBlock sb_block; |
| 143 | if (m_opaque_ptr) |
| 144 | sb_block.m_opaque_ptr = m_opaque_ptr->GetFirstChild(); |
| 145 | return sb_block; |
| 146 | } |
| 147 | |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 148 | const lldb_private::Block * |
| 149 | SBBlock::get () const |
| 150 | { |
| 151 | return m_opaque_ptr; |
| 152 | } |
| 153 | |
Greg Clayton | dd62d72 | 2010-12-14 04:58:53 +0000 | [diff] [blame^] | 154 | void |
| 155 | SBBlock::reset (lldb_private::Block *block) |
| 156 | { |
| 157 | m_opaque_ptr = block; |
| 158 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 159 | |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 160 | bool |
| 161 | SBBlock::GetDescription (SBStream &description) |
| 162 | { |
| 163 | if (m_opaque_ptr) |
Caroline Tice | e7a566e | 2010-09-20 16:21:41 +0000 | [diff] [blame] | 164 | { |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 165 | lldb::user_id_t id = m_opaque_ptr->GetID(); |
| 166 | description.Printf ("Block: {id: %d} ", id); |
| 167 | if (IsInlined()) |
Caroline Tice | e7a566e | 2010-09-20 16:21:41 +0000 | [diff] [blame] | 168 | { |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 169 | description.Printf (" (inlined, '%s') ", GetInlinedName()); |
Caroline Tice | e7a566e | 2010-09-20 16:21:41 +0000 | [diff] [blame] | 170 | } |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 171 | lldb_private::SymbolContext sc; |
| 172 | m_opaque_ptr->CalculateSymbolContext (&sc); |
| 173 | if (sc.function) |
Caroline Tice | e7a566e | 2010-09-20 16:21:41 +0000 | [diff] [blame] | 174 | { |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 175 | m_opaque_ptr->DumpAddressRanges (description.get(), |
| 176 | sc.function->GetAddressRange().GetBaseAddress().GetFileAddress()); |
Caroline Tice | e7a566e | 2010-09-20 16:21:41 +0000 | [diff] [blame] | 177 | } |
| 178 | } |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 179 | else |
| 180 | description.Printf ("No value"); |
| 181 | |
| 182 | return true; |
| 183 | } |