summaryrefslogtreecommitdiff
path: root/camel/camel-debug.h
blob: 4f3d5ae5adfa6eae4b6a4611a681f32e72dcceb3 (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
135
136
137
138
139
140
141
142
143
144
145
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 *
 * This library is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation.
 *
 * This library 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 Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library. If not, see <http://www.gnu.org/licenses/>.
 *
 * Authors: Michael Zucchi <notzed@ximian.com>
 */

#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
#error "Only <camel/camel.h> can be included directly."
#endif

#ifndef CAMEL_DEBUG_H
#define CAMEL_DEBUG_H

#include <glib.h>

/* This is how the basic debug checking strings should be done */
#define CAMEL_DEBUG_IMAP "imap"
#define CAMEL_DEBUG_IMAP_FOLDER "imap:folder"

G_BEGIN_DECLS

void camel_debug_init (void);
gboolean camel_debug (const gchar *mode);

gboolean camel_debug_start (const gchar *mode);
void camel_debug_end (void);

/**
 * CAMEL_CHECK_GERROR:
 *
 * This sanity checks return values and #GErrors.  If returning
 * failure, make sure the #GError is set.  If returning success,
 * make sure the #GError is NOT set.
 *
 * Example:
 *
 *     success = class->foo (object, some_data, error);
 *     CAMEL_CHECK_GERROR (object, foo, success, error);
 *     return success;
 *
 * Since: 2.32
 */
#define CAMEL_CHECK_GERROR(object, method, expr, error) \
	G_STMT_START { \
	if (expr) { \
		if ((error) != NULL && *(error) != NULL) { \
			g_warning ( \
				"%s::%s() set its GError " \
				"but then reported success", \
				G_OBJECT_TYPE_NAME (object), \
				G_STRINGIFY (method)); \
			g_warning ( \
				"Error message was: %s", \
				(*(error))->message); \
		} \
	} else { \
		if ((error) != NULL && *(error) == NULL) { \
			g_warning ( \
				"%s::%s() reported failure " \
				"without setting its GError", \
				G_OBJECT_TYPE_NAME (object), \
				G_STRINGIFY (method)); \
		} \
	} \
	} G_STMT_END

/**
 * CAMEL_CHECK_LOCAL_GERROR:
 *
 * Same as CAMEL_CHECK_GERROR, but for direct #GError pointers.
 *
 * Example:
 *
 *     success = class->foo (object, some_data, &local_error);
 *     CAMEL_CHECK_LOCAL_GERROR (object, foo, success, local_error);
 *     return success;
 *
 * Since: 3.12
 */
#define CAMEL_CHECK_LOCAL_GERROR(object, method, expr, error) \
	G_STMT_START { \
	if (expr) { \
		if ((error) != NULL) { \
			g_warning ( \
				"%s::%s() set its GError " \
				"but then reported success", \
				G_OBJECT_TYPE_NAME (object), \
				G_STRINGIFY (method)); \
			g_warning ( \
				"Error message was: %s", \
				((error))->message); \
		} \
	} else { \
		if ((error) == NULL) { \
			g_warning ( \
				"%s::%s() reported failure " \
				"without setting its GError", \
				G_OBJECT_TYPE_NAME (object), \
				G_STRINGIFY (method)); \
		} \
	} \
	} G_STMT_END
/**
 * camel_pointer_tracker_track:
 * @ptr: pointer to add to pointer tracker
 *
 * Adds pointer 'ptr' to pointer tracker. Usual use case is to add object
 * to the tracker in GObject::init and remove it from tracker within
 * GObject::finalize. Since the tracker's functions are called, the application
 * prints summary of the pointers on console on exit. If everything gone right
 * then it prints message about all tracked pointers were removed. Otherwise
 * it prints summary of left pointers in the tracker. Added pointer should
 * be removed with pair function camel_pointer_tracker_untrack().
 *
 * See camel_pointer_tracker_dump(), camel_pointer_tracker_track_with_info().
 *
 * Since: 3.6
 **/
#define camel_pointer_tracker_track(ptr) \
	(camel_pointer_tracker_track_with_info ((ptr), G_STRFUNC))

void		camel_pointer_tracker_track_with_info
						(gpointer ptr,
						 const gchar *info);
void		camel_pointer_tracker_untrack	(gpointer ptr);
void		camel_pointer_tracker_dump	(void);

GString *	camel_debug_get_backtrace	(void);

G_END_DECLS

#endif /* CAMEL_DEBUG_H */