/[pcsx2_0.9.7]/trunk/pcsx2/DebugTools/Debug.h
ViewVC logotype

Contents of /trunk/pcsx2/DebugTools/Debug.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 62 - (show annotations) (download)
Tue Sep 7 11:08:22 2010 UTC (9 years, 10 months ago) by william
File MIME type: text/plain
File size: 11222 byte(s)
Auto Commited Import of: pcsx2-0.9.7-r3738-debug in ./trunk
1 /* PCSX2 - PS2 Emulator for PCs
2 * Copyright (C) 2002-2010 PCSX2 Dev Team
3 *
4 * PCSX2 is free software: you can redistribute it and/or modify it under the terms
5 * of the GNU Lesser General Public License as published by the Free Software Found-
6 * ation, either version 3 of the License, or (at your option) any later version.
7 *
8 * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10 * PURPOSE. See the GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License along with PCSX2.
13 * If not, see <http://www.gnu.org/licenses/>.
14 */
15
16 #pragma once
17
18 #include "Utilities/TraceLog.h"
19
20 extern FILE *emuLog;
21 extern wxString emuLogName;
22
23 extern char* disVU0MicroUF(u32 code, u32 pc);
24 extern char* disVU0MicroLF(u32 code, u32 pc);
25 extern char* disVU1MicroUF(u32 code, u32 pc);
26 extern char* disVU1MicroLF(u32 code, u32 pc);
27
28 extern const char * const CP2VFnames[];
29 extern const char * const disRNameCP2f[];
30 extern const char * const disRNameCP2i[];
31
32 namespace R5900
33 {
34 // [TODO] : These function names can be de-obfuscated with the help of a little namespace love.
35
36 void disR5900F( std::string& output, u32 code );
37 void disR5900Fasm( std::string& output, u32 code, u32 pc);
38 void disR5900AddSym(u32 addr, const char *name);
39 const char* disR5900GetSym(u32 addr);
40 const char* disR5900GetUpperSym(u32 addr);
41 void disR5900FreeSyms();
42 void dFindSym( std::string& output, u32 addr );
43
44 extern const char * const disRNameGPR[];
45
46 // A helper class for getting a quick and efficient string representation of the
47 // R5900's current instruction. This class is *not* thread safe!
48 class DisR5900CurrentState
49 {
50 protected:
51 std::string result;
52
53 public:
54 const std::string& getString();
55 const char* getCString();
56 };
57
58 extern DisR5900CurrentState disR5900Current;
59 }
60
61 namespace R3000A
62 {
63 extern void (*IOP_DEBUG_BSC[64])(char *buf);
64
65 extern const char * const disRNameGPR[];
66 extern char* disR3000Fasm(u32 code, u32 pc);
67 extern char* disR3000AF(u32 code, u32 pc);
68 }
69
70 // this structure uses old fashioned C-style "polymorphism". The base struct TraceLogDescriptor
71 // must always be the first member in the struct.
72 struct SysTraceLogDescriptor
73 {
74 TraceLogDescriptor base;
75 const char* Prefix;
76 };
77
78 // --------------------------------------------------------------------------------------
79 // SysTraceLog
80 // --------------------------------------------------------------------------------------
81 // Default trace log for high volume VM/System logging.
82 // This log dumps to emuLog.txt directly and has no ability to pipe output
83 // to the console (due to the console's inability to handle extremely high
84 // logging volume).
85 class SysTraceLog : public TextFileTraceLog
86 {
87 public:
88 const char* PrePrefix;
89
90 public:
91 TraceLog_ImplementBaseAPI(SysTraceLog)
92
93 // Pass me a NULL and you *will* suffer! Muahahaha.
94 SysTraceLog( const SysTraceLogDescriptor* desc )
95 : TextFileTraceLog( &desc->base ) {}
96
97 void DoWrite( const char *fmt ) const;
98
99 SysTraceLog& SetPrefix( const char* name )
100 {
101 PrePrefix = name;
102 return *this;
103 }
104
105 };
106
107 class SysTraceLog_EE : public SysTraceLog
108 {
109 typedef SysTraceLog _parent;
110
111 public:
112 SysTraceLog_EE( const SysTraceLogDescriptor* desc ) : _parent( desc ) {}
113
114 void ApplyPrefix( FastFormatAscii& ascii ) const;
115 bool IsActive() const
116 {
117 return EmuConfig.Trace.Enabled && Enabled && EmuConfig.Trace.EE.m_EnableAll;
118 }
119
120 wxString GetCategory() const { return L"EE"; }
121 };
122
123 class SysTraceLog_VIFcode : public SysTraceLog_EE
124 {
125 typedef SysTraceLog_EE _parent;
126
127 public:
128 SysTraceLog_VIFcode( const SysTraceLogDescriptor* desc ) : _parent( desc ) {}
129
130 void ApplyPrefix( FastFormatAscii& ascii ) const;
131 };
132
133 class SysTraceLog_EE_Disasm : public SysTraceLog_EE
134 {
135 typedef SysTraceLog_EE _parent;
136
137 public:
138 SysTraceLog_EE_Disasm( const SysTraceLogDescriptor* desc ) : _parent( desc ) {}
139
140 bool IsActive() const
141 {
142 return _parent::IsActive() && EmuConfig.Trace.EE.m_EnableDisasm;
143 }
144
145 wxString GetCategory() const { return _parent::GetCategory() + L".Disasm"; }
146 };
147
148 class SysTraceLog_EE_Registers : public SysTraceLog_EE
149 {
150 typedef SysTraceLog_EE _parent;
151
152 public:
153 SysTraceLog_EE_Registers( const SysTraceLogDescriptor* desc ) : _parent( desc ) {}
154
155 bool IsActive() const
156 {
157 return _parent::IsActive() && EmuConfig.Trace.EE.m_EnableRegisters;
158 }
159
160 wxString GetCategory() const { return _parent::GetCategory() + L".Registers"; }
161 };
162
163 class SysTraceLog_EE_Events : public SysTraceLog_EE
164 {
165 typedef SysTraceLog_EE _parent;
166
167 public:
168 SysTraceLog_EE_Events( const SysTraceLogDescriptor* desc ) : _parent( desc ) {}
169
170 bool IsActive() const
171 {
172 return _parent::IsActive() && EmuConfig.Trace.EE.m_EnableEvents;
173 }
174
175 wxString GetCategory() const { return _parent::GetCategory() + L".Events"; }
176 };
177
178
179 class SysTraceLog_IOP : public SysTraceLog
180 {
181 typedef SysTraceLog _parent;
182
183 public:
184 SysTraceLog_IOP( const SysTraceLogDescriptor* desc ) : _parent( desc ) {}
185
186 void ApplyPrefix( FastFormatAscii& ascii ) const;
187 bool IsActive() const
188 {
189 return EmuConfig.Trace.Enabled && Enabled && EmuConfig.Trace.IOP.m_EnableAll;
190 }
191
192 wxString GetCategory() const { return L"IOP"; }
193 };
194
195 class SysTraceLog_IOP_Disasm : public SysTraceLog_IOP
196 {
197 typedef SysTraceLog_IOP _parent;
198
199 public:
200 SysTraceLog_IOP_Disasm( const SysTraceLogDescriptor* desc ) : _parent( desc ) {}
201 bool IsActive() const
202 {
203 return _parent::IsActive() && EmuConfig.Trace.IOP.m_EnableDisasm;
204 }
205
206 wxString GetCategory() const { return _parent::GetCategory() + L".Disasm"; }
207 };
208
209 class SysTraceLog_IOP_Registers : public SysTraceLog_IOP
210 {
211 typedef SysTraceLog_IOP _parent;
212
213 public:
214 SysTraceLog_IOP_Registers( const SysTraceLogDescriptor* desc ) : _parent( desc ) {}
215 bool IsActive() const
216 {
217 return _parent::IsActive() && EmuConfig.Trace.IOP.m_EnableRegisters;
218 }
219
220 wxString GetCategory() const { return _parent::GetCategory() + L".Registers"; }
221 };
222
223 class SysTraceLog_IOP_Events : public SysTraceLog_IOP
224 {
225 typedef SysTraceLog_IOP _parent;
226
227 public:
228 SysTraceLog_IOP_Events( const SysTraceLogDescriptor* desc ) : _parent( desc ) {}
229 bool IsActive() const
230 {
231 return _parent::IsActive() && EmuConfig.Trace.IOP.m_EnableEvents;
232 }
233
234 wxString GetCategory() const { return _parent::GetCategory() + L".Events"; }
235 };
236
237 // --------------------------------------------------------------------------------------
238 // ConsoleLogFromVM
239 // --------------------------------------------------------------------------------------
240 // Special console logger for Virtual Machine log sources, such as the EE and IOP console
241 // writes (actual game developer messages and such). These logs do *not* automatically
242 // append newlines, since the VM generates them manually; and they do *not* support printf
243 // formatting, since anything coming over the EE/IOP consoles should be considered raw
244 // string data. (otherwise %'s would get mis-interpreted).
245 //
246 template< ConsoleColors conColor >
247 class ConsoleLogFromVM : public BaseTraceLogSource
248 {
249 typedef BaseTraceLogSource _parent;
250
251 public:
252 ConsoleLog_ImplementBaseAPI(ConsoleLogFromVM)
253
254 ConsoleLogFromVM( const TraceLogDescriptor* desc ) : _parent( desc ) {}
255
256 bool Write( const wxChar* msg ) const
257 {
258 ConsoleColorScope cs(conColor);
259 Console.WriteRaw( msg );
260 return false;
261 }
262 };
263
264 // --------------------------------------------------------------------------------------
265 // SysTraceLogPack
266 // --------------------------------------------------------------------------------------
267 struct SysTraceLogPack
268 {
269 // TODO : Sif has special logging needs.. ?
270 SysTraceLog SIF;
271
272 struct EE_PACK
273 {
274 SysTraceLog_EE Bios;
275 SysTraceLog_EE Memory;
276 SysTraceLog_EE GIFtag;
277 SysTraceLog_VIFcode VIFcode;
278
279 SysTraceLog_EE_Disasm R5900;
280 SysTraceLog_EE_Disasm COP0;
281 SysTraceLog_EE_Disasm COP1;
282 SysTraceLog_EE_Disasm COP2;
283 SysTraceLog_EE_Disasm Cache;
284
285 SysTraceLog_EE_Registers KnownHw;
286 SysTraceLog_EE_Registers UnknownHw;
287 SysTraceLog_EE_Registers DMAhw;
288 SysTraceLog_EE_Registers IPU;
289
290 SysTraceLog_EE_Events DMAC;
291 SysTraceLog_EE_Events Counters;
292 SysTraceLog_EE_Events SPR;
293
294 SysTraceLog_EE_Events VIF;
295 SysTraceLog_EE_Events GIF;
296
297 EE_PACK();
298 } EE;
299
300 struct IOP_PACK
301 {
302 SysTraceLog_IOP Bios;
303 SysTraceLog_IOP Memcards;
304 SysTraceLog_IOP PAD;
305
306 SysTraceLog_IOP_Disasm R3000A;
307 SysTraceLog_IOP_Disasm COP2;
308 SysTraceLog_IOP_Disasm Memory;
309
310 SysTraceLog_IOP_Registers KnownHw;
311 SysTraceLog_IOP_Registers UnknownHw;
312 SysTraceLog_IOP_Registers DMAhw;
313
314 // TODO items to be added, or removed? I can't remember which! --air
315 //SysTraceLog_IOP_Registers SPU2;
316 //SysTraceLog_IOP_Registers USB;
317 //SysTraceLog_IOP_Registers FW;
318
319 SysTraceLog_IOP_Events DMAC;
320 SysTraceLog_IOP_Events Counters;
321 SysTraceLog_IOP_Events CDVD;
322
323 IOP_PACK();
324 } IOP;
325
326 SysTraceLogPack();
327 };
328
329 struct SysConsoleLogPack
330 {
331 ConsoleLogSource ELF;
332 ConsoleLogSource eeRecPerf;
333
334 ConsoleLogFromVM<Color_Cyan> eeConsole;
335 ConsoleLogFromVM<Color_Yellow> iopConsole;
336 ConsoleLogFromVM<Color_Cyan> deci2;
337
338 SysConsoleLogPack();
339 };
340
341
342 extern SysTraceLogPack SysTrace;
343 extern SysConsoleLogPack SysConsole;
344
345 extern void __Log( const char* fmt, ... );
346
347 // Helper macro for cut&paste. Note that we intentionally use a top-level *inline* bitcheck
348 // against Trace.Enabled, to avoid extra overhead in Debug builds when logging is disabled.
349 // (specifically this allows debug builds to skip havingto resolve all the parameters being
350 // passed into the function)
351 #ifdef PCSX2_DEVBUILD
352 # define SysTraceActive(trace) SysTrace.trace.IsActive()
353 # define macTrace(trace) SysTraceActive(trace) && SysTrace.trace.Write
354 #else
355 # define SysTraceActive(trace) (false)
356 # define macTrace(trace)
357 #endif
358
359 #define SIF_LOG macTrace(SIF)
360
361 #define BIOS_LOG macTrace(EE.Bios)
362 #define CPU_LOG macTrace(EE.R5900)
363 #define COP0_LOG macTrace(EE.COP0)
364 #define VUM_LOG macTrace(EE.COP2)
365 #define MEM_LOG macTrace(EE.Memory)
366 #define CACHE_LOG macTrace(EE.Cache)
367 #define HW_LOG macTrace(EE.KnownHw)
368 #define UnknownHW_LOG macTrace(EE.UnknownHw)
369 #define DMA_LOG macTrace(EE.DMAhw)
370 #define IPU_LOG macTrace(EE.IPU)
371 #define VIF_LOG macTrace(EE.VIF)
372 #define SPR_LOG macTrace(EE.SPR)
373 #define GIF_LOG macTrace(EE.GIF)
374 #define EECNT_LOG macTrace(EE.Counters)
375 #define VifCodeLog macTrace(EE.VIFcode)
376
377
378 #define PSXBIOS_LOG macTrace(IOP.Bios)
379 #define PSXCPU_LOG macTrace(IOP.R3000A)
380 #define PSXMEM_LOG macTrace(IOP.Memory)
381 #define PSXHW_LOG macTrace(IOP.KnownHw)
382 #define PSXUnkHW_LOG macTrace(IOP.UnknownHw)
383 #define PSXDMA_LOG macTrace(IOP.DMAhw)
384 #define PSXCNT_LOG macTrace(IOP.Counters)
385 #define MEMCARDS_LOG macTrace(IOP.Memcards)
386 #define PAD_LOG macTrace(IOP.PAD)
387 #define GPU_LOG macTrace(IOP.GPU)
388 #define CDVD_LOG macTrace(IOP.CDVD)
389
390
391 #define ELF_LOG SysConsole.ELF.IsActive() && SysConsole.ELF.Write
392 #define eeRecPerfLog SysConsole.eeRecPerf.IsActive() && SysConsole.eeRecPerf
393 #define eeConLog SysConsole.eeConsole.IsActive() && SysConsole.eeConsole.Write
394 #define eeDeci2Log SysConsole.deci2.IsActive() && SysConsole.deci2.Write
395 #define iopConLog SysConsole.iopConsole.IsActive()&& SysConsole.iopConsole.Write

  ViewVC Help
Powered by ViewVC 1.1.22