Debian Codegraph @

debugger.h

raw symbols SCIP
1 /****************************************************************************
2 ** SASM - simple IDE for assembler development
3 ** Copyright (C) 2013 Dmitriy Manushin
4 ** Contact: site: http://dman95.github.io/SASM/
5 ** e-mail: [email protected]
6 **
7 ** This file is part of SASM.
8 **
9 ** SASM is free software: you can redistribute it and/or modify
10 ** it under the terms of the GNU General Public License as published by
11 ** the Free Software Foundation, either version 3 of the License, or
12 ** (at your option) any later version.
13 **
14 ** SASM is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ** GNU General Public License for more details.
18 **
19 ** You should have received a copy of the GNU General Public License
20 ** along with SASM. If not, see <http://www.gnu.org/licenses/>.
21 **
22 ** Этот файл — часть SASM.
23 **
24 ** SASM - свободная программа: вы можете перераспространять ее и/или
25 ** изменять ее на условиях Стандартной общественной лицензии GNU в том виде,
26 ** в каком она была опубликована Фондом свободного программного обеспечения;
27 ** либо версии 3 лицензии, либо (по вашему выбору) любой более поздней
28 ** версии.
29 **
30 ** SASM распространяется в надежде, что она будет полезной,
31 ** но БЕЗО ВСЯКИХ ГАРАНТИЙ; даже без неявной гарантии ТОВАРНОГО ВИДА
32 ** или ПРИГОДНОСТИ ДЛЯ ОПРЕДЕЛЕННЫХ ЦЕЛЕЙ. Подробнее см. в Стандартной
33 ** общественной лицензии GNU.
34 **
35 ** Вы должны были получить копию Стандартной общественной лицензии GNU
36 ** вместе с этой программой. Если это не так, см.
37 ** <http://www.gnu.org/licenses/>.)
38 **
39 ****************************************************************************/
40
41 #ifndef DEBUGGER_H
42 #define DEBUGGER_H
43
44 #include <QProcess>
45 #include <QProcessEnvironment>
46 #include <QString>
47 #include <QTextStream>
48 #include <QTextEdit>
49 #include <QFile>
50 #include <QVector>
51 #include <QCoreApplication>
52 #include <QTimer>
53 #include <QQueue>
54 #include <QSettings>
55 #include <QFile>
56 #include "assembler.h"
57
58 #ifdef Q_OS_WIN32
59 #include <Windows.h>
60 #include <stddef.h>
61 #include <stdlib.h>
62 #else
63 #include <signal.h>
64 #endif
65
66 /**
67 * @file debugger.h
68 * Defines the debugger.
69 */
70
71 enum DebugActionType {ni, si, showLine, infoRegisters, infoMemory, anyAction, none, breakpoint};
72
73
74 /**
75 * ! \brief This class represents the debugger.
76 *
77 *
78 * */
79 class Debugger : public QObject
80 {
81 Q_OBJECT
82
83 public:
84 Debugger(QTextEdit *tEdit,
85 const QString &exePathParam,
86 const QString &workingDirectoryPathParam,
87 const QString &inputPathParam,
88 Assembler *assembler,
89 QWidget *parent = 0);
90 ~Debugger();
91 void setWatchesCount(int count);
92
93 struct registersInfo {
94 QString name;
95 QString hexValue;
96 QString decValue;
97 };
98
99 struct memoryInfo {
100 QString value;
101 bool isValid;
102 };
103
104 typedef Assembler::LineNum LineNum;
105
106 bool isStopped();
107 void pause();
108
109 private:
110 void processLst();
111 void run();
112
113 QProcess *process;
114 QTextEdit *textEdit;
115
116 //! Offset between program code in memory and in file
117 quint64 offset;
118
119 //! Accordance between program lines in memory and in file
120 QVector<LineNum> lines;
121 //! Counter for sequential performing of actions
122 int c;
123
124 bool registersOk;
125
126 //! Flag for checking if gdb run
127 bool gdbRun;
128
129 //! Queue of actions type from enum
130 QQueue<DebugActionType> actionTypeQueue;
131
132 //! Queue of commands
133 QQueue<QString> commandQueue;
134
135 //! Message on exit in current platform
136 QString exitMessage;
137
138 //! Message on exit which shows when "continue" command used
139 QRegExp cExitMessage;
140
141 //! Path to executable
142 QString exePath;
143
144 //! Path to working directory
145 QString workingDirectoryPath;
146
147 //! Path to temporary input.txt file
148 QString inputPath;
149
150 //! Global gdb output buffer
151 QString buffer;
152
153 //! Global gdb all output buffer
154 QString allBuffer;
155
156 //! Global gdb error buffer
157 QString errorBuffer;
158
159 //! Global gdb all error buffer
160 QString allErrorBuffer;
161
162 //! Timer for checking output and sending ready output to processing with Debugger::processOutput() function
163 QTimer *bufferTimer;
164
165 //! Timer for run checking
166 QTimer *checkGdbRunTimer;
167
168 //! The number of variable watches
169 int watchesCount;
170
171 //! List of the variable watches
172 QList<Debugger::memoryInfo> watches;
173
174 //! Flag for checking if Debugger::processAction call is first time in current debug session
175 bool firstAction;
176
177 //! Information about location of breakpoints
178 QList<LineNum> breakPairs;
179
180 Assembler *assembler;
181
182 bool stopped;
183 quint64 pid;
184 bool dbgSymbols;
185
186 quint64 entryPoint;
187
188 public slots:
189 void readOutputToBuffer();
190 void processOutput();
191 void processMessage(QString output, QString error);
192 void processAction(QString output, QString error = QString());
193 void doInput(QString command, DebugActionType actionType);
194 void changeBreakpoint(quint64 lineNumber, bool isAdded);
195 void emitStarted();
196 void checkGdbRun();
197
198 signals:
199 //! Highlight the current debug line.
200 void highlightLine(int);
201 void finished();
202 //! Signal is emited when debugger is ready to get commands like step into and etc.
203 void started();
204 void printRegisters(QList<Debugger::registersInfo>);
205 void printMemory(QList<Debugger::memoryInfo>);
206 void printLog(QString msg, QColor color);
207 void printOutput(QString msg);
208 void inMacro();
209 void wasStopped();
210 void needToContinue();
211 };
212
213 #endif // DEBUGGER_H