Add tracing to r5900 p* instructions.
[deliverable/binutils-gdb.git] / sim / common / sim-trace.h
1 /* Simulator tracing/debugging support.
2 Copyright (C) 1997, 1998 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
4
5 This file is part of GDB, the GNU debugger.
6
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 2, or (at your option)
10 any later version.
11
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.
16
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21 /* This file is meant to be included by sim-basics.h. */
22
23 #ifndef SIM_TRACE_H
24 #define SIM_TRACE_H
25
26 /* Standard traceable entities. */
27
28 enum {
29 /* Trace insn execution. */
30 TRACE_INSN_IDX = 1,
31
32 /* Trace insn decoding.
33 ??? This is more of a simulator debugging operation and might best be
34 moved to --debug-decode. */
35 TRACE_DECODE_IDX,
36
37 /* Trace insn extraction.
38 ??? This is more of a simulator debugging operation and might best be
39 moved to --debug-extract. */
40 TRACE_EXTRACT_IDX,
41
42 /* Trace insn execution but include line numbers. */
43 TRACE_LINENUM_IDX,
44
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. */
49 TRACE_MEMORY_IDX,
50
51 /* Include model performance data in tracing output. */
52 TRACE_MODEL_IDX,
53
54 /* Trace ALU operations. */
55 TRACE_ALU_IDX,
56
57 /* Trace memory core operations. */
58 TRACE_CORE_IDX,
59
60 /* Trace events. */
61 TRACE_EVENTS_IDX,
62
63 /* Trace fpu operations. */
64 TRACE_FPU_IDX,
65
66 /* Trace branching. */
67 TRACE_BRANCH_IDX,
68
69 /* Add information useful for debugging the simulator to trace output. */
70 TRACE_DEBUG_IDX,
71
72 /* Simulator specific trace bits begin here. */
73 TRACE_NEXT_IDX,
74
75 };
76 /* Maximum number of traceable entities. */
77 #ifndef MAX_TRACE_VALUES
78 #define MAX_TRACE_VALUES 32
79 #endif
80
81 /* The -t option only prints useful values. It's easy to type and shouldn't
82 splat on the screen everything under the sun making nothing easy to
83 find. */
84 #define TRACE_USEFUL_MASK \
85 ((1 << TRACE_INSN_IDX) \
86 | (1 << TRACE_LINENUM_IDX) \
87 | (1 << TRACE_MEMORY_IDX) \
88 | (1 << TRACE_MODEL_IDX) \
89 | (1 << TRACE_EVENTS_IDX))
90 \f
91 /* Masks so WITH_TRACE can have symbolic values.
92 The case choice here is on purpose. The lowercase parts are args to
93 --with-trace. */
94 #define TRACE_insn (1 << TRACE_INSN_IDX)
95 #define TRACE_decode (1 << TRACE_DECODE_IDX)
96 #define TRACE_extract (1 << TRACE_EXTRACT_IDX)
97 #define TRACE_linenum (1 << TRACE_LINENUM_IDX)
98 #define TRACE_memory (1 << TRACE_MEMORY_IDX)
99 #define TRACE_model (1 << TRACE_MODEL_IDX)
100 #define TRACE_alu (1 << TRACE_ALU_IDX)
101 #define TRACE_core (1 << TRACE_CORE_IDX)
102 #define TRACE_events (1 << TRACE_EVENTS_IDX)
103 #define TRACE_fpu (1 << TRACE_FPU_IDX)
104 #define TRACE_branch (1 << TRACE_BRANCH_IDX)
105 #define TRACE_debug (1 << TRACE_DEBUG_IDX)
106
107 /* Preprocessor macros to simplify tests of WITH_TRACE. */
108 #define WITH_TRACE_INSN_P (WITH_TRACE & TRACE_insn)
109 #define WITH_TRACE_DECODE_P (WITH_TRACE & TRACE_decode)
110 #define WITH_TRACE_EXTRACT_P (WITH_TRACE & TRACE_extract)
111 #define WITH_TRACE_LINENUM_P (WITH_TRACE & TRACE_linenum)
112 #define WITH_TRACE_MEMORY_P (WITH_TRACE & TRACE_memory)
113 #define WITH_TRACE_MODEL_P (WITH_TRACE & TRACE_model)
114 #define WITH_TRACE_ALU_P (WITH_TRACE & TRACE_alu)
115 #define WITH_TRACE_CORE_P (WITH_TRACE & TRACE_core)
116 #define WITH_TRACE_EVENTS_P (WITH_TRACE & TRACE_events)
117 #define WITH_TRACE_FPU_P (WITH_TRACE & TRACE_fpu)
118 #define WITH_TRACE_BRANCH_P (WITH_TRACE & TRACE_branch)
119 #define WITH_TRACE_DEBUG_P (WITH_TRACE & TRACE_debug)
120
121 /* Tracing install handler. */
122 MODULE_INSTALL_FN trace_install;
123 \f
124 /* Struct containing all system and cpu trace data.
125
126 System trace data is stored with the associated module.
127 System and cpu tracing must share the same space of bitmasks as they
128 are arguments to --with-trace. One could have --with-trace and
129 --with-cpu-trace or some such but that's an over-complication at this point
130 in time. Also, there may be occasions where system and cpu tracing may
131 wish to share a name. */
132
133 typedef struct _trace_data {
134
135 /* Boolean array of specified tracing flags. */
136 /* ??? It's not clear that using an array vs a bit mask is faster.
137 Consider the case where one wants to test whether any of several bits
138 are set. */
139 char trace_flags[MAX_TRACE_VALUES];
140 #define TRACE_FLAGS(t) ((t)->trace_flags)
141
142 /* Tracing output goes to this or stderr if NULL.
143 We can't store `stderr' here as stderr goes through a callback. */
144 FILE *trace_file;
145 #define TRACE_FILE(t) ((t)->trace_file)
146
147 /* Buffer to store the prefix to be printed before any trace line */
148 char trace_prefix[256];
149 #define TRACE_PREFIX(t) ((t)->trace_prefix)
150
151 /* Buffer to save the inputs for the current instruction. Use a
152 union to force the buffer into correct alignment */
153 union {
154 unsigned8 i8;
155 unsigned16 i16;
156 unsigned32 i32;
157 unsigned64 i64;
158 } trace_input_data[16];
159 unsigned8 trace_input_fmt[16];
160 unsigned8 trace_input_size[16];
161 int trace_input_idx;
162 #define TRACE_INPUT_DATA(t) ((t)->trace_input_data)
163 #define TRACE_INPUT_FMT(t) ((t)->trace_input_fmt)
164 #define TRACE_INPUT_SIZE(t) ((t)->trace_input_size)
165 #define TRACE_INPUT_IDX(t) ((t)->trace_input_idx)
166
167 /* Category of trace being performed */
168 int trace_idx;
169 #define TRACE_IDX(t) ((t)->trace_idx)
170
171 } TRACE_DATA;
172
173 \f
174 /* System tracing support. */
175
176 #define STATE_TRACE_FLAGS(sd) TRACE_FLAGS (STATE_TRACE_DATA (sd))
177
178 /* Return non-zero if tracing of IDX is enabled for non-cpu specific
179 components. The "S" in "STRACE" refers to "System". */
180 #define STRACE_P(sd,idx) \
181 ((WITH_TRACE & (1 << (idx))) != 0 \
182 && STATE_TRACE_FLAGS (sd)[idx] != 0)
183
184 /* Non-zero if --trace-<xxxx> was specified for SD. */
185 #define STRACE_DEBUG_P(sd) STRACE_P (sd, TRACE_DEBUG_IDX)
186 \f
187 /* CPU tracing support. */
188
189 #define CPU_TRACE_FLAGS(cpu) TRACE_FLAGS (CPU_TRACE_DATA (cpu))
190
191 /* Return non-zero if tracing of IDX is enabled for CPU. */
192 #define TRACE_P(cpu,idx) \
193 ((WITH_TRACE & (1 << (idx))) != 0 \
194 && CPU_TRACE_FLAGS (cpu)[idx] != 0)
195
196 /* Non-zero if --trace-<xxxx> was specified for CPU. */
197 #define TRACE_INSN_P(cpu) TRACE_P (cpu, TRACE_INSN_IDX)
198 #define TRACE_DECODE_P(cpu) TRACE_P (cpu, TRACE_DECODE_IDX)
199 #define TRACE_EXTRACT_P(cpu) TRACE_P (cpu, TRACE_EXTRACT_IDX)
200 #define TRACE_LINENUM_P(cpu) TRACE_P (cpu, TRACE_LINENUM_IDX)
201 #define TRACE_MEMORY_P(cpu) TRACE_P (cpu, TRACE_MEMORY_IDX)
202 #define TRACE_MODEL_P(cpu) TRACE_P (cpu, TRACE_MODEL_IDX)
203 #define TRACE_ALU_P(cpu) TRACE_P (cpu, TRACE_ALU_IDX)
204 #define TRACE_CORE_P(cpu) TRACE_P (cpu, TRACE_CORE_IDX)
205 #define TRACE_EVENTS_P(cpu) TRACE_P (cpu, TRACE_EVENTS_IDX)
206 #define TRACE_FPU_P(cpu) TRACE_P (cpu, TRACE_FPU_IDX)
207 #define TRACE_BRANCH_P(cpu) TRACE_P (cpu, TRACE_BRANCH_IDX)
208 #define TRACE_DEBUG_P(cpu) TRACE_P (cpu, TRACE_DEBUG_IDX)
209 \f
210 /* Traceing functions.
211
212 */
213
214 /* Prime the trace buffers ready for any trace output.
215 Must be called prior to any other trace operation */
216 extern void trace_prefix PARAMS ((SIM_DESC sd,
217 sim_cpu * cpu,
218 address_word cia,
219 int print_linenum_p,
220 const char *file_name,
221 int line_nr,
222 const char *fmt,
223 ...))
224 __attribute__((format (printf, 7, 8)));
225
226 /* Generic trace print, assumes trace_prefix() has been called */
227
228 extern void trace_generic PARAMS ((SIM_DESC sd,
229 sim_cpu *cpu,
230 int trace_idx,
231 char *fmt,
232 ...))
233 __attribute__((format (printf, 4, 5)));
234
235 /* Trace a varying number of word sized inputs/outputs. trace_result*
236 must be called to close the trace operation. */
237
238 extern void trace_input0 PARAMS ((SIM_DESC sd,
239 sim_cpu *cpu,
240 int trace_idx));
241
242 extern void trace_input_word1 PARAMS ((SIM_DESC sd,
243 sim_cpu *cpu,
244 int trace_idx,
245 unsigned_word d0));
246
247 extern void trace_input_word2 PARAMS ((SIM_DESC sd,
248 sim_cpu *cpu,
249 int trace_idx,
250 unsigned_word d0,
251 unsigned_word d1));
252
253 extern void trace_input_word3 PARAMS ((SIM_DESC sd,
254 sim_cpu *cpu,
255 int trace_idx,
256 unsigned_word d0,
257 unsigned_word d1,
258 unsigned_word d2));
259
260 extern void trace_input_word4 PARAMS ((SIM_DESC sd,
261 sim_cpu *cpu,
262 int trace_idx,
263 unsigned_word d0,
264 unsigned_word d1,
265 unsigned_word d2,
266 unsigned_word d3));
267
268 extern void trace_input_addr1 PARAMS ((SIM_DESC sd,
269 sim_cpu *cpu,
270 int trace_idx,
271 address_word d0));
272
273 extern void trace_input_bool1 PARAMS ((SIM_DESC sd,
274 sim_cpu *cpu,
275 int trace_idx,
276 int d0));
277
278 extern void trace_input_fp1 PARAMS ((SIM_DESC sd,
279 sim_cpu *cpu,
280 int trace_idx,
281 fp_word f0));
282
283 extern void trace_input_fp2 PARAMS ((SIM_DESC sd,
284 sim_cpu *cpu,
285 int trace_idx,
286 fp_word f0,
287 fp_word f1));
288
289 extern void trace_input_fp3 PARAMS ((SIM_DESC sd,
290 sim_cpu *cpu,
291 int trace_idx,
292 fp_word f0,
293 fp_word f1,
294 fp_word f2));
295
296 extern void trace_input_fpu1 PARAMS ((SIM_DESC sd,
297 sim_cpu *cpu,
298 int trace_idx,
299 struct _sim_fpu *f0));
300
301 extern void trace_input_fpu2 PARAMS ((SIM_DESC sd,
302 sim_cpu *cpu,
303 int trace_idx,
304 struct _sim_fpu *f0,
305 struct _sim_fpu *f1));
306
307 extern void trace_input_fpu3 PARAMS ((SIM_DESC sd,
308 sim_cpu *cpu,
309 int trace_idx,
310 struct _sim_fpu *f0,
311 struct _sim_fpu *f1,
312 struct _sim_fpu *f2));
313
314 /* Other trace_input{_<fmt><nr-inputs>} functions can go here */
315
316 extern void trace_result_word1 PARAMS ((SIM_DESC sd,
317 sim_cpu *cpu,
318 int trace_idx,
319 unsigned_word r0));
320
321 extern void trace_result_word2 PARAMS ((SIM_DESC sd,
322 sim_cpu *cpu,
323 int trace_idx,
324 unsigned_word r0,
325 unsigned_word r1));
326
327 extern void trace_result_word4 PARAMS ((SIM_DESC sd,
328 sim_cpu *cpu,
329 int trace_idx,
330 unsigned_word r0,
331 unsigned_word r1,
332 unsigned_word r2,
333 unsigned_word r3));
334
335 extern void trace_result_bool1 PARAMS ((SIM_DESC sd,
336 sim_cpu *cpu,
337 int trace_idx,
338 int r0));
339
340 extern void trace_result_addr1 PARAMS ((SIM_DESC sd,
341 sim_cpu *cpu,
342 int trace_idx,
343 address_word r0));
344
345 extern void trace_result_fp1 PARAMS ((SIM_DESC sd,
346 sim_cpu *cpu,
347 int trace_idx,
348 fp_word f0));
349
350 extern void trace_result_fpu1 PARAMS ((SIM_DESC sd,
351 sim_cpu *cpu,
352 int trace_idx,
353 struct _sim_fpu *f0));
354
355 extern void trace_result_string1 PARAMS ((SIM_DESC sd,
356 sim_cpu *cpu,
357 int trace_idx,
358 char *str0));
359
360 extern void trace_result_word1_string1 PARAMS ((SIM_DESC sd,
361 sim_cpu *cpu,
362 int trace_idx,
363 unsigned_word r0,
364 char *s0));
365
366 /* Other trace_result{_<type><nr-results>} */
367
368
369 /* Macro's for tracing ALU instructions */
370
371 #define TRACE_ALU_INPUT0() \
372 do { \
373 if (TRACE_ALU_P (CPU)) \
374 trace_input0 (SD, CPU, TRACE_ALU_IDX); \
375 } while (0)
376
377 #define TRACE_ALU_INPUT1(V0) \
378 do { \
379 if (TRACE_ALU_P (CPU)) \
380 trace_input_word1 (SD, CPU, TRACE_ALU_IDX, (V0)); \
381 } while (0)
382
383 #define TRACE_ALU_INPUT2(V0,V1) \
384 do { \
385 if (TRACE_ALU_P (CPU)) \
386 trace_input_word2 (SD, CPU, TRACE_ALU_IDX, (V0), (V1)); \
387 } while (0)
388
389 #define TRACE_ALU_INPUT3(V0,V1,V2) \
390 do { \
391 if (TRACE_ALU_P (CPU)) \
392 trace_input_word3 (SD, CPU, TRACE_ALU_IDX, (V0), (V1), (V2)); \
393 } while (0)
394
395 #define TRACE_ALU_INPUT4(V0,V1,V2,V3) \
396 do { \
397 if (TRACE_ALU_P (CPU)) \
398 trace_input_word4 (SD, CPU, TRACE_ALU_IDX, (V0), (V1), (V2), (V3)); \
399 } while (0)
400
401 #define TRACE_ALU_RESULT(R0) TRACE_ALU_RESULT1(R0)
402
403 #define TRACE_ALU_RESULT1(R0) \
404 do { \
405 if (TRACE_ALU_P (CPU)) \
406 trace_result_word1 (SD, CPU, TRACE_ALU_IDX, (R0)); \
407 } while (0)
408
409 #define TRACE_ALU_RESULT2(R0,R1) \
410 do { \
411 if (TRACE_ALU_P (CPU)) \
412 trace_result_word2 (SD, CPU, TRACE_ALU_IDX, (R0), (R1)); \
413 } while (0)
414
415 #define TRACE_ALU_RESULT4(R0,R1,R2,R3) \
416 do { \
417 if (TRACE_ALU_P (CPU)) \
418 trace_result_word4 (SD, CPU, TRACE_ALU_IDX, (R0), (R1), (R2), (R3)); \
419 } while (0)
420
421
422 /* Macro's for tracing FPU instructions */
423
424 #define TRACE_FPU_INPUT0() \
425 do { \
426 if (TRACE_FPU_P (CPU)) \
427 trace_input0 (SD, CPU, TRACE_FPU_IDX); \
428 } while (0)
429
430 #define TRACE_FPU_INPUT1(V0) \
431 do { \
432 if (TRACE_FPU_P (CPU)) \
433 trace_input_fp1 (SD, CPU, TRACE_FPU_IDX, (V0)); \
434 } while (0)
435
436 #define TRACE_FPU_INPUT2(V0,V1) \
437 do { \
438 if (TRACE_FPU_P (CPU)) \
439 trace_input_fp2 (SD, CPU, TRACE_FPU_IDX, (V0), (V1)); \
440 } while (0)
441
442 #define TRACE_FPU_INPUT3(V0,V1,V2) \
443 do { \
444 if (TRACE_FPU_P (CPU)) \
445 trace_input_fp3 (SD, CPU, TRACE_FPU_IDX, (V0), (V1), (V2)); \
446 } while (0)
447
448 #define TRACE_FPU_RESULT(R0) \
449 do { \
450 if (TRACE_FPU_P (CPU)) \
451 trace_result_fp1 (SD, CPU, TRACE_FPU_IDX, (R0)); \
452 } while (0)
453
454 #define TRACE_FPU_RESULT_BOOL(R0) \
455 do { \
456 if (TRACE_FPU_P (CPU)) \
457 trace_result_bool1 (SD, CPU, TRACE_FPU_IDX, (R0)); \
458 } while (0)
459
460
461 /* Macros for tracing branches */
462
463 #define TRACE_BRANCH_INPUT(COND) \
464 do { \
465 if (TRACE_BRANCH_P (CPU)) \
466 trace_input_bool1 (SD, CPU, TRACE_BRANCH_IDX, (COND)); \
467 } while (0)
468
469 #define TRACE_BRANCH_RESULT(DEST) \
470 do { \
471 if (TRACE_BRANCH_P (CPU)) \
472 trace_result_addr1 (SD, CPU, TRACE_BRANCH_IDX, (DEST)); \
473 } while (0)
474
475 \f
476 /* The function trace_one_insn has been replaced by trace_generic */
477 extern void trace_one_insn PARAMS ((SIM_DESC sd,
478 sim_cpu * cpu,
479 address_word cia,
480 int print_linenum_p,
481 const char *file_name,
482 int line_nr,
483 const char *unit,
484 const char *fmt,
485 ...))
486 __attribute__((format (printf, 8, 9)));
487
488 extern void trace_printf PARAMS ((SIM_DESC, sim_cpu *, const char *, ...))
489 __attribute__((format (printf, 3, 4)));
490
491 extern void trace_vprintf PARAMS ((SIM_DESC, sim_cpu *, const char *, va_list));
492
493 /* Debug support.
494 This is included here because there isn't enough of it to justify
495 a sim-debug.h. */
496
497 /* Return non-zero if debugging of IDX for CPU is enabled. */
498 #define DEBUG_P(cpu, idx) \
499 ((WITH_DEBUG & (1 << (idx))) != 0 \
500 && CPU_DEBUG_FLAGS (cpu)[idx] != 0)
501
502 /* Non-zero if "--debug-insn" specified. */
503 #define DEBUG_INSN_P(cpu) DEBUG_P (cpu, DEBUG_INSN_IDX)
504
505 extern void debug_printf PARAMS ((sim_cpu *, const char *, ...))
506 __attribute__((format (printf, 2, 3)));
507
508 #endif /* SIM_TRACE_H */
This page took 0.04057 seconds and 5 git commands to generate.