SBBlock.cpp revision 538eb82a89a68dbc57251915080bd5152b333978
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/SBFileSpec.h"
12#include "lldb/API/SBStream.h"
13#include "lldb/Symbol/Block.h"
14#include "lldb/Symbol/Function.h"
15#include "lldb/Symbol/SymbolContext.h"
16
17using namespace lldb;
18using namespace lldb_private;
19
20
21SBBlock::SBBlock () :
22    m_opaque_ptr (NULL)
23{
24}
25
26SBBlock::SBBlock (lldb_private::Block *lldb_object_ptr) :
27    m_opaque_ptr (lldb_object_ptr)
28{
29}
30
31SBBlock::SBBlock(const SBBlock &rhs) :
32    m_opaque_ptr (rhs.m_opaque_ptr)
33{
34}
35
36const SBBlock &
37SBBlock::operator = (const SBBlock &rhs)
38{
39    m_opaque_ptr = rhs.m_opaque_ptr;
40    return *this;
41}
42
43SBBlock::~SBBlock ()
44{
45    m_opaque_ptr = NULL;
46}
47
48bool
49SBBlock::IsValid () const
50{
51    return m_opaque_ptr != NULL;
52}
53
54bool
55SBBlock::IsInlined () const
56{
57    if (m_opaque_ptr)
58        return m_opaque_ptr->GetInlinedFunctionInfo () != NULL;
59    return false;
60}
61
62const char *
63SBBlock::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
74SBFileSpec
75SBBlock::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
87uint32_t
88SBBlock::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
99uint32_t
100SBBlock::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
111void
112SBBlock::AppendVariables (bool can_create, bool get_parent_variables, lldb_private::VariableList *var_list)
113{
114    if (IsValid())
115    {
116        bool show_inline = true;
117        m_opaque_ptr->AppendVariables (can_create, get_parent_variables, show_inline, var_list);
118    }
119}
120
121SBBlock
122SBBlock::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
130SBBlock
131SBBlock::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
139SBBlock
140SBBlock::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
148const lldb_private::Block *
149SBBlock::get () const
150{
151    return m_opaque_ptr;
152}
153
154
155bool
156SBBlock::GetDescription (SBStream &description)
157{
158    if (m_opaque_ptr)
159    {
160        lldb::user_id_t id = m_opaque_ptr->GetID();
161        description.Printf ("Block: {id: %d} ", id);
162        if (IsInlined())
163        {
164            description.Printf (" (inlined, '%s') ", GetInlinedName());
165        }
166        lldb_private::SymbolContext sc;
167        m_opaque_ptr->CalculateSymbolContext (&sc);
168        if (sc.function)
169        {
170            m_opaque_ptr->DumpAddressRanges (description.get(),
171                                             sc.function->GetAddressRange().GetBaseAddress().GetFileAddress());
172        }
173    }
174    else
175        description.Printf ("No value");
176
177    return true;
178}
179