SBBlock.cpp revision 444e35b5fdf15a25a427285650f06f1390e62c75
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"
11#include "lldb/API/SBAddress.h"
12#include "lldb/API/SBFileSpec.h"
13#include "lldb/API/SBStream.h"
14#include "lldb/Core/AddressRange.h"
15#include "lldb/Symbol/Block.h"
16#include "lldb/Symbol/Function.h"
17#include "lldb/Symbol/SymbolContext.h"
18
19using namespace lldb;
20using namespace lldb_private;
21
22
23SBBlock::SBBlock () :
24    m_opaque_ptr (NULL)
25{
26}
27
28SBBlock::SBBlock (lldb_private::Block *lldb_object_ptr) :
29    m_opaque_ptr (lldb_object_ptr)
30{
31}
32
33SBBlock::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
45SBBlock::~SBBlock ()
46{
47    m_opaque_ptr = NULL;
48}
49
50bool
51SBBlock::IsValid () const
52{
53    return m_opaque_ptr != NULL;
54}
55
56bool
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
113void
114SBBlock::AppendVariables (bool can_create, bool get_parent_variables, lldb_private::VariableList *var_list)
115{
116    if (IsValid())
117    {
118        bool show_inline = true;
119        m_opaque_ptr->AppendVariables (can_create, get_parent_variables, show_inline, var_list);
120    }
121}
122
123SBBlock
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
132lldb::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
141SBBlock
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
159lldb_private::Block *
160SBBlock::get ()
161{
162    return m_opaque_ptr;
163}
164
165void
166SBBlock::reset (lldb_private::Block *block)
167{
168    m_opaque_ptr = block;
169}
170
171bool
172SBBlock::GetDescription (SBStream &description)
173{
174    if (m_opaque_ptr)
175    {
176        lldb::user_id_t id = m_opaque_ptr->GetID();
177        description.Printf ("Block: {id: %llu} ", id);
178        if (IsInlined())
179        {
180            description.Printf (" (inlined, '%s') ", GetInlinedName());
181        }
182        lldb_private::SymbolContext sc;
183        m_opaque_ptr->CalculateSymbolContext (&sc);
184        if (sc.function)
185        {
186            m_opaque_ptr->DumpAddressRanges (description.get(),
187                                             sc.function->GetAddressRange().GetBaseAddress().GetFileAddress());
188        }
189    }
190    else
191        description.Printf ("No value");
192
193    return true;
194}
195
196uint32_t
197SBBlock::GetNumRanges ()
198{
199    if (m_opaque_ptr)
200        return m_opaque_ptr->GetNumRanges();
201    return 0;
202}
203
204lldb::SBAddress
205SBBlock::GetRangeStartAddress (uint32_t idx)
206{
207    lldb::SBAddress sb_addr;
208    if (m_opaque_ptr)
209    {
210        AddressRange range;
211        if (m_opaque_ptr->GetRangeAtIndex(idx, range))
212        {
213            sb_addr.ref() = range.GetBaseAddress();
214        }
215    }
216    return sb_addr;
217}
218
219lldb::SBAddress
220SBBlock::GetRangeEndAddress (uint32_t idx)
221{
222    lldb::SBAddress sb_addr;
223    if (m_opaque_ptr)
224    {
225        AddressRange range;
226        if (m_opaque_ptr->GetRangeAtIndex(idx, range))
227        {
228            sb_addr.ref() = range.GetBaseAddress();
229            sb_addr.ref().Slide(range.GetByteSize());
230        }
231    }
232    return sb_addr;
233}
234
235uint32_t
236SBBlock::GetRangeIndexForBlockAddress (lldb::SBAddress block_addr)
237{
238    if (m_opaque_ptr && block_addr.IsValid())
239    {
240        return m_opaque_ptr->GetRangeIndexContainingAddress (block_addr.ref());
241    }
242
243    return UINT32_MAX;
244}
245
246