Automatically install any CPU breakpoints in any newly-defined functions if necessary.
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
namespace xe {
|
||||
namespace cpu {
|
||||
class Breakpoint;
|
||||
class Function;
|
||||
class GuestFunction;
|
||||
class Module;
|
||||
class Processor;
|
||||
@@ -53,6 +54,7 @@ class Backend {
|
||||
Module* module, uint32_t address) = 0;
|
||||
|
||||
virtual bool InstallBreakpoint(Breakpoint* bp) { return false; }
|
||||
virtual bool InstallBreakpoint(Breakpoint* bp, Function* func) { return false; }
|
||||
virtual bool UninstallBreakpoint(Breakpoint* bp) { return false; }
|
||||
|
||||
protected:
|
||||
|
||||
@@ -133,7 +133,11 @@ bool X64Backend::InstallBreakpoint(Breakpoint* bp) {
|
||||
assert_true(function->is_guest());
|
||||
auto guest_function = reinterpret_cast<cpu::GuestFunction*>(function);
|
||||
auto code = guest_function->MapGuestAddressToMachineCode(bp->address());
|
||||
assert_not_zero(code);
|
||||
if (!code) {
|
||||
// This should not happen.
|
||||
assert_always();
|
||||
return false;
|
||||
}
|
||||
|
||||
auto orig_bytes =
|
||||
xe::load_and_swap<uint16_t>(reinterpret_cast<void*>(code + 0x0));
|
||||
@@ -145,6 +149,24 @@ bool X64Backend::InstallBreakpoint(Breakpoint* bp) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool X64Backend::InstallBreakpoint(Breakpoint* bp, Function* func) {
|
||||
assert_true(func->is_guest());
|
||||
auto guest_function = reinterpret_cast<cpu::GuestFunction*>(func);
|
||||
auto code = guest_function->MapGuestAddressToMachineCode(bp->address());
|
||||
if (!code) {
|
||||
assert_always();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Assume we haven't already installed a breakpoint in this spot.
|
||||
auto orig_bytes =
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool X64Backend::UninstallBreakpoint(Breakpoint* bp) {
|
||||
for (auto pair : bp->backend_data()) {
|
||||
xe::store_and_swap<uint16_t>(reinterpret_cast<void*>(pair.first),
|
||||
|
||||
@@ -63,6 +63,7 @@ class X64Backend : public Backend {
|
||||
uint32_t address) override;
|
||||
|
||||
bool InstallBreakpoint(Breakpoint* bp) override;
|
||||
bool InstallBreakpoint(Breakpoint* bp, Function* func) override;
|
||||
bool UninstallBreakpoint(Breakpoint* bp) override;
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user