Added comparison operator for --break_on_instruction.

This commit is contained in:
gibbed 2016-06-19 21:01:18 -05:00
parent b5bef8c54d
commit 450ca87120
4 changed files with 50 additions and 15 deletions

View File

@ -40,6 +40,7 @@ DEFINE_uint64(break_on_instruction, 0,
"int3 before the given guest address is executed."); "int3 before the given guest address is executed.");
DEFINE_int32(break_condition_gpr, -1, "GPR compared to"); DEFINE_int32(break_condition_gpr, -1, "GPR compared to");
DEFINE_uint64(break_condition_value, 0, "value compared against"); DEFINE_uint64(break_condition_value, 0, "value compared against");
DEFINE_string(break_condition_op, "eq", "comparison operator");
DEFINE_bool(break_condition_truncate, true, "truncate value to 32-bits"); DEFINE_bool(break_condition_truncate, true, "truncate value to 32-bits");
DEFINE_bool(break_on_debugbreak, true, "int3 on JITed __debugbreak requests."); DEFINE_bool(break_on_debugbreak, true, "int3 on JITed __debugbreak requests.");

View File

@ -30,6 +30,7 @@ DECLARE_bool(validate_hir);
DECLARE_uint64(break_on_instruction); DECLARE_uint64(break_on_instruction);
DECLARE_int32(break_condition_gpr); DECLARE_int32(break_condition_gpr);
DECLARE_uint64(break_condition_value); DECLARE_uint64(break_condition_value);
DECLARE_string(break_condition_op);
DECLARE_bool(break_condition_truncate); DECLARE_bool(break_condition_truncate);
DECLARE_bool(break_on_debugbreak); DECLARE_bool(break_on_debugbreak);

View File

@ -157,21 +157,7 @@ bool PPCHIRBuilder::Emit(GuestFunction* function, uint32_t flags) {
ContextBarrier(); ContextBarrier();
} }
if (address == FLAGS_break_on_instruction) { MaybeBreakOnInstruction(address);
Comment("--break-on-instruction target");
if (FLAGS_break_condition_gpr < 0) {
DebugBreak();
} else {
auto left = LoadGPR(FLAGS_break_condition_gpr);
auto right = LoadConstantUint64(FLAGS_break_condition_value);
if (FLAGS_break_condition_truncate) {
left = Truncate(left, INT32_TYPE);
right = Truncate(right, INT32_TYPE);
}
TrapTrue(CompareEQ(left, right));
}
}
InstrData i; InstrData i;
i.address = address; i.address = address;
@ -194,6 +180,52 @@ bool PPCHIRBuilder::Emit(GuestFunction* function, uint32_t flags) {
return Finalize(); return Finalize();
} }
void PPCHIRBuilder::MaybeBreakOnInstruction(uint32_t address) {
if (address != FLAGS_break_on_instruction) {
return;
}
Comment("--break-on-instruction target");
if (FLAGS_break_condition_gpr < 0) {
DebugBreak();
return;
}
auto left = LoadGPR(FLAGS_break_condition_gpr);
auto right = LoadConstantUint64(FLAGS_break_condition_value);
if (FLAGS_break_condition_truncate) {
left = Truncate(left, INT32_TYPE);
right = Truncate(right, INT32_TYPE);
}
auto op = FLAGS_break_condition_op.c_str();
// TODO(rick): table?
if (strcasecmp(op, "eq") == 0) {
TrapTrue(CompareEQ(left, right));
} else if (strcasecmp(op, "ne") == 0) {
TrapTrue(CompareNE(left, right));
} else if (strcasecmp(op, "slt") == 0) {
TrapTrue(CompareSLT(left, right));
} else if (strcasecmp(op, "sle") == 0) {
TrapTrue(CompareSLE(left, right));
} else if (strcasecmp(op, "sgt") == 0) {
TrapTrue(CompareSGT(left, right));
} else if (strcasecmp(op, "sge") == 0) {
TrapTrue(CompareSGE(left, right));
} else if (strcasecmp(op, "ult") == 0) {
TrapTrue(CompareULT(left, right));
} else if (strcasecmp(op, "ule") == 0) {
TrapTrue(CompareULE(left, right));
} else if (strcasecmp(op, "ugt") == 0) {
TrapTrue(CompareUGT(left, right));
} else if (strcasecmp(op, "uge") == 0) {
TrapTrue(CompareUGE(left, right));
} else {
assert_always();
}
}
void PPCHIRBuilder::AnnotateLabel(uint32_t address, Label* label) { void PPCHIRBuilder::AnnotateLabel(uint32_t address, Label* label) {
char name_buffer[13]; char name_buffer[13];
snprintf(name_buffer, xe::countof(name_buffer), "loc_%.8X", address); snprintf(name_buffer, xe::countof(name_buffer), "loc_%.8X", address);

View File

@ -82,6 +82,7 @@ class PPCHIRBuilder : public hir::HIRBuilder {
Value* LoadReserved(); Value* LoadReserved();
private: private:
void MaybeBreakOnInstruction(uint32_t address);
void AnnotateLabel(uint32_t address, Label* label); void AnnotateLabel(uint32_t address, Label* label);
PPCFrontend* frontend_; PPCFrontend* frontend_;