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.
This commit is contained in:
Mike Frysinger 2015-06-24 19:37:21 +05:45
parent cf304b56ca
commit fa8f87e53b
8 changed files with 56 additions and 42 deletions

View File

@ -1,3 +1,8 @@
2015-06-24 Mike Frysinger <vapier@gentoo.org>
* interp.c (trace_register): Delete.
* sim-main.h (trace_register, TRACE_REGISTER, TRACE_REG): Delete.
2015-06-23 Mike Frysinger <vapier@gentoo.org>
* configure: Regenerate.

View File

@ -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

View File

@ -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)

View File

@ -1,3 +1,13 @@
2015-06-24 Mike Frysinger <vapier@gentoo.org>
* 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 <vapier@gentoo.org>
* sim-trace.h (STRACE, STRACE_INSN, STRACE_DECODE, STRACE_EXTRACT,

View File

@ -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;

View File

@ -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. */

View File

@ -1,3 +1,8 @@
2015-06-24 Mike Frysinger <vapier@gentoo.org>
* msp430-sim.c (trace_reg_put): Change TRACE_VPU to TRACE_REGISTER.
(trace_reg_get): Likewise.
2015-06-23 Mike Frysinger <vapier@gentoo.org>
* configure: Regenerate.

View File

@ -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);
}