mirror of
https://github.com/rizinorg/cutter.git
synced 2025-01-19 10:58:51 +00:00
Fixed many warnings in DisassemblerGraphView (#1103)
Most of them were qreal to integer precision loss, so I added static_cast to remove the warnings.
This commit is contained in:
parent
f385cf26d5
commit
b0bb1f0610
@ -183,7 +183,7 @@ void DisassemblerGraphView::loadCurrentGraph()
|
|||||||
if (emptyGraph) {
|
if (emptyGraph) {
|
||||||
// If there's no function to print, just add a message
|
// If there's no function to print, just add a message
|
||||||
if (!emptyText) {
|
if (!emptyText) {
|
||||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
auto *layout = new QVBoxLayout(this);
|
||||||
emptyText = new QLabel(this);
|
emptyText = new QLabel(this);
|
||||||
emptyText->setText(tr("No function detected. Cannot display graph."));
|
emptyText->setText(tr("No function detected. Cannot display graph."));
|
||||||
emptyText->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
|
emptyText->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
|
||||||
@ -222,7 +222,7 @@ void DisassemblerGraphView::loadCurrentGraph()
|
|||||||
RVA entry = func["offset"].toVariant().toULongLong();
|
RVA entry = func["offset"].toVariant().toULongLong();
|
||||||
|
|
||||||
setEntry(entry);
|
setEntry(entry);
|
||||||
for (const QJsonValue &value : func["blocks"].toArray()) {
|
for (const QJsonValueRef &value : func["blocks"].toArray()) {
|
||||||
QJsonObject block = value.toObject();
|
QJsonObject block = value.toObject();
|
||||||
RVA block_entry = block["offset"].toVariant().toULongLong();
|
RVA block_entry = block["offset"].toVariant().toULongLong();
|
||||||
RVA block_size = block["size"].toVariant().toULongLong();
|
RVA block_size = block["size"].toVariant().toULongLong();
|
||||||
@ -309,7 +309,7 @@ void DisassemblerGraphView::loadCurrentGraph()
|
|||||||
anal.status = "Ready.";
|
anal.status = "Ready.";
|
||||||
anal.entry = f.entry;
|
anal.entry = f.entry;
|
||||||
|
|
||||||
if (func["blocks"].toArray().size() > 0) {
|
if (!func["blocks"].toArray().isEmpty()) {
|
||||||
computeGraph(entry);
|
computeGraph(entry);
|
||||||
viewport()->update();
|
viewport()->update();
|
||||||
|
|
||||||
@ -343,8 +343,8 @@ void DisassemblerGraphView::prepareGraphNode(GraphBlock &block)
|
|||||||
height += 1;
|
height += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int extra = 4 * charWidth + 4;
|
int extra = static_cast<int>(4 * charWidth + 4);
|
||||||
block.width = width + extra + charWidth;
|
block.width = static_cast<int>(width + extra + charWidth);
|
||||||
block.height = (height * charHeight) + extra;
|
block.height = (height * charHeight) + extra;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -365,9 +365,8 @@ void DisassemblerGraphView::initFont()
|
|||||||
QFontMetricsF metrics(font());
|
QFontMetricsF metrics(font());
|
||||||
baseline = int(metrics.ascent());
|
baseline = int(metrics.ascent());
|
||||||
charWidth = metrics.width('X');
|
charWidth = metrics.width('X');
|
||||||
charHeight = metrics.height();
|
charHeight = static_cast<int>(metrics.height());
|
||||||
charOffset = 0;
|
charOffset = 0;
|
||||||
if (mFontMetrics)
|
|
||||||
delete mFontMetrics;
|
delete mFontMetrics;
|
||||||
mFontMetrics = new CachedFontMetrics(this, font());
|
mFontMetrics = new CachedFontMetrics(this, font());
|
||||||
}
|
}
|
||||||
@ -426,7 +425,7 @@ void DisassemblerGraphView::drawBlock(QPainter &p, GraphView::GraphBlock &block)
|
|||||||
|
|
||||||
// Draw different background for selected instruction
|
// Draw different background for selected instruction
|
||||||
if (selected_instruction != RVA_INVALID) {
|
if (selected_instruction != RVA_INVALID) {
|
||||||
int y = block.y + (2 * charWidth) + (db.header_text.lines.size() * charHeight);
|
int y = static_cast<int>(block.y + (2 * charWidth) + (db.header_text.lines.size() * charHeight));
|
||||||
for (const Instr &instr : db.instrs) {
|
for (const Instr &instr : db.instrs) {
|
||||||
if (instr.addr > selected_instruction) {
|
if (instr.addr > selected_instruction) {
|
||||||
break;
|
break;
|
||||||
@ -435,10 +434,12 @@ void DisassemblerGraphView::drawBlock(QPainter &p, GraphView::GraphBlock &block)
|
|||||||
//auto traceCount = dbgfunctions->GetTraceRecordHitCount(instr.addr);
|
//auto traceCount = dbgfunctions->GetTraceRecordHitCount(instr.addr);
|
||||||
auto traceCount = 0;
|
auto traceCount = 0;
|
||||||
if (selected && traceCount) {
|
if (selected && traceCount) {
|
||||||
p.fillRect(QRect(block.x + charWidth, y, block.width - (10 + 2 * charWidth),
|
p.fillRect(QRect(static_cast<int>(block.x + charWidth), y,
|
||||||
|
static_cast<int>(block.width - (10 + 2 * charWidth)),
|
||||||
int(instr.text.lines.size()) * charHeight), disassemblyTracedSelectionColor);
|
int(instr.text.lines.size()) * charHeight), disassemblyTracedSelectionColor);
|
||||||
} else if (selected) {
|
} else if (selected) {
|
||||||
p.fillRect(QRect(block.x + charWidth, y, block.width - (10 + 2 * charWidth),
|
p.fillRect(QRect(static_cast<int>(block.x + charWidth), y,
|
||||||
|
static_cast<int>(block.width - (10 + 2 * charWidth)),
|
||||||
int(instr.text.lines.size()) * charHeight), disassemblySelectionColor);
|
int(instr.text.lines.size()) * charHeight), disassemblySelectionColor);
|
||||||
} else if (traceCount) {
|
} else if (traceCount) {
|
||||||
// Color depending on how often a sequence of code is executed
|
// Color depending on how often a sequence of code is executed
|
||||||
@ -451,7 +452,8 @@ void DisassemblerGraphView::drawBlock(QPainter &p, GraphView::GraphBlock &block)
|
|||||||
if (disassemblyTracedColor.blue() > 160)
|
if (disassemblyTracedColor.blue() > 160)
|
||||||
colorDiff *= -1;
|
colorDiff *= -1;
|
||||||
|
|
||||||
p.fillRect(QRect(block.x + charWidth, y, block.width - (10 + 2 * charWidth),
|
p.fillRect(QRect(static_cast<int>(block.x + charWidth), y,
|
||||||
|
static_cast<int>(block.width - (10 + 2 * charWidth)),
|
||||||
int(instr.text.lines.size()) * charHeight),
|
int(instr.text.lines.size()) * charHeight),
|
||||||
QColor(disassemblyTracedColor.red(),
|
QColor(disassemblyTracedColor.red(),
|
||||||
disassemblyTracedColor.green(),
|
disassemblyTracedColor.green(),
|
||||||
@ -463,7 +465,7 @@ void DisassemblerGraphView::drawBlock(QPainter &p, GraphView::GraphBlock &block)
|
|||||||
|
|
||||||
// highlight selected tokens
|
// highlight selected tokens
|
||||||
if (highlight_token != nullptr) {
|
if (highlight_token != nullptr) {
|
||||||
int y = block.y + (2 * charWidth) + (db.header_text.lines.size() * charHeight);
|
int y = static_cast<int>(block.y + (2 * charWidth) + (db.header_text.lines.size() * charHeight));
|
||||||
int tokenWidth = mFontMetrics->width(highlight_token->content);
|
int tokenWidth = mFontMetrics->width(highlight_token->content);
|
||||||
|
|
||||||
for (const Instr &instr : db.instrs) {
|
for (const Instr &instr : db.instrs) {
|
||||||
@ -484,12 +486,12 @@ void DisassemblerGraphView::drawBlock(QPainter &p, GraphView::GraphBlock &block)
|
|||||||
|
|
||||||
int highlightWidth = tokenWidth;
|
int highlightWidth = tokenWidth;
|
||||||
if (charWidth * 3 + widthBefore + tokenWidth >= block.width - (10 + 2 * charWidth)) {
|
if (charWidth * 3 + widthBefore + tokenWidth >= block.width - (10 + 2 * charWidth)) {
|
||||||
highlightWidth = block.width - widthBefore - (10 + 4 * charWidth);
|
highlightWidth = static_cast<int>(block.width - widthBefore - (10 + 4 * charWidth));
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor selectionColor = ConfigColor("highlightWord");
|
QColor selectionColor = ConfigColor("highlightWord");
|
||||||
|
|
||||||
p.fillRect(QRect(block.x + charWidth * 3 + widthBefore, y, highlightWidth,
|
p.fillRect(QRect(static_cast<int>(block.x + charWidth * 3 + widthBefore), y, highlightWidth,
|
||||||
charHeight), selectionColor);
|
charHeight), selectionColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -499,14 +501,15 @@ void DisassemblerGraphView::drawBlock(QPainter &p, GraphView::GraphBlock &block)
|
|||||||
|
|
||||||
// highlight program counter
|
// highlight program counter
|
||||||
if (PCInBlock) {
|
if (PCInBlock) {
|
||||||
int y = block.y + (2 * charWidth) + (db.header_text.lines.size() * charHeight);
|
int y = static_cast<int>(block.y + (2 * charWidth) + (db.header_text.lines.size() * charHeight));
|
||||||
for (const Instr &instr : db.instrs) {
|
for (const Instr &instr : db.instrs) {
|
||||||
if (instr.addr > PCAddr) {
|
if (instr.addr > PCAddr) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
auto PC = instr.addr == PCAddr;
|
auto PC = instr.addr == PCAddr;
|
||||||
if (PC) {
|
if (PC) {
|
||||||
p.fillRect(QRect(block.x + charWidth, y, block.width - (10 + 2 * charWidth),
|
p.fillRect(QRect(static_cast<int>(block.x + charWidth), y,
|
||||||
|
static_cast<int>(block.width - (10 + 2 * charWidth)),
|
||||||
int(instr.text.lines.size()) * charHeight), PCSelectionColor);
|
int(instr.text.lines.size()) * charHeight), PCSelectionColor);
|
||||||
}
|
}
|
||||||
y += int(instr.text.lines.size()) * charHeight;
|
y += int(instr.text.lines.size()) * charHeight;
|
||||||
@ -515,17 +518,19 @@ void DisassemblerGraphView::drawBlock(QPainter &p, GraphView::GraphBlock &block)
|
|||||||
|
|
||||||
// Render node text
|
// Render node text
|
||||||
auto x = block.x + (2 * charWidth);
|
auto x = block.x + (2 * charWidth);
|
||||||
int y = block.y + (2 * charWidth);
|
int y = static_cast<int>(block.y + (2 * charWidth));
|
||||||
for (auto &line : db.header_text.lines) {
|
for (auto &line : db.header_text.lines) {
|
||||||
RichTextPainter::paintRichText(&p, x, y, block.width, charHeight, 0, line, mFontMetrics);
|
RichTextPainter::paintRichText(&p, static_cast<int>(x), y, block.width, charHeight, 0, line, mFontMetrics);
|
||||||
y += charHeight;
|
y += charHeight;
|
||||||
}
|
}
|
||||||
for (const Instr &instr : db.instrs) {
|
for (const Instr &instr : db.instrs) {
|
||||||
if (Core()->isBreakpoint(breakpoints, instr.addr)) {
|
if (Core()->isBreakpoint(breakpoints, instr.addr)) {
|
||||||
p.fillRect(QRect(block.x + charWidth, y, block.width - (10 + 2 * charWidth),
|
p.fillRect(QRect(static_cast<int>(block.x + charWidth), y,
|
||||||
|
static_cast<int>(block.width - (10 + 2 * charWidth)),
|
||||||
int(instr.text.lines.size()) * charHeight), ConfigColor("gui.breakpoint_background"));
|
int(instr.text.lines.size()) * charHeight), ConfigColor("gui.breakpoint_background"));
|
||||||
if (instr.addr == selected_instruction) {
|
if (instr.addr == selected_instruction) {
|
||||||
p.fillRect(QRect(block.x + charWidth, y, block.width - (10 + 2 * charWidth),
|
p.fillRect(QRect(static_cast<int>(block.x + charWidth), y,
|
||||||
|
static_cast<int>(block.width - (10 + 2 * charWidth)),
|
||||||
int(instr.text.lines.size()) * charHeight), disassemblySelectionColor);
|
int(instr.text.lines.size()) * charHeight), disassemblySelectionColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -535,11 +540,12 @@ void DisassemblerGraphView::drawBlock(QPainter &p, GraphView::GraphBlock &block)
|
|||||||
rectSize++;
|
rectSize++;
|
||||||
}
|
}
|
||||||
// Assume charWidth <= charHeight
|
// Assume charWidth <= charHeight
|
||||||
QRectF bpRect(x - rectSize / 3.0, y + (charHeight - rectSize) / 2.0, rectSize, rectSize);
|
|
||||||
|
|
||||||
// TODO: Breakpoint/Cip stuff
|
// TODO: Breakpoint/Cip stuff
|
||||||
|
QRectF bpRect(x - rectSize / 3.0, y + (charHeight - rectSize) / 2.0, rectSize, rectSize);
|
||||||
|
Q_UNUSED(bpRect);
|
||||||
|
|
||||||
RichTextPainter::paintRichText(&p, x + charWidth, y, block.width - charWidth, charHeight, 0, line,
|
RichTextPainter::paintRichText(&p, static_cast<int>(x + charWidth), y,
|
||||||
|
static_cast<int>(block.width - charWidth), charHeight, 0, line,
|
||||||
mFontMetrics);
|
mFontMetrics);
|
||||||
y += charHeight;
|
y += charHeight;
|
||||||
|
|
||||||
@ -570,12 +576,13 @@ RVA DisassemblerGraphView::getAddrForMouseEvent(GraphBlock &block, QPoint *point
|
|||||||
DisassemblyBlock &db = disassembly_blocks[block.entry];
|
DisassemblyBlock &db = disassembly_blocks[block.entry];
|
||||||
|
|
||||||
// Remove header and margin
|
// Remove header and margin
|
||||||
int off_y = (2 * charWidth) + (db.header_text.lines.size() * charHeight);
|
int off_y = static_cast<int>((2 * charWidth) + (db.header_text.lines.size() * charHeight));
|
||||||
|
|
||||||
// Get mouse coordinate over the actual text
|
// Get mouse coordinate over the actual text
|
||||||
int text_point_y = point->y() - off_y;
|
int text_point_y = point->y() - off_y;
|
||||||
int mouse_row = text_point_y / charHeight;
|
int mouse_row = text_point_y / charHeight;
|
||||||
|
|
||||||
int cur_row = db.header_text.lines.size();
|
int cur_row = static_cast<int>(db.header_text.lines.size());
|
||||||
if (mouse_row < cur_row) {
|
if (mouse_row < cur_row) {
|
||||||
return db.entry;
|
return db.entry;
|
||||||
}
|
}
|
||||||
@ -594,12 +601,13 @@ DisassemblerGraphView::Instr *DisassemblerGraphView::getInstrForMouseEvent(
|
|||||||
DisassemblyBlock &db = disassembly_blocks[block.entry];
|
DisassemblyBlock &db = disassembly_blocks[block.entry];
|
||||||
|
|
||||||
// Remove header and margin
|
// Remove header and margin
|
||||||
int off_y = (2 * charWidth) + (db.header_text.lines.size() * charHeight);
|
int off_y = static_cast<int>((2 * charWidth) + (db.header_text.lines.size() * charHeight));
|
||||||
|
|
||||||
// Get mouse coordinate over the actual text
|
// Get mouse coordinate over the actual text
|
||||||
int text_point_y = point->y() - off_y;
|
int text_point_y = point->y() - off_y;
|
||||||
int mouse_row = text_point_y / charHeight;
|
int mouse_row = text_point_y / charHeight;
|
||||||
|
|
||||||
int cur_row = db.header_text.lines.size();
|
int cur_row = static_cast<int>(db.header_text.lines.size());
|
||||||
|
|
||||||
for (Instr &instr : db.instrs) {
|
for (Instr &instr : db.instrs) {
|
||||||
if (mouse_row < cur_row + (int)instr.text.lines.size()) {
|
if (mouse_row < cur_row + (int)instr.text.lines.size()) {
|
||||||
@ -712,7 +720,7 @@ void DisassemblerGraphView::takeTrue()
|
|||||||
|
|
||||||
if (db->true_path != RVA_INVALID) {
|
if (db->true_path != RVA_INVALID) {
|
||||||
seekable->seek(db->true_path);
|
seekable->seek(db->true_path);
|
||||||
} else if (blocks[db->entry].exits.size()) {
|
} else if (!blocks[db->entry].exits.empty()) {
|
||||||
seekable->seek(blocks[db->entry].exits[0]);
|
seekable->seek(blocks[db->entry].exits[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -726,7 +734,7 @@ void DisassemblerGraphView::takeFalse()
|
|||||||
|
|
||||||
if (db->false_path != RVA_INVALID) {
|
if (db->false_path != RVA_INVALID) {
|
||||||
seekable->seek(db->false_path);
|
seekable->seek(db->false_path);
|
||||||
} else if (blocks[db->entry].exits.size()) {
|
} else if (!blocks[db->entry].exits.empty()) {
|
||||||
seekable->seek(blocks[db->entry].exits[0]);
|
seekable->seek(blocks[db->entry].exits[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -776,7 +784,7 @@ void DisassemblerGraphView::seekLocal(RVA addr, bool update_viewport)
|
|||||||
|
|
||||||
DisassemblerGraphView::Token *DisassemblerGraphView::getToken(Instr *instr, int x)
|
DisassemblerGraphView::Token *DisassemblerGraphView::getToken(Instr *instr, int x)
|
||||||
{
|
{
|
||||||
x -= (3 * charWidth); // Ignore left margin
|
x -= (int) (3 * charWidth); // Ignore left margin
|
||||||
if (x < 0) {
|
if (x < 0) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -786,14 +794,14 @@ DisassemblerGraphView::Token *DisassemblerGraphView::getToken(Instr *instr, int
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const QRegularExpression tokenRegExp("\\b(?<!\\.)([^\\s]+)\\b(?!\\.)");
|
static const QRegularExpression tokenRegExp(R"(\b(?<!\.)([^\s]+)\b(?!\.))");
|
||||||
QRegularExpressionMatchIterator i = tokenRegExp.globalMatch(instr->plainText);
|
QRegularExpressionMatchIterator i = tokenRegExp.globalMatch(instr->plainText);
|
||||||
|
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
QRegularExpressionMatch match = i.next();
|
QRegularExpressionMatch match = i.next();
|
||||||
|
|
||||||
if (match.capturedStart() <= clickedCharPos && match.capturedEnd() > clickedCharPos) {
|
if (match.capturedStart() <= clickedCharPos && match.capturedEnd() > clickedCharPos) {
|
||||||
Token *t = new Token;
|
auto t = new Token;
|
||||||
t->start = match.capturedStart();
|
t->start = match.capturedStart();
|
||||||
t->length = match.capturedLength();
|
t->length = match.capturedLength();
|
||||||
t->content = match.captured();
|
t->content = match.captured();
|
||||||
|
@ -53,8 +53,8 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct GraphBlock {
|
struct GraphBlock {
|
||||||
qreal x = 0.0;
|
int x = 0;
|
||||||
qreal y = 0.0;
|
int y = 0;
|
||||||
int width = 0;
|
int width = 0;
|
||||||
int height = 0;
|
int height = 0;
|
||||||
// This is a unique identifier, e.g. offset in the case of r2 blocks
|
// This is a unique identifier, e.g. offset in the case of r2 blocks
|
||||||
@ -86,8 +86,8 @@ public:
|
|||||||
bool end_arrow = true;
|
bool end_arrow = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
GraphView(QWidget *parent);
|
explicit GraphView(QWidget *parent);
|
||||||
~GraphView();
|
~GraphView() override;
|
||||||
void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
|
|
||||||
// Show a block centered. Animates to it if animated=true
|
// Show a block centered. Animates to it if animated=true
|
||||||
|
Loading…
Reference in New Issue
Block a user