SBBlock.cpp revision e7a566e3301b272d18a5f752f99c8cb8b63b28a4
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
136
137bool
138SBBlock::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}
161
162PyObject *
163SBBlock::__repr__ ()
164{
165    SBStream description;
166    description.ref();
167    GetDescription (description);
168    return PyString_FromString (description.GetData());
169}
170