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