~ubuntu-branches/ubuntu/oneiric/codeblocks/oneiric

« back to all changes in this revision

Viewing changes to src/plugins/debuggergdb/breakpointsdlg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Casadevall
  • Date: 2008-07-17 04:39:23 UTC
  • Revision ID: james.westby@ubuntu.com-20080717043923-gmsy5cwkdjswghkm
Tags: upstream-8.02
ImportĀ upstreamĀ versionĀ 8.02

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of the Code::Blocks IDE and licensed under the GNU General Public License, version 3
 
3
 * http://www.gnu.org/licenses/gpl-3.0.html
 
4
 *
 
5
 * $Revision: 4909 $
 
6
 * $Id: breakpointsdlg.cpp 4909 2008-02-27 13:15:26Z mortenmacfly $
 
7
 * $HeadURL: svn://svn.berlios.de/codeblocks/tags/8.02/src/plugins/debuggergdb/breakpointsdlg.cpp $
 
8
 */
 
9
 
 
10
#include <sdk.h>
 
11
#include <wx/listctrl.h>
 
12
#include "breakpointsdlg.h"
 
13
#include <manager.h>
 
14
#include <editormanager.h>
 
15
#include <cbeditor.h>
 
16
#include "editbreakpointdlg.h"
 
17
#include "databreakpointdlg.h"
 
18
#include "debuggerstate.h"
 
19
#include "debuggerdriver.h"
 
20
#include <wx/intl.h>
 
21
#include <wx/xrc/xmlres.h>
 
22
#include <wx/textctrl.h>
 
23
#include <wx/button.h>
 
24
#include <wx/listbox.h>
 
25
#include <wx/checkbox.h>
 
26
#include <wx/spinctrl.h>
 
27
#include <wx/menu.h>
 
28
#include <globals.h>
 
29
namespace
 
30
{
 
31
        const int idList = wxNewId();
 
32
        const int idRemove = wxNewId();
 
33
        const int idRemoveAll = wxNewId();
 
34
        const int idProperties = wxNewId();
 
35
        const int idOpen = wxNewId();
 
36
};
 
37
 
 
38
BEGIN_EVENT_TABLE(BreakpointsDlg, wxPanel)
 
39
    EVT_MENU(idRemove, BreakpointsDlg::OnRemove)
 
40
    EVT_MENU(idRemoveAll, BreakpointsDlg::OnRemoveAll)
 
41
    EVT_MENU(idProperties, BreakpointsDlg::OnProperties)
 
42
    EVT_MENU(idOpen, BreakpointsDlg::OnOpen)
 
43
END_EVENT_TABLE()
 
44
 
 
45
BreakpointsDlg::BreakpointsDlg(DebuggerState& state)
 
46
    : wxPanel(Manager::Get()->GetAppWindow(), -1),
 
47
    m_State(state),
 
48
    m_BreakpointsList(state.GetBreakpoints())
 
49
{
 
50
    //ctor
 
51
    wxBoxSizer* bs = new wxBoxSizer(wxVERTICAL);
 
52
        m_pList = new wxListCtrl(this, idList, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_SINGLE_SEL | wxLC_HRULES | wxLC_VRULES);
 
53
    bs->Add(m_pList, 1, wxEXPAND | wxALL);
 
54
    SetAutoLayout(TRUE);
 
55
    SetSizer(bs);
 
56
 
 
57
        m_pList->InsertColumn(0, _("Type"), wxLIST_FORMAT_LEFT, 128);
 
58
        m_pList->InsertColumn(1, _("Filename/Address"), wxLIST_FORMAT_LEFT, 128);
 
59
        m_pList->InsertColumn(2, _("Line"), wxLIST_FORMAT_LEFT, 44);
 
60
 
 
61
    Connect(idList, -1, wxEVT_COMMAND_LIST_ITEM_ACTIVATED,
 
62
            (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction)
 
63
            &BreakpointsDlg::OnDoubleClick);
 
64
 
 
65
    Connect(idList, -1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK,
 
66
            (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction)
 
67
            &BreakpointsDlg::OnRightClick);
 
68
 
 
69
    FillBreakpoints();
 
70
}
 
71
 
 
72
BreakpointsDlg::~BreakpointsDlg()
 
73
{
 
74
    //dtor
 
75
}
 
76
 
 
77
void BreakpointsDlg::Refresh()
 
78
{
 
79
    FillBreakpoints();
 
80
}
 
81
 
 
82
void BreakpointsDlg::FillBreakpoints()
 
83
{
 
84
    m_pList->Freeze();
 
85
    m_pList->DeleteAllItems();
 
86
    for (unsigned int i = 0; i < m_BreakpointsList.GetCount(); ++i)
 
87
    {
 
88
        DebuggerBreakpoint* bp = m_State.GetBreakpoints()[i];
 
89
        if (bp->temporary)
 
90
            continue;
 
91
        if (bp->type == DebuggerBreakpoint::bptCode)
 
92
        {
 
93
                        m_pList->InsertItem(m_pList->GetItemCount(), _("Code"));
 
94
                        m_pList->SetItem(m_pList->GetItemCount() - 1, 1, bp->filename);
 
95
                        m_pList->SetItem(m_pList->GetItemCount() - 1, 2, wxString::Format(_T("%d"), bp->line + 1));
 
96
        }
 
97
        else if (bp->type == DebuggerBreakpoint::bptData)
 
98
        {
 
99
                        m_pList->InsertItem(m_pList->GetItemCount(), _("Data"));
 
100
                        m_pList->SetItem(m_pList->GetItemCount() - 1, 1, wxString::Format(_T("%s (read: %s, write: %s)"),
 
101
                                                                                                                                                                bp->breakAddress.c_str(),
 
102
                                                                                                                                                                bp->breakOnRead ? _T("yes") : _T("no"),
 
103
                                                                                                                                                                bp->breakOnWrite ? _T("yes") : _T("no")));
 
104
                        m_pList->SetItem(m_pList->GetItemCount() - 1, 2, wxEmptyString);
 
105
        }
 
106
        else if (bp->type == DebuggerBreakpoint::bptFunction)
 
107
        {
 
108
                        m_pList->InsertItem(m_pList->GetItemCount(), _("Function"));
 
109
                        m_pList->SetItem(m_pList->GetItemCount() - 1, 1, bp->filename);
 
110
                        m_pList->SetItem(m_pList->GetItemCount() - 1, 2, wxString::Format(_T("%d"), bp->line + 1));
 
111
        }
 
112
        m_pList->SetItemData(m_pList->GetItemCount() - 1, (long)bp);
 
113
    }
 
114
    m_pList->SetColumnWidth(0, wxLIST_AUTOSIZE);
 
115
    m_pList->SetColumnWidth(1, wxLIST_AUTOSIZE);
 
116
    m_pList->SetColumnWidth(2, wxLIST_AUTOSIZE);
 
117
    m_pList->Thaw();
 
118
}
 
119
 
 
120
void BreakpointsDlg::RemoveBreakpoint(int sel)
 
121
{
 
122
    // if debugger is running and is not paused, return
 
123
    if (m_State.HasDriver() && !m_State.GetDriver()->IsStopped())
 
124
        return;
 
125
    // if index is out of range, return
 
126
    if (sel < 0 || sel >= (int)m_State.GetBreakpoints().GetCount())
 
127
        return;
 
128
    // if not valid breakpoint, return
 
129
    DebuggerBreakpoint* bp = (DebuggerBreakpoint*)m_pList->GetItemData(sel);//m_State.GetBreakpoints()[sel];
 
130
    if (!bp)
 
131
        return;
 
132
        if (bp->type == DebuggerBreakpoint::bptData)
 
133
        {
 
134
                m_State.RemoveBreakpoint(bp);
 
135
                Refresh();
 
136
        }
 
137
        else
 
138
        {
 
139
                cbEditor* ed = Manager::Get()->GetEditorManager()->IsBuiltinOpen(bp->filenameAsPassed);
 
140
                if (ed)
 
141
                        ed->RemoveBreakpoint(bp->line);
 
142
        }
 
143
}
 
144
 
 
145
void BreakpointsDlg::OnRemove(wxCommandEvent& event)
 
146
{
 
147
    long item = m_pList->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
 
148
    if (item == -1)
 
149
        return;
 
150
    RemoveBreakpoint(item);
 
151
}
 
152
 
 
153
void BreakpointsDlg::OnRemoveAll(wxCommandEvent& event)
 
154
{
 
155
    // if debugger is running and is not paused, return
 
156
    if (m_State.HasDriver() && !m_State.GetDriver()->IsStopped())
 
157
        return;
 
158
    while (m_State.GetBreakpoints().GetCount())
 
159
    {
 
160
        // if not valid breakpoint, continue with the next one
 
161
        DebuggerBreakpoint* bp = m_State.GetBreakpoints()[0];
 
162
        if (!bp)
 
163
            continue;
 
164
        cbEditor* ed = Manager::Get()->GetEditorManager()->IsBuiltinOpen(bp->filenameAsPassed);
 
165
        if (ed)
 
166
            ed->RemoveBreakpoint(bp->line, false);
 
167
        m_State.RemoveBreakpoint(0);
 
168
    }
 
169
    FillBreakpoints();
 
170
}
 
171
 
 
172
void BreakpointsDlg::OnProperties(wxCommandEvent& event)
 
173
{
 
174
    long item = m_pList->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
 
175
    if (item == -1 || item > (int)m_State.GetBreakpoints().GetCount())
 
176
        return;
 
177
    DebuggerBreakpoint* bp = (DebuggerBreakpoint*)m_pList->GetItemData(item);//m_State.GetBreakpoints()[item];
 
178
    if (!bp)
 
179
        return;
 
180
 
 
181
    if (bp->type == DebuggerBreakpoint::bptData)
 
182
    {
 
183
        int sel = 0;
 
184
        if (bp->breakOnRead && bp->breakOnWrite)
 
185
                        sel = 2;
 
186
        else if (!bp->breakOnRead && bp->breakOnWrite)
 
187
                        sel = 1;
 
188
        DataBreakpointDlg dlg(this, -1, bp->enabled, sel);
 
189
        if (dlg.ShowModal() == wxID_OK)
 
190
        {
 
191
                bp->enabled = dlg.IsEnabled();
 
192
                bp->breakOnRead = dlg.GetSelection() != 1;
 
193
                bp->breakOnWrite = dlg.GetSelection() != 0;
 
194
                m_State.ResetBreakpoint(bp);
 
195
        }
 
196
    }
 
197
    else
 
198
    {
 
199
                int idx = m_State.HasBreakpoint(bp->filename, bp->line);
 
200
                bp = m_State.GetBreakpoint(idx);
 
201
 
 
202
                EditBreakpointDlg dlg(bp);
 
203
                PlaceWindow(&dlg);
 
204
                if (dlg.ShowModal() == wxID_OK)
 
205
                {
 
206
                        m_State.ResetBreakpoint(idx);
 
207
                }
 
208
    }
 
209
}
 
210
 
 
211
void BreakpointsDlg::OnOpen(wxCommandEvent& event)
 
212
{
 
213
    long item = m_pList->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
 
214
    if (item < 0 || item >= (int)m_State.GetBreakpoints().GetCount())
 
215
        return;
 
216
    DebuggerBreakpoint* bp = m_State.GetBreakpoints()[item];
 
217
    cbEditor* ed = Manager::Get()->GetEditorManager()->Open(bp->filename);
 
218
    if (ed)
 
219
    {
 
220
        ed->GotoLine(bp->line, true);
 
221
        ed->Activate();
 
222
    }
 
223
}
 
224
 
 
225
void BreakpointsDlg::OnRightClick(wxListEvent& event)
 
226
{
 
227
    wxMenu menu;
 
228
    menu.Append(idOpen, _("Open in editor"));
 
229
    menu.Append(idProperties, _("Breakpoint properties"));
 
230
    menu.AppendSeparator();
 
231
    menu.Append(idRemove, _("Remove breakpoint"));
 
232
    menu.Append(idRemoveAll, _("Remove all breakpoints"));
 
233
    PopupMenu(&menu);
 
234
}
 
235
 
 
236
void BreakpointsDlg::OnDoubleClick(wxListEvent& event)
 
237
{
 
238
    wxCommandEvent evt;
 
239
    OnOpen(evt);
 
240
}