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/>. */
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 (TRACE_insn | TRACE_linenum | TRACE_memory | TRACE_model)
92 /* Masks so WITH_TRACE can have symbolic values.
93 The case choice here is on purpose. The lowercase parts are args to
95 #define TRACE_insn (1 << TRACE_INSN_IDX)
96 #define TRACE_decode (1 << TRACE_DECODE_IDX)
97 #define TRACE_extract (1 << TRACE_EXTRACT_IDX)
98 #define TRACE_linenum (1 << TRACE_LINENUM_IDX)
99 #define TRACE_memory (1 << TRACE_MEMORY_IDX)
100 #define TRACE_model (1 << TRACE_MODEL_IDX)
101 #define TRACE_alu (1 << TRACE_ALU_IDX)
102 #define TRACE_core (1 << TRACE_CORE_IDX)
103 #define TRACE_events (1 << TRACE_EVENTS_IDX)
104 #define TRACE_fpu (1 << TRACE_FPU_IDX)
105 #define TRACE_vpu (1 << TRACE_VPU_IDX)
106 #define TRACE_branch (1 << TRACE_BRANCH_IDX)
107 #define TRACE_syscall (1 << TRACE_SYSCALL_IDX)
108 #define TRACE_debug (1 << TRACE_DEBUG_IDX)
110 /* Return non-zero if tracing of idx is enabled (compiled in). */
111 #define WITH_TRACE_P(idx) (WITH_TRACE & (1 << idx))
113 /* Preprocessor macros to simplify tests of WITH_TRACE. */
114 #define WITH_TRACE_ANY_P (WITH_TRACE)
115 #define WITH_TRACE_INSN_P WITH_TRACE_P (TRACE_INSN_IDX)
116 #define WITH_TRACE_DECODE_P WITH_TRACE_P (TRACE_DECODE_IDX)
117 #define WITH_TRACE_EXTRACT_P WITH_TRACE_P (TRACE_EXTRACT_IDX)
118 #define WITH_TRACE_LINENUM_P WITH_TRACE_P (TRACE_LINENUM_IDX)
119 #define WITH_TRACE_MEMORY_P WITH_TRACE_P (TRACE_MEMORY_IDX)
120 #define WITH_TRACE_MODEL_P WITH_TRACE_P (TRACE_MODEL_IDX)
121 #define WITH_TRACE_ALU_P WITH_TRACE_P (TRACE_ALU_IDX)
122 #define WITH_TRACE_CORE_P WITH_TRACE_P (TRACE_CORE_IDX)
123 #define WITH_TRACE_EVENTS_P WITH_TRACE_P (TRACE_EVENTS_IDX)
124 #define WITH_TRACE_FPU_P WITH_TRACE_P (TRACE_FPU_IDX)
125 #define WITH_TRACE_VPU_P WITH_TRACE_P (TRACE_VPU_IDX)
126 #define WITH_TRACE_BRANCH_P WITH_TRACE_P (TRACE_BRANCH_IDX)
127 #define WITH_TRACE_SYSCALL_P WITH_TRACE_P (TRACE_SYSCALL_IDX)
128 #define WITH_TRACE_DEBUG_P WITH_TRACE_P (TRACE_DEBUG_IDX)
130 /* Tracing install handler. */
131 MODULE_INSTALL_FN trace_install
;
133 /* Struct containing all system and cpu trace data.
135 System trace data is stored with the associated module.
136 System and cpu tracing must share the same space of bitmasks as they
137 are arguments to --with-trace. One could have --with-trace and
138 --with-cpu-trace or some such but that's an over-complication at this point
139 in time. Also, there may be occasions where system and cpu tracing may
140 wish to share a name. */
142 typedef struct _trace_data
{
144 /* Global summary of all the current trace options */
147 /* Boolean array of specified tracing flags. */
148 /* ??? It's not clear that using an array vs a bit mask is faster.
149 Consider the case where one wants to test whether any of several bits
151 char trace_flags
[MAX_TRACE_VALUES
];
152 #define TRACE_FLAGS(t) ((t)->trace_flags)
154 /* Tracing output goes to this or stderr if NULL.
155 We can't store `stderr' here as stderr goes through a callback. */
157 #define TRACE_FILE(t) ((t)->trace_file)
159 /* Buffer to store the prefix to be printed before any trace line. */
160 char trace_prefix
[256];
161 #define TRACE_PREFIX(t) ((t)->trace_prefix)
163 /* Buffer to save the inputs for the current instruction. Use a
164 union to force the buffer into correct alignment */
170 } trace_input_data
[16];
171 unsigned8 trace_input_fmt
[16];
172 unsigned8 trace_input_size
[16];
174 #define TRACE_INPUT_DATA(t) ((t)->trace_input_data)
175 #define TRACE_INPUT_FMT(t) ((t)->trace_input_fmt)
176 #define TRACE_INPUT_SIZE(t) ((t)->trace_input_size)
177 #define TRACE_INPUT_IDX(t) ((t)->trace_input_idx)
179 /* Category of trace being performed */
181 #define TRACE_IDX(t) ((t)->trace_idx)
184 ??? Not all cpu's support this. */
186 #define TRACE_RANGE(t) (& (t)->range)
189 /* System tracing support. */
191 #define STATE_TRACE_FLAGS(sd) TRACE_FLAGS (STATE_TRACE_DATA (sd))
193 /* Return non-zero if tracing of IDX is enabled for non-cpu specific
194 components. The "S" in "STRACE" refers to "System". */
195 #define STRACE_P(sd,idx) \
196 (WITH_TRACE_P (idx) && STATE_TRACE_FLAGS (sd)[idx] != 0)
198 /* Non-zero if --trace-<xxxx> was specified for SD. */
199 #define STRACE_ANY_P(sd) (WITH_TRACE_ANY_P && (STATE_TRACE_DATA (sd)->trace_any_p))
200 #define STRACE_INSN_P(sd) STRACE_P (sd, TRACE_INSN_IDX)
201 #define STRACE_DECODE_P(sd) STRACE_P (sd, TRACE_DECODE_IDX)
202 #define STRACE_EXTRACT_P(sd) STRACE_P (sd, TRACE_EXTRACT_IDX)
203 #define STRACE_LINENUM_P(sd) STRACE_P (sd, TRACE_LINENUM_IDX)
204 #define STRACE_MEMORY_P(sd) STRACE_P (sd, TRACE_MEMORY_IDX)
205 #define STRACE_MODEL_P(sd) STRACE_P (sd, TRACE_MODEL_IDX)
206 #define STRACE_ALU_P(sd) STRACE_P (sd, TRACE_ALU_IDX)
207 #define STRACE_CORE_P(sd) STRACE_P (sd, TRACE_CORE_IDX)
208 #define STRACE_EVENTS_P(sd) STRACE_P (sd, TRACE_EVENTS_IDX)
209 #define STRACE_FPU_P(sd) STRACE_P (sd, TRACE_FPU_IDX)
210 #define STRACE_VPU_P(sd) STRACE_P (sd, TRACE_VPU_IDX)
211 #define STRACE_BRANCH_P(sd) STRACE_P (sd, TRACE_BRANCH_IDX)
212 #define STRACE_SYSCALL_P(sd) STRACE_P (sd, TRACE_SYSCALL_IDX)
213 #define STRACE_DEBUG_P(sd) STRACE_P (sd, TRACE_DEBUG_IDX)
215 /* CPU tracing support. */
217 #define CPU_TRACE_FLAGS(cpu) TRACE_FLAGS (CPU_TRACE_DATA (cpu))
219 /* Return non-zero if tracing of IDX is enabled for CPU. */
220 #define TRACE_P(cpu,idx) \
221 (WITH_TRACE_P (idx) && CPU_TRACE_FLAGS (cpu)[idx] != 0)
223 /* Non-zero if --trace-<xxxx> was specified for CPU. */
224 #define TRACE_ANY_P(cpu) (WITH_TRACE_ANY_P && (CPU_TRACE_DATA (cpu)->trace_any_p))
225 #define TRACE_INSN_P(cpu) TRACE_P (cpu, TRACE_INSN_IDX)
226 #define TRACE_DECODE_P(cpu) TRACE_P (cpu, TRACE_DECODE_IDX)
227 #define TRACE_EXTRACT_P(cpu) TRACE_P (cpu, TRACE_EXTRACT_IDX)
228 #define TRACE_LINENUM_P(cpu) TRACE_P (cpu, TRACE_LINENUM_IDX)
229 #define TRACE_MEMORY_P(cpu) TRACE_P (cpu, TRACE_MEMORY_IDX)
230 #define TRACE_MODEL_P(cpu) TRACE_P (cpu, TRACE_MODEL_IDX)
231 #define TRACE_ALU_P(cpu) TRACE_P (cpu, TRACE_ALU_IDX)
232 #define TRACE_CORE_P(cpu) TRACE_P (cpu, TRACE_CORE_IDX)
233 #define TRACE_EVENTS_P(cpu) TRACE_P (cpu, TRACE_EVENTS_IDX)
234 #define TRACE_FPU_P(cpu) TRACE_P (cpu, TRACE_FPU_IDX)
235 #define TRACE_VPU_P(cpu) TRACE_P (cpu, TRACE_VPU_IDX)
236 #define TRACE_BRANCH_P(cpu) TRACE_P (cpu, TRACE_BRANCH_IDX)
237 #define TRACE_SYSCALL_P(cpu) TRACE_P (cpu, TRACE_SYSCALL_IDX)
238 #define TRACE_DEBUG_P(cpu) TRACE_P (cpu, TRACE_DEBUG_IDX)
240 /* Tracing functions. */
242 /* Prime the trace buffers ready for any trace output.
243 Must be called prior to any other trace operation */
244 extern void trace_prefix (SIM_DESC sd
,
249 const char *file_name
,
253 __attribute__((format (printf
, 8, 9)));
255 /* Generic trace print, assumes trace_prefix() has been called */
257 extern void trace_generic (SIM_DESC sd
,
262 __attribute__((format (printf
, 4, 5)));
272 trace_fmt_instruction_incomplete
,
275 /* Trace a varying number of word sized inputs/outputs. trace_result*
276 must be called to close the trace operation. */
278 extern void save_data (SIM_DESC sd
,
284 extern void trace_input0 (SIM_DESC sd
,
288 extern void trace_input_word1 (SIM_DESC sd
,
293 extern void trace_input_word2 (SIM_DESC sd
,
299 extern void trace_input_word3 (SIM_DESC sd
,
306 extern void trace_input_word4 (SIM_DESC sd
,
314 extern void trace_input_addr1 (SIM_DESC sd
,
319 extern void trace_input_bool1 (SIM_DESC sd
,
324 extern void trace_input_fp1 (SIM_DESC sd
,
329 extern void trace_input_fp2 (SIM_DESC sd
,
335 extern void trace_input_fp3 (SIM_DESC sd
,
342 extern void trace_input_fpu1 (SIM_DESC sd
,
345 struct _sim_fpu
*f0
);
347 extern void trace_input_fpu2 (SIM_DESC sd
,
351 struct _sim_fpu
*f1
);
353 extern void trace_input_fpu3 (SIM_DESC sd
,
358 struct _sim_fpu
*f2
);
360 /* Other trace_input{_<fmt><nr-inputs>} functions can go here */
362 extern void trace_result0 (SIM_DESC sd
,
366 extern void trace_result_word1 (SIM_DESC sd
,
371 extern void trace_result_word2 (SIM_DESC sd
,
377 extern void trace_result_word4 (SIM_DESC sd
,
385 extern void trace_result_bool1 (SIM_DESC sd
,
390 extern void trace_result_addr1 (SIM_DESC sd
,
395 extern void trace_result_fp1 (SIM_DESC sd
,
400 extern void trace_result_fp2 (SIM_DESC sd
,
406 extern void trace_result_fpu1 (SIM_DESC sd
,
409 struct _sim_fpu
*f0
);
411 extern void trace_result_string1 (SIM_DESC sd
,
416 extern void trace_result_word1_string1 (SIM_DESC sd
,
422 /* Other trace_result{_<type><nr-results>} */
425 /* Macros for tracing ALU instructions */
427 #define TRACE_ALU_INPUT0() \
429 if (TRACE_ALU_P (CPU)) \
430 trace_input0 (SD, CPU, TRACE_ALU_IDX); \
433 #define TRACE_ALU_INPUT1(V0) \
435 if (TRACE_ALU_P (CPU)) \
436 trace_input_word1 (SD, CPU, TRACE_ALU_IDX, (V0)); \
439 #define TRACE_ALU_INPUT2(V0,V1) \
441 if (TRACE_ALU_P (CPU)) \
442 trace_input_word2 (SD, CPU, TRACE_ALU_IDX, (V0), (V1)); \
445 #define TRACE_ALU_INPUT3(V0,V1,V2) \
447 if (TRACE_ALU_P (CPU)) \
448 trace_input_word3 (SD, CPU, TRACE_ALU_IDX, (V0), (V1), (V2)); \
451 #define TRACE_ALU_INPUT4(V0,V1,V2,V3) \
453 if (TRACE_ALU_P (CPU)) \
454 trace_input_word4 (SD, CPU, TRACE_ALU_IDX, (V0), (V1), (V2), (V3)); \
457 #define TRACE_ALU_RESULT(R0) TRACE_ALU_RESULT1(R0)
459 #define TRACE_ALU_RESULT0() \
461 if (TRACE_ALU_P (CPU)) \
462 trace_result0 (SD, CPU, TRACE_ALU_IDX); \
465 #define TRACE_ALU_RESULT1(R0) \
467 if (TRACE_ALU_P (CPU)) \
468 trace_result_word1 (SD, CPU, TRACE_ALU_IDX, (R0)); \
471 #define TRACE_ALU_RESULT2(R0,R1) \
473 if (TRACE_ALU_P (CPU)) \
474 trace_result_word2 (SD, CPU, TRACE_ALU_IDX, (R0), (R1)); \
477 #define TRACE_ALU_RESULT4(R0,R1,R2,R3) \
479 if (TRACE_ALU_P (CPU)) \
480 trace_result_word4 (SD, CPU, TRACE_ALU_IDX, (R0), (R1), (R2), (R3)); \
483 /* Macros for tracing inputs to comparative branch instructions. */
485 #define TRACE_BRANCH_INPUT1(V0) \
487 if (TRACE_BRANCH_P (CPU)) \
488 trace_input_word1 (SD, CPU, TRACE_BRANCH_IDX, (V0)); \
491 #define TRACE_BRANCH_INPUT2(V0,V1) \
493 if (TRACE_BRANCH_P (CPU)) \
494 trace_input_word2 (SD, CPU, TRACE_BRANCH_IDX, (V0), (V1)); \
497 /* Macros for tracing FPU instructions */
499 #define TRACE_FP_INPUT0() \
501 if (TRACE_FPU_P (CPU)) \
502 trace_input0 (SD, CPU, TRACE_FPU_IDX); \
505 #define TRACE_FP_INPUT1(V0) \
507 if (TRACE_FPU_P (CPU)) \
508 trace_input_fp1 (SD, CPU, TRACE_FPU_IDX, (V0)); \
511 #define TRACE_FP_INPUT2(V0,V1) \
513 if (TRACE_FPU_P (CPU)) \
514 trace_input_fp2 (SD, CPU, TRACE_FPU_IDX, (V0), (V1)); \
517 #define TRACE_FP_INPUT3(V0,V1,V2) \
519 if (TRACE_FPU_P (CPU)) \
520 trace_input_fp3 (SD, CPU, TRACE_FPU_IDX, (V0), (V1), (V2)); \
523 #define TRACE_FP_INPUT_WORD1(V0) \
525 if (TRACE_FPU_P (CPU)) \
526 trace_input_word1 (SD, CPU, TRACE_FPU_IDX, (V0)); \
529 #define TRACE_FP_RESULT(R0) \
531 if (TRACE_FPU_P (CPU)) \
532 trace_result_fp1 (SD, CPU, TRACE_FPU_IDX, (R0)); \
535 #define TRACE_FP_RESULT2(R0,R1) \
537 if (TRACE_FPU_P (CPU)) \
538 trace_result_fp2 (SD, CPU, TRACE_FPU_IDX, (R0), (R1)); \
541 #define TRACE_FP_RESULT_BOOL(R0) \
543 if (TRACE_FPU_P (CPU)) \
544 trace_result_bool1 (SD, CPU, TRACE_FPU_IDX, (R0)); \
547 #define TRACE_FP_RESULT_WORD(R0) \
549 if (TRACE_FPU_P (CPU)) \
550 trace_result_word1 (SD, CPU, TRACE_FPU_IDX, (R0)); \
554 /* Macros for tracing branches */
556 #define TRACE_BRANCH_INPUT(COND) \
558 if (TRACE_BRANCH_P (CPU)) \
559 trace_input_bool1 (SD, CPU, TRACE_BRANCH_IDX, (COND)); \
562 #define TRACE_BRANCH_RESULT(DEST) \
564 if (TRACE_BRANCH_P (CPU)) \
565 trace_result_addr1 (SD, CPU, TRACE_BRANCH_IDX, (DEST)); \
569 /* The function trace_one_insn has been replaced by the function pair
570 trace_prefix() + trace_generic() */
571 extern void trace_one_insn (SIM_DESC sd
,
575 const char *file_name
,
580 __attribute__((format (printf
, 8, 9)));
582 extern void trace_printf (SIM_DESC
, sim_cpu
*, const char *, ...)
583 __attribute__((format (printf
, 3, 4)));
585 extern void trace_vprintf (SIM_DESC
, sim_cpu
*, const char *, va_list);
588 This is included here because there isn't enough of it to justify
591 /* Return non-zero if debugging of IDX for CPU is enabled. */
592 #define DEBUG_P(cpu, idx) \
593 ((WITH_DEBUG & (1 << (idx))) != 0 \
594 && CPU_DEBUG_FLAGS (cpu)[idx] != 0)
596 /* Non-zero if "--debug-insn" specified. */
597 #define DEBUG_INSN_P(cpu) DEBUG_P (cpu, DEBUG_INSN_IDX)
599 /* GDB also has a debug_printf, so we shadow ours. */
600 #define debug_printf sim_debug_printf
602 extern void debug_printf (sim_cpu
*, const char *, ...)
603 __attribute__((format (printf
, 2, 3)));
605 #endif /* SIM_TRACE_H */