From bf296ca0643fa445b83d8bd45eefa3fca02d9921 Mon Sep 17 00:00:00 2001 From: Rupert Swarbrick Date: Fri, 27 Mar 2020 10:25:20 +0000 Subject: Write execution logs to a named log file (#409) This patch adds a --log argument to spike. If not given, the behaviour is unchanged: messages logging execution of instructions and (if commit logging is enabled) commits go to stderr. If --log=P is given, Spike now writes these messages to a log file at the path P. This is nice, because they are no longer tangled up with other errors and warnings. The code is mostly plumbing: passing a FILE* object through to the functions that were using stderr. I've written a simple "log_file_t" class, which opens a log file if necessary and yields it or stderr. --- riscv/sim.h | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'riscv/sim.h') diff --git a/riscv/sim.h b/riscv/sim.h index a9d4923..91aedab 100644 --- a/riscv/sim.h +++ b/riscv/sim.h @@ -3,10 +3,12 @@ #ifndef _RISCV_SIM_H #define _RISCV_SIM_H -#include "processor.h" -#include "devices.h" #include "debug_module.h" +#include "devices.h" +#include "log_file.h" +#include "processor.h" #include "simif.h" + #include #include #include @@ -27,15 +29,22 @@ public: reg_t start_pc, std::vector> mems, std::vector> plugin_devices, const std::vector& args, const std::vector hartids, - const debug_module_config_t &dm_config); + const debug_module_config_t &dm_config, const char *log_path); ~sim_t(); // run the simulation to completion int run(); void set_debug(bool value); - void set_log(bool value); void set_histogram(bool value); - void set_log_commits(bool value); + + // Configure logging + // + // If enable_log is true, an instruction trace will be generated. If + // enable_commitlog is true, so will the commit results (if this + // build was configured without support for commit logging, the + // function will print an error message and abort). + void configure_log(bool enable_log, bool enable_commitlog); + void set_procs_debug(bool value); void set_dtb_enabled(bool value) { this->dtb_enabled = value; @@ -62,6 +71,7 @@ private: std::unique_ptr boot_rom; std::unique_ptr clint; bus_t bus; + log_file_t log_file; processor_t* get_core(const std::string& i); void step(size_t n); // step through simulation @@ -71,9 +81,8 @@ private: size_t current_step; size_t current_proc; bool debug; - bool log; bool histogram_enabled; // provide a histogram of PCs - bool log_commits_enabled; + bool log; bool dtb_enabled; remote_bitbang_t* remote_bitbang; -- cgit v1.1