SBBlock.cpp revision a66ba46379fe41036d870975c56ccc2319cb6618
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 ()
32{
33    m_opaque_ptr = NULL;
34}
35
36bool
37SBBlock::IsValid () const
38{
39    return m_opaque_ptr != NULL;
40}
41
42bool
43SBBlock::IsInlined () const
44{
45    if (m_opaque_ptr)
46        return m_opaque_ptr->GetInlinedFunctionInfo () != NULL;
47    return false;
48}
49
50const char *
51SBBlock::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
62SBFileSpec
63SBBlock::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
75uint32_t
76SBBlock::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
87uint32_t
88SBBlock::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
99void
100SBBlock::AppendVariables (bool can_create, bool get_parent_variables, lldb_private::VariableList *var_list)
101{
102    if (IsValid())
103    {
104        bool show_inline = true;
105        m_opaque_ptr->AppendVariables (can_create, get_parent_variables, show_inline, var_list);
106    }
107}
108
109SBBlock
110SBBlock::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
118SBBlock
119SBBlock::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
127SBBlock
128SBBlock::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
136const lldb_private::Block *
137SBBlock::get () const
138{
139    return m_opaque_ptr;
140}
141
142
143bool
144SBBlock::GetDescription (SBStream &description)
145{
146    if (m_opaque_ptr)
147    {
148        lldb::user_id_t id = m_opaque_ptr->GetID();
149        description.Printf ("Block: {id: %d} ", id);
150        if (IsInlined())
151        {
152            description.Printf (" (inlined, '%s') ", GetInlinedName());
153        }
154        lldb_private::SymbolContext sc;
155        m_opaque_ptr->CalculateSymbolContext (&sc);
156        if (sc.function)
157        {
158            m_opaque_ptr->DumpAddressRanges (description.get(),
159                                             sc.function->GetAddressRange().GetBaseAddress().GetFileAddress());
160        }
161    }
162    else
163        description.Printf ("No value");
164
165    return true;
166}
167