From ad22697ae2fb9ee210af8f8d125db140fe7bc5a6 Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Mon, 4 Apr 2022 20:33:04 +0200 Subject: [PATCH] Disable software breakpoints while dumping Closes #1 --- src/plugin.cpp | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/plugin.cpp b/src/plugin.cpp index 032501e..76f88b0 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -41,6 +41,25 @@ static bool cbMiniDump(int argc, char* argv[]) return false; } + // Disable all software breakpoints + std::vector disabled_breakpoints; + { + BPMAP bplist; + DbgGetBpList(bp_normal, &bplist); + for (int i = 0; i < bplist.count; i++) + { + const auto& bp = bplist.bp[i]; + if (bp.active && bp.enabled) + { + char cmd[256] = ""; + sprintf_s(cmd, "bd 0x%p", bp.addr); + if (DbgCmdExecDirect(cmd)) + disabled_breakpoints.push_back(bp.addr); + } + } + BridgeFree(bplist.bp); + } + CONTEXT context = {}; context.ContextFlags = CONTEXT_ALL; GetThreadContext(DbgGetThreadHandle(), &context); @@ -65,7 +84,17 @@ static bool cbMiniDump(int argc, char* argv[]) exceptionInfo.ExceptionPointers = &exceptionPointers; exceptionInfo.ClientPointers = FALSE; auto dumpType = MINIDUMP_TYPE(MiniDumpWithFullMemory | MiniDumpWithFullMemoryInfo | MiniDumpIgnoreInaccessibleMemory); - if (MiniDumpWriteDump(DbgGetProcessHandle(), DbgGetProcessId(), hFile, dumpType, &exceptionInfo, nullptr, nullptr)) + auto dumpSaved = !!MiniDumpWriteDump(DbgGetProcessHandle(), DbgGetProcessId(), hFile, dumpType, &exceptionInfo, nullptr, nullptr); + + // Re-enable all breakpoints that were previously disabled + for (auto addr : disabled_breakpoints) + { + char cmd[256] = ""; + sprintf_s(cmd, "be 0x%p", addr); + DbgCmdExecDirect(cmd); + } + + if (dumpSaved) { dputs("Dump saved!"); }