Skip to content

Commit

Permalink
Don't WaitForEvent when using IDebugControl::Execute (#221)
Browse files Browse the repository at this point in the history
Don't `WaitForEvent` when calling `IDebugControl::Execute` as it doesn't
seem required. Calling it caused an error which seemed to prevent `GetSymbolByName`
to work (it would return a catastrophic error).
  • Loading branch information
0vercl0k authored Jan 7, 2025
1 parent 1397403 commit 4988d42
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/wtf/debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,16 @@ class WindowsDebugger_t : public Debugger_t {
//
// Turn the below on to debug issues.
//

// #define SYMOPT_DEBUG 0x80000000
// Status = Symbols_->SetSymbolOptions(SYMOPT_DEBUG);
// if (FAILED(Status)) {
// fmt::print("IDebugSymbols::SetSymbolOptions failed with
// hr={:#x}\n", Status); return false;
// }
// Client_->SetOutputCallbacks(&StdioCallbacks_);
#if 0
const uint32_t SYMOPT_DEBUG = 0x80'00'00'00;
Status = Symbols_->SetSymbolOptions(SYMOPT_DEBUG);
if (FAILED(Status)) {
fmt::print("IDebugSymbols::SetSymbolOptions failed with hr={:#x}\n ",
Status);
return false;
}
Client_->SetOutputCallbacks(&StdioCallbacks_);
#endif

const std::string &DumpFileString = DumpPath.string();
const char *DumpFileA = DumpFileString.c_str();
Expand All @@ -275,13 +277,15 @@ class WindowsDebugger_t : public Debugger_t {
return false;
}

//
// Note The engine doesn't completely attach to the dump file until the
// WaitForEvent method has been called. When a dump file is created from a
// process or kernel, information about the last event is stored in the
// dump file. After the dump file is opened, the next time execution is
// attempted, the engine will generate this event for the event callbacks.
// Only then does the dump file become available in the debugging session.
// https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/dbgeng/nf-dbgeng-idebugclient-opendumpfile
//

Status = WaitForEvent();
if (FAILED(Status)) {
Expand All @@ -290,16 +294,20 @@ class WindowsDebugger_t : public Debugger_t {
return false;
}

// XXX: Figure out whats wrong.
// Execute("? ucrtbase");
//
// To debug what might be wrong with the debugger, you can execute command
// with `Execute` like below.
//

// Execute("? ucrtbase");
// Execute("? nt!SwapContext");
return true;
}

[[nodiscard]] HRESULT WaitForEvent() const {
const HRESULT Status = Control_->WaitForEvent(DEBUG_WAIT_DEFAULT, INFINITE);
if (FAILED(Status)) {
fmt::print("Execute::WaitForEvent failed with {:#x}\n", Status);
fmt::print("IDebugControl::WaitForEvent failed with {:#x}\n", Status);
}
return Status;
}
Expand All @@ -310,10 +318,9 @@ class WindowsDebugger_t : public Debugger_t {
Str, DEBUG_EXECUTE_NOT_LOGGED);
if (FAILED(Status)) {
fmt::print("IDebugControl::Execute failed with {:#x}\n", Status);
return Status;
}

return WaitForEvent();
return Status;
}

[[nodiscard]] uint64_t GetModuleBase(const char *Name) const {
Expand Down

0 comments on commit 4988d42

Please sign in to comment.