Added DEBUG, INFO, and ERROR systems. Very little code is converted yet.

Original commit message from CVS:
Added DEBUG, INFO, and ERROR systems.  Very little code is converted yet.
Policy decisions need to be made as to what kinds of cases get what kind
of response, and what the default ERROR response should be.  Right now it
will print out all the information, then have gdb spew a stack trace.
This commit is contained in:
Erik Walthinsen 2000-12-29 10:02:17 +00:00
parent 104c1889ed
commit a80b0c26d5
12 changed files with 443 additions and 81 deletions

View file

@ -19,6 +19,7 @@ EXTRA_libgst_la_SOURCES = \
libgst_la_SOURCES = \
gst.c \
gstinfo.c \
$(GSTOBJECT_SRCS) \
gstpad.c \
gstautoplug.c \
@ -48,6 +49,7 @@ libgst_la_SOURCES = \
libgstincludedir = $(includedir)/gst
libgstinclude_HEADERS = \
gst.h \
gstinfo.h \
gstlog.h \
$(GSTOBJECT_INCLUDES) \
gstpad.h \
@ -70,7 +72,6 @@ libgstinclude_HEADERS = \
gstmeta.h \
gsttee.h \
gstxml.h \
gstdebug.h \
cothreads.h \
gstscheduler.h

View file

@ -31,9 +31,13 @@
#include "gstthread.h"
gchar *_gst_progname;
extern gint _gst_trace_on;
GHashTable *__gst_function_pointers = NULL;
/**
* gst_init:
@ -50,6 +54,8 @@ gst_init (int *argc, char **argv[])
if (!g_thread_supported ()) g_thread_init (NULL);
_gst_progname = g_strdup(*argv[0]);
gtk_init (argc,argv);
_gst_cpu_initialize ();

View file

@ -24,8 +24,7 @@
#ifndef __GST_H__
#define __GST_H__
#include <gst/gstdebug.h>
#include <gst/gstlog.h>
#include <gst/gstinfo.h>
#include <gst/gstobject.h>
#include <gst/gstpad.h>
#include <gst/gstbuffer.h>
@ -52,4 +51,6 @@ void gst_init(int *argc,char **argv[]);
void gst_main (void);
void gst_main_quit (void);
#include <gst/gstlog.h>
#endif /* __GST_H__ */

View file

@ -28,7 +28,6 @@
#include "config.h"
#endif
#include <gst/gstdebug.h>
//#include <gst/gstinfo.h>
#include <gst/gstinfo.h>
#endif /* __GST_PRIVATE_H__ */

View file

@ -171,7 +171,6 @@ gst_element_add_pad (GstElement *element, GstPad *pad)
element->numsinkpads++;
/* emit the NEW_PAD signal */
// g_print("emitting NEW_PAD signal, \"%s\"!\n",gst_pad_get_name(pad));
gtk_signal_emit (GTK_OBJECT (element), gst_element_signals[NEW_PAD], pad);
}
@ -227,8 +226,8 @@ gst_element_get_pad (GstElement *element, gchar *name)
/* look through the list, matching by name */
walk = element->pads;
while (walk) {
if (!strcmp (((GstPad *)(walk->data))->name, name))
return (GstPad *)(walk->data);
if (!strcmp ((GST_PAD(walk->data))->name, name))
return GST_PAD(walk->data);
walk = g_list_next (walk);
}
@ -305,16 +304,26 @@ gst_element_connect (GstElement *src, gchar *srcpadname,
/* obtain the pads requested */
srcpad = gst_element_get_pad (src, srcpadname);
g_return_if_fail (srcpad != NULL);
if (srcpad == NULL) {
ERROR(src,"source element has no pad \"%s\"",srcpadname);
return;
}
destpad = gst_element_get_pad (dest, destpadname);
g_return_if_fail (destpad != NULL);
if (srcpad == NULL) {
ERROR(dest,"destination element has no pad \"%s\"",destpadname);
return;
}
/* find the parent elements of each element */
srcparent = gst_object_get_parent (GST_OBJECT (src));
destparent = gst_object_get_parent (GST_OBJECT (dest));
/* have to make sure that they have the same parents... */
g_return_if_fail (srcparent == destparent);
if (srcparent != destparent) {
ERROR_OBJECT(srcparent,destparent,"%s and %s have different parents",
gst_element_get_name(src),gst_element_get_name(dest));
return;
}
/* we're satisified they can be connected, let's do it */
gst_pad_connect(srcpad,destpad);
@ -649,12 +658,11 @@ gst_element_load_thyself (xmlNodePtr parent,
guchar *value = NULL;
guchar *type = NULL;
// first get the needed tags to cunstruct the element
// first get the needed tags to construct the element
while (children) {
if (!strcmp (children->name, "name")) {
name = g_strdup (xmlNodeGetContent (children));
}
else if (!strcmp (children->name, "type")) {
} else if (!strcmp (children->name, "type")) {
type = g_strdup (xmlNodeGetContent (children));
}
children = children->next;
@ -662,7 +670,7 @@ gst_element_load_thyself (xmlNodePtr parent,
g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (type != NULL, NULL);
g_print ("gstelement: loading \"%s\" of type \"%s\"\n", name, type);
INFO(0,NULL,"loading \"%s\" of type \"%s\"\n", name, type);
element = gst_elementfactory_make (type, name);

View file

@ -26,7 +26,6 @@
#include <gnome-xml/parser.h>
#include <gst/gstlog.h>
#include <gst/gstobject.h>
#include <gst/gstpad.h>
#include <gst/cothreads.h>

197
gst/gstinfo.c Normal file
View file

@ -0,0 +1,197 @@
/* GStreamer
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
* 2000 Wim Taymans <wtay@chello.be>
*
* gstinfo.c: INFO, ERROR, and DEBUG systems
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "gst.h"
extern gchar *_gst_progname;
/***** DEBUG system *****/
GHashTable *__gst_function_pointers = NULL;
/***** INFO system *****/
GstInfoHandler _gst_info_handler = gst_default_info_handler;
void
gst_default_info_handler (gint level, gchar *file, gchar *function,
gint line, gchar *debug_string,
void *element, gchar *string)
{
if (element) {
if (debug_string)
fprintf(stderr,"INFO:%d:%s:%d%s: [%s] %s\n",
level,function,line,debug_string,gst_element_get_name(element),string);
else
fprintf(stderr,"INFO:%d:%s:%d: [%s] %s\n",
level,function,line,gst_element_get_name(element),string);
} else {
if (debug_string)
fprintf(stderr,"INFO:%d:%s:%d%s: %s\n",
level,function,line,debug_string,string);
else
fprintf(stderr,"INFO:%d:%s:%d: %s\n",
level,function,line,string);
}
g_free(string);
}
/***** ERROR system *****/
GstErrorHandler _gst_error_handler = gst_default_error_handler;
/*
gchar *gst_object_get_path_string(GstObject *object) {
GSList *parentage = NULL;
GSList *parents;
void *parent;
gchar *prevpath, *path = "";
const char *component;
gchar *separator = "";
gboolean free_component;
parentage = g_slist_prepend (NULL, object);
// first walk the object hierarchy to build a list of the parents
do {
if (GST_IS_OBJECT(object)) {
if (GST_IS_PAD(object)) {
parent = GST_PAD(object)->parent;
// } else if (GST_IS_ELEMENT(object)) {
// parent = gst_element_get_parent(GST_ELEMENT(object));
} else {
parent = gst_object_get_parent (object);
}
} else {
parentage = g_slist_prepend (parentage, NULL);
parent = NULL;
}
if (parent != NULL) {
parentage = g_slist_prepend (parentage, parent);
}
object = parent;
} while (object != NULL);
// then walk the parent list and print them out
parents = parentage;
while (parents) {
if (GST_IS_OBJECT(parents->data)) {
if (GST_IS_PAD(parents->data)) {
component = gst_pad_get_name(GST_PAD(parents->data));
separator = ".";
free_component = FALSE;
} else if (GST_IS_ELEMENT(parents->data)) {
component = gst_element_get_name(GST_ELEMENT(parents->data));
separator = "/";
free_component = FALSE;
} else {
// component = g_strdup_printf("a %s",gtk_type_name(gtk_identifier_get_type(parents->data)));
component = g_strdup_printf("unknown%p",parents->data);
separator = "/";
free_component = TRUE;
}
} else {
component = g_strdup_printf("%p",parents->data);
separator = "/";
free_component = TRUE;
}
prevpath = path;
path = g_strjoin(separator,prevpath,component,NULL);
g_free(prevpath);
if (free_component)
g_free((gchar *)component);
parents = g_slist_next(parents);
}
g_slist_free(parentage);
return path;
}
*/
void
gst_default_error_handler (gchar *file, gchar *function,
gint line, gchar *debug_string,
void *element, void *object, gchar *string)
{
int chars = 0;
GSList *parentage;
GstObject *parent;
gchar *path;
int i;
// if there are NULL pointers, point them to null strings to clean up output
if (!debug_string) debug_string = "";
if (!string) string = "";
// print out a preamble
fprintf(stderr,"***** GStreamer ERROR ***** in file %s at %s:%d%s\n",
file,function,line,debug_string);
// if there's an element, print out the pertinent information
if (element) {
if (GST_IS_ELEMENT(element)) {
path = gst_object_get_path_string(element);
fprintf(stderr,"Element: %s",path);
chars = 9 + strlen(path);
g_free(path);
} else {
fprintf(stderr,"Element ptr: %p",element);
chars = 15 + sizeof(void*)*2;
}
}
// if there's an object, print it out as well
if (object) {
// attempt to pad the line, or create a new one
if (chars < 40)
for (i=0;i<(40-chars)/8+1;i++) fprintf(stderr,"\t");
else
fprintf(stderr,"\n");
if (GST_IS_OBJECT(object)) {
path = gst_object_get_path_string(object);
fprintf(stderr,"Object: %s",path);
g_free(path);
} else {
fprintf(stderr,"Object ptr: %p",object);
}
}
fprintf(stderr,"\n");
fprintf(stderr,"Error: %s\n",string);
g_free(string);
fprintf(stderr,"***** attempting to stack trace.... *****\n");
g_on_error_stack_trace (_gst_progname);
exit(1);
}

View file

@ -20,84 +20,36 @@
* Boston, MA 02111-1307, USA.
*/
#ifndef __GSTDEBUG_H__
#define __GSTDEBUG_H__
#ifndef __GSTINFO_H__
#define __GSTINFO_H__
#include <stdio.h>
#include <gmodule.h>
#include <unistd.h>
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <gmodule.h>
#include <unistd.h>
#include <gst/gsttrace.h>
/**********************************************************************
* DEBUG system
**********************************************************************/
/* for include files that make too much noise normally */
#ifdef GST_DEBUG_FORCE_DISABLE
#undef GST_DEBUG_ENABLED
#endif
/* for applications that really really want all the noise */
#ifdef GST_DEBUG_FORCE_ENABLE
#define GST_DEBUG_ENABLED
#endif
#define GST_DEBUG_PREFIX(format,args...) \
"DEBUG(%d:%d)" __PRETTY_FUNCTION__ ":%d" format , getpid() , cothread_getcurrent() , __LINE__ , ## args
/* fallback, this should probably be a 'weak' symbol or something */
G_GNUC_UNUSED static gchar *_debug_string = NULL;
/**********************************************************************
* The following is a DEBUG_ENTER implementation that will wrap the
* function it sits at the head of. It removes the need for a
* DEBUG_LEAVE call. However, it segfaults whenever it gets anywhere
* near cothreads. We will not use it for the moment.
*/
typedef void (*_debug_function_f)();
G_GNUC_UNUSED static gchar *_debug_string_pointer = NULL;
G_GNUC_UNUSED static GModule *_debug_self_module = NULL;
#define _DEBUG_ENTER_BUILTIN(format,args...) \
static int _debug_in_wrapper = 0; \
gchar *_debug_string = ({ \
if (!_debug_in_wrapper) { \
void *_return_value; \
gchar *_debug_string; \
_debug_function_f function; \
void *_function_args = __builtin_apply_args(); \
_debug_in_wrapper = 1; \
_debug_string = g_strdup_printf(GST_DEBUG_PREFIX("")); \
_debug_string_pointer = _debug_string; \
fprintf(stderr,"%s: entered " __PRETTY_FUNCTION__ format "\n" , _debug_string , ## args ); \
if (_debug_self_module == NULL) _debug_self_module = g_module_open(NULL,0); \
g_module_symbol(_debug_self_module,__FUNCTION__,(gpointer *)&function); \
_return_value = __builtin_apply(function,_function_args,64); \
fprintf(stderr,"%s: left " __PRETTY_FUNCTION__ format "\n" , _debug_string , ## args ); \
g_free(_debug_string); \
__builtin_return(_return_value); \
} else { \
_debug_in_wrapper = 0; \
} \
_debug_string_pointer; \
});
/* WARNING: there's a gcc CPP bug lurking in here. The extra space before the ##args *
* somehow make the preprocessor leave the _debug_string. If it's removed, the *
* _debug_string somehow gets stripped along with the ##args, and that's all she wrote. */
#define _DEBUG_BUILTIN(format,args...) \
if (_debug_string != (void *)-1) { \
if (_debug_string) \
fprintf(stderr,"%s: " format , _debug_string , ## args); \
else \
fprintf(stderr,GST_DEBUG_PREFIX(": " format , ## args)); \
}
#define GST_DEBUG_PREFIX(format,args...) \
"DEBUG(%d:%d)" __PRETTY_FUNCTION__ ":%d" format , getpid() , cothread_getcurrent() , __LINE__ , ## args
#ifdef GST_DEBUG_ENABLED
#define DEBUG(format,args...) \
@ -160,4 +112,110 @@ _gst_debug_nameof_funcptr (void *ptr)
else return ptrname;
}
#endif /* __GST_H__ */
/**********************************************************************
* The following is a DEBUG_ENTER implementation that will wrap the
* function it sits at the head of. It removes the need for a
* DEBUG_LEAVE call. However, it segfaults whenever it gets anywhere
* near cothreads. We will not use it for the moment.
*
typedef void (*_debug_function_f)();
G_GNUC_UNUSED static gchar *_debug_string_pointer = NULL;
G_GNUC_UNUSED static GModule *_debug_self_module = NULL;
#define _DEBUG_ENTER_BUILTIN(format,args...) \
static int _debug_in_wrapper = 0; \
gchar *_debug_string = ({ \
if (!_debug_in_wrapper) { \
void *_return_value; \
gchar *_debug_string; \
_debug_function_f function; \
void *_function_args = __builtin_apply_args(); \
_debug_in_wrapper = 1; \
_debug_string = g_strdup_printf(GST_DEBUG_PREFIX("")); \
_debug_string_pointer = _debug_string; \
fprintf(stderr,"%s: entered " __PRETTY_FUNCTION__ format "\n" , _debug_string , ## args ); \
if (_debug_self_module == NULL) _debug_self_module = g_module_open(NULL,0); \
g_module_symbol(_debug_self_module,__FUNCTION__,(gpointer *)&function); \
_return_value = __builtin_apply(function,_function_args,64); \
fprintf(stderr,"%s: left " __PRETTY_FUNCTION__ format "\n" , _debug_string , ## args ); \
g_free(_debug_string); \
__builtin_return(_return_value); \
} else { \
_debug_in_wrapper = 0; \
} \
_debug_string_pointer; \
});
* WARNING: there's a gcc CPP bug lurking in here. The extra space before the ##args *
* somehow make the preprocessor leave the _debug_string. If it's removed, the *
* _debug_string somehow gets stripped along with the ##args, and that's all she wrote. *
#define _DEBUG_BUILTIN(format,args...) \
if (_debug_string != (void *)-1) { \
if (_debug_string) \
fprintf(stderr,"%s: " format , _debug_string , ## args); \
else \
fprintf(stderr,GST_DEBUG_PREFIX(": " format , ## args)); \
}
*/
/**********************************************************************
* INFO system
**********************************************************************/
typedef void (*GstInfoHandler) (gint level,gchar *file,gchar *function,
gint line,gchar *debug_string,
void *element,gchar *string);
void gst_default_info_handler (gint level,gchar *file,gchar *function,
gint line,gchar *debug_string,
void *element,gchar *string);
extern GstInfoHandler _gst_info_handler;
#define INFO(lvl,format,args...) \
_gst_info_handler(lvl,__FILE__,__PRETTY_FUNCTION__,__LINE__,_debug_string, \
NULL,g_strdup_printf( format , ## args ))
#define INFO_ELEMENT(lvl,element,object,format,args...) \
_gst_info_handler(lvl,__FILE__,__PRETTY_FUNCTION__,__LINE__,_debug_string, \
element,g_strdup_printf( format , ## args ))
#define GST_INFO_PLUGIN_LOAD 0
/**********************************************************************
* ERROR system
**********************************************************************/
typedef void (*GstErrorHandler) (gchar *file,gchar *function,
gint line,gchar *debug_string,
void *element,void *object,gchar *string);
void gst_default_error_handler (gchar *file,gchar *function,
gint line,gchar *debug_string,
void *element,void *object,gchar *string);
extern GstErrorHandler _gst_error_handler;
#define ERROR(element,format,args...) \
_gst_error_handler(__FILE__,__PRETTY_FUNCTION__,__LINE__,_debug_string, \
element,NULL,g_strdup_printf( format , ## args ))
#define ERROR_OBJECT(element,object,format,args...) \
_gst_error_handler(__FILE__,__PRETTY_FUNCTION__,__LINE__,_debug_string, \
element,object,g_strdup_printf( format , ## args ))
#define GST_ERROR_PLUGIN_LOAD 0
#endif /* __GSTINFO_H__ */

View file

@ -23,6 +23,8 @@
#include "gst_private.h"
#include "gstobject.h"
#include "gstpad.h"
#include "gstelement.h"
/* Object signals and args */
enum {
@ -110,11 +112,15 @@ GstObject *gst_object_new() {
void gst_object_set_parent(GstObject *object,GstObject *parent) {
g_return_if_fail(object != NULL);
g_return_if_fail(GST_IS_OBJECT(object));
g_return_if_fail(object->parent == NULL);
g_return_if_fail(parent != NULL);
g_return_if_fail(GST_IS_OBJECT(parent));
g_return_if_fail(object != parent);
if (object->parent != NULL) {
ERROR_OBJECT(object,object->parent,"object's parent is already set, must unparent first");
return;
}
gst_object_ref(object);
gst_object_sink(object);
object->parent = parent;
@ -245,3 +251,76 @@ void gst_object_sink(GstObject *object) {
}
#endif /* gst_object_sink */
gchar *gst_object_get_path_string(GstObject *object) {
GSList *parentage = NULL;
GSList *parents;
void *parent;
gchar *prevpath, *path = "";
const char *component;
gchar *separator = "";
gboolean free_component;
parentage = g_slist_prepend (NULL, object);
// first walk the object hierarchy to build a list of the parents
do {
if (GST_IS_OBJECT(object)) {
if (GST_IS_PAD(object)) {
parent = GST_PAD(object)->parent;
// } else if (GST_IS_ELEMENT(object)) {
// parent = gst_element_get_parent(GST_ELEMENT(object));
} else {
parent = gst_object_get_parent (object);
}
} else {
parentage = g_slist_prepend (parentage, NULL);
parent = NULL;
}
if (parent != NULL) {
parentage = g_slist_prepend (parentage, parent);
}
object = parent;
} while (object != NULL);
// then walk the parent list and print them out
parents = parentage;
while (parents) {
if (GST_IS_OBJECT(parents->data)) {
if (GST_IS_PAD(parents->data)) {
component = gst_pad_get_name(GST_PAD(parents->data));
separator = ".";
free_component = FALSE;
} else if (GST_IS_ELEMENT(parents->data)) {
component = gst_element_get_name(GST_ELEMENT(parents->data));
separator = "/";
free_component = FALSE;
} else {
// component = g_strdup_printf("a %s",gtk_type_name(gtk_identifier_get_type(parents->data)));
component = g_strdup_printf("unknown%p",parents->data);
separator = "/";
free_component = TRUE;
}
} else {
component = g_strdup_printf("%p",parents->data);
separator = "/";
free_component = TRUE;
}
prevpath = path;
path = g_strjoin(separator,prevpath,component,NULL);
g_free(prevpath);
if (free_component)
g_free((gchar *)component);
parents = g_slist_next(parents);
}
g_slist_free(parentage);
return path;
}

View file

@ -35,6 +35,9 @@
#include <asm/atomic.h>
#endif
// FIXME
#include "gstlog.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
@ -110,6 +113,9 @@ void gst_object_unparent (GstObject *object);
/* destroying an object */
#define gst_object_destroy(object) gtk_object_destroy(GTK_OBJECT(object))
/* printing out the 'path' of the object */
gchar * gst_object_get_path_string (GstObject *object);
#ifdef __cplusplus
}

View file

@ -260,7 +260,8 @@ gst_plugin_load_absolute (gchar *name)
if (module != NULL) {
if (g_module_symbol(module,"plugin_init",(gpointer *)&initfunc)) {
if ((plugin = (initfunc)(module))) {
DEBUG("gstplugin: plugin %s loaded\n", plugin->name);
// DEBUG("gstplugin: plugin %s loaded\n", plugin->name);
INFO(0,"plugin %s loaded", plugin->name);
plugin->filename = g_strdup(name);
plugin->loaded = TRUE;
_gst_modules = g_list_prepend(_gst_modules,module);
@ -407,7 +408,8 @@ gst_plugin_load_elementfactory (gchar *name)
if (!strcmp(factory->name,name)) {
if (!plugin->loaded) {
gchar *filename = g_strdup (plugin->filename);
DEBUG("gstplugin: loading element factory %s from plugin %s\n", name, plugin->name);
// DEBUG("gstplugin: loading element factory %s from plugin %s\n", name, plugin->name);
INFO("loaded elementfactory %s from plugin %s",name,plugin->name);
gst_plugin_remove(plugin);
if (!gst_plugin_load_absolute(filename)) {
DEBUG("gstplugin: error loading element factory %s from plugin %s\n", name, plugin->name);
@ -449,7 +451,8 @@ gst_plugin_load_typefactory (gchar *mime)
if (!strcmp(factory->mime,mime)) {
if (!plugin->loaded) {
gchar *filename = g_strdup (plugin->filename);
DEBUG("gstplugin: loading type factory for \"%s\" from plugin %s\n", mime, plugin->name);
// DEBUG("gstplugin: loading type factory for \"%s\" from plugin %s\n", mime, plugin->name);
INFO(GST_INFO_PLUGIN_LOAD,"loading type factory for \"%s\" from plugin %s",mime,plugin->name);
gst_plugin_remove(plugin);
if (!gst_plugin_load_absolute(filename)) {
DEBUG("gstplugin: error loading type factory \"%s\" from plugin %s\n", mime, plugin->name);
@ -619,6 +622,7 @@ gst_plugin_load_thyself (xmlNodePtr parent)
kinderen = kinderen->next;
}
DEBUG("gstplugin: added %d registered factories and %d types\n", elementcount, typecount);
// DEBUG("gstplugin: added %d registered factories and %d types\n", elementcount, typecount);
INFO(GST_INFO_PLUGIN_LOAD,"added %d registered factories and %d types",elementcount,typecount);
}

View file

@ -396,6 +396,10 @@ void gst_bin_schedule_func(GstBin *bin) {
pads = g_list_next (pads);
DEBUG("have pad %s:%s\n",GST_DEBUG_PAD_NAME(pad));
g_assert(pad->peer != NULL);
g_assert(pad->peer->parent != NULL);
g_assert(GST_ELEMENT(pad->peer->parent)->manager != NULL);
DEBUG("peer pad %p\n", pad->peer);
// only bother with if the pad's peer's parent is this bin or it's DECOUPLED
// only add it if it's in the list of un-visited elements still