From fa8f87e53b68881c5e3aab296b517203407c4378 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 24 Jun 2015 19:37:21 +0545 Subject: [PATCH] sim: trace: add a basic cpu register class The bfin/msp430 ports already had trace logic set up for reading/writing cpu registers, albeit using different unrelated levels (core & vpu). Add a proper register class for these and for other ports. --- sim/bfin/ChangeLog | 5 +++++ sim/bfin/interp.c | 16 ---------------- sim/bfin/sim-main.h | 12 ------------ sim/common/ChangeLog | 10 ++++++++++ sim/common/sim-trace.c | 36 ++++++++++++++++++++++++------------ sim/common/sim-trace.h | 10 ++++++++++ sim/msp430/ChangeLog | 5 +++++ sim/msp430/msp430-sim.c | 4 ++-- 8 files changed, 56 insertions(+), 42 deletions(-) diff --git a/sim/bfin/ChangeLog b/sim/bfin/ChangeLog index 300b081581d..d0e91b3b5a5 100644 --- a/sim/bfin/ChangeLog +++ b/sim/bfin/ChangeLog @@ -1,3 +1,8 @@ +2015-06-24 Mike Frysinger + + * interp.c (trace_register): Delete. + * sim-main.h (trace_register, TRACE_REGISTER, TRACE_REG): Delete. + 2015-06-23 Mike Frysinger * configure: Regenerate. diff --git a/sim/bfin/interp.c b/sim/bfin/interp.c index 07030da0036..3013ca05928 100644 --- a/sim/bfin/interp.c +++ b/sim/bfin/interp.c @@ -606,22 +606,6 @@ bfin_syscall (SIM_CPU *cpu) TRACE_SYSCALL (cpu, "%s", _tbuf); } -void -trace_register (SIM_DESC sd, - sim_cpu *cpu, - const char *fmt, - ...) -{ - va_list ap; - trace_printf (sd, cpu, "%s %s", - "reg: ", - TRACE_PREFIX (CPU_TRACE_DATA (cpu))); - va_start (ap, fmt); - trace_vprintf (sd, cpu, fmt, ap); - va_end (ap); - trace_printf (sd, cpu, "\n"); -} - /* Execute a single instruction. */ static sim_cia diff --git a/sim/bfin/sim-main.h b/sim/bfin/sim-main.h index c11dcea272e..806fe157757 100644 --- a/sim/bfin/sim-main.h +++ b/sim/bfin/sim-main.h @@ -81,18 +81,6 @@ struct sim_state { bfin_trace_queue (cpu, oldpc, newpc, hwloop); \ } while (0) -extern void trace_register (SIM_DESC sd, - sim_cpu *cpu, - const char *fmt, - ...) - __attribute__((format (printf, 3, 4))); -#define TRACE_REGISTER(cpu, fmt, ...) \ - do { \ - if (TRACE_CORE_P (cpu)) \ - trace_register (CPU_STATE (cpu), cpu, fmt, ## __VA_ARGS__); \ - } while (0) -#define TRACE_REG(cpu, reg, val) TRACE_REGISTER (cpu, "wrote "#reg" = %#x", val) - /* Default memory size. */ #define BFIN_DEFAULT_MEM_SIZE (128 * 1024 * 1024) diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog index 63978bf6410..7a224bc02d3 100644 --- a/sim/common/ChangeLog +++ b/sim/common/ChangeLog @@ -1,3 +1,13 @@ +2015-06-24 Mike Frysinger + + * sim-trace.c (OPTION_TRACE_REGISTER): New enum. + (trace_options): Add trace-register option. + (trace_option_handler): Handle OPTION_TRACE_REGISTER case. + (trace_idx_to_str): Handle TRACE_REGISTER_IDX case and re-indent. + * sim-trace.h (TRACE_REGISTER_IDX): New enum. + (TRACE_register, WITH_TRACE_REGISTER_P, STRACE_REGISTER_P, + TRACE_REGISTER_P, TRACE_REGISTER): Define. + 2015-06-24 Mike Frysinger * sim-trace.h (STRACE, STRACE_INSN, STRACE_DECODE, STRACE_EXTRACT, diff --git a/sim/common/sim-trace.c b/sim/common/sim-trace.c index 1693a6e5f07..6e11cceb822 100644 --- a/sim/common/sim-trace.c +++ b/sim/common/sim-trace.c @@ -77,7 +77,8 @@ enum { OPTION_TRACE_DEBUG, OPTION_TRACE_FILE, OPTION_TRACE_VPU, - OPTION_TRACE_SYSCALL + OPTION_TRACE_SYSCALL, + OPTION_TRACE_REGISTER }; static const OPTION trace_options[] = @@ -128,6 +129,9 @@ static const OPTION trace_options[] = { {"trace-syscall", optional_argument, NULL, OPTION_TRACE_SYSCALL}, '\0', "on|off", "Trace system calls", trace_option_handler, NULL }, + { {"trace-register", optional_argument, NULL, OPTION_TRACE_REGISTER}, + '\0', "on|off", "Trace cpu register accesses", + trace_option_handler, NULL }, #ifdef SIM_HAVE_ADDR_RANGE { {"trace-range", required_argument, NULL, OPTION_TRACE_RANGE}, '\0', "START,END", "Specify range of addresses for instruction tracing", @@ -333,6 +337,13 @@ trace_option_handler (SIM_DESC sd, sim_cpu *cpu, int opt, sim_io_eprintf (sd, "System call tracing not compiled in, `--trace-syscall' ignored\n"); break; + case OPTION_TRACE_REGISTER : + if (WITH_TRACE_REGISTER_P) + return set_trace_option (sd, "-register", TRACE_REGISTER_IDX, arg); + else + sim_io_eprintf (sd, "Register tracing not compiled in, `--trace-register' ignored\n"); + break; + case OPTION_TRACE_SEMANTICS : if (WITH_TRACE_ALU_P && WITH_TRACE_FPU_P @@ -603,17 +614,18 @@ trace_idx_to_str (int trace_idx) static char num[8]; switch (trace_idx) { - case TRACE_ALU_IDX: return "alu: "; - case TRACE_INSN_IDX: return "insn: "; - case TRACE_DECODE_IDX: return "decode: "; - case TRACE_EXTRACT_IDX: return "extract: "; - case TRACE_MEMORY_IDX: return "memory: "; - case TRACE_CORE_IDX: return "core: "; - case TRACE_EVENTS_IDX: return "events: "; - case TRACE_FPU_IDX: return "fpu: "; - case TRACE_BRANCH_IDX: return "branch: "; - case TRACE_SYSCALL_IDX: return "syscall: "; - case TRACE_VPU_IDX: return "vpu: "; + case TRACE_ALU_IDX: return "alu: "; + case TRACE_INSN_IDX: return "insn: "; + case TRACE_DECODE_IDX: return "decode: "; + case TRACE_EXTRACT_IDX: return "extract: "; + case TRACE_MEMORY_IDX: return "memory: "; + case TRACE_CORE_IDX: return "core: "; + case TRACE_EVENTS_IDX: return "events: "; + case TRACE_FPU_IDX: return "fpu: "; + case TRACE_BRANCH_IDX: return "branch: "; + case TRACE_SYSCALL_IDX: return "syscall: "; + case TRACE_REGISTER_IDX: return "reg: "; + case TRACE_VPU_IDX: return "vpu: "; default: sprintf (num, "?%d?", trace_idx); return num; diff --git a/sim/common/sim-trace.h b/sim/common/sim-trace.h index 4ef2584151c..54a282407c9 100644 --- a/sim/common/sim-trace.h +++ b/sim/common/sim-trace.h @@ -71,6 +71,10 @@ enum { /* Trace syscalls. */ TRACE_SYSCALL_IDX, + /* Trace cpu register accesses. Registers that are part of hardware devices + should use the HW_TRACE macros instead. */ + TRACE_REGISTER_IDX, + /* Add information useful for debugging the simulator to trace output. */ TRACE_DEBUG_IDX, @@ -105,6 +109,7 @@ enum { #define TRACE_vpu (1 << TRACE_VPU_IDX) #define TRACE_branch (1 << TRACE_BRANCH_IDX) #define TRACE_syscall (1 << TRACE_SYSCALL_IDX) +#define TRACE_register (1 << TRACE_REGISTER_IDX) #define TRACE_debug (1 << TRACE_DEBUG_IDX) /* Return non-zero if tracing of idx is enabled (compiled in). */ @@ -125,6 +130,7 @@ enum { #define WITH_TRACE_VPU_P WITH_TRACE_P (TRACE_VPU_IDX) #define WITH_TRACE_BRANCH_P WITH_TRACE_P (TRACE_BRANCH_IDX) #define WITH_TRACE_SYSCALL_P WITH_TRACE_P (TRACE_SYSCALL_IDX) +#define WITH_TRACE_REGISTER_P WITH_TRACE_P (TRACE_REGISTER_IDX) #define WITH_TRACE_DEBUG_P WITH_TRACE_P (TRACE_DEBUG_IDX) /* Tracing install handler. */ @@ -210,6 +216,7 @@ typedef struct _trace_data { #define STRACE_VPU_P(sd) STRACE_P (sd, TRACE_VPU_IDX) #define STRACE_BRANCH_P(sd) STRACE_P (sd, TRACE_BRANCH_IDX) #define STRACE_SYSCALL_P(sd) STRACE_P (sd, TRACE_SYSCALL_IDX) +#define STRACE_REGISTER_P(sd) STRACE_P (sd, TRACE_REGISTER_IDX) #define STRACE_DEBUG_P(sd) STRACE_P (sd, TRACE_DEBUG_IDX) /* Helper functions for printing messages. */ @@ -231,6 +238,7 @@ typedef struct _trace_data { #define STRACE_VPU(sd, fmt, args...) STRACE (sd, TRACE_VPU_IDX, fmt, ## args) #define STRACE_BRANCH(sd, fmt, args...) STRACE (sd, TRACE_BRANCH_IDX, fmt, ## args) #define STRACE_SYSCALL(sd, fmt, args...) STRACE (sd, TRACE_SYSCALL_IDX, fmt, ## args) +#define STRACE_REGISTER(sd, fmt, args...) STRACE (sd, TRACE_REGISTER_IDX, fmt, ## args) #define STRACE_DEBUG(sd, fmt, args...) STRACE (sd, TRACE_DEBUG_IDX, fmt, ## args) /* CPU tracing support. */ @@ -256,6 +264,7 @@ typedef struct _trace_data { #define TRACE_VPU_P(cpu) TRACE_P (cpu, TRACE_VPU_IDX) #define TRACE_BRANCH_P(cpu) TRACE_P (cpu, TRACE_BRANCH_IDX) #define TRACE_SYSCALL_P(cpu) TRACE_P (cpu, TRACE_SYSCALL_IDX) +#define TRACE_REGISTER_P(cpu) TRACE_P (cpu, TRACE_REGISTER_IDX) #define TRACE_DEBUG_P(cpu) TRACE_P (cpu, TRACE_DEBUG_IDX) /* Helper functions for printing messages. */ @@ -277,6 +286,7 @@ typedef struct _trace_data { #define TRACE_VPU(cpu, fmt, args...) TRACE (cpu, TRACE_VPU_IDX, fmt, ## args) #define TRACE_BRANCH(cpu, fmt, args...) TRACE (cpu, TRACE_BRANCH_IDX, fmt, ## args) #define TRACE_SYSCALL(cpu, fmt, args...) TRACE (cpu, TRACE_SYSCALL_IDX, fmt, ## args) +#define TRACE_REGISTER(cpu, fmt, args...) TRACE (cpu, TRACE_REGISTER_IDX, fmt, ## args) #define TRACE_DEBUG(cpu, fmt, args...) TRACE (cpu, TRACE_DEBUG_IDX, fmt, ## args) /* Tracing functions. */ diff --git a/sim/msp430/ChangeLog b/sim/msp430/ChangeLog index fa59f270be1..08da33dc2da 100644 --- a/sim/msp430/ChangeLog +++ b/sim/msp430/ChangeLog @@ -1,3 +1,8 @@ +2015-06-24 Mike Frysinger + + * msp430-sim.c (trace_reg_put): Change TRACE_VPU to TRACE_REGISTER. + (trace_reg_get): Likewise. + 2015-06-23 Mike Frysinger * configure: Regenerate. diff --git a/sim/msp430/msp430-sim.c b/sim/msp430/msp430-sim.c index 931573e1afe..f32cb69030c 100644 --- a/sim/msp430/msp430-sim.c +++ b/sim/msp430/msp430-sim.c @@ -303,14 +303,14 @@ register_names[] = static void trace_reg_put (SIM_DESC sd, int n, unsigned int v) { - TRACE_VPU (MSP430_CPU (sd), "PUT: %#x -> %s", v, register_names[n]); + TRACE_REGISTER (MSP430_CPU (sd), "PUT: %#x -> %s", v, register_names[n]); REG (n) = v; } static unsigned int trace_reg_get (SIM_DESC sd, int n) { - TRACE_VPU (MSP430_CPU (sd), "GET: %s -> %#x", register_names[n], REG (n)); + TRACE_REGISTER (MSP430_CPU (sd), "GET: %s -> %#x", register_names[n], REG (n)); return REG (n); } -- 2.30.2