1 /* Simulator tracing/debugging support.
2 Copyright (C) 1997, 1998, 2001, 2007 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. */
71 /* Add information useful for debugging the simulator to trace output. */
74 /* Simulator specific trace bits begin here. */
78 /* Maximum number of traceable entities. */
79 #ifndef MAX_TRACE_VALUES
80 #define MAX_TRACE_VALUES 32
83 /* The -t option only prints useful values. It's easy to type and shouldn't
84 splat on the screen everything under the sun making nothing easy to
86 #define TRACE_USEFUL_MASK \
87 ((1 << TRACE_INSN_IDX) \
88 | (1 << TRACE_LINENUM_IDX) \
89 | (1 << TRACE_MEMORY_IDX) \
90 | (1 << TRACE_MODEL_IDX))
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_debug (1 << TRACE_DEBUG_IDX)
109 /* Preprocessor macros to simplify tests of WITH_TRACE. */
110 #define WITH_TRACE_INSN_P (WITH_TRACE & TRACE_insn)
111 #define WITH_TRACE_DECODE_P (WITH_TRACE & TRACE_decode)
112 #define WITH_TRACE_EXTRACT_P (WITH_TRACE & TRACE_extract)
113 #define WITH_TRACE_LINENUM_P (WITH_TRACE & TRACE_linenum)
114 #define WITH_TRACE_MEMORY_P (WITH_TRACE & TRACE_memory)
115 #define WITH_TRACE_MODEL_P (WITH_TRACE & TRACE_model)
116 #define WITH_TRACE_ALU_P (WITH_TRACE & TRACE_alu)
117 #define WITH_TRACE_CORE_P (WITH_TRACE & TRACE_core)
118 #define WITH_TRACE_EVENTS_P (WITH_TRACE & TRACE_events)
119 #define WITH_TRACE_FPU_P (WITH_TRACE & TRACE_fpu)
120 #define WITH_TRACE_VPU_P (WITH_TRACE & TRACE_vpu)
121 #define WITH_TRACE_BRANCH_P (WITH_TRACE & TRACE_branch)
122 #define WITH_TRACE_DEBUG_P (WITH_TRACE & TRACE_debug)
124 /* Tracing install handler. */
125 MODULE_INSTALL_FN trace_install
;
127 /* Struct containing all system and cpu trace data.
129 System trace data is stored with the associated module.
130 System and cpu tracing must share the same space of bitmasks as they
131 are arguments to --with-trace. One could have --with-trace and
132 --with-cpu-trace or some such but that's an over-complication at this point
133 in time. Also, there may be occasions where system and cpu tracing may
134 wish to share a name. */
136 typedef struct _trace_data
{
138 /* Global summary of all the current trace options */
141 /* Boolean array of specified tracing flags. */
142 /* ??? It's not clear that using an array vs a bit mask is faster.
143 Consider the case where one wants to test whether any of several bits
145 char trace_flags
[MAX_TRACE_VALUES
];
146 #define TRACE_FLAGS(t) ((t)->trace_flags)
148 /* Tracing output goes to this or stderr if NULL.
149 We can't store `stderr' here as stderr goes through a callback. */
151 #define TRACE_FILE(t) ((t)->trace_file)
153 /* Buffer to store the prefix to be printed before any trace line. */
154 char trace_prefix
[256];
155 #define TRACE_PREFIX(t) ((t)->trace_prefix)
157 /* Buffer to save the inputs for the current instruction. Use a
158 union to force the buffer into correct alignment */
164 } trace_input_data
[16];
165 unsigned8 trace_input_fmt
[16];
166 unsigned8 trace_input_size
[16];
168 #define TRACE_INPUT_DATA(t) ((t)->trace_input_data)
169 #define TRACE_INPUT_FMT(t) ((t)->trace_input_fmt)
170 #define TRACE_INPUT_SIZE(t) ((t)->trace_input_size)
171 #define TRACE_INPUT_IDX(t) ((t)->trace_input_idx)
173 /* Category of trace being performed */
175 #define TRACE_IDX(t) ((t)->trace_idx)
178 ??? Not all cpu's support this. */
180 #define TRACE_RANGE(t) (& (t)->range)
183 /* System tracing support. */
185 #define STATE_TRACE_FLAGS(sd) TRACE_FLAGS (STATE_TRACE_DATA (sd))
187 /* Return non-zero if tracing of IDX is enabled for non-cpu specific
188 components. The "S" in "STRACE" refers to "System". */
189 #define STRACE_P(sd,idx) \
190 ((WITH_TRACE & (1 << (idx))) != 0 \
191 && STATE_TRACE_FLAGS (sd)[idx] != 0)
193 /* Non-zero if --trace-<xxxx> was specified for SD. */
194 #define STRACE_DEBUG_P(sd) STRACE_P (sd, TRACE_DEBUG_IDX)
196 /* CPU tracing support. */
198 #define CPU_TRACE_FLAGS(cpu) TRACE_FLAGS (CPU_TRACE_DATA (cpu))
200 /* Return non-zero if tracing of IDX is enabled for CPU. */
201 #define TRACE_P(cpu,idx) \
202 ((WITH_TRACE & (1 << (idx))) != 0 \
203 && CPU_TRACE_FLAGS (cpu)[idx] != 0)
205 /* Non-zero if --trace-<xxxx> was specified for CPU. */
206 #define TRACE_ANY_P(cpu) ((WITH_TRACE) && (CPU_TRACE_DATA (cpu)->trace_any_p))
207 #define TRACE_INSN_P(cpu) TRACE_P (cpu, TRACE_INSN_IDX)
208 #define TRACE_DECODE_P(cpu) TRACE_P (cpu, TRACE_DECODE_IDX)
209 #define TRACE_EXTRACT_P(cpu) TRACE_P (cpu, TRACE_EXTRACT_IDX)
210 #define TRACE_LINENUM_P(cpu) TRACE_P (cpu, TRACE_LINENUM_IDX)
211 #define TRACE_MEMORY_P(cpu) TRACE_P (cpu, TRACE_MEMORY_IDX)
212 #define TRACE_MODEL_P(cpu) TRACE_P (cpu, TRACE_MODEL_IDX)
213 #define TRACE_ALU_P(cpu) TRACE_P (cpu, TRACE_ALU_IDX)
214 #define TRACE_CORE_P(cpu) TRACE_P (cpu, TRACE_CORE_IDX)
215 #define TRACE_EVENTS_P(cpu) TRACE_P (cpu, TRACE_EVENTS_IDX)
216 #define TRACE_FPU_P(cpu) TRACE_P (cpu, TRACE_FPU_IDX)
217 #define TRACE_VPU_P(cpu) TRACE_P (cpu, TRACE_VPU_IDX)
218 #define TRACE_BRANCH_P(cpu) TRACE_P (cpu, TRACE_BRANCH_IDX)
219 #define TRACE_DEBUG_P(cpu) TRACE_P (cpu, TRACE_DEBUG_IDX)
221 /* Tracing functions. */
223 /* Prime the trace buffers ready for any trace output.
224 Must be called prior to any other trace operation */
225 extern void trace_prefix
PARAMS ((SIM_DESC sd
,
230 const char *file_name
,
234 __attribute__((format (printf
, 8, 9)));
236 /* Generic trace print, assumes trace_prefix() has been called */
238 extern void trace_generic
PARAMS ((SIM_DESC sd
,
243 __attribute__((format (printf
, 4, 5)));
245 /* Trace a varying number of word sized inputs/outputs. trace_result*
246 must be called to close the trace operation. */
248 extern void trace_input0
PARAMS ((SIM_DESC sd
,
252 extern void trace_input_word1
PARAMS ((SIM_DESC sd
,
257 extern void trace_input_word2
PARAMS ((SIM_DESC sd
,
263 extern void trace_input_word3
PARAMS ((SIM_DESC sd
,
270 extern void trace_input_word4
PARAMS ((SIM_DESC sd
,
278 extern void trace_input_addr1
PARAMS ((SIM_DESC sd
,
283 extern void trace_input_bool1
PARAMS ((SIM_DESC sd
,
288 extern void trace_input_fp1
PARAMS ((SIM_DESC sd
,
293 extern void trace_input_fp2
PARAMS ((SIM_DESC sd
,
299 extern void trace_input_fp3
PARAMS ((SIM_DESC sd
,
306 extern void trace_input_fpu1
PARAMS ((SIM_DESC sd
,
309 struct _sim_fpu
*f0
));
311 extern void trace_input_fpu2
PARAMS ((SIM_DESC sd
,
315 struct _sim_fpu
*f1
));
317 extern void trace_input_fpu3
PARAMS ((SIM_DESC sd
,
322 struct _sim_fpu
*f2
));
324 /* Other trace_input{_<fmt><nr-inputs>} functions can go here */
326 extern void trace_result0
PARAMS ((SIM_DESC sd
,
330 extern void trace_result_word1
PARAMS ((SIM_DESC sd
,
335 extern void trace_result_word2
PARAMS ((SIM_DESC sd
,
341 extern void trace_result_word4
PARAMS ((SIM_DESC sd
,
349 extern void trace_result_bool1
PARAMS ((SIM_DESC sd
,
354 extern void trace_result_addr1
PARAMS ((SIM_DESC sd
,
359 extern void trace_result_fp1
PARAMS ((SIM_DESC sd
,
364 extern void trace_result_fp2
PARAMS ((SIM_DESC sd
,
370 extern void trace_result_fpu1
PARAMS ((SIM_DESC sd
,
373 struct _sim_fpu
*f0
));
375 extern void trace_result_string1
PARAMS ((SIM_DESC sd
,
380 extern void trace_result_word1_string1
PARAMS ((SIM_DESC sd
,
386 /* Other trace_result{_<type><nr-results>} */
389 /* Macros for tracing ALU instructions */
391 #define TRACE_ALU_INPUT0() \
393 if (TRACE_ALU_P (CPU)) \
394 trace_input0 (SD, CPU, TRACE_ALU_IDX); \
397 #define TRACE_ALU_INPUT1(V0) \
399 if (TRACE_ALU_P (CPU)) \
400 trace_input_word1 (SD, CPU, TRACE_ALU_IDX, (V0)); \
403 #define TRACE_ALU_INPUT2(V0,V1) \
405 if (TRACE_ALU_P (CPU)) \
406 trace_input_word2 (SD, CPU, TRACE_ALU_IDX, (V0), (V1)); \
409 #define TRACE_ALU_INPUT3(V0,V1,V2) \
411 if (TRACE_ALU_P (CPU)) \
412 trace_input_word3 (SD, CPU, TRACE_ALU_IDX, (V0), (V1), (V2)); \
415 #define TRACE_ALU_INPUT4(V0,V1,V2,V3) \
417 if (TRACE_ALU_P (CPU)) \
418 trace_input_word4 (SD, CPU, TRACE_ALU_IDX, (V0), (V1), (V2), (V3)); \
421 #define TRACE_ALU_RESULT(R0) TRACE_ALU_RESULT1(R0)
423 #define TRACE_ALU_RESULT0() \
425 if (TRACE_ALU_P (CPU)) \
426 trace_result0 (SD, CPU, TRACE_ALU_IDX); \
429 #define TRACE_ALU_RESULT1(R0) \
431 if (TRACE_ALU_P (CPU)) \
432 trace_result_word1 (SD, CPU, TRACE_ALU_IDX, (R0)); \
435 #define TRACE_ALU_RESULT2(R0,R1) \
437 if (TRACE_ALU_P (CPU)) \
438 trace_result_word2 (SD, CPU, TRACE_ALU_IDX, (R0), (R1)); \
441 #define TRACE_ALU_RESULT4(R0,R1,R2,R3) \
443 if (TRACE_ALU_P (CPU)) \
444 trace_result_word4 (SD, CPU, TRACE_ALU_IDX, (R0), (R1), (R2), (R3)); \
447 /* Macros for tracing inputs to comparative branch instructions. */
449 #define TRACE_BRANCH_INPUT1(V0) \
451 if (TRACE_BRANCH_P (CPU)) \
452 trace_input_word1 (SD, CPU, TRACE_BRANCH_IDX, (V0)); \
455 #define TRACE_BRANCH_INPUT2(V0,V1) \
457 if (TRACE_BRANCH_P (CPU)) \
458 trace_input_word2 (SD, CPU, TRACE_BRANCH_IDX, (V0), (V1)); \
461 /* Macros for tracing FPU instructions */
463 #define TRACE_FP_INPUT0() \
465 if (TRACE_FPU_P (CPU)) \
466 trace_input0 (SD, CPU, TRACE_FPU_IDX); \
469 #define TRACE_FP_INPUT1(V0) \
471 if (TRACE_FPU_P (CPU)) \
472 trace_input_fp1 (SD, CPU, TRACE_FPU_IDX, (V0)); \
475 #define TRACE_FP_INPUT2(V0,V1) \
477 if (TRACE_FPU_P (CPU)) \
478 trace_input_fp2 (SD, CPU, TRACE_FPU_IDX, (V0), (V1)); \
481 #define TRACE_FP_INPUT3(V0,V1,V2) \
483 if (TRACE_FPU_P (CPU)) \
484 trace_input_fp3 (SD, CPU, TRACE_FPU_IDX, (V0), (V1), (V2)); \
487 #define TRACE_FP_INPUT_WORD1(V0) \
489 if (TRACE_FPU_P (CPU)) \
490 trace_input_word1 (SD, CPU, TRACE_FPU_IDX, (V0)); \
493 #define TRACE_FP_RESULT(R0) \
495 if (TRACE_FPU_P (CPU)) \
496 trace_result_fp1 (SD, CPU, TRACE_FPU_IDX, (R0)); \
499 #define TRACE_FP_RESULT2(R0,R1) \
501 if (TRACE_FPU_P (CPU)) \
502 trace_result_fp2 (SD, CPU, TRACE_FPU_IDX, (R0), (R1)); \
505 #define TRACE_FP_RESULT_BOOL(R0) \
507 if (TRACE_FPU_P (CPU)) \
508 trace_result_bool1 (SD, CPU, TRACE_FPU_IDX, (R0)); \
511 #define TRACE_FP_RESULT_WORD(R0) \
513 if (TRACE_FPU_P (CPU)) \
514 trace_result_word1 (SD, CPU, TRACE_FPU_IDX, (R0)); \
518 /* Macros for tracing branches */
520 #define TRACE_BRANCH_INPUT(COND) \
522 if (TRACE_BRANCH_P (CPU)) \
523 trace_input_bool1 (SD, CPU, TRACE_BRANCH_IDX, (COND)); \
526 #define TRACE_BRANCH_RESULT(DEST) \
528 if (TRACE_BRANCH_P (CPU)) \
529 trace_result_addr1 (SD, CPU, TRACE_BRANCH_IDX, (DEST)); \
533 /* The function trace_one_insn has been replaced by the function pair
534 trace_prefix() + trace_generic() */
535 extern void trace_one_insn
PARAMS ((SIM_DESC sd
,
539 const char *file_name
,
544 __attribute__((format (printf
, 8, 9)));
546 extern void trace_printf
PARAMS ((SIM_DESC
, sim_cpu
*, const char *, ...))
547 __attribute__((format (printf
, 3, 4)));
549 extern void trace_vprintf
PARAMS ((SIM_DESC
, sim_cpu
*, const char *, va_list));
552 This is included here because there isn't enough of it to justify
555 /* Return non-zero if debugging of IDX for CPU is enabled. */
556 #define DEBUG_P(cpu, idx) \
557 ((WITH_DEBUG & (1 << (idx))) != 0 \
558 && CPU_DEBUG_FLAGS (cpu)[idx] != 0)
560 /* Non-zero if "--debug-insn" specified. */
561 #define DEBUG_INSN_P(cpu) DEBUG_P (cpu, DEBUG_INSN_IDX)
563 extern void debug_printf
PARAMS ((sim_cpu
*, const char *, ...))
564 __attribute__((format (printf
, 2, 3)));
566 #endif /* SIM_TRACE_H */