1 /* Simulator tracing/debugging support.
2 Copyright (C) 1997, 1998, 2001, 2007 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,
82 static const OPTION trace_options[] =
84 /* This table is organized to group related instructions together. */
85 { {"trace", optional_argument, NULL, 't'},
86 't', "on|off", "Trace useful things",
87 trace_option_handler },
88 { {"trace-insn", optional_argument, NULL, OPTION_TRACE_INSN},
89 '\0', "on|off", "Perform instruction tracing",
90 trace_option_handler },
91 { {"trace-decode", optional_argument, NULL, OPTION_TRACE_DECODE},
92 '\0', "on|off", "Trace instruction decoding",
93 trace_option_handler },
94 { {"trace-extract", optional_argument, NULL, OPTION_TRACE_EXTRACT},
95 '\0', "on|off", "Trace instruction extraction",
96 trace_option_handler },
97 { {"trace-linenum", optional_argument, NULL, OPTION_TRACE_LINENUM},
98 '\0', "on|off", "Perform line number tracing (implies --trace-insn)",
99 trace_option_handler },
100 { {"trace-memory", optional_argument, NULL, OPTION_TRACE_MEMORY},
101 '\0', "on|off", "Trace memory operations",
102 trace_option_handler },
103 { {"trace-alu", optional_argument, NULL, OPTION_TRACE_ALU},
104 '\0', "on|off", "Trace ALU operations",
105 trace_option_handler },
106 { {"trace-fpu", optional_argument, NULL, OPTION_TRACE_FPU},
107 '\0', "on|off", "Trace FPU operations",
108 trace_option_handler },
109 { {"trace-vpu", optional_argument, NULL, OPTION_TRACE_VPU},
110 '\0', "on|off", "Trace VPU operations",
111 trace_option_handler },
112 { {"trace-branch", optional_argument, NULL, OPTION_TRACE_BRANCH},
113 '\0', "on|off", "Trace branching",
114 trace_option_handler },
115 { {"trace-semantics", optional_argument, NULL, OPTION_TRACE_SEMANTICS},
116 '\0', "on|off", "Perform ALU, FPU, MEMORY, and BRANCH tracing",
117 trace_option_handler },
118 { {"trace-model", optional_argument, NULL, OPTION_TRACE_MODEL},
119 '\0', "on|off", "Include model performance data",
120 trace_option_handler },
121 { {"trace-core", optional_argument, NULL, OPTION_TRACE_CORE},
122 '\0', "on|off", "Trace core operations",
123 trace_option_handler },
124 { {"trace-events", optional_argument, NULL, OPTION_TRACE_EVENTS},
125 '\0', "on|off", "Trace events",
126 trace_option_handler },
127 #ifdef SIM_HAVE_ADDR_RANGE
128 { {"trace-range", required_argument, NULL, OPTION_TRACE_RANGE},
129 '\0', "START,END", "Specify range of addresses for instruction tracing",
130 trace_option_handler },
132 { {"trace-function", required_argument, NULL, OPTION_TRACE_FUNCTION},
133 '\0', "FUNCTION", "Specify function to trace",
134 trace_option_handler },
137 { {"trace-debug", optional_argument, NULL, OPTION_TRACE_DEBUG},
138 '\0', "on|off", "Add information useful for debugging the simulator to the tracing output",
139 trace_option_handler },
140 { {"trace-file", required_argument, NULL, OPTION_TRACE_FILE},
141 '\0', "FILE NAME", "Specify tracing output file",
142 trace_option_handler },
143 { {NULL, no_argument, NULL, 0}, '\0', NULL, NULL, NULL }
146 /* Set/reset the trace options indicated in MASK. */
149 set_trace_option_mask (sd, name, mask, 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 (sd, name, idx, arg)
234 return set_trace_option_mask (sd, name, 1 << idx, arg);
239 trace_option_handler (SIM_DESC sd, sim_cpu *cpu, int opt,
240 char *arg, int is_command)
249 sim_io_eprintf (sd, "Tracing not compiled in, `-t' ignored\n");
251 return set_trace_option_mask (sd, "trace", TRACE_USEFUL_MASK, arg);
254 case OPTION_TRACE_INSN :
255 if (WITH_TRACE_INSN_P)
256 return set_trace_option (sd, "-insn", TRACE_INSN_IDX, arg);
258 sim_io_eprintf (sd, "Instruction tracing not compiled in, `--trace-insn' ignored\n");
261 case OPTION_TRACE_DECODE :
262 if (WITH_TRACE_DECODE_P)
263 return set_trace_option (sd, "-decode", TRACE_DECODE_IDX, arg);
265 sim_io_eprintf (sd, "Decode tracing not compiled in, `--trace-decode' ignored\n");
268 case OPTION_TRACE_EXTRACT :
269 if (WITH_TRACE_EXTRACT_P)
270 return set_trace_option (sd, "-extract", TRACE_EXTRACT_IDX, arg);
272 sim_io_eprintf (sd, "Extract tracing not compiled in, `--trace-extract' ignored\n");
275 case OPTION_TRACE_LINENUM :
276 if (WITH_TRACE_LINENUM_P && WITH_TRACE_INSN_P)
278 if (set_trace_option (sd, "-linenum", TRACE_LINENUM_IDX, arg) != SIM_RC_OK
279 || set_trace_option (sd, "-linenum", TRACE_INSN_IDX, arg) != SIM_RC_OK)
283 sim_io_eprintf (sd, "Line number or instruction tracing not compiled in, `--trace-linenum' ignored\n");
286 case OPTION_TRACE_MEMORY :
287 if (WITH_TRACE_MEMORY_P)
288 return set_trace_option (sd, "-memory", TRACE_MEMORY_IDX, arg);
290 sim_io_eprintf (sd, "Memory tracing not compiled in, `--trace-memory' ignored\n");
293 case OPTION_TRACE_MODEL :
294 if (WITH_TRACE_MODEL_P)
295 return set_trace_option (sd, "-model", TRACE_MODEL_IDX, arg);
297 sim_io_eprintf (sd, "Model tracing not compiled in, `--trace-model' ignored\n");
300 case OPTION_TRACE_ALU :
301 if (WITH_TRACE_ALU_P)
302 return set_trace_option (sd, "-alu", TRACE_ALU_IDX, arg);
304 sim_io_eprintf (sd, "ALU tracing not compiled in, `--trace-alu' ignored\n");
307 case OPTION_TRACE_CORE :
308 if (WITH_TRACE_CORE_P)
309 return set_trace_option (sd, "-core", TRACE_CORE_IDX, arg);
311 sim_io_eprintf (sd, "CORE tracing not compiled in, `--trace-core' ignored\n");
314 case OPTION_TRACE_EVENTS :
315 if (WITH_TRACE_EVENTS_P)
316 return set_trace_option (sd, "-events", TRACE_EVENTS_IDX, arg);
318 sim_io_eprintf (sd, "EVENTS tracing not compiled in, `--trace-events' ignored\n");
321 case OPTION_TRACE_FPU :
322 if (WITH_TRACE_FPU_P)
323 return set_trace_option (sd, "-fpu", TRACE_FPU_IDX, arg);
325 sim_io_eprintf (sd, "FPU tracing not compiled in, `--trace-fpu' ignored\n");
328 case OPTION_TRACE_VPU :
329 if (WITH_TRACE_VPU_P)
330 return set_trace_option (sd, "-vpu", TRACE_VPU_IDX, arg);
332 sim_io_eprintf (sd, "VPU tracing not compiled in, `--trace-vpu' ignored\n");
335 case OPTION_TRACE_BRANCH :
336 if (WITH_TRACE_BRANCH_P)
337 return set_trace_option (sd, "-branch", TRACE_BRANCH_IDX, arg);
339 sim_io_eprintf (sd, "Branch tracing not compiled in, `--trace-branch' ignored\n");
342 case OPTION_TRACE_SEMANTICS :
345 && WITH_TRACE_MEMORY_P
346 && WITH_TRACE_BRANCH_P)
348 if (set_trace_option (sd, "-semantics", TRACE_ALU_IDX, arg) != SIM_RC_OK
349 || set_trace_option (sd, "-semantics", TRACE_FPU_IDX, arg) != SIM_RC_OK
350 || set_trace_option (sd, "-semantics", TRACE_VPU_IDX, arg) != SIM_RC_OK
351 || set_trace_option (sd, "-semantics", TRACE_MEMORY_IDX, arg) != SIM_RC_OK
352 || set_trace_option (sd, "-semantics", TRACE_BRANCH_IDX, arg) != SIM_RC_OK)
356 sim_io_eprintf (sd, "Alu, fpu, memory, and/or branch tracing not compiled in, `--trace-semantics' ignored\n");
359 #ifdef SIM_HAVE_ADDR_RANGE
360 case OPTION_TRACE_RANGE :
364 unsigned long start,end;
365 start = strtoul (chp, &chp, 0);
368 sim_io_eprintf (sd, "--trace-range missing END argument\n");
371 end = strtoul (chp + 1, NULL, 0);
372 /* FIXME: Argument validation. */
374 sim_addr_range_add (TRACE_RANGE (CPU_PROFILE_DATA (cpu)),
377 for (cpu_nr = 0; cpu_nr < MAX_NR_PROCESSORS; ++cpu_nr)
378 sim_addr_range_add (TRACE_RANGE (CPU_TRACE_DATA (STATE_CPU (sd, cpu_nr))),
382 sim_io_eprintf (sd, "Tracing not compiled in, `--trace-range' ignored\n");
385 case OPTION_TRACE_FUNCTION :
388 /*wip: need to compute function range given name*/
391 sim_io_eprintf (sd, "Tracing not compiled in, `--trace-function' ignored\n");
393 #endif /* SIM_HAVE_ADDR_RANGE */
395 case OPTION_TRACE_DEBUG :
396 if (WITH_TRACE_DEBUG_P)
397 return set_trace_option (sd, "-debug", TRACE_DEBUG_IDX, arg);
399 sim_io_eprintf (sd, "Tracing debug support not compiled in, `--trace-debug' ignored\n");
402 case OPTION_TRACE_FILE :
404 sim_io_eprintf (sd, "Tracing not compiled in, `--trace-file' ignored\n");
407 FILE *f = fopen (arg, "w");
411 sim_io_eprintf (sd, "Unable to open trace output file `%s'\n", arg);
414 for (n = 0; n < MAX_NR_PROCESSORS; ++n)
415 TRACE_FILE (CPU_TRACE_DATA (STATE_CPU (sd, n))) = f;
416 TRACE_FILE (STATE_TRACE_DATA (sd)) = f;
424 /* Install tracing support. */
427 trace_install (SIM_DESC sd)
431 SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
433 sim_add_option_table (sd, NULL, trace_options);
434 memset (STATE_TRACE_DATA (sd), 0, sizeof (* STATE_TRACE_DATA (sd)));
435 for (i = 0; i < MAX_NR_PROCESSORS; ++i)
436 memset (CPU_TRACE_DATA (STATE_CPU (sd, i)), 0,
437 sizeof (* CPU_TRACE_DATA (STATE_CPU (sd, i))));
438 sim_module_add_init_fn (sd, trace_init);
439 sim_module_add_uninstall_fn (sd, trace_uninstall);
444 trace_init (SIM_DESC sd)
446 #ifdef SIM_HAVE_ADDR_RANGE
447 /* Check if a range has been specified without specifying what to
452 for (i = 0; i < MAX_NR_PROCESSORS; ++i)
454 sim_cpu *cpu = STATE_CPU (sd, i);
456 if (ADDR_RANGE_RANGES (TRACE_RANGE (CPU_TRACE_DATA (cpu)))
457 && ! TRACE_INSN_P (cpu))
459 sim_io_eprintf_cpu (cpu, "Tracing address range specified without --trace-insn.\n");
460 sim_io_eprintf_cpu (cpu, "Address range ignored.\n");
461 sim_addr_range_delete (TRACE_RANGE (CPU_TRACE_DATA (cpu)),
462 0, ~ (address_word) 0);
472 trace_uninstall (SIM_DESC sd)
475 FILE *sfile = TRACE_FILE (STATE_TRACE_DATA (sd));
480 for (i = 0; i < MAX_NR_PROCESSORS; ++i)
482 FILE *cfile = TRACE_FILE (CPU_TRACE_DATA (STATE_CPU (sd, i)));
483 if (cfile != NULL && cfile != sfile)
485 /* If output from different cpus is going to the same file,
486 avoid closing the file twice. */
487 for (j = 0; j < i; ++j)
488 if (TRACE_FILE (CPU_TRACE_DATA (STATE_CPU (sd, j))) == cfile)
504 trace_fmt_instruction_incomplete,
507 /* compute the nr of trace data units consumed by data */
509 save_data_size (TRACE_DATA *data,
512 return ((size + sizeof (TRACE_INPUT_DATA (data) [0]) - 1)
513 / sizeof (TRACE_INPUT_DATA (data) [0]));
517 /* Archive DATA into the trace buffer */
519 save_data (SIM_DESC sd,
525 int i = TRACE_INPUT_IDX (data);
526 if (i == sizeof (TRACE_INPUT_FMT (data)))
527 sim_io_error (sd, "trace buffer overflow");
528 TRACE_INPUT_FMT (data) [i] = fmt;
529 TRACE_INPUT_SIZE (data) [i] = size;
530 memcpy (&TRACE_INPUT_DATA (data) [i], buf, size);
531 i += save_data_size (data, size);
532 TRACE_INPUT_IDX (data) = i;
536 print_data (SIM_DESC sd,
544 case trace_fmt_instruction_incomplete:
545 trace_printf (sd, cpu, " (instruction incomplete)");
552 case sizeof (unsigned32):
553 trace_printf (sd, cpu, " 0x%08lx", (long) * (unsigned32*) data);
555 case sizeof (unsigned64):
556 trace_printf (sd, cpu, " 0x%08lx%08lx",
557 (long) ((* (unsigned64*) data) >> 32),
558 (long) * (unsigned64*) data);
567 SIM_ASSERT (size == sizeof (int));
568 trace_printf (sd, cpu, " %-8s",
569 (* (int*) data) ? "true" : "false");
577 /* FIXME: Assumes sizeof float == 4; sizeof double == 8 */
579 sim_fpu_32to (&fp, *(unsigned32*)data);
582 sim_fpu_64to (&fp, *(unsigned64*)data);
587 trace_printf (sd, cpu, " %8g", sim_fpu_2d (&fp));
591 trace_printf (sd, cpu, " (0x%08lx)",
592 (long) *(unsigned32*)data);
595 trace_printf (sd, cpu, " (0x%08lx%08lx)",
596 (long) (*(unsigned64*)data >> 32),
597 (long) (*(unsigned64*)data));
605 /* FIXME: At present sim_fpu data is stored as a double */
606 trace_printf (sd, cpu, " %8g", * (double*) data);
608 case trace_fmt_string:
609 trace_printf (sd, cpu, " %-8s", (char*) data);
617 trace_idx_to_str (int trace_idx)
622 case TRACE_ALU_IDX: return "alu: ";
623 case TRACE_INSN_IDX: return "insn: ";
624 case TRACE_DECODE_IDX: return "decode: ";
625 case TRACE_EXTRACT_IDX: return "extract: ";
626 case TRACE_MEMORY_IDX: return "memory: ";
627 case TRACE_CORE_IDX: return "core: ";
628 case TRACE_EVENTS_IDX: return "events: ";
629 case TRACE_FPU_IDX: return "fpu: ";
630 case TRACE_BRANCH_IDX: return "branch: ";
631 case TRACE_VPU_IDX: return "vpu: ";
633 sprintf (num, "?%d?", trace_idx);
639 trace_results (SIM_DESC sd,
644 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
648 /* cross check trace_idx against TRACE_IDX (data)? */
651 trace_printf (sd, cpu, "%s %s",
652 trace_idx_to_str (TRACE_IDX (data)),
653 TRACE_PREFIX (data));
654 TRACE_IDX (data) = 0;
656 for (i = 0, nr_out = 0;
657 i < TRACE_INPUT_IDX (data);
658 i += save_data_size (data, TRACE_INPUT_SIZE (data) [i]), nr_out++)
662 int pad = (strlen (" 0x") + sizeof (unsigned_word) * 2);
663 int padding = pad * (3 - nr_out);
666 padding += strlen (" ::");
667 trace_printf (sd, cpu, "%*s", padding, " ::");
670 TRACE_INPUT_FMT (data) [i],
671 TRACE_INPUT_SIZE (data) [i],
672 &TRACE_INPUT_DATA (data) [i]);
674 trace_printf (sd, cpu, "\n");
678 trace_prefix (SIM_DESC sd,
683 const char *filename,
688 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
690 char *prefix = TRACE_PREFIX (data);
692 /* FIXME: The TRACE_PREFIX_WIDTH should be determined at build time using
693 known information about the disassembled instructions. */
694 #ifndef TRACE_PREFIX_WIDTH
695 #define TRACE_PREFIX_WIDTH 48
697 int width = TRACE_PREFIX_WIDTH;
699 /* if the previous trace data wasn't flushed, flush it now with a
700 note indicating that the trace was incomplete. */
701 if (TRACE_IDX (data) != 0)
703 int last_input = TRACE_INPUT_IDX (data);
704 save_data (sd, data, trace_fmt_instruction_incomplete, 1, "");
705 trace_results (sd, cpu, TRACE_IDX (data), last_input);
707 TRACE_IDX (data) = 0;
708 TRACE_INPUT_IDX (data) = 0;
710 /* Create the text prefix for this new instruction: */
715 sprintf (prefix, "%s:%-*d 0x%.*lx ",
717 SIZE_LINE_NUMBER, linenum,
722 sprintf (prefix, "0x%.*lx ",
724 /* Shrink the width by the amount that we didn't print. */
725 width -= SIZE_LINE_NUMBER + SIZE_PC + 8;
727 chp = strchr (prefix, '\0');
729 vsprintf (chp, fmt, ap);
736 if (STATE_TEXT_SECTION (CPU_STATE (cpu))
737 && pc >= STATE_TEXT_START (CPU_STATE (cpu))
738 && pc < STATE_TEXT_END (CPU_STATE (cpu)))
740 const char *pc_filename = (const char *)0;
741 const char *pc_function = (const char *)0;
742 unsigned int pc_linenum = 0;
746 abfd = STATE_PROG_BFD (CPU_STATE (cpu));
747 asymbols = STATE_PROG_SYMS (CPU_STATE (cpu));
748 if (asymbols == NULL)
753 symsize = bfd_get_symtab_upper_bound (abfd);
756 sim_engine_abort (sd, cpu, cia, "could not read symbols");
758 asymbols = (asymbol **) xmalloc (symsize);
759 symbol_count = bfd_canonicalize_symtab (abfd, asymbols);
760 if (symbol_count < 0)
762 sim_engine_abort (sd, cpu, cia, "could not canonicalize symbols");
764 STATE_PROG_SYMS (CPU_STATE (cpu)) = asymbols;
767 if (bfd_find_nearest_line (abfd,
768 STATE_TEXT_SECTION (CPU_STATE (cpu)),
770 pc - STATE_TEXT_START (CPU_STATE (cpu)),
771 &pc_filename, &pc_function, &pc_linenum))
776 sprintf (p, "#%-*d ", SIZE_LINE_NUMBER, pc_linenum);
781 sprintf (p, "%-*s ", SIZE_LINE_NUMBER+1, "---");
782 p += SIZE_LINE_NUMBER+2;
787 sprintf (p, "%s ", pc_function);
790 else if (pc_filename)
792 char *q = (char *) strrchr (pc_filename, '/');
793 sprintf (p, "%s ", (q) ? q+1 : pc_filename);
802 sprintf (prefix, "0x%.*x %-*.*s ",
803 SIZE_PC, (unsigned) pc,
804 SIZE_LOCATION, SIZE_LOCATION, buf);
805 chp = strchr (prefix, '\0');
807 vsprintf (chp, fmt, ap);
811 /* Pad it out to TRACE_PREFIX_WIDTH. */
812 chp = strchr (prefix, '\0');
813 if (chp - prefix < width)
815 memset (chp, ' ', width - (chp - prefix));
816 chp = &prefix [width];
821 /* check that we've not over flowed the prefix buffer */
822 if (strlen (prefix) >= sizeof (TRACE_PREFIX (data)))
827 trace_generic (SIM_DESC sd,
834 trace_printf (sd, cpu, "%s %s",
835 trace_idx_to_str (trace_idx),
836 TRACE_PREFIX (CPU_TRACE_DATA (cpu)));
838 trace_vprintf (sd, cpu, fmt, ap);
840 trace_printf (sd, cpu, "\n");
844 trace_input0 (SIM_DESC sd,
848 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
849 TRACE_IDX (data) = trace_idx;
853 trace_input_word1 (SIM_DESC sd,
858 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
859 TRACE_IDX (data) = trace_idx;
860 save_data (sd, data, trace_fmt_word, sizeof (unsigned_word), &d0);
864 trace_input_word2 (SIM_DESC sd,
870 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
871 TRACE_IDX (data) = trace_idx;
872 save_data (sd, data, trace_fmt_word, sizeof (unsigned_word), &d0);
873 save_data (sd, data, trace_fmt_word, sizeof (unsigned_word), &d1);
877 trace_input_word3 (SIM_DESC sd,
884 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
885 TRACE_IDX (data) = trace_idx;
886 save_data (sd, data, trace_fmt_word, sizeof (unsigned_word), &d0);
887 save_data (sd, data, trace_fmt_word, sizeof (unsigned_word), &d1);
888 save_data (sd, data, trace_fmt_word, sizeof (unsigned_word), &d2);
892 trace_input_word4 (SIM_DESC sd,
900 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
901 TRACE_IDX (data) = trace_idx;
902 save_data (sd, data, trace_fmt_word, sizeof (d0), &d0);
903 save_data (sd, data, trace_fmt_word, sizeof (d1), &d1);
904 save_data (sd, data, trace_fmt_word, sizeof (d2), &d2);
905 save_data (sd, data, trace_fmt_word, sizeof (d3), &d3);
909 trace_input_bool1 (SIM_DESC sd,
914 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
915 TRACE_IDX (data) = trace_idx;
916 save_data (sd, data, trace_fmt_bool, sizeof (d0), &d0);
920 trace_input_addr1 (SIM_DESC sd,
925 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
926 TRACE_IDX (data) = trace_idx;
927 save_data (sd, data, trace_fmt_addr, sizeof (d0), &d0);
931 trace_input_fp1 (SIM_DESC sd,
936 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
937 TRACE_IDX (data) = trace_idx;
938 save_data (sd, data, trace_fmt_fp, sizeof (fp_word), &f0);
942 trace_input_fp2 (SIM_DESC sd,
948 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
949 TRACE_IDX (data) = trace_idx;
950 save_data (sd, data, trace_fmt_fp, sizeof (fp_word), &f0);
951 save_data (sd, data, trace_fmt_fp, sizeof (fp_word), &f1);
955 trace_input_fp3 (SIM_DESC sd,
962 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
963 TRACE_IDX (data) = trace_idx;
964 save_data (sd, data, trace_fmt_fp, sizeof (fp_word), &f0);
965 save_data (sd, data, trace_fmt_fp, sizeof (fp_word), &f1);
966 save_data (sd, data, trace_fmt_fp, sizeof (fp_word), &f2);
970 trace_input_fpu1 (SIM_DESC sd,
976 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
977 TRACE_IDX (data) = trace_idx;
979 save_data (sd, data, trace_fmt_fp, sizeof (double), &d);
983 trace_input_fpu2 (SIM_DESC sd,
990 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
991 TRACE_IDX (data) = trace_idx;
993 save_data (sd, data, trace_fmt_fp, sizeof (double), &d);
995 save_data (sd, data, trace_fmt_fp, sizeof (double), &d);
999 trace_input_fpu3 (SIM_DESC sd,
1007 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1008 TRACE_IDX (data) = trace_idx;
1009 d = sim_fpu_2d (f0);
1010 save_data (sd, data, trace_fmt_fp, sizeof (double), &d);
1011 d = sim_fpu_2d (f1);
1012 save_data (sd, data, trace_fmt_fp, sizeof (double), &d);
1013 d = sim_fpu_2d (f2);
1014 save_data (sd, data, trace_fmt_fp, sizeof (double), &d);
1018 trace_result_word1 (SIM_DESC sd,
1023 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1026 /* Append any results to the end of the inputs */
1027 last_input = TRACE_INPUT_IDX (data);
1028 save_data (sd, data, trace_fmt_word, sizeof (unsigned_word), &r0);
1030 trace_results (sd, cpu, trace_idx, last_input);
1034 trace_result0 (SIM_DESC sd,
1038 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1041 /* Append any results to the end of the inputs */
1042 last_input = TRACE_INPUT_IDX (data);
1044 trace_results (sd, cpu, trace_idx, last_input);
1048 trace_result_word2 (SIM_DESC sd,
1054 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1057 /* Append any results to the end of the inputs */
1058 last_input = TRACE_INPUT_IDX (data);
1059 save_data (sd, data, trace_fmt_word, sizeof (r0), &r0);
1060 save_data (sd, data, trace_fmt_word, sizeof (r1), &r1);
1062 trace_results (sd, cpu, trace_idx, last_input);
1066 trace_result_word4 (SIM_DESC sd,
1074 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1077 /* Append any results to the end of the inputs */
1078 last_input = TRACE_INPUT_IDX (data);
1079 save_data (sd, data, trace_fmt_word, sizeof (r0), &r0);
1080 save_data (sd, data, trace_fmt_word, sizeof (r1), &r1);
1081 save_data (sd, data, trace_fmt_word, sizeof (r2), &r2);
1082 save_data (sd, data, trace_fmt_word, sizeof (r3), &r3);
1084 trace_results (sd, cpu, trace_idx, last_input);
1088 trace_result_bool1 (SIM_DESC sd,
1093 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1096 /* Append any results to the end of the inputs */
1097 last_input = TRACE_INPUT_IDX (data);
1098 save_data (sd, data, trace_fmt_bool, sizeof (r0), &r0);
1100 trace_results (sd, cpu, trace_idx, last_input);
1104 trace_result_addr1 (SIM_DESC sd,
1109 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1112 /* Append any results to the end of the inputs */
1113 last_input = TRACE_INPUT_IDX (data);
1114 save_data (sd, data, trace_fmt_addr, sizeof (r0), &r0);
1116 trace_results (sd, cpu, trace_idx, last_input);
1120 trace_result_fp1 (SIM_DESC sd,
1125 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1128 /* Append any results to the end of the inputs */
1129 last_input = TRACE_INPUT_IDX (data);
1130 save_data (sd, data, trace_fmt_fp, sizeof (fp_word), &f0);
1132 trace_results (sd, cpu, trace_idx, last_input);
1136 trace_result_fp2 (SIM_DESC sd,
1142 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1145 /* Append any results to the end of the inputs */
1146 last_input = TRACE_INPUT_IDX (data);
1147 save_data (sd, data, trace_fmt_fp, sizeof (f0), &f0);
1148 save_data (sd, data, trace_fmt_fp, sizeof (f1), &f1);
1150 trace_results (sd, cpu, trace_idx, last_input);
1154 trace_result_fpu1 (SIM_DESC sd,
1160 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1163 /* Append any results to the end of the inputs */
1164 last_input = TRACE_INPUT_IDX (data);
1165 d = sim_fpu_2d (f0);
1166 save_data (sd, data, trace_fmt_fp, sizeof (double), &d);
1168 trace_results (sd, cpu, trace_idx, last_input);
1172 trace_result_string1 (SIM_DESC sd,
1177 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1180 /* Append any results to the end of the inputs */
1181 last_input = TRACE_INPUT_IDX (data);
1182 save_data (sd, data, trace_fmt_string, strlen (s0) + 1, s0);
1184 trace_results (sd, cpu, trace_idx, last_input);
1188 trace_result_word1_string1 (SIM_DESC sd,
1194 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1197 /* Append any results to the end of the inputs */
1198 last_input = TRACE_INPUT_IDX (data);
1199 save_data (sd, data, trace_fmt_word, sizeof (unsigned_word), &r0);
1200 save_data (sd, data, trace_fmt_string, strlen (s0) + 1, s0);
1202 trace_results (sd, cpu, trace_idx, last_input);
1206 trace_vprintf (SIM_DESC sd, sim_cpu *cpu, const char *fmt, va_list ap)
1210 if (TRACE_FILE (CPU_TRACE_DATA (cpu)) != NULL)
1211 vfprintf (TRACE_FILE (CPU_TRACE_DATA (cpu)), fmt, ap);
1213 sim_io_evprintf (sd, fmt, ap);
1217 if (TRACE_FILE (STATE_TRACE_DATA (sd)) != NULL)
1218 vfprintf (TRACE_FILE (STATE_TRACE_DATA (sd)), fmt, ap);
1220 sim_io_evprintf (sd, fmt, ap);
1224 /* The function trace_one_insn has been replaced by the function pair
1225 trace_prefix() + trace_generic(). It is still used. */
1227 trace_one_insn (SIM_DESC sd, sim_cpu *cpu, address_word pc,
1228 int line_p, const char *filename, int linenum,
1229 const char *phase_wo_colon, const char *fmt,
1233 char phase[SIZE_PHASE+2];
1235 strncpy (phase, phase_wo_colon, SIZE_PHASE);
1236 strcat (phase, ":");
1240 trace_printf (sd, cpu, "%-*s %s:%-*d 0x%.*lx ",
1241 SIZE_PHASE+1, phase,
1243 SIZE_LINE_NUMBER, linenum,
1246 trace_vprintf (sd, cpu, fmt, ap);
1248 trace_printf (sd, cpu, "\n");
1255 if (STATE_TEXT_SECTION (CPU_STATE (cpu))
1256 && pc >= STATE_TEXT_START (CPU_STATE (cpu))
1257 && pc < STATE_TEXT_END (CPU_STATE (cpu)))
1259 const char *pc_filename = (const char *)0;
1260 const char *pc_function = (const char *)0;
1261 unsigned int pc_linenum = 0;
1263 if (bfd_find_nearest_line (STATE_PROG_BFD (CPU_STATE (cpu)),
1264 STATE_TEXT_SECTION (CPU_STATE (cpu)),
1265 (struct bfd_symbol **) 0,
1266 pc - STATE_TEXT_START (CPU_STATE (cpu)),
1267 &pc_filename, &pc_function, &pc_linenum))
1272 sprintf (p, "#%-*d ", SIZE_LINE_NUMBER, pc_linenum);
1277 sprintf (p, "%-*s ", SIZE_LINE_NUMBER+1, "---");
1278 p += SIZE_LINE_NUMBER+2;
1283 sprintf (p, "%s ", pc_function);
1286 else if (pc_filename)
1288 char *q = (char *) strrchr (pc_filename, '/');
1289 sprintf (p, "%s ", (q) ? q+1 : pc_filename);
1298 trace_printf (sd, cpu, "%-*s 0x%.*x %-*.*s ",
1299 SIZE_PHASE+1, phase,
1300 SIZE_PC, (unsigned) pc,
1301 SIZE_LOCATION, SIZE_LOCATION, buf);
1303 trace_vprintf (sd, cpu, fmt, ap);
1305 trace_printf (sd, cpu, "\n");
1310 trace_printf VPARAMS ((SIM_DESC sd, sim_cpu *cpu, const char *fmt, ...))
1312 #if !defined __STDC__ && !defined ALMOST_STDC
1320 #if !defined __STDC__ && !defined ALMOST_STDC
1321 sd = va_arg (ap, SIM_DESC);
1322 cpu = va_arg (ap, sim_cpu *);
1323 fmt = va_arg (ap, const char *);
1326 trace_vprintf (sd, cpu, fmt, ap);
1332 debug_printf VPARAMS ((sim_cpu *cpu, const char *fmt, ...))
1334 #if !defined __STDC__ && !defined ALMOST_STDC
1341 #if !defined __STDC__ && !defined ALMOST_STDC
1342 cpu = va_arg (ap, sim_cpu *);
1343 fmt = va_arg (ap, const char *);
1346 if (CPU_DEBUG_FILE (cpu) == NULL)
1347 (* STATE_CALLBACK (CPU_STATE (cpu))->evprintf_filtered)
1348 (STATE_CALLBACK (CPU_STATE (cpu)), fmt, ap);
1350 vfprintf (CPU_DEBUG_FILE (cpu), fmt, ap);