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/connection */
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];
117 /**********************************************************************
119 **********************************************************************/
121 /* for include files that make too much noise normally */
122 #ifdef GST_DEBUG_FORCE_DISABLE
123 #undef GST_DEBUG_ENABLED
125 /* for applications that really really want all the noise */
126 #ifdef GST_DEBUG_FORCE_ENABLE
127 #define GST_DEBUG_ENABLED
130 /*#ifdef GST_DEBUG_ENABLED */
131 #define GST_DEBUG_ENABLE_CATEGORIES 0xffffffff
133 /*#define GST_DEBUG_ENABLE_CATEGORIES 0x00000000 */
137 typedef void (*GstDebugHandler) (gint category,gboolean core,
138 const gchar *file,const gchar *function,
139 gint line,const gchar *debug_string,
140 void *element,gchar *string);
142 void gst_default_debug_handler (gint category,gboolean incore,
143 const gchar *file, const gchar *function,
144 gint line,const gchar *debug_string,
145 void *element,gchar *string);
147 extern guint32 _gst_debug_categories;
148 extern GstDebugHandler _gst_debug_handler;
150 /* fallback, this should probably be a 'weak' symbol or something */
151 G_GNUC_UNUSED static gchar *_debug_string = NULL;
155 #ifdef G_HAVE_ISO_VARARGS
157 #ifdef GST_DEBUG_ENABLED
158 #define GST_DEBUG(cat, ...) G_STMT_START{ \
159 if ((1<<cat) & _gst_debug_categories) \
160 _gst_debug_handler(cat,_GST_DEBUG_INCORE,__FILE__,FUNCTION,__LINE__,_debug_string, \
161 NULL,g_strdup_printf( __VA_ARGS__ )); \
164 #define GST_DEBUG_ELEMENT(cat, element, ...) G_STMT_START{ \
165 if ((1<<cat) & _gst_debug_categories) \
166 _gst_debug_handler(cat,_GST_DEBUG_INCORE,__FILE__,FUNCTION,__LINE__,_debug_string, \
167 element,g_strdup_printf( __VA_ARGS__ )); \
171 #define GST_DEBUG(cat, ...)
172 #define GST_DEBUG_ELEMENT(cat,element, ...)
175 #elif defined(G_HAVE_GNUC_VARARGS)
177 #ifdef GST_DEBUG_ENABLED
178 #define GST_DEBUG(cat,format,args...) G_STMT_START{ \
179 if ((1<<cat) & _gst_debug_categories) \
180 _gst_debug_handler(cat,_GST_DEBUG_INCORE,__FILE__,FUNCTION,__LINE__,_debug_string, \
181 NULL,g_strdup_printf( format , ## args )); \
184 #define GST_DEBUG_ELEMENT(cat,element,format,args...) G_STMT_START{ \
185 if ((1<<cat) & _gst_debug_categories) \
186 _gst_debug_handler(cat,_GST_DEBUG_INCORE,__FILE__,FUNCTION,__LINE__,_debug_string, \
187 element,g_strdup_printf( format , ## args )); \
191 #define GST_DEBUG(cat,format,args...)
192 #define GST_DEBUG_ELEMENT(cat,element,format,args...)
200 /********** some convenience macros for debugging **********/
201 #define GST_DEBUG_PAD_NAME(pad) \
202 (GST_OBJECT_PARENT(pad) != NULL) ? \
203 GST_OBJECT_NAME (GST_OBJECT_PARENT(pad)) : \
204 "''", GST_OBJECT_NAME (pad)
206 #ifdef G_HAVE_ISO_VARARGS
208 #ifdef GST_DEBUG_COLOR
209 #define GST_DEBUG_ENTER(...) GST_DEBUG( 31 , "\033[00;37mentering\033[00m :" __VA_ARGS__ )
210 #define GST_DEBUG_LEAVE(...) GST_DEBUG( 31 , "\033[00;37mleaving\033[00m :" __VA_ARGS__ )
212 #define GST_DEBUG_ENTER(...) GST_DEBUG( 31 , "entering :" __VA_ARGS__ )
213 #define GST_DEBUG_LEAVE(...) GST_DEBUG( 31 , "leaving :" __VA_ARGS__ )
216 #elif defined(G_HAVE_GNUC_VARARGS)
218 #ifdef GST_DEBUG_COLOR
219 #define GST_DEBUG_ENTER(format, args...) GST_DEBUG( 31 , format ": \033[00;37mentering\033[00m" , ##args )
220 #define GST_DEBUG_LEAVE(format, args...) GST_DEBUG( 31 , format ": \033[00;37mleaving\033[00m" , ##args )
222 #define GST_DEBUG_ENTER(format, args...) GST_DEBUG( 31 , format ": entering" , ##args )
223 #define GST_DEBUG_LEAVE(format, args...) GST_DEBUG( 31 , format ": leaving" , ##args )
229 /***** Colorized debug for thread ids *****/
230 #ifdef GST_DEBUG_COLOR
231 #define GST_DEBUG_THREAD_FORMAT "\033[00;%dm%d\033[00m"
232 #define GST_DEBUG_THREAD_ARGS(id) ( ((id) < 0) ? 37 : ((id) % 6 + 31) ), (id)
234 #define GST_DEBUG_THREAD_FORMAT "%d"
235 #define GST_DEBUG_THREAD_ARGS(id) (id)
240 /**********************************************************************
241 * The following is a DEBUG_ENTER implementation that will wrap the
242 * function it sits at the head of. It removes the need for a
243 * DEBUG_LEAVE call. However, it segfaults whenever it gets anywhere
244 * near cothreads. We will not use it for the moment.
246 typedef void (*_debug_function_f)();
247 G_GNUC_UNUSED static gchar *_debug_string_pointer = NULL;
248 G_GNUC_UNUSED static GModule *_debug_self_module = NULL;
250 #ifdef G_HAVE_ISO_VARARGS
252 #define _DEBUG_ENTER_BUILTIN(...) \
253 static int _debug_in_wrapper = 0; \
254 gchar *_debug_string = ({ \
255 if (!_debug_in_wrapper) { \
256 void *_return_value; \
257 gchar *_debug_string; \
258 _debug_function_f function; \
259 void *_function_args = __builtin_apply_args(); \
260 _debug_in_wrapper = 1; \
261 _debug_string = g_strdup_printf(GST_DEBUG_PREFIX("")); \
262 _debug_string_pointer = _debug_string; \
263 fprintf(stderr,"%s: entered " FUNCTION, _debug_string); \
264 fprintf(stderr, __VA_ARGS__ ); \
265 fprintf(stderr,"\n"); \
266 if (_debug_self_module == NULL) _debug_self_module = g_module_open(NULL,0); \
267 g_module_symbol(_debug_self_module,FUNCTION,(gpointer *)&function); \
268 _return_value = __builtin_apply(function,_function_args,64); \
269 fprintf(stderr,"%s: left " FUNCTION, _debug_string); \
270 fprintf(stderr, __VA_ARGS__); \
271 fprintf(stderr,"\n"); \
272 g_free(_debug_string); \
273 __builtin_return(_return_value); \
275 _debug_in_wrapper = 0; \
277 _debug_string_pointer; \
280 #elif defined(G_HAVE_GNUC_VARARGS)
282 #define _DEBUG_ENTER_BUILTIN(format,args...) \
283 static int _debug_in_wrapper = 0; \
284 gchar *_debug_string = ({ \
285 if (!_debug_in_wrapper) { \
286 void *_return_value; \
287 gchar *_debug_string; \
288 _debug_function_f function; \
289 void *_function_args = __builtin_apply_args(); \
290 _debug_in_wrapper = 1; \
291 _debug_string = g_strdup_printf(GST_DEBUG_PREFIX("")); \
292 _debug_string_pointer = _debug_string; \
293 fprintf(stderr,"%s: entered " FUNCTION format "\n" , _debug_string , ## args ); \
294 if (_debug_self_module == NULL) _debug_self_module = g_module_open(NULL,0); \
295 g_module_symbol(_debug_self_module,FUNCTION,(gpointer *)&function); \
296 _return_value = __builtin_apply(function,_function_args,64); \
297 fprintf(stderr,"%s: left " FUNCTION format "\n" , _debug_string , ## args ); \
298 g_free(_debug_string); \
299 __builtin_return(_return_value); \
301 _debug_in_wrapper = 0; \
303 _debug_string_pointer; \
308 * WARNING: there's a gcc CPP bug lurking in here. The extra space before the ##args *
309 * somehow make the preprocessor leave the _debug_string. If it's removed, the *
310 * _debug_string somehow gets stripped along with the ##args, and that's all she wrote. *
312 #ifdef G_HAVE_ISO_VARARGS
314 #define _DEBUG_BUILTIN(...) \
315 if (_debug_string != (void *)-1) { \
316 if (_debug_string) { \
317 fprintf(stderr, "%s: " _debug_string); \
318 fprintf(stderr, __VA_ARGS__); \
320 fprintf(stderr,GST_DEBUG_PREFIX(": " __VA_ARGS__)); \
324 #elif defined(G_HAVE_GNUC_VARARGS)
326 #define _DEBUG_BUILTIN(format,args...) \
327 if (_debug_string != (void *)-1) { \
329 fprintf(stderr,"%s: " format , _debug_string , ## args); \
331 fprintf(stderr,GST_DEBUG_PREFIX(": " format , ## args)); \
340 /**********************************************************************
342 **********************************************************************/
344 typedef void (*GstInfoHandler) (gint category,gboolean incore,
345 const gchar *file,const gchar *function,
346 gint line,const gchar *debug_string,
347 void *element,gchar *string);
349 void gst_default_info_handler (gint category,gboolean incore,
350 const gchar *file,const gchar *function,
351 gint line,const gchar *debug_string,
352 void *element,gchar *string);
354 extern GstInfoHandler _gst_info_handler;
355 extern guint32 _gst_info_categories;
357 /* for include files that make too much noise normally */
358 #ifdef GST_INFO_FORCE_DISABLE
359 #undef GST_INFO_ENABLED
361 /* for applications that really really want all the noise */
362 #ifdef GST_INFO_FORCE_ENABLE
363 #define GST_INFO_ENABLED
366 #ifdef G_HAVE_ISO_VARARGS
368 #ifdef GST_INFO_ENABLED
369 #define GST_INFO(cat,...) G_STMT_START{ \
370 if ((1<<cat) & _gst_info_categories) \
371 _gst_info_handler(cat,_GST_DEBUG_INCORE,__FILE__,FUNCTION,__LINE__,_debug_string, \
372 NULL,g_strdup_printf( __VA_ARGS__ )); \
375 #define GST_INFO_ELEMENT(cat,element,...) G_STMT_START{ \
376 if ((1<<cat) & _gst_info_categories) \
377 _gst_info_handler(cat,_GST_DEBUG_INCORE,__FILE__,FUNCTION,__LINE__,_debug_string, \
378 element,g_strdup_printf( __VA_ARGS__ )); \
382 #define GST_INFO(cat,...)
383 #define GST_INFO_ELEMENT(cat,element,...)
386 #elif defined(G_HAVE_GNUC_VARARGS)
388 #ifdef GST_INFO_ENABLED
389 #define GST_INFO(cat,format,args...) G_STMT_START{ \
390 if ((1<<cat) & _gst_info_categories) \
391 _gst_info_handler(cat,_GST_DEBUG_INCORE,__FILE__,FUNCTION,__LINE__,_debug_string, \
392 NULL,g_strdup_printf( format , ## args )); \
395 #define GST_INFO_ELEMENT(cat,element,format,args...) G_STMT_START{ \
396 if ((1<<cat) & _gst_info_categories) \
397 _gst_info_handler(cat,_GST_DEBUG_INCORE,__FILE__,FUNCTION,__LINE__,_debug_string, \
398 element,g_strdup_printf( format , ## args )); \
402 #define GST_INFO(cat,format,args...)
403 #define GST_INFO_ELEMENT(cat,element,format,args...)
409 void gst_info_set_categories (guint32 categories);
410 guint32 gst_info_get_categories (void);
411 void gst_info_enable_category (gint category);
412 void gst_info_disable_category (gint category);
414 void gst_debug_set_categories (guint32 categories);
415 guint32 gst_debug_get_categories (void);
416 void gst_debug_enable_category (gint category);
417 void gst_debug_disable_category (gint category);
422 /**********************************************************************
424 **********************************************************************/
426 typedef void (*GstErrorHandler) (gchar *file,gchar *function,
427 gint line,gchar *debug_string,
428 void *element,void *object,gchar *string);
430 void gst_default_error_handler (gchar *file,gchar *function,
431 gint line,gchar *debug_string,
432 void *element,void *object,gchar *string);
434 extern GstErrorHandler _gst_error_handler;
436 #ifdef G_HAVE_ISO_VARARGS
438 #define GST_ERROR(element,...) \
439 _gst_error_handler(__FILE__,FUNCTION,__LINE__,_debug_string, \
440 element,NULL,g_strdup_printf( __VA_ARGS__ ))
442 #define GST_ERROR_OBJECT(element,object,...) \
443 _gst_error_handler(__FILE__,FUNCTION,__LINE__,_debug_string, \
444 element,object,g_strdup_printf( __VA_ARGS__ ))
446 #elif defined(G_HAVE_GNUC_VARARGS)
448 #define GST_ERROR(element,format,args...) \
449 _gst_error_handler(__FILE__,FUNCTION,__LINE__,_debug_string, \
450 element,NULL,g_strdup_printf( format , ## args ))
452 #define GST_ERROR_OBJECT(element,object,format,args...) \
453 _gst_error_handler(__FILE__,FUNCTION,__LINE__,_debug_string, \
454 element,object,g_strdup_printf( format , ## args ))
461 /********** function pointer stuff **********/
462 extern GHashTable *__gst_function_pointers;
465 #if GST_DEBUG_ENABLED
466 #define GST_DEBUG_FUNCPTR(ptr) _gst_debug_register_funcptr((void *)(ptr), #ptr)
467 #define GST_DEBUG_FUNCPTR_NAME(ptr) _gst_debug_nameof_funcptr((void *)ptr)
469 #define GST_DEBUG_FUNCPTR(ptr) (ptr)
470 #define GST_DEBUG_FUNCPTR_NAME(ptr) ""
474 _gst_debug_register_funcptr (void *ptr, gchar *ptrname)
476 if (!__gst_function_pointers) __gst_function_pointers = g_hash_table_new(g_direct_hash,g_direct_equal);
477 if (!g_hash_table_lookup(__gst_function_pointers,ptr))
478 g_hash_table_insert(__gst_function_pointers,ptr,ptrname);
482 gchar *_gst_debug_nameof_funcptr (void *ptr);
484 void gst_debug_print_stack_trace (void);
488 #endif /* __GSTINFO_H__ */