diff --git a/src/core/Cutter.cpp b/src/core/Cutter.cpp index a13aada2..7c7b0985 100644 --- a/src/core/Cutter.cpp +++ b/src/core/Cutter.cpp @@ -1123,6 +1123,7 @@ void CutterCore::startDebug() if (!currentlyDebugging) { offsetPriorDebugging = getOffset(); } + currentlyOpenFile = getConfig("file.path"); cmd("ood"); emit registersChanged(); if (!currentlyDebugging) { @@ -1141,8 +1142,7 @@ void CutterCore::startEmulation() offsetPriorDebugging = getOffset(); } // clear registers, init esil state, stack, progcounter at current seek - cmd("ar0; aei; aeim; aeip"); - emit registersChanged(); + cmd("aei; aeim; aeip"); if (!currentlyDebugging || !currentlyEmulating) { // prevent register flags from appearing during debug/emul setConfig("asm.flags", false); @@ -1153,6 +1153,7 @@ void CutterCore::startEmulation() emit changeDebugView(); emit flagsChanged(); } + emit registersChanged(); emit stackChanged(); emit refreshCodeViews(); } @@ -1188,7 +1189,16 @@ void CutterCore::stopDebug() cmd(QString("dp- %1; o %2; .ar-").arg(QString::number(currentlyAttachedToPID), currentlyOpenFile)); currentlyAttachedToPID = -1; } else { - cmd("dk 9; oo; .ar-"); + cmd(QString("dk 9; e cfg.debug=false; o %1; .ar-").arg(currentlyOpenFile)); + // close ptrace file descriptors left open + QJsonArray openFilesArray = cmdj("oj").array();; + for (QJsonValue value : openFilesArray) { + QJsonObject openFile = value.toObject(); + QString URI = openFile["uri"].toString(); + if (URI.contains("ptrace")) { + cmd("o-" + QString::number(openFile["fd"].toInt())); + } + } } seekAndShow(offsetPriorDebugging); setConfig("asm.flags", true); @@ -1199,6 +1209,13 @@ void CutterCore::stopDebug() } } +void CutterCore::syncAndSeekProgramCounter() +{ + QString programCounterValue = cmd("dr?`drn PC`").trimmed(); + seekAndShow(programCounterValue); + emit registersChanged(); +} + void CutterCore::continueDebug() { if (currentlyDebugging) { @@ -1221,6 +1238,7 @@ void CutterCore::continueUntilDebug(QString offset) cmd("dcu " + offset); } emit registersChanged(); + emit stackChanged(); emit refreshCodeViews(); } } @@ -1233,9 +1251,7 @@ void CutterCore::continueUntilCall() } else { cmd("dcc"); } - QString programCounterValue = cmd("dr?`drn PC`").trimmed(); - seekAndShow(programCounterValue); - emit registersChanged(); + syncAndSeekProgramCounter(); } } @@ -1247,29 +1263,31 @@ void CutterCore::continueUntilSyscall() } else { cmd("dcs"); } - QString programCounterValue = cmd("dr?`drn PC`").trimmed(); - seekAndShow(programCounterValue); - emit registersChanged(); + syncAndSeekProgramCounter(); } } void CutterCore::stepDebug() { if (currentlyDebugging) { - cmdEsil("ds"); - QString programCounterValue = cmd("dr?`drn PC`").trimmed(); - seekAndShow(programCounterValue); - emit registersChanged(); + if (currentlyEmulating) { + cmdEsil("aes"); + } else { + cmd("ds"); + } + syncAndSeekProgramCounter(); } } void CutterCore::stepOverDebug() { if (currentlyDebugging) { - cmdEsil("dso"); - QString programCounterValue = cmd("dr?`drn PC`").trimmed(); - seekAndShow(programCounterValue); - emit registersChanged(); + if (currentlyEmulating) { + cmdEsil("aeso"); + } else { + cmd("dso"); + } + syncAndSeekProgramCounter(); } } @@ -1277,9 +1295,7 @@ void CutterCore::stepOutDebug() { if (currentlyDebugging) { cmd("dsf"); - QString programCounterValue = cmd("dr?`drn PC`").trimmed(); - seekAndShow(programCounterValue); - emit registersChanged(); + syncAndSeekProgramCounter(); } } diff --git a/src/core/Cutter.h b/src/core/Cutter.h index 656aee09..72c2766a 100644 --- a/src/core/Cutter.h +++ b/src/core/Cutter.h @@ -227,6 +227,7 @@ public: void startEmulation(); void attachDebug(int pid); void stopDebug(); + void syncAndSeekProgramCounter(); void continueDebug(); void continueUntilCall(); void continueUntilSyscall(); diff --git a/src/widgets/MemoryMapWidget.cpp b/src/widgets/MemoryMapWidget.cpp index 389b4458..039aeef6 100644 --- a/src/widgets/MemoryMapWidget.cpp +++ b/src/widgets/MemoryMapWidget.cpp @@ -139,6 +139,9 @@ void MemoryMapWidget::refreshMemoryMap() return; } + if (Core()->currentlyEmulating) { + return; + } memoryModel->beginResetModel(); memoryMaps = Core()->getMemoryMap(); memoryModel->endResetModel();