Add tracing of booleans and addresses.
[deliverable/binutils-gdb.git] / sim / common / sim-trace.h
CommitLineData
0f2811d1 1/* Simulator tracing/debugging support.
0325f2dc 2 Copyright (C) 1997, 1998 Free Software Foundation, Inc.
0f2811d1
DE
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
3971886a 26/* Standard traceable entities. */
3971886a 27
8dcc896d
AC
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
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};
7b167b09
MM
76/* Maximum number of traceable entities. */
77#ifndef MAX_TRACE_VALUES
78#define MAX_TRACE_VALUES 32
79#endif
0325f2dc
AC
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))
8dcc896d
AC
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)
3971886a
AC
106
107/* Preprocessor macros to simplify tests of WITH_TRACE. */
7b167b09
MM
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)
8dcc896d 119#define WITH_TRACE_DEBUG_P (WITH_TRACE & TRACE_debug)
3971886a
AC
120
121/* Tracing install handler. */
122MODULE_INSTALL_FN trace_install;
123\f
8dcc896d
AC
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
133typedef struct _trace_data {
3971886a 134
3971886a
AC
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)
8dcc896d
AC
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
3971886a 171} TRACE_DATA;
8dcc896d 172
3971886a 173\f
8dcc896d 174/* System tracing support. */
3971886a 175
8dcc896d 176#define STATE_TRACE_FLAGS(sd) TRACE_FLAGS (STATE_TRACE_DATA (sd))
3971886a 177
8dcc896d
AC
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. */
0f2811d1 188
8dcc896d 189#define CPU_TRACE_FLAGS(cpu) TRACE_FLAGS (CPU_TRACE_DATA (cpu))
0f2811d1
DE
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
8dcc896d 196/* Non-zero if --trace-<xxxx> was specified for CPU. */
7b167b09
MM
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)
8dcc896d
AC
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 */
216extern 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
228extern 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
238extern void trace_input0 PARAMS ((SIM_DESC sd,
239 sim_cpu *cpu,
240 int trace_idx));
0325f2dc 241
8dcc896d
AC
242extern void trace_input_word1 PARAMS ((SIM_DESC sd,
243 sim_cpu *cpu,
244 int trace_idx,
245 unsigned_word d0));
0325f2dc 246
8dcc896d
AC
247extern void trace_input_word2 PARAMS ((SIM_DESC sd,
248 sim_cpu *cpu,
249 int trace_idx,
250 unsigned_word d0,
251 unsigned_word d1));
0325f2dc 252
8dcc896d
AC
253extern 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
0325f2dc
AC
260extern void trace_input_bool1 PARAMS ((SIM_DESC sd,
261 sim_cpu *cpu,
262 int trace_idx,
263 int d0));
264
8dcc896d
AC
265extern void trace_input_fp1 PARAMS ((SIM_DESC sd,
266 sim_cpu *cpu,
267 int trace_idx,
268 fp_word f0));
269
270extern void trace_input_fp2 PARAMS ((SIM_DESC sd,
271 sim_cpu *cpu,
272 int trace_idx,
273 fp_word f0,
274 fp_word f1));
275
276extern void trace_input_fp3 PARAMS ((SIM_DESC sd,
277 sim_cpu *cpu,
278 int trace_idx,
279 fp_word f0,
280 fp_word f1,
281 fp_word f2));
282
283extern void trace_input_fpu1 PARAMS ((SIM_DESC sd,
284 sim_cpu *cpu,
285 int trace_idx,
286 struct _sim_fpu *f0));
287
288extern void trace_input_fpu2 PARAMS ((SIM_DESC sd,
289 sim_cpu *cpu,
290 int trace_idx,
291 struct _sim_fpu *f0,
292 struct _sim_fpu *f1));
293
294extern void trace_input_fpu3 PARAMS ((SIM_DESC sd,
295 sim_cpu *cpu,
296 int trace_idx,
297 struct _sim_fpu *f0,
298 struct _sim_fpu *f1,
299 struct _sim_fpu *f2));
0f2811d1 300
8dcc896d
AC
301/* Other trace_input{_<fmt><nr-inputs>} functions can go here */
302
303extern void trace_result_word1 PARAMS ((SIM_DESC sd,
304 sim_cpu *cpu,
305 int trace_idx,
306 unsigned_word r0));
307
0325f2dc
AC
308extern void trace_result_bool1 PARAMS ((SIM_DESC sd,
309 sim_cpu *cpu,
310 int trace_idx,
311 int r0));
312
313extern void trace_result_addr1 PARAMS ((SIM_DESC sd,
314 sim_cpu *cpu,
315 int trace_idx,
316 address_word r0));
317
8dcc896d
AC
318extern void trace_result_fp1 PARAMS ((SIM_DESC sd,
319 sim_cpu *cpu,
320 int trace_idx,
321 fp_word f0));
322
323extern void trace_result_fpu1 PARAMS ((SIM_DESC sd,
324 sim_cpu *cpu,
325 int trace_idx,
326 struct _sim_fpu *f0));
327
328extern void trace_result_string1 PARAMS ((SIM_DESC sd,
329 sim_cpu *cpu,
330 int trace_idx,
331 char *str0));
332
333extern void trace_result_word1_string1 PARAMS ((SIM_DESC sd,
334 sim_cpu *cpu,
335 int trace_idx,
336 unsigned_word r0,
337 char *s0));
338
339/* Other trace_result{_<type><nr-results>} */
340
341
342/* Macro's for tracing ALU instructions */
0325f2dc 343
8dcc896d
AC
344#define TRACE_ALU_INPUT0() \
345do { \
346 if (TRACE_ALU_P (CPU)) \
347 trace_input0 (SD, CPU, TRACE_ALU_IDX); \
348} while (0)
349
350#define TRACE_ALU_INPUT1(V0) \
351do { \
352 if (TRACE_ALU_P (CPU)) \
353 trace_input_word1 (SD, CPU, TRACE_ALU_IDX, (V0)); \
354} while (0)
355
356#define TRACE_ALU_INPUT2(V0,V1) \
357do { \
358 if (TRACE_ALU_P (CPU)) \
359 trace_input_word2 (SD, CPU, TRACE_ALU_IDX, (V0), (V1)); \
360} while (0)
361
362#define TRACE_ALU_INPUT3(V0,V1,V2) \
363do { \
364 if (TRACE_ALU_P (CPU)) \
365 trace_input_word3 (SD, CPU, TRACE_ALU_IDX, (V0), (V1), (V2)); \
366} while (0)
367
368#define TRACE_ALU_RESULT(R0) \
369do { \
370 if (TRACE_ALU_P (CPU)) \
371 trace_result_word1 (SD, CPU, TRACE_ALU_IDX, (R0)); \
372} while (0)
373
0325f2dc
AC
374
375/* Macro's for tracing FPU instructions */
376
377#define TRACE_FPU_INPUT0() \
378do { \
379 if (TRACE_FPU_P (CPU)) \
380 trace_input0 (SD, CPU, TRACE_FPU_IDX); \
381} while (0)
382
383#define TRACE_FPU_INPUT1(V0) \
384do { \
385 if (TRACE_FPU_P (CPU)) \
386 trace_input_fp1 (SD, CPU, TRACE_FPU_IDX, (V0)); \
387} while (0)
388
389#define TRACE_FPU_INPUT2(V0,V1) \
390do { \
391 if (TRACE_FPU_P (CPU)) \
392 trace_input_fp2 (SD, CPU, TRACE_FPU_IDX, (V0), (V1)); \
393} while (0)
394
395#define TRACE_FPU_INPUT3(V0,V1,V2) \
396do { \
397 if (TRACE_FPU_P (CPU)) \
398 trace_input_fp3 (SD, CPU, TRACE_FPU_IDX, (V0), (V1), (V2)); \
399} while (0)
400
401#define TRACE_FPU_RESULT(R0) \
402do { \
403 if (TRACE_FPU_P (CPU)) \
404 trace_result_fp1 (SD, CPU, TRACE_FPU_IDX, (R0)); \
405} while (0)
406
407#define TRACE_FPU_RESULT_BOOL(R0) \
408do { \
409 if (TRACE_FPU_P (CPU)) \
410 trace_result_bool1 (SD, CPU, TRACE_FPU_IDX, (R0)); \
411} while (0)
412
413
414/* Macros for tracing branches */
415
416#define TRACE_BRANCH_INPUT(COND) \
417do { \
418 if (TRACE_BRANCH_P (CPU)) \
419 trace_input_bool1 (SD, CPU, TRACE_BRANCH_IDX, (COND)); \
420} while (0)
421
422#define TRACE_BRANCH_RESULT(DEST) \
423do { \
424 if (TRACE_BRANCH_P (CPU)) \
425 trace_result_addr1 (SD, CPU, TRACE_BRANCH_IDX, (DEST)); \
426} while (0)
427
8dcc896d
AC
428\f
429/* The function trace_one_insn has been replaced by trace_generic */
381f42ef
AC
430extern void trace_one_insn PARAMS ((SIM_DESC sd,
431 sim_cpu * cpu,
432 address_word cia,
433 int print_linenum_p,
434 const char *file_name,
435 int line_nr,
436 const char *unit,
437 const char *fmt,
438 ...))
439 __attribute__((format (printf, 8, 9)));
a7724171 440
23b04e79
MM
441extern void trace_printf PARAMS ((SIM_DESC, sim_cpu *, const char *, ...))
442 __attribute__((format (printf, 3, 4)));
0f2811d1 443
381f42ef
AC
444extern void trace_vprintf PARAMS ((SIM_DESC, sim_cpu *, const char *, va_list));
445
3971886a
AC
446/* Debug support.
447 This is included here because there isn't enough of it to justify
448 a sim-debug.h. */
0f2811d1 449
0f2811d1
DE
450/* Return non-zero if debugging of IDX for CPU is enabled. */
451#define DEBUG_P(cpu, idx) \
452((WITH_DEBUG & (1 << (idx))) != 0 \
453 && CPU_DEBUG_FLAGS (cpu)[idx] != 0)
454
455/* Non-zero if "--debug-insn" specified. */
456#define DEBUG_INSN_P(cpu) DEBUG_P (cpu, DEBUG_INSN_IDX)
457
8dcc896d 458extern void debug_printf PARAMS ((sim_cpu *, const char *, ...))
23b04e79 459 __attribute__((format (printf, 2, 3)));
0f2811d1
DE
460
461#endif /* SIM_TRACE_H */
This page took 0.063942 seconds and 4 git commands to generate.