Code::Blocks  SVN r11506
debuggeroptionsdlg.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: 11165 $
6  * $Id: debuggeroptionsdlg.cpp 11165 2017-09-09 14:40:32Z fuscated $
7  * $HeadURL: https://svn.code.sf.net/p/codeblocks/code/trunk/src/plugins/debuggergdb/debuggeroptionsdlg.cpp $
8  */
9 
10 #include <sdk.h>
11 #include "debuggeroptionsdlg.h"
12 #ifndef CB_PRECOMP
13  #include <wx/checkbox.h>
14  #include <wx/choice.h>
15  #include <wx/filedlg.h>
16  #include <wx/intl.h>
17  #include <wx/radiobox.h>
18  #include <wx/spinctrl.h>
19  #include <wx/textctrl.h>
20  #include <wx/xrc/xmlres.h>
21 
22  #include <configmanager.h>
23  #include <macrosmanager.h>
24 #endif
25 
26 #include "debuggergdb.h"
27 
29 {
30  public:
32  {
33  wxTextCtrl *pathCtrl = XRCCTRL(*this, "txtExecutablePath", wxTextCtrl);
34  wxString path = pathCtrl->GetValue();
36  if (!wxFileExists(path))
37  {
38  pathCtrl->SetForegroundColour(*wxWHITE);
39  pathCtrl->SetBackgroundColour(*wxRED);
40  pathCtrl->SetToolTip(_("Full path to the debugger's executable. Executable can't be found on the filesystem!"));
41  }
42  else
43  {
44  pathCtrl->SetForegroundColour(wxNullColour);
45  pathCtrl->SetBackgroundColour(wxNullColour);
46  pathCtrl->SetToolTip(_("Full path to the debugger's executable."));
47  }
48  pathCtrl->Refresh();
49  }
50  private:
51  void OnBrowse(cb_unused wxCommandEvent &event)
52  {
53  wxString oldPath = XRCCTRL(*this, "txtExecutablePath", wxTextCtrl)->GetValue();
55  wxFileDialog dlg(this, _("Select executable file"), wxEmptyString, oldPath,
57  PlaceWindow(&dlg);
58  if (dlg.ShowModal() == wxID_OK)
59  {
60  wxString newPath = dlg.GetPath();
61  XRCCTRL(*this, "txtExecutablePath", wxTextCtrl)->ChangeValue(newPath);
62  }
63  }
64 
65  void OnTextChange(cb_unused wxCommandEvent &event)
66  {
68  }
69  private:
70  DECLARE_EVENT_TABLE()
71 };
72 
73 BEGIN_EVENT_TABLE(DebuggerConfigurationPanel, wxPanel)
74  EVT_BUTTON(XRCID("btnBrowse"), DebuggerConfigurationPanel::OnBrowse)
75  EVT_TEXT(XRCID("txtExecutablePath"), DebuggerConfigurationPanel::OnTextChange)
76 END_EVENT_TABLE()
77 
79 {
80 }
81 
83 {
84  return new DebuggerConfiguration(*this);
85 }
86 
88 {
90  if (!wxXmlResource::Get()->LoadPanel(panel, parent, wxT("dlgDebuggerOptions")))
91  return panel;
92 
93  XRCCTRL(*panel, "txtExecutablePath", wxTextCtrl)->ChangeValue(GetDebuggerExecutable(false));
94  panel->ValidateExecutablePath();
95  XRCCTRL(*panel, "chkDisableInit", wxCheckBox)->SetValue(GetFlag(DisableInit));
96  XRCCTRL(*panel, "txtArguments", wxTextCtrl)->ChangeValue(GetUserArguments(false));
97 
98  XRCCTRL(*panel, "rbType", wxRadioBox)->SetSelection(IsGDB() ? 0 : 1);
99  XRCCTRL(*panel, "txtInit", wxTextCtrl)->ChangeValue(GetInitCommands());
100  XRCCTRL(*panel, "txtInit", wxTextCtrl)->SetMinSize(wxSize(-1, 75));;
101  XRCCTRL(*panel, "chkWatchArgs", wxCheckBox)->SetValue(GetFlag(WatchFuncArgs));
102  XRCCTRL(*panel, "chkWatchLocals", wxCheckBox)->SetValue(GetFlag(WatchLocals));
103  XRCCTRL(*panel, "chkCatchExceptions",wxCheckBox)->SetValue(GetFlag(CatchExceptions));
104  XRCCTRL(*panel, "chkTooltipEval", wxCheckBox)->SetValue(GetFlag(EvalExpression));
105  XRCCTRL(*panel, "chkAddForeignDirs", wxCheckBox)->SetValue(GetFlag(AddOtherProjectDirs));
106  XRCCTRL(*panel, "chkDoNotRun", wxCheckBox)->SetValue(GetFlag(DoNotRun));
107  XRCCTRL(*panel, "choDisassemblyFlavor", wxChoice)->SetSelection(m_config.ReadInt(wxT("disassembly_flavor"), 0));
108  XRCCTRL(*panel, "txtInstructionSet", wxTextCtrl)->ChangeValue(m_config.Read(wxT("instruction_set"), wxEmptyString));
109  return panel;
110 }
111 
113 {
114  m_config.Write(wxT("executable_path"), XRCCTRL(*panel, "txtExecutablePath", wxTextCtrl)->GetValue());
115  m_config.Write(wxT("disable_init"), XRCCTRL(*panel, "chkDisableInit", wxCheckBox)->GetValue());
116  m_config.Write(wxT("user_arguments"), XRCCTRL(*panel, "txtArguments", wxTextCtrl)->GetValue());
117  m_config.Write(wxT("type"), XRCCTRL(*panel, "rbType", wxRadioBox)->GetSelection());
118  m_config.Write(wxT("init_commands"), XRCCTRL(*panel, "txtInit", wxTextCtrl)->GetValue());
119  m_config.Write(wxT("watch_args"), XRCCTRL(*panel, "chkWatchArgs", wxCheckBox)->GetValue());
120  m_config.Write(wxT("watch_locals"), XRCCTRL(*panel, "chkWatchLocals", wxCheckBox)->GetValue());
121  m_config.Write(wxT("catch_exceptions"), XRCCTRL(*panel, "chkCatchExceptions",wxCheckBox)->GetValue());
122  m_config.Write(wxT("eval_tooltip"), XRCCTRL(*panel, "chkTooltipEval", wxCheckBox)->GetValue());
123  m_config.Write(wxT("add_other_search_dirs"), XRCCTRL(*panel, "chkAddForeignDirs", wxCheckBox)->GetValue());
124  m_config.Write(wxT("do_not_run"), XRCCTRL(*panel, "chkDoNotRun", wxCheckBox)->GetValue());
125  m_config.Write(wxT("disassembly_flavor"), XRCCTRL(*panel, "choDisassemblyFlavor", wxChoice)->GetSelection());
126  m_config.Write(wxT("instruction_set"), XRCCTRL(*panel, "txtInstructionSet", wxTextCtrl)->GetValue());
127 
128  return true;
129 }
130 
132 {
133  switch (flag)
134  {
135  case DisableInit:
136  return m_config.ReadBool(wxT("disable_init"), true);
137  case WatchFuncArgs:
138  return m_config.ReadBool(wxT("watch_args"), true);
139  case WatchLocals:
140  return m_config.ReadBool(wxT("watch_locals"), true);
141  case CatchExceptions:
142  return m_config.ReadBool(wxT("catch_exceptions"), true);
143  case EvalExpression:
144  return m_config.ReadBool(wxT("eval_tooltip"), false);
145  case AddOtherProjectDirs:
146  return m_config.ReadBool(wxT("add_other_search_dirs"), false);
147  case DoNotRun:
148  return m_config.ReadBool(wxT("do_not_run"), false);
149  default:
150  return false;
151  }
152 }
153 void DebuggerConfiguration::SetFlag(Flags flag, bool value)
154 {
155  switch (flag)
156  {
157  case DisableInit:
158  m_config.Write(wxT("disable_init"), value);
159  break;
160  case WatchFuncArgs:
161  m_config.Write(wxT("watch_args"), value);
162  break;
163  case WatchLocals:
164  m_config.Write(wxT("watch_locals"), value);
165  break;
166  case CatchExceptions:
167  m_config.Write(wxT("catch_exceptions"), value);
168  break;
169  case EvalExpression:
170  m_config.Write(wxT("eval_tooltip"), value);
171  break;
172  case AddOtherProjectDirs:
173  m_config.Write(wxT("add_other_search_dirs"), value);
174  break;
175  case DoNotRun:
176  m_config.Write(wxT("do_not_run"), value);
177  break;
178  default:
179  ;
180  }
181 }
182 
184 {
185  return m_config.ReadInt(wxT("type"), 0) == 0;
186 }
187 
189 {
190  wxString result = m_config.Read(wxT("executable_path"), wxEmptyString);
191  if (expandMacro)
193  return !result.empty() ? result : cbDetectDebuggerExecutable(wxT("gdb"));
194 }
195 
197 {
198  wxString result = m_config.Read(wxT("user_arguments"), wxEmptyString);
199  if (expandMacro)
201  return result;
202 }
203 
205 {
206  int disassembly_flavour = m_config.ReadInt(wxT("disassembly_flavor"), 0);
207 
208  wxString flavour = wxT("set disassembly-flavor ");
209  switch (disassembly_flavour)
210  {
211  case 1: // AT & T
212  {
213  flavour << wxT("att");
214  break;
215  }
216  case 2: // Intel
217  {
218  flavour << wxT("intel");
219  break;
220  }
221  case 3: // Custom
222  {
223  wxString instruction_set = m_config.Read(wxT("instruction_set"), wxEmptyString);
224  flavour << instruction_set;
225  break;
226  }
227  default: // including case 0: // System default
228 
229  if(platform::windows)
230  flavour << wxT("att");
231  else
232  flavour << wxT("intel");
233  }// switch
234  return flavour;
235 }
236 
238 {
239  return m_config.Read(wxT("init_commands"), wxEmptyString);
240 }
virtual bool SaveChanges(wxPanel *panel)
virtual int ShowModal()
wxString GetUserArguments(bool expandMacro=true)
void SetFlag(Flags flag, bool value)
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
bool wxFileExists(const wxString &filename)
wxString GetDebuggerExecutable(bool expandMacro=true)
wxColour wxNullColour
void OnTextChange(cb_unused wxCommandEvent &event)
#define wxT(string)
bool empty() const
wxColour * wxRED
wxColour * wxWHITE
wxString wxEmptyString
virtual wxString GetPath() const
MacrosManager * GetMacrosManager() const
Definition: manager.cpp:454
virtual wxPanel * MakePanel(wxWindow *parent)
const wxString & _(const wxString &string)
virtual cbDebuggerConfiguration * Clone() const
DLLIMPORT void PlaceWindow(wxTopLevelWindow *w, cbPlaceDialogMode mode=pdlBest, bool enforce=false)
Definition: globals.cpp:1177
void ReplaceEnvVars(wxString &buffer)
Definition: macrosmanager.h:32
DLLIMPORT wxString cbDetectDebuggerExecutable(const wxString &exeName)
Tries to detect the path to the debugger&#39;s executable.
static wxXmlResource * Get()
const char wxFileSelectorDefaultWildcardStr[]
void OnBrowse(cb_unused wxCommandEvent &event)
Wrapper class for reading or writing config values, without the need for the full path...