aboutsummaryrefslogtreecommitdiff
path: root/source/DataFormatters/TypeSynthetic.cpp
blob: 5bd8d30e48737ce9ed1ed1acb1d4b9dd77398574 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
//===-- TypeSynthetic.cpp ----------------------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

// C Includes

// C++ Includes

// Other libraries and framework includes

// Project includes
#include "lldb/lldb-public.h"
#include "lldb/lldb-enumerations.h"

#include "lldb/Core/Debugger.h"
#include "lldb/Core/StreamString.h"
#include "lldb/DataFormatters/TypeSynthetic.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/ScriptInterpreter.h"
#include "lldb/Symbol/ClangASTType.h"
#include "lldb/Target/StackFrame.h"
#include "lldb/Target/Target.h"

using namespace lldb;
using namespace lldb_private;

void
TypeFilterImpl::AddExpressionPath (const std::string& path)
{
    bool need_add_dot = true;
    if (path[0] == '.' ||
        (path[0] == '-' && path[1] == '>') ||
        path[0] == '[')
        need_add_dot = false;
    // add a '.' symbol to help forgetful users
    if(!need_add_dot)
        m_expression_paths.push_back(path);
    else
        m_expression_paths.push_back(std::string(".") + path);
}

bool
TypeFilterImpl::SetExpressionPathAtIndex (size_t i, const std::string& path)
{
    if (i >= GetCount())
        return false;
    bool need_add_dot = true;
    if (path[0] == '.' ||
        (path[0] == '-' && path[1] == '>') ||
        path[0] == '[')
        need_add_dot = false;
    // add a '.' symbol to help forgetful users
    if(!need_add_dot)
        m_expression_paths[i] = path;
    else
        m_expression_paths[i] = std::string(".") + path;
    return true;
}

size_t
TypeFilterImpl::FrontEnd::GetIndexOfChildWithName (const ConstString &name)
{
    const char* name_cstr = name.GetCString();
    if (name_cstr)
    {
        for (size_t i = 0; i < filter->GetCount(); i++)
        {
            const char* expr_cstr = filter->GetExpressionPathAtIndex(i);
            if (expr_cstr)
            {
                if (*expr_cstr == '.')
                    expr_cstr++;
                else if (*expr_cstr == '-' && *(expr_cstr+1) == '>')
                    expr_cstr += 2;
            }
            if (expr_cstr)
            {
                if (!::strcmp(name_cstr, expr_cstr))
                    return i;
            }
        }
    }
    return UINT32_MAX;
}

std::string
TypeFilterImpl::GetDescription()
{
    StreamString sstr;
    sstr.Printf("%s%s%s {\n",
                Cascades() ? "" : " (not cascading)",
                SkipsPointers() ? " (skip pointers)" : "",
                SkipsReferences() ? " (skip references)" : "");
    
    for (size_t i = 0; i < GetCount(); i++)
    {
        sstr.Printf("    %s\n",
                    GetExpressionPathAtIndex(i));
    }
    
    sstr.Printf("}");
    return sstr.GetString();
}

std::string
CXXSyntheticChildren::GetDescription()
{
    StreamString sstr;
    sstr.Printf("%s%s%s Generator at %p - %s",
                Cascades() ? "" : " (not cascading)",
                SkipsPointers() ? " (skip pointers)" : "",
                SkipsReferences() ? " (skip references)" : "",
                reinterpret_cast<void*>(reinterpret_cast<intptr_t>(m_create_callback)),
                m_description.c_str());

    return sstr.GetString();
}

lldb::ValueObjectSP
SyntheticChildrenFrontEnd::CreateValueObjectFromExpression (const char* name,
                                                            const char* expression,
                                                            const ExecutionContext& exe_ctx)
{
    ValueObjectSP valobj_sp(ValueObject::CreateValueObjectFromExpression(name, expression, exe_ctx));
    if (valobj_sp)
        valobj_sp->SetSyntheticChildrenGenerated(true);
    return valobj_sp;
}

lldb::ValueObjectSP
SyntheticChildrenFrontEnd::CreateValueObjectFromAddress (const char* name,
                                                         uint64_t address,
                                                         const ExecutionContext& exe_ctx,
                                                         ClangASTType type)
{
    ValueObjectSP valobj_sp(ValueObject::CreateValueObjectFromAddress(name, address, exe_ctx, type));
    if (valobj_sp)
        valobj_sp->SetSyntheticChildrenGenerated(true);
    return valobj_sp;
}

lldb::ValueObjectSP
SyntheticChildrenFrontEnd::CreateValueObjectFromData (const char* name,
                                                      const DataExtractor& data,
                                                      const ExecutionContext& exe_ctx,
                                                      ClangASTType type)
{
    ValueObjectSP valobj_sp(ValueObject::CreateValueObjectFromData(name, data, exe_ctx, type));
    if (valobj_sp)
        valobj_sp->SetSyntheticChildrenGenerated(true);
    return valobj_sp;
}

#ifndef LLDB_DISABLE_PYTHON

ScriptedSyntheticChildren::FrontEnd::FrontEnd(std::string pclass, ValueObject &backend) :
SyntheticChildrenFrontEnd(backend),
m_python_class(pclass),
m_wrapper_sp(),
m_interpreter(NULL)
{
    if (backend == LLDB_INVALID_UID)
        return;
    
    TargetSP target_sp = backend.GetTargetSP();
    
    if (!target_sp)
        return;
    
    m_interpreter = target_sp->GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
    
    if (m_interpreter != NULL)
        m_wrapper_sp = m_interpreter->CreateSyntheticScriptedProvider(m_python_class.c_str(), backend.GetSP());
}

ScriptedSyntheticChildren::FrontEnd::~FrontEnd()
{
}

lldb::ValueObjectSP
ScriptedSyntheticChildren::FrontEnd::GetChildAtIndex (size_t idx)
{
    if (!m_wrapper_sp || !m_interpreter)
        return lldb::ValueObjectSP();
    
    return m_interpreter->GetChildAtIndex(m_wrapper_sp, idx);
}

bool
ScriptedSyntheticChildren::FrontEnd::IsValid ()
{
    return (m_wrapper_sp && m_wrapper_sp->IsValid() && m_interpreter);
}

size_t
ScriptedSyntheticChildren::FrontEnd::CalculateNumChildren ()
{
    if (!m_wrapper_sp || m_interpreter == NULL)
        return 0;
    return m_interpreter->CalculateNumChildren(m_wrapper_sp);
}

bool
ScriptedSyntheticChildren::FrontEnd::Update ()
{
    if (!m_wrapper_sp || m_interpreter == NULL)
        return false;
    
    return m_interpreter->UpdateSynthProviderInstance(m_wrapper_sp);
}

bool
ScriptedSyntheticChildren::FrontEnd::MightHaveChildren ()
{
    if (!m_wrapper_sp || m_interpreter == NULL)
        return false;
    
    return m_interpreter->MightHaveChildrenSynthProviderInstance(m_wrapper_sp);
}

size_t
ScriptedSyntheticChildren::FrontEnd::GetIndexOfChildWithName (const ConstString &name)
{
    if (!m_wrapper_sp || m_interpreter == NULL)
        return UINT32_MAX;
    return m_interpreter->GetIndexOfChildWithName(m_wrapper_sp, name.GetCString());
}

lldb::ValueObjectSP
ScriptedSyntheticChildren::FrontEnd::GetSyntheticValue ()
{
    if (!m_wrapper_sp || m_interpreter == NULL)
        return nullptr;
    
    return m_interpreter->GetSyntheticValue(m_wrapper_sp);
}

std::string
ScriptedSyntheticChildren::GetDescription()
{
    StreamString sstr;
    sstr.Printf("%s%s%s Python class %s",
                Cascades() ? "" : " (not cascading)",
                SkipsPointers() ? " (skip pointers)" : "",
                SkipsReferences() ? " (skip references)" : "",
                m_python_class.c_str());
    
    return sstr.GetString();
}

#endif // #ifndef LLDB_DISABLE_PYTHON