Skip to content

Commit

Permalink
duplicate logic to be abe to use logging functions
Browse files Browse the repository at this point in the history
  • Loading branch information
0vercl0k committed May 25, 2024
1 parent c3c1c82 commit bd38fb5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 31 deletions.
6 changes: 4 additions & 2 deletions src/wtf/kvm_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2158,8 +2158,10 @@ bool KvmBackend_t::EnableSingleStep(CpuState_t &CpuState) {
return false;
}

if (!SetBreakpoint(*Handler,
[](Backend_t *Backend) { Backend->TrapFlag(true); })) {
if (!SetBreakpoint(*Handler, [](Backend_t *Backend) {
KvmDebugPrint("Hit IDT breakpoint, turning on TF\n");
Backend->TrapFlag(true);
})) {
fmt::print("Failed to set breakpoint on IDT[{}]", Idx);
return false;
}
Expand Down
19 changes: 0 additions & 19 deletions src/wtf/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -513,22 +513,3 @@ ReadIDTEntryHandler(const Backend_t &Backend, const CpuState_t &CpuState,

return Entry.Handler();
}

[[nodiscard]] bool BreakOnIDTEntries(Backend_t &Backend,
const CpuState_t &CpuState) {
for (size_t Idx = 0; Idx < 256; Idx++) {
const auto Handler = ReadIDTEntryHandler(Backend, CpuState, Idx);
if (!Handler) {
fmt::print("ReadIDTEntryHandler failed\n");
return false;
}

if (!Backend.SetBreakpoint(
*Handler, [](Backend_t *Backend) { Backend->TrapFlag(true); })) {
fmt::print("Failed to set breakpoint on IDT[{}]\n", Idx);
return false;
}
}

return true;
}
7 changes: 0 additions & 7 deletions src/wtf/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,3 @@ SaveFile(const fs::path &Path, const uint8_t *Buffer, const size_t BufferSize);
[[nodiscard]] std::optional<Gva_t>
ReadIDTEntryHandler(const Backend_t &Backend, const CpuState_t &CpuState,
const size_t Vector);

//
// Set a breakpoint on every IDT handlers that turn on TF.
//

[[nodiscard]] bool BreakOnIDTEntries(Backend_t &Backend,
const CpuState_t &CpuState);
17 changes: 14 additions & 3 deletions src/wtf/whv_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1430,9 +1430,20 @@ bool WhvBackend_t::EnableSingleStep(CpuState_t &CpuState) {
// interrupts/exceptions.
//

if (!BreakOnIDTEntries(*this, CpuState)) {
fmt::print("Failed to BreakOnIDTEntries\n");
return false;
for (size_t Idx = 0; Idx < 256; Idx++) {
const auto Handler = ReadIDTEntryHandler(*this, CpuState, Idx);
if (!Handler) {
fmt::print("ReadIDTEntryHandler failed\n");
return false;
}

if (!SetBreakpoint(*Handler, [](Backend_t *Backend) {
WhvDebugPrint("Hit IDT breakpoint, turning on TF\n");
Backend->TrapFlag(true);
})) {
fmt::print("Failed to set breakpoint on IDT[{}]", Idx);
return false;
}
}

return true;
Expand Down

0 comments on commit bd38fb5

Please sign in to comment.