1 /* Simulator tracing/debugging support.
2 Copyright (C) 1997-2018 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"
30 #include "sim-assert.h"
48 #define SIZE_LOCATION 20
55 #ifndef SIZE_LINE_NUMBER
56 #define SIZE_LINE_NUMBER 4
59 static MODULE_INIT_FN trace_init;
60 static MODULE_UNINSTALL_FN trace_uninstall;
62 static DECLARE_OPTION_HANDLER (trace_option_handler);
65 OPTION_TRACE_INSN = OPTION_START,
77 OPTION_TRACE_SEMANTICS,
79 OPTION_TRACE_FUNCTION,
87 static const OPTION trace_options[] =
89 /* This table is organized to group related instructions together. */
90 { {"trace", optional_argument, NULL, 't'},
91 't', "on|off", "Trace useful things",
92 trace_option_handler, NULL },
93 { {"trace-insn", optional_argument, NULL, OPTION_TRACE_INSN},
94 '\0', "on|off", "Perform instruction tracing",
95 trace_option_handler, NULL },
96 { {"trace-disasm", optional_argument, NULL, OPTION_TRACE_DISASM},
97 '\0', "on|off", "Disassemble instructions (slower, but more accurate)",
98 trace_option_handler, NULL },
99 { {"trace-decode", optional_argument, NULL, OPTION_TRACE_DECODE},
100 '\0', "on|off", "Trace instruction decoding",
101 trace_option_handler, NULL },
102 { {"trace-extract", optional_argument, NULL, OPTION_TRACE_EXTRACT},
103 '\0', "on|off", "Trace instruction extraction",
104 trace_option_handler, NULL },
105 { {"trace-linenum", optional_argument, NULL, OPTION_TRACE_LINENUM},
106 '\0', "on|off", "Perform line number tracing (implies --trace-insn)",
107 trace_option_handler, NULL },
108 { {"trace-memory", optional_argument, NULL, OPTION_TRACE_MEMORY},
109 '\0', "on|off", "Trace memory operations",
110 trace_option_handler, NULL },
111 { {"trace-alu", optional_argument, NULL, OPTION_TRACE_ALU},
112 '\0', "on|off", "Trace ALU (Arithmetic Logic Unit) operations",
113 trace_option_handler, NULL },
114 { {"trace-fpu", optional_argument, NULL, OPTION_TRACE_FPU},
115 '\0', "on|off", "Trace FPU (Floating Point Unit) operations",
116 trace_option_handler, NULL },
117 { {"trace-vpu", optional_argument, NULL, OPTION_TRACE_VPU},
118 '\0', "on|off", "Trace VPU (Vector Processing Unit) operations",
119 trace_option_handler, NULL },
120 { {"trace-branch", optional_argument, NULL, OPTION_TRACE_BRANCH},
121 '\0', "on|off", "Trace branching",
122 trace_option_handler, NULL },
123 { {"trace-semantics", optional_argument, NULL, OPTION_TRACE_SEMANTICS},
124 '\0', "on|off", "Perform ALU, FPU, VPU, MEMORY, and BRANCH tracing",
125 trace_option_handler, NULL },
126 { {"trace-model", optional_argument, NULL, OPTION_TRACE_MODEL},
127 '\0', "on|off", "Include model performance data",
128 trace_option_handler, NULL },
129 { {"trace-core", optional_argument, NULL, OPTION_TRACE_CORE},
130 '\0', "on|off", "Trace core operations",
131 trace_option_handler, NULL },
132 { {"trace-events", optional_argument, NULL, OPTION_TRACE_EVENTS},
133 '\0', "on|off", "Trace events",
134 trace_option_handler, NULL },
135 { {"trace-syscall", optional_argument, NULL, OPTION_TRACE_SYSCALL},
136 '\0', "on|off", "Trace system calls",
137 trace_option_handler, NULL },
138 { {"trace-register", optional_argument, NULL, OPTION_TRACE_REGISTER},
139 '\0', "on|off", "Trace cpu register accesses",
140 trace_option_handler, NULL },
141 #ifdef SIM_HAVE_ADDR_RANGE
142 { {"trace-range", required_argument, NULL, OPTION_TRACE_RANGE},
143 '\0', "START,END", "Specify range of addresses for instruction tracing",
144 trace_option_handler, NULL },
146 { {"trace-function", required_argument, NULL, OPTION_TRACE_FUNCTION},
147 '\0', "FUNCTION", "Specify function to trace",
148 trace_option_handler, NULL },
151 { {"trace-debug", optional_argument, NULL, OPTION_TRACE_DEBUG},
152 '\0', "on|off", "Add information useful for debugging the simulator to the tracing output",
153 trace_option_handler, NULL },
154 { {"trace-file", required_argument, NULL, OPTION_TRACE_FILE},
155 '\0', "FILE NAME", "Specify tracing output file",
156 trace_option_handler, NULL },
157 { {NULL, no_argument, NULL, 0}, '\0', NULL, NULL, NULL, NULL }
160 /* Set/reset the trace options indicated in MASK. */
163 set_trace_option_mask (SIM_DESC sd, const char *name, int mask, const char *arg)
171 if (strcmp (arg, "yes") == 0
172 || strcmp (arg, "on") == 0
173 || strcmp (arg, "1") == 0)
175 else if (strcmp (arg, "no") == 0
176 || strcmp (arg, "off") == 0
177 || strcmp (arg, "0") == 0)
181 sim_io_eprintf (sd, "Argument `%s' for `--trace%s' invalid, one of `on', `off', `yes', `no' expected\n", arg, name);
186 /* Update applicable trace bits. */
187 for (trace_nr = 0; trace_nr < MAX_TRACE_VALUES; ++trace_nr)
189 if ((mask & (1 << trace_nr)) == 0)
192 /* Set non-cpu specific values. */
193 STATE_TRACE_FLAGS (sd)[trace_nr] = trace_val;
195 /* Set cpu values. */
196 for (cpu_nr = 0; cpu_nr < MAX_NR_PROCESSORS; cpu_nr++)
198 CPU_TRACE_FLAGS (STATE_CPU (sd, cpu_nr))[trace_nr] = trace_val;
202 /* Re-compute the cpu trace summary. */
205 for (cpu_nr = 0; cpu_nr < MAX_NR_PROCESSORS; cpu_nr++)
206 CPU_TRACE_DATA (STATE_CPU (sd, cpu_nr))->trace_any_p = 1;
210 for (cpu_nr = 0; cpu_nr < MAX_NR_PROCESSORS; cpu_nr++)
212 CPU_TRACE_DATA (STATE_CPU (sd, cpu_nr))->trace_any_p = 0;
213 for (trace_nr = 0; trace_nr < MAX_TRACE_VALUES; ++trace_nr)
215 if (CPU_TRACE_FLAGS (STATE_CPU (sd, cpu_nr))[trace_nr])
217 CPU_TRACE_DATA (STATE_CPU (sd, cpu_nr))->trace_any_p = 1;
227 /* Set one trace option based on its IDX value. */
230 set_trace_option (SIM_DESC sd, const char *name, int idx, const char *arg)
232 return set_trace_option_mask (sd, name, 1 << idx, arg);
237 trace_option_handler (SIM_DESC sd, sim_cpu *cpu, int opt,
238 char *arg, int is_command)
245 if (!WITH_TRACE_ANY_P)
246 sim_io_eprintf (sd, "Tracing not compiled in, `-t' ignored\n");
248 return set_trace_option_mask (sd, "trace", TRACE_USEFUL_MASK, arg);
251 case OPTION_TRACE_INSN :
252 if (WITH_TRACE_INSN_P)
253 return set_trace_option (sd, "-insn", TRACE_INSN_IDX, arg);
255 sim_io_eprintf (sd, "Instruction tracing not compiled in, `--trace-insn' ignored\n");
258 case OPTION_TRACE_DISASM :
259 if (WITH_TRACE_DISASM_P)
260 return set_trace_option (sd, "-disasm", TRACE_DISASM_IDX, arg);
262 sim_io_eprintf (sd, "Instruction tracing not compiled in, `--trace-disasm' ignored\n");
265 case OPTION_TRACE_DECODE :
266 if (WITH_TRACE_DECODE_P)
267 return set_trace_option (sd, "-decode", TRACE_DECODE_IDX, arg);
269 sim_io_eprintf (sd, "Decode tracing not compiled in, `--trace-decode' ignored\n");
272 case OPTION_TRACE_EXTRACT :
273 if (WITH_TRACE_EXTRACT_P)
274 return set_trace_option (sd, "-extract", TRACE_EXTRACT_IDX, arg);
276 sim_io_eprintf (sd, "Extract tracing not compiled in, `--trace-extract' ignored\n");
279 case OPTION_TRACE_LINENUM :
280 if (WITH_TRACE_LINENUM_P && WITH_TRACE_INSN_P)
282 if (set_trace_option (sd, "-linenum", TRACE_LINENUM_IDX, arg) != SIM_RC_OK
283 || set_trace_option (sd, "-linenum", TRACE_INSN_IDX, arg) != SIM_RC_OK)
287 sim_io_eprintf (sd, "Line number or instruction tracing not compiled in, `--trace-linenum' ignored\n");
290 case OPTION_TRACE_MEMORY :
291 if (WITH_TRACE_MEMORY_P)
292 return set_trace_option (sd, "-memory", TRACE_MEMORY_IDX, arg);
294 sim_io_eprintf (sd, "Memory tracing not compiled in, `--trace-memory' ignored\n");
297 case OPTION_TRACE_MODEL :
298 if (WITH_TRACE_MODEL_P)
299 return set_trace_option (sd, "-model", TRACE_MODEL_IDX, arg);
301 sim_io_eprintf (sd, "Model tracing not compiled in, `--trace-model' ignored\n");
304 case OPTION_TRACE_ALU :
305 if (WITH_TRACE_ALU_P)
306 return set_trace_option (sd, "-alu", TRACE_ALU_IDX, arg);
308 sim_io_eprintf (sd, "ALU tracing not compiled in, `--trace-alu' ignored\n");
311 case OPTION_TRACE_CORE :
312 if (WITH_TRACE_CORE_P)
313 return set_trace_option (sd, "-core", TRACE_CORE_IDX, arg);
315 sim_io_eprintf (sd, "CORE tracing not compiled in, `--trace-core' ignored\n");
318 case OPTION_TRACE_EVENTS :
319 if (WITH_TRACE_EVENTS_P)
320 return set_trace_option (sd, "-events", TRACE_EVENTS_IDX, arg);
322 sim_io_eprintf (sd, "EVENTS tracing not compiled in, `--trace-events' ignored\n");
325 case OPTION_TRACE_FPU :
326 if (WITH_TRACE_FPU_P)
327 return set_trace_option (sd, "-fpu", TRACE_FPU_IDX, arg);
329 sim_io_eprintf (sd, "FPU tracing not compiled in, `--trace-fpu' ignored\n");
332 case OPTION_TRACE_VPU :
333 if (WITH_TRACE_VPU_P)
334 return set_trace_option (sd, "-vpu", TRACE_VPU_IDX, arg);
336 sim_io_eprintf (sd, "VPU tracing not compiled in, `--trace-vpu' ignored\n");
339 case OPTION_TRACE_BRANCH :
340 if (WITH_TRACE_BRANCH_P)
341 return set_trace_option (sd, "-branch", TRACE_BRANCH_IDX, arg);
343 sim_io_eprintf (sd, "Branch tracing not compiled in, `--trace-branch' ignored\n");
346 case OPTION_TRACE_SYSCALL :
347 if (WITH_TRACE_SYSCALL_P)
348 return set_trace_option (sd, "-syscall", TRACE_SYSCALL_IDX, arg);
350 sim_io_eprintf (sd, "System call tracing not compiled in, `--trace-syscall' ignored\n");
353 case OPTION_TRACE_REGISTER :
354 if (WITH_TRACE_REGISTER_P)
355 return set_trace_option (sd, "-register", TRACE_REGISTER_IDX, arg);
357 sim_io_eprintf (sd, "Register tracing not compiled in, `--trace-register' ignored\n");
360 case OPTION_TRACE_SEMANTICS :
363 && WITH_TRACE_MEMORY_P
364 && WITH_TRACE_BRANCH_P)
366 if (set_trace_option (sd, "-semantics", TRACE_ALU_IDX, arg) != SIM_RC_OK
367 || set_trace_option (sd, "-semantics", TRACE_FPU_IDX, arg) != SIM_RC_OK
368 || set_trace_option (sd, "-semantics", TRACE_VPU_IDX, arg) != SIM_RC_OK
369 || set_trace_option (sd, "-semantics", TRACE_MEMORY_IDX, arg) != SIM_RC_OK
370 || set_trace_option (sd, "-semantics", TRACE_BRANCH_IDX, arg) != SIM_RC_OK)
374 sim_io_eprintf (sd, "Alu, fpu, memory, and/or branch tracing not compiled in, `--trace-semantics' ignored\n");
377 #ifdef SIM_HAVE_ADDR_RANGE
378 case OPTION_TRACE_RANGE :
379 if (WITH_TRACE_ANY_P)
383 unsigned long start,end;
384 start = strtoul (chp, &chp, 0);
387 sim_io_eprintf (sd, "--trace-range missing END argument\n");
390 end = strtoul (chp + 1, NULL, 0);
391 /* FIXME: Argument validation. */
393 sim_addr_range_add (TRACE_RANGE (CPU_PROFILE_DATA (cpu)),
396 for (cpu_nr = 0; cpu_nr < MAX_NR_PROCESSORS; ++cpu_nr)
397 sim_addr_range_add (TRACE_RANGE (CPU_TRACE_DATA (STATE_CPU (sd, cpu_nr))),
401 sim_io_eprintf (sd, "Tracing not compiled in, `--trace-range' ignored\n");
404 case OPTION_TRACE_FUNCTION :
405 if (WITH_TRACE_ANY_P)
407 /*wip: need to compute function range given name*/
410 sim_io_eprintf (sd, "Tracing not compiled in, `--trace-function' ignored\n");
412 #endif /* SIM_HAVE_ADDR_RANGE */
414 case OPTION_TRACE_DEBUG :
415 if (WITH_TRACE_DEBUG_P)
416 return set_trace_option (sd, "-debug", TRACE_DEBUG_IDX, arg);
418 sim_io_eprintf (sd, "Tracing debug support not compiled in, `--trace-debug' ignored\n");
421 case OPTION_TRACE_FILE :
422 if (!WITH_TRACE_ANY_P)
423 sim_io_eprintf (sd, "Tracing not compiled in, `--trace-file' ignored\n");
426 FILE *f = fopen (arg, "w");
430 sim_io_eprintf (sd, "Unable to open trace output file `%s'\n", arg);
433 for (n = 0; n < MAX_NR_PROCESSORS; ++n)
434 TRACE_FILE (CPU_TRACE_DATA (STATE_CPU (sd, n))) = f;
435 TRACE_FILE (STATE_TRACE_DATA (sd)) = f;
443 /* Install tracing support. */
446 trace_install (SIM_DESC sd)
450 SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
452 sim_add_option_table (sd, NULL, trace_options);
453 memset (STATE_TRACE_DATA (sd), 0, sizeof (* STATE_TRACE_DATA (sd)));
454 for (i = 0; i < MAX_NR_PROCESSORS; ++i)
455 memset (CPU_TRACE_DATA (STATE_CPU (sd, i)), 0,
456 sizeof (* CPU_TRACE_DATA (STATE_CPU (sd, i))));
457 sim_module_add_init_fn (sd, trace_init);
458 sim_module_add_uninstall_fn (sd, trace_uninstall);
463 trace_init (SIM_DESC sd)
465 #ifdef SIM_HAVE_ADDR_RANGE
466 /* Check if a range has been specified without specifying what to
471 for (i = 0; i < MAX_NR_PROCESSORS; ++i)
473 sim_cpu *cpu = STATE_CPU (sd, i);
475 if (ADDR_RANGE_RANGES (TRACE_RANGE (CPU_TRACE_DATA (cpu)))
476 && ! TRACE_INSN_P (cpu))
478 sim_io_eprintf_cpu (cpu, "Tracing address range specified without --trace-insn.\n");
479 sim_io_eprintf_cpu (cpu, "Address range ignored.\n");
480 sim_addr_range_delete (TRACE_RANGE (CPU_TRACE_DATA (cpu)),
481 0, ~ (address_word) 0);
491 trace_uninstall (SIM_DESC sd)
494 FILE *sfile = TRACE_FILE (STATE_TRACE_DATA (sd));
499 for (i = 0; i < MAX_NR_PROCESSORS; ++i)
501 FILE *cfile = TRACE_FILE (CPU_TRACE_DATA (STATE_CPU (sd, i)));
502 if (cfile != NULL && cfile != sfile)
504 /* If output from different cpus is going to the same file,
505 avoid closing the file twice. */
506 for (j = 0; j < i; ++j)
507 if (TRACE_FILE (CPU_TRACE_DATA (STATE_CPU (sd, j))) == cfile)
514 if (STATE_PROG_SYMS (sd))
515 free (STATE_PROG_SYMS (sd));
518 /* compute the nr of trace data units consumed by data */
520 save_data_size (TRACE_DATA *data,
523 return ((size + sizeof (TRACE_INPUT_DATA (data) [0]) - 1)
524 / sizeof (TRACE_INPUT_DATA (data) [0]));
528 /* Archive DATA into the trace buffer */
530 save_data (SIM_DESC sd,
536 int i = TRACE_INPUT_IDX (data);
537 if (i == sizeof (TRACE_INPUT_FMT (data)))
538 sim_io_error (sd, "trace buffer overflow");
539 TRACE_INPUT_FMT (data) [i] = fmt;
540 TRACE_INPUT_SIZE (data) [i] = size;
541 memcpy (&TRACE_INPUT_DATA (data) [i], buf, size);
542 i += save_data_size (data, size);
543 TRACE_INPUT_IDX (data) = i;
547 print_data (SIM_DESC sd,
555 case trace_fmt_instruction_incomplete:
556 trace_printf (sd, cpu, " (instruction incomplete)");
563 case sizeof (unsigned32):
564 trace_printf (sd, cpu, " 0x%08lx", (long) * (unsigned32*) data);
566 case sizeof (unsigned64):
567 trace_printf (sd, cpu, " 0x%08lx%08lx",
568 (long) ((* (unsigned64*) data) >> 32),
569 (long) * (unsigned64*) data);
578 SIM_ASSERT (size == sizeof (int));
579 trace_printf (sd, cpu, " %-8s",
580 (* (int*) data) ? "true" : "false");
588 /* FIXME: Assumes sizeof float == 4; sizeof double == 8 */
590 sim_fpu_32to (&fp, *(unsigned32*)data);
593 sim_fpu_64to (&fp, *(unsigned64*)data);
598 trace_printf (sd, cpu, " %8g", sim_fpu_2d (&fp));
602 trace_printf (sd, cpu, " (0x%08lx)",
603 (long) *(unsigned32*)data);
606 trace_printf (sd, cpu, " (0x%08lx%08lx)",
607 (long) (*(unsigned64*)data >> 32),
608 (long) (*(unsigned64*)data));
616 /* FIXME: At present sim_fpu data is stored as a double */
617 trace_printf (sd, cpu, " %8g", * (double*) data);
619 case trace_fmt_string:
620 trace_printf (sd, cpu, " %-8s", (char*) data);
628 trace_idx_to_str (int trace_idx)
633 case TRACE_ALU_IDX: return "alu: ";
634 case TRACE_INSN_IDX: return "insn: ";
635 case TRACE_DISASM_IDX: return "disasm: ";
636 case TRACE_DECODE_IDX: return "decode: ";
637 case TRACE_EXTRACT_IDX: return "extract: ";
638 case TRACE_MEMORY_IDX: return "memory: ";
639 case TRACE_CORE_IDX: return "core: ";
640 case TRACE_EVENTS_IDX: return "events: ";
641 case TRACE_FPU_IDX: return "fpu: ";
642 case TRACE_BRANCH_IDX: return "branch: ";
643 case TRACE_SYSCALL_IDX: return "syscall: ";
644 case TRACE_REGISTER_IDX: return "reg: ";
645 case TRACE_VPU_IDX: return "vpu: ";
647 sprintf (num, "?%d?", trace_idx);
653 trace_results (SIM_DESC sd,
658 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
662 /* cross check trace_idx against TRACE_IDX (data)? */
665 trace_printf (sd, cpu, "%s %s",
666 trace_idx_to_str (TRACE_IDX (data)),
667 TRACE_PREFIX (data));
668 TRACE_IDX (data) = 0;
670 for (i = 0, nr_out = 0;
671 i < TRACE_INPUT_IDX (data);
672 i += save_data_size (data, TRACE_INPUT_SIZE (data) [i]), nr_out++)
676 int pad = (strlen (" 0x") + sizeof (unsigned_word) * 2);
677 int padding = pad * (3 - nr_out);
680 padding += strlen (" ::");
681 trace_printf (sd, cpu, "%*s", padding, " ::");
684 TRACE_INPUT_FMT (data) [i],
685 TRACE_INPUT_SIZE (data) [i],
686 &TRACE_INPUT_DATA (data) [i]);
688 trace_printf (sd, cpu, "\n");
692 trace_load_symbols (SIM_DESC sd)
699 /* Already loaded, so nothing to do. */
700 if (STATE_PROG_SYMS (sd))
703 abfd = STATE_PROG_BFD (sd);
707 symsize = bfd_get_symtab_upper_bound (abfd);
711 asymbols = xmalloc (symsize);
712 symbol_count = bfd_canonicalize_symtab (abfd, asymbols);
713 if (symbol_count < 0)
719 STATE_PROG_SYMS (sd) = asymbols;
720 STATE_PROG_SYMS_COUNT (sd) = symbol_count;
725 trace_sym_value (SIM_DESC sd, const char *name)
730 if (!trace_load_symbols (sd))
733 asymbols = STATE_PROG_SYMS (sd);
735 for (i = 0; i < STATE_PROG_SYMS_COUNT (sd); ++i)
736 if (strcmp (asymbols[i]->name, name) == 0)
737 return bfd_asymbol_value (asymbols[i]);
743 trace_prefix (SIM_DESC sd,
748 const char *filename,
753 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
755 char *prefix = TRACE_PREFIX (data);
757 /* FIXME: The TRACE_PREFIX_WIDTH should be determined at build time using
758 known information about the disassembled instructions. */
759 #ifndef TRACE_PREFIX_WIDTH
760 #define TRACE_PREFIX_WIDTH 48
762 int width = TRACE_PREFIX_WIDTH;
764 /* if the previous trace data wasn't flushed, flush it now with a
765 note indicating that the trace was incomplete. */
766 if (TRACE_IDX (data) != 0)
768 int last_input = TRACE_INPUT_IDX (data);
769 save_data (sd, data, trace_fmt_instruction_incomplete, 1, "");
770 trace_results (sd, cpu, TRACE_IDX (data), last_input);
772 TRACE_IDX (data) = 0;
773 TRACE_INPUT_IDX (data) = 0;
775 /* Create the text prefix for this new instruction: */
780 sprintf (prefix, "%s:%-*d 0x%.*lx ",
782 SIZE_LINE_NUMBER, linenum,
787 sprintf (prefix, "0x%.*lx ",
789 /* Shrink the width by the amount that we didn't print. */
790 width -= SIZE_LINE_NUMBER + SIZE_PC + 8;
792 chp = strchr (prefix, '\0');
794 vsprintf (chp, fmt, ap);
801 if (STATE_TEXT_SECTION (sd)
802 && pc >= STATE_TEXT_START (sd)
803 && pc < STATE_TEXT_END (sd))
805 const char *pc_filename = (const char *)0;
806 const char *pc_function = (const char *)0;
807 unsigned int pc_linenum = 0;
811 if (!trace_load_symbols (sd))
812 sim_engine_abort (sd, cpu, cia, "could not load symbols");
814 abfd = STATE_PROG_BFD (sd);
815 asymbols = STATE_PROG_SYMS (sd);
817 if (bfd_find_nearest_line (abfd, STATE_TEXT_SECTION (sd), asymbols,
818 pc - STATE_TEXT_START (sd),
819 &pc_filename, &pc_function, &pc_linenum))
824 sprintf (p, "#%-*d ", SIZE_LINE_NUMBER, pc_linenum);
829 sprintf (p, "%-*s ", SIZE_LINE_NUMBER+1, "---");
830 p += SIZE_LINE_NUMBER+2;
835 sprintf (p, "%s ", pc_function);
838 else if (pc_filename)
840 char *q = (char *) strrchr (pc_filename, '/');
841 sprintf (p, "%s ", (q) ? q+1 : pc_filename);
850 sprintf (prefix, "0x%.*x %-*.*s ",
851 SIZE_PC, (unsigned) pc,
852 SIZE_LOCATION, SIZE_LOCATION, buf);
853 chp = strchr (prefix, '\0');
855 vsprintf (chp, fmt, ap);
859 /* Pad it out to TRACE_PREFIX_WIDTH. */
860 chp = strchr (prefix, '\0');
861 if (chp - prefix < width)
863 memset (chp, ' ', width - (chp - prefix));
864 chp = &prefix [width];
869 /* check that we've not over flowed the prefix buffer */
870 if (strlen (prefix) >= sizeof (TRACE_PREFIX (data)))
875 trace_generic (SIM_DESC sd,
882 trace_printf (sd, cpu, "%s %s",
883 trace_idx_to_str (trace_idx),
884 TRACE_PREFIX (CPU_TRACE_DATA (cpu)));
886 trace_vprintf (sd, cpu, fmt, ap);
888 trace_printf (sd, cpu, "\n");
892 dis_read (bfd_vma memaddr, bfd_byte *myaddr, unsigned int length,
893 struct disassemble_info *dinfo)
895 SIM_CPU *cpu = dinfo->application_data;
896 sim_core_read_buffer (CPU_STATE (cpu), cpu, NULL_CIA, myaddr, memaddr, length);
901 dis_printf (SIM_CPU *cpu, const char *fmt, ...)
903 SIM_DESC sd = CPU_STATE (cpu);
906 trace_vprintf (sd, cpu, fmt, ap);
912 trace_disasm (SIM_DESC sd, sim_cpu *cpu, address_word addr)
914 struct bfd *bfd = STATE_PROG_BFD (sd);
915 TRACE_DATA *trace_data = CPU_TRACE_DATA (cpu);
916 disassemble_info *info = &trace_data->dis_info;
918 /* See if we need to set up the disassembly func. */
919 if (trace_data->dis_bfd != bfd)
921 trace_data->dis_bfd = bfd;
922 trace_data->disassembler
923 = disassembler (bfd_get_arch (trace_data->dis_bfd),
924 bfd_big_endian (trace_data->dis_bfd),
925 bfd_get_mach (trace_data->dis_bfd),
926 trace_data->dis_bfd);
927 INIT_DISASSEMBLE_INFO (*info, cpu, dis_printf);
928 info->read_memory_func = dis_read;
929 info->arch = bfd_get_arch (bfd);
930 info->mach = bfd_get_mach (bfd);
931 disassemble_init_for_target (info);
934 info->application_data = cpu;
936 trace_printf (sd, cpu, "%s %s",
937 trace_idx_to_str (TRACE_DISASM_IDX),
938 TRACE_PREFIX (trace_data));
939 trace_data->disassembler (addr, info);
940 trace_printf (sd, cpu, "\n");
944 trace_input0 (SIM_DESC sd,
948 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
949 TRACE_IDX (data) = trace_idx;
953 trace_input_word1 (SIM_DESC sd,
958 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
959 TRACE_IDX (data) = trace_idx;
960 save_data (sd, data, trace_fmt_word, sizeof (unsigned_word), &d0);
964 trace_input_word2 (SIM_DESC sd,
970 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
971 TRACE_IDX (data) = trace_idx;
972 save_data (sd, data, trace_fmt_word, sizeof (unsigned_word), &d0);
973 save_data (sd, data, trace_fmt_word, sizeof (unsigned_word), &d1);
977 trace_input_word3 (SIM_DESC sd,
984 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
985 TRACE_IDX (data) = trace_idx;
986 save_data (sd, data, trace_fmt_word, sizeof (unsigned_word), &d0);
987 save_data (sd, data, trace_fmt_word, sizeof (unsigned_word), &d1);
988 save_data (sd, data, trace_fmt_word, sizeof (unsigned_word), &d2);
992 trace_input_word4 (SIM_DESC sd,
1000 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1001 TRACE_IDX (data) = trace_idx;
1002 save_data (sd, data, trace_fmt_word, sizeof (d0), &d0);
1003 save_data (sd, data, trace_fmt_word, sizeof (d1), &d1);
1004 save_data (sd, data, trace_fmt_word, sizeof (d2), &d2);
1005 save_data (sd, data, trace_fmt_word, sizeof (d3), &d3);
1009 trace_input_bool1 (SIM_DESC sd,
1014 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1015 TRACE_IDX (data) = trace_idx;
1016 save_data (sd, data, trace_fmt_bool, sizeof (d0), &d0);
1020 trace_input_addr1 (SIM_DESC sd,
1025 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1026 TRACE_IDX (data) = trace_idx;
1027 save_data (sd, data, trace_fmt_addr, sizeof (d0), &d0);
1031 trace_input_fp1 (SIM_DESC sd,
1036 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1037 TRACE_IDX (data) = trace_idx;
1038 save_data (sd, data, trace_fmt_fp, sizeof (fp_word), &f0);
1042 trace_input_fp2 (SIM_DESC sd,
1048 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1049 TRACE_IDX (data) = trace_idx;
1050 save_data (sd, data, trace_fmt_fp, sizeof (fp_word), &f0);
1051 save_data (sd, data, trace_fmt_fp, sizeof (fp_word), &f1);
1055 trace_input_fp3 (SIM_DESC sd,
1062 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1063 TRACE_IDX (data) = trace_idx;
1064 save_data (sd, data, trace_fmt_fp, sizeof (fp_word), &f0);
1065 save_data (sd, data, trace_fmt_fp, sizeof (fp_word), &f1);
1066 save_data (sd, data, trace_fmt_fp, sizeof (fp_word), &f2);
1070 trace_input_fpu1 (SIM_DESC sd,
1076 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1077 TRACE_IDX (data) = trace_idx;
1078 d = sim_fpu_2d (f0);
1079 save_data (sd, data, trace_fmt_fp, sizeof (double), &d);
1083 trace_input_fpu2 (SIM_DESC sd,
1090 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1091 TRACE_IDX (data) = trace_idx;
1092 d = sim_fpu_2d (f0);
1093 save_data (sd, data, trace_fmt_fp, sizeof (double), &d);
1094 d = sim_fpu_2d (f1);
1095 save_data (sd, data, trace_fmt_fp, sizeof (double), &d);
1099 trace_input_fpu3 (SIM_DESC sd,
1107 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1108 TRACE_IDX (data) = trace_idx;
1109 d = sim_fpu_2d (f0);
1110 save_data (sd, data, trace_fmt_fp, sizeof (double), &d);
1111 d = sim_fpu_2d (f1);
1112 save_data (sd, data, trace_fmt_fp, sizeof (double), &d);
1113 d = sim_fpu_2d (f2);
1114 save_data (sd, data, trace_fmt_fp, sizeof (double), &d);
1118 trace_result_word1 (SIM_DESC sd,
1123 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1126 /* Append any results to the end of the inputs */
1127 last_input = TRACE_INPUT_IDX (data);
1128 save_data (sd, data, trace_fmt_word, sizeof (unsigned_word), &r0);
1130 trace_results (sd, cpu, trace_idx, last_input);
1134 trace_result0 (SIM_DESC sd,
1138 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1141 /* Append any results to the end of the inputs */
1142 last_input = TRACE_INPUT_IDX (data);
1144 trace_results (sd, cpu, trace_idx, last_input);
1148 trace_result_word2 (SIM_DESC sd,
1154 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1157 /* Append any results to the end of the inputs */
1158 last_input = TRACE_INPUT_IDX (data);
1159 save_data (sd, data, trace_fmt_word, sizeof (r0), &r0);
1160 save_data (sd, data, trace_fmt_word, sizeof (r1), &r1);
1162 trace_results (sd, cpu, trace_idx, last_input);
1166 trace_result_word4 (SIM_DESC sd,
1174 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1177 /* Append any results to the end of the inputs */
1178 last_input = TRACE_INPUT_IDX (data);
1179 save_data (sd, data, trace_fmt_word, sizeof (r0), &r0);
1180 save_data (sd, data, trace_fmt_word, sizeof (r1), &r1);
1181 save_data (sd, data, trace_fmt_word, sizeof (r2), &r2);
1182 save_data (sd, data, trace_fmt_word, sizeof (r3), &r3);
1184 trace_results (sd, cpu, trace_idx, last_input);
1188 trace_result_bool1 (SIM_DESC sd,
1193 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1196 /* Append any results to the end of the inputs */
1197 last_input = TRACE_INPUT_IDX (data);
1198 save_data (sd, data, trace_fmt_bool, sizeof (r0), &r0);
1200 trace_results (sd, cpu, trace_idx, last_input);
1204 trace_result_addr1 (SIM_DESC sd,
1209 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1212 /* Append any results to the end of the inputs */
1213 last_input = TRACE_INPUT_IDX (data);
1214 save_data (sd, data, trace_fmt_addr, sizeof (r0), &r0);
1216 trace_results (sd, cpu, trace_idx, last_input);
1220 trace_result_fp1 (SIM_DESC sd,
1225 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1228 /* Append any results to the end of the inputs */
1229 last_input = TRACE_INPUT_IDX (data);
1230 save_data (sd, data, trace_fmt_fp, sizeof (fp_word), &f0);
1232 trace_results (sd, cpu, trace_idx, last_input);
1236 trace_result_fp2 (SIM_DESC sd,
1242 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1245 /* Append any results to the end of the inputs */
1246 last_input = TRACE_INPUT_IDX (data);
1247 save_data (sd, data, trace_fmt_fp, sizeof (f0), &f0);
1248 save_data (sd, data, trace_fmt_fp, sizeof (f1), &f1);
1250 trace_results (sd, cpu, trace_idx, last_input);
1254 trace_result_fpu1 (SIM_DESC sd,
1260 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1263 /* Append any results to the end of the inputs */
1264 last_input = TRACE_INPUT_IDX (data);
1265 d = sim_fpu_2d (f0);
1266 save_data (sd, data, trace_fmt_fp, sizeof (double), &d);
1268 trace_results (sd, cpu, trace_idx, last_input);
1272 trace_result_string1 (SIM_DESC sd,
1277 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1280 /* Append any results to the end of the inputs */
1281 last_input = TRACE_INPUT_IDX (data);
1282 save_data (sd, data, trace_fmt_string, strlen (s0) + 1, s0);
1284 trace_results (sd, cpu, trace_idx, last_input);
1288 trace_result_word1_string1 (SIM_DESC sd,
1294 TRACE_DATA *data = CPU_TRACE_DATA (cpu);
1297 /* Append any results to the end of the inputs */
1298 last_input = TRACE_INPUT_IDX (data);
1299 save_data (sd, data, trace_fmt_word, sizeof (unsigned_word), &r0);
1300 save_data (sd, data, trace_fmt_string, strlen (s0) + 1, s0);
1302 trace_results (sd, cpu, trace_idx, last_input);
1306 trace_vprintf (SIM_DESC sd, sim_cpu *cpu, const char *fmt, va_list ap)
1310 if (TRACE_FILE (CPU_TRACE_DATA (cpu)) != NULL)
1311 vfprintf (TRACE_FILE (CPU_TRACE_DATA (cpu)), fmt, ap);
1313 sim_io_evprintf (sd, fmt, ap);
1317 if (TRACE_FILE (STATE_TRACE_DATA (sd)) != NULL)
1318 vfprintf (TRACE_FILE (STATE_TRACE_DATA (sd)), fmt, ap);
1320 sim_io_evprintf (sd, fmt, ap);
1325 trace_printf (SIM_DESC sd, sim_cpu *cpu, const char *fmt, ...)
1331 trace_vprintf (sd, cpu, fmt, ap);
1337 sim_debug_printf (sim_cpu *cpu, const char *fmt, ...)
1343 if (CPU_DEBUG_FILE (cpu) == NULL)
1344 (* STATE_CALLBACK (CPU_STATE (cpu))->evprintf_filtered)
1345 (STATE_CALLBACK (CPU_STATE (cpu)), fmt, ap);
1347 vfprintf (CPU_DEBUG_FILE (cpu), fmt, ap);