Code::Blocks  SVN r11506
debuggergdb.h
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 
6 #ifndef DEBUGGERGDB_H
7 #define DEBUGGERGDB_H
8 
9 #include <map>
10 
11 #include <settings.h> // much of the SDK is here
12 #include <sdk_events.h>
13 #include <cbplugin.h>
14 #include <loggers.h>
15 #include <pipedprocess.h>
16 #include <wx/regex.h>
17 
18 #include "remotedebugging.h"
19 #include "debuggerstate.h"
20 #include "debugger_defs.h"
21 
22 extern const wxString g_EscapeChar;
23 
24 class cbProject;
25 class TiXmlElement;
26 class DebuggerDriver;
27 class DebuggerCmd;
28 class Compiler;
29 struct TestIfBelogToProject;
31 
33 {
35  public:
36  DebuggerGDB();
37  ~DebuggerGDB();
38 
40  void OnAttachReal(); // fires when the plugin is attached to the application
41  void OnReleaseReal(bool appShutDown); // fires when the plugin is released from the application
42 
44 
46 
48 
49  void RunCommand(int cmd);
50 
51  cb::shared_ptr<cbBreakpoint> AddBreakpoint(const wxString& filename, int line);
52  cb::shared_ptr<cbBreakpoint> AddDataBreakpoint(const wxString& dataExpression);
53  int GetBreakpointsCount() const;
54  cb::shared_ptr<cbBreakpoint> GetBreakpoint(int index);
55  cb::shared_ptr<const cbBreakpoint> GetBreakpoint(int index) const;
56  void UpdateBreakpoint(cb::shared_ptr<cbBreakpoint> breakpoint);
57  void DeleteBreakpoint(cb::shared_ptr<cbBreakpoint> breakpoint);
58  void DeleteAllBreakpoints();
59  void ShiftBreakpoint(int index, int lines_to_shift);
60  void EnableBreakpoint(cb::shared_ptr<cbBreakpoint> breakpoint, bool enable);
61 
62  // stack frame calls;
63  int GetStackFrameCount() const;
64  cb::shared_ptr<const cbStackFrame> GetStackFrame(int index) const;
65  void SwitchToFrame(int number);
66  int GetActiveStackFrame() const;
67 
68  // threads
69  int GetThreadsCount() const;
70  cb::shared_ptr<const cbThread> GetThread(int index) const;
71  bool SwitchToThread(int thread_number);
72 
73  bool Debug(bool breakOnEntry);
74  void Continue();
75  void Next();
76  void NextInstruction();
77  void StepIntoInstruction();
78  void Step();
79  void StepOut();
80  bool RunToCursor(const wxString& filename, int line, const wxString& line_text);
81  void SetNextStatement(const wxString& filename, int line);
82  void Break();
83  void Stop();
84  bool Validate(const wxString& line, const char cb);
85  bool IsRunning() const { return m_pProcess; }
86  bool IsStopped() const;
87  bool IsBusy() const;
88  bool IsTemporaryBreak() const {return m_TemporaryBreak;}
89  int GetExitCode() const { return m_LastExitCode; }
90 
91  cb::shared_ptr<cbWatch> AddWatch(const wxString& symbol);
92  void DeleteWatch(cb::shared_ptr<cbWatch> watch);
93  bool HasWatch(cb::shared_ptr<cbWatch> watch);
94  void ShowWatchProperties(cb::shared_ptr<cbWatch> watch);
95  bool SetWatchValue(cb::shared_ptr<cbWatch> watch, const wxString &value);
96  void ExpandWatch(cb::shared_ptr<cbWatch> watch);
97  void CollapseWatch(cb::shared_ptr<cbWatch> watch);
98  void UpdateWatch(cb::shared_ptr<cbWatch> watch);
99 
100  void AddWatchNoUpdate(const cb::shared_ptr<GDBWatch> &watch);
101 
102  void OnWatchesContextMenu(wxMenu &menu, const cbWatch &watch, wxObject *property, int &disabledMenus);
103 
104  void GetCurrentPosition(wxString &filename, int &line);
105  void RequestUpdate(DebugWindows window);
106 
107  void AttachToProcess(const wxString& pid);
108  void DetachFromProcess();
109  bool IsAttachedToProcess() const;
110 
111  void SendCommand(const wxString& cmd, bool debugLog);
112  void DoSendCommand(const wxString& cmd);
113 
115 
116  void OnConfigurationChange(bool isActive);
117 
120 
121  void OnProjectLoadingHook(cbProject* project, TiXmlElement* elem, bool loading);
122 
123  void OnValueTooltip(const wxString &token, const wxRect &evalRect);
124  bool ShowValueTooltip(int style);
125 
126  static void ConvertToGDBFriendly(wxString& str);
127  static void ConvertToGDBFile(wxString& str);
128  static void ConvertToGDBDirectory(wxString& str, wxString base = _T(""), bool relative = true);
129  static void StripQuotes(wxString& str);
130 
131  void DebuggeeContinued();
132 
133  void DetermineLanguage();
134 
135  protected:
138  void ConvertDirectory(wxString& str, wxString base, bool relative);
139  void CleanupWhenProjectClosed(cbProject *project);
140  bool CompilerFinished(bool compilerFailed, StartType startType);
141  protected:
142  void AddSourceDir(const wxString& dir);
143  private:
144  void ParseOutput(const wxString& output);
145  void DoWatches();
147  int LaunchProcess(const wxString& cmd, const wxString& cwd);
148  int LaunchProcessWithShell(const wxString &cmd, wxProcess *process, const wxString &cwd);
149 
150  int DoDebug(bool breakOnEntry);
151  void DoBreak(bool temporary);
152 
153  void OnAddSymbolFile(wxCommandEvent& event);
154  void DeleteAllProjectBreakpoints(cbProject* project);
156  void OnGDBOutput(wxCommandEvent& event);
157  void OnGDBError(wxCommandEvent& event);
158  void OnGDBTerminated(wxCommandEvent& event);
159  void OnIdle(wxIdleEvent& event);
160  void OnTimer(wxTimerEvent& event);
161  void OnShowFile(wxCommandEvent& event);
162  void OnCursorChanged(wxCommandEvent& event);
163 
164  void SetupToolsMenu(wxMenu &menu);
165  void KillConsole();
166  void CheckIfConsoleIsClosed();
167 
168  void OnInfoFrame(wxCommandEvent& event);
169  void OnInfoDLL(wxCommandEvent& event);
170  void OnInfoFiles(wxCommandEvent& event);
171  void OnInfoFPU(wxCommandEvent& event);
172  void OnInfoSignals(wxCommandEvent& event);
173 
175 
176  void OnUpdateTools(wxUpdateUIEvent &event);
177  void OnPrintElements(wxCommandEvent &event);
178 
179  void OnUpdateCatchThrow(wxUpdateUIEvent &event);
180  void OnCatchThrow(wxCommandEvent &event);
181  private:
184  int m_Pid;
185  int m_PidToAttach; // for "attach to process"
189 
191 
192  // extra dialogs
193  cbProject* m_pProject; // keep the currently debugged project handy
195 
196  // per-project debugger search-dirs
197  typedef std::map<cbProject*, wxArrayString> SearchDirsMap;
198  SearchDirsMap m_SearchDirs;
199 
200  typedef std::map<cbProject*, RemoteDebuggingMap> ProjectRemoteDebuggingMap;
201  ProjectRemoteDebuggingMap m_RemoteDebugging;
202 
203  int m_HookId; // project loader hook ID
204 
205  // Linux console support
209 
210  bool m_Canceled; // flag to avoid re-entering DoDebug when we shouldn't
211 
213 
215  cb::shared_ptr<GDBWatch> m_localsWatch, m_funcArgsWatch;
218 
219  friend struct TestIfBelongToProject;
220 
222 
223  DECLARE_EVENT_TABLE()
224 };
225 
226 #endif // DEBUGGERGDB_H
227 
bool m_LastExitCode
Definition: debuggergdb.h:183
void OnWatchesContextMenu(wxMenu &menu, const cbWatch &watch, wxObject *property, int &disabledMenus)
void ConvertDirectory(wxString &str, wxString base, bool relative)
void AttachToProcess(const wxString &pid)
wxArrayString & GetSearchDirs(cbProject *prj)
bool SetWatchValue(cb::shared_ptr< cbWatch > watch, const wxString &value)
int GetStackFrameCount() const
SearchDirsMap m_SearchDirs
Definition: debuggergdb.h:198
cb::shared_ptr< const cbStackFrame > GetStackFrame(int index) const
cb::shared_ptr< cbBreakpoint > AddBreakpoint(const wxString &filename, int line)
Request to add a breakpoint.
bool Validate(const wxString &line, const char cb)
void DeleteBreakpoint(cb::shared_ptr< cbBreakpoint > breakpoint)
wxObject * m_watchToDereferenceProperty
Definition: debuggergdb.h:217
Base class for debugger plugins.
Definition: cbplugin.h:397
void DoBreak(bool temporary)
void DeleteAllProjectBreakpoints(cbProject *project)
void OnProjectLoadingHook(cbProject *project, TiXmlElement *elem, bool loading)
void OnTimer(wxTimerEvent &event)
void DeleteAllBreakpoints()
void DoWatches()
void OnInfoDLL(wxCommandEvent &event)
wxTimer m_TimerPollDebugger
Definition: debuggergdb.h:187
void MarkAllWatchesAsUnchanged()
bool IsStopped() const
Is the plugin stopped on breakpoint?
cb::shared_ptr< cbWatch > AddWatch(const wxString &symbol)
std::map< cbProject *, RemoteDebuggingMap > ProjectRemoteDebuggingMap
Definition: debuggergdb.h:200
std::vector< cb::shared_ptr< GDBWatch > > WatchesContainer
void Stop()
Stop the debugging process (exit debugging).
void CollapseWatch(cb::shared_ptr< cbWatch > watch)
cbProject * m_pProject
Definition: debuggergdb.h:193
wxString m_watchToDereferenceSymbol
Definition: debuggergdb.h:216
void RequestUpdate(DebugWindows window)
void DoSendCommand(const wxString &cmd)
void SwitchToFrame(int number)
static void ConvertToGDBFile(wxString &str)
void DetachFromProcess()
wxString m_ActiveBuildTarget
Definition: debuggergdb.h:194
static void StripQuotes(wxString &str)
void Next()
Execute the next instruction and return control to the debugger.
#define _T(string)
bool IsBusy() const
Is the plugin processing something?
void OnMenuWatchDereference(wxCommandEvent &event)
bool Debug(bool breakOnEntry)
Start a new debugging process.
void ExpandWatch(cb::shared_ptr< cbWatch > watch)
static void ConvertToGDBFriendly(wxString &str)
void OnCursorChanged(wxCommandEvent &event)
void KillConsole()
void OnReleaseReal(bool appShutDown)
A generic Code::Blocks event.
Definition: sdk_events.h:20
void ParseOutput(const wxString &output)
bool CompilerFinished(bool compilerFailed, StartType startType)
Called when the compilation has finished.
int GetThreadsCount() const
int GetActiveStackFrame() const
void CleanupWhenProjectClosed(cbProject *project)
static void ConvertToGDBDirectory(wxString &str, wxString base=_T(""), bool relative=true)
PipedProcess * m_pProcess
Definition: debuggergdb.h:182
void OnUpdateTools(wxUpdateUIEvent &event)
cb::shared_ptr< const cbThread > GetThread(int index) const
bool IsAttachedToProcess() const
bool m_bIsConsole
Definition: debuggergdb.h:206
void StepOut()
Execute the next instruction, stepping out of function calls if needed, and return control to the deb...
bool SupportsFeature(cbDebuggerFeature::Flags flag)
void GetCurrentPosition(wxString &filename, int &line)
int m_PidToAttach
Definition: debuggergdb.h:185
Represents a Code::Blocks project.
Definition: cbproject.h:96
void Continue()
Continue running the debugged program.
void DetermineLanguage()
void OnCatchThrow(wxCommandEvent &event)
int m_nConsolePid
Definition: debuggergdb.h:208
int GetBreakpointsCount() const
void SendCommand(const wxString &cmd, bool debugLog)
void DebuggeeContinued()
void DeleteWatch(cb::shared_ptr< cbWatch > watch)
void CheckIfConsoleIsClosed()
void OnConfigurationChange(bool isActive)
Called when the user clicks OK in Settings -> Debugger...
ProjectRemoteDebuggingMap m_RemoteDebugging
Definition: debuggergdb.h:201
void Break()
Break the debugging process (stop the debuggee for debugging).
void ShowWatchProperties(cb::shared_ptr< cbWatch > watch)
DebuggerState & GetState()
Definition: debuggergdb.h:114
void OnPrintElements(wxCommandEvent &event)
void UpdateWatch(cb::shared_ptr< cbWatch > watch)
int GetExitCode() const
Get the exit code of the last debug process.
Definition: debuggergdb.h:89
int LaunchProcess(const wxString &cmd, const wxString &cwd)
void UpdateBreakpoint(cb::shared_ptr< cbBreakpoint > breakpoint)
void OnInfoFPU(wxCommandEvent &event)
bool IsTemporaryBreak() const
Definition: debuggergdb.h:88
void OnAddSymbolFile(wxCommandEvent &event)
DebuggerConfiguration & GetActiveConfigEx()
void AddWatchNoUpdate(const cb::shared_ptr< GDBWatch > &watch)
wxRect m_EvalRect
Definition: debuggergdb.h:186
cbProject * GetProject()
Definition: debuggergdb.h:136
void OnShowFile(wxCommandEvent &event)
Base class for plugin configuration panels.
friend struct TestIfBelongToProject
Definition: debuggergdb.h:219
void OnAttachReal()
const wxString g_EscapeChar
Abstract base class for compilers.
Definition: compiler.h:274
void OnGDBError(wxCommandEvent &event)
void ShiftBreakpoint(int index, int lines_to_shift)
void OnInfoFiles(wxCommandEvent &event)
bool m_StoppedOnSignal
Definition: debuggergdb.h:190
bool m_stopDebuggerConsoleClosed
Definition: debuggergdb.h:207
bool HasWatch(cb::shared_ptr< cbWatch > watch)
void OnInfoFrame(wxCommandEvent &event)
void OnInfoSignals(wxCommandEvent &event)
int DoDebug(bool breakOnEntry)
bool m_Canceled
Definition: debuggergdb.h:210
RemoteDebuggingMap & GetRemoteDebuggingMap(cbProject *project=0)
bool ShowValueTooltip(int style)
cbDebuggerConfiguration * LoadConfig(const ConfigManagerWrapper &config)
void AddSourceDir(const wxString &dir)
void StepIntoInstruction()
Execute the next instruction and return control to the debugger, if the instruction is a function cal...
void OnGDBTerminated(wxCommandEvent &event)
int m_printElements
Definition: debuggergdb.h:221
int LaunchProcessWithShell(const wxString &cmd, wxProcess *process, const wxString &cwd)
cbConfigurationPanel * GetProjectConfigurationPanel(wxWindow *parent, cbProject *project)
cb::shared_ptr< cbBreakpoint > GetBreakpoint(int index)
void OnBuildTargetSelected(CodeBlocksEvent &event)
std::map< cbProject *, wxArrayString > SearchDirsMap
Definition: debuggergdb.h:197
void OnIdle(wxIdleEvent &event)
void SetupToolsMenu(wxMenu &menu)
bool RunToCursor(const wxString &filename, int line, const wxString &line_text)
Run the debugged program until it reaches the cursor at the current editor.
bool m_NoDebugInfo
Definition: debuggergdb.h:188
void EnableBreakpoint(cb::shared_ptr< cbBreakpoint > breakpoint, bool enable)
void SetNextStatement(const wxString &filename, int line)
Sets the position of the Program counter to the specified filename:line.
cb::shared_ptr< cbBreakpoint > AddDataBreakpoint(const wxString &dataExpression)
Request to add a breakpoint based on a data expression.
WatchesContainer m_watches
Definition: debuggergdb.h:214
void OnGDBOutput(wxCommandEvent &event)
cb::shared_ptr< GDBWatch > m_funcArgsWatch
Definition: debuggergdb.h:215
void OnValueTooltip(const wxString &token, const wxRect &evalRect)
std::map< ProjectBuildTarget *, RemoteDebugging > RemoteDebuggingMap
cb::shared_ptr< GDBWatch > m_localsWatch
Definition: debuggergdb.h:215
void NextInstruction()
Execute the next instruction and return control to the debugger.
Basic interface for debugger commands.
Definition: debugger_defs.h:49
#define NULL
Definition: prefix.cpp:59
void Step()
Execute the next instruction, stepping into function calls if needed, and return control to the debug...
bool m_TemporaryBreak
Definition: debuggergdb.h:212
Wrapper class for reading or writing config values, without the need for the full path...
void OnUpdateCatchThrow(wxUpdateUIEvent &event)
void ResetProject()
Definition: debuggergdb.h:137
bool IsRunning() const
Is the plugin currently debugging?
Definition: debuggergdb.h:85
DebuggerState m_State
Definition: debuggergdb.h:34
void RunCommand(int cmd)
bool SwitchToThread(int thread_number)