File: LLDBOutputView.cpp

package info (click to toggle)
codelite 14.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 112,816 kB
  • sloc: cpp: 483,662; ansic: 150,144; php: 9,569; lex: 4,186; python: 3,417; yacc: 2,820; sh: 1,147; makefile: 52; xml: 13
file content (282 lines) | stat: -rw-r--r-- 10,953 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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright            : (C) 2014 Eran Ifrah
// file name            : LLDBBreakpointsPane.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 "LLDBOutputView.h"
#include "LLDBProtocol/LLDBBreakpoint.h"
#include "event_notifier.h"
#include "LLDBNewBreakpointDlg.h"
#include "LLDBPlugin.h"
#include "ieditor.h"
#include "LLDBProtocol/LLDBEnums.h"
#include "file_logger.h"
#include "ColoursAndFontsManager.h"
#include "lexer_configuration.h"
#include "bitmap_loader.h"
#include "imanager.h"
#include "globals.h"

class LLDBBreakpointClientData : public wxTreeItemData
{
    LLDBBreakpoint::Ptr_t m_breakpoint;

public:
    LLDBBreakpointClientData(LLDBBreakpoint::Ptr_t bp)
        : m_breakpoint(bp)
    {
    }

    LLDBBreakpoint::Ptr_t GetBreakpoint() { return m_breakpoint; }
};

LLDBOutputView::LLDBOutputView(wxWindow* parent, LLDBPlugin* plugin)
    : LLDBOutputViewBase(parent)
    , m_plugin(plugin)
    , m_connector(plugin->GetLLDB())
{
    m_tbBreakpoints->AddTool(wxID_DELETE, _("Delete Breakpoint"), clGetManager()->GetStdIcons()->LoadBitmap("minus"));
    m_tbBreakpoints->AddTool(wxID_CLEAR, _("Delete All Breakpoints"),
                             clGetManager()->GetStdIcons()->LoadBitmap("clean"));
    m_tbBreakpoints->AddTool(wxID_NEW, _("New Breakpoint"), clGetManager()->GetStdIcons()->LoadBitmap("plus"));
    m_tbBreakpoints->Realize();
    m_tbBreakpoints->Bind(wxEVT_TOOL, &LLDBOutputView::OnDeleteBreakpoint, this, wxID_DELETE);
    m_tbBreakpoints->Bind(wxEVT_UPDATE_UI, &LLDBOutputView::OnDeleteBreakpointUI, this, wxID_DELETE);
    m_tbBreakpoints->Bind(wxEVT_TOOL, &LLDBOutputView::OnDeleteAll, this, wxID_CLEAR);
    m_tbBreakpoints->Bind(wxEVT_UPDATE_UI, &LLDBOutputView::OnDeleteAllUI, this, wxID_CLEAR);
    m_tbBreakpoints->Bind(wxEVT_TOOL, &LLDBOutputView::OnNewBreakpoint, this, wxID_NEW);
    m_tbBreakpoints->Bind(wxEVT_UPDATE_UI, &LLDBOutputView::OnNewBreakpointUI, this, wxID_NEW);

    Initialize();
    m_connector->Bind(wxEVT_LLDB_INTERPERTER_REPLY, &LLDBOutputView::OnConsoleOutput, this);
    m_connector->Bind(wxEVT_LLDB_STARTED, &LLDBOutputView::OnLLDBStarted, this);
    m_connector->Bind(wxEVT_LLDB_BREAKPOINTS_UPDATED, &LLDBOutputView::OnBreakpointsUpdated, this);
    m_connector->Bind(wxEVT_LLDB_BREAKPOINTS_DELETED_ALL, &LLDBOutputView::OnBreakpointsUpdated, this);
    EventNotifier::Get()->TopFrame()->Bind(wxEVT_COMMAND_MENU_SELECTED, &LLDBOutputView::OnSelectAll, this,
                                           wxID_SELECTALL);
    EventNotifier::Get()->TopFrame()->Bind(wxEVT_COMMAND_MENU_SELECTED, &LLDBOutputView::OnCopy, this, wxID_COPY);
    m_treeCtrlBreakpoints->AddHeader("#");
    m_treeCtrlBreakpoints->AddHeader("Function");
    m_treeCtrlBreakpoints->AddHeader("File");
    m_treeCtrlBreakpoints->AddHeader("Line");
    m_treeCtrlBreakpoints->AddRoot("Breakpoints");
}

LLDBOutputView::~LLDBOutputView()
{
    m_connector->Unbind(wxEVT_LLDB_INTERPERTER_REPLY, &LLDBOutputView::OnConsoleOutput, this);
    m_connector->Unbind(wxEVT_LLDB_STARTED, &LLDBOutputView::OnLLDBStarted, this);
    m_connector->Unbind(wxEVT_LLDB_BREAKPOINTS_UPDATED, &LLDBOutputView::OnBreakpointsUpdated, this);
    m_connector->Unbind(wxEVT_LLDB_BREAKPOINTS_DELETED_ALL, &LLDBOutputView::OnBreakpointsUpdated, this);
    EventNotifier::Get()->TopFrame()->Unbind(wxEVT_COMMAND_MENU_SELECTED, &LLDBOutputView::OnSelectAll, this,
                                             wxID_SELECTALL);
    EventNotifier::Get()->TopFrame()->Unbind(wxEVT_COMMAND_MENU_SELECTED, &LLDBOutputView::OnCopy, this, wxID_COPY);
}

void LLDBOutputView::Clear()
{
    // free all user data from the list
    m_treeCtrlBreakpoints->DeleteAllItems();
    m_treeCtrlBreakpoints->AddRoot("Breakpoints");
}

void LLDBOutputView::Initialize()
{
    Clear();
    LexerConf::Ptr_t lexer = ColoursAndFontsManager::Get().GetLexer("text");
    if(lexer) { lexer->Apply(m_stcConsole); }

    // initialize the console view
    m_stcConsole->SetReadOnly(true);

    LLDBBreakpoint::Vec_t breakpoints = m_connector->GetAllBreakpoints();
    for(size_t i = 0; i < breakpoints.size(); ++i) {

        LLDBBreakpoint::Ptr_t bp = breakpoints.at(i);
        wxTreeItemId parent =
            m_treeCtrlBreakpoints->AppendItem(m_treeCtrlBreakpoints->GetRootItem(), wxString() << bp->GetId(),
                                              wxNOT_FOUND, wxNOT_FOUND, new LLDBBreakpointClientData(bp));
        m_treeCtrlBreakpoints->SetItemText(parent, bp->GetName(), 1);
        m_treeCtrlBreakpoints->SetItemText(parent, m_plugin->GetFilenameForDisplay(bp->GetFilename()), 2);
        m_treeCtrlBreakpoints->SetItemText(parent, wxString() << bp->GetLineNumber(), 3);

        // add the children breakpoints (sites)
        if(!bp->GetChildren().empty()) {
            const LLDBBreakpoint::Vec_t& children = bp->GetChildren();
            for(size_t i = 0; i < children.size(); ++i) {
                LLDBBreakpoint::Ptr_t breakpoint = children.at(i);
                wxTreeItemId child =
                    m_treeCtrlBreakpoints->AppendItem(parent, wxString() << breakpoint->GetId(), wxNOT_FOUND,
                                                      wxNOT_FOUND, new LLDBBreakpointClientData(breakpoint));
                m_treeCtrlBreakpoints->SetItemText(child, breakpoint->GetName(), 1);
                m_treeCtrlBreakpoints->SetItemText(child, m_plugin->GetFilenameForDisplay(breakpoint->GetFilename()),
                                                   2);
                m_treeCtrlBreakpoints->SetItemText(child, wxString() << breakpoint->GetLineNumber(), 3);
            }
        }
    }
}

void LLDBOutputView::OnBreakpointsUpdated(LLDBEvent& event)
{
    event.Skip();
    clDEBUG() << "Setting LLDB breakpoints to:";
    for(size_t i = 0; i < event.GetBreakpoints().size(); ++i) {
        clDEBUG() << event.GetBreakpoints().at(i)->ToString();
    }
    m_connector->UpdateAppliedBreakpoints(event.GetBreakpoints());
    Initialize();
}

void LLDBOutputView::OnNewBreakpoint(wxCommandEvent& event)
{
    LLDBNewBreakpointDlg dlg(EventNotifier::Get()->TopFrame());
    if(dlg.ShowModal() == wxID_OK) {
        LLDBBreakpoint::Ptr_t bp = dlg.GetBreakpoint();
        if(bp->IsValid()) {
            m_connector->AddBreakpoint(bp);
            m_connector->ApplyBreakpoints();
        }
    }
}

void LLDBOutputView::OnNewBreakpointUI(wxUpdateUIEvent& event) { event.Enable(true); }

void LLDBOutputView::OnDeleteAll(wxCommandEvent& event)
{
    wxUnusedVar(event);
    m_connector->DeleteAllBreakpoints();
}

void LLDBOutputView::OnDeleteAllUI(wxUpdateUIEvent& event)
{
    event.Enable(m_treeCtrlBreakpoints->GetChildrenCount(m_treeCtrlBreakpoints->GetRootItem()));
}

void LLDBOutputView::OnDeleteBreakpoint(wxCommandEvent& event)
{
    // get the breakpoint we want to delete
    wxArrayTreeItemIds selections;
    m_treeCtrlBreakpoints->GetSelections(selections);
    for(size_t i = 0; i < selections.GetCount(); ++i) {
        m_connector->MarkBreakpointForDeletion(GetBreakpoint(selections.Item(i)));
    }
    m_connector->DeleteBreakpoints();
}

void LLDBOutputView::OnDeleteBreakpointUI(wxUpdateUIEvent& event)
{
    wxTreeItemId item = m_treeCtrlBreakpoints->GetSelection();
    LLDBBreakpoint::Ptr_t bp = GetBreakpoint(item);
    event.Enable(bp && !bp->IsLocation());
}

LLDBBreakpoint::Ptr_t LLDBOutputView::GetBreakpoint(const wxTreeItemId& item)
{
    if(!item.IsOk()) { return LLDBBreakpoint::Ptr_t(NULL); }
    LLDBBreakpointClientData* cd = dynamic_cast<LLDBBreakpointClientData*>(m_treeCtrlBreakpoints->GetItemData(item));
    if(cd) {
        return cd->GetBreakpoint();
    } else {
        return LLDBBreakpoint::Ptr_t(NULL);
    }
}

void LLDBOutputView::GotoBreakpoint(LLDBBreakpoint::Ptr_t bp)
{
    if(!bp) return;
    wxFileName fileLoc(bp->GetFilename());
    if(fileLoc.Exists()) {
        if(m_plugin->GetManager()->OpenFile(fileLoc.GetFullPath(), "", bp->GetLineNumber() - 1)) {
            IEditor* editor = m_plugin->GetManager()->GetActiveEditor();
            if(editor) { editor->SetActive(); }
        }
    }
}

void LLDBOutputView::OnSelectAll(wxCommandEvent& event)
{
    event.Skip();
    if(m_stcConsole->HasFocus()) {
        event.Skip(false);
        m_stcConsole->SelectAll();
    }
}

void LLDBOutputView::OnCopy(wxCommandEvent& event)
{
    event.Skip();
    if(m_stcConsole->HasFocus()) {
        event.Skip(false);
        if(m_stcConsole->CanCopy()) m_stcConsole->Copy();
    }
}

void LLDBOutputView::OnConsoleOutput(LLDBEvent& event)
{
    event.Skip();
    m_stcConsole->SetReadOnly(false);
    wxString text;
    if(!m_stcConsole->IsEmpty() && !m_stcConsole->GetText().EndsWith("\n")) { text << "\n"; }
    text << event.GetString();
    text.Trim();
    if(text.IsEmpty()) return;

    text << "\n";
    m_stcConsole->AppendText(text);
    m_stcConsole->SetReadOnly(true);
    int lastPos = m_stcConsole->GetLastPosition();
    m_stcConsole->SetCurrentPos(lastPos);
    m_stcConsole->SetSelectionStart(lastPos);
    m_stcConsole->SetSelectionEnd(lastPos);
    m_stcConsole->ScrollToEnd();

    // give the focus back to the console text control
    m_textCtrlConsoleSend->CallAfter(&wxTextCtrl::SetFocus);
}

void LLDBOutputView::OnSendCommandToLLDB(wxCommandEvent& event)
{
    wxString commandText = m_textCtrlConsoleSend->GetValue();
    commandText.Trim().Trim(false);

    if(commandText.Lower() == "quit" || commandText.Lower() == "exit") {
        m_textCtrlConsoleSend->ChangeValue("");
        return;
    }
    m_connector->SendInterperterCommand(commandText);
    m_textCtrlConsoleSend->ChangeValue("");
}

void LLDBOutputView::OnLLDBStarted(LLDBEvent& event)
{
    event.Skip();
    m_stcConsole->SetReadOnly(false);
    m_stcConsole->ClearAll();
    m_stcConsole->SetReadOnly(true);
}
void LLDBOutputView::OnBpActivated(wxTreeEvent& event)
{
    event.Skip();
    CallAfter(&LLDBOutputView::GotoBreakpoint, GetBreakpoint(event.GetItem()));
}