Skip to content

Commit

Permalink
Show disassembly var tooltips (#3206)
Browse files Browse the repository at this point in the history
  • Loading branch information
frmdstryr authored Jul 30, 2023
1 parent d1da807 commit 7418f9c
Show file tree
Hide file tree
Showing 12 changed files with 289 additions and 150 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,7 @@ docs/source/_build
# Local gdb files
.gdb_history
.gdbinit

# Kdevelop
.kdev/
*.kdev4
10 changes: 10 additions & 0 deletions src/common/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,16 @@ bool Configuration::getPreviewValue() const
return s.value("asm.preview").toBool();
}

void Configuration::setShowVarTooltips(bool enabled)
{
s.setValue("showVarTooltips", enabled);
}

bool Configuration::getShowVarTooltips() const
{
return s.value("showVarTooltips").toBool();
}

bool Configuration::getGraphBlockEntryOffset()
{
return s.value("graphBlockEntryOffset", true).value<bool>();
Expand Down
6 changes: 6 additions & 0 deletions src/common/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ class CUTTER_EXPORT Configuration : public QObject
void setPreviewValue(bool checked);
bool getPreviewValue() const;

/**
* @brief Show tooltips for known values of registers, variables, and memory when debugging
*/
void setShowVarTooltips(bool enabled);
bool getShowVarTooltips() const;

/**
* @brief Recently opened binaries, as shown in NewFileDialog.
*/
Expand Down
72 changes: 72 additions & 0 deletions src/common/DisassemblyPreview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,75 @@ RVA DisassemblyPreview::readDisassemblyOffset(QTextCursor tc)

return userData->line.offset;
}

typedef struct mmio_lookup_context
{
QString selected;
RVA mmio_address;
} mmio_lookup_context_t;

static bool lookup_mmio_addr_cb(void *user, const ut64 key, const void *value)
{
mmio_lookup_context_t *ctx = (mmio_lookup_context_t *)user;
if (ctx->selected == (const char *)value) {
ctx->mmio_address = key;
return false;
}
return true;
}

bool DisassemblyPreview::showDebugValueTooltip(QWidget *parent, const QPoint &pointOfEvent,
const QString &selectedText, const RVA offset)
{
if (selectedText.isEmpty())
return false;

if (selectedText.at(0).isLetter()) {
{
const auto registerRefs = Core()->getRegisterRefValues();
for (auto &reg : registerRefs) {
if (reg.name == selectedText) {
auto msg = QString("reg %1 = %2").arg(reg.name, reg.value);
QToolTip::showText(pointOfEvent, msg, parent);
return true;
}
}
}

if (offset != RVA_INVALID) {
auto vars = Core()->getVariables(offset);
for (auto &var : vars) {
if (var.name == selectedText) {
auto msg = QString("var %1 = %2").arg(var.name, var.value);
QToolTip::showText(pointOfEvent, msg, parent);
return true;
}
}
}

{
// Lookup MMIO address
mmio_lookup_context_t ctx;
ctx.selected = selectedText;
ctx.mmio_address = RVA_INVALID;
auto core = Core()->core();
RzPlatformTarget *arch_target = core->analysis->arch_target;
if (arch_target && arch_target->profile) {
ht_up_foreach(arch_target->profile->registers_mmio, lookup_mmio_addr_cb, &ctx);
}
if (ctx.mmio_address != RVA_INVALID) {
int len = 8; // TODO: Determine proper len of mmio address for the cpu
if (char *r = rz_core_print_hexdump_or_hexdiff_str(core, RZ_OUTPUT_MODE_STANDARD,
ctx.mmio_address, len, false)) {
auto val = QString::fromUtf8(r).trimmed().split("\n").last();
auto msg = QString("mmio %1 %2").arg(selectedText, val);
free(r);
QToolTip::showText(pointOfEvent, msg, parent);
return true;
}
}
}
}
// Else show preview for value?
return false;
}
8 changes: 8 additions & 0 deletions src/common/DisassemblyPreview.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,13 @@ bool showDisasPreview(QWidget *parent, const QPoint &pointOfEvent, const RVA off
* @return The disassembly offset of the hovered asm text
*/
RVA readDisassemblyOffset(QTextCursor tc);

/**
* @brief Show a QToolTip that shows the value of the highlighted register, variable, or memory
* @return True if the tooltip is shown
*/
bool showDebugValueTooltip(QWidget *parent, const QPoint &pointOfEvent, const QString &selectedText,
const RVA offset);

}
#endif
6 changes: 6 additions & 0 deletions src/core/Cutter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1804,6 +1804,12 @@ QList<VariableDescription> CutterCore::getVariables(RVA at)
}
desc.type = QString::fromUtf8(tn);
rz_mem_free(tn);

if (char *v = rz_core_analysis_var_display(core, var, false)) {
desc.value = QString::fromUtf8(v).trimmed();
rz_mem_free(v);
}

ret.push_back(desc);
}
return ret;
Expand Down
1 change: 1 addition & 0 deletions src/core/CutterDescriptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ struct VariableDescription
RzAnalysisVarStorageType storageType;
QString name;
QString type;
QString value;
};

struct RegisterRefValueDescription
Expand Down
8 changes: 8 additions & 0 deletions src/dialogs/preferences/AsmOptionsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ AsmOptionsWidget::AsmOptionsWidget(PreferencesDialog *dialog)
&AsmOptionsWidget::relOffCheckBoxToggled);
connect(Core(), &CutterCore::asmOptionsChanged, this,
&AsmOptionsWidget::updateAsmOptionsFromVars);

connect(ui->varTooltipsCheckBox, &QCheckBox::toggled, [this](bool checked) {
Config()->setShowVarTooltips(checked);
triggerAsmOptionsChanged();
});

updateAsmOptionsFromVars();
}

Expand Down Expand Up @@ -138,6 +144,8 @@ void AsmOptionsWidget::updateAsmOptionsFromVars()
ui->previewCheckBox->setChecked(Config()->getPreviewValue());
ui->previewCheckBox->blockSignals(false);

qhelpers::setCheckedWithoutSignals(ui->varTooltipsCheckBox, Config()->getShowVarTooltips());

QList<ConfigCheckbox>::iterator confCheckbox;

// Set the value for each checkbox in "checkboxes" as it exists in the configuration
Expand Down
Loading

0 comments on commit 7418f9c

Please sign in to comment.