another directory rename: failstar -> fail
"failstar" sounds like a name for a cruise liner from the 80s. As "*" isn't a desirable part of directory names, just name the whole thing "fail/", the core parts being stored in "fail/core/". Additionally fixing two build system dependency issues: - missing jobserver -> protomessages dependency - broken bochs -> fail dependency (add_custom_target DEPENDS only allows plain file dependencies ... cmake for the win) git-svn-id: https://www4.informatik.uni-erlangen.de/i4svn/danceos/trunk/devel/fail@956 8c4709b5-6ec9-48aa-a5cd-a96041d1645a
This commit is contained in:
6
core/plugins/CMakeLists.txt
Normal file
6
core/plugins/CMakeLists.txt
Normal file
@ -0,0 +1,6 @@
|
||||
# Note that we're allowing *multiple* plugins to be enabled at once.
|
||||
set(PLUGINS_ACTIVATED "" CACHE STRING "Activated plugins (a semicolon-separated list of fail/plugins/ subdirectories)")
|
||||
|
||||
foreach(plugin_name ${PLUGINS_ACTIVATED})
|
||||
add_subdirectory(${plugin_name})
|
||||
endforeach(plugin_name)
|
||||
18
core/plugins/tracing/CMakeLists.txt
Normal file
18
core/plugins/tracing/CMakeLists.txt
Normal file
@ -0,0 +1,18 @@
|
||||
set(PLUGIN_NAME tracing)
|
||||
|
||||
#### PROTOBUFS ####
|
||||
set(MY_PROTOS
|
||||
trace.proto
|
||||
)
|
||||
find_package(Protobuf REQUIRED)
|
||||
include_directories(${PROTOBUF_INCLUDE_DIRS})
|
||||
PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS ${MY_PROTOS})
|
||||
|
||||
set(MY_PLUGIN_SRCS
|
||||
TracingPlugin.cc
|
||||
TracingPlugin.hpp
|
||||
)
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
## Build library
|
||||
add_library(${PLUGIN_NAME} ${MY_PLUGIN_SRCS} ${PROTO_SRCS} ${PROTO_HDRS})
|
||||
75
core/plugins/tracing/TracingPlugin.cc
Normal file
75
core/plugins/tracing/TracingPlugin.cc
Normal file
@ -0,0 +1,75 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "SAL/SALInst.hpp"
|
||||
#include "SAL/Register.hpp"
|
||||
#include "TracingPlugin.hpp"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
using namespace fi;
|
||||
using namespace sal;
|
||||
|
||||
bool TracingPlugin::run()
|
||||
{
|
||||
MemAccessEvent ev_mem(ANY_ADDR);
|
||||
BPEvent ev_step(ANY_ADDR);
|
||||
BaseEvent *ev;
|
||||
|
||||
if (m_iponly || !m_memonly) {
|
||||
simulator.addEvent(&ev_step);
|
||||
}
|
||||
if (m_memonly || !m_iponly) {
|
||||
simulator.addEvent(&ev_mem);
|
||||
}
|
||||
|
||||
while (true) {
|
||||
ev = simulator.waitAny();
|
||||
|
||||
if (ev == &ev_step) {
|
||||
simulator.addEvent(&ev_step);
|
||||
|
||||
address_t ip = ev_step.getTriggerInstructionPointer();
|
||||
if (m_ipMap && !m_ipMap->isMatching(ip)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (m_os)
|
||||
*m_os << "[Tracing] IP " << hex << ip << "\n";
|
||||
if (m_trace) {
|
||||
Trace_Event *e = m_trace->add_event();
|
||||
e->set_ip(ip);
|
||||
}
|
||||
} else if (ev == &ev_mem) {
|
||||
simulator.addEvent(&ev_mem);
|
||||
|
||||
address_t ip = ev_mem.getTriggerInstructionPointer();
|
||||
address_t addr = ev_mem.getTriggerAddress();
|
||||
size_t width = ev_mem.getTriggerWidth();
|
||||
if ((m_ipMap && !m_ipMap->isMatching(ip)) ||
|
||||
(m_memMap && !m_memMap->isMatching(addr, width))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (m_os)
|
||||
*m_os << hex << "[Tracing] MEM "
|
||||
<< ((ev_mem.getTriggerAccessType() &
|
||||
MemAccessEvent::MEM_READ) ? "R " : "W ")
|
||||
<< addr << " width " << width << " IP " << ip << "\n";
|
||||
if (m_trace) {
|
||||
Trace_Event *e = m_trace->add_event();
|
||||
e->set_ip(ip);
|
||||
e->set_memaddr(addr);
|
||||
e->set_width(width);
|
||||
e->set_accesstype(
|
||||
(ev_mem.getTriggerAccessType() & MemAccessEvent::MEM_READ) ?
|
||||
e->READ : e->WRITE);
|
||||
}
|
||||
} else {
|
||||
if (m_os)
|
||||
*m_os << "[Tracing] SOMETHING IS SERIOUSLY WRONG\n";
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
76
core/plugins/tracing/TracingPlugin.hpp
Normal file
76
core/plugins/tracing/TracingPlugin.hpp
Normal file
@ -0,0 +1,76 @@
|
||||
#ifndef __TRACING_PLUGIN_HPP__
|
||||
#define __TRACING_PLUGIN_HPP__
|
||||
|
||||
#include <ostream>
|
||||
#include "controller/ExperimentFlow.hpp"
|
||||
#include "util/MemoryMap.hpp"
|
||||
|
||||
#include "plugins/tracing/trace.pb.h"
|
||||
|
||||
/**
|
||||
* \class TracingPlugin
|
||||
*
|
||||
* \brief Plugin to record instruction traces and memory accesses.
|
||||
*
|
||||
* This plugin is supposed to be instantiated, configured and run by
|
||||
* experiments needing instruction or memory access traces. Tracing can be
|
||||
* restricted to a memory or instruction address map; the restrictions are
|
||||
* applied together, i.e., a memory access is only logged if neither its
|
||||
* instruction address nor its memory address is restricted.
|
||||
*
|
||||
* TODO: document usage by example
|
||||
* FIXME: handle configuration changes after tracing start properly
|
||||
* FIXME: more explicit startup/shutdown; listener-based event interface needed?
|
||||
* -> should simulator.removeFlow make sure all remaining active events
|
||||
* are delivered?
|
||||
*/
|
||||
class TracingPlugin : public fi::ExperimentFlow
|
||||
{
|
||||
private:
|
||||
MemoryMap *m_memMap; //!< address restriction for memory accesses
|
||||
MemoryMap *m_ipMap; //!< instruction address restriction
|
||||
bool m_memonly; //!< log instructions only if they are memory accesses
|
||||
bool m_iponly; //!< log instruction addresses only
|
||||
|
||||
Trace *m_trace; //!< protobuf message to store trace in
|
||||
std::ostream *m_os; //!< ostream to write human-readable trace into
|
||||
|
||||
public:
|
||||
TracingPlugin()
|
||||
: m_memMap(0), m_ipMap(0), m_memonly(false), m_iponly(false),
|
||||
m_trace(0), m_os(0) { }
|
||||
bool run();
|
||||
/**
|
||||
* Restricts tracing to memory addresses listed in this MemoryMap. An
|
||||
* access wider than 8 bit *is* logged if *one* of the bytes it
|
||||
* reads/writes is listed.
|
||||
*/
|
||||
void restrictMemoryAddresses(MemoryMap *mm) { m_memMap = mm; }
|
||||
/**
|
||||
* Restricts tracing to instruction addresses listed in this MemoryMap.
|
||||
* This restriction currently silently assumes instructions are only
|
||||
* one byte wide; make sure your memory map covers this first byte of
|
||||
* the instructions you want to trace.
|
||||
*/
|
||||
void restrictInstructionAddresses(MemoryMap *mm) { m_ipMap = mm; }
|
||||
/**
|
||||
* If invoked with memonly=true, instructions are only logged if they
|
||||
* conducted a memory access. Defaults to false: All instructions are
|
||||
* logged.
|
||||
*/
|
||||
void setLogMemOnly(bool memonly) { m_memonly = memonly; }
|
||||
/**
|
||||
* If invoked with iponly=true, only instruction addresses are logged.
|
||||
*/
|
||||
void setLogIPOnly(bool iponly) { m_iponly = iponly; }
|
||||
/**
|
||||
* ostream to trace into (human-readable)
|
||||
*/
|
||||
void setOstream(std::ostream *os) { m_os = os; }
|
||||
/**
|
||||
* Protobuf message to trace into (trace.proto instance)
|
||||
*/
|
||||
void setTraceMessage(Trace *trace) { m_trace = trace; }
|
||||
};
|
||||
|
||||
#endif /* __TRACING_PLUGIN_HPP__ */
|
||||
34
core/plugins/tracing/dump-trace.py
Executable file
34
core/plugins/tracing/dump-trace.py
Executable file
@ -0,0 +1,34 @@
|
||||
#! /usr/bin/env python
|
||||
|
||||
# create python bindings before running:
|
||||
# protoc --python_out=. trace.proto
|
||||
|
||||
import trace_pb2
|
||||
import sys
|
||||
|
||||
if len(sys.argv) != 2:
|
||||
print "Usage:", sys.argv[0], "tracefile.pb"
|
||||
sys.exit(-1)
|
||||
|
||||
trace = trace_pb2.Trace()
|
||||
|
||||
# Read trace
|
||||
try:
|
||||
f = open(sys.argv[1], "rb")
|
||||
trace.ParseFromString(f.read())
|
||||
f.close()
|
||||
except IOError:
|
||||
print sys.argv[1] + ": Could not open file."
|
||||
sys.exit(-1)
|
||||
|
||||
# This works for any type of pb message:
|
||||
#print trace
|
||||
|
||||
# More compact dump for traces:
|
||||
for event in trace.event:
|
||||
if not event.HasField("memaddr"):
|
||||
print "IP {0:x}".format(event.ip)
|
||||
else:
|
||||
print "MEM {0} {1:x} width {2:d} IP {3:x}".format(
|
||||
"R" if event.accesstype == trace_pb2.Trace.Event.READ else "W",
|
||||
event.memaddr, event.width, event.ip)
|
||||
12
core/plugins/tracing/trace.proto
Normal file
12
core/plugins/tracing/trace.proto
Normal file
@ -0,0 +1,12 @@
|
||||
message Trace {
|
||||
repeated group Event = 1{
|
||||
required uint64 ip = 1;
|
||||
optional uint64 memaddr = 2;
|
||||
optional uint32 width = 3;
|
||||
enum AccessType {
|
||||
READ = 1;
|
||||
WRITE = 2;
|
||||
}
|
||||
optional AccessType accesstype = 4;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user