1 /* Simulator tracing/debugging support.
2 Copyright (C) 1997-1998, 2001, 2007-2012 Free Software Foundation,
4 Contributed by Cygnus Support.
6 This file is part of GDB, the GNU debugger.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 /* This file is meant to be included by sim-basics.h. */
26 /* Standard traceable entities. */
29 /* Trace insn execution. */
32 /* Trace insn decoding.
33 ??? This is more of a simulator debugging operation and might best be
34 moved to --debug-decode. */
37 /* Trace insn extraction.
38 ??? This is more of a simulator debugging operation and might best be
39 moved to --debug-extract. */
42 /* Trace insn execution but include line numbers. */
45 /* Trace memory operations.
46 The difference between this and TRACE_CORE_IDX is (I think) that this
47 is intended to apply to a higher level. TRACE_CORE_IDX applies to the
48 low level core operations. */
51 /* Include model performance data in tracing output. */
54 /* Trace ALU operations. */
57 /* Trace memory core operations. */
63 /* Trace fpu operations. */
66 /* Trace vpu operations. */
69 /* Trace branching. */
75 /* Add information useful for debugging the simulator to trace output. */
78 /* Simulator specific trace bits begin here. */
82 /* Maximum number of traceable entities. */
83 #ifndef MAX_TRACE_VALUES
84 #define MAX_TRACE_VALUES 32
87 /* The -t option only prints useful values. It's easy to type and shouldn't
88 splat on the screen everything under the sun making nothing easy to
90 #define TRACE_USEFUL_MASK \
91 ((1 << TRACE_INSN_IDX) \
92 | (1 << TRACE_LINENUM_IDX) \
93 | (1 << TRACE_MEMORY_IDX) \
94 | (1 << TRACE_MODEL_IDX))
96 /* Masks so WITH_TRACE can have symbolic values.
97 The case choice here is on purpose. The lowercase parts are args to
99 #define TRACE_insn (1 << TRACE_INSN_IDX)
100 #define TRACE_decode (1 << TRACE_DECODE_IDX)
101 #define TRACE_extract (1 << TRACE_EXTRACT_IDX)
102 #define TRACE_linenum (1 << TRACE_LINENUM_IDX)
103 #define TRACE_memory (1 << TRACE_MEMORY_IDX)
104 #define TRACE_model (1 << TRACE_MODEL_IDX)
105 #define TRACE_alu (1 << TRACE_ALU_IDX)
106 #define TRACE_core (1 << TRACE_CORE_IDX)
107 #define TRACE_events (1 << TRACE_EVENTS_IDX)
108 #define TRACE_fpu (1 << TRACE_FPU_IDX)
109 #define TRACE_vpu (1 << TRACE_VPU_IDX)
110 #define TRACE_branch (1 << TRACE_BRANCH_IDX)
111 #define TRACE_syscall (1 << TRACE_SYSCALL_IDX)
112 #define TRACE_debug (1 << TRACE_DEBUG_IDX)
114 /* Preprocessor macros to simplify tests of WITH_TRACE. */
115 #define WITH_TRACE_INSN_P (WITH_TRACE & TRACE_insn)
116 #define WITH_TRACE_DECODE_P (WITH_TRACE & TRACE_decode)
117 #define WITH_TRACE_EXTRACT_P (WITH_TRACE & TRACE_extract)
118 #define WITH_TRACE_LINENUM_P (WITH_TRACE & TRACE_linenum)
119 #define WITH_TRACE_MEMORY_P (WITH_TRACE & TRACE_memory)
120 #define WITH_TRACE_MODEL_P (WITH_TRACE & TRACE_model)
121 #define WITH_TRACE_ALU_P (WITH_TRACE & TRACE_alu)
122 #define WITH_TRACE_CORE_P (WITH_TRACE & TRACE_core)
123 #define WITH_TRACE_EVENTS_P (WITH_TRACE & TRACE_events)
124 #define WITH_TRACE_FPU_P (WITH_TRACE & TRACE_fpu)
125 #define WITH_TRACE_VPU_P (WITH_TRACE & TRACE_vpu)
126 #define WITH_TRACE_BRANCH_P (WITH_TRACE & TRACE_branch)
127 #define WITH_TRACE_SYSCALL_P (WITH_TRACE & TRACE_syscall)
128 #define WITH_TRACE_DEBUG_P (WITH_TRACE & TRACE_debug)
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 & (1 << (idx))) != 0 \
197 && STATE_TRACE_FLAGS (sd)[idx] != 0)
199 /* Non-zero if --trace-<xxxx> was specified for SD. */
200 #define STRACE_DEBUG_P(sd) STRACE_P (sd, TRACE_DEBUG_IDX)
202 /* CPU tracing support. */
204 #define CPU_TRACE_FLAGS(cpu) TRACE_FLAGS (CPU_TRACE_DATA (cpu))
206 /* Return non-zero if tracing of IDX is enabled for CPU. */
207 #define TRACE_P(cpu,idx) \
208 ((WITH_TRACE & (1 << (idx))) != 0 \
209 && CPU_TRACE_FLAGS (cpu)[idx] != 0)
211 /* Non-zero if --trace-<xxxx> was specified for CPU. */
212 #define TRACE_ANY_P(cpu) ((WITH_TRACE) && (CPU_TRACE_DATA (cpu)->trace_any_p))
213 #define TRACE_INSN_P(cpu) TRACE_P (cpu, TRACE_INSN_IDX)
214 #define TRACE_DECODE_P(cpu) TRACE_P (cpu, TRACE_DECODE_IDX)
215 #define TRACE_EXTRACT_P(cpu) TRACE_P (cpu, TRACE_EXTRACT_IDX)
216 #define TRACE_LINENUM_P(cpu) TRACE_P (cpu, TRACE_LINENUM_IDX)
217 #define TRACE_MEMORY_P(cpu) TRACE_P (cpu, TRACE_MEMORY_IDX)
218 #define TRACE_MODEL_P(cpu) TRACE_P (cpu, TRACE_MODEL_IDX)
219 #define TRACE_ALU_P(cpu) TRACE_P (cpu, TRACE_ALU_IDX)
220 #define TRACE_CORE_P(cpu) TRACE_P (cpu, TRACE_CORE_IDX)
221 #define TRACE_EVENTS_P(cpu) TRACE_P (cpu, TRACE_EVENTS_IDX)
222 #define TRACE_FPU_P(cpu) TRACE_P (cpu, TRACE_FPU_IDX)
223 #define TRACE_VPU_P(cpu) TRACE_P (cpu, TRACE_VPU_IDX)
224 #define TRACE_BRANCH_P(cpu) TRACE_P (cpu, TRACE_BRANCH_IDX)
225 #define TRACE_SYSCALL_P(cpu) TRACE_P (cpu, TRACE_SYSCALL_IDX)
226 #define TRACE_DEBUG_P(cpu) TRACE_P (cpu, TRACE_DEBUG_IDX)
228 /* Tracing functions. */
230 /* Prime the trace buffers ready for any trace output.
231 Must be called prior to any other trace operation */
232 extern void trace_prefix
PARAMS ((SIM_DESC sd
,
237 const char *file_name
,
241 __attribute__((format (printf
, 8, 9)));
243 /* Generic trace print, assumes trace_prefix() has been called */
245 extern void trace_generic
PARAMS ((SIM_DESC sd
,
250 __attribute__((format (printf
, 4, 5)));
260 trace_fmt_instruction_incomplete
,
263 /* Trace a varying number of word sized inputs/outputs. trace_result*
264 must be called to close the trace operation. */
266 extern void save_data
PARAMS ((SIM_DESC sd
,
272 extern void trace_input0
PARAMS ((SIM_DESC sd
,
276 extern void trace_input_word1
PARAMS ((SIM_DESC sd
,
281 extern void trace_input_word2
PARAMS ((SIM_DESC sd
,
287 extern void trace_input_word3
PARAMS ((SIM_DESC sd
,
294 extern void trace_input_word4
PARAMS ((SIM_DESC sd
,
302 extern void trace_input_addr1
PARAMS ((SIM_DESC sd
,
307 extern void trace_input_bool1
PARAMS ((SIM_DESC sd
,
312 extern void trace_input_fp1
PARAMS ((SIM_DESC sd
,
317 extern void trace_input_fp2
PARAMS ((SIM_DESC sd
,
323 extern void trace_input_fp3
PARAMS ((SIM_DESC sd
,
330 extern void trace_input_fpu1
PARAMS ((SIM_DESC sd
,
333 struct _sim_fpu
*f0
));
335 extern void trace_input_fpu2
PARAMS ((SIM_DESC sd
,
339 struct _sim_fpu
*f1
));
341 extern void trace_input_fpu3
PARAMS ((SIM_DESC sd
,
346 struct _sim_fpu
*f2
));
348 /* Other trace_input{_<fmt><nr-inputs>} functions can go here */
350 extern void trace_result0
PARAMS ((SIM_DESC sd
,
354 extern void trace_result_word1
PARAMS ((SIM_DESC sd
,
359 extern void trace_result_word2
PARAMS ((SIM_DESC sd
,
365 extern void trace_result_word4
PARAMS ((SIM_DESC sd
,
373 extern void trace_result_bool1
PARAMS ((SIM_DESC sd
,
378 extern void trace_result_addr1
PARAMS ((SIM_DESC sd
,
383 extern void trace_result_fp1
PARAMS ((SIM_DESC sd
,
388 extern void trace_result_fp2
PARAMS ((SIM_DESC sd
,
394 extern void trace_result_fpu1
PARAMS ((SIM_DESC sd
,
397 struct _sim_fpu
*f0
));
399 extern void trace_result_string1
PARAMS ((SIM_DESC sd
,
404 extern void trace_result_word1_string1
PARAMS ((SIM_DESC sd
,
410 /* Other trace_result{_<type><nr-results>} */
413 /* Macros for tracing ALU instructions */
415 #define TRACE_ALU_INPUT0() \
417 if (TRACE_ALU_P (CPU)) \
418 trace_input0 (SD, CPU, TRACE_ALU_IDX); \
421 #define TRACE_ALU_INPUT1(V0) \
423 if (TRACE_ALU_P (CPU)) \
424 trace_input_word1 (SD, CPU, TRACE_ALU_IDX, (V0)); \
427 #define TRACE_ALU_INPUT2(V0,V1) \
429 if (TRACE_ALU_P (CPU)) \
430 trace_input_word2 (SD, CPU, TRACE_ALU_IDX, (V0), (V1)); \
433 #define TRACE_ALU_INPUT3(V0,V1,V2) \
435 if (TRACE_ALU_P (CPU)) \
436 trace_input_word3 (SD, CPU, TRACE_ALU_IDX, (V0), (V1), (V2)); \
439 #define TRACE_ALU_INPUT4(V0,V1,V2,V3) \
441 if (TRACE_ALU_P (CPU)) \
442 trace_input_word4 (SD, CPU, TRACE_ALU_IDX, (V0), (V1), (V2), (V3)); \
445 #define TRACE_ALU_RESULT(R0) TRACE_ALU_RESULT1(R0)
447 #define TRACE_ALU_RESULT0() \
449 if (TRACE_ALU_P (CPU)) \
450 trace_result0 (SD, CPU, TRACE_ALU_IDX); \
453 #define TRACE_ALU_RESULT1(R0) \
455 if (TRACE_ALU_P (CPU)) \
456 trace_result_word1 (SD, CPU, TRACE_ALU_IDX, (R0)); \
459 #define TRACE_ALU_RESULT2(R0,R1) \
461 if (TRACE_ALU_P (CPU)) \
462 trace_result_word2 (SD, CPU, TRACE_ALU_IDX, (R0), (R1)); \
465 #define TRACE_ALU_RESULT4(R0,R1,R2,R3) \
467 if (TRACE_ALU_P (CPU)) \
468 trace_result_word4 (SD, CPU, TRACE_ALU_IDX, (R0), (R1), (R2), (R3)); \
471 /* Macros for tracing inputs to comparative branch instructions. */
473 #define TRACE_BRANCH_INPUT1(V0) \
475 if (TRACE_BRANCH_P (CPU)) \
476 trace_input_word1 (SD, CPU, TRACE_BRANCH_IDX, (V0)); \
479 #define TRACE_BRANCH_INPUT2(V0,V1) \
481 if (TRACE_BRANCH_P (CPU)) \
482 trace_input_word2 (SD, CPU, TRACE_BRANCH_IDX, (V0), (V1)); \
485 /* Macros for tracing FPU instructions */
487 #define TRACE_FP_INPUT0() \
489 if (TRACE_FPU_P (CPU)) \
490 trace_input0 (SD, CPU, TRACE_FPU_IDX); \
493 #define TRACE_FP_INPUT1(V0) \
495 if (TRACE_FPU_P (CPU)) \
496 trace_input_fp1 (SD, CPU, TRACE_FPU_IDX, (V0)); \
499 #define TRACE_FP_INPUT2(V0,V1) \
501 if (TRACE_FPU_P (CPU)) \
502 trace_input_fp2 (SD, CPU, TRACE_FPU_IDX, (V0), (V1)); \
505 #define TRACE_FP_INPUT3(V0,V1,V2) \
507 if (TRACE_FPU_P (CPU)) \
508 trace_input_fp3 (SD, CPU, TRACE_FPU_IDX, (V0), (V1), (V2)); \
511 #define TRACE_FP_INPUT_WORD1(V0) \
513 if (TRACE_FPU_P (CPU)) \
514 trace_input_word1 (SD, CPU, TRACE_FPU_IDX, (V0)); \
517 #define TRACE_FP_RESULT(R0) \
519 if (TRACE_FPU_P (CPU)) \
520 trace_result_fp1 (SD, CPU, TRACE_FPU_IDX, (R0)); \
523 #define TRACE_FP_RESULT2(R0,R1) \
525 if (TRACE_FPU_P (CPU)) \
526 trace_result_fp2 (SD, CPU, TRACE_FPU_IDX, (R0), (R1)); \
529 #define TRACE_FP_RESULT_BOOL(R0) \
531 if (TRACE_FPU_P (CPU)) \
532 trace_result_bool1 (SD, CPU, TRACE_FPU_IDX, (R0)); \
535 #define TRACE_FP_RESULT_WORD(R0) \
537 if (TRACE_FPU_P (CPU)) \
538 trace_result_word1 (SD, CPU, TRACE_FPU_IDX, (R0)); \
542 /* Macros for tracing branches */
544 #define TRACE_BRANCH_INPUT(COND) \
546 if (TRACE_BRANCH_P (CPU)) \
547 trace_input_bool1 (SD, CPU, TRACE_BRANCH_IDX, (COND)); \
550 #define TRACE_BRANCH_RESULT(DEST) \
552 if (TRACE_BRANCH_P (CPU)) \
553 trace_result_addr1 (SD, CPU, TRACE_BRANCH_IDX, (DEST)); \
557 /* The function trace_one_insn has been replaced by the function pair
558 trace_prefix() + trace_generic() */
559 extern void trace_one_insn
PARAMS ((SIM_DESC sd
,
563 const char *file_name
,
568 __attribute__((format (printf
, 8, 9)));
570 extern void trace_printf
PARAMS ((SIM_DESC
, sim_cpu
*, const char *, ...))
571 __attribute__((format (printf
, 3, 4)));
573 extern void trace_vprintf
PARAMS ((SIM_DESC
, sim_cpu
*, const char *, va_list));
576 This is included here because there isn't enough of it to justify
579 /* Return non-zero if debugging of IDX for CPU is enabled. */
580 #define DEBUG_P(cpu, idx) \
581 ((WITH_DEBUG & (1 << (idx))) != 0 \
582 && CPU_DEBUG_FLAGS (cpu)[idx] != 0)
584 /* Non-zero if "--debug-insn" specified. */
585 #define DEBUG_INSN_P(cpu) DEBUG_P (cpu, DEBUG_INSN_IDX)
587 extern void debug_printf
PARAMS ((sim_cpu
*, const char *, ...))
588 __attribute__((format (printf
, 2, 3)));
590 #endif /* SIM_TRACE_H */