1 /* Simulator tracing/debugging support.
2 Copyright (C) 1997, 1998 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 2, or (at your option)
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 along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 #include "sim-options.h"
27 #include "sim-assert.h"
42 #define SIZE_LOCATION 20
49 #ifndef SIZE_LINE_NUMBER
50 #define SIZE_LINE_NUMBER 4
53 static MODULE_UNINSTALL_FN trace_uninstall
;
55 static DECLARE_OPTION_HANDLER (trace_option_handler
);
58 OPTION_TRACE_INSN
= OPTION_START
,
69 OPTION_TRACE_SEMANTICS
,
74 static const OPTION trace_options
[] =
76 /* This table is organized to group related instructions together. */
77 { {"trace", optional_argument
, NULL
, 't'},
78 't', "on|off", "Trace useful things",
79 trace_option_handler
},
80 { {"trace-insn", optional_argument
, NULL
, OPTION_TRACE_INSN
},
81 '\0', "on|off", "Perform instruction tracing",
82 trace_option_handler
},
83 { {"trace-decode", optional_argument
, NULL
, OPTION_TRACE_DECODE
},
84 '\0', "on|off", "Trace instruction decoding",
85 trace_option_handler
},
86 { {"trace-extract", optional_argument
, NULL
, OPTION_TRACE_EXTRACT
},
87 '\0', "on|off", "Trace instruction extraction",
88 trace_option_handler
},
89 { {"trace-linenum", optional_argument
, NULL
, OPTION_TRACE_LINENUM
},
90 '\0', "on|off", "Perform line number tracing (implies --trace-insn)",
91 trace_option_handler
},
92 { {"trace-memory", optional_argument
, NULL
, OPTION_TRACE_MEMORY
},
93 '\0', "on|off", "Trace memory operations",
94 trace_option_handler
},
95 { {"trace-alu", optional_argument
, NULL
, OPTION_TRACE_ALU
},
96 '\0', "on|off", "Trace ALU operations",
97 trace_option_handler
},
98 { {"trace-fpu", optional_argument
, NULL
, OPTION_TRACE_FPU
},
99 '\0', "on|off", "Trace FPU operations",
100 trace_option_handler
},
101 { {"trace-branch", optional_argument
, NULL
, OPTION_TRACE_BRANCH
},
102 '\0', "on|off", "Trace branching",
103 trace_option_handler
},
104 { {"trace-semantics", optional_argument
, NULL
, OPTION_TRACE_SEMANTICS
},
105 '\0', "on|off", "Perform ALU, FPU, MEMORY, and BRANCH tracing",
106 trace_option_handler
},
107 { {"trace-model", optional_argument
, NULL
, OPTION_TRACE_MODEL
},
108 '\0', "on|off", "Include model performance data",
109 trace_option_handler
},
110 { {"trace-core", optional_argument
, NULL
, OPTION_TRACE_CORE
},
111 '\0', "on|off", "Trace core operations",
112 trace_option_handler
},
113 { {"trace-events", optional_argument
, NULL
, OPTION_TRACE_EVENTS
},
114 '\0', "on|off", "Trace events",
115 trace_option_handler
},
116 { {"trace-debug", optional_argument
, NULL
, OPTION_TRACE_DEBUG
},
117 '\0', "on|off", "Add information useful for debugging the simulator to the tracing output",
118 trace_option_handler
},
119 { {"trace-file", required_argument
, NULL
, OPTION_TRACE_FILE
},
120 '\0', "FILE NAME", "Specify tracing output file",
121 trace_option_handler
},
122 { {NULL
, no_argument
, NULL
, 0}, '\0', NULL
, NULL
, NULL
}
125 /* Set/reset the trace options indicated in MASK. */
128 set_trace_option_mask (sd
, name
, mask
, arg
)
140 if (strcmp (arg
, "yes") == 0
141 || strcmp (arg
, "on") == 0
142 || strcmp (arg
, "1") == 0)
144 else if (strcmp (arg
, "no") == 0
145 || strcmp (arg
, "off") == 0
146 || strcmp (arg
, "0") == 0)
150 sim_io_eprintf (sd
, "Argument `%s' for `--trace%s' invalid, one of `on', `off', `yes', `no' expected\n", arg
, name
);
155 for (trace_nr
= 0; trace_nr
< MAX_TRACE_VALUES
; ++trace_nr
)
157 if ((mask
& (1 << trace_nr
)) == 0)
160 /* Set non-cpu specific values. */
163 case TRACE_EVENTS_IDX
:
164 STATE_EVENTS (sd
)->trace
= trace_val
;
166 case TRACE_DEBUG_IDX
:
167 STATE_TRACE_FLAGS (sd
)[trace_nr
] = trace_val
;
171 /* Set cpu values. */
172 for (cpu_nr
= 0; cpu_nr
< MAX_NR_PROCESSORS
; cpu_nr
++)
174 CPU_TRACE_FLAGS (STATE_CPU (sd
, cpu_nr
))[trace_nr
] = trace_val
;
181 /* Set one trace option based on its IDX value. */
184 set_trace_option (sd
, name
, idx
, arg
)
190 return set_trace_option_mask (sd
, name
, 1 << idx
, arg
);
195 trace_option_handler (sd
, opt
, arg
, is_command
)
207 sim_io_eprintf (sd
, "Tracing not compiled in, `-t' ignored\n");
209 return set_trace_option_mask (sd
, "trace", TRACE_USEFUL_MASK
, arg
);
212 case OPTION_TRACE_INSN
:
213 if (WITH_TRACE_INSN_P
)
214 return set_trace_option (sd
, "-insn", TRACE_INSN_IDX
, arg
);
216 sim_io_eprintf (sd
, "Instruction tracing not compiled in, `--trace-insn' ignored\n");
219 case OPTION_TRACE_DECODE
:
220 if (WITH_TRACE_DECODE_P
)
221 return set_trace_option (sd
, "-decode", TRACE_DECODE_IDX
, arg
);
223 sim_io_eprintf (sd
, "Decode tracing not compiled in, `--trace-decode' ignored\n");
226 case OPTION_TRACE_EXTRACT
:
227 if (WITH_TRACE_EXTRACT_P
)
228 return set_trace_option (sd
, "-extract", TRACE_EXTRACT_IDX
, arg
);
230 sim_io_eprintf (sd
, "Extract tracing not compiled in, `--trace-extract' ignored\n");
233 case OPTION_TRACE_LINENUM
:
234 if (WITH_TRACE_LINENUM_P
&& WITH_TRACE_INSN_P
)
236 if (set_trace_option (sd
, "-linenum", TRACE_LINENUM_IDX
, arg
) != SIM_RC_OK
237 || set_trace_option (sd
, "-linenum", TRACE_INSN_IDX
, arg
) != SIM_RC_OK
)
241 sim_io_eprintf (sd
, "Line number or instruction tracing not compiled in, `--trace-linenum' ignored\n");
244 case OPTION_TRACE_MEMORY
:
245 if (WITH_TRACE_MEMORY_P
)
246 return set_trace_option (sd
, "-memory", TRACE_MEMORY_IDX
, arg
);
248 sim_io_eprintf (sd
, "Memory tracing not compiled in, `--trace-memory' ignored\n");
251 case OPTION_TRACE_MODEL
:
252 if (WITH_TRACE_MODEL_P
)
253 return set_trace_option (sd
, "-model", TRACE_MODEL_IDX
, arg
);
255 sim_io_eprintf (sd
, "Model tracing not compiled in, `--trace-model' ignored\n");
258 case OPTION_TRACE_ALU
:
259 if (WITH_TRACE_ALU_P
)
260 return set_trace_option (sd
, "-alu", TRACE_ALU_IDX
, arg
);
262 sim_io_eprintf (sd
, "ALU tracing not compiled in, `--trace-alu' ignored\n");
265 case OPTION_TRACE_CORE
:
266 if (WITH_TRACE_CORE_P
)
267 return set_trace_option (sd
, "-core", TRACE_CORE_IDX
, arg
);
269 sim_io_eprintf (sd
, "CORE tracing not compiled in, `--trace-core' ignored\n");
272 case OPTION_TRACE_EVENTS
:
273 if (WITH_TRACE_EVENTS_P
)
274 return set_trace_option (sd
, "-events", TRACE_EVENTS_IDX
, arg
);
276 sim_io_eprintf (sd
, "EVENTS tracing not compiled in, `--trace-events' ignored\n");
279 case OPTION_TRACE_FPU
:
280 if (WITH_TRACE_FPU_P
)
281 return set_trace_option (sd
, "-fpu", TRACE_FPU_IDX
, arg
);
283 sim_io_eprintf (sd
, "FPU tracing not compiled in, `--trace-fpu' ignored\n");
286 case OPTION_TRACE_BRANCH
:
287 if (WITH_TRACE_BRANCH_P
)
288 return set_trace_option (sd
, "-branch", TRACE_BRANCH_IDX
, arg
);
290 sim_io_eprintf (sd
, "Branch tracing not compiled in, `--trace-branch' ignored\n");
293 case OPTION_TRACE_SEMANTICS
:
296 && WITH_TRACE_MEMORY_P
297 && WITH_TRACE_BRANCH_P
)
299 if (set_trace_option (sd
, "-semantics", TRACE_ALU_IDX
, arg
) != SIM_RC_OK
300 || set_trace_option (sd
, "-semantics", TRACE_FPU_IDX
, arg
) != SIM_RC_OK
301 || set_trace_option (sd
, "-semantics", TRACE_MEMORY_IDX
, arg
) != SIM_RC_OK
302 || set_trace_option (sd
, "-semantics", TRACE_BRANCH_IDX
, arg
) != SIM_RC_OK
)
306 sim_io_eprintf (sd
, "Alu, fpu, memory, and/or branch tracing not compiled in, `--trace-semantics' ignored\n");
309 case OPTION_TRACE_DEBUG
:
310 if (WITH_TRACE_DEBUG_P
)
311 return set_trace_option (sd
, "-debug", TRACE_DEBUG_IDX
, arg
);
313 sim_io_eprintf (sd
, "Tracing debug support not compiled in, `--trace-debug' ignored\n");
316 case OPTION_TRACE_FILE
:
318 sim_io_eprintf (sd
, "Tracing not compiled in, `--trace-file' ignored\n");
321 FILE *f
= fopen (arg
, "w");
325 sim_io_eprintf (sd
, "Unable to open trace output file `%s'\n", arg
);
328 for (n
= 0; n
< MAX_NR_PROCESSORS
; ++n
)
329 TRACE_FILE (CPU_TRACE_DATA (STATE_CPU (sd
, n
))) = f
;
330 TRACE_FILE (STATE_TRACE_DATA (sd
)) = f
;
338 /* Install tracing support. */
341 trace_install (SIM_DESC sd
)
345 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
347 sim_add_option_table (sd
, trace_options
);
348 memset (STATE_TRACE_DATA (sd
), 0, sizeof (* STATE_TRACE_DATA (sd
)));
349 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
350 memset (CPU_TRACE_DATA (STATE_CPU (sd
, i
)), 0,
351 sizeof (* CPU_TRACE_DATA (STATE_CPU (sd
, i
))));
352 sim_module_add_uninstall_fn (sd
, trace_uninstall
);
357 trace_uninstall (SIM_DESC sd
)
360 FILE *sfile
= TRACE_FILE (STATE_TRACE_DATA (sd
));
365 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
367 FILE *cfile
= TRACE_FILE (CPU_TRACE_DATA (STATE_CPU (sd
, i
)));
368 if (cfile
!= NULL
&& cfile
!= sfile
)
370 /* If output from different cpus is going to the same file,
371 avoid closing the file twice. */
372 for (j
= 0; j
< i
; ++j
)
373 if (TRACE_FILE (CPU_TRACE_DATA (STATE_CPU (sd
, j
))) == cfile
)
387 trace_fmt_instruction_incomplete
,
390 /* compute the nr of trace data units consumed by data */
392 save_data_size (TRACE_DATA
*data
,
395 return ((size
+ sizeof (TRACE_INPUT_DATA (data
) [0]) - 1)
396 / sizeof (TRACE_INPUT_DATA (data
) [0]));
400 /* Archive DATA into the trace buffer */
402 save_data (SIM_DESC sd
,
408 int i
= TRACE_INPUT_IDX (data
);
409 if (i
== sizeof (TRACE_INPUT_FMT (data
)))
410 sim_io_error (sd
, "trace buffer overflow");
411 TRACE_INPUT_FMT (data
) [i
] = fmt
;
412 TRACE_INPUT_SIZE (data
) [i
] = size
;
413 memcpy (&TRACE_INPUT_DATA (data
) [i
], buf
, size
);
414 i
+= save_data_size (data
, size
);
415 TRACE_INPUT_IDX (data
) = i
;
419 print_data (SIM_DESC sd
,
427 case trace_fmt_instruction_incomplete
:
428 trace_printf (sd
, cpu
, " (instruction incomplete)");
433 case sizeof (unsigned_word
):
434 trace_printf (sd
, cpu
, " 0x%08lx", (long) * (unsigned_word
*) data
);
443 /* FIXME: Assumes sizeof float == 4; sizeof double == 8 */
445 trace_printf (sd
, cpu
, " %8g", * (float*) data
);
448 trace_printf (sd
, cpu
, " %8g", * (double*) data
);
454 /* FIXME: At present sim_fpu data is stored as a double */
455 trace_printf (sd
, cpu
, " %8g", * (double*) data
);
457 case trace_fmt_string
:
458 trace_printf (sd
, cpu
, " %-8s", (char*) data
);
466 trace_idx_to_str (int trace_idx
)
471 case TRACE_ALU_IDX
: return "alu: ";
472 case TRACE_INSN_IDX
: return "insn: ";
473 case TRACE_DECODE_IDX
: return "decode: ";
474 case TRACE_EXTRACT_IDX
: return "extract: ";
475 case TRACE_MEMORY_IDX
: return "memory: ";
476 case TRACE_CORE_IDX
: return "core: ";
477 case TRACE_EVENTS_IDX
: return "events: ";
478 case TRACE_FPU_IDX
: return "fpu: ";
479 case TRACE_BRANCH_IDX
: return "branch: ";
481 sprintf (num
, "?%d?", trace_idx
);
487 trace_results (SIM_DESC sd
,
492 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
496 /* cross check trace_idx against TRACE_IDX (data)? */
499 trace_printf (sd
, cpu
, "%s %s",
500 trace_idx_to_str (TRACE_IDX (data
)),
501 TRACE_PREFIX (data
));
502 TRACE_IDX (data
) = 0;
504 for (i
= 0, nr_out
= 0;
505 i
< TRACE_INPUT_IDX (data
);
506 i
+= save_data_size (data
, TRACE_INPUT_SIZE (data
) [i
]), nr_out
++)
510 int pad
= (strlen (" 0x") + sizeof (unsigned_word
) * 2);
511 int padding
= pad
* (3 - nr_out
);
514 padding
+= strlen (" ::");
515 trace_printf (sd
, cpu
, "%*s", padding
, " ::");
518 TRACE_INPUT_FMT (data
) [i
],
519 TRACE_INPUT_SIZE (data
) [i
],
520 &TRACE_INPUT_DATA (data
) [i
]);
522 trace_printf (sd
, cpu
, "\n");
526 trace_prefix (SIM_DESC sd
,
530 const char *filename
,
535 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
537 char *prefix
= TRACE_PREFIX (data
);
540 /* if the previous trace data wasn't flushed, flush it now with a
541 note indicating that this occured. */
542 if (TRACE_IDX (data
) != 0)
544 int last_input
= TRACE_INPUT_IDX (data
);
545 save_data (sd
, data
, trace_fmt_instruction_incomplete
, 1, "");
546 trace_results (sd
, cpu
, TRACE_IDX (data
), last_input
);
548 TRACE_IDX (data
) = 0;
549 TRACE_INPUT_IDX (data
) = 0;
553 sprintf (prefix
, "%s:%-*d 0x%.*lx ",
555 SIZE_LINE_NUMBER
, linenum
,
557 chp
= strchr (prefix
, '\0');
559 vsprintf (chp
, fmt
, ap
);
566 if (STATE_TEXT_SECTION (CPU_STATE (cpu
))
567 && pc
>= STATE_TEXT_START (CPU_STATE (cpu
))
568 && pc
< STATE_TEXT_END (CPU_STATE (cpu
)))
570 const char *pc_filename
= (const char *)0;
571 const char *pc_function
= (const char *)0;
572 unsigned int pc_linenum
= 0;
574 if (bfd_find_nearest_line (STATE_PROG_BFD (CPU_STATE (cpu
)),
575 STATE_TEXT_SECTION (CPU_STATE (cpu
)),
576 (struct symbol_cache_entry
**) 0,
577 pc
- STATE_TEXT_START (CPU_STATE (cpu
)),
578 &pc_filename
, &pc_function
, &pc_linenum
))
583 sprintf (p
, "#%-*d ", SIZE_LINE_NUMBER
, pc_linenum
);
588 sprintf (p
, "%-*s ", SIZE_LINE_NUMBER
+1, "---");
589 p
+= SIZE_LINE_NUMBER
+2;
594 sprintf (p
, "%s ", pc_function
);
597 else if (pc_filename
)
599 char *q
= (char *) strrchr (pc_filename
, '/');
600 sprintf (p
, "%s ", (q
) ? q
+1 : pc_filename
);
609 sprintf (prefix
, "0x%.*x %-*.*s ",
610 SIZE_PC
, (unsigned) pc
,
611 SIZE_LOCATION
, SIZE_LOCATION
, buf
);
612 chp
= strchr (prefix
, '\0');
614 vsprintf (chp
, fmt
, ap
);
618 /* pad it out to TRACE_PREFIX_WIDTH. FIXME: The TRACE_PREFIX_WIDTH
619 should be determined at build time using known information about
620 the disassembled instructions */
621 #ifndef TRACE_PREFIX_WIDTH
622 #define TRACE_PREFIX_WIDTH 48
624 chp
= strchr (prefix
, '\0');
625 if (chp
- prefix
< TRACE_PREFIX_WIDTH
)
627 memset (chp
, ' ', TRACE_PREFIX_WIDTH
- (chp
- prefix
));
628 chp
= &prefix
[TRACE_PREFIX_WIDTH
];
633 /* check that we've not over flowed the prefix buffer */
634 if (strlen (prefix
) >= sizeof (TRACE_PREFIX (data
)))
639 trace_generic (SIM_DESC sd
,
646 trace_printf (sd
, cpu
, "%s %s",
647 trace_idx_to_str (trace_idx
),
648 TRACE_PREFIX (CPU_TRACE_DATA (cpu
)));
650 trace_vprintf (sd
, cpu
, fmt
, ap
);
652 trace_printf (sd
, cpu
, "\n");
656 trace_input0 (SIM_DESC sd
,
660 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
661 TRACE_IDX (data
) = trace_idx
;
665 trace_input_word1 (SIM_DESC sd
,
670 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
671 TRACE_IDX (data
) = trace_idx
;
672 save_data (sd
, data
, trace_fmt_word
, sizeof (unsigned_word
), &d0
);
676 trace_input_word2 (SIM_DESC sd
,
682 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
683 TRACE_IDX (data
) = trace_idx
;
684 save_data (sd
, data
, trace_fmt_word
, sizeof (unsigned_word
), &d0
);
685 save_data (sd
, data
, trace_fmt_word
, sizeof (unsigned_word
), &d1
);
689 trace_input_word3 (SIM_DESC sd
,
696 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
697 TRACE_IDX (data
) = trace_idx
;
698 save_data (sd
, data
, trace_fmt_word
, sizeof (unsigned_word
), &d0
);
699 save_data (sd
, data
, trace_fmt_word
, sizeof (unsigned_word
), &d1
);
700 save_data (sd
, data
, trace_fmt_word
, sizeof (unsigned_word
), &d2
);
704 trace_input_fp1 (SIM_DESC sd
,
709 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
710 TRACE_IDX (data
) = trace_idx
;
711 save_data (sd
, data
, trace_fmt_fp
, sizeof (fp_word
), &f0
);
715 trace_input_fp2 (SIM_DESC sd
,
721 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
722 TRACE_IDX (data
) = trace_idx
;
723 save_data (sd
, data
, trace_fmt_fp
, sizeof (fp_word
), &f0
);
724 save_data (sd
, data
, trace_fmt_fp
, sizeof (fp_word
), &f1
);
728 trace_input_fp3 (SIM_DESC sd
,
735 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
736 TRACE_IDX (data
) = trace_idx
;
737 save_data (sd
, data
, trace_fmt_fp
, sizeof (fp_word
), &f0
);
738 save_data (sd
, data
, trace_fmt_fp
, sizeof (fp_word
), &f1
);
739 save_data (sd
, data
, trace_fmt_fp
, sizeof (fp_word
), &f2
);
743 trace_input_fpu1 (SIM_DESC sd
,
749 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
750 TRACE_IDX (data
) = trace_idx
;
752 save_data (sd
, data
, trace_fmt_fp
, sizeof (double), &d
);
756 trace_input_fpu2 (SIM_DESC sd
,
763 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
764 TRACE_IDX (data
) = trace_idx
;
766 save_data (sd
, data
, trace_fmt_fp
, sizeof (double), &d
);
768 save_data (sd
, data
, trace_fmt_fp
, sizeof (double), &d
);
772 trace_input_fpu3 (SIM_DESC sd
,
780 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
781 TRACE_IDX (data
) = trace_idx
;
783 save_data (sd
, data
, trace_fmt_fp
, sizeof (double), &d
);
785 save_data (sd
, data
, trace_fmt_fp
, sizeof (double), &d
);
787 save_data (sd
, data
, trace_fmt_fp
, sizeof (double), &d
);
791 trace_result_word1 (SIM_DESC sd
,
796 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
799 /* Append any results to the end of the inputs */
800 last_input
= TRACE_INPUT_IDX (data
);
801 save_data (sd
, data
, trace_fmt_word
, sizeof (unsigned_word
), &r0
);
803 trace_results (sd
, cpu
, trace_idx
, last_input
);
807 trace_result_fp1 (SIM_DESC sd
,
812 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
815 /* Append any results to the end of the inputs */
816 last_input
= TRACE_INPUT_IDX (data
);
817 save_data (sd
, data
, trace_fmt_fp
, sizeof (fp_word
), &f0
);
819 trace_results (sd
, cpu
, trace_idx
, last_input
);
823 trace_result_fpu1 (SIM_DESC sd
,
829 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
832 /* Append any results to the end of the inputs */
833 last_input
= TRACE_INPUT_IDX (data
);
835 save_data (sd
, data
, trace_fmt_fp
, sizeof (double), &d
);
837 trace_results (sd
, cpu
, trace_idx
, last_input
);
841 trace_result_string1 (SIM_DESC sd
,
846 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
849 /* Append any results to the end of the inputs */
850 last_input
= TRACE_INPUT_IDX (data
);
851 save_data (sd
, data
, trace_fmt_string
, strlen (s0
) + 1, s0
);
853 trace_results (sd
, cpu
, trace_idx
, last_input
);
857 trace_result_word1_string1 (SIM_DESC sd
,
863 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
866 /* Append any results to the end of the inputs */
867 last_input
= TRACE_INPUT_IDX (data
);
868 save_data (sd
, data
, trace_fmt_word
, sizeof (unsigned_word
), &r0
);
869 save_data (sd
, data
, trace_fmt_string
, strlen (s0
) + 1, s0
);
871 trace_results (sd
, cpu
, trace_idx
, last_input
);
875 trace_vprintf (SIM_DESC sd
, sim_cpu
*cpu
, const char *fmt
, va_list ap
)
879 if (TRACE_FILE (CPU_TRACE_DATA (cpu
)) != NULL
)
880 vfprintf (TRACE_FILE (CPU_TRACE_DATA (cpu
)), fmt
, ap
);
882 sim_io_evprintf (sd
, fmt
, ap
);
886 if (TRACE_FILE (STATE_TRACE_DATA (sd
)) != NULL
)
887 vfprintf (TRACE_FILE (STATE_TRACE_DATA (sd
)), fmt
, ap
);
889 sim_io_evprintf (sd
, fmt
, ap
);
894 trace_one_insn (SIM_DESC sd
, sim_cpu
*cpu
, address_word pc
,
895 int line_p
, const char *filename
, int linenum
,
896 const char *phase_wo_colon
, const char *fmt
,
900 char phase
[SIZE_PHASE
+2];
902 strncpy (phase
, phase_wo_colon
, SIZE_PHASE
);
907 trace_printf (sd
, cpu
, "%-*s %s:%-*d 0x%.*lx ",
910 SIZE_LINE_NUMBER
, linenum
,
913 trace_vprintf (sd
, cpu
, fmt
, ap
);
915 trace_printf (sd
, cpu
, "\n");
922 if (STATE_TEXT_SECTION (CPU_STATE (cpu
))
923 && pc
>= STATE_TEXT_START (CPU_STATE (cpu
))
924 && pc
< STATE_TEXT_END (CPU_STATE (cpu
)))
926 const char *pc_filename
= (const char *)0;
927 const char *pc_function
= (const char *)0;
928 unsigned int pc_linenum
= 0;
930 if (bfd_find_nearest_line (STATE_PROG_BFD (CPU_STATE (cpu
)),
931 STATE_TEXT_SECTION (CPU_STATE (cpu
)),
932 (struct symbol_cache_entry
**) 0,
933 pc
- STATE_TEXT_START (CPU_STATE (cpu
)),
934 &pc_filename
, &pc_function
, &pc_linenum
))
939 sprintf (p
, "#%-*d ", SIZE_LINE_NUMBER
, pc_linenum
);
944 sprintf (p
, "%-*s ", SIZE_LINE_NUMBER
+1, "---");
945 p
+= SIZE_LINE_NUMBER
+2;
950 sprintf (p
, "%s ", pc_function
);
953 else if (pc_filename
)
955 char *q
= (char *) strrchr (pc_filename
, '/');
956 sprintf (p
, "%s ", (q
) ? q
+1 : pc_filename
);
965 trace_printf (sd
, cpu
, "%-*s 0x%.*x %-*.*s ",
967 SIZE_PC
, (unsigned) pc
,
968 SIZE_LOCATION
, SIZE_LOCATION
, buf
);
970 trace_vprintf (sd
, cpu
, fmt
, ap
);
972 trace_printf (sd
, cpu
, "\n");
977 trace_printf
VPARAMS ((SIM_DESC sd
, sim_cpu
*cpu
, const char *fmt
, ...))
979 #if !defined __STDC__ && !defined ALMOST_STDC
987 #if !defined __STDC__ && !defined ALMOST_STDC
988 sd
= va_arg (ap
, SIM_DESC
);
989 cpu
= va_arg (ap
, sim_cpu
*);
990 fmt
= va_arg (ap
, const char *);
993 trace_vprintf (sd
, cpu
, fmt
, ap
);
999 debug_printf
VPARAMS ((sim_cpu
*cpu
, const char *fmt
, ...))
1001 #if !defined __STDC__ && !defined ALMOST_STDC
1008 #if !defined __STDC__ && !defined ALMOST_STDC
1009 cpu
= va_arg (ap
, sim_cpu
*);
1010 fmt
= va_arg (ap
, const char *);
1013 if (CPU_DEBUG_FILE (cpu
) == NULL
)
1014 (* STATE_CALLBACK (CPU_STATE (cpu
))->evprintf_filtered
)
1015 (STATE_CALLBACK (CPU_STATE (cpu
)), fmt
, ap
);
1017 vfprintf (CPU_DEBUG_FILE (cpu
), fmt
, ap
);