File: breakpointpropertiesdlg.cpp

package info (click to toggle)
codelite 12.0+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 95,112 kB
  • sloc: cpp: 424,040; ansic: 18,284; php: 9,569; lex: 4,186; yacc: 2,820; python: 2,294; sh: 312; makefile: 51; xml: 13
file content (245 lines) | stat: -rw-r--r-- 9,267 bytes parent folder | download | duplicates (2)
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
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright            : (C) 2014 Eran Ifrah
// file name            : breakpointpropertiesdlg.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 <wx/msgdlg.h>
#include <wx/filedlg.h>
#include <wx/filename.h>
#include "breakpointpropertiesdlg.h"
#include "windowattrmanager.h"

BreakptPropertiesDlg::BreakptPropertiesDlg(wxWindow* parent)
    : BreakpointPropertiesDlgBase(parent)
{
    its_a_breakpt = true;       // Default to breakpoint for new items
    whichBreakcheck = wbc_line; // and assume it'll be a line-number type
    SetName("BreakptPropertiesDlg");
    WindowAttrManager::Load(this);
    CentreOnParent();
}

BreakptPropertiesDlg::~BreakptPropertiesDlg() {}

// Insert the data from an existing breakpoint into the dialog fields
void BreakptPropertiesDlg::EnterBPData(const BreakpointInfo& bp)
{
    // The class BreakpointInfo& b will become the new bp, so copy the old ids
    b.debugger_id = bp.debugger_id;
    b.internal_id = bp.internal_id;

    if(bp.bp_type == BP_type_watchpt) {
        its_a_breakpt = false; // UpdateUI will then tick the checkbox
        m_radioWatchtype->SetSelection(bp.watchpoint_type);
        m_textWatchExpression->SetValue(bp.watchpt_data);
    } else {
        its_a_breakpt = true;
        if(bp.memory_address.IsEmpty() == false) {
            m_checkBreakMemory->SetValue(true);
            m_textBreakMemory->Clear();
            *m_textBreakMemory << bp.memory_address;
            whichBreakcheck = wbc_memory;
        } else {
            m_textFilename->SetValue(bp.file);
            if(bp.lineno != -1) {
                m_checkLineno->SetValue(true);
                m_textLineno->Clear();
                *m_textLineno << bp.lineno;
                whichBreakcheck = wbc_line;
            } else if(!bp.function_name.IsEmpty()) {
                m_checkBreakFunction->SetValue(true);
                m_textFunctionname->SetValue(bp.function_name);
                m_checkRegex->SetValue(bp.regex == true);
                whichBreakcheck = wbc_function;
            }
        }
    }

    // We need temporarily to Disconnect this event, otherwise it's impossible to edit a watchpoint while the debugger's
    // running
    // as SetSelection(1) causes a wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING event, which is vetoed
    m_choicebook->Disconnect(wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING,
                             wxChoicebookEventHandler(BreakptPropertiesDlg::OnPageChanging),
                             NULL,
                             this);
    if(its_a_breakpt) {
        m_choicebook->SetSelection(0);
    } else {
        m_choicebook->SetSelection(1);
    }
    m_choicebook->Connect(wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING,
                          wxChoicebookEventHandler(BreakptPropertiesDlg::OnPageChanging),
                          NULL,
                          this);

    m_checkDisable->SetValue(!bp.is_enabled);
    m_checkTemp->SetValue(bp.is_temp);
    m_checkTemp->Show(its_a_breakpt); // Watchpoints can't be temporary
    m_spinIgnore->SetValue(bp.ignore_number);
    m_textCond->SetValue(bp.conditions);
    m_textCommands->SetValue(bp.commandlist);
}

void BreakptPropertiesDlg::EndModal(int retCode)
{
    if(retCode != wxID_OK) {
        return wxDialog::EndModal(retCode);
    }

    long l;
    wxString contents;
    int selectedPage = m_choicebook->GetSelection();
    if(m_choicebook->GetPageText((size_t)selectedPage) == _("Watchpoint")) {
        b.bp_type = BP_type_watchpt;
        b.watchpoint_type = (WatchpointType)m_radioWatchtype->GetSelection();
        b.watchpt_data = m_textWatchExpression->GetValue();
        if(b.watchpt_data.IsEmpty()) {
            wxMessageBox(_("You don't seem to have entered a variable for the watchpoint to watch. Please try again."),
                         wxT(":/"),
                         wxICON_ERROR);
            return;
        }
    } else {

        // reset the fields to only the proper ones are copied
        b.lineno = wxNOT_FOUND;
        b.memory_address.Clear();
        b.file.Clear();
        b.function_name.Clear();

        // It's some flavour of breakpoint (assume standard for now). Only insert enabled data, in case a lineno sort is
        // now a function bp
        b.bp_type = BP_type_break;
        switch(whichBreakcheck) {
        case wbc_line:
            contents = m_textLineno->GetValue();
            if(!contents.ToLong(&l, 0)) {
                wxMessageBox(_("The breakpoint's line-number is invalid. Please try again."), _(":/"), wxICON_ERROR);
                return;
            }
            b.lineno = (int)l;
            b.file = m_textFilename->GetValue();
            break;

        case wbc_function:
            b.function_name = m_textFunctionname->GetValue();
            if(b.function_name.IsEmpty()) {
                wxMessageBox(_("You don't seem to have entered a name for the function. Please try again."),
                             _(":/"),
                             wxICON_ERROR);
                return;
            }
            b.regex = m_checkRegex->IsChecked();
            b.file = m_textFilename->GetValue();
            break;

        case wbc_memory:
            contents = m_textBreakMemory->GetValue();
            b.memory_address = contents;
            break;
        }
    }

    b.is_enabled = !m_checkDisable->GetValue();
    b.is_temp = m_checkTemp->GetValue();
    b.ignore_number = m_spinIgnore->GetValue();
    b.conditions = m_textCond->GetValue();
    b.commandlist = m_textCommands->GetValue();

    wxDialog::EndModal(retCode);
}

void BreakptPropertiesDlg::OnCheckBreakLineno(wxCommandEvent& event)
{
    if(event.IsChecked()) {
        whichBreakcheck = wbc_line;
    }
}

void BreakptPropertiesDlg::OnCheckBreakFunction(wxCommandEvent& event)
{
    if(event.IsChecked()) {
        whichBreakcheck = wbc_function;
    }
}

void BreakptPropertiesDlg::OnCheckBreakMemory(wxCommandEvent& event)
{
    if(event.IsChecked()) {
        whichBreakcheck = wbc_memory;
    }
}

void BreakptPropertiesDlg::OnBrowse(wxCommandEvent& event)
{
    wxUnusedVar(event);
    wxString newfilepath, filepath(m_textFilename->GetValue());
    if((!filepath.IsEmpty()) && wxFileName::FileExists(filepath)) {
        newfilepath = wxFileSelector(_("Select file:"), filepath.c_str());
    } else {
        newfilepath = wxFileSelector(_("Select file:"));
    }

    if(!newfilepath.IsEmpty()) {
        m_textFilename->SetValue(newfilepath);
    }
}

void BreakptPropertiesDlg::OnCheckBreakLinenoUI(wxUpdateUIEvent& event)
{
    m_checkLineno->SetValue(whichBreakcheck == wbc_line);
    m_textLineno->Enable(m_checkLineno->IsChecked() && m_checkLineno->IsEnabled());
}

void BreakptPropertiesDlg::OnCheckBreakFunctionUI(wxUpdateUIEvent& event)
{
    m_checkBreakFunction->SetValue(whichBreakcheck == wbc_function);
    m_textFunctionname->Enable(m_checkBreakFunction->IsChecked() && m_checkBreakFunction->IsEnabled());
    m_checkRegex->Enable(m_textFunctionname->IsEnabled());
}

void BreakptPropertiesDlg::OnCheckBreakMemoryUI(wxUpdateUIEvent& event)
{
    m_checkBreakMemory->SetValue(whichBreakcheck == wbc_memory);
    m_textBreakMemory->Enable(m_checkBreakMemory->IsChecked() && m_checkBreakMemory->IsEnabled());
    // Disable the filename textctrl if the memory check is ticked
    m_textFilename->Enable(!m_textBreakMemory->IsEnabled());
}

void BreakptPropertiesDlg::OnPageChanging(wxChoicebookEvent& event)
{
    if(b.debugger_id != -1) {
        wxMessageBox(
            _("Sorry, you can't change a breakpoint to a watchpoint, or vice versa, while the debugger is running"),
            _("Not possible"),
            wxICON_ERROR | wxOK);
        event.Veto();
    }
}

void BreakptPropertiesDlg::OnPageChanged(wxChoicebookEvent& event)
{
    its_a_breakpt = m_choicebook->GetPageText(m_choicebook->GetSelection()) == _("Breakpoint");
    m_checkTemp->Show(its_a_breakpt); // Watchpoints can't be temporary
    m_checkTemp->GetContainingSizer()->Layout();
}