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