aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/psp/trace.h
blob: 8c113bef81b168083facae7027364efd9c42e55d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * $URL$
 * $Id$
 *
 */


#ifndef TRACE_H
#define TRACE_H

#include <stdio.h>
#include <psptypes.h>
#include <stdarg.h>

// Use these defines for debugging

//#define __PSP_PRINT_TO_FILE__
//#define __PSP_PRINT_TO_FILE_AND_SCREEN__
//#define __PSP_DEBUG_FUNCS__	/* can put this locally too */
//#define __PSP_DEBUG_PRINT__

void PSPDebugTrace(bool alsoToScreen, const char *format, ...);

#ifndef TRACE_C
extern int psp_debug_indent;
#endif

// From here on, we allow multiple definitions
#undef __PSP_PRINT__
#undef PSP_ERROR
#undef __PSP_INDENT__
#undef PSP_INFO_PRINT
#undef PSP_INFO_PRINT_INDENT
#undef PSP_DEBUG_PRINT
#undef PSP_DEBUG_PRINT_FUNC
#undef PSP_DEBUG_PRINT_SAMELN
#undef PSP_DEBUG_DO
#undef DEBUG_ENTER_FUNC
#undef DEBUG_EXIT_FUNC
#undef INLINE

/* Choose to print to file/screen/both */
#ifdef __PSP_PRINT_TO_FILE__
#define __PSP_PRINT__(format,...)			PSPDebugTrace(false, format, ## __VA_ARGS__)
#elif defined __PSP_PRINT_TO_FILE_AND_SCREEN__
#define __PSP_PRINT__(format,...)			PSPDebugTrace(true, format, ## __VA_ARGS__)
#else /* default - print to screen */
#define __PSP_PRINT__(format,...)			fprintf(stderr, format, ## __VA_ARGS__)
#endif /* PSP_PRINT_TO_FILE/SCREEN */

/* Error function */
#define PSP_ERROR(format,...)					__PSP_PRINT__("Error in %s: " format, __PRETTY_FUNCTION__, ## __VA_ARGS__)

/* Do the indent */
#define __PSP_INDENT__							for(int _i=psp_debug_indent; _i>0; _i--) \
													__PSP_PRINT__( "   ")

/* always print */
#define PSP_INFO_PRINT(format,...)				__PSP_PRINT__(format, ## __VA_ARGS__)
/* always print, with indent */
#define PSP_INFO_PRINT_INDENT(format,...)		{ __PSP_INDENT__; \
												__PSP_PRINT__(format, ## __VA_ARGS__); }

#ifdef __PSP_DEBUG_PRINT__
/* printf with indents */
#define PSP_DEBUG_PRINT_SAMELN(format,...)	__PSP_PRINT__(format, ## __VA_ARGS__)
#define PSP_DEBUG_PRINT(format,...)			{ __PSP_INDENT__; \
												__PSP_PRINT__(format, ## __VA_ARGS__); }
#define PSP_DEBUG_PRINT_FUNC(format,...)	{ __PSP_INDENT__; \
												__PSP_PRINT__("In %s: " format, __PRETTY_FUNCTION__, ## __VA_ARGS__); }
#define PSP_DEBUG_DO(x)						(x)

#else	/* no debug print */
#define PSP_DEBUG_PRINT_SAMELN(format,...)
#define PSP_DEBUG_PRINT(format,...)
#define PSP_DEBUG_PRINT_FUNC(format,...)
#define PSP_DEBUG_DO(x)
#endif /* __PSP_DEBUG_PRINT__ */

/* Debugging function calls */
#ifdef __PSP_DEBUG_FUNCS__

// We use this class to print out function calls on the stack in an easy way.
//
#include "common/str.h"
class PSPStackDebugFuncs {
    Common::String _name;

public:
	PSPStackDebugFuncs(const char *name) : _name(name) {
		PSP_INFO_PRINT_INDENT("++ %s\n", _name.c_str());
		psp_debug_indent++;
    }

	~PSPStackDebugFuncs() {
		psp_debug_indent--;
		if (psp_debug_indent < 0)
			PSP_ERROR("debug indent < 0\n");
		PSP_INFO_PRINT_INDENT("-- %s\n", _name.c_str());
	}
};

/* We don't need anything but this line at the beginning of each function to debug function calls */
	#define DEBUG_ENTER_FUNC()					PSPStackDebugFuncs(__PRETTY_FUNCTION__)
#else /* Don't debug function calls */
	#define DEBUG_ENTER_FUNC()
#endif /* __PSP_DEBUG_FUNCS__ */

// Undef the main defines for next time
#undef __PSP_PRINT_TO_FILE__
#undef __PSP_PRINT_TO_FILE_AND_SCREEN__
#undef __PSP_DEBUG_FUNCS__
#undef __PSP_DEBUG_PRINT__

#endif /* TRACE_H */