From 2d05ae259569cf6d4f13fdf1c5ae70449e48887a Mon Sep 17 00:00:00 2001 From: GustavoLCR Date: Thu, 12 Aug 2021 18:28:10 -0300 Subject: [PATCH] Fixes for debugging (#2727) * Fix continue until main not being enabled * Use Rizin API instead of commands * Fix attaching to a process with no file opened --- src/core/Cutter.cpp | 4 +++- src/widgets/DebugActions.cpp | 17 ++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/core/Cutter.cpp b/src/core/Cutter.cpp index 12d50fce..f6dbcda6 100644 --- a/src/core/Cutter.cpp +++ b/src/core/Cutter.cpp @@ -1957,8 +1957,10 @@ void CutterCore::attachDebug(int pid) offsetPriorDebugging = getOffset(); } + QString attach_command = currentlyOpenFile.isEmpty() ? "o" : "oodf"; // attach to process with dbg plugin - asyncCmd("e cfg.debug = true; oodf dbg://" + QString::number(pid), debugTask); + asyncCmd("e cfg.debug=true;" + attach_command + " dbg://" + QString::number(pid), debugTask); + emit debugTaskStateChanged(); connect(debugTask.data(), &RizinTask::finished, this, [this, pid]() { diff --git a/src/widgets/DebugActions.cpp b/src/widgets/DebugActions.cpp index cf0b6e74..3ed1b877 100644 --- a/src/widgets/DebugActions.cpp +++ b/src/widgets/DebugActions.cpp @@ -249,10 +249,10 @@ DebugActions::DebugActions(QToolBar *toolBar, MainWindow *main) : QObject(main), void DebugActions::setButtonVisibleIfMainExists() { - // Use cmd because cmdRaw would not handle multiple commands concatenated - int mainExists = Core()->cmd("f?sym.main; ??").toInt(); + RzCoreLocked core(Core()->core()); // if main is not a flag we hide the continue until main button - if (!mainExists) { + if (!rz_flag_get(Core()->core()->flags, "sym.main") + && !rz_flag_get(Core()->core()->flags, "main")) { actionContinueUntilMain->setVisible(false); continueUntilButton->setDefaultAction(actionContinueUntilCall); } @@ -273,8 +273,15 @@ void DebugActions::showDebugWarning() void DebugActions::continueUntilMain() { - QString mainAddr = Core()->cmdRaw("?v sym.main"); - Core()->continueUntilDebug(mainAddr); + RzCoreLocked core(Core()->core()); + RzFlagItem *main_flag = rz_flag_get(Core()->core()->flags, "sym.main"); + if (!main_flag) { + main_flag = rz_flag_get(Core()->core()->flags, "main"); + if (!main_flag) { + return; + } + } + Core()->continueUntilDebug(QString::number(main_flag->offset)); } void DebugActions::attachRemoteDebugger()