Skip to content

Commit 68ec5a3

Browse files
XVilkawargio
andauthored
Fix attaching debugger (rizinorg#3139)
* Fix attaching debugger * Fix deadlock on attach Co-authored-by: wargio <[email protected]>
1 parent c685987 commit 68ec5a3

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

src/core/Cutter.cpp

+21-11
Original file line numberDiff line numberDiff line change
@@ -2075,16 +2075,23 @@ void CutterCore::attachDebug(int pid)
20752075
offsetPriorDebugging = getOffset();
20762076
}
20772077

2078-
CORE_LOCK();
2079-
setConfig("cfg.debug", true);
2080-
auto uri = rz_str_newf("dbg://%d", pid);
2081-
if (currentlyOpenFile.isEmpty()) {
2082-
rz_core_file_open_load(core, uri, 0, RZ_PERM_R, false);
2083-
} else {
2084-
rz_core_file_reopen_remote_debug(core, uri, 0);
2078+
if (!asyncTask(
2079+
[&](RzCore *core) {
2080+
// cannot use setConfig because core is
2081+
// already locked, which causes a deadlock
2082+
rz_config_set_b(core->config, "cfg.debug", true);
2083+
auto uri = rz_str_newf("dbg://%d", pid);
2084+
if (currentlyOpenFile.isEmpty()) {
2085+
rz_core_file_open_load(core, uri, 0, RZ_PERM_R, false);
2086+
} else {
2087+
rz_core_file_reopen_remote_debug(core, uri, 0);
2088+
}
2089+
free(uri);
2090+
return nullptr;
2091+
},
2092+
debugTask)) {
2093+
return;
20852094
}
2086-
free(uri);
2087-
20882095
emit debugTaskStateChanged();
20892096

20902097
connect(debugTask.data(), &RizinTask::finished, this, [this, pid]() {
@@ -2144,7 +2151,10 @@ void CutterCore::stopDebug()
21442151
rz_core_analysis_esil_trace_stop(core);
21452152
currentlyEmulating = false;
21462153
} else {
2147-
rz_core_debug_process_close(core);
2154+
// ensure we have opened a file.
2155+
if (core->io->desc) {
2156+
rz_core_debug_process_close(core);
2157+
}
21482158
currentlyAttachedToPID = -1;
21492159
}
21502160

@@ -4579,4 +4589,4 @@ void CutterCore::writeGraphvizGraphToFile(QString path, QString format, RzCoreGr
45794589
qWarning() << "Cannot get graph at " << RzAddressString(address);
45804590
}
45814591
}
4582-
}
4592+
}

0 commit comments

Comments
 (0)