Code::Blocks  SVN r11506
debugger_defs.cpp
Go to the documentation of this file.
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: 11490 $
6  * $Id: debugger_defs.cpp 11490 2018-10-03 14:27:48Z mortenmacfly $
7  * $HeadURL: https://svn.code.sf.net/p/codeblocks/code/trunk/src/plugins/debuggergdb/debugger_defs.cpp $
8  */
9 
10 #include "sdk.h"
11 #ifndef CB_PRECOMP
12 #include "scrollingdialog.h"
13 #include <wx/font.h>
14 #include <wx/sizer.h>
15 #include <wx/textctrl.h>
16 #include <wx/frame.h>
17 #include "manager.h"
18 #endif
19 #include <cbdebugger_interfaces.h>
20 #include "debugger_defs.h"
21 #include "debuggerdriver.h"
22 
23 #include <wx/arrimpl.cpp>
24 
25 #if !defined(CB_TEST_PROJECT)
26 
29 
30 DebuggerCmd::DebuggerCmd(DebuggerDriver* driver, const wxString& cmd, bool logToNormalLog)
31  : m_Cmd(cmd),
32  m_pDriver(driver),
33  m_LogToNormalLog(logToNormalLog)
34 {
35 }
36 
38 {
39  if (!output.IsEmpty() && m_LogToNormalLog)
40  m_pDriver->Log(output);
41 }
42 
44  : DebuggerCmd(driver)
45 {
46 }
47 
49 {
51 }
52 
53 // Custom window to display output of DebuggerInfoCmd
55 {
56  public:
57  DebuggerInfoWindow(wxWindow *parent, const wxString& title, const wxString& content)
60  {
61  wxSizer* sizer = new wxBoxSizer(wxVERTICAL);
63  m_pText = new wxTextCtrl(this, -1, content, wxDefaultPosition, wxDefaultSize,
65  m_pText->SetFont(font);
66 
67  sizer->Add(m_pText, 1, wxGROW);
68 
69  SetSizer(sizer);
70  sizer->Layout();
71  }
73 };
74 
76 {
77  DebuggerInfoWindow win(Manager::Get()->GetAppWindow(), m_Title.wx_str(), output);
78  win.ShowModal();
79 }
80 
81 #endif // !defined(CB_TEST_PROJECT)
82 
84 {
85  enabled = flag;
86 }
87 
89 {
90  switch (type)
91  {
92  case bptData:
93  return breakAddress;
94  case bptCode:
95  return filenameAsPassed;
96  case bptFunction:
97  return func;
98  default:
99  return _("Unknown");
100  }
101 }
102 
104 {
105  return line;
106 }
107 
109 {
110  return (type == bptCode) ? wxString::Format(wxT("%d"), line) : wxString(wxEmptyString);
111 }
112 
114 {
115  switch (type)
116  {
117  case bptData:
118  return _("Data");
119  case bptCode:
120  return _("Code");
121  case bptFunction:
122  return _("Function");
123  default:
124  return _("Unknown");
125  }
126 }
127 
129 {
130  switch (type)
131  {
132  case bptData:
133  if (breakOnRead && breakOnWrite)
134  return _("type: read-write");
135  else if (breakOnRead)
136  return _("type: read");
137  else if (breakOnWrite)
138  return _("type: write");
139  else
140  return _("type: unknown");
141  case bptCode:
142  {
143  wxString s;
144  if (useCondition)
145  s += _("condition: ") + condition;
146  if (useIgnoreCount)
147  {
148  if (!s.empty())
149  s += wxT(" ");
150  s += wxString::Format(_("ignore count: %d"), ignoreCount);
151  }
152  if (temporary)
153  {
154  if (!s.empty())
155  s += wxT(" ");
156  s += _("temporary");
157  }
158  s += wxString::Format(wxT(" (index: %ld)"), index);
159  return s;
160  }
161  case bptFunction:
162  default:
163  return wxEmptyString;
164  }
165 }
166 
168 {
169  return enabled;
170 }
171 
173 {
174  return type == bptCode;
175 }
176 
178 {
179  return temporary;
180 }
181 
182 
183 GDBWatch::GDBWatch(wxString const &symbol) :
184  m_symbol(symbol),
185  m_format(Undefined),
186  m_array_start(0),
187  m_array_count(0),
188  m_is_array(false),
189  m_forTooltip(false)
190 {
191 }
193 {
194 }
195 void GDBWatch::GetSymbol(wxString &symbol) const
196 {
197  symbol = m_symbol;
198 }
199 void GDBWatch::GetValue(wxString &value) const
200 {
201  value = m_raw_value;
202 }
203 bool GDBWatch::SetValue(const wxString &value)
204 {
205  if(m_raw_value != value)
206  {
207  MarkAsChanged(true);
208  m_raw_value = value;
209  }
210  return true;
211 }
212 void GDBWatch::GetFullWatchString(wxString &full_watch) const
213 {
214  cb::shared_ptr<const cbWatch> parent = GetParent();
215  if (parent)
216  {
217  parent->GetFullWatchString(full_watch);
218  full_watch += wxT(".") + m_symbol;
219  }
220  else
221  full_watch = m_symbol;
222 }
223 
224 void GDBWatch::GetType(wxString &type) const
225 {
226  type = m_type;
227 }
228 void GDBWatch::SetType(const wxString &type)
229 {
230  m_type = type;
231 }
232 
234 {
235  return m_debug_value;
236 }
237 
239 {
240  return wxT("&") + m_symbol;
241 }
242 
244 {
246 }
247 
249 {
250  m_debug_value = value;
251 }
252 
253 void GDBWatch::SetSymbol(const wxString& symbol)
254 {
255  m_symbol = symbol;
256 }
257 
259 {
260  delete this;
261 }
262 
264 {
265  m_format = format;
266 }
267 
269 {
270  return m_format;
271 }
272 
273 void GDBWatch::SetArray(bool flag)
274 {
275  m_is_array = flag;
276 }
277 
278 bool GDBWatch::IsArray() const
279 {
280  return m_is_array;
281 }
282 
283 void GDBWatch::SetArrayParams(int start, int count)
284 {
285  m_array_start = start;
286  m_array_count = count;
287 }
288 
290 {
291  return m_array_start;
292 }
293 
295 {
296  return m_array_count;
297 }
298 
299 void GDBWatch::SetForTooltip(bool flag)
300 {
301  m_forTooltip = flag;
302 }
303 
305 {
306  return m_forTooltip;
307 }
308 
310 {
311  type.Trim(true);
312  type.Trim(false);
313 
314  if (type.Contains(wxT("char *")) || type.Contains(wxT("char const *")))
315  return false;
316  else if (type.EndsWith(wxT("*")))
317  return true;
318  else if (type.EndsWith(wxT("* const")))
319  return true;
320  else if (type.EndsWith(wxT("* volatile")))
321  return true;
322  return false;
323 }
324 
325 // Use this function to sanitize user input which might end as the last part of GDB commands.
326 // If the last character is '\', GDB will treat it as line continuation and it will stall.
328 {
329  while (value.EndsWith(wxT("\\")))
330  value.RemoveLast();
331  return value;
332 }
333 
335 
C++ or C language.
void SetSymbol(const wxString &symbol)
#define wxMAXIMIZE_BOX
Format is undefined (whatever the debugger uses by default).
DebuggerLanguage g_DebugLanguage
int m_array_start
int wxNewId()
void SetFormat(WatchFormat format)
virtual void GetSymbol(wxString &symbol) const
wxString m_raw_value
#define wxTE_READONLY
static Manager * Get()
Use Manager::Get() to get a pointer to its instance Manager::Get() is guaranteed to never return an i...
Definition: manager.cpp:182
virtual void GetType(wxString &type) const
virtual int GetLine() const
WatchFormat
Watch variable format.
#define wxTE_MULTILINE
wxString m_symbol
virtual bool IsEnabled() const
bool m_is_array
WatchFormat GetFormat() const
virtual void Action()
Executes an action.
#define wxTE_RICH2
bool IsArray() const
#define wxHSCROLL
void Log(const wxString &msg)
GDBWatch(wxString const &symbol)
virtual bool IsTemporary() const
#define wxT(string)
bool IsPointerType(wxString type)
virtual wxString GetInfo() const
bool empty() const
virtual wxString GetType() const
virtual void UpdateWatches()=0
DbgCmd_UpdateWatchesTree(DebuggerDriver *driver)
bool Contains(const wxString &str) const
DebuggerManager * GetDebuggerManager() const
Definition: manager.cpp:484
virtual void SetType(const wxString &type)
wxString & RemoveLast(size_t n=1)
bool m_LogToNormalLog
if true, log to normal log, else the debug log
Definition: debugger_defs.h:80
DebuggerCmd(DebuggerDriver *driver, const wxString &cmd=_T(""), bool logToNormalLog=false)
bool GetForTooltip() const
WatchFormat m_format
const wxSize wxDefaultSize
const int DEBUGGER_CURSOR_CHANGED
wxCommandEvent ID fired when the cursor has changed.
const wxPoint wxDefaultPosition
bool IsPointerType() const override
Tells us if the watch is for pointer variable.
cbWatchesDlg * GetWatchesDialog()
Returns a pointer to the watches dialog.
int GetArrayCount() const
virtual ~GDBWatch()
virtual wxString GetLocation() const
virtual void DoDestroy()
#define wxDEFAULT_DIALOG_STYLE
virtual int ShowModal()
int GetArrayStart() const
wxString wxEmptyString
void MarkAsChanged(bool flag)
wxString m_debug_value
const int DEBUGGER_SHOW_FILE_LINE
wxCommandEvent ID fired to display a file/line (w/out changing the cursor)
void SetForTooltip(bool flag=true)
const wxString & _(const wxString &string)
wxString & Trim(bool fromRight=true)
bool IsEmpty() const
virtual void GetValue(wxString &value) const
bool m_forTooltip
void SetDebugValue(wxString const &value)
virtual void ParseOutput(const wxString &output)
Parses the command&#39;s output.
wxString CleanStringValue(wxString value)
virtual wxString GetLineString() const
bool EndsWith(const wxString &suffix, wxString *rest=NULL) const
virtual void ParseOutput(const wxString &output)
Parses the command&#39;s output.
DebuggerDriver * m_pDriver
the driver
Definition: debugger_defs.h:79
virtual wxString const & GetDebugString() const
virtual void SetEnabled(bool flag)
wxString m_type
int m_array_count
void SetArrayParams(int start, int count)
#define wxMINIMIZE_BOX
DebuggerLanguage
void SetArray(bool flag)
wxTextCtrl * m_pText
virtual bool SetValue(const wxString &value)
#define wxRESIZE_BORDER
Basic interface for debugger commands.
Definition: debugger_defs.h:49
static wxString Format(const wxString &format,...)
cb::shared_ptr< const cbWatch > GetParent() const
virtual void GetFullWatchString(wxString &full_watch) const
virtual bool IsVisibleInEditor() const
wxString MakeSymbolToAddress() const override
This should return a string that when passed to the debugger will return the address of the variable...
DebuggerInfoWindow(wxWindow *parent, const wxString &title, const wxString &content)