1/*  This file is part of the program psim.
2
3    Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au>
4
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2 of the License, or
8    (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19    */
20
21
22#ifndef _DEBUG_H_
23#define _DEBUG_H_
24
25#include "filter_filename.h"
26
27typedef enum {
28  trace_invalid,
29  trace_tbd,
30  /**/
31  trace_gdb,
32  trace_os_emul,
33  /**/
34  trace_events,
35  trace_device_tree,
36  trace_devices,
37  trace_binary_device,
38  trace_com_device,
39  trace_console_device,
40  trace_core_device,
41  trace_disk_device,
42  trace_eeprom_device,
43  trace_file_device,
44  trace_glue_device,
45  trace_halt_device,
46  trace_htab_device,
47  trace_icu_device,
48  trace_ide_device,
49  trace_memory_device,
50  trace_opic_device,
51  trace_pal_device,
52  trace_pass_device,
53  trace_phb_device,
54  trace_stack_device,
55  trace_register_device,
56  trace_vm_device,
57  /**/
58  trace_disklabel_package,
59  /**/
60  trace_semantics,
61  trace_idecode,
62  trace_alu,
63  trace_load_store,
64  trace_model,
65  /**/
66  trace_vm,
67  trace_core,
68  trace_interrupts,
69  trace_psim,
70  trace_device_init,
71  trace_cpu,
72  trace_breakpoint,
73  trace_opts,
74  trace_print_info,
75  trace_print_device_tree,
76  trace_dump_device_tree,
77  nr_trace_options
78} trace_options;
79
80
81
82extern int ppc_trace[nr_trace_options];
83
84/* simple */
85#define TRACE(OBJECT, ARGS) \
86do { \
87  if (WITH_TRACE) { \
88    if (ppc_trace[OBJECT]) { \
89      printf_filtered("%s:%d: ", filter_filename(__FILE__), __LINE__); \
90      printf_filtered ARGS; \
91    } \
92  } \
93} while (0)
94
95/* issue */
96#define ITRACE(OBJECT, ARGS) \
97do { \
98  if (WITH_TRACE) { \
99    if (ppc_trace[OBJECT]) { \
100      printf_filtered("%s:%d:0x%08lx:%s ", itable[MY_INDEX].file, itable[MY_INDEX].line_nr, (long)cia, itable[MY_INDEX].name); \
101      printf_filtered ARGS; \
102    } \
103  } \
104} while (0)
105
106/* device */
107#define DTRACE(OBJECT, ARGS) \
108do { \
109  if (WITH_TRACE) { \
110    int trace_device = device_trace(me); \
111    if (ppc_trace[trace_devices] \
112	|| ppc_trace[trace_##OBJECT##_device] \
113	|| trace_device) { \
114      printf_filtered("%s:%d:%s:%s%s ", \
115		      filter_filename(__FILE__), __LINE__, #OBJECT, \
116		      trace_device ? device_path(me) : "", \
117		      trace_device ? ":" : ""); \
118      printf_filtered ARGS; \
119    } \
120  } \
121} while (0)
122
123/* device instance */
124#define DITRACE(OBJECT, ARGS) \
125do { \
126  if (WITH_TRACE) { \
127    device *me = device_instance_device(instance); \
128    int trace_device = device_trace(me); \
129    if (ppc_trace[trace_devices] \
130	|| ppc_trace[trace_##OBJECT##_device] \
131	|| trace_device) { \
132      printf_filtered("%s:%d:%s:%s%s ", \
133		      filter_filename(__FILE__), __LINE__, #OBJECT, \
134		      trace_device ? device_path(me) : "", \
135		      trace_device ? ":" : ""); \
136      printf_filtered ARGS; \
137    } \
138  } \
139} while (0)
140
141/* package */
142#define PTRACE(OBJECT, ARGS) \
143do { \
144  if (WITH_TRACE) { \
145    if (ppc_trace[trace_##OBJECT##_package]) { \
146      printf_filtered("%s:%d:%s: ", filter_filename(__FILE__), __LINE__, #OBJECT); \
147      printf_filtered ARGS; \
148    } \
149  } \
150} while (0)
151
152
153#define ASSERT(EXPRESSION) \
154do { \
155  if (WITH_ASSERT) { \
156    if (!(EXPRESSION)) { \
157      error("%s:%d: assertion failed - %s\n", \
158	    filter_filename(__FILE__), __LINE__, #EXPRESSION); \
159    } \
160  } \
161} while (0)
162
163/* Parse OPTION updating the trace array */
164extern void
165trace_option(const char *option, int setting);
166
167/* Output the list of trace options */
168extern void trace_usage
169(int verbose);
170
171
172#endif /* _DEBUG_H_ */
173