From 68ec5a3da18ee8f281b2926a037ba40ac2d1dab5 Mon Sep 17 00:00:00 2001 From: Anton Kochkov Date: Wed, 22 Feb 2023 23:09:24 +0800 Subject: [PATCH] Fix attaching debugger (#3139) * Fix attaching debugger * Fix deadlock on attach Co-authored-by: wargio --- src/core/Cutter.cpp | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/core/Cutter.cpp b/src/core/Cutter.cpp index dad33c8e..7a18898c 100644 --- a/src/core/Cutter.cpp +++ b/src/core/Cutter.cpp @@ -2075,16 +2075,23 @@ void CutterCore::attachDebug(int pid) offsetPriorDebugging = getOffset(); } - CORE_LOCK(); - setConfig("cfg.debug", true); - auto uri = rz_str_newf("dbg://%d", pid); - if (currentlyOpenFile.isEmpty()) { - rz_core_file_open_load(core, uri, 0, RZ_PERM_R, false); - } else { - rz_core_file_reopen_remote_debug(core, uri, 0); + if (!asyncTask( + [&](RzCore *core) { + // cannot use setConfig because core is + // already locked, which causes a deadlock + rz_config_set_b(core->config, "cfg.debug", true); + auto uri = rz_str_newf("dbg://%d", pid); + if (currentlyOpenFile.isEmpty()) { + rz_core_file_open_load(core, uri, 0, RZ_PERM_R, false); + } else { + rz_core_file_reopen_remote_debug(core, uri, 0); + } + free(uri); + return nullptr; + }, + debugTask)) { + return; } - free(uri); - emit debugTaskStateChanged(); connect(debugTask.data(), &RizinTask::finished, this, [this, pid]() { @@ -2144,7 +2151,10 @@ void CutterCore::stopDebug() rz_core_analysis_esil_trace_stop(core); currentlyEmulating = false; } else { - rz_core_debug_process_close(core); + // ensure we have opened a file. + if (core->io->desc) { + rz_core_debug_process_close(core); + } currentlyAttachedToPID = -1; } @@ -4579,4 +4589,4 @@ void CutterCore::writeGraphvizGraphToFile(QString path, QString format, RzCoreGr qWarning() << "Cannot get graph at " << RzAddressString(address); } } -} \ No newline at end of file +}