File: LLDBLocalsView.cpp

package info (click to toggle)
codelite 6.1.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 48,992 kB
  • ctags: 43,502
  • sloc: cpp: 334,263; ansic: 18,441; xml: 4,713; yacc: 2,653; lex: 2,449; python: 1,188; sh: 385; makefile: 40
file content (240 lines) | stat: -rw-r--r-- 8,431 bytes parent folder | download
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
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright            : (C) 2014 The CodeLite Team
// file name            : LLDBLocalsView.cpp
//
// -------------------------------------------------------------------------
// A
//              _____           _      _     _ _
//             /  __ \         | |    | |   (_) |
//             | /  \/ ___   __| | ___| |    _| |_ ___
//             | |    / _ \ / _  |/ _ \ |   | | __/ _ )
//             | \__/\ (_) | (_| |  __/ |___| | ||  __/
//              \____/\___/ \__,_|\___\_____/_|\__\___|
//
//                                                  F i l e
//
//    This program is free software; you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation; either version 2 of the License, or
//    (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

#include "LLDBLocalsView.h"
#include "LLDBPlugin.h"
#include "file_logger.h"
#include <wx/treelist.h>
#include <wx/wupdlock.h>
#include <wx/textdlg.h>

#define LOCALS_VIEW_NAME_COL_IDX 0
#define LOCALS_VIEW_VALUE_COL_IDX 1
#define LOCALS_VIEW_SUMMARY_COL_IDX 2
#define LOCALS_VIEW_TYPE_COL_IDX 3

LLDBLocalsView::LLDBLocalsView(wxWindow* parent, LLDBPlugin* plugin)
    : LLDBLocalsViewBase(parent)
    , m_plugin(plugin)
{
    m_treeList = new clTreeListCtrl(this,
                                    wxID_ANY,
                                    wxDefaultPosition,
                                    wxDefaultSize,
                                    wxTR_HIDE_ROOT | wxTR_HAS_BUTTONS | wxTR_FULL_ROW_HIGHLIGHT | wxTR_COLUMN_LINES |
                                        wxTR_ROW_LINES | wxTR_TWIST_BUTTONS | wxTR_MULTIPLE);

    m_treeList->AddColumn(_("Name"), 150);
    m_treeList->AddColumn(_("Value"), 300);
    m_treeList->AddColumn(_("Summary"), 300);
    m_treeList->AddColumn(_("Type"), 300);

    m_treeList->AddRoot(_("Local Vairables"));
    GetSizer()->Add(m_treeList, 1, wxEXPAND | wxALL, 2);

    m_plugin->GetLLDB()->Bind(wxEVT_LLDB_STARTED, &LLDBLocalsView::OnLLDBStarted, this);
    m_plugin->GetLLDB()->Bind(wxEVT_LLDB_EXITED, &LLDBLocalsView::OnLLDBExited, this);
    m_plugin->GetLLDB()->Bind(wxEVT_LLDB_LOCALS_UPDATED, &LLDBLocalsView::OnLLDBLocalsUpdated, this);
    m_plugin->GetLLDB()->Bind(wxEVT_LLDB_RUNNING, &LLDBLocalsView::OnLLDBRunning, this);
    m_plugin->GetLLDB()->Bind(wxEVT_LLDB_VARIABLE_EXPANDED, &LLDBLocalsView::OnLLDBVariableExpanded, this);

    m_treeList->Bind(wxEVT_COMMAND_TREE_ITEM_EXPANDING, &LLDBLocalsView::OnItemExpanding, this);
    GetSizer()->Layout();
}

LLDBLocalsView::~LLDBLocalsView()
{
    m_plugin->GetLLDB()->Unbind(wxEVT_LLDB_STARTED, &LLDBLocalsView::OnLLDBStarted, this);
    m_plugin->GetLLDB()->Unbind(wxEVT_LLDB_EXITED, &LLDBLocalsView::OnLLDBExited, this);
    m_plugin->GetLLDB()->Unbind(wxEVT_LLDB_LOCALS_UPDATED, &LLDBLocalsView::OnLLDBLocalsUpdated, this);
    m_plugin->GetLLDB()->Unbind(wxEVT_LLDB_RUNNING, &LLDBLocalsView::OnLLDBRunning, this);
    m_plugin->GetLLDB()->Unbind(wxEVT_LLDB_VARIABLE_EXPANDED, &LLDBLocalsView::OnLLDBVariableExpanded, this);
    m_treeList->Unbind(wxEVT_COMMAND_TREE_ITEM_EXPANDING, &LLDBLocalsView::OnItemExpanding, this);
}

void LLDBLocalsView::OnLLDBExited(LLDBEvent& event)
{
    event.Skip();
    Cleanup();
}

void LLDBLocalsView::OnLLDBRunning(LLDBEvent& event)
{
    event.Skip();
    Cleanup();
}

void LLDBLocalsView::OnLLDBStarted(LLDBEvent& event)
{
    event.Skip();
    Cleanup();
}

void LLDBLocalsView::OnLLDBLocalsUpdated(LLDBEvent& event)
{
    // FIXME: optimize this to only retrieve the top levle variables
    // the children should be obtained in the 'OnItemExpading' event handler
    event.Skip();
    wxWindowUpdateLocker locker(m_treeList);
    Enable(true);

    m_treeList->DeleteChildren(m_treeList->GetRootItem());
    CL_DEBUG("Updating locals view");
    DoAddVariableToView(event.GetVariables(), m_treeList->GetRootItem());
}

void LLDBLocalsView::DoAddVariableToView(const LLDBVariable::Vect_t& variables, wxTreeItemId parent)
{
    for(size_t i = 0; i < variables.size(); ++i) {
        LLDBVariable::Ptr_t variable = variables.at(i);
        wxTreeItemId item = m_treeList->AppendItem(
            parent, variable->GetName(), wxNOT_FOUND, wxNOT_FOUND, new LLDBVariableClientData(variable));
        m_treeList->SetItemText(item, LOCALS_VIEW_VALUE_COL_IDX, variable->GetValue());
        m_treeList->SetItemText(item, LOCALS_VIEW_SUMMARY_COL_IDX, variable->GetSummary());
        m_treeList->SetItemText(item, LOCALS_VIEW_TYPE_COL_IDX, variable->GetType());
        if(variable->IsValueChanged()) {
            m_treeList->SetItemTextColour(item, "RED");
        }
        if(variable->HasChildren()) {
            // insert dummy item here
            m_treeList->AppendItem(item, "<dummy>");
        }
    }

    if(!variables.empty()) {
        m_treeList->Expand(parent);
    }
}

void LLDBLocalsView::OnItemExpanding(wxTreeEvent& event)
{
    wxTreeItemIdValue cookie;
    wxTreeItemId child = m_treeList->GetFirstChild(event.GetItem(), cookie);
    if(m_treeList->GetItemText(child) == "<dummy>") {
        event.Veto();
        m_treeList->DeleteChildren(event.GetItem());

        // query the debugger about the children of this node
        if(m_plugin->GetLLDB()->IsCanInteract()) {
            int variableId = GetItemData(event.GetItem())->GetVariable()->GetLldbId();
            m_plugin->GetLLDB()->RequestVariableChildren(variableId);
            m_pendingExpandItems.insert(std::make_pair(variableId, event.GetItem()));
        }

    } else {
        event.Skip();
    }
}

LLDBVariableClientData* LLDBLocalsView::GetItemData(const wxTreeItemId& id)
{
    LLDBVariableClientData* cd = dynamic_cast<LLDBVariableClientData*>(m_treeList->GetItemData(id));
    return cd;
}

void LLDBLocalsView::Cleanup()
{
    m_treeList->DeleteChildren(m_treeList->GetRootItem());
    m_pendingExpandItems.clear();
}

void LLDBLocalsView::OnLLDBVariableExpanded(LLDBEvent& event)
{
    int variableId = event.GetVariableId();
    // try to locate this item in our map
    LLDBLocalsView::IntItemMap_t::iterator iter = m_pendingExpandItems.find(variableId);
    if(iter == m_pendingExpandItems.end()) {
        // does not belong to us - skip it
        event.Skip();
        return;
    }

    // add the variables
    DoAddVariableToView(event.GetVariables(), iter->second);
    m_pendingExpandItems.erase(iter);
}

void LLDBLocalsView::OnNewWatch(wxCommandEvent& event)
{
    wxString watch = ::wxGetTextFromUser(_("Expression to watch:"), _("Add New Watch"), "");
    if(watch.IsEmpty()) {
        return;
    }
    m_plugin->GetLLDB()->AddWatch(watch);
    
    // Refresh the locals view
    m_plugin->GetLLDB()->RequestLocals();
}

void LLDBLocalsView::OnDelete(wxCommandEvent& event)
{
    wxArrayTreeItemIds items;
    GetWatchesFromSelections(items);
    if(items.IsEmpty()) return;

    for(size_t i = 0; i < items.GetCount(); ++i) {
        wxTreeItemId item = items.Item(i);
        if(!GetItemData(item)) continue;
        LLDBVariableClientData* data = GetItemData(item);
        if(!data) continue;

        LLDBVariable::Ptr_t lldbVar = data->GetVariable();
        if(!lldbVar) continue;

        if(lldbVar->IsWatch()) {
            m_plugin->GetLLDB()->DeleteWatch(lldbVar->GetLldbId());
        }
    }
    // Refresh the locals view
    m_plugin->GetLLDB()->RequestLocals();
}

void LLDBLocalsView::OnDeleteUI(wxUpdateUIEvent& event) 
{
    wxArrayTreeItemIds items;
    GetWatchesFromSelections(items);
    event.Enable(!items.IsEmpty());
}

void LLDBLocalsView::GetWatchesFromSelections(wxArrayTreeItemIds& items)
{
    items.Clear();
    wxArrayTreeItemIds arr;
    m_treeList->GetSelections(arr);
    
    for(size_t i = 0; i < arr.GetCount(); ++i) {
        wxTreeItemId item = arr.Item(i);
        if(!GetItemData(item)) continue;
        LLDBVariableClientData* data = GetItemData(item);
        if(!data) continue;

        LLDBVariable::Ptr_t lldbVar = data->GetVariable();
        if(!lldbVar) continue;
        
        if(lldbVar->IsWatch()) {
            items.Add(item);
        }
    }
}