Skip to content

Commit

Permalink
Disable software breakpoints while dumping
Browse files Browse the repository at this point in the history
Closes #1
  • Loading branch information
mrexodia committed Apr 4, 2022
1 parent fb6266d commit ad22697
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,25 @@ static bool cbMiniDump(int argc, char* argv[])
return false;
}

// Disable all software breakpoints
std::vector<duint> 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);
Expand All @@ -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!");
}
Expand Down

0 comments on commit ad22697

Please sign in to comment.