1 /* GStreamer
2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
4 * 2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
5 * Copyright (C) 2008-2009 Tim-Philipp Müller <tim centricular net>
6 *
7 * gstinfo.c: debugging functions
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
18 *
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
23 */
25 /**
26 * SECTION:gstinfo
27 * @short_description: Debugging and logging facilities
28 * @see_also: #gstreamer-gstconfig, #gstreamer-Gst for command line parameters
29 * and environment variables that affect the debugging output.
30 *
31 * GStreamer's debugging subsystem is an easy way to get information about what
32 * the application is doing. It is not meant for programming errors. Use GLib
33 * methods (g_warning and friends) for that.
34 *
35 * The debugging subsystem works only after GStreamer has been initialized
36 * - for example by calling gst_init().
37 *
38 * The debugging subsystem is used to log informational messages while the
39 * application runs. Each messages has some properties attached to it. Among
40 * these properties are the debugging category, the severity (called "level"
41 * here) and an optional #GObject it belongs to. Each of these messages is sent
42 * to all registered debugging handlers, which then handle the messages.
43 * GStreamer attaches a default handler on startup, which outputs requested
44 * messages to stderr.
45 *
46 * Messages are output by using shortcut macros like #GST_DEBUG,
47 * #GST_CAT_ERROR_OBJECT or similar. These all expand to calling gst_debug_log()
48 * with the right parameters.
49 * The only thing a developer will probably want to do is define his own
50 * categories. This is easily done with 3 lines. At the top of your code,
51 * declare
52 * the variables and set the default category.
53 * <informalexample>
54 * <programlisting>
55 * GST_DEBUG_CATEGORY_STATIC (my_category); // define category (statically)
56 * &hash;define GST_CAT_DEFAULT my_category // set as default
57 * </programlisting>
58 * </informalexample>
59 * After that you only need to initialize the category.
60 * <informalexample>
61 * <programlisting>
62 * GST_DEBUG_CATEGORY_INIT (my_category, "my category",
63 * 0, "This is my very own");
64 * </programlisting>
65 * </informalexample>
66 * Initialization must be done before the category is used first.
67 * Plugins do this
68 * in their plugin_init function, libraries and applications should do that
69 * during their initialization.
70 *
71 * The whole debugging subsystem can be disabled at build time with passing the
72 * --disable-gst-debug switch to configure. If this is done, every function,
73 * macro and even structs described in this file evaluate to default values or
74 * nothing at all.
75 * So don't take addresses of these functions or use other tricks.
76 * If you must do that for some reason, there is still an option.
77 * If the debugging
78 * subsystem was compiled out, #GST_DISABLE_GST_DEBUG is defined in
79 * <gst/gst.h>,
80 * so you can check that before doing your trick.
81 * Disabling the debugging subsystem will give you a slight (read: unnoticeable)
82 * speed increase and will reduce the size of your compiled code. The GStreamer
83 * library itself becomes around 10% smaller.
84 *
85 * Please note that there are naming conventions for the names of debugging
86 * categories. These are explained at GST_DEBUG_CATEGORY_INIT().
87 */
89 #define GST_INFO_C
90 #include "gst_private.h"
91 #include "gstinfo.h"
93 #undef gst_debug_remove_log_function
94 #undef gst_debug_add_log_function
96 #ifndef GST_DISABLE_GST_DEBUG
98 #ifdef HAVE_DLFCN_H
99 # include <dlfcn.h>
100 #endif
101 #ifdef HAVE_PRINTF_EXTENSION
102 # include <printf.h>
103 #endif
104 #include <stdio.h> /* fprintf */
105 #include <glib/gstdio.h>
106 #include <errno.h>
107 #ifdef HAVE_UNISTD_H
108 # include <unistd.h> /* getpid on UNIX */
109 #endif
110 #ifdef HAVE_PROCESS_H
111 # include <process.h> /* getpid on win32 */
112 #endif
113 #include <string.h> /* G_VA_COPY */
114 #ifdef G_OS_WIN32
115 # define WIN32_LEAN_AND_MEAN /* prevents from including too many things */
116 # include <windows.h> /* GetStdHandle, windows console */
117 #endif
119 #include "gst_private.h"
120 #include "gstutils.h"
121 #include "gstquark.h"
122 #include "gstsegment.h"
123 #ifdef HAVE_VALGRIND_VALGRIND_H
124 # include <valgrind/valgrind.h>
125 #endif
126 #include <glib/gprintf.h> /* g_sprintf */
128 #endif /* !GST_DISABLE_GST_DEBUG */
130 /* we want these symbols exported even if debug is disabled, to maintain
131 * ABI compatibility. Unless GST_REMOVE_DISABLED is defined. */
132 #if !defined(GST_DISABLE_GST_DEBUG) || !defined(GST_REMOVE_DISABLED)
134 /* disabled by default, as soon as some threshold is set > NONE,
135 * it becomes enabled. */
136 gboolean __gst_debug_enabled = FALSE;
137 GstDebugLevel __gst_debug_min = GST_LEVEL_NONE;
139 GstDebugCategory *GST_CAT_DEFAULT = NULL;
141 GstDebugCategory *GST_CAT_GST_INIT = NULL;
142 GstDebugCategory *GST_CAT_AUTOPLUG = NULL;
143 GstDebugCategory *GST_CAT_AUTOPLUG_ATTEMPT = NULL;
144 GstDebugCategory *GST_CAT_PARENTAGE = NULL;
145 GstDebugCategory *GST_CAT_STATES = NULL;
146 GstDebugCategory *GST_CAT_SCHEDULING = NULL;
148 GstDebugCategory *GST_CAT_BUFFER = NULL;
149 GstDebugCategory *GST_CAT_BUFFER_LIST = NULL;
150 GstDebugCategory *GST_CAT_BUS = NULL;
151 GstDebugCategory *GST_CAT_CAPS = NULL;
152 GstDebugCategory *GST_CAT_CLOCK = NULL;
153 GstDebugCategory *GST_CAT_ELEMENT_PADS = NULL;
154 GstDebugCategory *GST_CAT_PADS = NULL;
155 GstDebugCategory *GST_CAT_PERFORMANCE = NULL;
156 GstDebugCategory *GST_CAT_PIPELINE = NULL;
157 GstDebugCategory *GST_CAT_PLUGIN_LOADING = NULL;
158 GstDebugCategory *GST_CAT_PLUGIN_INFO = NULL;
159 GstDebugCategory *GST_CAT_PROPERTIES = NULL;
160 GstDebugCategory *GST_CAT_TYPES = NULL;
161 GstDebugCategory *GST_CAT_XML = NULL;
162 GstDebugCategory *GST_CAT_NEGOTIATION = NULL;
163 GstDebugCategory *GST_CAT_REFCOUNTING = NULL;
164 GstDebugCategory *GST_CAT_ERROR_SYSTEM = NULL;
165 GstDebugCategory *GST_CAT_EVENT = NULL;
166 GstDebugCategory *GST_CAT_MESSAGE = NULL;
167 GstDebugCategory *GST_CAT_PARAMS = NULL;
168 GstDebugCategory *GST_CAT_CALL_TRACE = NULL;
169 GstDebugCategory *GST_CAT_SIGNAL = NULL;
170 GstDebugCategory *GST_CAT_PROBE = NULL;
171 GstDebugCategory *GST_CAT_REGISTRY = NULL;
172 GstDebugCategory *GST_CAT_QOS = NULL;
173 GstDebugCategory *_priv_GST_CAT_POLL = NULL;
176 #endif /* !defined(GST_DISABLE_GST_DEBUG) || !defined(GST_REMOVE_DISABLED) */
178 #ifndef GST_DISABLE_GST_DEBUG
180 /* underscore is to prevent conflict with GST_CAT_DEBUG define */
181 GST_DEBUG_CATEGORY_STATIC (_GST_CAT_DEBUG);
183 /* time of initialization, so we get useful debugging output times
184 * FIXME: we use this in gstdebugutils.c, what about a function + macro to
185 * get the running time: GST_DEBUG_RUNNING_TIME
186 */
187 GstClockTime _priv_gst_info_start_time;
189 #if 0
190 #if defined __sgi__
191 #include <rld_interface.h>
192 typedef struct DL_INFO
193 {
194 const char *dli_fname;
195 void *dli_fbase;
196 const char *dli_sname;
197 void *dli_saddr;
198 int dli_version;
199 int dli_reserved1;
200 long dli_reserved[4];
201 }
202 Dl_info;
204 #define _RLD_DLADDR 14
205 int dladdr (void *address, Dl_info * dl);
207 int
208 dladdr (void *address, Dl_info * dl)
209 {
210 void *v;
212 v = _rld_new_interface (_RLD_DLADDR, address, dl);
213 return (int) v;
214 }
215 #endif /* __sgi__ */
216 #endif
218 static void gst_debug_reset_threshold (gpointer category, gpointer unused);
219 static void gst_debug_reset_all_thresholds (void);
221 #ifdef HAVE_PRINTF_EXTENSION
222 static int _gst_info_printf_extension_ptr (FILE * stream,
223 const struct printf_info *info, const void *const *args);
224 static int _gst_info_printf_extension_segment (FILE * stream,
225 const struct printf_info *info, const void *const *args);
226 #ifdef HAVE_REGISTER_PRINTF_SPECIFIER
227 static int _gst_info_printf_extension_arginfo (const struct printf_info *info,
228 size_t n, int *argtypes, int *size);
229 #else
230 static int _gst_info_printf_extension_arginfo (const struct printf_info *info,
231 size_t n, int *argtypes);
232 #endif
233 #endif
235 struct _GstDebugMessage
236 {
237 gchar *message;
238 const gchar *format;
239 va_list arguments;
240 };
242 /* list of all name/level pairs from --gst-debug and GST_DEBUG */
243 static GStaticMutex __level_name_mutex = G_STATIC_MUTEX_INIT;
244 static GSList *__level_name = NULL;
245 typedef struct
246 {
247 GPatternSpec *pat;
248 GstDebugLevel level;
249 }
250 LevelNameEntry;
252 /* list of all categories */
253 static GStaticMutex __cat_mutex = G_STATIC_MUTEX_INIT;
254 static GSList *__categories = NULL;
256 /* all registered debug handlers */
257 typedef struct
258 {
259 GstLogFunction func;
260 gpointer user_data;
261 }
262 LogFuncEntry;
263 static GStaticMutex __log_func_mutex = G_STATIC_MUTEX_INIT;
264 static GSList *__log_functions = NULL;
266 #define PRETTY_TAGS_DEFAULT TRUE
267 static gboolean pretty_tags = PRETTY_TAGS_DEFAULT;
269 static volatile gint G_GNUC_MAY_ALIAS __default_level = GST_LEVEL_DEFAULT;
270 static volatile gint G_GNUC_MAY_ALIAS __use_color = 1;
272 static FILE *log_file;
274 /* FIXME: export this? */
275 gboolean
276 _priv_gst_in_valgrind (void)
277 {
278 static enum
279 {
280 GST_VG_UNCHECKED,
281 GST_VG_NO_VALGRIND,
282 GST_VG_INSIDE
283 }
284 in_valgrind = GST_VG_UNCHECKED;
286 if (in_valgrind == GST_VG_UNCHECKED) {
287 #ifdef HAVE_VALGRIND_VALGRIND_H
288 if (RUNNING_ON_VALGRIND) {
289 GST_CAT_INFO (GST_CAT_GST_INIT, "we're running inside valgrind");
290 printf ("GStreamer has detected that it is running inside valgrind.\n");
291 printf ("It might now take different code paths to ease debugging.\n");
292 printf ("Of course, this may also lead to different bugs.\n");
293 in_valgrind = GST_VG_INSIDE;
294 } else {
295 GST_CAT_LOG (GST_CAT_GST_INIT, "not doing extra valgrind stuff");
296 in_valgrind = GST_VG_NO_VALGRIND;
297 }
298 #else
299 in_valgrind = GST_VG_NO_VALGRIND;
300 #endif
301 g_assert (in_valgrind == GST_VG_NO_VALGRIND ||
302 in_valgrind == GST_VG_INSIDE);
303 }
304 return (in_valgrind == GST_VG_INSIDE);
305 }
307 /**
308 * _gst_debug_init:
309 *
310 * Initializes the debugging system.
311 * Normally you don't want to call this, because gst_init() does it for you.
312 */
313 void
314 _gst_debug_init (void)
315 {
316 const gchar *env;
318 env = g_getenv ("GST_DEBUG_FILE");
319 if (env != NULL && *env != '\0') {
320 if (strcmp (env, "-") == 0) {
321 log_file = stdout;
322 } else {
323 log_file = g_fopen (env, "w");
324 if (log_file == NULL) {
325 g_printerr ("Could not open log file '%s' for writing: %s\n", env,
326 g_strerror (errno));
327 log_file = stderr;
328 }
329 }
330 } else {
331 log_file = stderr;
332 }
334 /* get time we started for debugging messages */
335 _priv_gst_info_start_time = gst_util_get_timestamp ();
337 #ifdef HAVE_PRINTF_EXTENSION
338 #ifdef HAVE_REGISTER_PRINTF_SPECIFIER
339 register_printf_specifier (GST_PTR_FORMAT[0], _gst_info_printf_extension_ptr,
340 _gst_info_printf_extension_arginfo);
341 register_printf_specifier (GST_SEGMENT_FORMAT[0],
342 _gst_info_printf_extension_segment, _gst_info_printf_extension_arginfo);
343 #else
344 register_printf_function (GST_PTR_FORMAT[0], _gst_info_printf_extension_ptr,
345 _gst_info_printf_extension_arginfo);
346 register_printf_function (GST_SEGMENT_FORMAT[0],
347 _gst_info_printf_extension_segment, _gst_info_printf_extension_arginfo);
348 #endif
349 #endif
351 /* do NOT use a single debug function before this line has been run */
352 GST_CAT_DEFAULT = _gst_debug_category_new ("default",
353 GST_DEBUG_UNDERLINE, NULL);
354 _GST_CAT_DEBUG = _gst_debug_category_new ("GST_DEBUG",
355 GST_DEBUG_BOLD | GST_DEBUG_FG_YELLOW, "debugging subsystem");
357 gst_debug_add_log_function (gst_debug_log_default, NULL);
359 /* FIXME: add descriptions here */
360 GST_CAT_GST_INIT = _gst_debug_category_new ("GST_INIT",
361 GST_DEBUG_BOLD | GST_DEBUG_FG_RED, NULL);
362 GST_CAT_AUTOPLUG = _gst_debug_category_new ("GST_AUTOPLUG",
363 GST_DEBUG_BOLD | GST_DEBUG_FG_BLUE, NULL);
364 GST_CAT_AUTOPLUG_ATTEMPT = _gst_debug_category_new ("GST_AUTOPLUG_ATTEMPT",
365 GST_DEBUG_BOLD | GST_DEBUG_FG_CYAN | GST_DEBUG_BG_BLUE, NULL);
366 GST_CAT_PARENTAGE = _gst_debug_category_new ("GST_PARENTAGE",
367 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED, NULL);
368 GST_CAT_STATES = _gst_debug_category_new ("GST_STATES",
369 GST_DEBUG_BOLD | GST_DEBUG_FG_RED, NULL);
370 GST_CAT_SCHEDULING = _gst_debug_category_new ("GST_SCHEDULING",
371 GST_DEBUG_BOLD | GST_DEBUG_FG_MAGENTA, NULL);
372 GST_CAT_BUFFER = _gst_debug_category_new ("GST_BUFFER",
373 GST_DEBUG_BOLD | GST_DEBUG_BG_GREEN, NULL);
374 GST_CAT_BUFFER_LIST = _gst_debug_category_new ("GST_BUFFER_LIST",
375 GST_DEBUG_BOLD | GST_DEBUG_BG_GREEN, NULL);
376 GST_CAT_BUS = _gst_debug_category_new ("GST_BUS", GST_DEBUG_BG_YELLOW, NULL);
377 GST_CAT_CAPS = _gst_debug_category_new ("GST_CAPS",
378 GST_DEBUG_BOLD | GST_DEBUG_FG_BLUE, NULL);
379 GST_CAT_CLOCK = _gst_debug_category_new ("GST_CLOCK",
380 GST_DEBUG_BOLD | GST_DEBUG_FG_YELLOW, NULL);
381 GST_CAT_ELEMENT_PADS = _gst_debug_category_new ("GST_ELEMENT_PADS",
382 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED, NULL);
383 GST_CAT_PADS = _gst_debug_category_new ("GST_PADS",
384 GST_DEBUG_BOLD | GST_DEBUG_FG_RED | GST_DEBUG_BG_RED, NULL);
385 GST_CAT_PERFORMANCE = _gst_debug_category_new ("GST_PERFORMANCE",
386 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED, NULL);
387 GST_CAT_PIPELINE = _gst_debug_category_new ("GST_PIPELINE",
388 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED, NULL);
389 GST_CAT_PLUGIN_LOADING = _gst_debug_category_new ("GST_PLUGIN_LOADING",
390 GST_DEBUG_BOLD | GST_DEBUG_FG_CYAN, NULL);
391 GST_CAT_PLUGIN_INFO = _gst_debug_category_new ("GST_PLUGIN_INFO",
392 GST_DEBUG_BOLD | GST_DEBUG_FG_CYAN, NULL);
393 GST_CAT_PROPERTIES = _gst_debug_category_new ("GST_PROPERTIES",
394 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_BLUE, NULL);
395 GST_CAT_TYPES = _gst_debug_category_new ("GST_TYPES",
396 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED, NULL);
397 GST_CAT_XML = _gst_debug_category_new ("GST_XML",
398 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED, NULL);
399 GST_CAT_NEGOTIATION = _gst_debug_category_new ("GST_NEGOTIATION",
400 GST_DEBUG_BOLD | GST_DEBUG_FG_BLUE, NULL);
401 GST_CAT_REFCOUNTING = _gst_debug_category_new ("GST_REFCOUNTING",
402 GST_DEBUG_BOLD | GST_DEBUG_FG_RED | GST_DEBUG_BG_BLUE, NULL);
403 GST_CAT_ERROR_SYSTEM = _gst_debug_category_new ("GST_ERROR_SYSTEM",
404 GST_DEBUG_BOLD | GST_DEBUG_FG_RED | GST_DEBUG_BG_WHITE, NULL);
406 GST_CAT_EVENT = _gst_debug_category_new ("GST_EVENT",
407 GST_DEBUG_BOLD | GST_DEBUG_FG_BLUE, NULL);
408 GST_CAT_MESSAGE = _gst_debug_category_new ("GST_MESSAGE",
409 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED, NULL);
410 GST_CAT_PARAMS = _gst_debug_category_new ("GST_PARAMS",
411 GST_DEBUG_BOLD | GST_DEBUG_FG_BLACK | GST_DEBUG_BG_YELLOW, NULL);
412 GST_CAT_CALL_TRACE = _gst_debug_category_new ("GST_CALL_TRACE",
413 GST_DEBUG_BOLD, NULL);
414 GST_CAT_SIGNAL = _gst_debug_category_new ("GST_SIGNAL",
415 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED, NULL);
416 GST_CAT_PROBE = _gst_debug_category_new ("GST_PROBE",
417 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "pad probes");
418 GST_CAT_REGISTRY = _gst_debug_category_new ("GST_REGISTRY", 0, "registry");
419 GST_CAT_QOS = _gst_debug_category_new ("GST_QOS", 0, "QoS");
420 _priv_GST_CAT_POLL = _gst_debug_category_new ("GST_POLL", 0, "poll");
423 /* print out the valgrind message if we're in valgrind */
424 _priv_gst_in_valgrind ();
426 env = g_getenv ("GST_DEBUG_OPTIONS");
427 if (env != NULL) {
428 if (strstr (env, "full_tags") || strstr (env, "full-tags"))
429 pretty_tags = FALSE;
430 else if (strstr (env, "pretty_tags") || strstr (env, "pretty-tags"))
431 pretty_tags = TRUE;
432 }
433 }
435 /* we can't do this further above, because we initialize the GST_CAT_DEFAULT struct */
436 #define GST_CAT_DEFAULT _GST_CAT_DEBUG
439 /**
440 * gst_debug_log2:
441 * @category: category to log
442 * @level: level of the message is in
443 * @location: the file, function name, and line number of the location that
444 * emitted the message
445 * @object: the object this message relates to or NULL if none
446 * @format: a printf style format string
447 * @...: optional arguments for the format
448 *
449 * Logs the given message using the currently registered debugging handlers.
450 */
451 void
452 gst_debug_log2 (GstDebugCategory * category, GstDebugLevel level,
453 const GstDebugTraceLocation * location,
454 GObject * object, const gchar * format, ...)
455 {
456 va_list var_args;
458 va_start (var_args, format);
459 gst_debug_log_valist2 (category, level, location, object, format, var_args);
460 va_end (var_args);
461 }
464 /**
465 * gst_debug_log:
466 * @category: category to log
467 * @level: level of the message is in
468 * @file: the file that emitted the message, usually the __FILE__ identifier
469 * @function: the function that emitted the message
470 * @line: the line from that the message was emitted, usually __LINE__
471 * @object: (transfer none) (allow-none): the object this message relates to,
472 * or NULL if none
473 * @format: a printf style format string
474 * @...: optional arguments for the format
475 *
476 * Logs the given message using the currently registered debugging handlers.
477 */
478 void
479 gst_debug_log (GstDebugCategory * category, GstDebugLevel level,
480 const gchar * file, const gchar * function, gint line,
481 GObject * object, const gchar * format, ...)
482 {
483 va_list var_args;
485 va_start (var_args, format);
486 gst_debug_log_valist (category, level, file, function, line, object, format,
487 var_args);
488 va_end (var_args);
489 }
491 #ifdef _MSC_VER
492 /* based on g_basename(), which we can't use because it was deprecated */
493 static inline const gchar *
494 gst_path_basename (const gchar * file_name)
495 {
496 register const gchar *base;
498 base = strrchr (file_name, G_DIR_SEPARATOR);
500 {
501 const gchar *q = strrchr (file_name, '/');
502 if (base == NULL || (q != NULL && q > base))
503 base = q;
504 }
506 if (base)
507 return base + 1;
509 if (g_ascii_isalpha (file_name[0]) && file_name[1] == ':')
510 return file_name + 2;
512 return file_name;
513 }
514 #endif
516 /**
517 * gst_debug_log_valist:
518 * @category: category to log
519 * @level: level of the message is in
520 * @file: the file that emitted the message, usually the __FILE__ identifier
521 * @function: the function that emitted the message
522 * @line: the line from that the message was emitted, usually __LINE__
523 * @object: (transfer none) (allow-none): the object this message relates to,
524 * or NULL if none
525 * @format: a printf style format string
526 * @args: optional arguments for the format
527 *
528 * Logs the given message using the currently registered debugging handlers.
529 */
530 void
531 gst_debug_log_valist (GstDebugCategory * category, GstDebugLevel level,
532 const gchar * file, const gchar * function, gint line,
533 GObject * object, const gchar * format, va_list args)
534 {
535 GstDebugTraceLocation location = {
536 .file = file,
537 .function = function,
538 .line = line
539 };
540 gst_debug_log_valist2 (category, level, &location, object, format, args);
541 }
544 /**
545 * gst_debug_log_valist2:
546 * @category: category to log
547 * @level: level of the message is in
548 * @location: the file, function name, and line number of the location that
549 * emitted the message
550 * @object: the object this message relates to or NULL if none
551 * @format: a printf style format string
552 * @args: optional arguments for the format
553 *
554 * Logs the given message using the currently registered debugging handlers.
555 */
556 void
557 gst_debug_log_valist2 (GstDebugCategory * category, GstDebugLevel level,
558 const GstDebugTraceLocation * location,
559 GObject * object, const gchar * format, va_list args)
560 {
561 GstDebugMessage message;
562 LogFuncEntry *entry;
563 GSList *handler;
565 g_return_if_fail (category != NULL);
566 g_return_if_fail (location != NULL);
567 g_return_if_fail (location->file != NULL);
568 g_return_if_fail (location->function != NULL);
569 g_return_if_fail (format != NULL);
571 /* The predefined macro __FILE__ is always the exact path given to the
572 * compiler with MSVC, which may or may not be the basename. We work
573 * around it at runtime to improve the readability. */
574 #ifdef _MSC_VER
575 file = gst_path_basename (file);
576 #endif
578 message.message = NULL;
579 message.format = format;
580 G_VA_COPY (message.arguments, args);
582 handler = __log_functions;
583 while (handler) {
584 entry = handler->data;
585 handler = g_slist_next (handler);
586 // TODO: change GstLogFunction and pass GstDebugTraceLocation ptr instead..
587 entry->func (category, level, location->file, location->function,
588 location->line, object, &message, entry->user_data);
589 }
590 g_free (message.message);
591 va_end (message.arguments);
592 }
594 /**
595 * gst_debug_message_get:
596 * @message: a debug message
597 *
598 * Gets the string representation of a #GstDebugMessage. This function is used
599 * in debug handlers to extract the message.
600 *
601 * Returns: the string representation of a #GstDebugMessage.
602 */
603 const gchar *
604 gst_debug_message_get (GstDebugMessage * message)
605 {
606 if (message->message == NULL) {
607 message->message = g_strdup_vprintf (message->format, message->arguments);
608 }
609 return message->message;
610 }
612 #define MAX_BUFFER_DUMP_STRING_LEN 100
614 /* structure_to_pretty_string:
615 * @structure: a #GstStructure
616 *
617 * Converts @structure to a human-readable string representation. Basically
618 * the same as gst_structure_to_string(), but if the structure contains large
619 * buffers such as images the hex representation of those buffers will be
620 * shortened so that the string remains readable.
621 *
622 * Returns: a newly-allocated string. g_free() when no longer needed.
623 */
624 static gchar *
625 structure_to_pretty_string (const GstStructure * s)
626 {
627 gchar *str, *pos, *end;
629 str = gst_structure_to_string (s);
630 if (str == NULL)
631 return NULL;
633 pos = str;
634 while ((pos = strstr (pos, "(buffer)"))) {
635 guint count = 0;
637 pos += strlen ("(buffer)");
638 for (end = pos; *end != '\0' && *end != ';' && *end != ' '; ++end)
639 ++count;
640 if (count > MAX_BUFFER_DUMP_STRING_LEN) {
641 memcpy (pos + MAX_BUFFER_DUMP_STRING_LEN - 6, "..", 2);
642 memcpy (pos + MAX_BUFFER_DUMP_STRING_LEN - 4, pos + count - 4, 4);
643 g_memmove (pos + MAX_BUFFER_DUMP_STRING_LEN, pos + count,
644 strlen (pos + count) + 1);
645 pos += MAX_BUFFER_DUMP_STRING_LEN;
646 }
647 }
649 return str;
650 }
652 static inline gchar *
653 gst_info_structure_to_string (GstStructure * s)
654 {
655 if (G_UNLIKELY (pretty_tags && s->name == GST_QUARK (TAGLIST)))
656 return structure_to_pretty_string (s);
657 else
658 return gst_structure_to_string (s);
659 }
661 gchar *
662 gst_debug_print_object (gpointer ptr)
663 {
664 GObject *object = (GObject *) ptr;
666 #ifdef unused
667 /* This is a cute trick to detect unmapped memory, but is unportable,
668 * slow, screws around with madvise, and not actually that useful. */
669 {
670 int ret;
672 ret = madvise ((void *) ((unsigned long) ptr & (~0xfff)), 4096, 0);
673 if (ret == -1 && errno == ENOMEM) {
674 buffer = g_strdup_printf ("%p (unmapped memory)", ptr);
675 }
676 }
677 #endif
679 /* nicely printed object */
680 if (object == NULL) {
681 return g_strdup ("(NULL)");
682 }
683 if (*(GType *) ptr == GST_TYPE_CAPS) {
684 return gst_caps_to_string ((GstCaps *) ptr);
685 }
686 if (*(GType *) ptr == GST_TYPE_STRUCTURE) {
687 return gst_info_structure_to_string ((GstStructure *) ptr);
688 }
689 if (GST_IS_BUFFER (ptr)) {
690 GstBuffer *buf = (GstBuffer *) ptr;
691 gchar *caps, *ret;
693 caps = gst_caps_to_string (GST_BUFFER_CAPS (buf));
694 ret =
695 g_strdup_printf ("%p, data %p, malloc %p, ts %" GST_TIME_FORMAT
696 ", dur %" GST_TIME_FORMAT ", size %u, offset %" G_GUINT64_FORMAT
697 ", offset_end %" G_GUINT64_FORMAT ", caps: %s", buf,
698 GST_BUFFER_DATA (buf), GST_BUFFER_MALLOCDATA (buf),
699 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)),
700 GST_TIME_ARGS (GST_BUFFER_DURATION (buf)), GST_BUFFER_SIZE (buf),
701 GST_BUFFER_OFFSET (buf), GST_BUFFER_OFFSET_END (buf), caps);
703 g_free (caps);
704 return ret;
705 }
706 #ifdef USE_POISONING
707 if (*(guint32 *) ptr == 0xffffffff) {
708 return g_strdup_printf ("<poisoned@%p>", ptr);
709 }
710 #endif
711 if (GST_IS_PAD (object) && GST_OBJECT_NAME (object)) {
712 return g_strdup_printf ("<%s:%s>", GST_DEBUG_PAD_NAME (object));
713 }
714 if (GST_IS_OBJECT (object) && GST_OBJECT_NAME (object)) {
715 return g_strdup_printf ("<%s>", GST_OBJECT_NAME (object));
716 }
717 if (G_IS_OBJECT (object)) {
718 return g_strdup_printf ("<%s@%p>", G_OBJECT_TYPE_NAME (object), object);
719 }
720 if (GST_IS_MESSAGE (object)) {
721 GstMessage *msg = GST_MESSAGE_CAST (object);
722 gchar *s, *ret;
724 if (msg->structure) {
725 s = gst_info_structure_to_string (msg->structure);
726 } else {
727 s = g_strdup ("(NULL)");
728 }
730 ret = g_strdup_printf ("%s message from element '%s': %s",
731 GST_MESSAGE_TYPE_NAME (msg), (msg->src != NULL) ?
732 GST_ELEMENT_NAME (msg->src) : "(NULL)", s);
733 g_free (s);
734 return ret;
735 }
736 if (GST_IS_QUERY (object)) {
737 GstQuery *query = GST_QUERY_CAST (object);
739 if (query->structure) {
740 return gst_info_structure_to_string (query->structure);
741 } else {
742 const gchar *query_type_name;
744 query_type_name = gst_query_type_get_name (query->type);
745 if (G_LIKELY (query_type_name != NULL)) {
746 return g_strdup_printf ("%s query", query_type_name);
747 } else {
748 return g_strdup_printf ("query of unknown type %d", query->type);
749 }
750 }
751 }
752 if (GST_IS_EVENT (object)) {
753 GstEvent *event = GST_EVENT_CAST (object);
754 gchar *s, *ret;
756 if (event->structure) {
757 s = gst_info_structure_to_string (event->structure);
758 } else {
759 s = g_strdup ("(NULL)");
760 }
762 ret = g_strdup_printf ("%s event from '%s' at time %"
763 GST_TIME_FORMAT ": %s",
764 GST_EVENT_TYPE_NAME (event), (event->src != NULL) ?
765 GST_OBJECT_NAME (event->src) : "(NULL)",
766 GST_TIME_ARGS (event->timestamp), s);
767 g_free (s);
768 return ret;
769 }
771 return g_strdup_printf ("%p", ptr);
772 }
774 #ifdef HAVE_PRINTF_EXTENSION
776 gchar *
777 gst_debug_print_segment (gpointer ptr)
778 {
779 GstSegment *segment = (GstSegment *) ptr;
781 /* nicely printed segment */
782 if (segment == NULL) {
783 return g_strdup ("(NULL)");
784 }
786 switch (segment->format) {
787 case GST_FORMAT_UNDEFINED:{
788 return g_strdup_printf ("UNDEFINED segment");
789 }
790 case GST_FORMAT_TIME:{
791 return g_strdup_printf ("time segment start=%" GST_TIME_FORMAT
792 ", stop=%" GST_TIME_FORMAT ", last_stop=%" GST_TIME_FORMAT
793 ", duration=%" GST_TIME_FORMAT ", rate=%f, applied_rate=%f"
794 ", flags=0x%02x, time=%" GST_TIME_FORMAT ", accum=%" GST_TIME_FORMAT,
795 GST_TIME_ARGS (segment->start), GST_TIME_ARGS (segment->stop),
796 GST_TIME_ARGS (segment->last_stop), GST_TIME_ARGS (segment->duration),
797 segment->rate, segment->applied_rate, (guint) segment->flags,
798 GST_TIME_ARGS (segment->time), GST_TIME_ARGS (segment->accum));
799 }
800 default:{
801 const gchar *format_name;
803 format_name = gst_format_get_name (segment->format);
804 if (G_UNLIKELY (format_name == NULL))
805 format_name = "(UNKNOWN FORMAT)";
806 return g_strdup_printf ("%s segment start=%" G_GINT64_FORMAT
807 ", stop=%" G_GINT64_FORMAT ", last_stop=%" G_GINT64_FORMAT
808 ", duration=%" G_GINT64_FORMAT ", rate=%f, applied_rate=%f"
809 ", flags=0x%02x, time=%" GST_TIME_FORMAT ", accum=%" GST_TIME_FORMAT,
810 format_name, segment->start, segment->stop, segment->last_stop,
811 segment->duration, segment->rate, segment->applied_rate,
812 (guint) segment->flags, GST_TIME_ARGS (segment->time),
813 GST_TIME_ARGS (segment->accum));
814 }
815 }
816 }
818 #endif /* HAVE_PRINTF_EXTENSION */
820 /**
821 * gst_debug_construct_term_color:
822 * @colorinfo: the color info
823 *
824 * Constructs a string that can be used for getting the desired color in color
825 * terminals.
826 * You need to free the string after use.
827 *
828 * Returns: (transfer full) (type gchar*): a string containing the color
829 * definition
830 */
831 gchar *
832 gst_debug_construct_term_color (guint colorinfo)
833 {
834 GString *color;
836 color = g_string_new ("\033[00");
838 if (colorinfo & GST_DEBUG_BOLD) {
839 g_string_append_len (color, ";01", 3);
840 }
841 if (colorinfo & GST_DEBUG_UNDERLINE) {
842 g_string_append_len (color, ";04", 3);
843 }
844 if (colorinfo & GST_DEBUG_FG_MASK) {
845 g_string_append_printf (color, ";3%1d", colorinfo & GST_DEBUG_FG_MASK);
846 }
847 if (colorinfo & GST_DEBUG_BG_MASK) {
848 g_string_append_printf (color, ";4%1d",
849 (colorinfo & GST_DEBUG_BG_MASK) >> 4);
850 }
851 g_string_append_c (color, 'm');
853 return g_string_free (color, FALSE);
854 }
856 /**
857 * gst_debug_construct_win_color:
858 * @colorinfo: the color info
859 *
860 * Constructs an integer that can be used for getting the desired color in
861 * windows' terminals (cmd.exe). As there is no mean to underline, we simply
862 * ignore this attribute.
863 *
864 * This function returns 0 on non-windows machines.
865 *
866 * Returns: an integer containing the color definition
867 *
868 * Since: 0.10.23
869 */
870 gint
871 gst_debug_construct_win_color (guint colorinfo)
872 {
873 gint color = 0;
874 #ifdef G_OS_WIN32
875 static const guchar ansi_to_win_fg[8] = {
876 0, /* black */
877 FOREGROUND_RED, /* red */
878 FOREGROUND_GREEN, /* green */
879 FOREGROUND_RED | FOREGROUND_GREEN, /* yellow */
880 FOREGROUND_BLUE, /* blue */
881 FOREGROUND_RED | FOREGROUND_BLUE, /* magenta */
882 FOREGROUND_GREEN | FOREGROUND_BLUE, /* cyan */
883 FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE /* white */
884 };
885 static const guchar ansi_to_win_bg[8] = {
886 0,
887 BACKGROUND_RED,
888 BACKGROUND_GREEN,
889 BACKGROUND_RED | BACKGROUND_GREEN,
890 BACKGROUND_BLUE,
891 BACKGROUND_RED | BACKGROUND_BLUE,
892 BACKGROUND_GREEN | FOREGROUND_BLUE,
893 BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE
894 };
896 /* we draw black as white, as cmd.exe can only have black bg */
897 if (colorinfo == 0) {
898 return ansi_to_win_fg[7];
899 }
901 if (colorinfo & GST_DEBUG_BOLD) {
902 color |= FOREGROUND_INTENSITY;
903 }
904 if (colorinfo & GST_DEBUG_FG_MASK) {
905 color |= ansi_to_win_fg[colorinfo & GST_DEBUG_FG_MASK];
906 }
907 if (colorinfo & GST_DEBUG_BG_MASK) {
908 color |= ansi_to_win_bg[(colorinfo & GST_DEBUG_BG_MASK) >> 4];
909 }
910 #endif
911 return color;
912 }
914 /* width of %p varies depending on actual value of pointer, which can make
915 * output unevenly aligned if multiple threads are involved, hence the %14p
916 * (should really be %18p, but %14p seems a good compromise between too many
917 * white spaces and likely unalignment on my system) */
918 #if defined (GLIB_SIZEOF_VOID_P) && GLIB_SIZEOF_VOID_P == 8
919 #define PTR_FMT "%14p"
920 #else
921 #define PTR_FMT "%10p"
922 #endif
923 #define PID_FMT "%5d"
924 #define CAT_FMT "%20s %s:%d:%s:%s"
926 #ifdef G_OS_WIN32
927 static const guchar levelcolormap[GST_LEVEL_COUNT] = {
928 /* GST_LEVEL_NONE */
929 FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE,
930 /* GST_LEVEL_ERROR */
931 FOREGROUND_RED | FOREGROUND_INTENSITY,
932 /* GST_LEVEL_WARNING */
933 FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY,
934 /* GST_LEVEL_INFO */
935 FOREGROUND_GREEN | FOREGROUND_INTENSITY,
936 /* GST_LEVEL_DEBUG */
937 FOREGROUND_GREEN | FOREGROUND_BLUE,
938 /* GST_LEVEL_LOG */
939 FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE,
940 /* GST_LEVEL_FIXME */
941 FOREGROUND_RED | FOREGROUND_GREEN,
942 /* GST_LEVEL_TRACE */
943 FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE,
944 /* placeholder for log level 8 */
945 0,
946 /* GST_LEVEL_MEMDUMP */
947 FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE
948 };
950 static const guchar available_colors[] = {
951 FOREGROUND_RED, FOREGROUND_GREEN, FOREGROUND_RED | FOREGROUND_GREEN,
952 FOREGROUND_BLUE, FOREGROUND_RED | FOREGROUND_BLUE,
953 FOREGROUND_GREEN | FOREGROUND_BLUE,
954 };
955 #else
956 static const gchar *levelcolormap[GST_LEVEL_COUNT] = {
957 "\033[37m", /* GST_LEVEL_NONE */
958 "\033[31;01m", /* GST_LEVEL_ERROR */
959 "\033[33;01m", /* GST_LEVEL_WARNING */
960 "\033[32;01m", /* GST_LEVEL_INFO */
961 "\033[36m", /* GST_LEVEL_DEBUG */
962 "\033[37m", /* GST_LEVEL_LOG */
963 "\033[33;01m", /* GST_LEVEL_FIXME */
964 "\033[37m", /* GST_LEVEL_TRACE */
965 "\033[37m", /* placeholder for log level 8 */
966 "\033[37m" /* GST_LEVEL_MEMDUMP */
967 };
968 #endif
970 /**
971 * gst_debug_log_default:
972 * @category: category to log
973 * @level: level of the message
974 * @file: the file that emitted the message, usually the __FILE__ identifier
975 * @function: the function that emitted the message
976 * @line: the line from that the message was emitted, usually __LINE__
977 * @message: the actual message
978 * @object: (transfer none) (allow-none): the object this message relates to,
979 * or NULL if none
980 * @unused: an unused variable, reserved for some user_data.
981 *
982 * The default logging handler used by GStreamer. Logging functions get called
983 * whenever a macro like GST_DEBUG or similar is used. This function outputs the
984 * message and additional info to stderr (or the log file specified via the
985 * GST_DEBUG_FILE environment variable).
986 *
987 * You can add other handlers by using gst_debug_add_log_function().
988 * And you can remove this handler by calling
989 * gst_debug_remove_log_function(gst_debug_log_default);
990 */
991 void
992 gst_debug_log_default (GstDebugCategory * category, GstDebugLevel level,
993 const gchar * file, const gchar * function, gint line,
994 GObject * object, GstDebugMessage * message, gpointer unused)
995 {
996 gint pid;
997 GstClockTime elapsed;
998 gchar *obj = NULL;
999 gboolean is_colored;
1001 if (level > gst_debug_category_get_threshold (category))
1002 return;
1004 pid = getpid ();
1005 is_colored = gst_debug_is_colored ();
1007 if (object) {
1008 obj = gst_debug_print_object (object);
1009 } else {
1010 obj = g_strdup ("");
1011 }
1013 elapsed = GST_CLOCK_DIFF (_priv_gst_info_start_time,
1014 gst_util_get_timestamp ());
1016 if (is_colored) {
1017 #ifndef G_OS_WIN32
1018 /* colors, non-windows */
1019 gchar *color = NULL;
1020 const gchar *clear;
1021 gchar pidcolor[10];
1022 const gchar *levelcolor;
1024 color = gst_debug_construct_term_color (gst_debug_category_get_color
1025 (category));
1026 clear = "\033[00m";
1027 g_sprintf (pidcolor, "\033[3%1dm", pid % 6 + 31);
1028 levelcolor = levelcolormap[level];
1030 #define PRINT_FMT " %s"PID_FMT"%s "PTR_FMT" %s%s%s %s"CAT_FMT"%s %s\n"
1031 fprintf (log_file, "%" GST_TIME_FORMAT PRINT_FMT, GST_TIME_ARGS (elapsed),
1032 pidcolor, pid, clear, g_thread_self (), levelcolor,
1033 gst_debug_level_get_name (level), clear, color,
1034 gst_debug_category_get_name (category), file, line, function, obj,
1035 clear, gst_debug_message_get (message));
1036 fflush (log_file);
1037 #undef PRINT_FMT
1038 g_free (color);
1039 #else
1040 /* colors, windows. We take a lock to keep colors and content together.
1041 * Maybe there is a better way but for now this will do the right
1042 * thing. */
1043 static GStaticMutex win_print_mutex = G_STATIC_MUTEX_INIT;
1044 const gint clear = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
1045 #define SET_COLOR(c) G_STMT_START { \
1046 if (log_file == stderr) \
1047 SetConsoleTextAttribute (GetStdHandle (STD_ERROR_HANDLE), (c)); \
1048 } G_STMT_END
1049 g_static_mutex_lock (&win_print_mutex);
1050 /* timestamp */
1051 fprintf (log_file, "%" GST_TIME_FORMAT " ", GST_TIME_ARGS (elapsed));
1052 fflush (log_file);
1053 /* pid */
1054 SET_COLOR (available_colors[pid % G_N_ELEMENTS (available_colors)]);
1055 fprintf (log_file, PID_FMT, pid);
1056 fflush (log_file);
1057 /* thread */
1058 SET_COLOR (clear);
1059 fprintf (log_file, " " PTR_FMT " ", g_thread_self ());
1060 fflush (log_file);
1061 /* level */
1062 SET_COLOR (levelcolormap[level]);
1063 fprintf (log_file, "%s ", gst_debug_level_get_name (level));
1064 fflush (log_file);
1065 /* category */
1066 SET_COLOR (gst_debug_construct_win_color (gst_debug_category_get_color
1067 (category)));
1068 fprintf (log_file, CAT_FMT, gst_debug_category_get_name (category),
1069 file, line, function, obj);
1070 fflush (log_file);
1071 /* message */
1072 SET_COLOR (clear);
1073 fprintf (log_file, " %s\n", gst_debug_message_get (message));
1074 fflush (log_file);
1075 g_static_mutex_unlock (&win_print_mutex);
1076 #endif
1077 } else {
1078 /* no color, all platforms */
1079 #define PRINT_FMT " "PID_FMT" "PTR_FMT" %s "CAT_FMT" %s\n"
1080 fprintf (log_file, "%" GST_TIME_FORMAT PRINT_FMT, GST_TIME_ARGS (elapsed),
1081 pid, g_thread_self (), gst_debug_level_get_name (level),
1082 gst_debug_category_get_name (category), file, line, function, obj,
1083 gst_debug_message_get (message));
1084 fflush (log_file);
1085 #undef PRINT_FMT
1086 }
1088 g_free (obj);
1089 }
1091 /**
1092 * gst_debug_level_get_name:
1093 * @level: the level to get the name for
1094 *
1095 * Get the string representation of a debugging level
1096 *
1097 * Returns: the name
1098 */
1099 const gchar *
1100 gst_debug_level_get_name (GstDebugLevel level)
1101 {
1102 switch (level) {
1103 case GST_LEVEL_NONE:
1104 return "";
1105 case GST_LEVEL_ERROR:
1106 return "ERROR ";
1107 case GST_LEVEL_WARNING:
1108 return "WARN ";
1109 case GST_LEVEL_INFO:
1110 return "INFO ";
1111 case GST_LEVEL_DEBUG:
1112 return "DEBUG ";
1113 case GST_LEVEL_LOG:
1114 return "LOG ";
1115 case GST_LEVEL_FIXME:
1116 return "FIXME ";
1117 case GST_LEVEL_TRACE:
1118 return "TRACE ";
1119 case GST_LEVEL_MEMDUMP:
1120 return "MEMDUMP";
1121 default:
1122 g_warning ("invalid level specified for gst_debug_level_get_name");
1123 return "";
1124 }
1125 }
1127 /**
1128 * gst_debug_add_log_function:
1129 * @func: the function to use
1130 * @data: (closure): user data
1131 *
1132 * Adds the logging function to the list of logging functions.
1133 * Be sure to use #G_GNUC_NO_INSTRUMENT on that function, it is needed.
1134 */
1135 void
1136 gst_debug_add_log_function (GstLogFunction func, gpointer data)
1137 {
1138 LogFuncEntry *entry;
1139 GSList *list;
1141 if (func == NULL)
1142 func = gst_debug_log_default;
1144 entry = g_slice_new (LogFuncEntry);
1145 entry->func = func;
1146 entry->user_data = data;
1147 /* FIXME: we leak the old list here - other threads might access it right now
1148 * in gst_debug_logv. Another solution is to lock the mutex in gst_debug_logv,
1149 * but that is waaay costly.
1150 * It'd probably be clever to use some kind of RCU here, but I don't know
1151 * anything about that.
1152 */
1153 g_static_mutex_lock (&__log_func_mutex);
1154 list = g_slist_copy (__log_functions);
1155 __log_functions = g_slist_prepend (list, entry);
1156 g_static_mutex_unlock (&__log_func_mutex);
1158 GST_DEBUG ("prepended log function %p (user data %p) to log functions",
1159 func, data);
1160 }
1162 static gint
1163 gst_debug_compare_log_function_by_func (gconstpointer entry, gconstpointer func)
1164 {
1165 gpointer entryfunc = (gpointer) (((LogFuncEntry *) entry)->func);
1167 return (entryfunc < func) ? -1 : (entryfunc > func) ? 1 : 0;
1168 }
1170 static gint
1171 gst_debug_compare_log_function_by_data (gconstpointer entry, gconstpointer data)
1172 {
1173 gpointer entrydata = ((LogFuncEntry *) entry)->user_data;
1175 return (entrydata < data) ? -1 : (entrydata > data) ? 1 : 0;
1176 }
1178 static guint
1179 gst_debug_remove_with_compare_func (GCompareFunc func, gpointer data)
1180 {
1181 GSList *found;
1182 GSList *new;
1183 guint removals = 0;
1185 g_static_mutex_lock (&__log_func_mutex);
1186 new = __log_functions;
1187 while ((found = g_slist_find_custom (new, data, func))) {
1188 if (new == __log_functions) {
1189 /* make a copy when we have the first hit, so that we modify the copy and
1190 * make that the new list later */
1191 new = g_slist_copy (new);
1192 continue;
1193 }
1194 g_slice_free (LogFuncEntry, found->data);
1195 new = g_slist_delete_link (new, found);
1196 removals++;
1197 }
1198 /* FIXME: We leak the old list here. See _add_log_function for why. */
1199 __log_functions = new;
1200 g_static_mutex_unlock (&__log_func_mutex);
1202 return removals;
1203 }
1205 /**
1206 * gst_debug_remove_log_function:
1207 * @func: the log function to remove
1208 *
1209 * Removes all registered instances of the given logging functions.
1210 *
1211 * Returns: How many instances of the function were removed
1212 */
1213 guint
1214 gst_debug_remove_log_function (GstLogFunction func)
1215 {
1216 guint removals;
1218 if (func == NULL)
1219 func = gst_debug_log_default;
1221 removals =
1222 gst_debug_remove_with_compare_func
1223 (gst_debug_compare_log_function_by_func, (gpointer) func);
1224 GST_DEBUG ("removed log function %p %d times from log function list", func,
1225 removals);
1227 return removals;
1228 }
1230 /**
1231 * gst_debug_remove_log_function_by_data:
1232 * @data: user data of the log function to remove
1233 *
1234 * Removes all registered instances of log functions with the given user data.
1235 *
1236 * Returns: How many instances of the function were removed
1237 */
1238 guint
1239 gst_debug_remove_log_function_by_data (gpointer data)
1240 {
1241 guint removals;
1243 removals =
1244 gst_debug_remove_with_compare_func
1245 (gst_debug_compare_log_function_by_data, data);
1246 GST_DEBUG
1247 ("removed %d log functions with user data %p from log function list",
1248 removals, data);
1250 return removals;
1251 }
1253 /**
1254 * gst_debug_set_colored:
1255 * @colored: Whether to use colored output or not
1256 *
1257 * Sets or unsets the use of coloured debugging output.
1258 *
1259 * This function may be called before gst_init().
1260 */
1261 void
1262 gst_debug_set_colored (gboolean colored)
1263 {
1264 g_atomic_int_set (&__use_color, (gint) colored);
1265 }
1267 /**
1268 * gst_debug_is_colored:
1269 *
1270 * Checks if the debugging output should be colored.
1271 *
1272 * Returns: TRUE, if the debug output should be colored.
1273 */
1274 gboolean
1275 gst_debug_is_colored (void)
1276 {
1277 return (gboolean) g_atomic_int_get (&__use_color);
1278 }
1280 /**
1281 * gst_debug_set_active:
1282 * @active: Whether to use debugging output or not
1283 *
1284 * If activated, debugging messages are sent to the debugging
1285 * handlers.
1286 * It makes sense to deactivate it for speed issues.
1287 * <note><para>This function is not threadsafe. It makes sense to only call it
1288 * during initialization.</para></note>
1289 */
1290 void
1291 gst_debug_set_active (gboolean active)
1292 {
1293 __gst_debug_enabled = active;
1294 if (active)
1295 __gst_debug_min = GST_LEVEL_COUNT;
1296 else
1297 __gst_debug_min = GST_LEVEL_NONE;
1298 }
1300 /**
1301 * gst_debug_is_active:
1302 *
1303 * Checks if debugging output is activated.
1304 *
1305 * Returns: TRUE, if debugging is activated
1306 */
1307 gboolean
1308 gst_debug_is_active (void)
1309 {
1310 return __gst_debug_enabled;
1311 }
1313 /**
1314 * gst_debug_set_default_threshold:
1315 * @level: level to set
1316 *
1317 * Sets the default threshold to the given level and updates all categories to
1318 * use this threshold.
1319 *
1320 * This function may be called before gst_init().
1321 */
1322 void
1323 gst_debug_set_default_threshold (GstDebugLevel level)
1324 {
1325 g_atomic_int_set (&__default_level, level);
1326 gst_debug_reset_all_thresholds ();
1327 }
1329 /**
1330 * gst_debug_get_default_threshold:
1331 *
1332 * Returns the default threshold that is used for new categories.
1333 *
1334 * Returns: the default threshold level
1335 */
1336 GstDebugLevel
1337 gst_debug_get_default_threshold (void)
1338 {
1339 return (GstDebugLevel) g_atomic_int_get (&__default_level);
1340 }
1342 static void
1343 gst_debug_reset_threshold (gpointer category, gpointer unused)
1344 {
1345 GstDebugCategory *cat = (GstDebugCategory *) category;
1346 GSList *walk;
1348 g_static_mutex_lock (&__level_name_mutex);
1349 walk = __level_name;
1350 while (walk) {
1351 LevelNameEntry *entry = walk->data;
1353 walk = g_slist_next (walk);
1354 if (g_pattern_match_string (entry->pat, cat->name)) {
1355 GST_LOG ("category %s matches pattern %p - gets set to level %d",
1356 cat->name, entry->pat, entry->level);
1357 gst_debug_category_set_threshold (cat, entry->level);
1358 goto exit;
1359 }
1360 }
1361 gst_debug_category_set_threshold (cat, gst_debug_get_default_threshold ());
1363 exit:
1364 g_static_mutex_unlock (&__level_name_mutex);
1365 }
1367 static void
1368 gst_debug_reset_all_thresholds (void)
1369 {
1370 g_static_mutex_lock (&__cat_mutex);
1371 g_slist_foreach (__categories, gst_debug_reset_threshold, NULL);
1372 g_static_mutex_unlock (&__cat_mutex);
1373 }
1375 static void
1376 for_each_threshold_by_entry (gpointer data, gpointer user_data)
1377 {
1378 GstDebugCategory *cat = (GstDebugCategory *) data;
1379 LevelNameEntry *entry = (LevelNameEntry *) user_data;
1381 if (g_pattern_match_string (entry->pat, cat->name)) {
1382 GST_LOG ("category %s matches pattern %p - gets set to level %d",
1383 cat->name, entry->pat, entry->level);
1384 gst_debug_category_set_threshold (cat, entry->level);
1385 }
1386 }
1388 /**
1389 * gst_debug_set_threshold_for_name:
1390 * @name: name of the categories to set
1391 * @level: level to set them to
1392 *
1393 * Sets all categories which match the given glob style pattern to the given
1394 * level.
1395 */
1396 void
1397 gst_debug_set_threshold_for_name (const gchar * name, GstDebugLevel level)
1398 {
1399 GPatternSpec *pat;
1400 LevelNameEntry *entry;
1402 g_return_if_fail (name != NULL);
1404 pat = g_pattern_spec_new (name);
1405 entry = g_slice_new (LevelNameEntry);
1406 entry->pat = pat;
1407 entry->level = level;
1408 g_static_mutex_lock (&__level_name_mutex);
1409 __level_name = g_slist_prepend (__level_name, entry);
1410 g_static_mutex_unlock (&__level_name_mutex);
1411 g_static_mutex_lock (&__cat_mutex);
1412 g_slist_foreach (__categories, for_each_threshold_by_entry, entry);
1413 g_static_mutex_unlock (&__cat_mutex);
1414 }
1416 /**
1417 * gst_debug_unset_threshold_for_name:
1418 * @name: name of the categories to set
1419 *
1420 * Resets all categories with the given name back to the default level.
1421 */
1422 void
1423 gst_debug_unset_threshold_for_name (const gchar * name)
1424 {
1425 GSList *walk;
1426 GPatternSpec *pat;
1428 g_return_if_fail (name != NULL);
1430 pat = g_pattern_spec_new (name);
1431 g_static_mutex_lock (&__level_name_mutex);
1432 walk = __level_name;
1433 /* improve this if you want, it's mighty slow */
1434 while (walk) {
1435 LevelNameEntry *entry = walk->data;
1437 if (g_pattern_spec_equal (entry->pat, pat)) {
1438 __level_name = g_slist_remove_link (__level_name, walk);
1439 g_pattern_spec_free (entry->pat);
1440 g_slice_free (LevelNameEntry, entry);
1441 g_slist_free_1 (walk);
1442 walk = __level_name;
1443 }
1444 }
1445 g_static_mutex_unlock (&__level_name_mutex);
1446 g_pattern_spec_free (pat);
1447 gst_debug_reset_all_thresholds ();
1448 }
1450 GstDebugCategory *
1451 _gst_debug_category_new (const gchar * name, guint color,
1452 const gchar * description)
1453 {
1454 GstDebugCategory *cat;
1456 g_return_val_if_fail (name != NULL, NULL);
1458 cat = g_slice_new (GstDebugCategory);
1459 cat->name = g_strdup (name);
1460 cat->color = color;
1461 if (description != NULL) {
1462 cat->description = g_strdup (description);
1463 } else {
1464 cat->description = g_strdup ("no description");
1465 }
1466 g_atomic_int_set (&cat->threshold, 0);
1467 gst_debug_reset_threshold (cat, NULL);
1469 /* add to category list */
1470 g_static_mutex_lock (&__cat_mutex);
1471 __categories = g_slist_prepend (__categories, cat);
1472 g_static_mutex_unlock (&__cat_mutex);
1474 return cat;
1475 }
1477 /**
1478 * gst_debug_category_free:
1479 * @category: #GstDebugCategory to free.
1480 *
1481 * Removes and frees the category and all associated resources.
1482 */
1483 void
1484 gst_debug_category_free (GstDebugCategory * category)
1485 {
1486 if (category == NULL)
1487 return;
1489 /* remove from category list */
1490 g_static_mutex_lock (&__cat_mutex);
1491 __categories = g_slist_remove (__categories, category);
1492 g_static_mutex_unlock (&__cat_mutex);
1494 g_free ((gpointer) category->name);
1495 g_free ((gpointer) category->description);
1496 g_slice_free (GstDebugCategory, category);
1497 }
1499 /**
1500 * gst_debug_category_set_threshold:
1501 * @category: a #GstDebugCategory to set threshold of.
1502 * @level: the #GstDebugLevel threshold to set.
1503 *
1504 * Sets the threshold of the category to the given level. Debug information will
1505 * only be output if the threshold is lower or equal to the level of the
1506 * debugging message.
1507 * <note><para>
1508 * Do not use this function in production code, because other functions may
1509 * change the threshold of categories as side effect. It is however a nice
1510 * function to use when debugging (even from gdb).
1511 * </para></note>
1512 */
1513 void
1514 gst_debug_category_set_threshold (GstDebugCategory * category,
1515 GstDebugLevel level)
1516 {
1517 g_return_if_fail (category != NULL);
1519 if (level > __gst_debug_min) {
1520 __gst_debug_enabled = TRUE;
1521 __gst_debug_min = level;
1522 }
1524 g_atomic_int_set (&category->threshold, level);
1525 }
1527 /**
1528 * gst_debug_category_reset_threshold:
1529 * @category: a #GstDebugCategory to reset threshold of.
1530 *
1531 * Resets the threshold of the category to the default level. Debug information
1532 * will only be output if the threshold is lower or equal to the level of the
1533 * debugging message.
1534 * Use this function to set the threshold back to where it was after using
1535 * gst_debug_category_set_threshold().
1536 */
1537 void
1538 gst_debug_category_reset_threshold (GstDebugCategory * category)
1539 {
1540 gst_debug_reset_threshold (category, NULL);
1541 }
1543 /**
1544 * gst_debug_category_get_threshold:
1545 * @category: a #GstDebugCategory to get threshold of.
1546 *
1547 * Returns the threshold of a #GstDebugCategory.
1548 *
1549 * Returns: the #GstDebugLevel that is used as threshold.
1550 */
1551 GstDebugLevel
1552 gst_debug_category_get_threshold (GstDebugCategory * category)
1553 {
1554 return (GstDebugLevel) g_atomic_int_get (&category->threshold);
1555 }
1557 /**
1558 * gst_debug_category_get_name:
1559 * @category: a #GstDebugCategory to get name of.
1560 *
1561 * Returns the name of a debug category.
1562 *
1563 * Returns: the name of the category.
1564 */
1565 const gchar *
1566 gst_debug_category_get_name (GstDebugCategory * category)
1567 {
1568 return category->name;
1569 }
1571 /**
1572 * gst_debug_category_get_color:
1573 * @category: a #GstDebugCategory to get the color of.
1574 *
1575 * Returns the color of a debug category used when printing output in this
1576 * category.
1577 *
1578 * Returns: the color of the category.
1579 */
1580 guint
1581 gst_debug_category_get_color (GstDebugCategory * category)
1582 {
1583 return category->color;
1584 }
1586 /**
1587 * gst_debug_category_get_description:
1588 * @category: a #GstDebugCategory to get the description of.
1589 *
1590 * Returns the description of a debug category.
1591 *
1592 * Returns: the description of the category.
1593 */
1594 const gchar *
1595 gst_debug_category_get_description (GstDebugCategory * category)
1596 {
1597 return category->description;
1598 }
1600 /**
1601 * gst_debug_get_all_categories:
1602 *
1603 * Returns a snapshot of a all categories that are currently in use . This list
1604 * may change anytime.
1605 * The caller has to free the list after use.
1606 *
1607 * Returns: (transfer container) (element-type Gst.DebugCategory): the list of
1608 * debug categories
1609 */
1610 GSList *
1611 gst_debug_get_all_categories (void)
1612 {
1613 GSList *ret;
1615 g_static_mutex_lock (&__cat_mutex);
1616 ret = g_slist_copy (__categories);
1617 g_static_mutex_unlock (&__cat_mutex);
1619 return ret;
1620 }
1622 GstDebugCategory *
1623 _gst_debug_get_category (const gchar * name)
1624 {
1625 GstDebugCategory *ret = NULL;
1626 GSList *node;
1628 for (node = __categories; node; node = g_slist_next (node)) {
1629 ret = (GstDebugCategory *) node->data;
1630 if (!strcmp (name, ret->name)) {
1631 return ret;
1632 }
1633 }
1634 return NULL;
1635 }
1637 /*** FUNCTION POINTERS ********************************************************/
1639 static GHashTable *__gst_function_pointers; /* NULL */
1640 static GStaticMutex __dbg_functions_mutex = G_STATIC_MUTEX_INIT;
1642 /* This function MUST NOT return NULL */
1643 const gchar *
1644 _gst_debug_nameof_funcptr (GstDebugFuncPtr func)
1645 {
1646 gchar *ptrname;
1648 #ifdef HAVE_DLADDR
1649 Dl_info dl_info;
1650 #endif
1652 if (G_UNLIKELY (func == NULL))
1653 return "(NULL)";
1655 g_static_mutex_lock (&__dbg_functions_mutex);
1656 if (G_LIKELY (__gst_function_pointers)) {
1657 ptrname = g_hash_table_lookup (__gst_function_pointers, (gpointer) func);
1658 g_static_mutex_unlock (&__dbg_functions_mutex);
1659 if (G_LIKELY (ptrname))
1660 return ptrname;
1661 } else {
1662 g_static_mutex_unlock (&__dbg_functions_mutex);
1663 }
1664 /* we need to create an entry in the hash table for this one so we don't leak
1665 * the name */
1666 #ifdef HAVE_DLADDR
1667 if (dladdr ((gpointer) func, &dl_info) && dl_info.dli_sname) {
1668 gchar *name = g_strdup (dl_info.dli_sname);
1670 _gst_debug_register_funcptr (func, name);
1671 return name;
1672 } else
1673 #endif
1674 {
1675 gchar *name = g_strdup_printf ("%p", (gpointer) func);
1677 _gst_debug_register_funcptr (func, name);
1678 return name;
1679 }
1680 }
1682 void
1683 _gst_debug_register_funcptr (GstDebugFuncPtr func, const gchar * ptrname)
1684 {
1685 gpointer ptr = (gpointer) func;
1687 g_static_mutex_lock (&__dbg_functions_mutex);
1689 if (!__gst_function_pointers)
1690 __gst_function_pointers = g_hash_table_new (g_direct_hash, g_direct_equal);
1691 if (!g_hash_table_lookup (__gst_function_pointers, ptr))
1692 g_hash_table_insert (__gst_function_pointers, ptr, (gpointer) ptrname);
1694 g_static_mutex_unlock (&__dbg_functions_mutex);
1695 }
1697 /*** PRINTF EXTENSIONS ********************************************************/
1699 #ifdef HAVE_PRINTF_EXTENSION
1700 static int
1701 _gst_info_printf_extension_ptr (FILE * stream, const struct printf_info *info,
1702 const void *const *args)
1703 {
1704 char *buffer;
1705 int len;
1706 void *ptr;
1708 buffer = NULL;
1709 ptr = *(void **) args[0];
1711 buffer = gst_debug_print_object (ptr);
1712 len = fprintf (stream, "%*s", (info->left ? -info->width : info->width),
1713 buffer);
1715 g_free (buffer);
1716 return len;
1717 }
1719 static int
1720 _gst_info_printf_extension_segment (FILE * stream,
1721 const struct printf_info *info, const void *const *args)
1722 {
1723 char *buffer;
1724 int len;
1725 void *ptr;
1727 buffer = NULL;
1728 ptr = *(void **) args[0];
1730 buffer = gst_debug_print_segment (ptr);
1731 len = fprintf (stream, "%*s", (info->left ? -info->width : info->width),
1732 buffer);
1734 g_free (buffer);
1735 return len;
1736 }
1738 #ifdef HAVE_REGISTER_PRINTF_SPECIFIER
1739 static int
1740 _gst_info_printf_extension_arginfo (const struct printf_info *info, size_t n,
1741 int *argtypes, int *size)
1742 #else
1743 static int
1744 _gst_info_printf_extension_arginfo (const struct printf_info *info, size_t n,
1745 int *argtypes)
1746 #endif
1747 {
1748 if (n > 0) {
1749 argtypes[0] = PA_POINTER;
1750 #ifdef HAVE_REGISTER_PRINTF_SPECIFIER
1751 *size = sizeof (gpointer);
1752 #endif
1753 }
1754 return 1;
1755 }
1756 #endif /* HAVE_PRINTF_EXTENSION */
1758 static void
1759 gst_info_dump_mem_line (gchar * linebuf, gsize linebuf_size,
1760 const guint8 * mem, gsize mem_offset, gsize mem_size)
1761 {
1762 gchar hexstr[50], ascstr[18], digitstr[4];
1764 if (mem_size > 16)
1765 mem_size = 16;
1767 hexstr[0] = '\0';
1768 ascstr[0] = '\0';
1770 if (mem != NULL) {
1771 guint i = 0;
1773 mem += mem_offset;
1774 while (i < mem_size) {
1775 ascstr[i] = (g_ascii_isprint (mem[i])) ? mem[i] : '.';
1776 g_snprintf (digitstr, sizeof (digitstr), "%02x ", mem[i]);
1777 g_strlcat (hexstr, digitstr, sizeof (hexstr));
1778 ++i;
1779 }
1780 ascstr[i] = '\0';
1781 }
1783 g_snprintf (linebuf, linebuf_size, "%08x: %-48.48s %-16.16s",
1784 (guint) mem_offset, hexstr, ascstr);
1785 }
1787 void
1788 _gst_debug_dump_mem (GstDebugCategory * cat, const gchar * file,
1789 const gchar * func, gint line, GObject * obj, const gchar * msg,
1790 const guint8 * data, guint length)
1791 {
1792 guint off = 0;
1794 gst_debug_log ((cat), GST_LEVEL_MEMDUMP, file, func, line, obj, "--------"
1795 "-------------------------------------------------------------------");
1797 if (msg != NULL && *msg != '\0') {
1798 gst_debug_log ((cat), GST_LEVEL_MEMDUMP, file, func, line, obj, "%s", msg);
1799 }
1801 while (off < length) {
1802 gchar buf[128];
1804 /* gst_info_dump_mem_line will process 16 bytes at most */
1805 gst_info_dump_mem_line (buf, sizeof (buf), data, off, length - off);
1806 gst_debug_log (cat, GST_LEVEL_MEMDUMP, file, func, line, obj, "%s", buf);
1807 off += 16;
1808 }
1810 gst_debug_log ((cat), GST_LEVEL_MEMDUMP, file, func, line, obj, "--------"
1811 "-------------------------------------------------------------------");
1812 }
1814 #else /* !GST_DISABLE_GST_DEBUG */
1815 #ifndef GST_REMOVE_DISABLED
1817 GstDebugCategory *
1818 _gst_debug_category_new (const gchar * name, guint color,
1819 const gchar * description)
1820 {
1821 return NULL;
1822 }
1824 void
1825 _gst_debug_register_funcptr (GstDebugFuncPtr func, const gchar * ptrname)
1826 {
1827 }
1829 /* This function MUST NOT return NULL */
1830 const gchar *
1831 _gst_debug_nameof_funcptr (GstDebugFuncPtr func)
1832 {
1833 return "(NULL)";
1834 }
1836 void
1837 gst_debug_log (GstDebugCategory * category, GstDebugLevel level,
1838 const gchar * file, const gchar * function, gint line,
1839 GObject * object, const gchar * format, ...)
1840 {
1841 }
1843 void
1844 gst_debug_log_valist (GstDebugCategory * category, GstDebugLevel level,
1845 const gchar * file, const gchar * function, gint line,
1846 GObject * object, const gchar * format, va_list args)
1847 {
1848 }
1850 const gchar *
1851 gst_debug_message_get (GstDebugMessage * message)
1852 {
1853 return "";
1854 }
1856 void
1857 gst_debug_log_default (GstDebugCategory * category, GstDebugLevel level,
1858 const gchar * file, const gchar * function, gint line,
1859 GObject * object, GstDebugMessage * message, gpointer unused)
1860 {
1861 }
1863 const gchar *
1864 gst_debug_level_get_name (GstDebugLevel level)
1865 {
1866 return "NONE";
1867 }
1869 void
1870 gst_debug_add_log_function (GstLogFunction func, gpointer data)
1871 {
1872 }
1874 guint
1875 gst_debug_remove_log_function (GstLogFunction func)
1876 {
1877 return 0;
1878 }
1880 guint
1881 gst_debug_remove_log_function_by_data (gpointer data)
1882 {
1883 return 0;
1884 }
1886 void
1887 gst_debug_set_active (gboolean active)
1888 {
1889 }
1891 gboolean
1892 gst_debug_is_active (void)
1893 {
1894 return FALSE;
1895 }
1897 void
1898 gst_debug_set_colored (gboolean colored)
1899 {
1900 }
1902 gboolean
1903 gst_debug_is_colored (void)
1904 {
1905 return FALSE;
1906 }
1908 void
1909 gst_debug_set_default_threshold (GstDebugLevel level)
1910 {
1911 }
1913 GstDebugLevel
1914 gst_debug_get_default_threshold (void)
1915 {
1916 return GST_LEVEL_NONE;
1917 }
1919 void
1920 gst_debug_set_threshold_for_name (const gchar * name, GstDebugLevel level)
1921 {
1922 }
1924 void
1925 gst_debug_unset_threshold_for_name (const gchar * name)
1926 {
1927 }
1929 void
1930 gst_debug_category_free (GstDebugCategory * category)
1931 {
1932 }
1934 void
1935 gst_debug_category_set_threshold (GstDebugCategory * category,
1936 GstDebugLevel level)
1937 {
1938 }
1940 void
1941 gst_debug_category_reset_threshold (GstDebugCategory * category)
1942 {
1943 }
1945 GstDebugLevel
1946 gst_debug_category_get_threshold (GstDebugCategory * category)
1947 {
1948 return GST_LEVEL_NONE;
1949 }
1951 const gchar *
1952 gst_debug_category_get_name (GstDebugCategory * category)
1953 {
1954 return "";
1955 }
1957 guint
1958 gst_debug_category_get_color (GstDebugCategory * category)
1959 {
1960 return 0;
1961 }
1963 const gchar *
1964 gst_debug_category_get_description (GstDebugCategory * category)
1965 {
1966 return "";
1967 }
1969 GSList *
1970 gst_debug_get_all_categories (void)
1971 {
1972 return NULL;
1973 }
1975 GstDebugCategory *
1976 _gst_debug_get_category (const gchar * name)
1977 {
1978 return NULL;
1979 }
1981 gchar *
1982 gst_debug_construct_term_color (guint colorinfo)
1983 {
1984 return g_strdup ("00");
1985 }
1987 gint
1988 gst_debug_construct_win_color (guint colorinfo)
1989 {
1990 return 0;
1991 }
1993 gboolean
1994 _priv_gst_in_valgrind (void)
1995 {
1996 return FALSE;
1997 }
1999 void
2000 _gst_debug_dump_mem (GstDebugCategory * cat, const gchar * file,
2001 const gchar * func, gint line, GObject * obj, const gchar * msg,
2002 const guint8 * data, guint length)
2003 {
2004 }
2005 #endif /* GST_REMOVE_DISABLED */
2006 #endif /* GST_DISABLE_GST_DEBUG */
2009 #ifdef GST_ENABLE_FUNC_INSTRUMENTATION
2010 /* FIXME make this thread specific */
2011 static GSList *stack_trace = NULL;
2013 void
2014 __cyg_profile_func_enter (void *this_fn, void *call_site)
2015 G_GNUC_NO_INSTRUMENT;
2016 void __cyg_profile_func_enter (void *this_fn, void *call_site)
2017 {
2018 gchar *name = _gst_debug_nameof_funcptr (this_fn);
2019 gchar *site = _gst_debug_nameof_funcptr (call_site);
2021 GST_CAT_DEBUG (GST_CAT_CALL_TRACE, "entering function %s from %s", name,
2022 site);
2023 stack_trace =
2024 g_slist_prepend (stack_trace, g_strdup_printf ("%8p in %s from %p (%s)",
2025 this_fn, name, call_site, site));
2027 g_free (name);
2028 g_free (site);
2029 }
2031 void
2032 __cyg_profile_func_exit (void *this_fn, void *call_site)
2033 G_GNUC_NO_INSTRUMENT;
2034 void __cyg_profile_func_exit (void *this_fn, void *call_site)
2035 {
2036 gchar *name = _gst_debug_nameof_funcptr (this_fn);
2038 GST_CAT_DEBUG (GST_CAT_CALL_TRACE, "leaving function %s", name);
2039 g_free (stack_trace->data);
2040 stack_trace = g_slist_delete_link (stack_trace, stack_trace);
2042 g_free (name);
2043 }
2045 /**
2046 * gst_debug_print_stack_trace:
2047 *
2048 * If GST_ENABLE_FUNC_INSTRUMENTATION is defined a stacktrace is available for
2049 * gstreamer code, which can be printed with this function.
2050 */
2051 void
2052 gst_debug_print_stack_trace (void)
2053 {
2054 GSList *walk = stack_trace;
2055 gint count = 0;
2057 if (walk)
2058 walk = g_slist_next (walk);
2060 while (walk) {
2061 gchar *name = (gchar *) walk->data;
2063 g_print ("#%-2d %s\n", count++, name);
2065 walk = g_slist_next (walk);
2066 }
2067 }
2068 #else
2069 void
2070 gst_debug_print_stack_trace (void)
2071 {
2072 /* nothing because it's compiled out */
2073 }
2075 #endif /* GST_ENABLE_FUNC_INSTRUMENTATION */