From 3dc752cd091974be3fd5606fcf4c65e565486eae Mon Sep 17 00:00:00 2001 From: Horst Schirmeier Date: Tue, 15 Oct 2013 16:15:56 +0200 Subject: [PATCH] tracing: fix loss of first dynamic instruction When starting the tracing plugin (simulator.addFlow()), at the moment the *current* dynamic instruction (e.g., the one the start symbol points to) is skipped, and tracing commences with the second instruction. This change records an additional instruction event at the trace begin. Note that this change affects all tracing-plugin users. The first event gets recorded when starting the plugin (simulator.addFlow()). This avoids compatibility/off-by-one issues when recording traces with the generic-tracing experiment vs. with custom experiments. Change-Id: Ic24e17a68b8a44edad3be994e9edd6d6712bfda1 --- src/plugins/tracing/TracingPlugin.cc | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/plugins/tracing/TracingPlugin.cc b/src/plugins/tracing/TracingPlugin.cc index 482413f8..ff0dae1c 100644 --- a/src/plugins/tracing/TracingPlugin.cc +++ b/src/plugins/tracing/TracingPlugin.cc @@ -16,11 +16,10 @@ bool TracingPlugin::run() MemAccessListener ev_mem(ANY_ADDR); BPSingleListener ev_step(ANY_ADDR); - BaseListener *ev; + BaseListener *ev = 0; + + // ev_step is added in the first loop iteration - if (m_iponly || !m_memonly) { - simulator.addListener(&ev_step); - } if (m_memonly || !m_iponly) { simulator.addListener(&ev_mem); } @@ -36,16 +35,17 @@ bool TracingPlugin::run() simtime_t prevtime = 0, curtime; simtime_diff_t deltatime; - while (true) { - ev = simulator.resume(); + bool first = true; + while (true) { curtime = simulator.getTimerTicks(); deltatime = curtime - prevtime; - if (ev == &ev_step) { + if (ev == &ev_step || (first && (m_iponly || !m_memonly))) { + first = false; simulator.addListener(&ev_step); + address_t ip = simulator.getCPU(0).getInstructionPointer(); - address_t ip = ev_step.getTriggerInstructionPointer(); if (m_ipMap && !m_ipMap->isMatching(ip)) { continue; } @@ -115,7 +115,7 @@ bool TracingPlugin::run() ps->writeMessage(&e); } - } else { + } else if (!first) { if (m_os) *m_os << "[Tracing] SOMETHING IS SERIOUSLY WRONG\n"; } @@ -123,6 +123,8 @@ bool TracingPlugin::run() // do this only if the last delta was written // (no, e.g., memory map mismatch) prevtime = curtime; + + ev = simulator.resume(); } return true;