1 /* Simulator tracing/debugging support.
2 Copyright (C) 1997, 1998, 2001 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 "libiberty.h"
29 #include "sim-assert.h"
47 #define SIZE_LOCATION 20
54 #ifndef SIZE_LINE_NUMBER
55 #define SIZE_LINE_NUMBER 4
58 static MODULE_INIT_FN trace_init
;
59 static MODULE_UNINSTALL_FN trace_uninstall
;
61 static DECLARE_OPTION_HANDLER (trace_option_handler
);
64 OPTION_TRACE_INSN
= OPTION_START
,
75 OPTION_TRACE_SEMANTICS
,
77 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
},
89 { {"trace-insn", optional_argument
, NULL
, OPTION_TRACE_INSN
},
90 '\0', "on|off", "Perform instruction tracing",
91 trace_option_handler
},
92 { {"trace-decode", optional_argument
, NULL
, OPTION_TRACE_DECODE
},
93 '\0', "on|off", "Trace instruction decoding",
94 trace_option_handler
},
95 { {"trace-extract", optional_argument
, NULL
, OPTION_TRACE_EXTRACT
},
96 '\0', "on|off", "Trace instruction extraction",
97 trace_option_handler
},
98 { {"trace-linenum", optional_argument
, NULL
, OPTION_TRACE_LINENUM
},
99 '\0', "on|off", "Perform line number tracing (implies --trace-insn)",
100 trace_option_handler
},
101 { {"trace-memory", optional_argument
, NULL
, OPTION_TRACE_MEMORY
},
102 '\0', "on|off", "Trace memory operations",
103 trace_option_handler
},
104 { {"trace-alu", optional_argument
, NULL
, OPTION_TRACE_ALU
},
105 '\0', "on|off", "Trace ALU operations",
106 trace_option_handler
},
107 { {"trace-fpu", optional_argument
, NULL
, OPTION_TRACE_FPU
},
108 '\0', "on|off", "Trace FPU operations",
109 trace_option_handler
},
110 { {"trace-vpu", optional_argument
, NULL
, OPTION_TRACE_VPU
},
111 '\0', "on|off", "Trace VPU operations",
112 trace_option_handler
},
113 { {"trace-branch", optional_argument
, NULL
, OPTION_TRACE_BRANCH
},
114 '\0', "on|off", "Trace branching",
115 trace_option_handler
},
116 { {"trace-semantics", optional_argument
, NULL
, OPTION_TRACE_SEMANTICS
},
117 '\0', "on|off", "Perform ALU, FPU, MEMORY, and BRANCH tracing",
118 trace_option_handler
},
119 { {"trace-model", optional_argument
, NULL
, OPTION_TRACE_MODEL
},
120 '\0', "on|off", "Include model performance data",
121 trace_option_handler
},
122 { {"trace-core", optional_argument
, NULL
, OPTION_TRACE_CORE
},
123 '\0', "on|off", "Trace core operations",
124 trace_option_handler
},
125 { {"trace-events", optional_argument
, NULL
, OPTION_TRACE_EVENTS
},
126 '\0', "on|off", "Trace events",
127 trace_option_handler
},
128 #ifdef SIM_HAVE_ADDR_RANGE
129 { {"trace-range", required_argument
, NULL
, OPTION_TRACE_RANGE
},
130 '\0', "START,END", "Specify range of addresses for instruction tracing",
131 trace_option_handler
},
133 { {"trace-function", required_argument
, NULL
, OPTION_TRACE_FUNCTION
},
134 '\0', "FUNCTION", "Specify function to trace",
135 trace_option_handler
},
138 { {"trace-debug", optional_argument
, NULL
, OPTION_TRACE_DEBUG
},
139 '\0', "on|off", "Add information useful for debugging the simulator to the tracing output",
140 trace_option_handler
},
141 { {"trace-file", required_argument
, NULL
, OPTION_TRACE_FILE
},
142 '\0', "FILE NAME", "Specify tracing output file",
143 trace_option_handler
},
144 { {NULL
, no_argument
, NULL
, 0}, '\0', NULL
, NULL
, NULL
}
147 /* Set/reset the trace options indicated in MASK. */
150 set_trace_option_mask (sd
, name
, mask
, arg
)
162 if (strcmp (arg
, "yes") == 0
163 || strcmp (arg
, "on") == 0
164 || strcmp (arg
, "1") == 0)
166 else if (strcmp (arg
, "no") == 0
167 || strcmp (arg
, "off") == 0
168 || strcmp (arg
, "0") == 0)
172 sim_io_eprintf (sd
, "Argument `%s' for `--trace%s' invalid, one of `on', `off', `yes', `no' expected\n", arg
, name
);
177 /* update applicable trace bits */
178 for (trace_nr
= 0; trace_nr
< MAX_TRACE_VALUES
; ++trace_nr
)
180 if ((mask
& (1 << trace_nr
)) == 0)
183 /* Set non-cpu specific values. */
186 case TRACE_EVENTS_IDX
:
187 STATE_EVENTS (sd
)->trace
= trace_val
;
189 case TRACE_DEBUG_IDX
:
190 STATE_TRACE_FLAGS (sd
)[trace_nr
] = trace_val
;
194 /* Set cpu values. */
195 for (cpu_nr
= 0; cpu_nr
< MAX_NR_PROCESSORS
; cpu_nr
++)
197 CPU_TRACE_FLAGS (STATE_CPU (sd
, cpu_nr
))[trace_nr
] = trace_val
;
201 /* Re-compute the cpu trace summary. */
204 for (cpu_nr
= 0; cpu_nr
< MAX_NR_PROCESSORS
; cpu_nr
++)
205 CPU_TRACE_DATA (STATE_CPU (sd
, cpu_nr
))->trace_any_p
= 1;
209 for (cpu_nr
= 0; cpu_nr
< MAX_NR_PROCESSORS
; cpu_nr
++)
211 CPU_TRACE_DATA (STATE_CPU (sd
, cpu_nr
))->trace_any_p
= 0;
212 for (trace_nr
= 0; trace_nr
< MAX_TRACE_VALUES
; ++trace_nr
)
214 if (CPU_TRACE_FLAGS (STATE_CPU (sd
, cpu_nr
))[trace_nr
])
216 CPU_TRACE_DATA (STATE_CPU (sd
, cpu_nr
))->trace_any_p
= 1;
226 /* Set one trace option based on its IDX value. */
229 set_trace_option (sd
, name
, idx
, arg
)
235 return set_trace_option_mask (sd
, name
, 1 << idx
, arg
);
240 trace_option_handler (SIM_DESC sd
, sim_cpu
*cpu
, int opt
,
241 char *arg
, int is_command
)
250 sim_io_eprintf (sd
, "Tracing not compiled in, `-t' ignored\n");
252 return set_trace_option_mask (sd
, "trace", TRACE_USEFUL_MASK
, arg
);
255 case OPTION_TRACE_INSN
:
256 if (WITH_TRACE_INSN_P
)
257 return set_trace_option (sd
, "-insn", TRACE_INSN_IDX
, arg
);
259 sim_io_eprintf (sd
, "Instruction tracing not compiled in, `--trace-insn' ignored\n");
262 case OPTION_TRACE_DECODE
:
263 if (WITH_TRACE_DECODE_P
)
264 return set_trace_option (sd
, "-decode", TRACE_DECODE_IDX
, arg
);
266 sim_io_eprintf (sd
, "Decode tracing not compiled in, `--trace-decode' ignored\n");
269 case OPTION_TRACE_EXTRACT
:
270 if (WITH_TRACE_EXTRACT_P
)
271 return set_trace_option (sd
, "-extract", TRACE_EXTRACT_IDX
, arg
);
273 sim_io_eprintf (sd
, "Extract tracing not compiled in, `--trace-extract' ignored\n");
276 case OPTION_TRACE_LINENUM
:
277 if (WITH_TRACE_LINENUM_P
&& WITH_TRACE_INSN_P
)
279 if (set_trace_option (sd
, "-linenum", TRACE_LINENUM_IDX
, arg
) != SIM_RC_OK
280 || set_trace_option (sd
, "-linenum", TRACE_INSN_IDX
, arg
) != SIM_RC_OK
)
284 sim_io_eprintf (sd
, "Line number or instruction tracing not compiled in, `--trace-linenum' ignored\n");
287 case OPTION_TRACE_MEMORY
:
288 if (WITH_TRACE_MEMORY_P
)
289 return set_trace_option (sd
, "-memory", TRACE_MEMORY_IDX
, arg
);
291 sim_io_eprintf (sd
, "Memory tracing not compiled in, `--trace-memory' ignored\n");
294 case OPTION_TRACE_MODEL
:
295 if (WITH_TRACE_MODEL_P
)
296 return set_trace_option (sd
, "-model", TRACE_MODEL_IDX
, arg
);
298 sim_io_eprintf (sd
, "Model tracing not compiled in, `--trace-model' ignored\n");
301 case OPTION_TRACE_ALU
:
302 if (WITH_TRACE_ALU_P
)
303 return set_trace_option (sd
, "-alu", TRACE_ALU_IDX
, arg
);
305 sim_io_eprintf (sd
, "ALU tracing not compiled in, `--trace-alu' ignored\n");
308 case OPTION_TRACE_CORE
:
309 if (WITH_TRACE_CORE_P
)
310 return set_trace_option (sd
, "-core", TRACE_CORE_IDX
, arg
);
312 sim_io_eprintf (sd
, "CORE tracing not compiled in, `--trace-core' ignored\n");
315 case OPTION_TRACE_EVENTS
:
316 if (WITH_TRACE_EVENTS_P
)
317 return set_trace_option (sd
, "-events", TRACE_EVENTS_IDX
, arg
);
319 sim_io_eprintf (sd
, "EVENTS tracing not compiled in, `--trace-events' ignored\n");
322 case OPTION_TRACE_FPU
:
323 if (WITH_TRACE_FPU_P
)
324 return set_trace_option (sd
, "-fpu", TRACE_FPU_IDX
, arg
);
326 sim_io_eprintf (sd
, "FPU tracing not compiled in, `--trace-fpu' ignored\n");
329 case OPTION_TRACE_VPU
:
330 if (WITH_TRACE_VPU_P
)
331 return set_trace_option (sd
, "-vpu", TRACE_VPU_IDX
, arg
);
333 sim_io_eprintf (sd
, "VPU tracing not compiled in, `--trace-vpu' ignored\n");
336 case OPTION_TRACE_BRANCH
:
337 if (WITH_TRACE_BRANCH_P
)
338 return set_trace_option (sd
, "-branch", TRACE_BRANCH_IDX
, arg
);
340 sim_io_eprintf (sd
, "Branch tracing not compiled in, `--trace-branch' ignored\n");
343 case OPTION_TRACE_SEMANTICS
:
346 && WITH_TRACE_MEMORY_P
347 && WITH_TRACE_BRANCH_P
)
349 if (set_trace_option (sd
, "-semantics", TRACE_ALU_IDX
, arg
) != SIM_RC_OK
350 || set_trace_option (sd
, "-semantics", TRACE_FPU_IDX
, arg
) != SIM_RC_OK
351 || set_trace_option (sd
, "-semantics", TRACE_VPU_IDX
, arg
) != SIM_RC_OK
352 || set_trace_option (sd
, "-semantics", TRACE_MEMORY_IDX
, arg
) != SIM_RC_OK
353 || set_trace_option (sd
, "-semantics", TRACE_BRANCH_IDX
, arg
) != SIM_RC_OK
)
357 sim_io_eprintf (sd
, "Alu, fpu, memory, and/or branch tracing not compiled in, `--trace-semantics' ignored\n");
360 #ifdef SIM_HAVE_ADDR_RANGE
361 case OPTION_TRACE_RANGE
:
365 unsigned long start
,end
;
366 start
= strtoul (chp
, &chp
, 0);
369 sim_io_eprintf (sd
, "--trace-range missing END argument\n");
372 end
= strtoul (chp
+ 1, NULL
, 0);
373 /* FIXME: Argument validation. */
375 sim_addr_range_add (TRACE_RANGE (CPU_PROFILE_DATA (cpu
)),
378 for (cpu_nr
= 0; cpu_nr
< MAX_NR_PROCESSORS
; ++cpu_nr
)
379 sim_addr_range_add (TRACE_RANGE (CPU_TRACE_DATA (STATE_CPU (sd
, cpu_nr
))),
383 sim_io_eprintf (sd
, "Tracing not compiled in, `--trace-range' ignored\n");
386 case OPTION_TRACE_FUNCTION
:
389 /*wip: need to compute function range given name*/
392 sim_io_eprintf (sd
, "Tracing not compiled in, `--trace-function' ignored\n");
394 #endif /* SIM_HAVE_ADDR_RANGE */
396 case OPTION_TRACE_DEBUG
:
397 if (WITH_TRACE_DEBUG_P
)
398 return set_trace_option (sd
, "-debug", TRACE_DEBUG_IDX
, arg
);
400 sim_io_eprintf (sd
, "Tracing debug support not compiled in, `--trace-debug' ignored\n");
403 case OPTION_TRACE_FILE
:
405 sim_io_eprintf (sd
, "Tracing not compiled in, `--trace-file' ignored\n");
408 FILE *f
= fopen (arg
, "w");
412 sim_io_eprintf (sd
, "Unable to open trace output file `%s'\n", arg
);
415 for (n
= 0; n
< MAX_NR_PROCESSORS
; ++n
)
416 TRACE_FILE (CPU_TRACE_DATA (STATE_CPU (sd
, n
))) = f
;
417 TRACE_FILE (STATE_TRACE_DATA (sd
)) = f
;
425 /* Install tracing support. */
428 trace_install (SIM_DESC sd
)
432 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
434 sim_add_option_table (sd
, NULL
, trace_options
);
435 memset (STATE_TRACE_DATA (sd
), 0, sizeof (* STATE_TRACE_DATA (sd
)));
436 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
437 memset (CPU_TRACE_DATA (STATE_CPU (sd
, i
)), 0,
438 sizeof (* CPU_TRACE_DATA (STATE_CPU (sd
, i
))));
439 sim_module_add_init_fn (sd
, trace_init
);
440 sim_module_add_uninstall_fn (sd
, trace_uninstall
);
445 trace_init (SIM_DESC sd
)
447 #ifdef SIM_HAVE_ADDR_RANGE
448 /* Check if a range has been specified without specifying what to
453 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
455 sim_cpu
*cpu
= STATE_CPU (sd
, i
);
457 if (ADDR_RANGE_RANGES (TRACE_RANGE (CPU_TRACE_DATA (cpu
)))
458 && ! TRACE_INSN_P (cpu
))
460 sim_io_eprintf_cpu (cpu
, "Tracing address range specified without --trace-insn.\n");
461 sim_io_eprintf_cpu (cpu
, "Address range ignored.\n");
462 sim_addr_range_delete (TRACE_RANGE (CPU_TRACE_DATA (cpu
)),
463 0, ~ (address_word
) 0);
473 trace_uninstall (SIM_DESC sd
)
476 FILE *sfile
= TRACE_FILE (STATE_TRACE_DATA (sd
));
481 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
483 FILE *cfile
= TRACE_FILE (CPU_TRACE_DATA (STATE_CPU (sd
, i
)));
484 if (cfile
!= NULL
&& cfile
!= sfile
)
486 /* If output from different cpus is going to the same file,
487 avoid closing the file twice. */
488 for (j
= 0; j
< i
; ++j
)
489 if (TRACE_FILE (CPU_TRACE_DATA (STATE_CPU (sd
, j
))) == cfile
)
505 trace_fmt_instruction_incomplete
,
508 /* compute the nr of trace data units consumed by data */
510 save_data_size (TRACE_DATA
*data
,
513 return ((size
+ sizeof (TRACE_INPUT_DATA (data
) [0]) - 1)
514 / sizeof (TRACE_INPUT_DATA (data
) [0]));
518 /* Archive DATA into the trace buffer */
520 save_data (SIM_DESC sd
,
526 int i
= TRACE_INPUT_IDX (data
);
527 if (i
== sizeof (TRACE_INPUT_FMT (data
)))
528 sim_io_error (sd
, "trace buffer overflow");
529 TRACE_INPUT_FMT (data
) [i
] = fmt
;
530 TRACE_INPUT_SIZE (data
) [i
] = size
;
531 memcpy (&TRACE_INPUT_DATA (data
) [i
], buf
, size
);
532 i
+= save_data_size (data
, size
);
533 TRACE_INPUT_IDX (data
) = i
;
537 print_data (SIM_DESC sd
,
545 case trace_fmt_instruction_incomplete
:
546 trace_printf (sd
, cpu
, " (instruction incomplete)");
553 case sizeof (unsigned32
):
554 trace_printf (sd
, cpu
, " 0x%08lx", (long) * (unsigned32
*) data
);
556 case sizeof (unsigned64
):
557 trace_printf (sd
, cpu
, " 0x%08lx%08lx",
558 (long) ((* (unsigned64
*) data
) >> 32),
559 (long) * (unsigned64
*) data
);
568 SIM_ASSERT (size
== sizeof (int));
569 trace_printf (sd
, cpu
, " %-8s",
570 (* (int*) data
) ? "true" : "false");
578 /* FIXME: Assumes sizeof float == 4; sizeof double == 8 */
580 sim_fpu_32to (&fp
, *(unsigned32
*)data
);
583 sim_fpu_64to (&fp
, *(unsigned64
*)data
);
588 trace_printf (sd
, cpu
, " %8g", sim_fpu_2d (&fp
));
592 trace_printf (sd
, cpu
, " (0x%08lx)",
593 (long) *(unsigned32
*)data
);
596 trace_printf (sd
, cpu
, " (0x%08lx%08lx)",
597 (long) (*(unsigned64
*)data
>> 32),
598 (long) (*(unsigned64
*)data
));
606 /* FIXME: At present sim_fpu data is stored as a double */
607 trace_printf (sd
, cpu
, " %8g", * (double*) data
);
609 case trace_fmt_string
:
610 trace_printf (sd
, cpu
, " %-8s", (char*) data
);
618 trace_idx_to_str (int trace_idx
)
623 case TRACE_ALU_IDX
: return "alu: ";
624 case TRACE_INSN_IDX
: return "insn: ";
625 case TRACE_DECODE_IDX
: return "decode: ";
626 case TRACE_EXTRACT_IDX
: return "extract: ";
627 case TRACE_MEMORY_IDX
: return "memory: ";
628 case TRACE_CORE_IDX
: return "core: ";
629 case TRACE_EVENTS_IDX
: return "events: ";
630 case TRACE_FPU_IDX
: return "fpu: ";
631 case TRACE_BRANCH_IDX
: return "branch: ";
632 case TRACE_VPU_IDX
: return "vpu: ";
634 sprintf (num
, "?%d?", trace_idx
);
640 trace_results (SIM_DESC sd
,
645 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
649 /* cross check trace_idx against TRACE_IDX (data)? */
652 trace_printf (sd
, cpu
, "%s %s",
653 trace_idx_to_str (TRACE_IDX (data
)),
654 TRACE_PREFIX (data
));
655 TRACE_IDX (data
) = 0;
657 for (i
= 0, nr_out
= 0;
658 i
< TRACE_INPUT_IDX (data
);
659 i
+= save_data_size (data
, TRACE_INPUT_SIZE (data
) [i
]), nr_out
++)
663 int pad
= (strlen (" 0x") + sizeof (unsigned_word
) * 2);
664 int padding
= pad
* (3 - nr_out
);
667 padding
+= strlen (" ::");
668 trace_printf (sd
, cpu
, "%*s", padding
, " ::");
671 TRACE_INPUT_FMT (data
) [i
],
672 TRACE_INPUT_SIZE (data
) [i
],
673 &TRACE_INPUT_DATA (data
) [i
]);
675 trace_printf (sd
, cpu
, "\n");
679 trace_prefix (SIM_DESC sd
,
684 const char *filename
,
689 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
691 char *prefix
= TRACE_PREFIX (data
);
693 /* FIXME: The TRACE_PREFIX_WIDTH should be determined at build time using
694 known information about the disassembled instructions. */
695 #ifndef TRACE_PREFIX_WIDTH
696 #define TRACE_PREFIX_WIDTH 48
698 int width
= TRACE_PREFIX_WIDTH
;
700 /* if the previous trace data wasn't flushed, flush it now with a
701 note indicating that the trace was incomplete. */
702 if (TRACE_IDX (data
) != 0)
704 int last_input
= TRACE_INPUT_IDX (data
);
705 save_data (sd
, data
, trace_fmt_instruction_incomplete
, 1, "");
706 trace_results (sd
, cpu
, TRACE_IDX (data
), last_input
);
708 TRACE_IDX (data
) = 0;
709 TRACE_INPUT_IDX (data
) = 0;
711 /* Create the text prefix for this new instruction: */
716 sprintf (prefix
, "%s:%-*d 0x%.*lx ",
718 SIZE_LINE_NUMBER
, linenum
,
723 sprintf (prefix
, "0x%.*lx ",
725 /* Shrink the width by the amount that we didn't print. */
726 width
-= SIZE_LINE_NUMBER
+ SIZE_PC
+ 8;
728 chp
= strchr (prefix
, '\0');
730 vsprintf (chp
, fmt
, ap
);
737 if (STATE_TEXT_SECTION (CPU_STATE (cpu
))
738 && pc
>= STATE_TEXT_START (CPU_STATE (cpu
))
739 && pc
< STATE_TEXT_END (CPU_STATE (cpu
)))
741 const char *pc_filename
= (const char *)0;
742 const char *pc_function
= (const char *)0;
743 unsigned int pc_linenum
= 0;
747 abfd
= STATE_PROG_BFD (CPU_STATE (cpu
));
748 asymbols
= STATE_PROG_SYMS (CPU_STATE (cpu
));
749 if (asymbols
== NULL
)
754 symsize
= bfd_get_symtab_upper_bound (abfd
);
757 sim_engine_abort (sd
, cpu
, cia
, "could not read symbols");
759 asymbols
= (asymbol
**) xmalloc (symsize
);
760 symbol_count
= bfd_canonicalize_symtab (abfd
, asymbols
);
761 if (symbol_count
< 0)
763 sim_engine_abort (sd
, cpu
, cia
, "could not canonicalize symbols");
765 STATE_PROG_SYMS (CPU_STATE (cpu
)) = asymbols
;
768 if (bfd_find_nearest_line (abfd
,
769 STATE_TEXT_SECTION (CPU_STATE (cpu
)),
771 pc
- STATE_TEXT_START (CPU_STATE (cpu
)),
772 &pc_filename
, &pc_function
, &pc_linenum
))
777 sprintf (p
, "#%-*d ", SIZE_LINE_NUMBER
, pc_linenum
);
782 sprintf (p
, "%-*s ", SIZE_LINE_NUMBER
+1, "---");
783 p
+= SIZE_LINE_NUMBER
+2;
788 sprintf (p
, "%s ", pc_function
);
791 else if (pc_filename
)
793 char *q
= (char *) strrchr (pc_filename
, '/');
794 sprintf (p
, "%s ", (q
) ? q
+1 : pc_filename
);
803 sprintf (prefix
, "0x%.*x %-*.*s ",
804 SIZE_PC
, (unsigned) pc
,
805 SIZE_LOCATION
, SIZE_LOCATION
, buf
);
806 chp
= strchr (prefix
, '\0');
808 vsprintf (chp
, fmt
, ap
);
812 /* Pad it out to TRACE_PREFIX_WIDTH. */
813 chp
= strchr (prefix
, '\0');
814 if (chp
- prefix
< width
)
816 memset (chp
, ' ', width
- (chp
- prefix
));
817 chp
= &prefix
[width
];
822 /* check that we've not over flowed the prefix buffer */
823 if (strlen (prefix
) >= sizeof (TRACE_PREFIX (data
)))
828 trace_generic (SIM_DESC sd
,
835 trace_printf (sd
, cpu
, "%s %s",
836 trace_idx_to_str (trace_idx
),
837 TRACE_PREFIX (CPU_TRACE_DATA (cpu
)));
839 trace_vprintf (sd
, cpu
, fmt
, ap
);
841 trace_printf (sd
, cpu
, "\n");
845 trace_input0 (SIM_DESC sd
,
849 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
850 TRACE_IDX (data
) = trace_idx
;
854 trace_input_word1 (SIM_DESC sd
,
859 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
860 TRACE_IDX (data
) = trace_idx
;
861 save_data (sd
, data
, trace_fmt_word
, sizeof (unsigned_word
), &d0
);
865 trace_input_word2 (SIM_DESC sd
,
871 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
872 TRACE_IDX (data
) = trace_idx
;
873 save_data (sd
, data
, trace_fmt_word
, sizeof (unsigned_word
), &d0
);
874 save_data (sd
, data
, trace_fmt_word
, sizeof (unsigned_word
), &d1
);
878 trace_input_word3 (SIM_DESC sd
,
885 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
886 TRACE_IDX (data
) = trace_idx
;
887 save_data (sd
, data
, trace_fmt_word
, sizeof (unsigned_word
), &d0
);
888 save_data (sd
, data
, trace_fmt_word
, sizeof (unsigned_word
), &d1
);
889 save_data (sd
, data
, trace_fmt_word
, sizeof (unsigned_word
), &d2
);
893 trace_input_word4 (SIM_DESC sd
,
901 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
902 TRACE_IDX (data
) = trace_idx
;
903 save_data (sd
, data
, trace_fmt_word
, sizeof (d0
), &d0
);
904 save_data (sd
, data
, trace_fmt_word
, sizeof (d1
), &d1
);
905 save_data (sd
, data
, trace_fmt_word
, sizeof (d2
), &d2
);
906 save_data (sd
, data
, trace_fmt_word
, sizeof (d3
), &d3
);
910 trace_input_bool1 (SIM_DESC sd
,
915 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
916 TRACE_IDX (data
) = trace_idx
;
917 save_data (sd
, data
, trace_fmt_bool
, sizeof (d0
), &d0
);
921 trace_input_addr1 (SIM_DESC sd
,
926 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
927 TRACE_IDX (data
) = trace_idx
;
928 save_data (sd
, data
, trace_fmt_addr
, sizeof (d0
), &d0
);
932 trace_input_fp1 (SIM_DESC sd
,
937 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
938 TRACE_IDX (data
) = trace_idx
;
939 save_data (sd
, data
, trace_fmt_fp
, sizeof (fp_word
), &f0
);
943 trace_input_fp2 (SIM_DESC sd
,
949 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
950 TRACE_IDX (data
) = trace_idx
;
951 save_data (sd
, data
, trace_fmt_fp
, sizeof (fp_word
), &f0
);
952 save_data (sd
, data
, trace_fmt_fp
, sizeof (fp_word
), &f1
);
956 trace_input_fp3 (SIM_DESC sd
,
963 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
964 TRACE_IDX (data
) = trace_idx
;
965 save_data (sd
, data
, trace_fmt_fp
, sizeof (fp_word
), &f0
);
966 save_data (sd
, data
, trace_fmt_fp
, sizeof (fp_word
), &f1
);
967 save_data (sd
, data
, trace_fmt_fp
, sizeof (fp_word
), &f2
);
971 trace_input_fpu1 (SIM_DESC sd
,
977 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
978 TRACE_IDX (data
) = trace_idx
;
980 save_data (sd
, data
, trace_fmt_fp
, sizeof (double), &d
);
984 trace_input_fpu2 (SIM_DESC sd
,
991 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
992 TRACE_IDX (data
) = trace_idx
;
994 save_data (sd
, data
, trace_fmt_fp
, sizeof (double), &d
);
996 save_data (sd
, data
, trace_fmt_fp
, sizeof (double), &d
);
1000 trace_input_fpu3 (SIM_DESC sd
,
1008 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
1009 TRACE_IDX (data
) = trace_idx
;
1010 d
= sim_fpu_2d (f0
);
1011 save_data (sd
, data
, trace_fmt_fp
, sizeof (double), &d
);
1012 d
= sim_fpu_2d (f1
);
1013 save_data (sd
, data
, trace_fmt_fp
, sizeof (double), &d
);
1014 d
= sim_fpu_2d (f2
);
1015 save_data (sd
, data
, trace_fmt_fp
, sizeof (double), &d
);
1019 trace_result_word1 (SIM_DESC sd
,
1024 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
1027 /* Append any results to the end of the inputs */
1028 last_input
= TRACE_INPUT_IDX (data
);
1029 save_data (sd
, data
, trace_fmt_word
, sizeof (unsigned_word
), &r0
);
1031 trace_results (sd
, cpu
, trace_idx
, last_input
);
1035 trace_result0 (SIM_DESC sd
,
1039 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
1042 /* Append any results to the end of the inputs */
1043 last_input
= TRACE_INPUT_IDX (data
);
1045 trace_results (sd
, cpu
, trace_idx
, last_input
);
1049 trace_result_word2 (SIM_DESC sd
,
1055 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
1058 /* Append any results to the end of the inputs */
1059 last_input
= TRACE_INPUT_IDX (data
);
1060 save_data (sd
, data
, trace_fmt_word
, sizeof (r0
), &r0
);
1061 save_data (sd
, data
, trace_fmt_word
, sizeof (r1
), &r1
);
1063 trace_results (sd
, cpu
, trace_idx
, last_input
);
1067 trace_result_word4 (SIM_DESC sd
,
1075 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
1078 /* Append any results to the end of the inputs */
1079 last_input
= TRACE_INPUT_IDX (data
);
1080 save_data (sd
, data
, trace_fmt_word
, sizeof (r0
), &r0
);
1081 save_data (sd
, data
, trace_fmt_word
, sizeof (r1
), &r1
);
1082 save_data (sd
, data
, trace_fmt_word
, sizeof (r2
), &r2
);
1083 save_data (sd
, data
, trace_fmt_word
, sizeof (r3
), &r3
);
1085 trace_results (sd
, cpu
, trace_idx
, last_input
);
1089 trace_result_bool1 (SIM_DESC sd
,
1094 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
1097 /* Append any results to the end of the inputs */
1098 last_input
= TRACE_INPUT_IDX (data
);
1099 save_data (sd
, data
, trace_fmt_bool
, sizeof (r0
), &r0
);
1101 trace_results (sd
, cpu
, trace_idx
, last_input
);
1105 trace_result_addr1 (SIM_DESC sd
,
1110 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
1113 /* Append any results to the end of the inputs */
1114 last_input
= TRACE_INPUT_IDX (data
);
1115 save_data (sd
, data
, trace_fmt_addr
, sizeof (r0
), &r0
);
1117 trace_results (sd
, cpu
, trace_idx
, last_input
);
1121 trace_result_fp1 (SIM_DESC sd
,
1126 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
1129 /* Append any results to the end of the inputs */
1130 last_input
= TRACE_INPUT_IDX (data
);
1131 save_data (sd
, data
, trace_fmt_fp
, sizeof (fp_word
), &f0
);
1133 trace_results (sd
, cpu
, trace_idx
, last_input
);
1137 trace_result_fp2 (SIM_DESC sd
,
1143 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
1146 /* Append any results to the end of the inputs */
1147 last_input
= TRACE_INPUT_IDX (data
);
1148 save_data (sd
, data
, trace_fmt_fp
, sizeof (f0
), &f0
);
1149 save_data (sd
, data
, trace_fmt_fp
, sizeof (f1
), &f1
);
1151 trace_results (sd
, cpu
, trace_idx
, last_input
);
1155 trace_result_fpu1 (SIM_DESC sd
,
1161 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
1164 /* Append any results to the end of the inputs */
1165 last_input
= TRACE_INPUT_IDX (data
);
1166 d
= sim_fpu_2d (f0
);
1167 save_data (sd
, data
, trace_fmt_fp
, sizeof (double), &d
);
1169 trace_results (sd
, cpu
, trace_idx
, last_input
);
1173 trace_result_string1 (SIM_DESC sd
,
1178 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
1181 /* Append any results to the end of the inputs */
1182 last_input
= TRACE_INPUT_IDX (data
);
1183 save_data (sd
, data
, trace_fmt_string
, strlen (s0
) + 1, s0
);
1185 trace_results (sd
, cpu
, trace_idx
, last_input
);
1189 trace_result_word1_string1 (SIM_DESC sd
,
1195 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
1198 /* Append any results to the end of the inputs */
1199 last_input
= TRACE_INPUT_IDX (data
);
1200 save_data (sd
, data
, trace_fmt_word
, sizeof (unsigned_word
), &r0
);
1201 save_data (sd
, data
, trace_fmt_string
, strlen (s0
) + 1, s0
);
1203 trace_results (sd
, cpu
, trace_idx
, last_input
);
1207 trace_vprintf (SIM_DESC sd
, sim_cpu
*cpu
, const char *fmt
, va_list ap
)
1211 if (TRACE_FILE (CPU_TRACE_DATA (cpu
)) != NULL
)
1212 vfprintf (TRACE_FILE (CPU_TRACE_DATA (cpu
)), fmt
, ap
);
1214 sim_io_evprintf (sd
, fmt
, ap
);
1218 if (TRACE_FILE (STATE_TRACE_DATA (sd
)) != NULL
)
1219 vfprintf (TRACE_FILE (STATE_TRACE_DATA (sd
)), fmt
, ap
);
1221 sim_io_evprintf (sd
, fmt
, ap
);
1225 /* The function trace_one_insn has been replaced by the function pair
1226 trace_prefix() + trace_generic(). It is still used. */
1228 trace_one_insn (SIM_DESC sd
, sim_cpu
*cpu
, address_word pc
,
1229 int line_p
, const char *filename
, int linenum
,
1230 const char *phase_wo_colon
, const char *fmt
,
1234 char phase
[SIZE_PHASE
+2];
1236 strncpy (phase
, phase_wo_colon
, SIZE_PHASE
);
1237 strcat (phase
, ":");
1241 trace_printf (sd
, cpu
, "%-*s %s:%-*d 0x%.*lx ",
1242 SIZE_PHASE
+1, phase
,
1244 SIZE_LINE_NUMBER
, linenum
,
1247 trace_vprintf (sd
, cpu
, fmt
, ap
);
1249 trace_printf (sd
, cpu
, "\n");
1256 if (STATE_TEXT_SECTION (CPU_STATE (cpu
))
1257 && pc
>= STATE_TEXT_START (CPU_STATE (cpu
))
1258 && pc
< STATE_TEXT_END (CPU_STATE (cpu
)))
1260 const char *pc_filename
= (const char *)0;
1261 const char *pc_function
= (const char *)0;
1262 unsigned int pc_linenum
= 0;
1264 if (bfd_find_nearest_line (STATE_PROG_BFD (CPU_STATE (cpu
)),
1265 STATE_TEXT_SECTION (CPU_STATE (cpu
)),
1266 (struct bfd_symbol
**) 0,
1267 pc
- STATE_TEXT_START (CPU_STATE (cpu
)),
1268 &pc_filename
, &pc_function
, &pc_linenum
))
1273 sprintf (p
, "#%-*d ", SIZE_LINE_NUMBER
, pc_linenum
);
1278 sprintf (p
, "%-*s ", SIZE_LINE_NUMBER
+1, "---");
1279 p
+= SIZE_LINE_NUMBER
+2;
1284 sprintf (p
, "%s ", pc_function
);
1287 else if (pc_filename
)
1289 char *q
= (char *) strrchr (pc_filename
, '/');
1290 sprintf (p
, "%s ", (q
) ? q
+1 : pc_filename
);
1299 trace_printf (sd
, cpu
, "%-*s 0x%.*x %-*.*s ",
1300 SIZE_PHASE
+1, phase
,
1301 SIZE_PC
, (unsigned) pc
,
1302 SIZE_LOCATION
, SIZE_LOCATION
, buf
);
1304 trace_vprintf (sd
, cpu
, fmt
, ap
);
1306 trace_printf (sd
, cpu
, "\n");
1311 trace_printf
VPARAMS ((SIM_DESC sd
, sim_cpu
*cpu
, const char *fmt
, ...))
1313 #if !defined __STDC__ && !defined ALMOST_STDC
1321 #if !defined __STDC__ && !defined ALMOST_STDC
1322 sd
= va_arg (ap
, SIM_DESC
);
1323 cpu
= va_arg (ap
, sim_cpu
*);
1324 fmt
= va_arg (ap
, const char *);
1327 trace_vprintf (sd
, cpu
, fmt
, ap
);
1333 debug_printf
VPARAMS ((sim_cpu
*cpu
, const char *fmt
, ...))
1335 #if !defined __STDC__ && !defined ALMOST_STDC
1342 #if !defined __STDC__ && !defined ALMOST_STDC
1343 cpu
= va_arg (ap
, sim_cpu
*);
1344 fmt
= va_arg (ap
, const char *);
1347 if (CPU_DEBUG_FILE (cpu
) == NULL
)
1348 (* STATE_CALLBACK (CPU_STATE (cpu
))->evprintf_filtered
)
1349 (STATE_CALLBACK (CPU_STATE (cpu
)), fmt
, ap
);
1351 vfprintf (CPU_DEBUG_FILE (cpu
), fmt
, ap
);