Code::Blocks  SVN r11506
debuggerdriver.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: 11404 $
6  * $Id: debuggerdriver.cpp 11404 2018-05-14 23:20:26Z fuscated $
7  * $HeadURL: https://svn.code.sf.net/p/codeblocks/code/trunk/src/plugins/debuggergdb/debuggerdriver.cpp $
8  */
9 
10 #include <sdk.h>
11 #include "debuggerdriver.h"
12 #include "debuggergdb.h"
13 
14 #include <cbdebugger_interfaces.h>
15 
17  : m_pDBG(plugin),
18  m_ProgramIsStopped(true),
19  m_ChildPID(0),
20  m_QueueBusy(false),
21  m_currentFrameNo(0),
22  m_userSelectedFrameNo(-1)
23 {
24  //ctor
25 }
26 
28 {
29  //dtor
30  for (size_t ii = 0; ii < m_DCmds.GetCount(); ++ii)
31  delete m_DCmds[ii];
32  m_DCmds.Clear();
33 }
34 
35 void DebuggerDriver::Log(const wxString& msg)
36 {
37  m_pDBG->Log(msg);
38 }
39 
41 {
42  m_pDBG->DebugLog(msg);
43 }
44 
46 {
47  m_Dirs.Clear();
48 }
49 
51 {
52  if (m_Dirs.Index(dir) == wxNOT_FOUND)
53  m_Dirs.Add(dir);
54 }
55 
57 {
58  m_WorkingDir = dir;
59 }
60 
62 {
63  if (m_WorkingDir.empty())
64  return wxEmptyString;
65  wxString oldDir = wxGetCwd();
67  wxString newDir = wxGetCwd();
68  wxSetWorkingDirectory(oldDir);
69  return newDir;
70 }
71 
73 {
74  m_Args = args;
75 }
76 
77 void DebuggerDriver::ShowFile(const wxString& file, int line)
78 {
80  event.SetString(file);
81  event.SetInt(line);
82  m_pDBG->ProcessEvent(event);
83 }
84 
86 {
88  return;
91  m_pDBG->ProcessEvent(event);
92 }
93 
95 {
97  ResetCursor();
98 }
99 
101 {
104  m_Cursor.file.Clear();
106  m_Cursor.line = -1;
107  m_Cursor.changed = false;
108 }
109 
111 {
112 // DebugLog(_T("Queueing command: ") + dcmd->m_Cmd);
113  if (prio == Low)
114  m_DCmds.Add(dcmd);
115  else
116  m_DCmds.Insert(dcmd, 0);
117  RunQueue();
118 }
119 
121 {
122  return m_DCmds.GetCount() ? m_DCmds[0] : 0;
123 }
124 
126 {
127  if (m_QueueBusy || !m_DCmds.GetCount() || !IsProgramStopped())
128  return;
129 
130  DebuggerCmd *command = CurrentCommand();
131 
132 // Log(_T("Running command: ") + CurrentCommand()->m_Cmd);
133  // don't send a command if empty; most debuggers repeat the last command this way...
134  if (!command->m_Cmd.IsEmpty())
135  {
136  m_QueueBusy = true;
137  m_pDBG->DoSendCommand(command->m_Cmd);
138  if (command->IsContinueCommand())
139  m_ProgramIsStopped = false;
140  }
141 
142  // Call Action()
143  command->Action();
144 
145  // If the command was an action (i.e. no command specified,
146  // remove it from the queue and run the next command.
147  // For other commands, this happens in driver's ParseOutput().
148  if (command->m_Cmd.IsEmpty())
149  {
150  RemoveTopCommand(true);
151  RunQueue();
152  }
153 }
154 
156 {
157  if (m_QueueBusy || !m_DCmds.GetCount())
158  return;
159 
160 // Log(_T("Removing command: ") + CurrentCommand()->m_Cmd);
161  if (deleteIt)
162  delete m_DCmds[0];
163  m_DCmds.RemoveAt(0);
164 }
165 
167 {
168  return m_backtrace;
169 }
170 
172 {
173  return m_backtrace;
174 }
175 
177 {
178  return m_threads;
179 }
180 
182 {
183  return m_threads;
184 }
185 
186 void DebuggerDriver::SetCurrentFrame(int number, bool user_selected)
187 {
188  m_currentFrameNo = number;
189  if (user_selected)
190  m_userSelectedFrameNo = number;
191 }
192 
194 {
195  m_currentFrameNo = 0;
197 
198  if (Manager::Get()->GetDebuggerManager()->UpdateBacktrace())
200 }
201 
virtual bool IsContinueCommand() const
Tells if the command is a continue type command (continue, step, next and run to cursor commands shou...
Definition: debugger_defs.h:75
void NotifyCursorChanged()
Called by implementations to notify cursor changes.
virtual ~DebuggerDriver()
void ShowFile(const wxString &file, int line)
Show a file/line without changing the cursor.
virtual void AddDirectory(const wxString &dir)
Add a directory in search list.
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
void RunQueue()
runs the next command in the queue, if it is idle
DebuggerGDB * m_pDBG
void DoSendCommand(const wxString &cmd)
int Index(const wxString &sz, bool bCase=true, bool bFromEnd=false) const
wxString m_Cmd
the actual command
Definition: debugger_defs.h:77
wxString GetDebuggersWorkingDirectory() const
bool IsProgramStopped() const
Is the program stopped?
virtual void SetArguments(const wxString &args)
Set the execution arguments.
StackFrameContainer m_backtrace
void Log(const wxString &msg, Logger::level level=Logger::info)
Definition: cbplugin.cpp:530
QueuePriority
The priority used when adding a command in the queue.
const ThreadsContainer & GetThreads() const
returns the thread container with the current list of threads
void RemoveTopCommand(bool deleteIt=true)
removes the top command (it has finished)
long int line
If -1, no line info.
Definition: debugger_defs.h:32
void Log(const wxString &msg)
std::vector< cb::shared_ptr< cbStackFrame > > StackFrameContainer
#define wxNOT_FOUND
bool empty() const
virtual void Reload()=0
const StackFrameContainer & GetStackFrames() const
returns the container with the current backtrace
virtual void SetWorkingDirectory(const wxString &dir)
Set the working directory.
bool changed
Definition: debugger_defs.h:33
DebuggerManager * GetDebuggerManager() const
Definition: manager.cpp:484
bool wxSetWorkingDirectory(const wxString &dir)
void DebugLog(const wxString &msg)
void DebuggeeContinued()
void ResetCursor()
Called by implementations to reset the cursor.
const int DEBUGGER_CURSOR_CHANGED
wxCommandEvent ID fired when the cursor has changed.
void NotifyDebuggeeContinued()
void QueueCommand(DebuggerCmd *dcmd, QueuePriority prio=Low)
add a command in the queue. The DebuggerCmd will be deleted automatically when finished.
wxArrayString m_Dirs
std::vector< cb::shared_ptr< cbThread > > ThreadsContainer
wxString wxEmptyString
virtual void ClearDirectories()
Clear directories search list.
ThreadsContainer m_threads
const int DEBUGGER_SHOW_FILE_LINE
wxCommandEvent ID fired to display a file/line (w/out changing the cursor)
wxString m_LastCursorAddress
wxString function
Definition: debugger_defs.h:31
void SetCurrentFrame(int number, bool user_selected)
bool IsEmpty() const
void Clear()
cbBacktraceDlg * GetBacktraceDialog()
size_t Add(const wxString &str, size_t copies=1)
DebuggerDriver(DebuggerGDB *plugin)
wxString file
Definition: debugger_defs.h:29
DebuggerCmd * CurrentCommand()
returns the currently executing command
wxString address
Definition: debugger_defs.h:30
DebuggerCommands m_DCmds
wxString m_WorkingDir
Basic interface for debugger commands.
Definition: debugger_defs.h:49
virtual void Action()
Executes an action.
Definition: debugger_defs.h:63
void DebugLog(const wxString &msg, Logger::level level=Logger::info)
Definition: cbplugin.cpp:540
wxString wxGetCwd()