2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
29 #include <glib/gmacros.h>
35 /* This is needed in printf's if a char* might be NULL. Solaris crashes then */
36 #define GST_STR_NULL(str) ((str) ? (str) : "(NULL)")
38 /* FIXME: convert to using G_STRLOC all the way if we can ! */
41 #ifdef G_GNUC_PRETTY_FUNCTION
42 #define FUNCTION G_GNUC_PRETTY_FUNCTION
44 #define FUNCTION __func__
45 #elif HAVE_PRETTY_FUNCTION
46 #define FUNCTION __PRETTY_FUNCTION__
48 #define FUNCTION __FUNCTION__
52 #endif /* ifndef FUNCTION */
54 /***** are we in the core or not? *****/
55 #ifdef __GST_PRIVATE_H__
56 #define _GST_DEBUG_INCORE TRUE
58 #define _GST_DEBUG_INCORE FALSE
62 /* colorization stuff */
63 #ifdef GST_DEBUG_COLOR
64 #ifdef __GST_PRIVATE_H__ /* FIXME this should be some libgst.la -specific thing */
65 #define GST_DEBUG_CHAR_MODE "00"
67 #define GST_DEBUG_CHAR_MODE "01"
71 gint _gst_debug_stringhash_color(gchar *file);
75 /**********************************************************************
77 **********************************************************************/
79 const gchar * gst_get_category_name (gint category);
82 GST_CAT_GST_INIT = 0, /* Library initialization */
83 GST_CAT_COTHREADS, /* Cothread creation, etc. */
84 GST_CAT_COTHREAD_SWITCH, /* Cothread switching */
85 GST_CAT_AUTOPLUG, /* Successful autoplug results */
86 GST_CAT_AUTOPLUG_ATTEMPT, /* Attempted autoplug operations */
87 GST_CAT_PARENTAGE, /* GstBin parentage issues */
88 GST_CAT_STATES, /* State changes and such */
89 GST_CAT_PLANNING, /* Plan generation */
90 GST_CAT_SCHEDULING, /* Schedule construction */
91 GST_CAT_DATAFLOW, /* Events during actual data movement */
92 GST_CAT_BUFFER, /* Buffer creation/destruction */
93 GST_CAT_CAPS, /* Capabilities matching */
94 GST_CAT_CLOCK, /* Clocking */
95 GST_CAT_ELEMENT_PADS, /* Element pad management */
96 GST_CAT_ELEMENT_FACTORY, /* Elementfactory stuff */
97 GST_CAT_PADS, /* Pad creation/linking */
98 GST_CAT_PIPELINE, /* Pipeline stuff */
99 GST_CAT_PLUGIN_LOADING, /* Plugin loading */
100 GST_CAT_PLUGIN_ERRORS, /* Errors during plugin loading */
101 GST_CAT_PLUGIN_INFO, /* Plugin state information */
102 GST_CAT_PROPERTIES, /* Properties */
103 GST_CAT_THREAD, /* Thread creation/management */
104 GST_CAT_TYPES, /* Typing */
105 GST_CAT_XML, /* XML load/save of everything */
106 GST_CAT_NEGOTIATION, /* Caps Negotiation stuff */
107 GST_CAT_REFCOUNTING, /* Ref Counting stuff */
108 GST_CAT_EVENT, /* Event system */
109 GST_CAT_PARAMS, /* Dynamic parameters */
111 GST_CAT_CALL_TRACE = 30, /* Call tracing */
113 GST_CAT_MAX_CATEGORY = 31
116 extern const gchar *_gst_category_colors[32];
118 extern GStaticPrivate _gst_debug_cothread_index;
121 /**********************************************************************
123 **********************************************************************/
125 /* for include files that make too much noise normally */
126 #ifdef GST_DEBUG_FORCE_DISABLE
127 #undef GST_DEBUG_ENABLED
129 /* for applications that really really want all the noise */
130 #ifdef GST_DEBUG_FORCE_ENABLE
131 #define GST_DEBUG_ENABLED
134 /*#ifdef GST_DEBUG_ENABLED */
135 #define GST_DEBUG_ENABLE_CATEGORIES 0xffffffff
137 /*#define GST_DEBUG_ENABLE_CATEGORIES 0x00000000 */
141 typedef void (*GstDebugHandler) (gint category,gboolean core,
142 const gchar *file,const gchar *function,
143 gint line,const gchar *debug_string,
144 void *element,gchar *string);
146 void gst_default_debug_handler (gint category,gboolean incore,
147 const gchar *file, const gchar *function,
148 gint line,const gchar *debug_string,
149 void *element,gchar *string);
151 extern guint32 _gst_debug_categories;
152 extern GstDebugHandler _gst_debug_handler;
154 /* fallback, this should probably be a 'weak' symbol or something */
155 G_GNUC_UNUSED static gchar *_debug_string = NULL;
159 #ifdef G_HAVE_ISO_VARARGS
161 #ifdef GST_DEBUG_ENABLED
162 #define GST_DEBUG(cat, ...) G_STMT_START{ \
163 if ((1<<cat) & _gst_debug_categories) \
164 _gst_debug_handler(cat,_GST_DEBUG_INCORE,__FILE__,FUNCTION,__LINE__,_debug_string, \
165 NULL,g_strdup_printf( __VA_ARGS__ )); \
168 #define GST_DEBUG_ELEMENT(cat, element, ...) G_STMT_START{ \
169 if ((1<<cat) & _gst_debug_categories) \
170 _gst_debug_handler(cat,_GST_DEBUG_INCORE,__FILE__,FUNCTION,__LINE__,_debug_string, \
171 element,g_strdup_printf( __VA_ARGS__ )); \
175 #define GST_DEBUG(cat, ...)
176 #define GST_DEBUG_ELEMENT(cat,element, ...)
179 #elif defined(G_HAVE_GNUC_VARARGS)
181 #ifdef GST_DEBUG_ENABLED
182 #define GST_DEBUG(cat,format,args...) G_STMT_START{ \
183 if ((1<<cat) & _gst_debug_categories) \
184 _gst_debug_handler(cat,_GST_DEBUG_INCORE,__FILE__,FUNCTION,__LINE__,_debug_string, \
185 NULL,g_strdup_printf( format , ## args )); \
188 #define GST_DEBUG_ELEMENT(cat,element,format,args...) G_STMT_START{ \
189 if ((1<<cat) & _gst_debug_categories) \
190 _gst_debug_handler(cat,_GST_DEBUG_INCORE,__FILE__,FUNCTION,__LINE__,_debug_string, \
191 element,g_strdup_printf( format , ## args )); \
195 #define GST_DEBUG(cat,format,args...)
196 #define GST_DEBUG_ELEMENT(cat,element,format,args...)
204 /********** some convenience macros for debugging **********/
205 #define GST_DEBUG_PAD_NAME(pad) \
206 (GST_OBJECT_PARENT(pad) != NULL) ? \
207 GST_OBJECT_NAME (GST_OBJECT_PARENT(pad)) : \
208 "''", GST_OBJECT_NAME (pad)
210 #ifdef G_HAVE_ISO_VARARGS
212 #ifdef GST_DEBUG_COLOR
213 #define GST_DEBUG_ENTER(...) GST_DEBUG( 31 , "\033[00;37mentering\033[00m: " __VA_ARGS__ )
214 #define GST_DEBUG_LEAVE(...) GST_DEBUG( 31 , "\033[00;37mleaving\033[00m: " __VA_ARGS__ )
216 #define GST_DEBUG_ENTER(...) GST_DEBUG( 31 , "entering: " __VA_ARGS__ )
217 #define GST_DEBUG_LEAVE(...) GST_DEBUG( 31 , "leaving: " __VA_ARGS__ )
220 #elif defined(G_HAVE_GNUC_VARARGS)
222 #ifdef GST_DEBUG_COLOR
223 #define GST_DEBUG_ENTER(format, args...) GST_DEBUG( 31 , format ": \033[00;37mentering\033[00m" , ##args )
224 #define GST_DEBUG_LEAVE(format, args...) GST_DEBUG( 31 , format ": \033[00;37mleaving\033[00m" , ##args )
226 #define GST_DEBUG_ENTER(format, args...) GST_DEBUG( 31 , format ": entering" , ##args )
227 #define GST_DEBUG_LEAVE(format, args...) GST_DEBUG( 31 , format ": leaving" , ##args )
233 /***** Colorized debug for thread ids *****/
234 #ifdef GST_DEBUG_COLOR
235 #define GST_DEBUG_THREAD_FORMAT "\033[00;%dm%d\033[00m"
236 #define GST_DEBUG_THREAD_ARGS(id) ( ((id) < 0) ? 37 : ((id) % 6 + 31) ), (id)
238 #define GST_DEBUG_THREAD_FORMAT "%d"
239 #define GST_DEBUG_THREAD_ARGS(id) (id)
244 /**********************************************************************
245 * The following is a DEBUG_ENTER implementation that will wrap the
246 * function it sits at the head of. It removes the need for a
247 * DEBUG_LEAVE call. However, it segfaults whenever it gets anywhere
248 * near cothreads. We will not use it for the moment.
250 typedef void (*_debug_function_f)();
251 G_GNUC_UNUSED static gchar *_debug_string_pointer = NULL;
252 G_GNUC_UNUSED static GModule *_debug_self_module = NULL;
254 #ifdef G_HAVE_ISO_VARARGS
256 #define _DEBUG_ENTER_BUILTIN(...) \
257 static int _debug_in_wrapper = 0; \
258 gchar *_debug_string = ({ \
259 if (!_debug_in_wrapper) { \
260 void *_return_value; \
261 gchar *_debug_string; \
262 _debug_function_f function; \
263 void *_function_args = __builtin_apply_args(); \
264 _debug_in_wrapper = 1; \
265 _debug_string = g_strdup_printf(GST_DEBUG_PREFIX("")); \
266 _debug_string_pointer = _debug_string; \
267 fprintf(stderr,"%s: entered " FUNCTION, _debug_string); \
268 fprintf(stderr, __VA_ARGS__ ); \
269 fprintf(stderr,"\n"); \
270 if (_debug_self_module == NULL) _debug_self_module = g_module_open(NULL,0); \
271 g_module_symbol(_debug_self_module,FUNCTION,(gpointer *)&function); \
272 _return_value = __builtin_apply(function,_function_args,64); \
273 fprintf(stderr,"%s: left " FUNCTION, _debug_string); \
274 fprintf(stderr, __VA_ARGS__); \
275 fprintf(stderr,"\n"); \
276 g_free(_debug_string); \
277 __builtin_return(_return_value); \
279 _debug_in_wrapper = 0; \
281 _debug_string_pointer; \
284 #elif defined(G_HAVE_GNUC_VARARGS)
286 #define _DEBUG_ENTER_BUILTIN(format,args...) \
287 static int _debug_in_wrapper = 0; \
288 gchar *_debug_string = ({ \
289 if (!_debug_in_wrapper) { \
290 void *_return_value; \
291 gchar *_debug_string; \
292 _debug_function_f function; \
293 void *_function_args = __builtin_apply_args(); \
294 _debug_in_wrapper = 1; \
295 _debug_string = g_strdup_printf(GST_DEBUG_PREFIX("")); \
296 _debug_string_pointer = _debug_string; \
297 fprintf(stderr,"%s: entered " FUNCTION format "\n" , _debug_string , ## args ); \
298 if (_debug_self_module == NULL) _debug_self_module = g_module_open(NULL,0); \
299 g_module_symbol(_debug_self_module,FUNCTION,(gpointer *)&function); \
300 _return_value = __builtin_apply(function,_function_args,64); \
301 fprintf(stderr,"%s: left " FUNCTION format "\n" , _debug_string , ## args ); \
302 g_free(_debug_string); \
303 __builtin_return(_return_value); \
305 _debug_in_wrapper = 0; \
307 _debug_string_pointer; \
312 * WARNING: there's a gcc CPP bug lurking in here. The extra space before the ##args *
313 * somehow make the preprocessor leave the _debug_string. If it's removed, the *
314 * _debug_string somehow gets stripped along with the ##args, and that's all she wrote. *
316 #ifdef G_HAVE_ISO_VARARGS
318 #define _DEBUG_BUILTIN(...) \
319 if (_debug_string != (void *)-1) { \
320 if (_debug_string) { \
321 fprintf(stderr, "%s: " _debug_string); \
322 fprintf(stderr, __VA_ARGS__); \
324 fprintf(stderr,GST_DEBUG_PREFIX(": " __VA_ARGS__)); \
328 #elif defined(G_HAVE_GNUC_VARARGS)
330 #define _DEBUG_BUILTIN(format,args...) \
331 if (_debug_string != (void *)-1) { \
333 fprintf(stderr,"%s: " format , _debug_string , ## args); \
335 fprintf(stderr,GST_DEBUG_PREFIX(": " format , ## args)); \
344 /**********************************************************************
346 **********************************************************************/
348 typedef void (*GstInfoHandler) (gint category,gboolean incore,
349 const gchar *file,const gchar *function,
350 gint line,const gchar *debug_string,
351 void *element,gchar *string);
353 void gst_default_info_handler (gint category,gboolean incore,
354 const gchar *file,const gchar *function,
355 gint line,const gchar *debug_string,
356 void *element,gchar *string);
358 extern GstInfoHandler _gst_info_handler;
359 extern guint32 _gst_info_categories;
361 /* for include files that make too much noise normally */
362 #ifdef GST_INFO_FORCE_DISABLE
363 #undef GST_INFO_ENABLED
365 /* for applications that really really want all the noise */
366 #ifdef GST_INFO_FORCE_ENABLE
367 #define GST_INFO_ENABLED
370 #ifdef G_HAVE_ISO_VARARGS
372 #ifdef GST_INFO_ENABLED
373 #define GST_INFO(cat,...) G_STMT_START{ \
374 if ((1<<cat) & _gst_info_categories) \
375 _gst_info_handler(cat,_GST_DEBUG_INCORE,__FILE__,FUNCTION,__LINE__,_debug_string, \
376 NULL,g_strdup_printf( __VA_ARGS__ )); \
379 #define GST_INFO_ELEMENT(cat,element,...) G_STMT_START{ \
380 if ((1<<cat) & _gst_info_categories) \
381 _gst_info_handler(cat,_GST_DEBUG_INCORE,__FILE__,FUNCTION,__LINE__,_debug_string, \
382 element,g_strdup_printf( __VA_ARGS__ )); \
386 #define GST_INFO(cat,...)
387 #define GST_INFO_ELEMENT(cat,element,...)
390 #elif defined(G_HAVE_GNUC_VARARGS)
392 #ifdef GST_INFO_ENABLED
393 #define GST_INFO(cat,format,args...) G_STMT_START{ \
394 if ((1<<cat) & _gst_info_categories) \
395 _gst_info_handler(cat,_GST_DEBUG_INCORE,__FILE__,FUNCTION,__LINE__,_debug_string, \
396 NULL,g_strdup_printf( format , ## args )); \
399 #define GST_INFO_ELEMENT(cat,element,format,args...) G_STMT_START{ \
400 if ((1<<cat) & _gst_info_categories) \
401 _gst_info_handler(cat,_GST_DEBUG_INCORE,__FILE__,FUNCTION,__LINE__,_debug_string, \
402 element,g_strdup_printf( format , ## args )); \
406 #define GST_INFO(cat,format,args...)
407 #define GST_INFO_ELEMENT(cat,element,format,args...)
413 void gst_info_set_categories (guint32 categories);
414 guint32 gst_info_get_categories (void);
415 void gst_info_enable_category (gint category);
416 void gst_info_disable_category (gint category);
418 void gst_debug_set_categories (guint32 categories);
419 guint32 gst_debug_get_categories (void);
420 void gst_debug_enable_category (gint category);
421 void gst_debug_disable_category (gint category);
426 /**********************************************************************
428 **********************************************************************/
430 typedef void (*GstErrorHandler) (gchar *file,gchar *function,
431 gint line,gchar *debug_string,
432 void *element,void *object,gchar *string);
434 void gst_default_error_handler (gchar *file,gchar *function,
435 gint line,gchar *debug_string,
436 void *element,void *object,gchar *string);
438 extern GstErrorHandler _gst_error_handler;
440 #ifdef G_HAVE_ISO_VARARGS
442 #define GST_ERROR(element,...) \
443 _gst_error_handler(__FILE__,FUNCTION,__LINE__,_debug_string, \
444 element,NULL,g_strdup_printf( __VA_ARGS__ ))
446 #define GST_ERROR_OBJECT(element,object,...) \
447 _gst_error_handler(__FILE__,FUNCTION,__LINE__,_debug_string, \
448 element,object,g_strdup_printf( __VA_ARGS__ ))
450 #elif defined(G_HAVE_GNUC_VARARGS)
452 #define GST_ERROR(element,format,args...) \
453 _gst_error_handler(__FILE__,FUNCTION,__LINE__,_debug_string, \
454 element,NULL,g_strdup_printf( format , ## args ))
456 #define GST_ERROR_OBJECT(element,object,format,args...) \
457 _gst_error_handler(__FILE__,FUNCTION,__LINE__,_debug_string, \
458 element,object,g_strdup_printf( format , ## args ))
462 /********** function pointer stuff **********/
463 #if GST_DEBUG_ENABLED
464 void* _gst_debug_register_funcptr (void *ptr, gchar *ptrname);
465 gchar* _gst_debug_nameof_funcptr (void *ptr);
467 #define GST_DEBUG_FUNCPTR(ptr) _gst_debug_register_funcptr((void *)(ptr), #ptr)
468 #define GST_DEBUG_FUNCPTR_NAME(ptr) _gst_debug_nameof_funcptr((void *)ptr)
470 #define GST_DEBUG_FUNCPTR(ptr) (ptr)
471 #define GST_DEBUG_FUNCPTR_NAME(ptr) ""
472 #endif /* GST_DEBUG_ENABLED */
474 void gst_debug_print_stack_trace (void);
476 #endif /* __GSTINFO_H__ */