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

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [debugger/] [src/] [gui_plugin/] [CpuWidgets/] [SymbolBrowserArea.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
/**
2
 * @file
3
 * @copyright  Copyright 2017 GNSS Sensor Ltd. All right reserved.
4
 * @author     Sergey Khabarov - sergeykhbr@gmail.com
5
 * @brief      Symbol Browser main area.
6
 */
7
 
8 4 sergeykhbr
#include "coreservices/ielfreader.h"
9 3 sergeykhbr
#include "SymbolBrowserArea.h"
10
#include "moc_SymbolBrowserArea.h"
11
 
12
#include <memory>
13
#include <string.h>
14
#include <QtWidgets/QBoxLayout>
15
#include <QtWidgets/QLabel>
16
#include <QtWidgets/QHeaderView>
17
#include <QtWidgets/QScrollBar>
18
 
19
namespace debugger {
20
 
21
SymbolBrowserArea::SymbolBrowserArea(IGui *gui, QWidget *parent)
22
    : QTableWidget(parent) {
23
    igui_ = gui;
24
 
25
    clear();
26
    QFont font("Courier");
27
    font.setStyleHint(QFont::Monospace);
28
    font.setPointSize(8);
29
    font.setFixedPitch(true);
30
    setFont(font);
31
    setContentsMargins(QMargins(0, 0, 0, 0));
32
    QFontMetrics fm(font);
33
    setMinimumWidth(50 + fm.width(tr(
34
    "some_test_function  (void ())       P:aabbccdd--aabbffff")));
35
    lineHeight_ = fm.height() + 4;
36
    hideLineIdx_ = 0;
37
 
38
    setColumnCount(COL_Total);
39
    setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
40
    setListSize(1);
41
 
42
    verticalHeader()->setVisible(false);        // remove row indexes
43
    setShowGrid(false);                         // remove borders
44
    setSelectionMode(QAbstractItemView::SingleSelection);
45
    setSelectionBehavior(QAbstractItemView::SelectRows); //select full row
46
 
47
    // change selected row color
48
    QPalette *palette = new QPalette();
49
    palette->setColor(QPalette::Highlight, Qt::gray);
50
    setPalette(*palette);
51
 
52
    setHorizontalHeaderLabels(
53
        QString("symbol;type;address").split(";"));
54
    setColumnWidth(COL_symbol, 10 + fm.width(tr("some_test_function ")));
55
    setColumnWidth(COL_type, 10 + fm.width(tr("(void ())      ")));
56
    setColumnWidth(COL_address, 10 + fm.width(tr("P:0x00001000--0x00001040")));
57
 
58
    connect(this, SIGNAL(cellDoubleClicked(int, int)),
59
            this, SLOT(slotCellDoubleClicked(int, int)));
60
 
61
    connect(this, SIGNAL(signalHandleResponse()),
62
            this, SLOT(slotHandleResponse()));
63
 
64
    AttributeType tcmd("symb");
65
    igui_->registerCommand(static_cast<IGuiCmdHandler *>(this),
66
                           &tcmd, true);
67
}
68
 
69
SymbolBrowserArea::~SymbolBrowserArea() {
70
    igui_->removeFromQueue(static_cast<IGuiCmdHandler *>(this));
71
}
72
 
73
void SymbolBrowserArea::setListSize(int sz) {
74
    if (sz > rowCount()) {
75
        for (int i = hideLineIdx_; i < rowCount(); i++) {
76
            showRow(i);
77
        }
78
        hideLineIdx_ = sz;
79
 
80
        Qt::ItemFlags fl;
81
        int rowcnt_cur = rowCount();
82
        setRowCount(sz);
83
        for (int i = rowcnt_cur; i < rowCount(); i++) {
84
            for (int n = 0; n < COL_Total; n++) {
85
                setItem(i, n, new QTableWidgetItem());
86
                fl = item(i, n)->flags();
87
                fl &= ~Qt::ItemIsEditable;
88
                //fl &= ~Qt::ItemIsSelectable;
89
                item(i, n)->setFlags(fl);
90
            }
91
            setRowHeight(i, lineHeight_);
92
        }
93
    } else {
94
        for (int i = hideLineIdx_; i < sz; i++) {
95
            showRow(i);
96
        }
97
        hideLineIdx_ = sz;
98
        for (int i = sz; i < rowCount(); i++) {
99
            hideRow(i);
100
        }
101
    }
102
}
103
 
104
void SymbolBrowserArea::handleResponse(AttributeType *req,
105
                                       AttributeType *resp) {
106
    if (strstr(req->to_string(), "symb") == 0) {
107
        return;
108
    }
109
    symbolList_ = *resp;
110
    emit signalHandleResponse();
111
}
112
 
113
void SymbolBrowserArea::slotHandleResponse() {
114
    if (!symbolList_.is_list()) {
115
        return;
116
    }
117
    QTableWidgetItem *pw;
118
    Qt::ItemFlags fl;
119
    char tstr[256];
120
    uint64_t addr;
121
    int list_sz = static_cast<int>(symbolList_.size());
122
    setListSize(list_sz);
123
 
124
    for (int i = 0; i < list_sz; i++) {
125
        AttributeType &symb = symbolList_[i];
126
 
127
        pw = item(i, COL_symbol);
128
        pw->setText(QString(symb[Symbol_Name].to_string()));
129
 
130
        pw = item(i, COL_type);
131
        if (symb[Symbol_Type].to_uint64() & SYMBOL_TYPE_FUNCTION) {
132
            pw->setText(tr("function"));
133
        } else if (symb[Symbol_Type].to_uint64() & SYMBOL_TYPE_DATA) {
134
            pw->setText(tr("data"));
135
        } else {
136
        }
137
 
138
        pw = item(i, COL_address);
139
        addr = symb[Symbol_Addr].to_uint64();
140
        RISCV_sprintf(tstr, sizeof(tstr),
141
                    "%08" RV_PRI64 "x--%08" RV_PRI64 "x",
142
                    addr, addr + symb[Symbol_Size].to_uint64());
143
        pw->setText(QString(tstr));
144
    }
145
}
146
 
147
void SymbolBrowserArea::slotFilterChanged(const QString &flt) {
148
    AttributeType tcmd;
149
    QByteArray flt_buf;
150
    flt_buf.append("symb " + flt);
151
    tcmd.make_string(flt_buf.data());
152
    igui_->registerCommand(static_cast<IGuiCmdHandler *>(this),
153
                           &tcmd, true);
154
}
155
 
156
void SymbolBrowserArea::slotCellDoubleClicked(int row, int column) {
157
    if (row >= static_cast<int>(symbolList_.size())) {
158
        return;
159
    }
160
 
161
    AttributeType &symb = symbolList_[row];
162
    uint64_t addr = symb[Symbol_Addr].to_uint64();
163
    uint64_t sz = symb[Symbol_Size].to_uint64();
164
 
165
    if (symb[Symbol_Type].to_uint64() & SYMBOL_TYPE_FUNCTION) {
166
        emit signalShowFunction(addr, sz);
167
    } else {
168
        emit signalShowData(addr, sz);
169
    }
170
}
171
 
172
}  // namespace debugger

powered by: WebSVN 2.1.0

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