Index: runtime/vm/simulator_dbc.cc |
diff --git a/runtime/vm/simulator_dbc.cc b/runtime/vm/simulator_dbc.cc |
index afb5487f7b648781c6d84937682f9aff3616295b..12423cac0a067e4c8b7dc35f2fc2728b161d80f9 100644 |
--- a/runtime/vm/simulator_dbc.cc |
+++ b/runtime/vm/simulator_dbc.cc |
@@ -529,7 +529,7 @@ void Simulator::InitOnce() { |
} |
-Simulator::Simulator() : stack_(NULL), fp_(NULL) { |
+Simulator::Simulator() : stack_(NULL), fp_(NULL), icount_(0) { |
// Setup simulator support first. Some of this information is needed to |
// setup the architecture state. |
// We allocate the stack here, the size is computed as the sum of |
@@ -575,6 +575,24 @@ uword Simulator::StackTop() const { |
} |
+// Returns true if tracing of executed instructions is enabled. |
+DART_FORCE_INLINE bool Simulator::IsTracingExecution() const { |
+ return icount_ > FLAG_trace_sim_after; |
+} |
+ |
+ |
+// Prints bytecode instruction at given pc for instruction tracing. |
+DART_NOINLINE void Simulator::TraceInstruction(uint32_t* pc) const { |
+ THR_Print("%" Pu64 " ", icount_); |
+ if (FLAG_support_disassembler) { |
+ Disassembler::Disassemble(reinterpret_cast<uword>(pc), |
+ reinterpret_cast<uword>(pc + 1)); |
+ } else { |
+ THR_Print("Disassembler not supported in this mode.\n"); |
+ } |
+} |
+ |
+ |
// Calls into the Dart runtime are based on this interface. |
typedef void (*SimulatorRuntimeCall)(NativeArguments arguments); |
@@ -984,12 +1002,24 @@ static DART_NOINLINE bool InvokeNativeAutoScopeWrapper(Thread* thread, |
// Note: all macro helpers are intended to be used only inside Simulator::Call. |
+// Counts and prints executed bytecode instructions (in a non-PRODUCT mode). |
+#if !defined(PRODUCT) |
+#define TRACE_INSTRUCTION \ |
+ icount_++; \ |
+ if (IsTracingExecution()) { \ |
+ TraceInstruction(pc - 1); \ |
+ } |
+#else |
+#define TRACE_INSTRUCTION |
+#endif |
+ |
// Decode opcode and A part of the given value and dispatch to the |
// corresponding bytecode handler. |
#define DISPATCH_OP(val) \ |
do { \ |
op = (val); \ |
rA = ((op >> 8) & 0xFF); \ |
+ TRACE_INSTRUCTION \ |
goto* dispatch[op & 0xFF]; \ |
} while (0) |