1 /* Simulator tracing/debugging support.
2 Copyright (C) 1997-2015 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. */
183 STATE_TRACE_FLAGS (sd
)[trace_nr
] = trace_val
;
185 /* Set cpu values. */
186 for (cpu_nr
= 0; cpu_nr
< MAX_NR_PROCESSORS
; cpu_nr
++)
188 CPU_TRACE_FLAGS (STATE_CPU (sd
, cpu_nr
))[trace_nr
] = trace_val
;
192 /* Re-compute the cpu trace summary. */
195 for (cpu_nr
= 0; cpu_nr
< MAX_NR_PROCESSORS
; cpu_nr
++)
196 CPU_TRACE_DATA (STATE_CPU (sd
, cpu_nr
))->trace_any_p
= 1;
200 for (cpu_nr
= 0; cpu_nr
< MAX_NR_PROCESSORS
; cpu_nr
++)
202 CPU_TRACE_DATA (STATE_CPU (sd
, cpu_nr
))->trace_any_p
= 0;
203 for (trace_nr
= 0; trace_nr
< MAX_TRACE_VALUES
; ++trace_nr
)
205 if (CPU_TRACE_FLAGS (STATE_CPU (sd
, cpu_nr
))[trace_nr
])
207 CPU_TRACE_DATA (STATE_CPU (sd
, cpu_nr
))->trace_any_p
= 1;
217 /* Set one trace option based on its IDX value. */
220 set_trace_option (SIM_DESC sd
, const char *name
, int idx
, const char *arg
)
222 return set_trace_option_mask (sd
, name
, 1 << idx
, arg
);
227 trace_option_handler (SIM_DESC sd
, sim_cpu
*cpu
, int opt
,
228 char *arg
, int is_command
)
235 if (!WITH_TRACE_ANY_P
)
236 sim_io_eprintf (sd
, "Tracing not compiled in, `-t' ignored\n");
238 return set_trace_option_mask (sd
, "trace", TRACE_USEFUL_MASK
, arg
);
241 case OPTION_TRACE_INSN
:
242 if (WITH_TRACE_INSN_P
)
243 return set_trace_option (sd
, "-insn", TRACE_INSN_IDX
, arg
);
245 sim_io_eprintf (sd
, "Instruction tracing not compiled in, `--trace-insn' ignored\n");
248 case OPTION_TRACE_DECODE
:
249 if (WITH_TRACE_DECODE_P
)
250 return set_trace_option (sd
, "-decode", TRACE_DECODE_IDX
, arg
);
252 sim_io_eprintf (sd
, "Decode tracing not compiled in, `--trace-decode' ignored\n");
255 case OPTION_TRACE_EXTRACT
:
256 if (WITH_TRACE_EXTRACT_P
)
257 return set_trace_option (sd
, "-extract", TRACE_EXTRACT_IDX
, arg
);
259 sim_io_eprintf (sd
, "Extract tracing not compiled in, `--trace-extract' ignored\n");
262 case OPTION_TRACE_LINENUM
:
263 if (WITH_TRACE_LINENUM_P
&& WITH_TRACE_INSN_P
)
265 if (set_trace_option (sd
, "-linenum", TRACE_LINENUM_IDX
, arg
) != SIM_RC_OK
266 || set_trace_option (sd
, "-linenum", TRACE_INSN_IDX
, arg
) != SIM_RC_OK
)
270 sim_io_eprintf (sd
, "Line number or instruction tracing not compiled in, `--trace-linenum' ignored\n");
273 case OPTION_TRACE_MEMORY
:
274 if (WITH_TRACE_MEMORY_P
)
275 return set_trace_option (sd
, "-memory", TRACE_MEMORY_IDX
, arg
);
277 sim_io_eprintf (sd
, "Memory tracing not compiled in, `--trace-memory' ignored\n");
280 case OPTION_TRACE_MODEL
:
281 if (WITH_TRACE_MODEL_P
)
282 return set_trace_option (sd
, "-model", TRACE_MODEL_IDX
, arg
);
284 sim_io_eprintf (sd
, "Model tracing not compiled in, `--trace-model' ignored\n");
287 case OPTION_TRACE_ALU
:
288 if (WITH_TRACE_ALU_P
)
289 return set_trace_option (sd
, "-alu", TRACE_ALU_IDX
, arg
);
291 sim_io_eprintf (sd
, "ALU tracing not compiled in, `--trace-alu' ignored\n");
294 case OPTION_TRACE_CORE
:
295 if (WITH_TRACE_CORE_P
)
296 return set_trace_option (sd
, "-core", TRACE_CORE_IDX
, arg
);
298 sim_io_eprintf (sd
, "CORE tracing not compiled in, `--trace-core' ignored\n");
301 case OPTION_TRACE_EVENTS
:
302 if (WITH_TRACE_EVENTS_P
)
303 return set_trace_option (sd
, "-events", TRACE_EVENTS_IDX
, arg
);
305 sim_io_eprintf (sd
, "EVENTS tracing not compiled in, `--trace-events' ignored\n");
308 case OPTION_TRACE_FPU
:
309 if (WITH_TRACE_FPU_P
)
310 return set_trace_option (sd
, "-fpu", TRACE_FPU_IDX
, arg
);
312 sim_io_eprintf (sd
, "FPU tracing not compiled in, `--trace-fpu' ignored\n");
315 case OPTION_TRACE_VPU
:
316 if (WITH_TRACE_VPU_P
)
317 return set_trace_option (sd
, "-vpu", TRACE_VPU_IDX
, arg
);
319 sim_io_eprintf (sd
, "VPU tracing not compiled in, `--trace-vpu' ignored\n");
322 case OPTION_TRACE_BRANCH
:
323 if (WITH_TRACE_BRANCH_P
)
324 return set_trace_option (sd
, "-branch", TRACE_BRANCH_IDX
, arg
);
326 sim_io_eprintf (sd
, "Branch tracing not compiled in, `--trace-branch' ignored\n");
329 case OPTION_TRACE_SYSCALL
:
330 if (WITH_TRACE_SYSCALL_P
)
331 return set_trace_option (sd
, "-syscall", TRACE_SYSCALL_IDX
, arg
);
333 sim_io_eprintf (sd
, "System call tracing not compiled in, `--trace-syscall' ignored\n");
336 case OPTION_TRACE_SEMANTICS
:
339 && WITH_TRACE_MEMORY_P
340 && WITH_TRACE_BRANCH_P
)
342 if (set_trace_option (sd
, "-semantics", TRACE_ALU_IDX
, arg
) != SIM_RC_OK
343 || set_trace_option (sd
, "-semantics", TRACE_FPU_IDX
, arg
) != SIM_RC_OK
344 || set_trace_option (sd
, "-semantics", TRACE_VPU_IDX
, arg
) != SIM_RC_OK
345 || set_trace_option (sd
, "-semantics", TRACE_MEMORY_IDX
, arg
) != SIM_RC_OK
346 || set_trace_option (sd
, "-semantics", TRACE_BRANCH_IDX
, arg
) != SIM_RC_OK
)
350 sim_io_eprintf (sd
, "Alu, fpu, memory, and/or branch tracing not compiled in, `--trace-semantics' ignored\n");
353 #ifdef SIM_HAVE_ADDR_RANGE
354 case OPTION_TRACE_RANGE
:
355 if (WITH_TRACE_ANY_P
)
359 unsigned long start
,end
;
360 start
= strtoul (chp
, &chp
, 0);
363 sim_io_eprintf (sd
, "--trace-range missing END argument\n");
366 end
= strtoul (chp
+ 1, NULL
, 0);
367 /* FIXME: Argument validation. */
369 sim_addr_range_add (TRACE_RANGE (CPU_PROFILE_DATA (cpu
)),
372 for (cpu_nr
= 0; cpu_nr
< MAX_NR_PROCESSORS
; ++cpu_nr
)
373 sim_addr_range_add (TRACE_RANGE (CPU_TRACE_DATA (STATE_CPU (sd
, cpu_nr
))),
377 sim_io_eprintf (sd
, "Tracing not compiled in, `--trace-range' ignored\n");
380 case OPTION_TRACE_FUNCTION
:
381 if (WITH_TRACE_ANY_P
)
383 /*wip: need to compute function range given name*/
386 sim_io_eprintf (sd
, "Tracing not compiled in, `--trace-function' ignored\n");
388 #endif /* SIM_HAVE_ADDR_RANGE */
390 case OPTION_TRACE_DEBUG
:
391 if (WITH_TRACE_DEBUG_P
)
392 return set_trace_option (sd
, "-debug", TRACE_DEBUG_IDX
, arg
);
394 sim_io_eprintf (sd
, "Tracing debug support not compiled in, `--trace-debug' ignored\n");
397 case OPTION_TRACE_FILE
:
398 if (!WITH_TRACE_ANY_P
)
399 sim_io_eprintf (sd
, "Tracing not compiled in, `--trace-file' ignored\n");
402 FILE *f
= fopen (arg
, "w");
406 sim_io_eprintf (sd
, "Unable to open trace output file `%s'\n", arg
);
409 for (n
= 0; n
< MAX_NR_PROCESSORS
; ++n
)
410 TRACE_FILE (CPU_TRACE_DATA (STATE_CPU (sd
, n
))) = f
;
411 TRACE_FILE (STATE_TRACE_DATA (sd
)) = f
;
419 /* Install tracing support. */
422 trace_install (SIM_DESC sd
)
426 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
428 sim_add_option_table (sd
, NULL
, trace_options
);
429 memset (STATE_TRACE_DATA (sd
), 0, sizeof (* STATE_TRACE_DATA (sd
)));
430 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
431 memset (CPU_TRACE_DATA (STATE_CPU (sd
, i
)), 0,
432 sizeof (* CPU_TRACE_DATA (STATE_CPU (sd
, i
))));
433 sim_module_add_init_fn (sd
, trace_init
);
434 sim_module_add_uninstall_fn (sd
, trace_uninstall
);
439 trace_init (SIM_DESC sd
)
441 #ifdef SIM_HAVE_ADDR_RANGE
442 /* Check if a range has been specified without specifying what to
447 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
449 sim_cpu
*cpu
= STATE_CPU (sd
, i
);
451 if (ADDR_RANGE_RANGES (TRACE_RANGE (CPU_TRACE_DATA (cpu
)))
452 && ! TRACE_INSN_P (cpu
))
454 sim_io_eprintf_cpu (cpu
, "Tracing address range specified without --trace-insn.\n");
455 sim_io_eprintf_cpu (cpu
, "Address range ignored.\n");
456 sim_addr_range_delete (TRACE_RANGE (CPU_TRACE_DATA (cpu
)),
457 0, ~ (address_word
) 0);
467 trace_uninstall (SIM_DESC sd
)
470 FILE *sfile
= TRACE_FILE (STATE_TRACE_DATA (sd
));
475 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
477 FILE *cfile
= TRACE_FILE (CPU_TRACE_DATA (STATE_CPU (sd
, i
)));
478 if (cfile
!= NULL
&& cfile
!= sfile
)
480 /* If output from different cpus is going to the same file,
481 avoid closing the file twice. */
482 for (j
= 0; j
< i
; ++j
)
483 if (TRACE_FILE (CPU_TRACE_DATA (STATE_CPU (sd
, j
))) == cfile
)
491 /* compute the nr of trace data units consumed by data */
493 save_data_size (TRACE_DATA
*data
,
496 return ((size
+ sizeof (TRACE_INPUT_DATA (data
) [0]) - 1)
497 / sizeof (TRACE_INPUT_DATA (data
) [0]));
501 /* Archive DATA into the trace buffer */
503 save_data (SIM_DESC sd
,
509 int i
= TRACE_INPUT_IDX (data
);
510 if (i
== sizeof (TRACE_INPUT_FMT (data
)))
511 sim_io_error (sd
, "trace buffer overflow");
512 TRACE_INPUT_FMT (data
) [i
] = fmt
;
513 TRACE_INPUT_SIZE (data
) [i
] = size
;
514 memcpy (&TRACE_INPUT_DATA (data
) [i
], buf
, size
);
515 i
+= save_data_size (data
, size
);
516 TRACE_INPUT_IDX (data
) = i
;
520 print_data (SIM_DESC sd
,
528 case trace_fmt_instruction_incomplete
:
529 trace_printf (sd
, cpu
, " (instruction incomplete)");
536 case sizeof (unsigned32
):
537 trace_printf (sd
, cpu
, " 0x%08lx", (long) * (unsigned32
*) data
);
539 case sizeof (unsigned64
):
540 trace_printf (sd
, cpu
, " 0x%08lx%08lx",
541 (long) ((* (unsigned64
*) data
) >> 32),
542 (long) * (unsigned64
*) data
);
551 SIM_ASSERT (size
== sizeof (int));
552 trace_printf (sd
, cpu
, " %-8s",
553 (* (int*) data
) ? "true" : "false");
561 /* FIXME: Assumes sizeof float == 4; sizeof double == 8 */
563 sim_fpu_32to (&fp
, *(unsigned32
*)data
);
566 sim_fpu_64to (&fp
, *(unsigned64
*)data
);
571 trace_printf (sd
, cpu
, " %8g", sim_fpu_2d (&fp
));
575 trace_printf (sd
, cpu
, " (0x%08lx)",
576 (long) *(unsigned32
*)data
);
579 trace_printf (sd
, cpu
, " (0x%08lx%08lx)",
580 (long) (*(unsigned64
*)data
>> 32),
581 (long) (*(unsigned64
*)data
));
589 /* FIXME: At present sim_fpu data is stored as a double */
590 trace_printf (sd
, cpu
, " %8g", * (double*) data
);
592 case trace_fmt_string
:
593 trace_printf (sd
, cpu
, " %-8s", (char*) data
);
601 trace_idx_to_str (int trace_idx
)
606 case TRACE_ALU_IDX
: return "alu: ";
607 case TRACE_INSN_IDX
: return "insn: ";
608 case TRACE_DECODE_IDX
: return "decode: ";
609 case TRACE_EXTRACT_IDX
: return "extract: ";
610 case TRACE_MEMORY_IDX
: return "memory: ";
611 case TRACE_CORE_IDX
: return "core: ";
612 case TRACE_EVENTS_IDX
: return "events: ";
613 case TRACE_FPU_IDX
: return "fpu: ";
614 case TRACE_BRANCH_IDX
: return "branch: ";
615 case TRACE_SYSCALL_IDX
: return "syscall: ";
616 case TRACE_VPU_IDX
: return "vpu: ";
618 sprintf (num
, "?%d?", trace_idx
);
624 trace_results (SIM_DESC sd
,
629 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
633 /* cross check trace_idx against TRACE_IDX (data)? */
636 trace_printf (sd
, cpu
, "%s %s",
637 trace_idx_to_str (TRACE_IDX (data
)),
638 TRACE_PREFIX (data
));
639 TRACE_IDX (data
) = 0;
641 for (i
= 0, nr_out
= 0;
642 i
< TRACE_INPUT_IDX (data
);
643 i
+= save_data_size (data
, TRACE_INPUT_SIZE (data
) [i
]), nr_out
++)
647 int pad
= (strlen (" 0x") + sizeof (unsigned_word
) * 2);
648 int padding
= pad
* (3 - nr_out
);
651 padding
+= strlen (" ::");
652 trace_printf (sd
, cpu
, "%*s", padding
, " ::");
655 TRACE_INPUT_FMT (data
) [i
],
656 TRACE_INPUT_SIZE (data
) [i
],
657 &TRACE_INPUT_DATA (data
) [i
]);
659 trace_printf (sd
, cpu
, "\n");
663 trace_prefix (SIM_DESC sd
,
668 const char *filename
,
673 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
675 char *prefix
= TRACE_PREFIX (data
);
677 /* FIXME: The TRACE_PREFIX_WIDTH should be determined at build time using
678 known information about the disassembled instructions. */
679 #ifndef TRACE_PREFIX_WIDTH
680 #define TRACE_PREFIX_WIDTH 48
682 int width
= TRACE_PREFIX_WIDTH
;
684 /* if the previous trace data wasn't flushed, flush it now with a
685 note indicating that the trace was incomplete. */
686 if (TRACE_IDX (data
) != 0)
688 int last_input
= TRACE_INPUT_IDX (data
);
689 save_data (sd
, data
, trace_fmt_instruction_incomplete
, 1, "");
690 trace_results (sd
, cpu
, TRACE_IDX (data
), last_input
);
692 TRACE_IDX (data
) = 0;
693 TRACE_INPUT_IDX (data
) = 0;
695 /* Create the text prefix for this new instruction: */
700 sprintf (prefix
, "%s:%-*d 0x%.*lx ",
702 SIZE_LINE_NUMBER
, linenum
,
707 sprintf (prefix
, "0x%.*lx ",
709 /* Shrink the width by the amount that we didn't print. */
710 width
-= SIZE_LINE_NUMBER
+ SIZE_PC
+ 8;
712 chp
= strchr (prefix
, '\0');
714 vsprintf (chp
, fmt
, ap
);
721 if (STATE_TEXT_SECTION (CPU_STATE (cpu
))
722 && pc
>= STATE_TEXT_START (CPU_STATE (cpu
))
723 && pc
< STATE_TEXT_END (CPU_STATE (cpu
)))
725 const char *pc_filename
= (const char *)0;
726 const char *pc_function
= (const char *)0;
727 unsigned int pc_linenum
= 0;
731 abfd
= STATE_PROG_BFD (CPU_STATE (cpu
));
732 asymbols
= STATE_PROG_SYMS (CPU_STATE (cpu
));
733 if (asymbols
== NULL
)
738 symsize
= bfd_get_symtab_upper_bound (abfd
);
741 sim_engine_abort (sd
, cpu
, cia
, "could not read symbols");
743 asymbols
= (asymbol
**) xmalloc (symsize
);
744 symbol_count
= bfd_canonicalize_symtab (abfd
, asymbols
);
745 if (symbol_count
< 0)
747 sim_engine_abort (sd
, cpu
, cia
, "could not canonicalize symbols");
749 STATE_PROG_SYMS (CPU_STATE (cpu
)) = asymbols
;
752 if (bfd_find_nearest_line (abfd
,
753 STATE_TEXT_SECTION (CPU_STATE (cpu
)),
755 pc
- STATE_TEXT_START (CPU_STATE (cpu
)),
756 &pc_filename
, &pc_function
, &pc_linenum
))
761 sprintf (p
, "#%-*d ", SIZE_LINE_NUMBER
, pc_linenum
);
766 sprintf (p
, "%-*s ", SIZE_LINE_NUMBER
+1, "---");
767 p
+= SIZE_LINE_NUMBER
+2;
772 sprintf (p
, "%s ", pc_function
);
775 else if (pc_filename
)
777 char *q
= (char *) strrchr (pc_filename
, '/');
778 sprintf (p
, "%s ", (q
) ? q
+1 : pc_filename
);
787 sprintf (prefix
, "0x%.*x %-*.*s ",
788 SIZE_PC
, (unsigned) pc
,
789 SIZE_LOCATION
, SIZE_LOCATION
, buf
);
790 chp
= strchr (prefix
, '\0');
792 vsprintf (chp
, fmt
, ap
);
796 /* Pad it out to TRACE_PREFIX_WIDTH. */
797 chp
= strchr (prefix
, '\0');
798 if (chp
- prefix
< width
)
800 memset (chp
, ' ', width
- (chp
- prefix
));
801 chp
= &prefix
[width
];
806 /* check that we've not over flowed the prefix buffer */
807 if (strlen (prefix
) >= sizeof (TRACE_PREFIX (data
)))
812 trace_generic (SIM_DESC sd
,
819 trace_printf (sd
, cpu
, "%s %s",
820 trace_idx_to_str (trace_idx
),
821 TRACE_PREFIX (CPU_TRACE_DATA (cpu
)));
823 trace_vprintf (sd
, cpu
, fmt
, ap
);
825 trace_printf (sd
, cpu
, "\n");
829 trace_input0 (SIM_DESC sd
,
833 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
834 TRACE_IDX (data
) = trace_idx
;
838 trace_input_word1 (SIM_DESC sd
,
843 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
844 TRACE_IDX (data
) = trace_idx
;
845 save_data (sd
, data
, trace_fmt_word
, sizeof (unsigned_word
), &d0
);
849 trace_input_word2 (SIM_DESC sd
,
855 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
856 TRACE_IDX (data
) = trace_idx
;
857 save_data (sd
, data
, trace_fmt_word
, sizeof (unsigned_word
), &d0
);
858 save_data (sd
, data
, trace_fmt_word
, sizeof (unsigned_word
), &d1
);
862 trace_input_word3 (SIM_DESC sd
,
869 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
870 TRACE_IDX (data
) = trace_idx
;
871 save_data (sd
, data
, trace_fmt_word
, sizeof (unsigned_word
), &d0
);
872 save_data (sd
, data
, trace_fmt_word
, sizeof (unsigned_word
), &d1
);
873 save_data (sd
, data
, trace_fmt_word
, sizeof (unsigned_word
), &d2
);
877 trace_input_word4 (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 (d0
), &d0
);
888 save_data (sd
, data
, trace_fmt_word
, sizeof (d1
), &d1
);
889 save_data (sd
, data
, trace_fmt_word
, sizeof (d2
), &d2
);
890 save_data (sd
, data
, trace_fmt_word
, sizeof (d3
), &d3
);
894 trace_input_bool1 (SIM_DESC sd
,
899 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
900 TRACE_IDX (data
) = trace_idx
;
901 save_data (sd
, data
, trace_fmt_bool
, sizeof (d0
), &d0
);
905 trace_input_addr1 (SIM_DESC sd
,
910 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
911 TRACE_IDX (data
) = trace_idx
;
912 save_data (sd
, data
, trace_fmt_addr
, sizeof (d0
), &d0
);
916 trace_input_fp1 (SIM_DESC sd
,
921 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
922 TRACE_IDX (data
) = trace_idx
;
923 save_data (sd
, data
, trace_fmt_fp
, sizeof (fp_word
), &f0
);
927 trace_input_fp2 (SIM_DESC sd
,
933 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
934 TRACE_IDX (data
) = trace_idx
;
935 save_data (sd
, data
, trace_fmt_fp
, sizeof (fp_word
), &f0
);
936 save_data (sd
, data
, trace_fmt_fp
, sizeof (fp_word
), &f1
);
940 trace_input_fp3 (SIM_DESC sd
,
947 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
948 TRACE_IDX (data
) = trace_idx
;
949 save_data (sd
, data
, trace_fmt_fp
, sizeof (fp_word
), &f0
);
950 save_data (sd
, data
, trace_fmt_fp
, sizeof (fp_word
), &f1
);
951 save_data (sd
, data
, trace_fmt_fp
, sizeof (fp_word
), &f2
);
955 trace_input_fpu1 (SIM_DESC sd
,
961 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
962 TRACE_IDX (data
) = trace_idx
;
964 save_data (sd
, data
, trace_fmt_fp
, sizeof (double), &d
);
968 trace_input_fpu2 (SIM_DESC sd
,
975 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
976 TRACE_IDX (data
) = trace_idx
;
978 save_data (sd
, data
, trace_fmt_fp
, sizeof (double), &d
);
980 save_data (sd
, data
, trace_fmt_fp
, sizeof (double), &d
);
984 trace_input_fpu3 (SIM_DESC sd
,
992 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
993 TRACE_IDX (data
) = trace_idx
;
995 save_data (sd
, data
, trace_fmt_fp
, sizeof (double), &d
);
997 save_data (sd
, data
, trace_fmt_fp
, sizeof (double), &d
);
999 save_data (sd
, data
, trace_fmt_fp
, sizeof (double), &d
);
1003 trace_result_word1 (SIM_DESC sd
,
1008 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
1011 /* Append any results to the end of the inputs */
1012 last_input
= TRACE_INPUT_IDX (data
);
1013 save_data (sd
, data
, trace_fmt_word
, sizeof (unsigned_word
), &r0
);
1015 trace_results (sd
, cpu
, trace_idx
, last_input
);
1019 trace_result0 (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
);
1029 trace_results (sd
, cpu
, trace_idx
, last_input
);
1033 trace_result_word2 (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
);
1044 save_data (sd
, data
, trace_fmt_word
, sizeof (r0
), &r0
);
1045 save_data (sd
, data
, trace_fmt_word
, sizeof (r1
), &r1
);
1047 trace_results (sd
, cpu
, trace_idx
, last_input
);
1051 trace_result_word4 (SIM_DESC sd
,
1059 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
1062 /* Append any results to the end of the inputs */
1063 last_input
= TRACE_INPUT_IDX (data
);
1064 save_data (sd
, data
, trace_fmt_word
, sizeof (r0
), &r0
);
1065 save_data (sd
, data
, trace_fmt_word
, sizeof (r1
), &r1
);
1066 save_data (sd
, data
, trace_fmt_word
, sizeof (r2
), &r2
);
1067 save_data (sd
, data
, trace_fmt_word
, sizeof (r3
), &r3
);
1069 trace_results (sd
, cpu
, trace_idx
, last_input
);
1073 trace_result_bool1 (SIM_DESC sd
,
1078 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
1081 /* Append any results to the end of the inputs */
1082 last_input
= TRACE_INPUT_IDX (data
);
1083 save_data (sd
, data
, trace_fmt_bool
, sizeof (r0
), &r0
);
1085 trace_results (sd
, cpu
, trace_idx
, last_input
);
1089 trace_result_addr1 (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_addr
, sizeof (r0
), &r0
);
1101 trace_results (sd
, cpu
, trace_idx
, last_input
);
1105 trace_result_fp1 (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_fp
, sizeof (fp_word
), &f0
);
1117 trace_results (sd
, cpu
, trace_idx
, last_input
);
1121 trace_result_fp2 (SIM_DESC sd
,
1127 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
1130 /* Append any results to the end of the inputs */
1131 last_input
= TRACE_INPUT_IDX (data
);
1132 save_data (sd
, data
, trace_fmt_fp
, sizeof (f0
), &f0
);
1133 save_data (sd
, data
, trace_fmt_fp
, sizeof (f1
), &f1
);
1135 trace_results (sd
, cpu
, trace_idx
, last_input
);
1139 trace_result_fpu1 (SIM_DESC sd
,
1145 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
1148 /* Append any results to the end of the inputs */
1149 last_input
= TRACE_INPUT_IDX (data
);
1150 d
= sim_fpu_2d (f0
);
1151 save_data (sd
, data
, trace_fmt_fp
, sizeof (double), &d
);
1153 trace_results (sd
, cpu
, trace_idx
, last_input
);
1157 trace_result_string1 (SIM_DESC sd
,
1162 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
1165 /* Append any results to the end of the inputs */
1166 last_input
= TRACE_INPUT_IDX (data
);
1167 save_data (sd
, data
, trace_fmt_string
, strlen (s0
) + 1, s0
);
1169 trace_results (sd
, cpu
, trace_idx
, last_input
);
1173 trace_result_word1_string1 (SIM_DESC sd
,
1179 TRACE_DATA
*data
= CPU_TRACE_DATA (cpu
);
1182 /* Append any results to the end of the inputs */
1183 last_input
= TRACE_INPUT_IDX (data
);
1184 save_data (sd
, data
, trace_fmt_word
, sizeof (unsigned_word
), &r0
);
1185 save_data (sd
, data
, trace_fmt_string
, strlen (s0
) + 1, s0
);
1187 trace_results (sd
, cpu
, trace_idx
, last_input
);
1191 trace_vprintf (SIM_DESC sd
, sim_cpu
*cpu
, const char *fmt
, va_list ap
)
1195 if (TRACE_FILE (CPU_TRACE_DATA (cpu
)) != NULL
)
1196 vfprintf (TRACE_FILE (CPU_TRACE_DATA (cpu
)), fmt
, ap
);
1198 sim_io_evprintf (sd
, fmt
, ap
);
1202 if (TRACE_FILE (STATE_TRACE_DATA (sd
)) != NULL
)
1203 vfprintf (TRACE_FILE (STATE_TRACE_DATA (sd
)), fmt
, ap
);
1205 sim_io_evprintf (sd
, fmt
, ap
);
1209 /* The function trace_one_insn has been replaced by the function pair
1210 trace_prefix() + trace_generic(). It is still used. */
1212 trace_one_insn (SIM_DESC sd
, sim_cpu
*cpu
, address_word pc
,
1213 int line_p
, const char *filename
, int linenum
,
1214 const char *phase_wo_colon
, const char *fmt
,
1218 char phase
[SIZE_PHASE
+2];
1220 strncpy (phase
, phase_wo_colon
, SIZE_PHASE
);
1221 strcat (phase
, ":");
1225 trace_printf (sd
, cpu
, "%-*s %s:%-*d 0x%.*lx ",
1226 SIZE_PHASE
+1, phase
,
1228 SIZE_LINE_NUMBER
, linenum
,
1231 trace_vprintf (sd
, cpu
, fmt
, ap
);
1233 trace_printf (sd
, cpu
, "\n");
1240 if (STATE_TEXT_SECTION (CPU_STATE (cpu
))
1241 && pc
>= STATE_TEXT_START (CPU_STATE (cpu
))
1242 && pc
< STATE_TEXT_END (CPU_STATE (cpu
)))
1244 const char *pc_filename
= (const char *)0;
1245 const char *pc_function
= (const char *)0;
1246 unsigned int pc_linenum
= 0;
1248 if (bfd_find_nearest_line (STATE_PROG_BFD (CPU_STATE (cpu
)),
1249 STATE_TEXT_SECTION (CPU_STATE (cpu
)),
1250 (struct bfd_symbol
**) 0,
1251 pc
- STATE_TEXT_START (CPU_STATE (cpu
)),
1252 &pc_filename
, &pc_function
, &pc_linenum
))
1257 sprintf (p
, "#%-*d ", SIZE_LINE_NUMBER
, pc_linenum
);
1262 sprintf (p
, "%-*s ", SIZE_LINE_NUMBER
+1, "---");
1263 p
+= SIZE_LINE_NUMBER
+2;
1268 sprintf (p
, "%s ", pc_function
);
1271 else if (pc_filename
)
1273 char *q
= (char *) strrchr (pc_filename
, '/');
1274 sprintf (p
, "%s ", (q
) ? q
+1 : pc_filename
);
1283 trace_printf (sd
, cpu
, "%-*s 0x%.*x %-*.*s ",
1284 SIZE_PHASE
+1, phase
,
1285 SIZE_PC
, (unsigned) pc
,
1286 SIZE_LOCATION
, SIZE_LOCATION
, buf
);
1288 trace_vprintf (sd
, cpu
, fmt
, ap
);
1290 trace_printf (sd
, cpu
, "\n");
1295 trace_printf (SIM_DESC sd
, sim_cpu
*cpu
, const char *fmt
, ...)
1297 #if !defined __STDC__ && !defined ALMOST_STDC
1305 #if !defined __STDC__ && !defined ALMOST_STDC
1306 sd
= va_arg (ap
, SIM_DESC
);
1307 cpu
= va_arg (ap
, sim_cpu
*);
1308 fmt
= va_arg (ap
, const char *);
1311 trace_vprintf (sd
, cpu
, fmt
, ap
);
1317 debug_printf (sim_cpu
*cpu
, const char *fmt
, ...)
1319 #if !defined __STDC__ && !defined ALMOST_STDC
1326 #if !defined __STDC__ && !defined ALMOST_STDC
1327 cpu
= va_arg (ap
, sim_cpu
*);
1328 fmt
= va_arg (ap
, const char *);
1331 if (CPU_DEBUG_FILE (cpu
) == NULL
)
1332 (* STATE_CALLBACK (CPU_STATE (cpu
))->evprintf_filtered
)
1333 (STATE_CALLBACK (CPU_STATE (cpu
)), fmt
, ap
);
1335 vfprintf (CPU_DEBUG_FILE (cpu
), fmt
, ap
);