Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't WaitForEvent when using IDebugControl::Execute #221

Merged
merged 6 commits into from
Jan 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading