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 /* FIXME: convert to using G_STRLOC all the way if we can ! */
38 #ifdef G_GNUC_PRETTY_FUNCTION
39 #define FUNCTION G_GNUC_PRETTY_FUNCTION
41 #define FUNCTION __func__
42 #elif HAVE_PRETTY_FUNCTION
43 #define FUNCTION __PRETTY_FUNCTION__
45 #define FUNCTION __FUNCTION__
49 #endif /* ifndef FUNCTION */
51 /***** are we in the core or not? *****/
52 #ifdef __GST_PRIVATE_H__
53 #define _GST_DEBUG_INCORE TRUE
55 #define _GST_DEBUG_INCORE FALSE
59 /* colorization stuff */
60 #ifdef GST_DEBUG_COLOR
61 #ifdef __GST_PRIVATE_H__ /* FIXME this should be some libgst.la -specific thing */
62 #define GST_DEBUG_CHAR_MODE "00"
64 #define GST_DEBUG_CHAR_MODE "01"
68 gint _gst_debug_stringhash_color(gchar *file);
72 /**********************************************************************
74 **********************************************************************/
76 const gchar * gst_get_category_name (gint category);
79 GST_CAT_GST_INIT = 0, /* Library initialization */
80 GST_CAT_COTHREADS, /* Cothread creation, etc. */
81 GST_CAT_COTHREAD_SWITCH, /* Cothread switching */
82 GST_CAT_AUTOPLUG, /* Successful autoplug results */
83 GST_CAT_AUTOPLUG_ATTEMPT, /* Attempted autoplug operations */
84 GST_CAT_PARENTAGE, /* GstBin parentage issues */
85 GST_CAT_STATES, /* State changes and such */
86 GST_CAT_PLANNING, /* Plan generation */
87 GST_CAT_SCHEDULING, /* Schedule construction */
88 GST_CAT_DATAFLOW, /* Events during actual data movement */
89 GST_CAT_BUFFER, /* Buffer creation/destruction */
90 GST_CAT_CAPS, /* Capabilities matching */
91 GST_CAT_CLOCK, /* Clocking */
92 GST_CAT_ELEMENT_PADS, /* Element pad management */
93 GST_CAT_ELEMENT_FACTORY, /* Elementfactory stuff */
94 GST_CAT_PADS, /* Pad creation/linking */
95 GST_CAT_PIPELINE, /* Pipeline stuff */
96 GST_CAT_PLUGIN_LOADING, /* Plugin loading */
97 GST_CAT_PLUGIN_ERRORS, /* Errors during plugin loading */
98 GST_CAT_PLUGIN_INFO, /* Plugin state information */
99 GST_CAT_PROPERTIES, /* Properties */
100 GST_CAT_THREAD, /* Thread creation/management */
101 GST_CAT_TYPES, /* Typing */
102 GST_CAT_XML, /* XML load/save of everything */
103 GST_CAT_NEGOTIATION, /* Caps Negotiation stuff */
104 GST_CAT_REFCOUNTING, /* Ref Counting stuff */
105 GST_CAT_EVENT, /* Event system */
106 GST_CAT_PARAMS, /* Dynamic parameters */
108 GST_CAT_CALL_TRACE = 30, /* Call tracing */
110 GST_CAT_MAX_CATEGORY = 31
113 extern const gchar *_gst_category_colors[32];
115 extern GStaticPrivate _gst_debug_cothread_index;
118 /**********************************************************************
120 **********************************************************************/
122 /* for include files that make too much noise normally */
123 #ifdef GST_DEBUG_FORCE_DISABLE
124 #undef GST_DEBUG_ENABLED
126 /* for applications that really really want all the noise */
127 #ifdef GST_DEBUG_FORCE_ENABLE
128 #define GST_DEBUG_ENABLED
131 /*#ifdef GST_DEBUG_ENABLED */
132 #define GST_DEBUG_ENABLE_CATEGORIES 0xffffffff
134 /*#define GST_DEBUG_ENABLE_CATEGORIES 0x00000000 */
138 typedef void (*GstDebugHandler) (gint category,gboolean core,
139 const gchar *file,const gchar *function,
140 gint line,const gchar *debug_string,
141 void *element,gchar *string);
143 void gst_default_debug_handler (gint category,gboolean incore,
144 const gchar *file, const gchar *function,
145 gint line,const gchar *debug_string,
146 void *element,gchar *string);
148 extern guint32 _gst_debug_categories;
149 extern GstDebugHandler _gst_debug_handler;
151 /* fallback, this should probably be a 'weak' symbol or something */
152 G_GNUC_UNUSED static gchar *_debug_string = NULL;
156 #ifdef G_HAVE_ISO_VARARGS
158 #ifdef GST_DEBUG_ENABLED
159 #define GST_DEBUG(cat, ...) G_STMT_START{ \
160 if ((1<<cat) & _gst_debug_categories) \
161 _gst_debug_handler(cat,_GST_DEBUG_INCORE,__FILE__,FUNCTION,__LINE__,_debug_string, \
162 NULL,g_strdup_printf( __VA_ARGS__ )); \
165 #define GST_DEBUG_ELEMENT(cat, element, ...) G_STMT_START{ \
166 if ((1<<cat) & _gst_debug_categories) \
167 _gst_debug_handler(cat,_GST_DEBUG_INCORE,__FILE__,FUNCTION,__LINE__,_debug_string, \
168 element,g_strdup_printf( __VA_ARGS__ )); \
172 #define GST_DEBUG(cat, ...)
173 #define GST_DEBUG_ELEMENT(cat,element, ...)
176 #elif defined(G_HAVE_GNUC_VARARGS)
178 #ifdef GST_DEBUG_ENABLED
179 #define GST_DEBUG(cat,format,args...) G_STMT_START{ \
180 if ((1<<cat) & _gst_debug_categories) \
181 _gst_debug_handler(cat,_GST_DEBUG_INCORE,__FILE__,FUNCTION,__LINE__,_debug_string, \
182 NULL,g_strdup_printf( format , ## args )); \
185 #define GST_DEBUG_ELEMENT(cat,element,format,args...) G_STMT_START{ \
186 if ((1<<cat) & _gst_debug_categories) \
187 _gst_debug_handler(cat,_GST_DEBUG_INCORE,__FILE__,FUNCTION,__LINE__,_debug_string, \
188 element,g_strdup_printf( format , ## args )); \
192 #define GST_DEBUG(cat,format,args...)
193 #define GST_DEBUG_ELEMENT(cat,element,format,args...)
201 /********** some convenience macros for debugging **********/
202 #define GST_DEBUG_PAD_NAME(pad) \
203 (GST_OBJECT_PARENT(pad) != NULL) ? \
204 GST_OBJECT_NAME (GST_OBJECT_PARENT(pad)) : \
205 "''", GST_OBJECT_NAME (pad)
207 #ifdef G_HAVE_ISO_VARARGS
209 #ifdef GST_DEBUG_COLOR
210 #define GST_DEBUG_ENTER(...) GST_DEBUG( 31 , "\033[00;37mentering\033[00m: " __VA_ARGS__ )
211 #define GST_DEBUG_LEAVE(...) GST_DEBUG( 31 , "\033[00;37mleaving\033[00m: " __VA_ARGS__ )
213 #define GST_DEBUG_ENTER(...) GST_DEBUG( 31 , "entering: " __VA_ARGS__ )
214 #define GST_DEBUG_LEAVE(...) GST_DEBUG( 31 , "leaving: " __VA_ARGS__ )
217 #elif defined(G_HAVE_GNUC_VARARGS)
219 #ifdef GST_DEBUG_COLOR
220 #define GST_DEBUG_ENTER(format, args...) GST_DEBUG( 31 , format ": \033[00;37mentering\033[00m" , ##args )
221 #define GST_DEBUG_LEAVE(format, args...) GST_DEBUG( 31 , format ": \033[00;37mleaving\033[00m" , ##args )
223 #define GST_DEBUG_ENTER(format, args...) GST_DEBUG( 31 , format ": entering" , ##args )
224 #define GST_DEBUG_LEAVE(format, args...) GST_DEBUG( 31 , format ": leaving" , ##args )
230 /***** Colorized debug for thread ids *****/
231 #ifdef GST_DEBUG_COLOR
232 #define GST_DEBUG_THREAD_FORMAT "\033[00;%dm%d\033[00m"
233 #define GST_DEBUG_THREAD_ARGS(id) ( ((id) < 0) ? 37 : ((id) % 6 + 31) ), (id)
235 #define GST_DEBUG_THREAD_FORMAT "%d"
236 #define GST_DEBUG_THREAD_ARGS(id) (id)
241 /**********************************************************************
242 * The following is a DEBUG_ENTER implementation that will wrap the
243 * function it sits at the head of. It removes the need for a
244 * DEBUG_LEAVE call. However, it segfaults whenever it gets anywhere
245 * near cothreads. We will not use it for the moment.
247 typedef void (*_debug_function_f)();
248 G_GNUC_UNUSED static gchar *_debug_string_pointer = NULL;
249 G_GNUC_UNUSED static GModule *_debug_self_module = NULL;
251 #ifdef G_HAVE_ISO_VARARGS
253 #define _DEBUG_ENTER_BUILTIN(...) \
254 static int _debug_in_wrapper = 0; \
255 gchar *_debug_string = ({ \
256 if (!_debug_in_wrapper) { \
257 void *_return_value; \
258 gchar *_debug_string; \
259 _debug_function_f function; \
260 void *_function_args = __builtin_apply_args(); \
261 _debug_in_wrapper = 1; \
262 _debug_string = g_strdup_printf(GST_DEBUG_PREFIX("")); \
263 _debug_string_pointer = _debug_string; \
264 fprintf(stderr,"%s: entered " FUNCTION, _debug_string); \
265 fprintf(stderr, __VA_ARGS__ ); \
266 fprintf(stderr,"\n"); \
267 if (_debug_self_module == NULL) _debug_self_module = g_module_open(NULL,0); \
268 g_module_symbol(_debug_self_module,FUNCTION,(gpointer *)&function); \
269 _return_value = __builtin_apply(function,_function_args,64); \
270 fprintf(stderr,"%s: left " FUNCTION, _debug_string); \
271 fprintf(stderr, __VA_ARGS__); \
272 fprintf(stderr,"\n"); \
273 g_free(_debug_string); \
274 __builtin_return(_return_value); \
276 _debug_in_wrapper = 0; \
278 _debug_string_pointer; \
281 #elif defined(G_HAVE_GNUC_VARARGS)
283 #define _DEBUG_ENTER_BUILTIN(format,args...) \
284 static int _debug_in_wrapper = 0; \
285 gchar *_debug_string = ({ \
286 if (!_debug_in_wrapper) { \
287 void *_return_value; \
288 gchar *_debug_string; \
289 _debug_function_f function; \
290 void *_function_args = __builtin_apply_args(); \
291 _debug_in_wrapper = 1; \
292 _debug_string = g_strdup_printf(GST_DEBUG_PREFIX("")); \
293 _debug_string_pointer = _debug_string; \
294 fprintf(stderr,"%s: entered " FUNCTION format "\n" , _debug_string , ## args ); \
295 if (_debug_self_module == NULL) _debug_self_module = g_module_open(NULL,0); \
296 g_module_symbol(_debug_self_module,FUNCTION,(gpointer *)&function); \
297 _return_value = __builtin_apply(function,_function_args,64); \
298 fprintf(stderr,"%s: left " FUNCTION format "\n" , _debug_string , ## args ); \
299 g_free(_debug_string); \
300 __builtin_return(_return_value); \
302 _debug_in_wrapper = 0; \
304 _debug_string_pointer; \
309 * WARNING: there's a gcc CPP bug lurking in here. The extra space before the ##args *
310 * somehow make the preprocessor leave the _debug_string. If it's removed, the *
311 * _debug_string somehow gets stripped along with the ##args, and that's all she wrote. *
313 #ifdef G_HAVE_ISO_VARARGS
315 #define _DEBUG_BUILTIN(...) \
316 if (_debug_string != (void *)-1) { \
317 if (_debug_string) { \
318 fprintf(stderr, "%s: " _debug_string); \
319 fprintf(stderr, __VA_ARGS__); \
321 fprintf(stderr,GST_DEBUG_PREFIX(": " __VA_ARGS__)); \
325 #elif defined(G_HAVE_GNUC_VARARGS)
327 #define _DEBUG_BUILTIN(format,args...) \
328 if (_debug_string != (void *)-1) { \
330 fprintf(stderr,"%s: " format , _debug_string , ## args); \
332 fprintf(stderr,GST_DEBUG_PREFIX(": " format , ## args)); \
341 /**********************************************************************
343 **********************************************************************/
345 typedef void (*GstInfoHandler) (gint category,gboolean incore,
346 const gchar *file,const gchar *function,
347 gint line,const gchar *debug_string,
348 void *element,gchar *string);
350 void gst_default_info_handler (gint category,gboolean incore,
351 const gchar *file,const gchar *function,
352 gint line,const gchar *debug_string,
353 void *element,gchar *string);
355 inline void * _gst_debug_register_funcptr (void *ptr, gchar *ptrname);
357 extern GstInfoHandler _gst_info_handler;
358 extern guint32 _gst_info_categories;
360 /* for include files that make too much noise normally */
361 #ifdef GST_INFO_FORCE_DISABLE
362 #undef GST_INFO_ENABLED
364 /* for applications that really really want all the noise */
365 #ifdef GST_INFO_FORCE_ENABLE
366 #define GST_INFO_ENABLED
369 #ifdef G_HAVE_ISO_VARARGS
371 #ifdef GST_INFO_ENABLED
372 #define GST_INFO(cat,...) G_STMT_START{ \
373 if ((1<<cat) & _gst_info_categories) \
374 _gst_info_handler(cat,_GST_DEBUG_INCORE,__FILE__,FUNCTION,__LINE__,_debug_string, \
375 NULL,g_strdup_printf( __VA_ARGS__ )); \
378 #define GST_INFO_ELEMENT(cat,element,...) G_STMT_START{ \
379 if ((1<<cat) & _gst_info_categories) \
380 _gst_info_handler(cat,_GST_DEBUG_INCORE,__FILE__,FUNCTION,__LINE__,_debug_string, \
381 element,g_strdup_printf( __VA_ARGS__ )); \
385 #define GST_INFO(cat,...)
386 #define GST_INFO_ELEMENT(cat,element,...)
389 #elif defined(G_HAVE_GNUC_VARARGS)
391 #ifdef GST_INFO_ENABLED
392 #define GST_INFO(cat,format,args...) G_STMT_START{ \
393 if ((1<<cat) & _gst_info_categories) \
394 _gst_info_handler(cat,_GST_DEBUG_INCORE,__FILE__,FUNCTION,__LINE__,_debug_string, \
395 NULL,g_strdup_printf( format , ## args )); \
398 #define GST_INFO_ELEMENT(cat,element,format,args...) G_STMT_START{ \
399 if ((1<<cat) & _gst_info_categories) \
400 _gst_info_handler(cat,_GST_DEBUG_INCORE,__FILE__,FUNCTION,__LINE__,_debug_string, \
401 element,g_strdup_printf( format , ## args )); \
405 #define GST_INFO(cat,format,args...)
406 #define GST_INFO_ELEMENT(cat,element,format,args...)
412 void gst_info_set_categories (guint32 categories);
413 guint32 gst_info_get_categories (void);
414 void gst_info_enable_category (gint category);
415 void gst_info_disable_category (gint category);
417 void gst_debug_set_categories (guint32 categories);
418 guint32 gst_debug_get_categories (void);
419 void gst_debug_enable_category (gint category);
420 void gst_debug_disable_category (gint category);
425 /**********************************************************************
427 **********************************************************************/
429 typedef void (*GstErrorHandler) (gchar *file,gchar *function,
430 gint line,gchar *debug_string,
431 void *element,void *object,gchar *string);
433 void gst_default_error_handler (gchar *file,gchar *function,
434 gint line,gchar *debug_string,
435 void *element,void *object,gchar *string);
437 extern GstErrorHandler _gst_error_handler;
439 #ifdef G_HAVE_ISO_VARARGS
441 #define GST_ERROR(element,...) \
442 _gst_error_handler(__FILE__,FUNCTION,__LINE__,_debug_string, \
443 element,NULL,g_strdup_printf( __VA_ARGS__ ))
445 #define GST_ERROR_OBJECT(element,object,...) \
446 _gst_error_handler(__FILE__,FUNCTION,__LINE__,_debug_string, \
447 element,object,g_strdup_printf( __VA_ARGS__ ))
449 #elif defined(G_HAVE_GNUC_VARARGS)
451 #define GST_ERROR(element,format,args...) \
452 _gst_error_handler(__FILE__,FUNCTION,__LINE__,_debug_string, \
453 element,NULL,g_strdup_printf( format , ## args ))
455 #define GST_ERROR_OBJECT(element,object,format,args...) \
456 _gst_error_handler(__FILE__,FUNCTION,__LINE__,_debug_string, \
457 element,object,g_strdup_printf( format , ## args ))
464 /********** function pointer stuff **********/
465 extern GHashTable *__gst_function_pointers;
467 #if GST_DEBUG_ENABLED
468 #define GST_DEBUG_FUNCPTR(ptr) _gst_debug_register_funcptr((void *)(ptr), #ptr)
469 #define GST_DEBUG_FUNCPTR_NAME(ptr) _gst_debug_nameof_funcptr((void *)ptr)
471 #define GST_DEBUG_FUNCPTR(ptr) (ptr)
472 #define GST_DEBUG_FUNCPTR_NAME(ptr) ""
473 #endif /* GST_DEBUG_ENABLED */
475 gchar *_gst_debug_nameof_funcptr (void *ptr);
477 void gst_debug_print_stack_trace (void);
479 #endif /* __GSTINFO_H__ */