From 036e340bd9322f94a1e6b16048309645245d514a Mon Sep 17 00:00:00 2001 From: Christian Dietrich Date: Thu, 19 Sep 2013 15:57:11 +0200 Subject: [PATCH] generic-tracing: fix lossage of first event When using the generic-tracing experiment for generating a trace, the first event, after the tracing is started (the start-symbol) is lost in the trace. This patch handles this special case seperately. Change-Id: Ia131a8559d67161532504160826fdb100247ed75 --- src/experiments/generic-tracing/experiment.cc | 4 +++ src/plugins/tracing/TracingPlugin.cc | 36 ++++++++++++++++--- src/plugins/tracing/TracingPlugin.hpp | 15 +++++++- 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/experiments/generic-tracing/experiment.cc b/src/experiments/generic-tracing/experiment.cc index 0d57f049..553a9056 100644 --- a/src/experiments/generic-tracing/experiment.cc +++ b/src/experiments/generic-tracing/experiment.cc @@ -209,6 +209,10 @@ bool GenericTracing::run() // this must be done *after* configuring the plugin: simulator.addFlow(&tp); + // In order to not loose the IP event at the beginning of the + // trace, we have to handle the IP event manually + tp.handleSingleIP(l_start_symbol); + //////////////////////////////////////////////////////////////// // STEP 2: continue to the save point, and save state if (start_symbol != save_symbol) { diff --git a/src/plugins/tracing/TracingPlugin.cc b/src/plugins/tracing/TracingPlugin.cc index 482413f8..12ee464c 100644 --- a/src/plugins/tracing/TracingPlugin.cc +++ b/src/plugins/tracing/TracingPlugin.cc @@ -1,6 +1,7 @@ #include #include +#include "sal/SALConfig.hpp" #include "sal/SALInst.hpp" #include "sal/Register.hpp" #include "sal/Memory.hpp" @@ -10,6 +11,34 @@ using namespace std; using namespace fail; +void TracingPlugin::handleSingleIP(const BPListener &bp) { + address_t ip = bp.getTriggerInstructionPointer(); + if (m_ipMap && !m_ipMap->isMatching(ip)) { + return; + } + + m_curtime = simulator.getTimerTicks(); + simtime_diff_t deltatime = m_curtime - m_prevtime; + + if (m_os) + *m_os << "[Tracing] IP " << hex << ip << "\n"; + + if (m_protoStreamFile) { + Trace_Event e; + e.set_ip(ip); + // only store deltas != 0 + if (deltatime != 0) { + e.set_time_delta(deltatime); + } + if (!ps) { + ps = new ProtoOStream (m_protoStreamFile); + } + + ps->writeMessage(&e); + } +} + + bool TracingPlugin::run() { MemoryManager& mm = simulator.getMemoryManager(); @@ -33,14 +62,13 @@ bool TracingPlugin::run() // the first event gets an absolute time stamp, all others a delta to their // predecessor - simtime_t prevtime = 0, curtime; simtime_diff_t deltatime; while (true) { ev = simulator.resume(); - curtime = simulator.getTimerTicks(); - deltatime = curtime - prevtime; + m_curtime = simulator.getTimerTicks(); + deltatime = m_curtime - m_prevtime; if (ev == &ev_step) { simulator.addListener(&ev_step); @@ -122,7 +150,7 @@ bool TracingPlugin::run() // do this only if the last delta was written // (no, e.g., memory map mismatch) - prevtime = curtime; + m_prevtime = m_curtime; } return true; diff --git a/src/plugins/tracing/TracingPlugin.hpp b/src/plugins/tracing/TracingPlugin.hpp index e8cec478..de9bb026 100644 --- a/src/plugins/tracing/TracingPlugin.hpp +++ b/src/plugins/tracing/TracingPlugin.hpp @@ -7,6 +7,8 @@ #include "util/ProtoStream.hpp" #include "efw/ExperimentFlow.hpp" #include "config/FailConfig.hpp" +#include "sal/Listener.hpp" + #include "TracePlugin.pb.h" @@ -48,10 +50,14 @@ private: std::ostream *m_os; //!< ostream to write human-readable trace into fail::ProtoOStream *ps; + fail::simtime_t m_prevtime; + fail::simtime_t m_curtime; + public: TracingPlugin(bool full_trace = false) : m_memMap(0), m_ipMap(0), m_memonly(false), m_iponly(false), - m_full_trace(full_trace), m_protoStreamFile(0), m_os(0) { } + m_full_trace(full_trace), m_protoStreamFile(0), m_os(0), + m_prevtime(0) { } bool run(); /** * Restricts tracing to memory addresses listed in this MemoryMap. An @@ -88,6 +94,13 @@ public: * ProtoStream file to trace into (trace.proto instance) */ void setTraceFile(std::ostream *os) { m_protoStreamFile = os; } + + /** + * Handles a single IP event. This is important for starting the + * tracing process after triggering a breakpoint. Just pass on the + * breakpoint + */ + void handleSingleIP(const fail::BPListener &bp); }; #endif // __TRACING_PLUGIN_HPP__