File: breakpointsmgr.h

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 (341 lines) | stat: -rw-r--r-- 10,843 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
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright            : (C) 2008 by Eran Ifrah
// file name            : breakpointmgr.h
//
// -------------------------------------------------------------------------
// 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.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
#ifndef BREAKPOINTS_MANAGER_H
#define BREAKPOINTS_MANAGER_H

#include "list"
#include "vector"
#include <set>
#include "wx/string.h"
#include "debugger.h"
#include "cl_editor.h"
#include "sessionmanager.h"
#include "wx/arrstr.h"
#include "wx/dragimag.h"

class myDragImage;

#define FIRST_INTERNAL_ID 10000

class BreakptMgr
{
    BreakpointInfoVec_t m_bps;                    // The vector of breakpoints
    BreakpointInfoVec_t m_pendingBreakpointsList; // These are any breakpoints that the debugger won't (yet) accept
                                                  // (often because they're in a plugin)

    int NextInternalID; // Used to give each bp a unique internal ID. Start at 10k to avoid confusion with gdb's IDs

    myDragImage* m_dragImage;
    bool m_expectingControl;

protected:
    // Delete all breakpoint markers for this file, then re-mark with the currently-correct marker
    void DoRefreshFileBreakpoints(LEditor* editor);
    void DoProvideBestBP_Type(
        LEditor* editor,
        const std::vector<BreakpointInfo>& li); // Tells the editor which is the most appropriate bp marker to show

    // Delete all line-type breakpoint markers in all editors
    // Done before refreshing after a delete, lest it was the last bp in a file
    void DeleteAllBreakpointMarkers();
    std::set<wxString> GetFilesWithBreakpointMarkers();

    /**
     * Return the index of the bp with the passed id, in the vector that will normally be m_bps
     */
    int FindBreakpointById(double id, const std::vector<BreakpointInfo>& li);

    /**
     * Can gdb accept this alteration, or will be bp have to be replaced?
     */
    bool CanThisBreakpointBeUpdated(const BreakpointInfo& bp1, const BreakpointInfo& bp2) const;

    /**
     * Sets bp.bp_type to the value most appropriate to its contents
     */
    void SetBestBPType(BreakpointInfo& bp);

    /**
     * Ignore this bp
     */
    bool SetBPIgnoreCount(double bid, const int ignorecount);

    /**
     * Enable or Disable this breakpoint
     */
    bool SetBPEnabledState(double bid, const bool enable);

    /**
     * Set this breakpoint's condition to that in bp.condition
     */
    bool SetBPConditon(const BreakpointInfo& bp);

    /**
     * Set this breakpoint's command-list to that in bp.commandlist
     */
    bool SetBPCommands(const BreakpointInfo& bp);

    /**
     * Clear the list of breakpoints
     */
    void Clear() { m_bps.clear(); }

    bool IsDuplicate(const BreakpointInfo& bp, const std::vector<BreakpointInfo>& bpList);

    void DoRemoveDuplicateBreakpoints();

public:
    void SetExpectingControl(bool expectingControl) { this->m_expectingControl = expectingControl; }
    bool GetExpectingControl() const { return m_expectingControl; }
    BreakptMgr()
    {
        NextInternalID = FIRST_INTERNAL_ID;
        m_expectingControl = false;
    }

    ~BreakptMgr() { Clear(); }

    /**
     * @brief refresh the breakpoints marker for a given editor
     * @param editor
     */
    void RefreshBreakpointsForEditor(LEditor* editor);

    /**
     * Refresh all line-type breakpoint markers in all editors
    */
    void RefreshBreakpointMarkers();

    /**
     * @brief add list of breakpoints to the stored breakpoints list
     * @param bps
     */
    void SetBreakpoints(const std::vector<BreakpointInfo>& bps);

    /**
     * @brief Store list of breakpoints in the pending-breakpoints list
     * @param bps
     */
    void SetPendingBreakpoints(const std::vector<BreakpointInfo>& bps)
    {
        m_pendingBreakpointsList.clear();
        m_pendingBreakpointsList = bps;
    }

    /**
     * @brief Returns true if there are pending breakpoints
     */
    bool PendingBreakpointsExist() { return !m_pendingBreakpointsList.empty(); }

    /**
     * Send again to the debugger any breakpoints that weren't accepted by the debugger the first time
     *  (e.g. because they're inside a plugin)
     */
    void ApplyPendingBreakpoints();

    /**
     * @brief delete all stored breakpoints related to file. this method should does not update the
     * debugger, so it must be called *before* starting the debugger
     * @param fileName
     */
    void DeleteAllBreakpointsByFileName(const wxString& fileName);

    /**
     * Add a breakpoint to the current debugger at the given line-number/file
     * Depending on the parameters, a temporary/ignored/conditional/commandlist bp can be created
     */
    bool AddBreakpointByLineno(const wxString& file,
                               const int lineno,
                               const wxString& conditions = wxT(""),
                               bool is_temp = false,
                               bool is_disabled = false);

    /**
     * Add a breakpoint using the 'Properties' dialog
     * Depending on the parameters, a temporary/ignored/conditional/commandlist bp can be created
     */
    void AddBreakpoint();

    /**
     * Add a break point to the current debugger
     * all breakpoints will be passed to the debugger
     * once started
     */
    bool AddBreakpoint(const BreakpointInfo& bp);

    /**
     * Delete break point by id
     */
    bool DelBreakpoint(double id);

    /**
     * Delete break point by file and line
     */
    bool DelBreakpointByLineno(const wxString& file, const int lineno);

    /**
     * @brief delete all breakpoints from a given memort address
     * @param address the memory address
     * @return number of breakpoints removed
     */
    int DelBreakpointByAddress(const wxString& address);

    /**
     * @brief add breakpoint by memory address.
     * @param address the memory address
     * @return true of success, false otherwise
     */
    bool AddBreakpointByAddress(const wxString& address);
    /**
     * @brief return list of allmemory breakpoints
     * @param memoryBps
     */
    void GetAllMemoryBreakpoints(BreakpointInfoVec_t& memoryBps);

    /**
     * Summon the BreakptProperties dialog for a bp
     */
    void EditBreakpointByLineno(const wxString& file, const int lineno);

    /**
     * Set a breakpoint's ignore count
     */
    bool IgnoreByLineno(const wxString& file, const int lineno);

    /**
     * return list of breakpoints
     */
    void GetBreakpoints(std::vector<BreakpointInfo>& li);

    /**
     * When a breakpoint is added, the debugger_id it returns finally arrives here
     * Update the breakpoint with it
     */
    void SetBreakpointDebuggerID(const int internal_id, const int debugger_id);

    /**
     * @brief return the breakpoint for a given file/line
     */
    BreakpointInfo& GetBreakpoint(const wxString& fileName, const int lineno);
    const BreakpointInfo& GetBreakpoint(const wxString& fileName, const int lineno) const;

    /**
     * Returns a string containing details of any breakpoints on this line
     */
    void GetTooltip(const wxString& fileName, int lineno, wxString& tip, wxString& title);

    /**
     * Update the m_bps with what the debugger really contains
     * from vector of breakpoints acquired from -break-list
     */
    void ReconcileBreakpoints(const std::vector<BreakpointInfo>& li);

    /**
     * Clears the debugger_ids of all breakpoints.
     * Called when the debugger has stopped, so they're  no longer valid
     */
    void DebuggerStopped();

    /**
     * Enable/Disable all breakpoints. Only used while the debugger is running
     */
    void SetAllBreakpointsEnabledState(bool enabled);

    /**
     * UpdateUI for SetAllBreakpointsEnabledState
     */
    bool AreThereEnabledBreakpoints(bool enabled = true);

    /**
     * UpdateUI for SetAllBreakpointsEnabledState, disabled version
     */
    bool AreThereDisabledBreakpoints() { return AreThereEnabledBreakpoints(false); }

    /**
     * remove all breakpoints
     */
    void DelAllBreakpoints();

    /**
     * The 'edit a breakpoint' dialog
     */
    void EditBreakpoint(int index, bool& bpExist);

    /**
     * If the debugger is running but can't interact, pause it.
     * Return true if a pause was done, to flag that a restart is needed
     */
    bool PauseDebuggerIfNeeded();

    /**
     * Notification from the debugger that breakpoint id was just hit
     */
    void BreakpointHit(double id);

    /**
     * Starts 'drag'n'drop' for breakpoints
     */
    void DragBreakpoint(LEditor* editor, int line, wxBitmap bitmap);

    /**
     * The 'drop' bit of breakpoints 'drag'n'drop'
     */
    void DropBreakpoint(const BreakpointInfo& bp, int newline);

    /**
     * Getter for the myDragImage pointer
     */
    myDragImage* GetDragImage() { return m_dragImage; }

    /**
     * Get a unique id for a breakpoint, to use when the debugger isn't running
     */
    int GetNextID() { return ++NextInternalID; }

    /**
     * Save session
     */
    void SaveSession(SessionEntry& session);

    /**
     * Load session
     */
    void LoadSession(const SessionEntry& session);
};

class myDragImage : public wxDragImage, public wxEvtHandler
{
    LEditor* editor;
    BreakpointInfo m_bp;
    int m_startx; // The initial x position
    wxCursor oldcursor;

public:
    myDragImage(LEditor* ed, const wxBitmap& bitmap, const BreakpointInfo& bp);
    bool StartDrag();
    void OnMotion(wxMouseEvent& event);
    void OnEndDrag(wxMouseEvent& event);
};
#endif // BREAKPOINTS_MANAGER_H