~ubuntu-branches/ubuntu/hardy/codeblocks/hardy-backports

« back to all changes in this revision

Viewing changes to src/plugins/debuggergdb/debuggerdriver.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Casadevall
  • Date: 2008-07-17 04:39:23 UTC
  • Revision ID: james.westby@ubuntu.com-20080717043923-gmsy5cwkdjswghkm
Tags: upstream-8.02
ImportĀ upstreamĀ versionĀ 8.02

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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: 4909 $
 
6
 * $Id: debuggerdriver.cpp 4909 2008-02-27 13:15:26Z mortenmacfly $
 
7
 * $HeadURL: svn://svn.berlios.de/codeblocks/tags/8.02/src/plugins/debuggergdb/debuggerdriver.cpp $
 
8
 */
 
9
 
 
10
#include <sdk.h>
 
11
#include "debuggerdriver.h"
 
12
#include "debuggergdb.h"
 
13
 
 
14
DebuggerDriver::DebuggerDriver(DebuggerGDB* plugin)
 
15
    : m_pDBG(plugin),
 
16
    m_ProgramIsStopped(true),
 
17
    m_ChildPID(0),
 
18
    m_pBacktrace(0),
 
19
    m_pDisassembly(0),
 
20
    m_pExamineMemory(0),
 
21
    m_QueueBusy(false)
 
22
{
 
23
    //ctor
 
24
}
 
25
 
 
26
DebuggerDriver::~DebuggerDriver()
 
27
{
 
28
    //dtor
 
29
    ClearQueue();
 
30
}
 
31
 
 
32
void DebuggerDriver::Log(const wxString& msg)
 
33
{
 
34
    m_pDBG->Log(msg);
 
35
}
 
36
 
 
37
void DebuggerDriver::DebugLog(const wxString& msg)
 
38
{
 
39
    m_pDBG->DebugLog(msg);
 
40
}
 
41
 
 
42
void DebuggerDriver::SetDebugWindows(BacktraceDlg* b,
 
43
                                    DisassemblyDlg* d,
 
44
                                    CPURegistersDlg* r,
 
45
                                    ExamineMemoryDlg* m,
 
46
                                    ThreadsDlg* t)
 
47
{
 
48
    m_pBacktrace = b;
 
49
    m_pDisassembly = d;
 
50
    m_pCPURegisters = r;
 
51
    m_pExamineMemory = m;
 
52
    m_pThreads = t;
 
53
}
 
54
 
 
55
void DebuggerDriver::ClearDirectories()
 
56
{
 
57
    m_Dirs.Clear();
 
58
}
 
59
 
 
60
void DebuggerDriver::AddDirectory(const wxString& dir)
 
61
{
 
62
    if (m_Dirs.Index(dir) == wxNOT_FOUND)
 
63
        m_Dirs.Add(dir);
 
64
}
 
65
 
 
66
void DebuggerDriver::SetWorkingDirectory(const wxString& dir)
 
67
{
 
68
    m_WorkingDir = dir;
 
69
}
 
70
 
 
71
void DebuggerDriver::SetArguments(const wxString& args)
 
72
{
 
73
    m_Args = args;
 
74
}
 
75
 
 
76
void DebuggerDriver::NotifyCursorChanged()
 
77
{
 
78
    if (!m_Cursor.changed || m_LastCursorAddress == m_Cursor.address)
 
79
        return;
 
80
    m_LastCursorAddress = m_Cursor.address;
 
81
    wxCommandEvent event(DEBUGGER_CURSOR_CHANGED);
 
82
    m_pDBG->ProcessEvent(event);
 
83
}
 
84
 
 
85
void DebuggerDriver::ResetCursor()
 
86
{
 
87
    m_LastCursorAddress.Clear();
 
88
    m_Cursor.address.Clear();
 
89
    m_Cursor.file.Clear();
 
90
    m_Cursor.function.Clear();
 
91
    m_Cursor.line = -1;
 
92
    m_Cursor.changed = false;
 
93
}
 
94
 
 
95
void DebuggerDriver::QueueCommand(DebuggerCmd* dcmd, QueuePriority prio)
 
96
{
 
97
//    DebugLog(_T("Queueing command: ") + dcmd->m_Cmd);
 
98
    if (prio == Low)
 
99
        m_DCmds.Add(dcmd);
 
100
    else
 
101
        m_DCmds.Insert(dcmd, 0);
 
102
    RunQueue();
 
103
}
 
104
 
 
105
DebuggerCmd* DebuggerDriver::CurrentCommand()
 
106
{
 
107
    return m_DCmds.GetCount() ? m_DCmds[0] : 0;
 
108
}
 
109
 
 
110
void DebuggerDriver::RunQueue()
 
111
{
 
112
    if (m_QueueBusy || !m_DCmds.GetCount())
 
113
        return;
 
114
 
 
115
//    Log(_T("Running command: ") + CurrentCommand()->m_Cmd);
 
116
    // don't send a command if empty; most debuggers repeat the last command this way...
 
117
    if (!CurrentCommand()->m_Cmd.IsEmpty())
 
118
    {
 
119
        m_QueueBusy = true;
 
120
        m_pDBG->SendCommand(CurrentCommand()->m_Cmd);
 
121
        m_ProgramIsStopped = false;
 
122
    }
 
123
 
 
124
    // Call Action()
 
125
    CurrentCommand()->Action();
 
126
 
 
127
    // If the command was an action (i.e. no command specified,
 
128
    // remove it from the queue and run the next command.
 
129
    // For other commands, this happens in driver's ParseOutput().
 
130
    if (CurrentCommand()->m_Cmd.IsEmpty())
 
131
    {
 
132
        RemoveTopCommand(true);
 
133
        RunQueue();
 
134
    }
 
135
}
 
136
 
 
137
void DebuggerDriver::RemoveTopCommand(bool deleteIt)
 
138
{
 
139
    if (m_QueueBusy || !m_DCmds.GetCount())
 
140
        return;
 
141
 
 
142
//    Log(_T("Removing command: ") + CurrentCommand()->m_Cmd);
 
143
    if (deleteIt)
 
144
        delete m_DCmds[0];
 
145
    m_DCmds.RemoveAt(0);
 
146
}
 
147
 
 
148
void DebuggerDriver::ClearQueue()
 
149
{
 
150
    int idx = 0;
 
151
    // if the first command in the queue is running, delete all others
 
152
    // (this will be deleted when done)
 
153
    if (m_QueueBusy && !m_DCmds.GetCount())
 
154
        idx = 1;
 
155
    for (int i = idx; i < (int)m_DCmds.GetCount(); ++i)
 
156
    {
 
157
        delete m_DCmds[i];
 
158
        m_DCmds.RemoveAt(i);
 
159
    }
 
160
}