OpenCores
URL https://opencores.org/ocsvn/riscv_vhdl/riscv_vhdl/trunk

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [debugger/] [src/] [gui_plugin/] [MainWindow/] [DbgMainWindow.cpp] - Blame information for rev 5

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 sergeykhbr
#include "DbgMainWindow.h"
2
#include "moc_DbgMainWindow.h"
3
#include "ControlWidget/PnpWidget.h"
4
#include "CpuWidgets/RegsViewWidget.h"
5
#include "CpuWidgets/AsmViewWidget.h"
6
#include "CpuWidgets/MemViewWidget.h"
7
#include "CpuWidgets/SymbolBrowserWidget.h"
8
#include "CpuWidgets/StackTraceWidget.h"
9
#include "ControlWidget/ConsoleWidget.h"
10
#include "PeriphWidgets/UartWidget.h"
11
#include "PeriphWidgets/GpioWidget.h"
12
#include "GnssWidgets/MapWidget.h"
13 4 sergeykhbr
#include "GnssWidgets/PlotWidget.h"
14 3 sergeykhbr
#include <QtWidgets/QtWidgets>
15
 
16 4 sergeykhbr
#ifdef WIN32
17
//#define GITHUB_SCREENSHOT_SIZE
18
#endif
19
 
20 3 sergeykhbr
namespace debugger {
21
 
22
DbgMainWindow::DbgMainWindow(IGui *igui) : QMainWindow() {
23
    igui_ = igui;
24
    statusRequested_ = false;
25
    ebreak_ = 0;
26
 
27
    setWindowTitle(tr("RISC-V platform debugger"));
28 4 sergeykhbr
#ifdef GITHUB_SCREENSHOT_SIZE
29
    resize(QSize(872, 600));
30
#else
31 3 sergeykhbr
    resize(QDesktopWidget().availableGeometry(this).size() * 0.7);
32 4 sergeykhbr
#endif
33 3 sergeykhbr
 
34
    listConsoleListeners_.make_list(0);
35
    /** Console commands used by main window: */
36
    cmdStatus_.make_string("status");
37
    cmdRun_.make_string("c");
38
    cmdHalt_.make_string("halt");
39
    cmdStep_.make_string("c 1");
40
 
41
    createActions();
42
    createMenus();
43
    createStatusBar();
44
    createMdiWindow();
45
 
46
    /** QT documeneted behaviour:
47
     *
48
     * If you add a child widget to an already visible widget
49
     * you must explicitly show the child to make it visible.
50
     */
51
    addWidgets();
52
 
53
    setUnifiedTitleAndToolBarOnMac(true);
54
 
55
    ISocInfo *isoc = static_cast<ISocInfo *>(igui_->getSocInfo());
56
    if (isoc) {
57
        DsuMapType *dsu = isoc->getpDsu();
58
        ebreak_ = new EBreakHandler(igui_);
59
 
60
        ebreak_->setBrAddressFetch(
61
            reinterpret_cast<uint64_t>(&dsu->udbg.v.br_address_fetch));
62
        ebreak_->setHwRemoveBreakpoint(
63
            reinterpret_cast<uint64_t>(&dsu->udbg.v.remove_breakpoint));
64
    }
65
 
66
    /**
67
     * To use the following type in SIGNAL -> SLOT definitions
68
     * we have to register them using qRegisterMetaType template
69
     */
70
    qRegisterMetaType<uint64_t>("uint64_t");
71
    qRegisterMetaType<uint32_t>("uint32_t");
72
 
73
    tmrGlobal_ = new QTimer(this);
74
    connect(tmrGlobal_, SIGNAL(timeout()), this, SLOT(slotUpdateByTimer()));
75
    tmrGlobal_->setSingleShot(false);
76 4 sergeykhbr
    const AttributeType &cfg = *igui->getpConfig();
77
    int t1 = cfg["PollingMs"].to_int();
78
    if (t1 < 10) {
79
        t1 = 10;
80
    }
81
    tmrGlobal_->setInterval(t1);
82 3 sergeykhbr
    tmrGlobal_->start();
83
}
84
 
85
DbgMainWindow::~DbgMainWindow() {
86
    if (ebreak_) {
87
        delete ebreak_;
88
    }
89
    igui_->removeFromQueue(static_cast<IGuiCmdHandler *>(this));
90
}
91
 
92
void DbgMainWindow::closeEvent(QCloseEvent *ev) {
93
    tmrGlobal_->stop();
94
    delete tmrGlobal_;
95
    ev->accept();
96
    emit signalAboutToClose();
97
}
98
 
99
#ifndef QT_NO_CONTEXTMENU
100
void DbgMainWindow::contextMenuEvent(QContextMenuEvent *ev_) {
101
    QMenu menu(this);
102
    menu.addAction(actionRegs_);
103
    menu.exec(ev_->globalPos());
104
}
105
#endif
106
 
107
void DbgMainWindow::handleResponse(AttributeType *req, AttributeType *resp) {
108
    if (req->is_equal(cmdStatus_.to_string())) {
109
        statusRequested_ = false;
110
        if (resp->is_nil()) {
111
            return;
112
        }
113 4 sergeykhbr
        GenericCpuControlType ctrl;
114 3 sergeykhbr
        ctrl.val = resp->to_uint64();
115
        if ((actionRun_->isChecked() && ctrl.bits.halt)
116
            || (!actionRun_->isChecked() && !ctrl.bits.halt)) {
117
            emit signalTargetStateChanged(ctrl.bits.halt == 0);
118
        }
119 4 sergeykhbr
        if ((ctrl.bits.sw_breakpoint || ctrl.bits.hw_breakpoint) && ebreak_) {
120 3 sergeykhbr
            ebreak_->skip();
121
        }
122
#if 0
123
        static const char *xSTATES[] = {"Idle", "WaitGrant", "WaitResp", "WaitAccept"};
124
        static const char *CSTATES[] = {"Idle", "IMem", "DMem"};
125
        RISCV_printf(0, 0, "istate=%s dstate=%s; cstate=%s",
126
          xSTATES[ctrl.bits.istate],
127
          xSTATES[ctrl.bits.dstate],
128
          CSTATES[ctrl.bits.cstate]);
129
#endif
130
    }
131
}
132
 
133
void DbgMainWindow::createActions() {
134
    actionRegs_ = new QAction(QIcon(tr(":/images/cpu_96x96.png")),
135
                              tr("&Regs"), this);
136
    actionRegs_->setToolTip(tr("CPU Registers view"));
137
    actionRegs_->setShortcut(QKeySequence(tr("Ctrl+r")));
138
    actionRegs_->setCheckable(true);
139
    actionRegs_->setChecked(false);
140
    connect(actionRegs_, SIGNAL(triggered(bool)),
141
            this, SLOT(slotActionTriggerRegs(bool)));
142
 
143
    actionCpuAsm_ = new QAction(QIcon(tr(":/images/asm_96x96.png")),
144
                              tr("&Memory"), this);
145
    actionCpuAsm_->setToolTip(tr("Disassembler view"));
146
    actionCpuAsm_->setShortcut(QKeySequence(tr("Ctrl+d")));
147
    actionCpuAsm_->setCheckable(true);
148
    connect(actionCpuAsm_, SIGNAL(triggered(bool)),
149
            this, SLOT(slotActionTriggerCpuAsmView(bool)));
150
 
151
    actionStackTrace_ = new QAction(QIcon(tr(":/images/stack_96x96.png")),
152
                              tr("&Stack"), this);
153
    actionStackTrace_->setToolTip(tr("Stack trace"));
154
    actionStackTrace_->setShortcut(QKeySequence(tr("Ctrl+t")));
155
    actionStackTrace_->setCheckable(true);
156
    connect(actionStackTrace_, SIGNAL(triggered(bool)),
157
            this, SLOT(slotActionTriggerStackTraceView(bool)));
158
 
159
    actionSymbolBrowser_ = new QAction(QIcon(tr(":/images/info_96x96.png")),
160
                              tr("&Symbols"), this);
161
    actionSymbolBrowser_->setToolTip(tr("Symbol Browser"));
162
    actionSymbolBrowser_->setShortcut(QKeySequence(tr("Ctrl+s")));
163
    actionSymbolBrowser_->setCheckable(false);
164
    connect(actionSymbolBrowser_, SIGNAL(triggered()),
165
            this, SLOT(slotActionTriggerSymbolBrowser()));
166
 
167
    actionMem_ = new QAction(QIcon(tr(":/images/mem_96x96.png")),
168
                              tr("&Memory"), this);
169
    actionMem_->setToolTip(tr("Memory view"));
170
    actionMem_->setShortcut(QKeySequence(tr("Ctrl+m")));
171
    actionMem_->setCheckable(true);
172
    actionMem_->setChecked(false);
173
    connect(actionMem_, SIGNAL(triggered(bool)),
174
            this, SLOT(slotActionTriggerMemView(bool)));
175
 
176
    actionPnp_ = new QAction(QIcon(tr(":/images/board_96x96.png")),
177
                              tr("&Pnp"), this);
178
    actionPnp_->setToolTip(tr("Plug'n'play information view"));
179
    actionPnp_->setShortcut(QKeySequence(tr("Ctrl+p")));
180
    actionPnp_->setCheckable(true);
181
    actionPnp_->setChecked(false);
182
    connect(actionPnp_, SIGNAL(triggered(bool)),
183
            this, SLOT(slotActionTriggerPnp(bool)));
184
 
185
    actionGpio_ = new QAction(QIcon(tr(":/images/gpio_96x96.png")),
186
                              tr("&GPIO"), this);
187
    actionGpio_->setToolTip(tr("GPIO control view"));
188
    actionGpio_->setCheckable(true);
189
    actionGpio_->setChecked(false);
190
    connect(actionGpio_, SIGNAL(triggered(bool)),
191
            this, SLOT(slotActionTriggerGpio(bool)));
192
 
193
    actionSerial_ = new QAction(QIcon(tr(":/images/serial_96x96.png")),
194
                              tr("&Serial port"), this);
195
    actionSerial_->setToolTip(tr("Serial port console view"));
196
    actionSerial_->setCheckable(true);
197
    actionSerial_->setChecked(false);
198
    connect(actionSerial_, SIGNAL(triggered(bool)),
199
            this, SLOT(slotActionTriggerUart0(bool)));
200
 
201
    actionGnssMap_ = new QAction(QIcon(tr(":/images/opmap_96x96.png")),
202
                              tr("&OpenStreetMap"), this);
203
    actionGnssMap_->setToolTip(tr("Open Street map with GNSS tracks view"));
204
    actionGnssMap_->setCheckable(true);
205
    actionGnssMap_->setChecked(false);
206
    connect(actionGnssMap_, SIGNAL(triggered(bool)),
207
            this, SLOT(slotActionTriggerGnssMap(bool)));
208
 
209 4 sergeykhbr
    actionGnssPlot_ = new QAction(QIcon(tr(":/images/plot_96x96.png")),
210
                              tr("HW Statistic"), this);
211
    actionGnssPlot_->setToolTip(tr("Open HW statistic"));
212
    actionGnssPlot_->setCheckable(true);
213
    actionGnssPlot_->setChecked(false);
214
    connect(actionGnssPlot_, SIGNAL(triggered(bool)),
215
            this, SLOT(slotActionTriggerGnssPlot(bool)));
216
 
217 3 sergeykhbr
    actionRun_ = new QAction(QIcon(tr(":/images/start_96x96.png")),
218
                             tr("&Run"), this);
219
    actionRun_->setToolTip(tr("Start Execution (F5)"));
220
    actionRun_->setShortcut(QKeySequence(tr("F5")));
221
    actionRun_->setCheckable(true);
222
    actionRun_->setChecked(false);
223
    connect(actionRun_ , SIGNAL(triggered()),
224
            this, SLOT(slotActionTargetRun()));
225
    connect(this, SIGNAL(signalTargetStateChanged(bool)),
226
            actionRun_, SLOT(setChecked(bool)));
227
 
228
    actionHalt_ = new QAction(QIcon(tr(":/images/pause_96x96.png")),
229
                              tr("&Halt"), this);
230
    actionHalt_->setToolTip(tr("Stop Execution (Ctrl+Alt+F5)"));
231
    actionHalt_->setShortcut(QKeySequence(tr("Ctrl+Alt+F5")));
232
    connect(actionHalt_ , SIGNAL(triggered()),
233
            this, SLOT(slotActionTargetHalt()));
234
 
235
    actionStep_ = new QAction(QIcon(tr(":/images/stepinto_96x96.png")),
236
                              tr("&Step Into"), this);
237
    actionStep_->setToolTip(tr("Instruction Step (F11)"));
238
    actionStep_->setShortcut(QKeySequence(tr("F11")));
239
    connect(actionStep_ , SIGNAL(triggered()),
240
            this, SLOT(slotActionTargetStepInto()));
241
 
242
 
243
    actionQuit_ = new QAction(tr("&Quit"), this);
244
    actionQuit_->setShortcuts(QKeySequence::Quit);
245
    actionQuit_->setStatusTip(tr("Quit the application"));
246
    connect(actionQuit_, SIGNAL(triggered()), this, SLOT(close()));
247
 
248
    actionAbout_ = new QAction(tr("&About"), this);
249
    actionAbout_->setStatusTip(tr("Show the application's About box"));
250
    connect(actionAbout_, SIGNAL(triggered()), this, SLOT(slotActionAbout()));
251
 
252
    QToolBar *toolbarRunControl = addToolBar(tr("toolbarRunControl"));
253
    toolbarRunControl->addAction(actionRun_);
254
    toolbarRunControl->addAction(actionHalt_);
255
    toolbarRunControl->addAction(actionStep_);
256
 
257
    QToolBar *toolbarCpu = addToolBar(tr("toolbarCpu"));
258
    toolbarCpu->addAction(actionCpuAsm_);
259
    toolbarCpu->addAction(actionRegs_);
260
    toolbarCpu->addAction(actionStackTrace_);
261
    toolbarCpu->addAction(actionMem_);
262
    QToolBar *toolbarPeriph = addToolBar(tr("toolbarPeriph"));
263
    toolbarPeriph->addAction(actionPnp_);
264
}
265
 
266
void DbgMainWindow::createMenus() {
267
    QMenu *menu = menuBar()->addMenu(tr("&File"));
268
    menu->addAction(actionQuit_);
269
    menu->addSeparator();
270
 
271
    menu = menuBar()->addMenu(tr("&Views"));
272
    menu->addAction(actionSerial_);
273
    menu->addAction(actionGpio_);
274
    menu->addAction(actionPnp_);
275
    menu->addSeparator();
276
    menu->addAction(actionRegs_);
277
    menu->addAction(actionSymbolBrowser_);
278 4 sergeykhbr
    menu->addAction(actionGnssPlot_);
279 3 sergeykhbr
 
280
    menu = menuBar()->addMenu(tr("&GNSS"));
281
    menu->addAction(actionGnssMap_);
282
 
283
    menu = menuBar()->addMenu(tr("&Help"));
284
    menu->addAction(actionAbout_);
285
}
286
 
287
 
288
void DbgMainWindow::createStatusBar() {
289
    statusBar()->showMessage(tr("Ready"));
290
}
291
 
292
void DbgMainWindow::createMdiWindow() {
293
    AttributeType cfgMdi(Attr_Dict);
294
    cfgMdi["Tabbed"].make_boolean(false);
295
    mdiArea_ = new MdiAreaWidget(cfgMdi, this);
296
    setCentralWidget(mdiArea_);
297
 
298
    /** Docked Widgets: */
299
    QDockWidget *dock = new QDockWidget(tr("Debugger console"), this);
300
    dock->setAllowedAreas(Qt::BottomDockWidgetArea);
301
    addDockWidget(Qt::BottomDockWidgetArea, dock);
302
 
303
    ConsoleWidget *consoleWidget = new ConsoleWidget(igui_, this);
304
    dock->setWidget(consoleWidget);
305 4 sergeykhbr
 
306
#ifdef GITHUB_SCREENSHOT_SIZE
307
    double desired_h =
308
        QDesktopWidget().availableGeometry(this).size().height() * 0.07;
309
    consoleWidget->setFixedHeight(desired_h);
310
#endif
311 3 sergeykhbr
}
312
 
313
void DbgMainWindow::addWidgets() {
314
    slotActionTriggerUart0(true);
315
    slotActionTriggerCpuAsmView(true);
316
 
317
    //slotActionTriggerGnssMap(true);
318
}
319
 
320
void DbgMainWindow::slotActionTriggerUart0(bool val) {
321
    if (val) {
322
        viewUart0_ =
323
            new UartQMdiSubWindow(igui_, mdiArea_, this, actionSerial_);
324
    } else {
325
        viewUart0_->close();
326
    }
327
}
328
 
329
void DbgMainWindow::slotActionTriggerCpuAsmView(bool val) {
330
    if (val) {
331
        viewCpuAsm_ =
332
            new AsmQMdiSubWindow(igui_, mdiArea_, this, actionCpuAsm_);
333
    } else {
334
        viewCpuAsm_->close();
335
    }
336
}
337
 
338
void DbgMainWindow::slotActionTriggerRegs(bool val) {
339
    if (val) {
340
        viewRegs_ = new RegsQMdiSubWindow(igui_, mdiArea_, this,
341
                                        actionRegs_);
342
    } else {
343
        viewRegs_->close();
344
    }
345
}
346
 
347
void DbgMainWindow::slotActionTriggerStackTraceView(bool val) {
348
    if (val) {
349
        viewStackTrace_ =
350
            new StackTraceQMdiSubWindow(igui_, mdiArea_, this, actionStackTrace_);
351
    } else {
352
        viewStackTrace_->close();
353
    }
354
}
355
 
356
void DbgMainWindow::slotActionTriggerMemView(bool val) {
357
    if (val) {
358
        viewMem_ = new MemQMdiSubWindow(igui_, mdiArea_, this,
359
                                        0xfffff000, 20, actionMem_);
360
    } else {
361
        viewMem_->close();
362
    }
363
}
364
 
365
void DbgMainWindow::slotActionTriggerGpio(bool val) {
366
    if (val) {
367
        viewGpio_ = new GpioQMdiSubWindow(igui_, mdiArea_, this,
368
                                        actionGpio_);
369
    } else {
370
        viewGpio_->close();
371
    }
372
}
373
 
374
void DbgMainWindow::slotActionTriggerPnp(bool val) {
375
    if (val) {
376
        viewPnp_ = new PnpQMdiSubWindow(igui_, mdiArea_, this,
377
                                        actionPnp_);
378
    } else {
379
        viewPnp_->close();
380
    }
381
}
382
 
383
void DbgMainWindow::slotActionTriggerGnssMap(bool val) {
384
    if (val) {
385
        viewGnssMap_ =
386
            new MapQMdiSubWindow(igui_, mdiArea_, this, actionGnssMap_);
387
    } else {
388
        viewGnssMap_->close();
389
    }
390
}
391
 
392 4 sergeykhbr
void DbgMainWindow::slotActionTriggerGnssPlot(bool val) {
393
    if (val) {
394
        viewGnssPlot_ =
395
            new PlotQMdiSubWindow(igui_, mdiArea_, this, actionGnssPlot_);
396
    } else {
397
        viewGnssPlot_->close();
398
    }
399
}
400 3 sergeykhbr
 
401
void DbgMainWindow::slotActionTriggerSymbolBrowser() {
402
    new SymbolBrowserQMdiSubWindow(igui_, mdiArea_, this);
403
}
404
 
405
void DbgMainWindow::slotOpenDisasm(uint64_t addr, uint64_t sz) {
406
    new AsmQMdiSubWindow(igui_, mdiArea_, this, NULL, addr);
407
}
408
 
409
void DbgMainWindow::slotOpenMemory(uint64_t addr, uint64_t sz) {
410
    new MemQMdiSubWindow(igui_, mdiArea_, this, addr, sz);
411
}
412
 
413
void DbgMainWindow::slotUpdateByTimer() {
414
    if (!statusRequested_) {
415
        statusRequested_ = true;
416
        igui_->registerCommand(static_cast<IGuiCmdHandler *>(this),
417
                               &cmdStatus_, true);
418
    }
419
    emit signalUpdateByTimer();
420
}
421
 
422
void DbgMainWindow::slotActionAbout() {
423
    char date[128];
424
    memcpy(date, __DATE__, sizeof(date));
425
    QString build;
426
    build.sprintf("Version: 1.0\nBuild:     %s\n", date);
427
    build += tr("Author: Sergey Khabarov\n");
428
    build += tr("git:    http://github.com/sergeykhbr/riscv_vhdl\n");
429
    build += tr("e-mail: sergeykhbr@gmail.com\n\n\n"
430
       "RISC-V debugger GUI plugin is the open source extension of\n"
431
       "the base RISC-V debugger functionality providing friendly interface\n"
432
       "with running SoC target or with the Simulated platform.\n"
433
       "\n"
434
       "This extension doesn't use any specific for GUI scripts or commands\n"
435
       "and all shown information maybe achievied using debugger's console\n"
436
       "commands. See 'help' command.\n\n"
437
    );
438
    build += tr("www.gnss-sensor.com\n");
439
 
440
    QMessageBox::about(this, tr("About GUI plugin"), build);
441
}
442
 
443
void DbgMainWindow::slotActionTargetRun() {
444
    actionRun_->setChecked(true);
445
    igui_->registerCommand(static_cast<IGuiCmdHandler *>(this),
446
                           &cmdRun_, true);
447
}
448
 
449
void DbgMainWindow::slotActionTargetHalt() {
450
    igui_->registerCommand(static_cast<IGuiCmdHandler *>(this),
451
                           &cmdHalt_, true);
452
}
453
 
454
void DbgMainWindow::slotActionTargetStepInto() {
455
    igui_->registerCommand(static_cast<IGuiCmdHandler *>(this),
456
                           &cmdStep_, true);
457
}
458
 
459
/** Redraw all opened disassembler views */
460
void DbgMainWindow::slotBreakpointsChanged() {
461
    emit signalRedrawDisasm();
462
}
463
 
464
}  // namespace debugger
465
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.