[gq-commit] gq/src debug.c,1.8,1.9 debug.h,1.6,1.7 errorchain.c,1.16,1.17
Status: Beta
Brought to you by:
sur5r
From: <sta...@us...> - 2003-10-17 06:31:21
|
Update of /cvsroot/gqclient/gq/src In directory sc8-pr-cvs1:/tmp/cvs-serv27821 Modified Files: debug.c debug.h errorchain.c Log Message: * Added a new debug flag GQ_DEBUG_ERROR_TRACE (64) to be used together with GQ_DEBUG_ERROR_LINE (1) to include a stack trace with error messages. Convenient to to used for debugging using the -d commandline switch Index: debug.c =================================================================== RCS file: /cvsroot/gqclient/gq/src/debug.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** debug.c 13 Oct 2003 07:30:19 -0000 1.8 --- debug.c 17 Oct 2003 06:31:16 -0000 1.9 *************** *** 1,5 **** /* GQ -- a GTK-based LDAP client ! Copyright (C) 1998-2001 Bert Vermeulen This program is released under the Gnu General Public License with --- 1,6 ---- /* GQ -- a GTK-based LDAP client ! Copyright (C) 1998-2003 Bert Vermeulen ! Copyright (C) 2002-2003 Peter Stamfest This program is released under the Gnu General Public License with *************** *** 26,29 **** --- 27,32 ---- #include <stdio.h> + #include "config.h" + #ifdef HAVE_BACKTRACE # include <execinfo.h> *************** *** 167,175 **** #endif /* HAVE_MALLINFO */ /* taken from the documentation of the GNU libc */ void print_trace(void) { - #ifdef HAVE_BACKTRACE void *array[200]; size_t size; --- 170,198 ---- #endif /* HAVE_MALLINFO */ + #ifdef HAVE_BACKTRACE + + /* taken from the documentation of the GNU libc */ + void sprint_trace(GString *str) + { + void *array[200]; + size_t size; + char **strings; + size_t i; + + size = backtrace(array, (sizeof(array) / sizeof(array[0])) ); + strings = backtrace_symbols(array, size); + + if (strings) { + for (i = 0; i < size; i++) { + g_string_append(str, strings[i]); + g_string_append(str, "\n"); + } + free(strings); + } + } /* taken from the documentation of the GNU libc */ void print_trace(void) { void *array[200]; size_t size; *************** *** 188,199 **** free(strings); } - #endif /* BACKTRACE */ } ! #else void print_trace(void) { } #endif /* DEBUG */ --- 211,226 ---- free(strings); } } + #else /* BACKTRACE */ ! void sprint_trace(GString *str) ! { ! } void print_trace(void) { } + + #endif /* BACKTRACE */ #endif /* DEBUG */ Index: debug.h =================================================================== RCS file: /cvsroot/gqclient/gq/src/debug.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** debug.h 13 Oct 2003 07:30:19 -0000 1.6 --- debug.h 17 Oct 2003 06:31:16 -0000 1.7 *************** *** 1,5 **** /* GQ -- a GTK-based LDAP client ! Copyright (C) 1998-2001 Bert Vermeulen This program is released under the Gnu General Public License with --- 1,6 ---- /* GQ -- a GTK-based LDAP client ! Copyright (C) 1998-2003 Bert Vermeulen ! Copyright (C) 2002-2003 Peter Stamfest This program is released under the Gnu General Public License with *************** *** 40,43 **** --- 41,45 ---- #define GQ_DEBUG_ENCODE 16 #define GQ_DEBUG_SIGNALS 32 + #define GQ_DEBUG_ERROR_TRACE 64 #endif *************** *** 71,74 **** --- 73,77 ---- void print_trace(void); + void sprint_trace(GString *s); #endif Index: errorchain.c =================================================================== RCS file: /cvsroot/gqclient/gq/src/errorchain.c,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** errorchain.c 9 Oct 2003 05:15:06 -0000 1.16 --- errorchain.c 17 Oct 2003 06:31:16 -0000 1.17 *************** *** 1,5 **** /* GQ -- a GTK-based LDAP client ! Copyright (C) 1998-2001 Bert Vermeulen This program is released under the Gnu General Public License with --- 1,6 ---- /* GQ -- a GTK-based LDAP client ! Copyright (C) 1998-2003 Bert Vermeulen ! Copyright (C) 2002-2003 Peter Stamfest This program is released under the Gnu General Public License with *************** *** 91,107 **** n = vsnprintf(str->str, a - 1, fmt, ap); ! #ifdef HAVE_C99_SNPRINTF if (n > a - 1) { g_string_free(str, TRUE); a = n + 2; str = g_string_sized_new(a); ! } ! #else ! if (n == -1) { g_string_free(str, TRUE); a *= 2; str = g_string_sized_new(a); } - #endif } while (n > (a - 1) || n == -1); --- 92,105 ---- n = vsnprintf(str->str, a - 1, fmt, ap); ! /* await both n==-1 and n > a -1 for not enough free space */ if (n > a - 1) { g_string_free(str, TRUE); a = n + 2; str = g_string_sized_new(a); ! } else if (n == -1) { g_string_free(str, TRUE); a *= 2; str = g_string_sized_new(a); } } while (n > (a - 1) || n == -1); *************** *** 129,140 **** if (debug & GQ_DEBUG_ERROR_LINE) { ! /* Is it allowed to change the fmt? */ ! int len = strlen(fmt) + strlen(file) + 100; ! char *s = g_malloc(len); ! snprintf(s, len, "%s:%d %s", file, line, fmt); ! error_push_production_v(context, s, ap); ! g_free(s); } else { error_push_production_v(context, fmt, ap); --- 127,141 ---- if (debug & GQ_DEBUG_ERROR_LINE) { + GString *s = g_string_sized_new(200); + g_string_sprintf(s, "%s:%d %s", file, line, fmt); ! if (debug & GQ_DEBUG_ERROR_TRACE) { ! g_string_append(s, "\n*** TRACE ***:\n"); ! sprint_trace(s); ! } ! /* Is it allowed to change the fmt? */ ! error_push_production_v(context, s->str, ap); ! g_string_free(s, TRUE); } else { error_push_production_v(context, fmt, ap); |