1 /* Simulator tracing/debugging support.
2 Copyright (C) 1997-2014 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/>. */
20 /* This file is meant to be included by sim-basics.h. */
25 /* Standard traceable entities. */
28 /* Trace insn execution. */
31 /* Trace insn decoding.
32 ??? This is more of a simulator debugging operation and might best be
33 moved to --debug-decode. */
36 /* Trace insn extraction.
37 ??? This is more of a simulator debugging operation and might best be
38 moved to --debug-extract. */
41 /* Trace insn execution but include line numbers. */
44 /* Trace memory operations.
45 The difference between this and TRACE_CORE_IDX is (I think) that this
46 is intended to apply to a higher level. TRACE_CORE_IDX applies to the
47 low level core operations. */
50 /* Include model performance data in tracing output. */
53 /* Trace ALU operations. */
56 /* Trace memory core operations. */
62 /* Trace fpu operations. */
65 /* Trace vpu operations. */
68 /* Trace branching. */
74 /* Add information useful for debugging the simulator to trace output. */
77 /* Simulator specific trace bits begin here. */
81 /* Maximum number of traceable entities. */
82 #ifndef MAX_TRACE_VALUES
83 #define MAX_TRACE_VALUES 32
86 /* The -t option only prints useful values. It's easy to type and shouldn't
87 splat on the screen everything under the sun making nothing easy to
89 #define TRACE_USEFUL_MASK \
90 ((1 << TRACE_INSN_IDX) \
91 | (1 << TRACE_LINENUM_IDX) \
92 | (1 << TRACE_MEMORY_IDX) \
93 | (1 << TRACE_MODEL_IDX))
95 /* Masks so WITH_TRACE can have symbolic values.
96 The case choice here is on purpose. The lowercase parts are args to
98 #define TRACE_insn (1 << TRACE_INSN_IDX)
99 #define TRACE_decode (1 << TRACE_DECODE_IDX)
100 #define TRACE_extract (1 << TRACE_EXTRACT_IDX)
101 #define TRACE_linenum (1 << TRACE_LINENUM_IDX)
102 #define TRACE_memory (1 << TRACE_MEMORY_IDX)
103 #define TRACE_model (1 << TRACE_MODEL_IDX)
104 #define TRACE_alu (1 << TRACE_ALU_IDX)
105 #define TRACE_core (1 << TRACE_CORE_IDX)
106 #define TRACE_events (1 << TRACE_EVENTS_IDX)
107 #define TRACE_fpu (1 << TRACE_FPU_IDX)
108 #define TRACE_vpu (1 << TRACE_VPU_IDX)
109 #define TRACE_branch (1 << TRACE_BRANCH_IDX)
110 #define TRACE_syscall (1 << TRACE_SYSCALL_IDX)
111 #define TRACE_debug (1 << TRACE_DEBUG_IDX)
113 /* Preprocessor macros to simplify tests of WITH_TRACE. */
114 #define WITH_TRACE_INSN_P (WITH_TRACE & TRACE_insn)
115 #define WITH_TRACE_DECODE_P (WITH_TRACE & TRACE_decode)
116 #define WITH_TRACE_EXTRACT_P (WITH_TRACE & TRACE_extract)
117 #define WITH_TRACE_LINENUM_P (WITH_TRACE & TRACE_linenum)
118 #define WITH_TRACE_MEMORY_P (WITH_TRACE & TRACE_memory)
119 #define WITH_TRACE_MODEL_P (WITH_TRACE & TRACE_model)
120 #define WITH_TRACE_ALU_P (WITH_TRACE & TRACE_alu)
121 #define WITH_TRACE_CORE_P (WITH_TRACE & TRACE_core)
122 #define WITH_TRACE_EVENTS_P (WITH_TRACE & TRACE_events)
123 #define WITH_TRACE_FPU_P (WITH_TRACE & TRACE_fpu)
124 #define WITH_TRACE_VPU_P (WITH_TRACE & TRACE_vpu)
125 #define WITH_TRACE_BRANCH_P (WITH_TRACE & TRACE_branch)
126 #define WITH_TRACE_SYSCALL_P (WITH_TRACE & TRACE_syscall)
127 #define WITH_TRACE_DEBUG_P (WITH_TRACE & TRACE_debug)
129 /* Tracing install handler. */
130 MODULE_INSTALL_FN trace_install;
132 /* Struct containing all system and cpu trace data.
134 System trace data is stored with the associated module.
135 System and cpu tracing must share the same space of bitmasks as they
136 are arguments to --with-trace. One could have --with-trace and
137 --with-cpu-trace or some such but that's an over-complication at this point
138 in time. Also, there may be occasions where system and cpu tracing may
139 wish to share a name. */
141 typedef struct _trace_data {
143 /* Global summary of all the current trace options */
146 /* Boolean array of specified tracing flags. */
147 /* ??? It's not clear that using an array vs a bit mask is faster.
148 Consider the case where one wants to test whether any of several bits
150 char trace_flags[MAX_TRACE_VALUES];
151 #define TRACE_FLAGS(t) ((t)->trace_flags)
153 /* Tracing output goes to this or stderr if NULL.
154 We can't store `stderr' here as stderr goes through a callback. */
156 #define TRACE_FILE(t) ((t)->trace_file)
158 /* Buffer to store the prefix to be printed before any trace line. */
159 char trace_prefix[256];
160 #define TRACE_PREFIX(t) ((t)->trace_prefix)
162 /* Buffer to save the inputs for the current instruction. Use a
163 union to force the buffer into correct alignment */
169 } trace_input_data[16];
170 unsigned8 trace_input_fmt[16];
171 unsigned8 trace_input_size[16];
173 #define TRACE_INPUT_DATA(t) ((t)->trace_input_data)
174 #define TRACE_INPUT_FMT(t) ((t)->trace_input_fmt)
175 #define TRACE_INPUT_SIZE(t) ((t)->trace_input_size)
176 #define TRACE_INPUT_IDX(t) ((t)->trace_input_idx)
178 /* Category of trace being performed */
180 #define TRACE_IDX(t) ((t)->trace_idx)
183 ??? Not all cpu's support this. */
185 #define TRACE_RANGE(t) (& (t)->range)
188 /* System tracing support. */
190 #define STATE_TRACE_FLAGS(sd) TRACE_FLAGS (STATE_TRACE_DATA (sd))
192 /* Return non-zero if tracing of IDX is enabled for non-cpu specific
193 components. The "S" in "STRACE" refers to "System". */
194 #define STRACE_P(sd,idx) \
195 ((WITH_TRACE & (1 << (idx))) != 0 \
196 && STATE_TRACE_FLAGS (sd)[idx] != 0)
198 /* Non-zero if --trace-<xxxx> was specified for SD. */
199 #define STRACE_DEBUG_P(sd) STRACE_P (sd, TRACE_DEBUG_IDX)
201 /* CPU tracing support. */
203 #define CPU_TRACE_FLAGS(cpu) TRACE_FLAGS (CPU_TRACE_DATA (cpu))
205 /* Return non-zero if tracing of IDX is enabled for CPU. */
206 #define TRACE_P(cpu,idx) \
207 ((WITH_TRACE & (1 << (idx))) != 0 \
208 && CPU_TRACE_FLAGS (cpu)[idx] != 0)
210 /* Non-zero if --trace-<xxxx> was specified for CPU. */
211 #define TRACE_ANY_P(cpu) ((WITH_TRACE) && (CPU_TRACE_DATA (cpu)->trace_any_p))
212 #define TRACE_INSN_P(cpu) TRACE_P (cpu, TRACE_INSN_IDX)
213 #define TRACE_DECODE_P(cpu) TRACE_P (cpu, TRACE_DECODE_IDX)
214 #define TRACE_EXTRACT_P(cpu) TRACE_P (cpu, TRACE_EXTRACT_IDX)
215 #define TRACE_LINENUM_P(cpu) TRACE_P (cpu, TRACE_LINENUM_IDX)
216 #define TRACE_MEMORY_P(cpu) TRACE_P (cpu, TRACE_MEMORY_IDX)
217 #define TRACE_MODEL_P(cpu) TRACE_P (cpu, TRACE_MODEL_IDX)
218 #define TRACE_ALU_P(cpu) TRACE_P (cpu, TRACE_ALU_IDX)
219 #define TRACE_CORE_P(cpu) TRACE_P (cpu, TRACE_CORE_IDX)
220 #define TRACE_EVENTS_P(cpu) TRACE_P (cpu, TRACE_EVENTS_IDX)
221 #define TRACE_FPU_P(cpu) TRACE_P (cpu, TRACE_FPU_IDX)
222 #define TRACE_VPU_P(cpu) TRACE_P (cpu, TRACE_VPU_IDX)
223 #define TRACE_BRANCH_P(cpu) TRACE_P (cpu, TRACE_BRANCH_IDX)
224 #define TRACE_SYSCALL_P(cpu) TRACE_P (cpu, TRACE_SYSCALL_IDX)
225 #define TRACE_DEBUG_P(cpu) TRACE_P (cpu, TRACE_DEBUG_IDX)
227 /* Tracing functions. */
229 /* Prime the trace buffers ready for any trace output.
230 Must be called prior to any other trace operation */
231 extern void trace_prefix (SIM_DESC sd,
236 const char *file_name,
240 __attribute__((format (printf, 8, 9)));
242 /* Generic trace print, assumes trace_prefix() has been called */
244 extern void trace_generic (SIM_DESC sd,
249 __attribute__((format (printf, 4, 5)));
259 trace_fmt_instruction_incomplete,
262 /* Trace a varying number of word sized inputs/outputs. trace_result*
263 must be called to close the trace operation. */
265 extern void save_data (SIM_DESC sd,
271 extern void trace_input0 (SIM_DESC sd,
275 extern void trace_input_word1 (SIM_DESC sd,
280 extern void trace_input_word2 (SIM_DESC sd,
286 extern void trace_input_word3 (SIM_DESC sd,
293 extern void trace_input_word4 (SIM_DESC sd,
301 extern void trace_input_addr1 (SIM_DESC sd,
306 extern void trace_input_bool1 (SIM_DESC sd,
311 extern void trace_input_fp1 (SIM_DESC sd,
316 extern void trace_input_fp2 (SIM_DESC sd,
322 extern void trace_input_fp3 (SIM_DESC sd,
329 extern void trace_input_fpu1 (SIM_DESC sd,
332 struct _sim_fpu *f0);
334 extern void trace_input_fpu2 (SIM_DESC sd,
338 struct _sim_fpu *f1);
340 extern void trace_input_fpu3 (SIM_DESC sd,
345 struct _sim_fpu *f2);
347 /* Other trace_input{_<fmt><nr-inputs>} functions can go here */
349 extern void trace_result0 (SIM_DESC sd,
353 extern void trace_result_word1 (SIM_DESC sd,
358 extern void trace_result_word2 (SIM_DESC sd,
364 extern void trace_result_word4 (SIM_DESC sd,
372 extern void trace_result_bool1 (SIM_DESC sd,
377 extern void trace_result_addr1 (SIM_DESC sd,
382 extern void trace_result_fp1 (SIM_DESC sd,
387 extern void trace_result_fp2 (SIM_DESC sd,
393 extern void trace_result_fpu1 (SIM_DESC sd,
396 struct _sim_fpu *f0);
398 extern void trace_result_string1 (SIM_DESC sd,
403 extern void trace_result_word1_string1 (SIM_DESC sd,
409 /* Other trace_result{_<type><nr-results>} */
412 /* Macros for tracing ALU instructions */
414 #define TRACE_ALU_INPUT0() \
416 if (TRACE_ALU_P (CPU)) \
417 trace_input0 (SD, CPU, TRACE_ALU_IDX); \
420 #define TRACE_ALU_INPUT1(V0) \
422 if (TRACE_ALU_P (CPU)) \
423 trace_input_word1 (SD, CPU, TRACE_ALU_IDX, (V0)); \
426 #define TRACE_ALU_INPUT2(V0,V1) \
428 if (TRACE_ALU_P (CPU)) \
429 trace_input_word2 (SD, CPU, TRACE_ALU_IDX, (V0), (V1)); \
432 #define TRACE_ALU_INPUT3(V0,V1,V2) \
434 if (TRACE_ALU_P (CPU)) \
435 trace_input_word3 (SD, CPU, TRACE_ALU_IDX, (V0), (V1), (V2)); \
438 #define TRACE_ALU_INPUT4(V0,V1,V2,V3) \
440 if (TRACE_ALU_P (CPU)) \
441 trace_input_word4 (SD, CPU, TRACE_ALU_IDX, (V0), (V1), (V2), (V3)); \
444 #define TRACE_ALU_RESULT(R0) TRACE_ALU_RESULT1(R0)
446 #define TRACE_ALU_RESULT0() \
448 if (TRACE_ALU_P (CPU)) \
449 trace_result0 (SD, CPU, TRACE_ALU_IDX); \
452 #define TRACE_ALU_RESULT1(R0) \
454 if (TRACE_ALU_P (CPU)) \
455 trace_result_word1 (SD, CPU, TRACE_ALU_IDX, (R0)); \
458 #define TRACE_ALU_RESULT2(R0,R1) \
460 if (TRACE_ALU_P (CPU)) \
461 trace_result_word2 (SD, CPU, TRACE_ALU_IDX, (R0), (R1)); \
464 #define TRACE_ALU_RESULT4(R0,R1,R2,R3) \
466 if (TRACE_ALU_P (CPU)) \
467 trace_result_word4 (SD, CPU, TRACE_ALU_IDX, (R0), (R1), (R2), (R3)); \
470 /* Macros for tracing inputs to comparative branch instructions. */
472 #define TRACE_BRANCH_INPUT1(V0) \
474 if (TRACE_BRANCH_P (CPU)) \
475 trace_input_word1 (SD, CPU, TRACE_BRANCH_IDX, (V0)); \
478 #define TRACE_BRANCH_INPUT2(V0,V1) \
480 if (TRACE_BRANCH_P (CPU)) \
481 trace_input_word2 (SD, CPU, TRACE_BRANCH_IDX, (V0), (V1)); \
484 /* Macros for tracing FPU instructions */
486 #define TRACE_FP_INPUT0() \
488 if (TRACE_FPU_P (CPU)) \
489 trace_input0 (SD, CPU, TRACE_FPU_IDX); \
492 #define TRACE_FP_INPUT1(V0) \
494 if (TRACE_FPU_P (CPU)) \
495 trace_input_fp1 (SD, CPU, TRACE_FPU_IDX, (V0)); \
498 #define TRACE_FP_INPUT2(V0,V1) \
500 if (TRACE_FPU_P (CPU)) \
501 trace_input_fp2 (SD, CPU, TRACE_FPU_IDX, (V0), (V1)); \
504 #define TRACE_FP_INPUT3(V0,V1,V2) \
506 if (TRACE_FPU_P (CPU)) \
507 trace_input_fp3 (SD, CPU, TRACE_FPU_IDX, (V0), (V1), (V2)); \
510 #define TRACE_FP_INPUT_WORD1(V0) \
512 if (TRACE_FPU_P (CPU)) \
513 trace_input_word1 (SD, CPU, TRACE_FPU_IDX, (V0)); \
516 #define TRACE_FP_RESULT(R0) \
518 if (TRACE_FPU_P (CPU)) \
519 trace_result_fp1 (SD, CPU, TRACE_FPU_IDX, (R0)); \
522 #define TRACE_FP_RESULT2(R0,R1) \
524 if (TRACE_FPU_P (CPU)) \
525 trace_result_fp2 (SD, CPU, TRACE_FPU_IDX, (R0), (R1)); \
528 #define TRACE_FP_RESULT_BOOL(R0) \
530 if (TRACE_FPU_P (CPU)) \
531 trace_result_bool1 (SD, CPU, TRACE_FPU_IDX, (R0)); \
534 #define TRACE_FP_RESULT_WORD(R0) \
536 if (TRACE_FPU_P (CPU)) \
537 trace_result_word1 (SD, CPU, TRACE_FPU_IDX, (R0)); \
541 /* Macros for tracing branches */
543 #define TRACE_BRANCH_INPUT(COND) \
545 if (TRACE_BRANCH_P (CPU)) \
546 trace_input_bool1 (SD, CPU, TRACE_BRANCH_IDX, (COND)); \
549 #define TRACE_BRANCH_RESULT(DEST) \
551 if (TRACE_BRANCH_P (CPU)) \
552 trace_result_addr1 (SD, CPU, TRACE_BRANCH_IDX, (DEST)); \
556 /* The function trace_one_insn has been replaced by the function pair
557 trace_prefix() + trace_generic() */
558 extern void trace_one_insn (SIM_DESC sd,
562 const char *file_name,
567 __attribute__((format (printf, 8, 9)));
569 extern void trace_printf (SIM_DESC, sim_cpu *, const char *, ...)
570 __attribute__((format (printf, 3, 4)));
572 extern void trace_vprintf (SIM_DESC, sim_cpu *, const char *, va_list);
575 This is included here because there isn't enough of it to justify
578 /* Return non-zero if debugging of IDX for CPU is enabled. */
579 #define DEBUG_P(cpu, idx) \
580 ((WITH_DEBUG & (1 << (idx))) != 0 \
581 && CPU_DEBUG_FLAGS (cpu)[idx] != 0)
583 /* Non-zero if "--debug-insn" specified. */
584 #define DEBUG_INSN_P(cpu) DEBUG_P (cpu, DEBUG_INSN_IDX)
586 extern void debug_printf (sim_cpu *, const char *, ...)
587 __attribute__((format (printf, 2, 3)));
589 #endif /* SIM_TRACE_H */