Fix incorrect backend breakpoints implementation
This commit is contained in:
parent
28468f8a18
commit
d09e3b7953
|
@ -135,8 +135,10 @@ bool X64Backend::InstallBreakpoint(Breakpoint* bp) {
|
||||||
auto code = guest_function->MapGuestAddressToMachineCode(bp->address());
|
auto code = guest_function->MapGuestAddressToMachineCode(bp->address());
|
||||||
assert_not_zero(code);
|
assert_not_zero(code);
|
||||||
|
|
||||||
bp->set_backend_data(
|
auto orig_bytes =
|
||||||
xe::load_and_swap<uint16_t>(reinterpret_cast<void*>(code + 0x0)));
|
xe::load_and_swap<uint16_t>(reinterpret_cast<void*>(code + 0x0));
|
||||||
|
bp->backend_data().push_back({code, orig_bytes });
|
||||||
|
|
||||||
xe::store_and_swap<uint16_t>(reinterpret_cast<void*>(code + 0x0), 0x0F0C);
|
xe::store_and_swap<uint16_t>(reinterpret_cast<void*>(code + 0x0), 0x0F0C);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,24 +146,12 @@ bool X64Backend::InstallBreakpoint(Breakpoint* bp) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool X64Backend::UninstallBreakpoint(Breakpoint* bp) {
|
bool X64Backend::UninstallBreakpoint(Breakpoint* bp) {
|
||||||
auto functions = processor()->FindFunctionsWithAddress(bp->address());
|
for (auto pair : bp->backend_data()) {
|
||||||
if (functions.empty()) {
|
xe::store_and_swap<uint16_t>(reinterpret_cast<void*>(pair.first),
|
||||||
// This should not happen.
|
uint16_t(pair.second));
|
||||||
assert_always();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto function : functions) {
|
|
||||||
assert_true(function->is_guest());
|
|
||||||
auto guest_function = reinterpret_cast<cpu::GuestFunction*>(function);
|
|
||||||
auto code = guest_function->MapGuestAddressToMachineCode(bp->address());
|
|
||||||
assert_not_zero(code);
|
|
||||||
|
|
||||||
xe::store_and_swap<uint16_t>(reinterpret_cast<void*>(code + 0x0),
|
|
||||||
uint16_t(bp->backend_data()));
|
|
||||||
bp->set_backend_data(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bp->backend_data().clear();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,8 +35,12 @@ class Breakpoint {
|
||||||
void Hit(uint64_t host_pc) { hit_callback_(address_, host_pc); }
|
void Hit(uint64_t host_pc) { hit_callback_(address_, host_pc); }
|
||||||
|
|
||||||
// CPU backend data. Implementation specific - DO NOT TOUCH THIS!
|
// CPU backend data. Implementation specific - DO NOT TOUCH THIS!
|
||||||
uint64_t backend_data() const { return backend_data_; }
|
std::vector<std::pair<uint64_t, uint64_t>> backend_data() const {
|
||||||
void set_backend_data(uint64_t backend_data) { backend_data_ = backend_data; }
|
return backend_data_;
|
||||||
|
}
|
||||||
|
std::vector<std::pair<uint64_t, uint64_t>>& backend_data() {
|
||||||
|
return backend_data_;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Processor* processor_ = nullptr;
|
Processor* processor_ = nullptr;
|
||||||
|
@ -46,7 +50,7 @@ class Breakpoint {
|
||||||
std::function<void(uint32_t, uint64_t)> hit_callback_;
|
std::function<void(uint32_t, uint64_t)> hit_callback_;
|
||||||
|
|
||||||
// Opaque backend data. Don't touch this.
|
// Opaque backend data. Don't touch this.
|
||||||
uint64_t backend_data_ = 0;
|
std::vector<std::pair<uint64_t, uint64_t>> backend_data_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace cpu
|
} // namespace cpu
|
||||||
|
|
Loading…
Reference in New Issue