Fix broken __PRETY_FUNCTION__
[platform/upstream/gstreamer.git] / gst / gstinfo.h
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wtay@chello.be>
4  *
5  * gstinfo.h:
6  *
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.
11  *
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.
16  *
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.
21  */
22
23 #ifndef __GSTINFO_H__
24 #define __GSTINFO_H__
25
26 #include <stdio.h>
27 #include <gmodule.h>
28 #include <unistd.h>
29
30 #ifdef HAVE_CONFIG_H
31 #include <config.h>
32 #endif
33
34 /***** are we in the core or not? *****/
35 #ifdef __GST_PRIVATE_H__
36   #define _GST_DEBUG_INCORE TRUE
37 #else
38   #define _GST_DEBUG_INCORE FALSE
39 #endif
40
41
42 /* colorization stuff */
43 #ifdef GST_DEBUG_COLOR
44   #ifdef __GST_PRIVATE_H__   /* FIXME this should be some libgst.la -specific thing */
45     #define GST_DEBUG_CHAR_MODE "00"
46   #else
47     #define GST_DEBUG_CHAR_MODE "01"
48   #endif
49 #endif
50
51 gint _gst_debug_stringhash_color(gchar *file);
52
53
54
55 /**********************************************************************
56  * Categories
57  **********************************************************************/
58
59 const gchar *   gst_get_category_name   (gint category);
60
61 enum {
62   GST_CAT_GST_INIT = 0,         /* Library initialization */
63   GST_CAT_COTHREADS,            /* Cothread creation, etc. */
64   GST_CAT_COTHREAD_SWITCH,      /* Cothread switching */
65   GST_CAT_AUTOPLUG,             /* Successful autoplug results */
66   GST_CAT_AUTOPLUG_ATTEMPT,     /* Attempted autoplug operations */
67   GST_CAT_PARENTAGE,            /* GstBin parentage issues */
68   GST_CAT_STATES,               /* State changes and such */
69   GST_CAT_PLANNING,             /* Plan generation */
70   GST_CAT_SCHEDULING,           /* Schedule construction */
71   GST_CAT_DATAFLOW,             /* Events during actual data movement */
72   GST_CAT_BUFFER,               /* Buffer creation/destruction */
73   GST_CAT_CAPS,                 /* Capabilities matching */
74   GST_CAT_CLOCK,                /* Clocking */
75   GST_CAT_ELEMENT_PADS,         /* Element pad management */
76   GST_CAT_ELEMENT_FACTORY,      /* Elementfactory stuff */
77   GST_CAT_PADS,                 /* Pad creation/connection */
78   GST_CAT_PIPELINE,             /* Pipeline stuff */
79   GST_CAT_PLUGIN_LOADING,       /* Plugin loading */
80   GST_CAT_PLUGIN_ERRORS,        /* Errors during plugin loading */
81   GST_CAT_PLUGIN_INFO,          /* Plugin state information */
82   GST_CAT_PROPERTIES,           /* Properties */
83   GST_CAT_THREAD,               /* Thread creation/management */
84   GST_CAT_TYPES,                /* Typing */
85   GST_CAT_XML,                  /* XML load/save of everything */
86   GST_CAT_NEGOTIATION,          /* Caps Negotiation stuff */
87   GST_CAT_REFCOUNTING,          /* Ref Counting stuff */
88   GST_CAT_EVENT,                /* Event system */
89   GST_CAT_PARAMS,               /* Dynamic parameters */
90
91   GST_CAT_CALL_TRACE = 30,      /* Call tracing */
92
93   GST_CAT_MAX_CATEGORY = 31
94 };
95
96 extern const gchar *_gst_category_colors[32];
97
98
99
100 /**********************************************************************
101  * DEBUG system
102  **********************************************************************/
103
104 /* for include files that make too much noise normally */
105 #ifdef GST_DEBUG_FORCE_DISABLE
106 #undef GST_DEBUG_ENABLED
107 #endif
108 /* for applications that really really want all the noise */
109 #ifdef GST_DEBUG_FORCE_ENABLE
110 #define GST_DEBUG_ENABLED
111 #endif
112
113 /*#ifdef GST_DEBUG_ENABLED */
114 #define GST_DEBUG_ENABLE_CATEGORIES 0xffffffff
115 /*#else */
116 /*#define GST_DEBUG_ENABLE_CATEGORIES 0x00000000 */
117 /*#endif */
118
119
120 typedef void (*GstDebugHandler) (gint category,gboolean core,
121                                  const gchar *file,const gchar *function,
122                                  gint line,const gchar *debug_string,
123                                  void *element,gchar *string);
124
125 void gst_default_debug_handler (gint category,gboolean incore,
126                                 const gchar *file, const gchar *function,
127                                 gint line,const gchar *debug_string,
128                                 void *element,gchar *string);
129
130 extern guint32 _gst_debug_categories;
131 extern GstDebugHandler _gst_debug_handler;
132
133 /* fallback, this should probably be a 'weak' symbol or something */
134 G_GNUC_UNUSED static gchar *_debug_string = NULL;
135
136
137
138 #ifdef G_HAVE_ISO_VARARGS
139
140 #ifdef GST_DEBUG_ENABLED
141 #define GST_DEBUG(cat, ...) G_STMT_START{ \
142   if ((1<<cat) & _gst_debug_categories) \
143     _gst_debug_handler(cat,_GST_DEBUG_INCORE,__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
144                        NULL,g_strdup_printf( __VA_ARGS__ )); \
145 }G_STMT_END
146
147 #define GST_DEBUG_ELEMENT(cat, element, ...) G_STMT_START{ \
148   if ((1<<cat) & _gst_debug_categories) \
149     _gst_debug_handler(cat,_GST_DEBUG_INCORE,__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
150                        element,g_strdup_printf( __VA_ARGS__ )); \
151 }G_STMT_END
152
153 #else
154 #define GST_DEBUG(cat, ...)
155 #define GST_DEBUG_ELEMENT(cat,element, ...)
156 #endif
157
158 #elif defined(G_HAVE_GNUC_VARARGS)
159
160 #ifdef GST_DEBUG_ENABLED
161 #define GST_DEBUG(cat,format,args...) G_STMT_START{ \
162   if ((1<<cat) & _gst_debug_categories) \
163     _gst_debug_handler(cat,_GST_DEBUG_INCORE,__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
164                        NULL,g_strdup_printf( format , ## args )); \
165 }G_STMT_END
166
167 #define GST_DEBUG_ELEMENT(cat,element,format,args...) G_STMT_START{ \
168   if ((1<<cat) & _gst_debug_categories) \
169     _gst_debug_handler(cat,_GST_DEBUG_INCORE,__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
170                        element,g_strdup_printf( format , ## args )); \
171 }G_STMT_END
172
173 #else
174 #define GST_DEBUG(cat,format,args...)
175 #define GST_DEBUG_ELEMENT(cat,element,format,args...)
176 #endif
177
178 #endif
179
180
181
182
183 /********** some convenience macros for debugging **********/
184 #define GST_DEBUG_PAD_NAME(pad) \
185   (GST_OBJECT_PARENT(pad) != NULL) ? \
186   GST_OBJECT_NAME (GST_OBJECT_PARENT(pad)) : \
187   "''", GST_OBJECT_NAME (pad)
188
189 #ifdef G_HAVE_ISO_VARARGS
190
191 #ifdef GST_DEBUG_COLOR
192   #define GST_DEBUG_ENTER(...) GST_DEBUG( 31 , "\033[00;37mentering\033[00m :" __VA_ARGS__ )
193   #define GST_DEBUG_LEAVE(...) GST_DEBUG( 31 , "\033[00;37mleaving\033[00m :"  __VA_ARGS__ )
194 #else
195   #define GST_DEBUG_ENTER(...) GST_DEBUG( 31 , "entering :" __VA_ARGS__ )
196   #define GST_DEBUG_LEAVE(...) GST_DEBUG( 31 , "leaving :" __VA_ARGS__ )
197 #endif
198
199 #elif defined(G_HAVE_GNUC_VARARGS)
200
201 #ifdef GST_DEBUG_COLOR
202   #define GST_DEBUG_ENTER(format, args...) GST_DEBUG( 31 , format ": \033[00;37mentering\033[00m" , ##args )
203   #define GST_DEBUG_LEAVE(format, args...) GST_DEBUG( 31 , format ": \033[00;37mleaving\033[00m" , ##args )
204 #else
205   #define GST_DEBUG_ENTER(format, args...) GST_DEBUG( 31 , format ": entering" , ##args )
206   #define GST_DEBUG_LEAVE(format, args...) GST_DEBUG( 31 , format ": leaving" , ##args )
207 #endif
208
209 #endif
210
211
212 /***** Colorized debug for thread ids *****/
213 #ifdef GST_DEBUG_COLOR
214   #define GST_DEBUG_THREAD_FORMAT "\033[00;%dm%d\033[00m"
215   #define GST_DEBUG_THREAD_ARGS(id) ( ((id) < 0) ? 37 : ((id) % 6 + 31) ), (id)
216 #else
217   #define GST_DEBUG_THREAD_FORMAT "%d"
218   #define GST_DEBUG_THREAD_ARGS(id) (id)
219 #endif
220
221
222
223 /**********************************************************************
224  * The following is a DEBUG_ENTER implementation that will wrap the
225  * function it sits at the head of.  It removes the need for a
226  * DEBUG_LEAVE call.  However, it segfaults whenever it gets anywhere
227  * near cothreads.  We will not use it for the moment.
228  *
229 typedef void (*_debug_function_f)();
230 G_GNUC_UNUSED static gchar *_debug_string_pointer = NULL;
231 G_GNUC_UNUSED static GModule *_debug_self_module = NULL;
232
233 #ifdef G_HAVE_ISO_VARARGS
234
235 #define _DEBUG_ENTER_BUILTIN(...)                                                       \
236   static int _debug_in_wrapper = 0;                                                     \
237   gchar *_debug_string = ({                                                             \
238     if (!_debug_in_wrapper) {                                                           \
239       void *_return_value;                                                              \
240       gchar *_debug_string;                                                             \
241       _debug_function_f function;                                                       \
242       void *_function_args = __builtin_apply_args();                                    \
243       _debug_in_wrapper = 1;                                                            \
244       _debug_string = g_strdup_printf(GST_DEBUG_PREFIX(""));                            \
245       _debug_string_pointer = _debug_string;                                            \
246       fprintf(stderr,"%s: entered " FUNCTION, _debug_string);                           \ 
247       fprintf(stderr, __VA_ARGS__ );                                                    \
248       fprintf(stderr,"\n");                                                             \
249       if (_debug_self_module == NULL) _debug_self_module = g_module_open(NULL,0);       \
250       g_module_symbol(_debug_self_module,FUNCTION,(gpointer *)&function);               \
251       _return_value = __builtin_apply(function,_function_args,64);                      \
252       fprintf(stderr,"%s: left " FUNCTION, _debug_string);                              \
253       fprintf(stderr, __VA_ARGS__);                                                     \
254       fprintf(stderr,"\n");                                                             \
255       g_free(_debug_string);                                                            \
256       __builtin_return(_return_value);                                                  \
257     } else {                                                                            \
258       _debug_in_wrapper = 0;                                                            \
259     }                                                                                   \
260     _debug_string_pointer;                                                              \
261   });
262
263 #elif defined(G_HAVE_GNUC_VARARGS)
264
265 #define _DEBUG_ENTER_BUILTIN(format,args...)                                            \
266   static int _debug_in_wrapper = 0;                                                     \
267   gchar *_debug_string = ({                                                             \
268     if (!_debug_in_wrapper) {                                                           \
269       void *_return_value;                                                              \
270       gchar *_debug_string;                                                             \
271       _debug_function_f function;                                                       \
272       void *_function_args = __builtin_apply_args();                                    \
273       _debug_in_wrapper = 1;                                                            \
274       _debug_string = g_strdup_printf(GST_DEBUG_PREFIX(""));                            \
275       _debug_string_pointer = _debug_string;                                            \
276       fprintf(stderr,"%s: entered " FUNCTION format "\n" , _debug_string , ## args );   \
277       if (_debug_self_module == NULL) _debug_self_module = g_module_open(NULL,0);       \
278       g_module_symbol(_debug_self_module,FUNCTION,(gpointer *)&function);               \
279       _return_value = __builtin_apply(function,_function_args,64);                      \
280       fprintf(stderr,"%s: left " FUNCTION format "\n" , _debug_string , ## args ); \
281       g_free(_debug_string);                                                            \
282       __builtin_return(_return_value);                                                  \
283     } else {                                                                            \
284       _debug_in_wrapper = 0;                                                            \
285     }                                                                                   \
286     _debug_string_pointer;                                                              \
287   });
288
289 #endif
290
291 * WARNING: there's a gcc CPP bug lurking in here.  The extra space before the ##args    *
292  * somehow make the preprocessor leave the _debug_string. If it's removed, the          *
293  * _debug_string somehow gets stripped along with the ##args, and that's all she wrote. *
294
295 #ifdef G_HAVE_ISO_VARARGS
296
297 #define _DEBUG_BUILTIN(...)                                     \
298   if (_debug_string != (void *)-1) {                            \
299     if (_debug_string) {                                        \
300       fprintf(stderr, "%s: " _debug_string);                    \
301       fprintf(stderr, __VA_ARGS__);                             \
302     } else {                                                    \
303       fprintf(stderr,GST_DEBUG_PREFIX(": " __VA_ARGS__));       \
304     }                                                           \
305   }
306
307 #elif defined(G_HAVE_GNUC_VARARGS)
308
309 #define _DEBUG_BUILTIN(format,args...)                          \
310   if (_debug_string != (void *)-1) {                            \
311     if (_debug_string)                                          \
312       fprintf(stderr,"%s: " format , _debug_string , ## args);  \
313     else                                                        \
314       fprintf(stderr,GST_DEBUG_PREFIX(": " format , ## args));  \
315   }
316
317 #endif
318
319 */
320
321
322
323 /**********************************************************************
324  * INFO system
325  **********************************************************************/
326
327 typedef void (*GstInfoHandler) (gint category,gboolean incore,
328                                 const gchar *file,const gchar *function,
329                                 gint line,const gchar *debug_string,
330                                 void *element,gchar *string);
331
332 void gst_default_info_handler (gint category,gboolean incore,
333                                const gchar *file,const gchar *function,
334                                gint line,const gchar *debug_string,
335                                void *element,gchar *string);
336
337 extern GstInfoHandler _gst_info_handler;
338 extern guint32 _gst_info_categories;
339
340 /* for include files that make too much noise normally */
341 #ifdef GST_INFO_FORCE_DISABLE
342 #undef GST_INFO_ENABLED
343 #endif
344 /* for applications that really really want all the noise */
345 #ifdef GST_INFO_FORCE_ENABLE
346 #define GST_INFO_ENABLED
347 #endif
348
349 #ifdef G_HAVE_ISO_VARARGS
350
351 #ifdef GST_INFO_ENABLED
352 #define GST_INFO(cat,...) G_STMT_START{ \
353   if ((1<<cat) & _gst_info_categories) \
354     _gst_info_handler(cat,_GST_DEBUG_INCORE,__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
355                       NULL,g_strdup_printf( __VA_ARGS__ )); \
356 }G_STMT_END
357
358 #define GST_INFO_ELEMENT(cat,element,...) G_STMT_START{ \
359   if ((1<<cat) & _gst_info_categories) \
360     _gst_info_handler(cat,_GST_DEBUG_INCORE,__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
361                       element,g_strdup_printf( __VA_ARGS__ )); \
362 }G_STMT_END
363
364 #else
365 #define GST_INFO(cat,...) 
366 #define GST_INFO_ELEMENT(cat,element,...)
367 #endif
368
369 #elif defined(G_HAVE_GNUC_VARARGS)
370
371 #ifdef GST_INFO_ENABLED
372 #define GST_INFO(cat,format,args...) G_STMT_START{ \
373   if ((1<<cat) & _gst_info_categories) \
374     _gst_info_handler(cat,_GST_DEBUG_INCORE,__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
375                       NULL,g_strdup_printf( format , ## args )); \
376 }G_STMT_END
377
378 #define GST_INFO_ELEMENT(cat,element,format,args...) G_STMT_START{ \
379   if ((1<<cat) & _gst_info_categories) \
380     _gst_info_handler(cat,_GST_DEBUG_INCORE,__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
381                       element,g_strdup_printf( format , ## args )); \
382 }G_STMT_END
383
384 #else
385 #define GST_INFO(cat,format,args...) 
386 #define GST_INFO_ELEMENT(cat,element,format,args...)
387 #endif
388
389 #endif
390
391
392 void            gst_info_set_categories         (guint32 categories);
393 guint32         gst_info_get_categories         (void);
394 void            gst_info_enable_category        (gint category);
395 void            gst_info_disable_category       (gint category);
396
397 void            gst_debug_set_categories        (guint32 categories);
398 guint32         gst_debug_get_categories        (void);
399 void            gst_debug_enable_category       (gint category);
400 void            gst_debug_disable_category      (gint category);
401
402
403
404
405 /**********************************************************************
406  * ERROR system
407  **********************************************************************/
408
409 typedef void (*GstErrorHandler) (gchar *file,gchar *function,
410                                  gint line,gchar *debug_string,
411                                  void *element,void *object,gchar *string);
412
413 void gst_default_error_handler (gchar *file,gchar *function,
414                                 gint line,gchar *debug_string,
415                                 void *element,void *object,gchar *string);
416
417 extern GstErrorHandler _gst_error_handler;
418
419 #ifdef G_HAVE_ISO_VARARGS
420
421 #define GST_ERROR(element,...) \
422   _gst_error_handler(__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
423                      element,NULL,g_strdup_printf( __VA_ARGS__ ))
424
425 #define GST_ERROR_OBJECT(element,object,...) \
426   _gst_error_handler(__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
427                      element,object,g_strdup_printf( __VA_ARGS__ ))
428
429 #elif defined(G_HAVE_GNUC_VARARGS)
430
431 #define GST_ERROR(element,format,args...) \
432   _gst_error_handler(__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
433                      element,NULL,g_strdup_printf( format , ## args ))
434
435 #define GST_ERROR_OBJECT(element,object,format,args...) \
436   _gst_error_handler(__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
437                      element,object,g_strdup_printf( format , ## args ))
438
439 #endif
440
441
442
443
444 /********** function pointer stuff **********/
445 extern GHashTable *__gst_function_pointers;
446
447
448 #ifdef GST_DEBUG_ENABLED
449 static inline void *
450 _gst_debug_register_funcptr (void *ptr, gchar *ptrname)
451 {
452   if (!__gst_function_pointers) __gst_function_pointers = g_hash_table_new(g_direct_hash,g_direct_equal);
453   if (!g_hash_table_lookup(__gst_function_pointers,ptr))
454     g_hash_table_insert(__gst_function_pointers,ptr,ptrname);
455   return ptr;
456 }
457 #define GST_DEBUG_FUNCPTR(ptr) _gst_debug_register_funcptr((void *)(ptr), #ptr)
458 #define GST_DEBUG_FUNCPTR_NAME(ptr) _gst_debug_nameof_funcptr((void *)ptr)
459
460 gchar * _gst_debug_nameof_funcptr (void *ptr);
461 #else
462 #define GST_DEBUG_FUNCPTR(ptr) (ptr)
463 #define GST_DEBUG_FUNCPTR_NAME(ptr) ""
464 #endif
465
466 void gst_debug_print_stack_trace (void);
467
468 #endif /* __GSTINFO_H__ */