diff options
author | Michael Meissner <gnu@the-meissners.org> | 1997-05-06 10:21:57 +0000 |
---|---|---|
committer | Michael Meissner <gnu@the-meissners.org> | 1997-05-06 10:21:57 +0000 |
commit | a77241718f660b81eaa8e85c9b66689101654a97 (patch) | |
tree | c699d6e22858b0ef9bc6d7ca5a8a1f33b619c853 /sim/common | |
parent | 0239838be49dd5b718c2e22ce4a02651c7ed6de5 (diff) | |
download | gdb-a77241718f660b81eaa8e85c9b66689101654a97.zip gdb-a77241718f660b81eaa8e85c9b66689101654a97.tar.gz gdb-a77241718f660b81eaa8e85c9b66689101654a97.tar.bz2 |
Enable --trace-linenum support
Diffstat (limited to 'sim/common')
-rw-r--r-- | sim/common/ChangeLog | 13 | ||||
-rw-r--r-- | sim/common/sim-trace.c | 97 | ||||
-rw-r--r-- | sim/common/sim-trace.h | 6 |
3 files changed, 112 insertions, 4 deletions
diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog index e8c67fc..f83108a 100644 --- a/sim/common/ChangeLog +++ b/sim/common/ChangeLog @@ -1,3 +1,16 @@ +Tue May 6 06:14:01 1997 Mike Meissner <meissner@cygnus.com> + + * sim-trace.c (toplevel): Include bfd.h. + (trace_options): Note that --trace-linenum also turns on + --trace-insn. + (trace_option_handler): If --trace-linenum, also turn on + --trace-insn. + (trace_one_insn): New function to trace an instruction. Support + --trace-linenum. + + * sim-trace.h (TRACE_LINENUM_P): Define macro. + (trace_one_insn): Declare function. + Mon May 5 14:08:34 1997 Mike Meissner <meissner@cygnus.com> * sim-trace.h (__attribute__): Define as nothing if not GNU C or diff --git a/sim/common/sim-trace.c b/sim/common/sim-trace.c index b4f7704..d6d85f8 100644 --- a/sim/common/sim-trace.c +++ b/sim/common/sim-trace.c @@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "sim-main.h" #include "sim-io.h" #include "sim-options.h" +#include "bfd.h" #ifdef HAVE_STRING_H #include <string.h> @@ -30,6 +31,18 @@ with this program; if not, write to the Free Software Foundation, Inc., #endif #endif +#ifndef SIZE_LOCATION +#define SIZE_LOCATION 20 +#endif + +#ifndef SIZE_PC +#define SIZE_PC 6 +#endif + +#ifndef SIZE_LINE_NUMBER +#define SIZE_LINE_NUMBER 4 +#endif + static MODULE_UNINSTALL_FN trace_uninstall; static DECLARE_OPTION_HANDLER (trace_option_handler); @@ -61,7 +74,7 @@ static const OPTION trace_options[] = '\0', NULL, "Perform instruction extraction tracing", trace_option_handler }, { {"trace-linenum", no_argument, NULL, OPTION_TRACE_LINENUM}, - '\0', NULL, "Perform line number tracing", + '\0', NULL, "Perform line number tracing (implies --trace-insn)", trace_option_handler }, { {"trace-memory", no_argument, NULL, OPTION_TRACE_MEMORY}, '\0', NULL, "Perform memory tracing", @@ -135,11 +148,14 @@ trace_option_handler (sd, opt, arg) break; case OPTION_TRACE_LINENUM : - if (WITH_TRACE_LINENUM_P) + if (WITH_TRACE_LINENUM_P && WITH_TRACE_INSN_P) for (n = 0; n < MAX_NR_PROCESSORS; ++n) - CPU_TRACE_FLAGS (STATE_CPU (sd, n))[TRACE_LINENUM_IDX] = 1; + { + CPU_TRACE_FLAGS (STATE_CPU (sd, n))[TRACE_LINENUM_IDX] = 1; + CPU_TRACE_FLAGS (STATE_CPU (sd, n))[TRACE_INSN_IDX] = 1; + } else - sim_io_eprintf (sd, "Line number tracing not compiled in, `--trace-linenum' ignored\n"); + sim_io_eprintf (sd, "Line number or instruction tracing not compiled in, `--trace-linenum' ignored\n"); break; case OPTION_TRACE_MEMORY : @@ -246,6 +262,79 @@ trace_uninstall (SIM_DESC sd) } void +trace_one_insn (SIM_DESC sd, sim_cpu *cpu, const char *filename, + int linenum, int idecode, address_word pc, const char *name) +{ + if (idecode) + trace_printf(sd, cpu, "%s:%-*d 0x%.*lx (decode) %s\n", + filename, + SIZE_LINE_NUMBER, linenum, + SIZE_PC, (long)pc, + name); + + else if (!TRACE_LINENUM_P (cpu)) + trace_printf(sd, cpu, "%s:%-*d 0x%.*lx %s\n", + filename, + SIZE_LINE_NUMBER, linenum, + SIZE_PC, (long)pc, + name); + + else + { + char buf[256]; + + buf[0] = 0; + if (STATE_TEXT_SECTION (CPU_STATE (cpu)) + && pc >= STATE_TEXT_START (CPU_STATE (cpu)) + && pc < STATE_TEXT_END (CPU_STATE (cpu))) + { + const char *pc_filename = (const char *)0; + const char *pc_function = (const char *)0; + unsigned int pc_linenum = 0; + + if (bfd_find_nearest_line (STATE_PROG_BFD (CPU_STATE (cpu)), + STATE_TEXT_SECTION (CPU_STATE (cpu)), + (struct symbol_cache_entry **) 0, + pc - STATE_TEXT_START (CPU_STATE (cpu)), + &pc_filename, &pc_function, &pc_linenum)) + { + char *p = buf; + if (pc_linenum) + { + sprintf (p, "#%-*d ", SIZE_LINE_NUMBER, pc_linenum); + p += strlen (p); + } + else + { + sprintf (p, "%-*s ", SIZE_LINE_NUMBER+1, "---"); + p += SIZE_LINE_NUMBER+2; + } + + if (pc_function) + { + sprintf (p, "%s ", pc_function); + p += strlen (p); + } + else if (filename) + { + char *q = (char *) strrchr (filename, '/'); + sprintf (p, "%s ", (q) ? q+1 : filename); + p += strlen (p); + } + + if (*p == ' ') + *p = '\0'; + } + } + + trace_printf (sd, cpu, "0x%.*x %-*.*s %s\n", + SIZE_PC, (unsigned) pc, + SIZE_LOCATION, SIZE_LOCATION, buf, + name); + } +} + +void trace_printf VPARAMS ((SIM_DESC sd, sim_cpu *cpu, const char *fmt, ...)) { #ifndef __STDC__ diff --git a/sim/common/sim-trace.h b/sim/common/sim-trace.h index b400b2d..91d0be6 100644 --- a/sim/common/sim-trace.h +++ b/sim/common/sim-trace.h @@ -106,11 +106,17 @@ struct _sim_cpu; /* Non-zero if "--trace-insn" specified for CPU. */ #define TRACE_INSN_P(cpu) TRACE_P (cpu, TRACE_INSN_IDX) +/* Non-zero if "--trace-linenum" specified for CPU. */ +#define TRACE_LINENUM_P(cpu) TRACE_P (cpu, TRACE_LINENUM_IDX) /* Non-zero if "--trace-decode" specified for CPU. */ #define TRACE_DECODE_P(cpu) TRACE_P (cpu, TRACE_DECODE_IDX) /* Non-zero if "--trace-fpu" specified for CPU. */ #define TRACE_FPU_P(cpu) TRACE_P (cpu, TRACE_FPU_IDX) +extern void trace_one_insn PARAMS ((SIM_DESC, sim_cpu *, const char *, + int, int, address_word, + const char *name)); + extern void trace_printf PARAMS ((SIM_DESC, sim_cpu *, const char *, ...)) __attribute__((format (printf, 3, 4))); |