diff options
author | Doug Evans <dje@google.com> | 1998-12-05 07:56:13 +0000 |
---|---|---|
committer | Doug Evans <dje@google.com> | 1998-12-05 07:56:13 +0000 |
commit | b61e2e146a85a1d93d1ad78f923005c8e4e2d7e4 (patch) | |
tree | ed328bc946a1dcc9e96bbb97e0449ec591066e21 /sim/common/sim-trace.c | |
parent | e8116eca81418b425f8a9e668b309fc4d594f8b1 (diff) | |
download | gdb-b61e2e146a85a1d93d1ad78f923005c8e4e2d7e4.zip gdb-b61e2e146a85a1d93d1ad78f923005c8e4e2d7e4.tar.gz gdb-b61e2e146a85a1d93d1ad78f923005c8e4e2d7e4.tar.bz2 |
* cgen-defs.h: New file, old cgen-sim.h.
* cgen-sim.h: Simple header that includes others.
* sim-arange.c: New file.
* sim-arange.h: New file.
* sim-basics.h: Include it.
* Make-common.in (SIM_NEW_COMMON_OBJS): Add sim-arange.o.
(sim-arange.o): Add rule for.
* sim-cpu.h (sim_cpu_msg_prefix): Add prototype.
(sim_io_eprintf_cpu): Add prototype.
* sim-inline.h (HAVE_INLINE): Define if GNUC.
(INLINE2): New macro.
(EXTERN_INLINE): New macro.
* sim-module.c (sim_post_argv_init): Initialize cpu backlink
before calling module init fns.
* sim-profile.h (OPTION_PROFILE_*): Move into enum.
(profile_init): New function.
(profile_options): New option --profile-range.
(profile_option_handler): Handle --profile-range.
(profile_print_insn): Qualify address range specific section titles.
(profile_print_addr_ranges): New function.
(profile_info): Print address ranges if specified.
(profile_install): Set profile_init init fn.
* sim-profile.h (PROFILE_DATA): New member `range'.
* sim-trace.c (trace_init): New function.
(trace_options): New option --trace-range.
(trace_option_handler): Handle --trace-range.
(trace_install): Set trace_init init fn.
* sim-trace.h (TRACE_DATA): New member `range'.
* sim-utils.c (sim_cpu_msg_prefix): New function.
(sim_io_eprintf_cpu): New function.
* cgen-engine.h (PC_IN_TRACE_RANGE_P): New macro.
(PC_IN_PROFILE_RANGE_P): New macro.
* cgen-trace.c (trace_insn_init): Set current_insn to NULL.
(trace_insn_fini): New arg abuf. All callers updated.
Exit early if trace_insn not called. Check ARGBUF_PROFILE_P before
printing cycle counts.
* cgen-trace.h (trace_insn_fini): Update prototype.
(TRACE_RESULT_P): New macro.
(TRACE_INSN_INIT,TRACE_INSN_FINI): New arg abuf. All callers updated.
(TRACE_INSN): Check ARGBUF_TRACE_P.
(TRACE_EXTRACT,TRACE_RESULT): New arg abuf. All callers updated.
* cgen-types.h (SIM_INLINE): Delete.
(SIM_HAVE_MODEL,SIM_HAVE_ADDR_RANGE): Define.
* cgen-utils.c: Don't include cgen-engine.h
* genmloop.sh (@cpu@_fill_argbuf): New function.
(@cpu@_fill_argbuf_tp): New function.
(@cpu@_emit_before,@cpu@_emit_after): New functions.
(@cpu@_pbb_begin): Prefix cti_sc,insn_count with '_'.
(SET_CTI_VPC,SET_INSN_COUNT): Update.
(@cpu@_pbb_before): Check ARGBUF_PROFILE_P before calling
doing profiling. Update call to TRACE_INSN_INIT,TRACE_INSN_FINI.
(@cpu@_pbb_after): Check ARGBUF_PROFILE_P before calling
doing profiling. Update call to TRACE_INSN_FINI.
Diffstat (limited to 'sim/common/sim-trace.c')
-rw-r--r-- | sim/common/sim-trace.c | 188 |
1 files changed, 170 insertions, 18 deletions
diff --git a/sim/common/sim-trace.c b/sim/common/sim-trace.c index 2e9e979..2319670 100644 --- a/sim/common/sim-trace.c +++ b/sim/common/sim-trace.c @@ -22,7 +22,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "sim-io.h" #include "sim-options.h" #include "sim-fpu.h" + #include "bfd.h" +#include "libiberty.h" #include "sim-assert.h" @@ -50,6 +52,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #define SIZE_LINE_NUMBER 4 #endif +static MODULE_INIT_FN trace_init; static MODULE_UNINSTALL_FN trace_uninstall; static DECLARE_OPTION_HANDLER (trace_option_handler); @@ -67,6 +70,8 @@ enum { OPTION_TRACE_FPU, OPTION_TRACE_BRANCH, OPTION_TRACE_SEMANTICS, + OPTION_TRACE_RANGE, + OPTION_TRACE_FUNCTION, OPTION_TRACE_DEBUG, OPTION_TRACE_FILE }; @@ -113,6 +118,16 @@ static const OPTION trace_options[] = { {"trace-events", optional_argument, NULL, OPTION_TRACE_EVENTS}, '\0', "on|off", "Trace events", trace_option_handler }, +#ifdef SIM_HAVE_ADDR_RANGE + { {"trace-range", required_argument, NULL, OPTION_TRACE_RANGE}, + '\0', "START,END", "Specify range of addresses for instruction tracing", + trace_option_handler }, +#if 0 /*wip*/ + { {"trace-function", required_argument, NULL, OPTION_TRACE_FUNCTION}, + '\0', "FUNCTION", "Specify function to trace", + trace_option_handler }, +#endif +#endif { {"trace-debug", optional_argument, NULL, OPTION_TRACE_DEBUG}, '\0', "on|off", "Add information useful for debugging the simulator to the tracing output", trace_option_handler }, @@ -152,6 +167,7 @@ set_trace_option_mask (sd, name, mask, arg) } } + /* update applicable trace bits */ for (trace_nr = 0; trace_nr < MAX_TRACE_VALUES; ++trace_nr) { if ((mask & (1 << trace_nr)) == 0) @@ -175,6 +191,28 @@ set_trace_option_mask (sd, name, mask, arg) } } + /* Re-compute the cpu trace summary. */ + if (trace_val) + { + for (cpu_nr = 0; cpu_nr < MAX_NR_PROCESSORS; cpu_nr++) + CPU_TRACE_DATA (STATE_CPU (sd, cpu_nr))->trace_any_p = 1; + } + else + { + for (cpu_nr = 0; cpu_nr < MAX_NR_PROCESSORS; cpu_nr++) + { + CPU_TRACE_DATA (STATE_CPU (sd, cpu_nr))->trace_any_p = 0; + for (trace_nr = 0; trace_nr < MAX_TRACE_VALUES; ++trace_nr) + { + if (CPU_TRACE_FLAGS (STATE_CPU (sd, cpu_nr))[trace_nr]) + { + CPU_TRACE_DATA (STATE_CPU (sd, cpu_nr))->trace_any_p = 1; + break; + } + } + } + } + return SIM_RC_OK; } @@ -196,6 +234,7 @@ trace_option_handler (SIM_DESC sd, sim_cpu *cpu, int opt, char *arg, int is_command) { int n; + int cpu_nr; switch (opt) { @@ -303,6 +342,42 @@ trace_option_handler (SIM_DESC sd, sim_cpu *cpu, int opt, sim_io_eprintf (sd, "Alu, fpu, memory, and/or branch tracing not compiled in, `--trace-semantics' ignored\n"); break; +#ifdef SIM_HAVE_ADDR_RANGE + case OPTION_TRACE_RANGE : + if (WITH_TRACE) + { + char *chp = arg; + unsigned long start,end; + start = strtoul (chp, &chp, 0); + if (*chp != ',') + { + sim_io_eprintf (sd, "--trace-range missing END argument\n"); + return SIM_RC_FAIL; + } + end = strtoul (chp + 1, NULL, 0); + /* FIXME: Argument validation. */ + if (cpu != NULL) + sim_addr_range_add (TRACE_RANGE (CPU_PROFILE_DATA (cpu)), + start, end); + else + for (cpu_nr = 0; cpu_nr < MAX_NR_PROCESSORS; ++cpu_nr) + sim_addr_range_add (TRACE_RANGE (CPU_TRACE_DATA (STATE_CPU (sd, cpu_nr))), + start, end); + } + else + sim_io_eprintf (sd, "Tracing not compiled in, `--trace-range' ignored\n"); + break; + + case OPTION_TRACE_FUNCTION : + if (WITH_TRACE) + { + /*wip: need to compute function range given name*/ + } + else + sim_io_eprintf (sd, "Tracing not compiled in, `--trace-function' ignored\n"); + break; +#endif /* SIM_HAVE_ADDR_RANGE */ + case OPTION_TRACE_DEBUG : if (WITH_TRACE_DEBUG_P) return set_trace_option (sd, "-debug", TRACE_DEBUG_IDX, arg); @@ -346,10 +421,39 @@ trace_install (SIM_DESC sd) for (i = 0; i < MAX_NR_PROCESSORS; ++i) memset (CPU_TRACE_DATA (STATE_CPU (sd, i)), 0, sizeof (* CPU_TRACE_DATA (STATE_CPU (sd, i)))); + sim_module_add_init_fn (sd, trace_init); sim_module_add_uninstall_fn (sd, trace_uninstall); return SIM_RC_OK; } +static SIM_RC +trace_init (SIM_DESC sd) +{ +#ifdef SIM_HAVE_ADDR_RANGE + /* Check if a range has been specified without specifying what to + collect. */ + { + int i; + + for (i = 0; i < MAX_NR_PROCESSORS; ++i) + { + sim_cpu *cpu = STATE_CPU (sd, i); + + if (ADDR_RANGE_RANGES (TRACE_RANGE (CPU_TRACE_DATA (cpu))) + && ! TRACE_INSN_P (cpu)) + { + sim_io_eprintf_cpu (cpu, "Tracing address range specified without --trace-insn.\n"); + sim_io_eprintf_cpu (cpu, "Address range ignored.\n"); + sim_addr_range_delete (TRACE_RANGE (CPU_TRACE_DATA (cpu)), + 0, ~ (address_word) 0); + } + } + } +#endif + + return SIM_RC_OK; +} + static void trace_uninstall (SIM_DESC sd) { @@ -458,15 +562,29 @@ print_data (SIM_DESC sd, { /* FIXME: Assumes sizeof float == 4; sizeof double == 8 */ case 4: - sim_fpu_32to (&fp, * (unsigned32*) data); + sim_fpu_32to (&fp, *(unsigned32*)data); break; case 8: - sim_fpu_64to (&fp, * (unsigned32*) data); + sim_fpu_64to (&fp, *(unsigned64*)data); break; default: abort (); } trace_printf (sd, cpu, " %8g", sim_fpu_2d (&fp)); + switch (size) + { + case 4: + trace_printf (sd, cpu, " (0x%08lx)", + (long) *(unsigned32*)data); + break; + case 8: + trace_printf (sd, cpu, " (0x%08lx%08lx)", + (long) (*(unsigned64*)data >> 32), + (long) (*(unsigned64*)data)); + break; + default: + abort (); + } break; } case trace_fmt_fpu: @@ -544,6 +662,7 @@ trace_results (SIM_DESC sd, void trace_prefix (SIM_DESC sd, sim_cpu *cpu, + sim_cia cia, address_word pc, int line_p, const char *filename, @@ -555,9 +674,15 @@ trace_prefix (SIM_DESC sd, va_list ap; char *prefix = TRACE_PREFIX (data); char *chp; + /* FIXME: The TRACE_PREFIX_WIDTH should be determined at build time using + known information about the disassembled instructions. */ +#ifndef TRACE_PREFIX_WIDTH +#define TRACE_PREFIX_WIDTH 48 +#endif + int width = TRACE_PREFIX_WIDTH; /* if the previous trace data wasn't flushed, flush it now with a - note indicating that this occured. */ + note indicating that the trace was incomplete. */ if (TRACE_IDX (data) != 0) { int last_input = TRACE_INPUT_IDX (data); @@ -567,12 +692,23 @@ trace_prefix (SIM_DESC sd, TRACE_IDX (data) = 0; TRACE_INPUT_IDX (data) = 0; + /* Create the text prefix for this new instruction: */ if (!line_p) { - sprintf (prefix, "%s:%-*d 0x%.*lx ", - filename, - SIZE_LINE_NUMBER, linenum, - SIZE_PC, (long)pc); + if (filename) + { + sprintf (prefix, "%s:%-*d 0x%.*lx ", + filename, + SIZE_LINE_NUMBER, linenum, + SIZE_PC, (long) pc); + } + else + { + sprintf (prefix, "0x%.*lx ", + SIZE_PC, (long) pc); + /* Shrink the width by the amount that we didn't print. */ + width -= SIZE_LINE_NUMBER + SIZE_PC + 8; + } chp = strchr (prefix, '\0'); va_start (ap, fmt); vsprintf (chp, fmt, ap); @@ -602,16 +738,17 @@ trace_prefix (SIM_DESC sd, symsize = bfd_get_symtab_upper_bound (abfd); if (symsize < 0) { - sim_engine_abort (sd, cpu, 0, "could not read symbols\n"); + sim_engine_abort (sd, cpu, cia, "could not read symbols"); } asymbols = (asymbol **) xmalloc (symsize); symbol_count = bfd_canonicalize_symtab (abfd, asymbols); if (symbol_count < 0) { - sim_engine_abort (sd, cpu, 0, "could not canonicalize symbols\n"); + sim_engine_abort (sd, cpu, cia, "could not canonicalize symbols"); } STATE_PROG_SYMS (CPU_STATE (cpu)) = asymbols; } + if (bfd_find_nearest_line (abfd, STATE_TEXT_SECTION (CPU_STATE (cpu)), asymbols, @@ -656,17 +793,12 @@ trace_prefix (SIM_DESC sd, va_end (ap); } - /* pad it out to TRACE_PREFIX_WIDTH. FIXME: The TRACE_PREFIX_WIDTH - should be determined at build time using known information about - the disassembled instructions */ -#ifndef TRACE_PREFIX_WIDTH -#define TRACE_PREFIX_WIDTH 48 -#endif + /* Pad it out to TRACE_PREFIX_WIDTH. */ chp = strchr (prefix, '\0'); - if (chp - prefix < TRACE_PREFIX_WIDTH) + if (chp - prefix < width) { - memset (chp, ' ', TRACE_PREFIX_WIDTH - (chp - prefix)); - chp = &prefix [TRACE_PREFIX_WIDTH]; + memset (chp, ' ', width - (chp - prefix)); + chp = &prefix [width]; *chp = '\0'; } strcpy (chp, " -"); @@ -986,6 +1118,24 @@ trace_result_fp1 (SIM_DESC sd, } void +trace_result_fp2 (SIM_DESC sd, + sim_cpu *cpu, + int trace_idx, + fp_word f0, + fp_word f1) +{ + TRACE_DATA *data = CPU_TRACE_DATA (cpu); + int last_input; + + /* Append any results to the end of the inputs */ + last_input = TRACE_INPUT_IDX (data); + save_data (sd, data, trace_fmt_fp, sizeof (f0), &f0); + save_data (sd, data, trace_fmt_fp, sizeof (f1), &f1); + + trace_results (sd, cpu, trace_idx, last_input); +} + +void trace_result_fpu1 (SIM_DESC sd, sim_cpu *cpu, int trace_idx, @@ -1056,6 +1206,8 @@ trace_vprintf (SIM_DESC sd, sim_cpu *cpu, const char *fmt, va_list ap) } } +/* The function trace_one_insn has been replaced by the function pair + trace_prefix() + trace_generic(). It is still used. */ void trace_one_insn (SIM_DESC sd, sim_cpu *cpu, address_word pc, int line_p, const char *filename, int linenum, |