-
Notifications
You must be signed in to change notification settings - Fork 1
/
mainwindow.cpp
365 lines (319 loc) · 12 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QProcess>
#include <QDebug>
#include <QTextStream>
#include <QMessageBox>
#include <algorithm>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
mProcess{new Gdb("debug/gdbx64/bin/gdb.exe")}
{
ui->setupUi(this);
connect(mProcess, SIGNAL(signalReadyReadGdb()), this, SLOT(slotReadOutput()), Qt::UniqueConnection);
connect(mProcess, SIGNAL(signalErrorOccured(QString)), this, SLOT(slotErrorOccured(QString)), Qt::UniqueConnection);
connect(mProcess, SIGNAL(signalLocalVarRecieved(QString)), this, SLOT(slotReadLocalVar(QString)), Qt::UniqueConnection);
connect(ui->command, SIGNAL(returnPressed()), this, SLOT(slotWriteToProcess()), Qt::UniqueConnection);
connect(ui->butLocalVar, SIGNAL(clicked(bool)), this, SLOT(slotGetLocalVar()), Qt::UniqueConnection);
connect(ui->butRun, SIGNAL(clicked(bool)), this, SLOT(slotRun()), Qt::UniqueConnection);
connect(ui->butStepOver, SIGNAL(clicked(bool)), this, SLOT(slotStepOver()), Qt::UniqueConnection);
connect(ui->butBreakPoint, SIGNAL(clicked(bool)), this, SLOT(slotSetBreakPoint()), Qt::UniqueConnection);
connect(ui->butClearBreakpoint, SIGNAL(clicked(bool)), this, SLOT(slotClearBreakPoint()), Qt::UniqueConnection);
connect(ui->butStepIn, SIGNAL(clicked(bool)), this, SLOT(slotStepIn()), Qt::UniqueConnection);
connect(ui->butStepOut, SIGNAL(clicked(bool)), this, SLOT(slotStepOut()), Qt::UniqueConnection);
connect(ui->butCurrLine, SIGNAL(clicked(bool)), this, SLOT(slotCurrentLine()), Qt::UniqueConnection);
connect(ui->butShwBrk, SIGNAL(clicked(bool)), this, SLOT(slotShowBreakpoints()), Qt::UniqueConnection);
connect(ui->butVar, SIGNAL(clicked(bool)), this, SLOT(slotShowVar()), Qt::UniqueConnection);
connect(ui->butLocal, SIGNAL(clicked(bool)), this, SLOT(slotShowLocal()), Qt::UniqueConnection);
connect(ui->butUpdateLocals, SIGNAL(clicked(bool)), this, SLOT(slotUpdtaeLocals()), Qt::UniqueConnection);
connect(ui->butGetVarType, SIGNAL(clicked(bool)), this, SLOT(slotGetVarType()), Qt::UniqueConnection);
connect(ui->butReadPointer, SIGNAL(clicked(bool)), this, SLOT(slotReadPointer()), Qt::UniqueConnection);
connect(ui->butTestVar, SIGNAL(clicked(bool)), this, SLOT(slotTestVariable()), Qt::UniqueConnection);
connect(ui->treeWidget, SIGNAL(itemExpanded(QTreeWidgetItem*)), this, SLOT(slotItemExpanded(QTreeWidgetItem*)), Qt::UniqueConnection);
connect(ui->butContinue, SIGNAL(clicked(bool)), this, SLOT(slotContinue()), Qt::UniqueConnection);
connect(ui->butKill, SIGNAL(clicked(bool)), this, SLOT(slotKill()), Qt::UniqueConnection);
connect(ui->butStopExecuting, SIGNAL(clicked(bool)), this, SLOT(slotStipExecuting()), Qt::UniqueConnection);
connect(mProcess, SIGNAL(signalUpdatedVariables()), this, SLOT(slotShowVariables()), Qt::UniqueConnection);
connect(mProcess, SIGNAL(signalTypeUpdated(Variable)), this, SLOT(slotTypeUpdated(Variable)), Qt::UniqueConnection);
connect(mProcess, SIGNAL(signalContentUpdated(Variable)), this, SLOT(slotDereferenceVar(Variable)), Qt::UniqueConnection);
connect(mProcess, SIGNAL(signalBreakpointHit(int)), this, SLOT(slotBreakpointHit(int)), Qt::UniqueConnection);
QFile file(qApp->applicationDirPath().append("/gdb/gdb.exe"));
// qDebug() << "File exist: " << (file.exists());
mProcess->start(QStringList() << "--interpreter=mi");
// ui->command->setText("target exec debug/gdbx64/main.exe");
mProcess->openProject("debug/gdbx64/pairs.exe");
mProcess->setBreakPoint(19);
mProcess->run();
ui->command->setFocus();
ui->treeWidget->setColumnCount(3);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::addTreeRoot(Variable var)
{
QTreeWidgetItem *treeItem = new QTreeWidgetItem(ui->treeWidget);
// QTreeWidgetItem::setText(int column, const QString & text)
mTypeVar[var] = treeItem;
mProcess->getVarType(var);
treeItem->setText(0, var.getName());
QString varContent = var.getContent();
// varContent.append(" (%1)");
// varContent = varContent.arg(var.getType());
treeItem->setText(1, varContent);
addTreeChildren(treeItem, var, "");
}
void MainWindow::addTreeChild(QTreeWidgetItem *parent, Variable var, QString prefix, bool internal = false)
{
QTreeWidgetItem *treeItem = new QTreeWidgetItem();
mTypeVar[var] = treeItem;
if(!internal)
{
mProcess->getVarType(var);
}
QString plainName = var.getName().split('.').last();
treeItem->setText(0, plainName);
treeItem->setText(1, var.getContent());
treeItem->setText(2, var.getType());
if(!internal)
{
addTreeChildren(treeItem, var, prefix);
}
else
{
treeItem->setHidden(true);
}
parent->addChild(treeItem);
}
void MainWindow::addTreeChildren(QTreeWidgetItem *parrent, Variable var, QString prefix, bool drfPointer)
{
std::vector<Variable> nestedTypes = var.getNestedTypes();
if(drfPointer && nestedTypes.size() ==0)
{
addTreeChild(parrent, var, "", false);
}
else if(var.isPointer())
{
QString dereferencedVarName = QString("*(%1)").arg(var.getName());
addTreeChild(parrent, var, "", true); //create fake node to enable expanding parent
mPointersName[parrent] = var; //Add pointer's node to map and attach to this node pointer
}
for(auto i : nestedTypes)
{
// throw;
// QString likelyType;/* = mProcess->getVarType(i.getName());*/
// i.setType(likelyType.isEmpty() ? "<No info>" : likelyType);
addTreeChild(parrent, i, prefix, false);
}
}
void MainWindow::moidifyTreeItemPointer(QTreeWidgetItem *itemPointer)
{ //remove helper node and attachs content of dereferenced pointer
Variable pointer = mPointersName[itemPointer];
QString drfName = tr("(*%1)").arg(pointer.getName());
Variable drfPointer(drfName, "", "");
mPointersContent[drfPointer] = itemPointer;
mProcess->getVarContent(drfName);
QTreeWidgetItem* child = itemPointer->child(0); //Pointer's node always has ony one shils so it's index is '0'
itemPointer->removeChild(child); //remove internal node in tree
}
// target exec D:\Studying\Programming\Qt\My Project\build-UiDebuggerGdb-Custom_Kit-Debug\debug\gdb\gdb.exe
void MainWindow::slotReadOutput()
{
QString processDataString(mProcess->getOutput());
ui->echo->appendPlainText(processDataString);
}
void MainWindow::slotWriteToProcess()
{
QByteArray data;
// data.append(ui->command->text());
// data.append('\n');
QByteArray enter("\n");
data.append(ui->command->text());
//data.append(enter);
mProcess->write(data);
ui->command->clear();
}
void MainWindow::slotGetLocalVar()
{
// mProcess->getLocalVar();
//ui->echo->appendPlainText(mProcess->peekLocalVar());
}
void MainWindow::slotReadLocalVar(const QString &str)
{
ui->echo->appendPlainText("\n*********************\t\t\t{\n");
auto lst = str.split("\\n");
for(QString i : lst)
{
i.replace("\"", "");
i.replace("~", "");
ui->echo->appendPlainText(i);
ui->echo->appendPlainText("\n");
}
ui->echo->appendPlainText("\n*********************\t\t\t}\n");
}
void MainWindow::slotRun()
{
mProcess->run();
}
void MainWindow::slotStepOver()
{
mProcess->stepOver();
}
void MainWindow::slotSetBreakPoint()
{
mProcess->setBreakPoint(9);
}
void MainWindow::slotClearBreakPoint()
{
mProcess->clearBreakPoint(40);
}
void MainWindow::slotStepIn()
{
mProcess->stepIn();
}
void MainWindow::slotStepOut()
{
mProcess->stepOut();
}
void MainWindow::slotCurrentLine()
{
qDebug() << "Current line is:" << mProcess->getCurrentLine();
}
void MainWindow::slotShowBreakpoints()
{
mProcess->updateBreakpointsList();
auto brkLst = mProcess->getBreakpoints();
for(Breakpoint i : brkLst)
{
QString disposition = (i.getDisposition() == Breakpoint::Disposition::Keep) ? "Keep" : "Delete";
ui->designOutput->appendPlainText(QString("Breakpoint. Disposition: %1 Function: %2 Line: %3 Enabled %4\n").arg(disposition)
.arg(i.getFrame()).arg(QString::number(i.getLine()))
.arg(i.isEnabled() ? "True" : "False"));
}
}
void MainWindow::slotShowVar()
{
}
void MainWindow::slotShowLocal()
{
// auto vars = mProcess->getLocalVar();
// for(auto i : vars)
// {
// ui->designOutput->appendPlainText(i.append(mProcess->getVarContent(i)).append("\n"));
// }
}
void MainWindow::slotUpdtaeLocals()
{
mProcess->updateVariable64x();
}
void MainWindow::slotShowVariables()
{
ui->designOutput->clear();
auto locals = mProcess->getLocalVariables();
ui->treeWidget->clear();
for(auto i : locals)
{
addTreeRoot(i);
}
}
void MainWindow::slotTypeUpdated(Variable var)
{
auto iterator = (find_if(mPointersContent.begin(), mPointersContent.end(),
[&](auto item)
{
return (var.getName() == item.first.getName());
}));
if(iterator != mPointersContent.end())
{
QTreeWidgetItem* itemPointer = (find_if(mPointersContent.begin(), mPointersContent.end(),
[&](auto item)
{
return (var.getName() == item.first.getName());
})->second);
if(var.isPointer())
{
var.setContent(var.getContent().replace(tr("(%1)").arg(var.getType()), ""));
}
auto nestedTypes = var.getNestedTypes();
bool isNotPointer = !var.isPointer();
if(nestedTypes.size() == 0 && isNotPointer)
{
addTreeChild(itemPointer, var, "", false);
mPointersContent.erase(iterator);
return;
}
addTreeChildren(itemPointer, var, "", true); //append dereferenced pointer to node with addres
mPointersContent.erase(iterator);
}
else
{
QTreeWidgetItem* item = mTypeVar[var];
item->setText(2, var.getType());
if(var.isPointer())
{
QString dereferencedVarName = QString("*(%1)").arg(var.getName());
addTreeChild(item, var, "", true); //create fake node to enable expanding parent
mPointersName[item] = var; //Add pointer's node to map and attach to this node pointer
}
}
}
void MainWindow::slotDereferenceVar(Variable var)
{
mProcess->getVarType(var);
}
void MainWindow::slotBreakpointHit(int line)
{
QMessageBox msg;
msg.setText(tr("Programm hit breakpoint at %1 line").arg(QString::number(line)));
msg.exec();
slotUpdtaeLocals();
}
void MainWindow::slotErrorOccured(QString error)
{
ui->designOutput->appendPlainText(error);
}
void MainWindow::slotGetVarType()
{
throw;
// mProcess->getVarType("conj.digit");
}
void MainWindow::slotReadPointer()
{
// ui->designOutput->appendPlainText(mProcess->getVarContent("pointer"));
}
void MainWindow::slotTestVariable()
{
QString vec = "~\"$1 = {< std::_Vector_base < int, std::allocator < int > >>"
" = { _M_impl = {< std::allocator < int >> = {< __gnu_cxx::new_allocator < int >> = {"
"< No data fields>}, < No data fields>}, _M_start = 0x786e58, _M_finish = 0x786e74, "
"_M_end_of_storage = 0x786e74}\"~\"}, <No data fields>}~\"\n\"^ done(gdb)";
Variable var("SomeName", "SomeType", vec);
auto nestedTypes = var.readNestedStruct(var.getContent());
for(auto i : nestedTypes)
{
qDebug() << i;
}
}
void MainWindow::slotItemExpanded(QTreeWidgetItem *item)
{
auto foundIterator = mPointersName.find(item);
if(foundIterator != mPointersName.end())
{
moidifyTreeItemPointer(item);
mPointersName.erase(foundIterator);
}
}
void MainWindow::slotContinue()
{
mProcess->stepContinue();
}
void MainWindow::slotKill()
{
mProcess->kill();
}
void MainWindow::slotStipExecuting()
{
mProcess->stopExecuting();
}