convert to api for dr

This commit is contained in:
billow 2022-05-14 19:13:45 +08:00 committed by Anton Kochkov
parent d6ce8048c5
commit c0f80a2628
4 changed files with 55 additions and 47 deletions

View File

@ -127,6 +127,11 @@ static QString fromOwnedCharPtr(char *str)
return result; return result;
} }
static bool reg_sync(RzCore *core, RzRegisterType type, bool write)
{
return rz_debug_reg_sync(core->dbg, type, write);
}
RzCoreLocked::RzCoreLocked(CutterCore *core) : core(core) RzCoreLocked::RzCoreLocked(CutterCore *core) : core(core)
{ {
core->coreMutex.lock(); core->coreMutex.lock();
@ -1376,11 +1381,6 @@ void CutterCore::createFunctionAt(RVA addr, QString name)
emit functionsChanged(); emit functionsChanged();
} }
CutterJson CutterCore::getRegistersInfo()
{
return cmdj("aeafj");
}
RVA CutterCore::getOffsetJump(RVA addr) RVA CutterCore::getOffsetJump(RVA addr)
{ {
auto rva = (RVA *)Core()->returnAtSeek( auto rva = (RVA *)Core()->returnAtSeek(
@ -1448,20 +1448,20 @@ static inline const QString appendVar(QString &dst, const QString val, const QSt
return val; return val;
} }
RefDescription CutterCore::formatRefDesc(const AddrRefs &refItem) RefDescription CutterCore::formatRefDesc(const QSharedPointer<AddrRefs> &refItem)
{ {
RefDescription desc; RefDescription desc;
if (refItem.addr == RVA_INVALID) { if (refItem->addr == RVA_INVALID) {
return desc; return desc;
} }
QString str = refItem.string; QString str = refItem->string;
if (!str.isEmpty()) { if (!str.isEmpty()) {
desc.ref = str; desc.ref = str;
desc.refColor = ConfigColor("comment"); desc.refColor = ConfigColor("comment");
} else { } else {
QSharedPointer<const AddrRefs> cursor(&refItem); QSharedPointer<const AddrRefs> cursor(refItem);
QString type, string; QString type, string;
while (true) { while (true) {
desc.ref += " ->"; desc.ref += " ->";
@ -1508,15 +1508,21 @@ QList<RegisterRef> CutterCore::getRegisterRefs(int depth)
return ret; return ret;
} }
CutterJson registers = cmdj("drj"); CORE_LOCK();
for (CutterJson value : registers) { RzList *ritems = rz_core_reg_filter_items_sync(core, core->dbg->reg, reg_sync, nullptr);
if (!ritems) {
return ret;
}
RzListIter *it;
RzRegItem *ri;
CutterRzListForeach (ritems, it, RzRegItem, ri) {
RegisterRef reg; RegisterRef reg;
reg.value = value.toUt64(); reg.value = rz_reg_get_value(core->dbg->reg, ri);
reg.ref = getAddrRefs(reg.value, depth); reg.ref = getAddrRefs(reg.value, depth);
reg.name = value.key(); reg.name = ri->name;
ret.append(reg); ret.append(reg);
} }
rz_list_free(ritems);
return ret; return ret;
} }
@ -1528,9 +1534,8 @@ QList<AddrRefs> CutterCore::getStack(int size, int depth)
} }
CORE_LOCK(); CORE_LOCK();
bool ret; RVA addr = rz_debug_reg_get(core->dbg, "SP");
RVA addr = cmdRaw("dr SP").toULongLong(&ret, 16); if (addr == RVA_INVALID) {
if (!ret) {
return stack; return stack;
} }
@ -1793,11 +1798,6 @@ bool CutterCore::writeHeapChunk(RzHeapChunkSimple *chunk_simple)
return rz_heap_write_chunk(core, chunk_simple); return rz_heap_write_chunk(core, chunk_simple);
} }
CutterJson CutterCore::getRegisterValues()
{
return cmdj("drj");
}
QList<VariableDescription> CutterCore::getVariables(RVA at) QList<VariableDescription> CutterCore::getVariables(RVA at)
{ {
QList<VariableDescription> ret; QList<VariableDescription> ret;
@ -1837,42 +1837,52 @@ QList<VariableDescription> CutterCore::getVariables(RVA at)
QVector<RegisterRefValueDescription> CutterCore::getRegisterRefValues() QVector<RegisterRefValueDescription> CutterCore::getRegisterRefValues()
{ {
CutterJson registerRefArray = cmdj("drrj");
QVector<RegisterRefValueDescription> result; QVector<RegisterRefValueDescription> result;
CORE_LOCK();
for (CutterJson regRefObject : registerRefArray) { RzList *ritems = rz_core_reg_filter_items_sync(core, core->dbg->reg, reg_sync, nullptr);
if (!ritems) {
return result;
}
RzListIter *it;
RzRegItem *ri;
CutterRzListForeach (ritems, it, RzRegItem, ri) {
RegisterRefValueDescription desc; RegisterRefValueDescription desc;
desc.name = regRefObject[RJsonKey::reg].toString(); desc.name = ri->name;
desc.value = regRefObject[RJsonKey::value].toString(); ut64 value = rz_reg_get_value(core->dbg->reg, ri);
desc.ref = regRefObject[RJsonKey::ref].toString(); desc.value = QString::number(value);
desc.ref = rz_core_analysis_hasrefs(core, value, true);
result.push_back(desc); result.push_back(desc);
} }
rz_list_free(ritems);
return result; return result;
} }
QString CutterCore::getRegisterName(QString registerRole) QString CutterCore::getRegisterName(QString registerRole)
{ {
return cmdRaw("drn " + registerRole).trimmed(); if (!currentlyDebugging) {
return "";
}
CORE_LOCK();
return rz_reg_get_name_by_type(core->dbg->reg, registerRole.toUtf8().constData());
} }
RVA CutterCore::getProgramCounterValue() RVA CutterCore::getProgramCounterValue()
{ {
bool ok;
if (currentlyDebugging) { if (currentlyDebugging) {
// Use cmd because cmdRaw would not work with inner command backticked CORE_LOCK();
// TODO: Risky command due to changes in API, search for something safer return rz_debug_reg_get(core->dbg, "PC");
RVA addr = cmd("dr `drn PC`").toULongLong(&ok, 16);
if (ok) {
return addr;
}
} }
return RVA_INVALID; return RVA_INVALID;
} }
void CutterCore::setRegister(QString regName, QString regValue) void CutterCore::setRegister(QString regName, QString regValue)
{ {
cmdRaw(QString("dr %1=%2").arg(regName).arg(regValue)); if (!currentlyDebugging) {
return;
}
CORE_LOCK();
ut64 val = rz_num_math(core->num, regValue.toUtf8().constData());
rz_core_reg_assign_sync(core, core->dbg->reg, reg_sync, regName.toUtf8().constData(), val);
emit registersChanged(); emit registersChanged();
emit refreshCodeViews(); emit refreshCodeViews();
} }
@ -1940,7 +1950,7 @@ void CutterCore::startDebug()
if (!asyncTask( if (!asyncTask(
[](RzCore *core) { [](RzCore *core) {
rz_core_file_reopen_debug(core, ""); rz_core_file_reopen_debug(core, "");
return (void *)NULL; return (void *)nullptr;
}, },
debugTask)) { debugTask)) {
return; return;
@ -1949,9 +1959,7 @@ void CutterCore::startDebug()
emit debugTaskStateChanged(); emit debugTaskStateChanged();
connect(debugTask.data(), &RizinTask::finished, this, [this]() { connect(debugTask.data(), &RizinTask::finished, this, [this]() {
if (debugTaskDialog) { delete debugTaskDialog;
delete debugTaskDialog;
}
debugTask.clear(); debugTask.clear();
emit registersChanged(); emit registersChanged();

View File

@ -417,8 +417,6 @@ public:
bool sdbSet(QString path, QString key, QString val); bool sdbSet(QString path, QString key, QString val);
/* Debug */ /* Debug */
CutterJson getRegistersInfo();
CutterJson getRegisterValues();
QString getRegisterName(QString registerRole); QString getRegisterName(QString registerRole);
RVA getProgramCounterValue(); RVA getProgramCounterValue();
void setRegister(QString regName, QString regValue); void setRegister(QString regName, QString regValue);
@ -444,7 +442,7 @@ public:
* @brief return a RefDescription with a formatted ref string and configured colors * @brief return a RefDescription with a formatted ref string and configured colors
* @param ref the "ref" JSON node from getAddrRefs * @param ref the "ref" JSON node from getAddrRefs
*/ */
RefDescription formatRefDesc(const AddrRefs &ref); RefDescription formatRefDesc(const QSharedPointer<AddrRefs> &ref);
/** /**
* @brief Get a list of a given process's threads * @brief Get a list of a given process's threads
* @param pid The pid of the process, -1 for the currently debugged process * @param pid The pid of the process, -1 for the currently debugged process

View File

@ -190,7 +190,7 @@ void RegisterRefsWidget::refreshRegisterRef()
desc.value = RzAddressString(reg.value); desc.value = RzAddressString(reg.value);
desc.reg = reg.name; desc.reg = reg.name;
desc.refDesc = Core()->formatRefDesc(reg.ref); desc.refDesc = Core()->formatRefDesc(QSharedPointer<AddrRefs>::create(reg.ref));
registerRefs.push_back(desc); registerRefs.push_back(desc);
} }

View File

@ -154,7 +154,9 @@ void StackModel::reload()
item.offset = stackItem.addr; item.offset = stackItem.addr;
item.value = RzAddressString(stackItem.value); item.value = RzAddressString(stackItem.value);
item.refDesc = Core()->formatRefDesc(*stackItem.ref); if (!stackItem.ref.isNull()) {
item.refDesc = Core()->formatRefDesc(stackItem.ref);
}
values.push_back(item); values.push_back(item);
} }