From c2b8566e3514beb3fb0fa5f042442f08d715fd54 Mon Sep 17 00:00:00 2001 From: Christoph Borchert Date: Mon, 15 Jun 2015 12:06:00 +0200 Subject: [PATCH] generic-tracing: add --serial-port and --serial-file command-line options The generic-tracing experiment now supports logging of I/O port access to file. Therefore, the serialoutput plugin needs to be included in the experiment configuration. Without the --serial-file option specified, logging is disabled. Change-Id: I9e60d8ffd598ee04a50b4d92fc283f75382d478a --- src/experiments/generic-tracing/config.cmake | 2 +- src/experiments/generic-tracing/experiment.cc | 43 +++++++++++++++++++ .../generic-tracing/experiment.hpp | 3 ++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/experiments/generic-tracing/config.cmake b/src/experiments/generic-tracing/config.cmake index a3c46366..3bb54ef5 100644 --- a/src/experiments/generic-tracing/config.cmake +++ b/src/experiments/generic-tracing/config.cmake @@ -1,4 +1,4 @@ -SET(PLUGINS_ACTIVATED "tracing" CACHE STRING "") +SET(PLUGINS_ACTIVATED "tracing;serialoutput" CACHE STRING "") SET(bochs_configure_params "--enable-a20-pin;--enable-x86-64;--enable-cpu-level=6;--enable-ne2000;--enable-acpi;--enable-pci;--enable-usb;--enable-trace-cache;--enable-fast-function-calls;--enable-host-specific-asms;--enable-readline;--enable-clgd54xx;--enable-fpu;--enable-vmx=2;--enable-monitor-mwait;--enable-cdrom;--enable-sb16=linux;--enable-gdb-stub;--with-nogui" CACHE STRING "") diff --git a/src/experiments/generic-tracing/experiment.cc b/src/experiments/generic-tracing/experiment.cc index 29cc1696..e2d9201d 100644 --- a/src/experiments/generic-tracing/experiment.cc +++ b/src/experiments/generic-tracing/experiment.cc @@ -10,6 +10,8 @@ // You need to have the tracing plugin enabled for this #include "../plugins/tracing/TracingPlugin.hpp" +// You need to have the serialoutput plugin enabled for this +#include "../plugins/serialoutput/SerialOutputLogger.hpp" /* @@ -57,6 +59,10 @@ void GenericTracing::parseOptions() { "-B,--start-address \tStart Address to start tracing"); CommandLine::option_handle STOP_ADDRESS = cmd.addOption("E", "end-address",Arg::Required, "-E--end-address \tEnd Address to end tracing"); + CommandLine::option_handle SERIAL_PORT = cmd.addOption("", "serial-port", Arg::Required, + "--serial-port \tListen to a given I/O address (default: 0x3F8)"); + CommandLine::option_handle SERIAL_FILE = cmd.addOption("", "serial-file", Arg::Required, + "--serial-file \tSave the serial output to file"); if (!cmd.parse()) { cerr << "Error parsing arguments." << endl; @@ -195,6 +201,26 @@ void GenericTracing::parseOptions() { this->full_trace = true; } + if (cmd[SERIAL_PORT]) { + option::Option *opt = cmd[SERIAL_PORT].first(); + char *endptr; + serial_port = strtoul(opt->arg, &endptr, 16); + if (endptr == opt->arg) { + m_log << "Couldn't parse " << opt->arg << std::endl; + exit(-1); + } + m_log << "serial port: " << serial_port << std::endl; + } else { + serial_port = 0x3F8; + } + + if (cmd[SERIAL_FILE]) { + serial_file = std::string(cmd[SERIAL_FILE].first()->arg); + m_log << "serial file: " << serial_file << std::endl; + } else { + serial_file = ""; + } + if (m_elf != NULL) { m_log << "start/save symbol: " << start_symbol << " 0x" << std::hex << start_address << std::endl; m_log << "stop symbol: " << stop_symbol << " 0x" << std::hex << stop_address << std::endl; @@ -243,6 +269,12 @@ bool GenericTracing::run() // this must be done *after* configuring the plugin: simulator.addFlow(&tp); + // record serial output + SerialOutputLogger sol(serial_port); + if (serial_file != "") { + simulator.addFlow(&sol); + } + //////////////////////////////////////////////////////////////// // Step 2: Continue to the stop point simulator.addListener(&l_stop_symbol); @@ -259,6 +291,17 @@ bool GenericTracing::run() } of.close(); + if (serial_file != "") { + simulator.removeFlow(&sol); + ofstream of_serial(serial_file.c_str(), ios::out|ios::binary); + if (!of_serial.fail()) { + of_serial << sol.getOutput(); + } else { + m_log << "failed to write " << serial_file << endl; + } + of_serial.close(); + } + simulator.clearListeners(); simulator.terminate(); diff --git a/src/experiments/generic-tracing/experiment.hpp b/src/experiments/generic-tracing/experiment.hpp index 2be6cd85..60eb0f6e 100644 --- a/src/experiments/generic-tracing/experiment.hpp +++ b/src/experiments/generic-tracing/experiment.hpp @@ -24,6 +24,9 @@ class GenericTracing : public fail::ExperimentFlow { bool full_trace; + fail::guest_address_t serial_port; + std::string serial_file; + fail::Logger m_log; fail::ElfReader *m_elf;