1 /* Simulator tracing/debugging support.
2 Copyright (C) 1997-2014 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
5 This file is part of GDB, the GNU debugger.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "sim-options.h"
26 #include "libiberty.h"
28 #include "sim-assert.h"
46 #define SIZE_LOCATION 20
53 #ifndef SIZE_LINE_NUMBER
54 #define SIZE_LINE_NUMBER 4
57 static MODULE_INIT_FN trace_init;
58 static MODULE_UNINSTALL_FN trace_uninstall;
60 static DECLARE_OPTION_HANDLER (trace_option_handler);
63 OPTION_TRACE_INSN = OPTION_START,
74 OPTION_TRACE_SEMANTICS,
76 OPTION_TRACE_FUNCTION,
83 static const OPTION trace_options[] =
85 /* This table is organized to group related instructions together. */
86 { {"trace", optional_argument, NULL, 't'},
87 't', "on|off", "Trace useful things",
88 trace_option_handler, NULL },
89 { {"trace-insn", optional_argument, NULL, OPTION_TRACE_INSN},
90 '\0', "on|off", "Perform instruction tracing",
91 trace_option_handler, NULL },
92 { {"trace-decode", optional_argument, NULL, OPTION_TRACE_DECODE},
93 '\0', "on|off", "Trace instruction decoding",
94 trace_option_handler, NULL },
95 { {"trace-extract", optional_argument, NULL, OPTION_TRACE_EXTRACT},
96 '\0', "on|off", "Trace instruction extraction",
97 trace_option_handler, NULL },
98 { {"trace-linenum", optional_argument, NULL, OPTION_TRACE_LINENUM},
99 '\0', "on|off", "Perform line number tracing (implies --trace-insn)",
100 trace_option_handler, NULL },
101 { {"trace-memory", optional_argument, NULL, OPTION_TRACE_MEMORY},
102 '\0', "on|off", "Trace memory operations",
103 trace_option_handler, NULL },
104 { {"trace-alu", optional_argument, NULL, OPTION_TRACE_ALU},
105 '\0', "on|off", "Trace ALU operations",
106 trace_option_handler, NULL },
107 { {"trace-fpu", optional_argument, NULL, OPTION_TRACE_FPU},
108 '\0', "on|off", "Trace FPU operations",
109 trace_option_handler, NULL },
110 { {"trace-vpu", optional_argument, NULL, OPTION_TRACE_VPU},
111 '\0', "on|off", "Trace VPU operations",
112 trace_option_handler, NULL },
113 { {"trace-branch", optional_argument, NULL, OPTION_TRACE_BRANCH},
114 '\0', "on|off", "Trace branching",
115 trace_option_handler, NULL },
116 { {"trace-semantics", optional_argument, NULL, OPTION_TRACE_SEMANTICS},
117 '\0', "on|off", "Perform ALU, FPU, MEMORY, and BRANCH tracing",
118 trace_option_handler, NULL },
119 { {"trace-model", optional_argument, NULL, OPTION_TRACE_MODEL},
120 '\0', "on|off", "Include model performance data",
121 trace_option_handler, NULL },
122 { {"trace-core", optional_argument, NULL, OPTION_TRACE_CORE},
123 '\0', "on|off", "Trace core operations",
124 trace_option_handler, NULL },
125 { {"trace-events", optional_argument, NULL, OPTION_TRACE_EVENTS},
126 '\0', "on|off", "Trace events",
127 trace_option_handler, NULL },
128 { {"trace-syscall", optional_argument, NULL, OPTION_TRACE_SYSCALL},
129 '\0', "on|off", "Trace system calls",
130 trace_option_handler, NULL },
131 #ifdef SIM_HAVE_ADDR_RANGE
132 { {"trace-range", required_argument, NULL, OPTION_TRACE_RANGE},
133 '\0', "START,END", "Specify range of addresses for instruction tracing",
134 trace_option_handler, NULL },
136 { {"trace-function", required_argument, NULL, OPTION_TRACE_FUNCTION},
137 '\0', "FUNCTION", "Specify function to trace",
138 trace_option_handler, NULL },
141 { {"trace-debug", optional_argument, NULL, OPTION_TRACE_DEBUG},
142 '\0', "on|off", "Add information useful for debugging the simulator to the tracing output",
143 trace_option_handler, NULL },
144 { {"trace-file", required_argument, NULL, OPTION_TRACE_FILE},
145 '\0', "FILE NAME", "Specify tracing output file",
146 trace_option_handler, NULL },
147 { {NULL, no_argument, NULL, 0}, '\0', NULL, NULL, NULL, NULL }
150 /* Set/reset the trace options indicated in MASK. */
153 set_trace_option_mask (SIM_DESC sd, const char *name, int mask, const char *arg)
161 if (strcmp (arg, "yes") == 0
162 || strcmp (arg, "on") == 0
163 || strcmp (arg, "1") == 0)
165 else if (strcmp (arg, "no") == 0
166 || strcmp (arg, "off") == 0
167 || strcmp (arg, "0") == 0)
171 sim_io_eprintf (sd, "Argument `%s' for `--trace%s' invalid, one of `on', `off', `yes', `no' expected\n", arg, name);
176 /* update applicable trace bits */
177 for (trace_nr = 0; trace_nr < MAX_TRACE_VALUES; ++trace_nr)
179 if ((mask & (1 << trace_nr)) == 0)
182 /* Set non-cpu specific values. */
185 case TRACE_EVENTS_IDX:
186 STATE_EVENTS (sd)->trace = trace_val;
188 case TRACE_DEBUG_IDX:
189 STATE_TRACE_FLAGS (sd)[trace_nr] = trace_val;
193 /* Set cpu values. */
194 for (cpu_nr = 0; cpu_nr < MAX_NR_PROCESSORS; cpu_nr++)
196 CPU_TRACE_FLAGS (STATE_CPU (sd, cpu_nr))[trace_nr] = trace_val;
200 /* Re-compute the cpu trace summary. */
203 for (cpu_nr = 0; cpu_nr < MAX_NR_PROCESSORS; cpu_nr++)
204 CPU_TRACE_DATA (STATE_CPU (sd, cpu_nr))->trace_any_p = 1;
208 for (cpu_nr = 0; cpu_nr < MAX_NR_PROCESSORS; cpu_nr++)
210 CPU_TRACE_DATA (STATE_CPU (sd, cpu_nr))->trace_any_p = 0;
211 for (trace_nr = 0; trace_nr < MAX_TRACE_VALUES; ++trace_nr)
213 if (CPU_TRACE_FLAGS (STATE_CPU (sd, cpu_nr))[trace_nr])
215 CPU_TRACE_DATA (STATE_CPU (sd, cpu_nr))->trace_any_p = 1;
225 /* Set one trace option based on its IDX value. */
228 set_trace_option (SIM_DESC sd, const char *name, int idx, const char *arg)
230 return set_trace_option_mask (sd, name, 1 << idx, arg);
235 trace_option_handler (SIM_DESC sd, sim_cpu *cpu, int opt,
236 char *arg, int is_command)
244 sim_io_eprintf (sd, "Tracing not compiled in, `-t' ignored\n");
246 return set_trace_option_mask (sd, "trace", TRACE_USEFUL_MASK, arg);
249 case OPTION_TRACE_INSN :
250 if (WITH_TRACE_INSN_P)
251 return set_trace_option (sd, "-insn", TRACE_INSN_IDX, arg);
253 sim_io_eprintf (sd, "Instruction tracing not compiled in, `--trace-insn' ignored\n");
256 case OPTION_TRACE_DECODE :
257 if (WITH_TRACE_DECODE_P)
258 return set_trace_option (sd, "-decode", TRACE_DECODE_IDX, arg);
260 sim_io_eprintf (sd, "Decode tracing not compiled in, `--trace-decode' ignored\n");
263 case OPTION_TRACE_EXTRACT :
264 if (WITH_TRACE_EXTRACT_P)
265 return set_trace_option (sd, "-extract", TRACE_EXTRACT_IDX, arg);
267 sim_io_eprintf (sd, "Extract tracing not compiled in, `--trace-extract' ignored\n");
270 case OPTION_TRACE_LINENUM :
271 if (WITH_TRACE_LINENUM_P && WITH_TRACE_INSN_P)
273 if (set_trace_option (sd, "-linenum", TRACE_LINENUM_IDX, arg) != SIM_RC_OK
274 || set_trace_option (sd, "-linenum", TRACE_INSN_IDX, arg) != SIM_RC_OK)
278 sim_io_eprintf (sd, "Line number or instruction tracing not compiled in, `--trace-linenum' ignored\n");
281 case OPTION_TRACE_MEMORY :
282 if (WITH_TRACE_MEMORY_P)
283 return set_trace_option (sd, "-memory", TRACE_MEMORY_IDX, arg);
285 sim_io_eprintf (sd, "Memory tracing not compiled in, `--trace-memory' ignored\n");
288 case OPTION_TRACE_MODEL :
289 if (WITH_TRACE_MODEL_P)
290 return set_trace_option (sd, "-model", TRACE_MODEL_IDX, arg);
292 sim_io_eprintf (sd, "Model tracing not compiled in, `--trace-model' ignored\n");
295 case OPTION_TRACE_ALU :
296 if (WITH_TRACE_ALU_P)
297 return set_trace_option (sd, "-alu", TRACE_ALU_IDX, arg);
299 sim_io_eprintf (sd, "ALU tracing not compiled in, `--trace-alu' ignored\n");
302 case OPTION_TRACE_CORE :
303 if (WITH_TRACE_CORE_P)
304 return set_trace_option (sd, "-core", TRACE_CORE_IDX, arg);
306 sim_io_eprintf (sd, "CORE tracing not compiled in, `--trace-core' ignored\n");
309 case OPTION_TRACE_EVENTS :
310 if (WITH_TRACE_EVENTS_P)
311 return set_trace_option (sd, "-events", TRACE_EVENTS_IDX, arg);
313 sim_io_eprintf (sd, "EVENTS tracing not compiled in, `--trace-events' ignored\n");
316 case OPTION_TRACE_FPU :
317 if (WITH_TRACE_FPU_P)
318 return set_trace_option (sd, "-fpu", TRACE_FPU_IDX, arg);
320 sim_io_eprintf (sd, "FPU tracing not compiled in, `--trace-fpu' ignored\n");
323 case OPTION_TRACE_VPU :
324 if (WITH_TRACE_VPU_P)
325 return set_trace_option (sd, "-vpu", TRACE_VPU_IDX, arg);
327 sim_io_eprintf (sd, "VPU tracing not compiled in, `--trace-vpu' ignored\n");
330 case OPTION_TRACE_BRANCH :
331 if (WITH_TRACE_BRANCH_P)
332 return set_trace_option (sd, "-branch", TRACE_BRANCH_IDX, arg);
334 sim_io_eprintf (sd, "Branch tracing not compiled in, `--trace-branch' ignored\n");
337 case OPTION_TRACE_SYSCALL :
338 if (WITH_TRACE_SYSCALL_P)
339 return set_trace_option (sd, "-syscall", TRACE_SYSCALL_IDX, arg);
341 sim_io_eprintf (sd, "System call tracing not compiled in, `--trace-syscall' ignored\n");
344 case OPTION_TRACE_SEMANTICS :
347 && WITH_TRACE_MEMORY_P
348 && WITH_TRACE_BRANCH_P)
350 if (set_trace_option (sd, "-semantics", TRACE_ALU_IDX, arg) != SIM_RC_OK
351 || set_trace_option (sd, "-semantics", TRACE_FPU_IDX, arg) != SIM_RC_OK
352 || set_trace_option (sd, "-semantics", TRACE_VPU_IDX, arg) != SIM_RC_OK
353 || set_trace_option (sd, "-semantics", TRACE_MEMORY_IDX, arg) != SIM_RC_OK
354 || set_trace_option (sd, "-semantics", TRACE_BRANCH_IDX, arg) != SIM_RC_OK)
358 sim_io_eprintf (sd, "Alu, fpu, memory, and/or branch tracing not compiled in, `--trace-semantics' ignored\n");
361 #ifdef SIM_HAVE_ADDR_RANGE
362 case OPTION_TRACE_RANGE :
367 unsigned long start,end;
368 start = strtoul (chp, &chp, 0);
371 sim_io_eprintf (sd, "--trace-range missing END argument\n");
374 end = strtoul (chp + 1, NULL, 0);
375 /* FIXME: Argument validation. */
377 sim_addr_range_add (TRACE_RANGE (CPU_PROFILE_DATA (cpu)),
380 for (cpu_nr = 0; cpu_nr < MAX_NR_PROCESSORS; ++cpu_nr)
381 sim_addr_range_add (TRACE_RANGE (CPU_TRACE_DATA (STATE_CPU (sd, cpu_nr))),
385 sim_io_eprintf (sd, "Tracing not compiled in, `--trace-range' ignored\n");
388 case OPTION_TRACE_FUNCTION :
391 /*wip: need to compute function range given name*/
394 sim_io_eprintf (sd, "Tracing not compiled in, `--trace-function' ignored\n");
396 #endif /* SIM_HAVE_ADDR_RANGE */
398 case OPTION_TRACE_DEBUG :
399 if (WITH_TRACE_DEBUG_P)
400 return set_trace_option (sd, "-debug", TRACE_DEBUG_IDX, arg);
402 sim_io_eprintf (sd, "Tracing debug support not compiled in, `--trace-debug' ignored\n");
405 case OPTION_TRACE_FILE :
407 sim_io_eprintf (sd, "Tracing not compiled in, `--trace-file' ignored\n");
410 FILE *f = fopen (arg, "w");
414 sim_io_eprintf (sd, "Unable to open trace output file `%s'\n", arg);
417 for (n = 0; n < MAX_NR_PROCESSORS; ++n)
418 TRACE_FILE (CPU_TRACE_DATA (STATE_CPU (sd, n))) = f;
419 TRACE_FILE (STATE_TRACE_DATA (sd)) = f;
427 /* Install tracing support. */
430 trace_install (SIM_DESC sd)
434 SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
436 sim_add_option_table (sd, NULL, trace_options);
437 memset (STATE_TRACE_DATA (sd), 0, sizeof (* STATE_TRACE_DATA (sd)));
438 for (i = 0; i < MAX_NR_PROCESSORS; ++i)
439 memset (CPU_TRACE_DATA (STATE_CPU (sd, i)), 0,
440 sizeof (* CPU_TRACE_DATA (STATE_CPU (sd, i))));
441 sim_module_add_init_fn (sd, trace_init);
442 sim_module_add_uninstall_fn (sd, trace_uninstall);
447 trace_init (SIM_DESC sd)
449 #ifdef SIM_HAVE_ADDR_RANGE
450 /* Check if a range has been specified without specifying what to
455 for (i = 0; i < MAX_NR_PROCESSORS; ++i)
457 sim_cpu *cpu = STATE_CPU (sd, i);
459 if (ADDR_RANGE_RANGES (TRACE_RANGE (CPU_TRACE_DATA (cpu)))
460 && ! TRACE_INSN_P (cpu))
462 sim_io_eprintf_cpu (cpu, "Tracing address range specified without --trace-insn.\n");
463 sim_io_eprintf_cpu (cpu, "Address range ignored.\n");
464 sim_addr_range_delete (TRACE_RANGE (CPU_TRACE_DATA (cpu)),
465 0, ~ (address_word) 0);
475 trace_uninstall (SIM_DESC sd)
478 FILE *sfile = TRACE_FILE (STATE_TRACE_DATA (sd));
483 for (i = 0; i < MAX_NR_PROCESSORS; ++i)
485 FILE *cfile = TRACE_FILE (CPU_TRACE_DATA (STATE_CPU (sd, i)));
486 if (cfile != NULL && cfile != sfile)
488 /* If output from different cpus is going to the same file,
489 avoid closing the file twice. */
490 for (j = 0; j < i; ++j)
491 if (TRACE_FILE (CPU_TRACE_DATA (STATE_CPU (sd, j))) == cfile)
499 /* compute the nr of trace data units consumed by data */
501 save_data_size (TRACE_DATA *data,
504 return ((size + sizeof (TRACE_INPUT_DATA (data) [0]) - 1)
505 / sizeof (TRACE_INPUT_DATA (data) [0]));
509 /* Archive DATA into the trace buffer */
511 save_data (SIM_DESC sd,
517 int i = TRACE_INPUT_IDX (data);
518 if (i == sizeof (TRACE_INPUT_FMT (data)))
519 sim_io_error (sd, "trace buffer overflow");
520 TRACE_INPUT_FMT (data) [i] = fmt;
521 TRACE_INPUT_SIZE (data) [i] = size;
522 memcpy (&TRACE_INPUT_DATA (data) [i], buf, size);
523 i += save_data_size (data, size);
524 TRACE_INPUT_IDX (data) = i;
528 print_data (SIM_DESC sd,
536 case trace_fmt_instruction_incomplete:
537 trace_printf (sd, cpu, " (instruction incomplete)");
544 case sizeof (unsigned32):
545 trace_printf (sd, cpu, " 0x%08lx", (long) * (unsigned32*) data);
547 case sizeof (unsigned64):
548 trace_printf (sd, cpu, " 0x%08lx%08lx",
549 (long) ((* (unsigned64*) data) >> 32),
550 (long) * (unsigned64*) data);
559 SIM_ASSERT (size == sizeof (int));
560 trace_printf (sd, cpu, " %-8s",
561 (* (int*) data) ? "true" : "false");
569 /* FIXME: Assumes sizeof float == 4; sizeof double == 8 */
571 sim_fpu_32to (&fp, *(unsigned32*)data);
574 sim_fpu_64to (&fp, *(unsigned64*)data);
579 trace_printf (sd, cpu, " %8g", sim_fpu_2d (&fp));
583 trace_printf (sd, cpu, " (0x%08lx)",
584 (long) *(unsigned32*)data);
587 trace_printf (sd, cpu, " (0x%08lx%08lx)",
588 (long) (*(unsigned64*)data >> 32),
589 (long) (*(unsigned64*)data));
597 /* FIXME: At present sim_fpu data is stored as a double */
598 trace_printf (sd, cpu, " %8g", * (double*) data);
600 case trace_fmt_string:
601 trace_printf (sd, cpu, " %-8s", (char*) data);
609 trace_idx_to_str (int trace_idx)
614 case TRACE_ALU_IDX: return "alu: ";
615 case TRACE_INSN_IDX: return "insn: ";
616 case TRACE_DECODE_IDX: return "decode: ";
617 case TRACE_EXTRACT_IDX: return "extract: ";
618 case TRACE_MEMORY_IDX: return "memory: ";
619 case TRACE_CORE_IDX: return "core: ";
620 case TRACE_EVENTS_IDX: return "events: ";
621 case TRACE_FPU_IDX: return "fpu: ";
622 case TRACE_BRANCH_IDX: return "branch: ";
623 case TRACE_SYSCALL_IDX: return "syscall: ";
624 case TRACE_VPU_IDX: return "vpu: ";
626 sprintf (num, "?%d?", trace_idx);
632 trace_results (SIM_DESC sd,
637 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
641 /* cross check trace_idx against TRACE_IDX (data)? */
644 trace_printf (sd, cpu, "%s %s",
645 trace_idx_to_str (TRACE_IDX (data)),
646 TRACE_PREFIX (data));
647 TRACE_IDX (data) = 0;
649 for (i = 0, nr_out = 0;
650 i < TRACE_INPUT_IDX (data);
651 i += save_data_size (data, TRACE_INPUT_SIZE (data) [i]), nr_out++)
655 int pad = (strlen (" 0x") + sizeof (unsigned_word) * 2);
656 int padding = pad * (3 - nr_out);
659 padding += strlen (" ::");
660 trace_printf (sd, cpu, "%*s", padding, " ::");
663 TRACE_INPUT_FMT (data) [i],
664 TRACE_INPUT_SIZE (data) [i],
665 &TRACE_INPUT_DATA (data) [i]);
667 trace_printf (sd, cpu, "\n");
671 trace_prefix (SIM_DESC sd,
676 const char *filename,
681 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
683 char *prefix = TRACE_PREFIX (data);
685 /* FIXME: The TRACE_PREFIX_WIDTH should be determined at build time using
686 known information about the disassembled instructions. */
687 #ifndef TRACE_PREFIX_WIDTH
688 #define TRACE_PREFIX_WIDTH 48
690 int width = TRACE_PREFIX_WIDTH;
692 /* if the previous trace data wasn't flushed, flush it now with a
693 note indicating that the trace was incomplete. */
694 if (TRACE_IDX (data) != 0)
696 int last_input = TRACE_INPUT_IDX (data);
697 save_data (sd, data, trace_fmt_instruction_incomplete, 1, "");
698 trace_results (sd, cpu, TRACE_IDX (data), last_input);
700 TRACE_IDX (data) = 0;
701 TRACE_INPUT_IDX (data) = 0;
703 /* Create the text prefix for this new instruction: */
708 sprintf (prefix, "%s:%-*d 0x%.*lx ",
710 SIZE_LINE_NUMBER, linenum,
715 sprintf (prefix, "0x%.*lx ",
717 /* Shrink the width by the amount that we didn't print. */
718 width -= SIZE_LINE_NUMBER + SIZE_PC + 8;
720 chp = strchr (prefix, '\0');
722 vsprintf (chp, fmt, ap);
729 if (STATE_TEXT_SECTION (CPU_STATE (cpu))
730 && pc >= STATE_TEXT_START (CPU_STATE (cpu))
731 && pc < STATE_TEXT_END (CPU_STATE (cpu)))
733 const char *pc_filename = (const char *)0;
734 const char *pc_function = (const char *)0;
735 unsigned int pc_linenum = 0;
739 abfd = STATE_PROG_BFD (CPU_STATE (cpu));
740 asymbols = STATE_PROG_SYMS (CPU_STATE (cpu));
741 if (asymbols == NULL)
746 symsize = bfd_get_symtab_upper_bound (abfd);
749 sim_engine_abort (sd, cpu, cia, "could not read symbols");
751 asymbols = (asymbol **) xmalloc (symsize);
752 symbol_count = bfd_canonicalize_symtab (abfd, asymbols);
753 if (symbol_count < 0)
755 sim_engine_abort (sd, cpu, cia, "could not canonicalize symbols");
757 STATE_PROG_SYMS (CPU_STATE (cpu)) = asymbols;
760 if (bfd_find_nearest_line (abfd,
761 STATE_TEXT_SECTION (CPU_STATE (cpu)),
763 pc - STATE_TEXT_START (CPU_STATE (cpu)),
764 &pc_filename, &pc_function, &pc_linenum))
769 sprintf (p, "#%-*d ", SIZE_LINE_NUMBER, pc_linenum);
774 sprintf (p, "%-*s ", SIZE_LINE_NUMBER+1, "---");
775 p += SIZE_LINE_NUMBER+2;
780 sprintf (p, "%s ", pc_function);
783 else if (pc_filename)
785 char *q = (char *) strrchr (pc_filename, '/');
786 sprintf (p, "%s ", (q) ? q+1 : pc_filename);
795 sprintf (prefix, "0x%.*x %-*.*s ",
796 SIZE_PC, (unsigned) pc,
797 SIZE_LOCATION, SIZE_LOCATION, buf);
798 chp = strchr (prefix, '\0');
800 vsprintf (chp, fmt, ap);
804 /* Pad it out to TRACE_PREFIX_WIDTH. */
805 chp = strchr (prefix, '\0');
806 if (chp - prefix < width)
808 memset (chp, ' ', width - (chp - prefix));
809 chp = &prefix [width];
814 /* check that we've not over flowed the prefix buffer */
815 if (strlen (prefix) >= sizeof (TRACE_PREFIX (data)))
820 trace_generic (SIM_DESC sd,
827 trace_printf (sd, cpu, "%s %s",
828 trace_idx_to_str (trace_idx),
829 TRACE_PREFIX (CPU_TRACE_DATA (cpu)));
831 trace_vprintf (sd, cpu, fmt, ap);
833 trace_printf (sd, cpu, "\n");
837 trace_input0 (SIM_DESC sd,
841 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
842 TRACE_IDX (data) = trace_idx;
846 trace_input_word1 (SIM_DESC sd,
851 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
852 TRACE_IDX (data) = trace_idx;
853 save_data (sd, data, trace_fmt_word, sizeof (unsigned_word), &d0);
857 trace_input_word2 (SIM_DESC sd,
863 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
864 TRACE_IDX (data) = trace_idx;
865 save_data (sd, data, trace_fmt_word, sizeof (unsigned_word), &d0);
866 save_data (sd, data, trace_fmt_word, sizeof (unsigned_word), &d1);
870 trace_input_word3 (SIM_DESC sd,
877 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
878 TRACE_IDX (data) = trace_idx;
879 save_data (sd, data, trace_fmt_word, sizeof (unsigned_word), &d0);
880 save_data (sd, data, trace_fmt_word, sizeof (unsigned_word), &d1);
881 save_data (sd, data, trace_fmt_word, sizeof (unsigned_word), &d2);
885 trace_input_word4 (SIM_DESC sd,
893 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
894 TRACE_IDX (data) = trace_idx;
895 save_data (sd, data, trace_fmt_word, sizeof (d0), &d0);
896 save_data (sd, data, trace_fmt_word, sizeof (d1), &d1);
897 save_data (sd, data, trace_fmt_word, sizeof (d2), &d2);
898 save_data (sd, data, trace_fmt_word, sizeof (d3), &d3);
902 trace_input_bool1 (SIM_DESC sd,
907 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
908 TRACE_IDX (data) = trace_idx;
909 save_data (sd, data, trace_fmt_bool, sizeof (d0), &d0);
913 trace_input_addr1 (SIM_DESC sd,
918 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
919 TRACE_IDX (data) = trace_idx;
920 save_data (sd, data, trace_fmt_addr, sizeof (d0), &d0);
924 trace_input_fp1 (SIM_DESC sd,
929 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
930 TRACE_IDX (data) = trace_idx;
931 save_data (sd, data, trace_fmt_fp, sizeof (fp_word), &f0);
935 trace_input_fp2 (SIM_DESC sd,
941 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
942 TRACE_IDX (data) = trace_idx;
943 save_data (sd, data, trace_fmt_fp, sizeof (fp_word), &f0);
944 save_data (sd, data, trace_fmt_fp, sizeof (fp_word), &f1);
948 trace_input_fp3 (SIM_DESC sd,
955 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
956 TRACE_IDX (data) = trace_idx;
957 save_data (sd, data, trace_fmt_fp, sizeof (fp_word), &f0);
958 save_data (sd, data, trace_fmt_fp, sizeof (fp_word), &f1);
959 save_data (sd, data, trace_fmt_fp, sizeof (fp_word), &f2);
963 trace_input_fpu1 (SIM_DESC sd,
969 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
970 TRACE_IDX (data) = trace_idx;
972 save_data (sd, data, trace_fmt_fp, sizeof (double), &d);
976 trace_input_fpu2 (SIM_DESC sd,
983 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
984 TRACE_IDX (data) = trace_idx;
986 save_data (sd, data, trace_fmt_fp, sizeof (double), &d);
988 save_data (sd, data, trace_fmt_fp, sizeof (double), &d);
992 trace_input_fpu3 (SIM_DESC sd,
1000 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1001 TRACE_IDX (data) = trace_idx;
1002 d = sim_fpu_2d (f0);
1003 save_data (sd, data, trace_fmt_fp, sizeof (double), &d);
1004 d = sim_fpu_2d (f1);
1005 save_data (sd, data, trace_fmt_fp, sizeof (double), &d);
1006 d = sim_fpu_2d (f2);
1007 save_data (sd, data, trace_fmt_fp, sizeof (double), &d);
1011 trace_result_word1 (SIM_DESC sd,
1016 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1019 /* Append any results to the end of the inputs */
1020 last_input = TRACE_INPUT_IDX (data);
1021 save_data (sd, data, trace_fmt_word, sizeof (unsigned_word), &r0);
1023 trace_results (sd, cpu, trace_idx, last_input);
1027 trace_result0 (SIM_DESC sd,
1031 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1034 /* Append any results to the end of the inputs */
1035 last_input = TRACE_INPUT_IDX (data);
1037 trace_results (sd, cpu, trace_idx, last_input);
1041 trace_result_word2 (SIM_DESC sd,
1047 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1050 /* Append any results to the end of the inputs */
1051 last_input = TRACE_INPUT_IDX (data);
1052 save_data (sd, data, trace_fmt_word, sizeof (r0), &r0);
1053 save_data (sd, data, trace_fmt_word, sizeof (r1), &r1);
1055 trace_results (sd, cpu, trace_idx, last_input);
1059 trace_result_word4 (SIM_DESC sd,
1067 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1070 /* Append any results to the end of the inputs */
1071 last_input = TRACE_INPUT_IDX (data);
1072 save_data (sd, data, trace_fmt_word, sizeof (r0), &r0);
1073 save_data (sd, data, trace_fmt_word, sizeof (r1), &r1);
1074 save_data (sd, data, trace_fmt_word, sizeof (r2), &r2);
1075 save_data (sd, data, trace_fmt_word, sizeof (r3), &r3);
1077 trace_results (sd, cpu, trace_idx, last_input);
1081 trace_result_bool1 (SIM_DESC sd,
1086 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1089 /* Append any results to the end of the inputs */
1090 last_input = TRACE_INPUT_IDX (data);
1091 save_data (sd, data, trace_fmt_bool, sizeof (r0), &r0);
1093 trace_results (sd, cpu, trace_idx, last_input);
1097 trace_result_addr1 (SIM_DESC sd,
1102 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1105 /* Append any results to the end of the inputs */
1106 last_input = TRACE_INPUT_IDX (data);
1107 save_data (sd, data, trace_fmt_addr, sizeof (r0), &r0);
1109 trace_results (sd, cpu, trace_idx, last_input);
1113 trace_result_fp1 (SIM_DESC sd,
1118 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1121 /* Append any results to the end of the inputs */
1122 last_input = TRACE_INPUT_IDX (data);
1123 save_data (sd, data, trace_fmt_fp, sizeof (fp_word), &f0);
1125 trace_results (sd, cpu, trace_idx, last_input);
1129 trace_result_fp2 (SIM_DESC sd,
1135 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1138 /* Append any results to the end of the inputs */
1139 last_input = TRACE_INPUT_IDX (data);
1140 save_data (sd, data, trace_fmt_fp, sizeof (f0), &f0);
1141 save_data (sd, data, trace_fmt_fp, sizeof (f1), &f1);
1143 trace_results (sd, cpu, trace_idx, last_input);
1147 trace_result_fpu1 (SIM_DESC sd,
1153 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1156 /* Append any results to the end of the inputs */
1157 last_input = TRACE_INPUT_IDX (data);
1158 d = sim_fpu_2d (f0);
1159 save_data (sd, data, trace_fmt_fp, sizeof (double), &d);
1161 trace_results (sd, cpu, trace_idx, last_input);
1165 trace_result_string1 (SIM_DESC sd,
1170 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1173 /* Append any results to the end of the inputs */
1174 last_input = TRACE_INPUT_IDX (data);
1175 save_data (sd, data, trace_fmt_string, strlen (s0) + 1, s0);
1177 trace_results (sd, cpu, trace_idx, last_input);
1181 trace_result_word1_string1 (SIM_DESC sd,
1187 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1190 /* Append any results to the end of the inputs */
1191 last_input = TRACE_INPUT_IDX (data);
1192 save_data (sd, data, trace_fmt_word, sizeof (unsigned_word), &r0);
1193 save_data (sd, data, trace_fmt_string, strlen (s0) + 1, s0);
1195 trace_results (sd, cpu, trace_idx, last_input);
1199 trace_vprintf (SIM_DESC sd, sim_cpu *cpu, const char *fmt, va_list ap)
1203 if (TRACE_FILE (CPU_TRACE_DATA (cpu)) != NULL)
1204 vfprintf (TRACE_FILE (CPU_TRACE_DATA (cpu)), fmt, ap);
1206 sim_io_evprintf (sd, fmt, ap);
1210 if (TRACE_FILE (STATE_TRACE_DATA (sd)) != NULL)
1211 vfprintf (TRACE_FILE (STATE_TRACE_DATA (sd)), fmt, ap);
1213 sim_io_evprintf (sd, fmt, ap);
1217 /* The function trace_one_insn has been replaced by the function pair
1218 trace_prefix() + trace_generic(). It is still used. */
1220 trace_one_insn (SIM_DESC sd, sim_cpu *cpu, address_word pc,
1221 int line_p, const char *filename, int linenum,
1222 const char *phase_wo_colon, const char *fmt,
1226 char phase[SIZE_PHASE+2];
1228 strncpy (phase, phase_wo_colon, SIZE_PHASE);
1229 strcat (phase, ":");
1233 trace_printf (sd, cpu, "%-*s %s:%-*d 0x%.*lx ",
1234 SIZE_PHASE+1, phase,
1236 SIZE_LINE_NUMBER, linenum,
1239 trace_vprintf (sd, cpu, fmt, ap);
1241 trace_printf (sd, cpu, "\n");
1248 if (STATE_TEXT_SECTION (CPU_STATE (cpu))
1249 && pc >= STATE_TEXT_START (CPU_STATE (cpu))
1250 && pc < STATE_TEXT_END (CPU_STATE (cpu)))
1252 const char *pc_filename = (const char *)0;
1253 const char *pc_function = (const char *)0;
1254 unsigned int pc_linenum = 0;
1256 if (bfd_find_nearest_line (STATE_PROG_BFD (CPU_STATE (cpu)),
1257 STATE_TEXT_SECTION (CPU_STATE (cpu)),
1258 (struct bfd_symbol **) 0,
1259 pc - STATE_TEXT_START (CPU_STATE (cpu)),
1260 &pc_filename, &pc_function, &pc_linenum))
1265 sprintf (p, "#%-*d ", SIZE_LINE_NUMBER, pc_linenum);
1270 sprintf (p, "%-*s ", SIZE_LINE_NUMBER+1, "---");
1271 p += SIZE_LINE_NUMBER+2;
1276 sprintf (p, "%s ", pc_function);
1279 else if (pc_filename)
1281 char *q = (char *) strrchr (pc_filename, '/');
1282 sprintf (p, "%s ", (q) ? q+1 : pc_filename);
1291 trace_printf (sd, cpu, "%-*s 0x%.*x %-*.*s ",
1292 SIZE_PHASE+1, phase,
1293 SIZE_PC, (unsigned) pc,
1294 SIZE_LOCATION, SIZE_LOCATION, buf);
1296 trace_vprintf (sd, cpu, fmt, ap);
1298 trace_printf (sd, cpu, "\n");
1303 trace_printf (SIM_DESC sd, sim_cpu *cpu, const char *fmt, ...)
1305 #if !defined __STDC__ && !defined ALMOST_STDC
1313 #if !defined __STDC__ && !defined ALMOST_STDC
1314 sd = va_arg (ap, SIM_DESC);
1315 cpu = va_arg (ap, sim_cpu *);
1316 fmt = va_arg (ap, const char *);
1319 trace_vprintf (sd, cpu, fmt, ap);
1325 debug_printf (sim_cpu *cpu, const char *fmt, ...)
1327 #if !defined __STDC__ && !defined ALMOST_STDC
1334 #if !defined __STDC__ && !defined ALMOST_STDC
1335 cpu = va_arg (ap, sim_cpu *);
1336 fmt = va_arg (ap, const char *);
1339 if (CPU_DEBUG_FILE (cpu) == NULL)
1340 (* STATE_CALLBACK (CPU_STATE (cpu))->evprintf_filtered)
1341 (STATE_CALLBACK (CPU_STATE (cpu)), fmt, ap);
1343 vfprintf (CPU_DEBUG_FILE (cpu), fmt, ap);