blob: eeae1d3b02b02083f795c1aab36cfd8542de8abb [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- 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 Clayton23b8abb2011-09-26 07:11:27 +000011#include "lldb/API/SBAddress.h"
Greg Clayton69aa5d92010-09-07 04:20:48 +000012#include "lldb/API/SBFileSpec.h"
Caroline Tice98f930f2010-09-20 05:20:02 +000013#include "lldb/API/SBStream.h"
Greg Clayton23b8abb2011-09-26 07:11:27 +000014#include "lldb/Core/AddressRange.h"
Chris Lattner24943d22010-06-08 16:52:24 +000015#include "lldb/Symbol/Block.h"
Greg Clayton69aa5d92010-09-07 04:20:48 +000016#include "lldb/Symbol/Function.h"
Caroline Tice98f930f2010-09-20 05:20:02 +000017#include "lldb/Symbol/SymbolContext.h"
Chris Lattner24943d22010-06-08 16:52:24 +000018
19using namespace lldb;
Greg Clayton69aa5d92010-09-07 04:20:48 +000020using namespace lldb_private;
Chris Lattner24943d22010-06-08 16:52:24 +000021
22
23SBBlock::SBBlock () :
Greg Clayton63094e02010-06-23 01:19:29 +000024 m_opaque_ptr (NULL)
Chris Lattner24943d22010-06-08 16:52:24 +000025{
26}
27
28SBBlock::SBBlock (lldb_private::Block *lldb_object_ptr) :
Greg Clayton63094e02010-06-23 01:19:29 +000029 m_opaque_ptr (lldb_object_ptr)
Chris Lattner24943d22010-06-08 16:52:24 +000030{
31}
32
Greg Clayton538eb822010-11-05 23:17:00 +000033SBBlock::SBBlock(const SBBlock &rhs) :
34 m_opaque_ptr (rhs.m_opaque_ptr)
35{
36}
37
38const SBBlock &
39SBBlock::operator = (const SBBlock &rhs)
40{
41 m_opaque_ptr = rhs.m_opaque_ptr;
42 return *this;
43}
44
Chris Lattner24943d22010-06-08 16:52:24 +000045SBBlock::~SBBlock ()
46{
Greg Clayton63094e02010-06-23 01:19:29 +000047 m_opaque_ptr = NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000048}
49
50bool
51SBBlock::IsValid () const
52{
Greg Clayton63094e02010-06-23 01:19:29 +000053 return m_opaque_ptr != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000054}
55
Greg Clayton69aa5d92010-09-07 04:20:48 +000056bool
57SBBlock::IsInlined () const
58{
59 if (m_opaque_ptr)
60 return m_opaque_ptr->GetInlinedFunctionInfo () != NULL;
61 return false;
62}
63
64const char *
65SBBlock::GetInlinedName () const
66{
67 if (m_opaque_ptr)
68 {
69 const InlineFunctionInfo* inlined_info = m_opaque_ptr->GetInlinedFunctionInfo ();
70 if (inlined_info)
71 return inlined_info->GetName().AsCString (NULL);
72 }
73 return NULL;
74}
75
76SBFileSpec
77SBBlock::GetInlinedCallSiteFile () const
78{
79 SBFileSpec sb_file;
80 if (m_opaque_ptr)
81 {
82 const InlineFunctionInfo* inlined_info = m_opaque_ptr->GetInlinedFunctionInfo ();
83 if (inlined_info)
84 sb_file.SetFileSpec (inlined_info->GetCallSite().GetFile());
85 }
86 return sb_file;
87}
88
89uint32_t
90SBBlock::GetInlinedCallSiteLine () const
91{
92 if (m_opaque_ptr)
93 {
94 const InlineFunctionInfo* inlined_info = m_opaque_ptr->GetInlinedFunctionInfo ();
95 if (inlined_info)
96 return inlined_info->GetCallSite().GetLine();
97 }
98 return 0;
99}
100
101uint32_t
102SBBlock::GetInlinedCallSiteColumn () const
103{
104 if (m_opaque_ptr)
105 {
106 const InlineFunctionInfo* inlined_info = m_opaque_ptr->GetInlinedFunctionInfo ();
107 if (inlined_info)
108 return inlined_info->GetCallSite().GetColumn();
109 }
110 return 0;
111}
112
Chris Lattner24943d22010-06-08 16:52:24 +0000113void
114SBBlock::AppendVariables (bool can_create, bool get_parent_variables, lldb_private::VariableList *var_list)
115{
116 if (IsValid())
117 {
Greg Clayton33ed1702010-08-24 00:45:41 +0000118 bool show_inline = true;
119 m_opaque_ptr->AppendVariables (can_create, get_parent_variables, show_inline, var_list);
Chris Lattner24943d22010-06-08 16:52:24 +0000120 }
121}
122
Greg Clayton69aa5d92010-09-07 04:20:48 +0000123SBBlock
124SBBlock::GetParent ()
125{
126 SBBlock sb_block;
127 if (m_opaque_ptr)
128 sb_block.m_opaque_ptr = m_opaque_ptr->GetParent();
129 return sb_block;
130}
131
Greg Clayton23b8abb2011-09-26 07:11:27 +0000132lldb::SBBlock
133SBBlock::GetContainingInlinedBlock ()
134{
135 SBBlock sb_block;
136 if (m_opaque_ptr)
137 sb_block.m_opaque_ptr = m_opaque_ptr->GetContainingInlinedBlock ();
138 return sb_block;
139}
140
Greg Clayton69aa5d92010-09-07 04:20:48 +0000141SBBlock
142SBBlock::GetSibling ()
143{
144 SBBlock sb_block;
145 if (m_opaque_ptr)
146 sb_block.m_opaque_ptr = m_opaque_ptr->GetSibling();
147 return sb_block;
148}
149
150SBBlock
151SBBlock::GetFirstChild ()
152{
153 SBBlock sb_block;
154 if (m_opaque_ptr)
155 sb_block.m_opaque_ptr = m_opaque_ptr->GetFirstChild();
156 return sb_block;
157}
158
Greg Clayton23b8abb2011-09-26 07:11:27 +0000159lldb_private::Block *
160SBBlock::get ()
Greg Claytona66ba462010-10-30 04:51:46 +0000161{
162 return m_opaque_ptr;
163}
164
Greg Claytondd62d722010-12-14 04:58:53 +0000165void
166SBBlock::reset (lldb_private::Block *block)
167{
168 m_opaque_ptr = block;
169}
Chris Lattner24943d22010-06-08 16:52:24 +0000170
Caroline Tice98f930f2010-09-20 05:20:02 +0000171bool
172SBBlock::GetDescription (SBStream &description)
173{
Greg Clayton96154be2011-11-13 06:57:31 +0000174 Stream &strm = description.ref();
175
Caroline Tice98f930f2010-09-20 05:20:02 +0000176 if (m_opaque_ptr)
Caroline Ticee7a566e2010-09-20 16:21:41 +0000177 {
Caroline Tice98f930f2010-09-20 05:20:02 +0000178 lldb::user_id_t id = m_opaque_ptr->GetID();
Greg Clayton96154be2011-11-13 06:57:31 +0000179 strm.Printf ("Block: {id: %llu} ", id);
Caroline Tice98f930f2010-09-20 05:20:02 +0000180 if (IsInlined())
Caroline Ticee7a566e2010-09-20 16:21:41 +0000181 {
Greg Clayton96154be2011-11-13 06:57:31 +0000182 strm.Printf (" (inlined, '%s') ", GetInlinedName());
Caroline Ticee7a566e2010-09-20 16:21:41 +0000183 }
Caroline Tice98f930f2010-09-20 05:20:02 +0000184 lldb_private::SymbolContext sc;
185 m_opaque_ptr->CalculateSymbolContext (&sc);
186 if (sc.function)
Caroline Ticee7a566e2010-09-20 16:21:41 +0000187 {
Greg Clayton96154be2011-11-13 06:57:31 +0000188 m_opaque_ptr->DumpAddressRanges (&strm,
Caroline Tice98f930f2010-09-20 05:20:02 +0000189 sc.function->GetAddressRange().GetBaseAddress().GetFileAddress());
Caroline Ticee7a566e2010-09-20 16:21:41 +0000190 }
191 }
Caroline Tice98f930f2010-09-20 05:20:02 +0000192 else
Greg Clayton96154be2011-11-13 06:57:31 +0000193 strm.PutCString ("No value");
Caroline Tice98f930f2010-09-20 05:20:02 +0000194
195 return true;
196}
Greg Clayton23b8abb2011-09-26 07:11:27 +0000197
198uint32_t
199SBBlock::GetNumRanges ()
200{
201 if (m_opaque_ptr)
202 return m_opaque_ptr->GetNumRanges();
203 return 0;
204}
205
206lldb::SBAddress
207SBBlock::GetRangeStartAddress (uint32_t idx)
208{
209 lldb::SBAddress sb_addr;
210 if (m_opaque_ptr)
211 {
212 AddressRange range;
213 if (m_opaque_ptr->GetRangeAtIndex(idx, range))
214 {
215 sb_addr.ref() = range.GetBaseAddress();
216 }
217 }
218 return sb_addr;
219}
220
221lldb::SBAddress
222SBBlock::GetRangeEndAddress (uint32_t idx)
223{
224 lldb::SBAddress sb_addr;
225 if (m_opaque_ptr)
226 {
227 AddressRange range;
228 if (m_opaque_ptr->GetRangeAtIndex(idx, range))
229 {
230 sb_addr.ref() = range.GetBaseAddress();
231 sb_addr.ref().Slide(range.GetByteSize());
232 }
233 }
234 return sb_addr;
235}
236
237uint32_t
238SBBlock::GetRangeIndexForBlockAddress (lldb::SBAddress block_addr)
239{
240 if (m_opaque_ptr && block_addr.IsValid())
241 {
Greg Claytonbc36a862011-10-08 00:49:15 +0000242 return m_opaque_ptr->GetRangeIndexContainingAddress (block_addr.ref());
Greg Clayton23b8abb2011-09-26 07:11:27 +0000243 }
244
245 return UINT32_MAX;
246}
247