From cvs-return-1549-apmail-apr-cvs-archive=apr.apache.org@apr.apache.org Mon Jul 02 16:22:06 2001 Return-Path: Delivered-To: apmail-apr-cvs-archive@apr.apache.org Received: (qmail 54059 invoked by uid 500); 2 Jul 2001 16:21:56 -0000 Mailing-List: contact cvs-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Reply-To: dev@apr.apache.org Delivered-To: mailing list cvs@apr.apache.org Received: (qmail 53955 invoked by uid 1103); 2 Jul 2001 16:21:50 -0000 Date: 2 Jul 2001 16:21:50 -0000 Message-ID: <20010702162150.53949.qmail@apache.org> From: dreid@apache.org To: apr-cvs@apache.org Subject: cvs commit: apr/memory/unix apr_sms.c dreid 01/07/02 09:21:49 Modified: include apr_sms.h memory/unix apr_sms.c Log: Add the ability to print the debugging output into a file instead of stdout. Change the way we "switch" on/off the debgugging to make it easier to use. Add support for showing the tag if we have one available. Still need to add a sensible default tag. Ben L suggested (at 5:45am this morning so I hope I remember this correctly) that we use the file and line number. Revision Changes Path 1.25 +12 -4 apr/include/apr_sms.h Index: apr_sms.h =================================================================== RCS file: /home/cvs/apr/include/apr_sms.h,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- apr_sms.h 2001/07/02 09:03:43 1.24 +++ apr_sms.h 2001/07/02 16:21:44 1.25 @@ -104,14 +104,22 @@ * Function definitions are at the end of the file... */ +/* APR_DEBUG_TO_FILE + * This will put all debug output into a file, that you can name + * using the APR_DEBUG_FILE define. Normally this is set to setdout + * and the output is simply printed there. + */ +#define APR_DEBUG_TO_FILE 0 +#define APR_DEBUG_FILE "/tmp/sms_debug" + /* APR_DEBUG_SHOW_STRUCTURE * This turns on a print of the ancestory of the SMS when * creating/destroying an SMS so it's place in the world can be seen. */ -/* #define APR_DEBUG_SHOW_STRUCTURE 1 */ +#define APR_DEBUG_SHOW_STRUCTURE 0 /* APR_DEBUG_SHOW_FUNCTIONS - * This turns on debug printing of every call to i + * This turns on debug printing of every call to * apr_sms_create * apr_sms_destroy * apr_sms_reset @@ -119,13 +127,13 @@ * Format of output is * CREATE - sms 0x0000000 [STANDARD] has been created */ -/* #define APR_DEBUG_SHOW_FUNCTIONS 1 */ +#define APR_DEBUG_SHOW_FUNCTIONS 0 /* APR_DEBUG_TAG_SMS * Turn on the ability to give an SMS a "tag" that can be used to identify * it. */ -/* #define APR_DEBUG_TAG_SMS 1 */ +#define APR_DEBUG_TAG_SMS 0 /** * @package APR memory system 1.33 +74 -47 apr/memory/unix/apr_sms.c Index: apr_sms.c =================================================================== RCS file: /home/cvs/apr/memory/unix/apr_sms.c,v retrieving revision 1.32 retrieving revision 1.33 diff -u -r1.32 -r1.33 --- apr_sms.c 2001/07/02 09:01:37 1.32 +++ apr_sms.c 2001/07/02 16:21:48 1.33 @@ -69,14 +69,14 @@ #ifdef APR_ASSERT_MEMORY #include #endif -#if defined(APR_DEBUG_SHOW_STRUCTURE) #include -#endif #include /* strikerXXX: had to add this for windows to stop * complaining, please autoconf the include stuff */ +FILE *dbg_file; + /* * private structure defenitions */ @@ -175,6 +175,13 @@ APR_DECLARE(apr_status_t) apr_sms_init(apr_sms_t *sms, apr_sms_t *pms) { +#if APR_DEBUG_TO_FILE + if (!dbg_file) + dbg_file = fopen(APR_DEBUG_FILE, "w"); +#else + dbg_file = stdout; +#endif + /* XXX - I've assumed that memory passed in will be zeroed, * i.e. calloc'd instead of malloc'd... * This may well be a bogus assumption, and if so we either need @@ -248,12 +255,14 @@ /* Create the sms framework lock we'll use. */ rv = apr_lock_create(&sms->sms_lock, APR_MUTEX, APR_LOCKALL, NULL, sms->pool); -#if DEBUG_SHOW_FUNCTIONS - printf("CREATE - sms %p [%s] has been created\n", sms, sms->identity); + +#if APR_DEBUG_SHOW_FUNCTIONS + fprintf(dbg_file, "CREATE - sms %p [%s] has been created\n", + sms, sms->identity); #endif -#if DEBUG_SHOW_STRUCTURE +#if APR_DEBUG_SHOW_STRUCTURE apr_sms_show_structure(sms, 1); -#endif /* DEBUG_SHOW_STRUCTURE */ +#endif /* APR_DEBUG_SHOW_STRUCTURE */ return rv; } @@ -369,8 +378,13 @@ if (!sms->reset_fn) return APR_ENOTIMPL; -#if DEBUG_SHOW_FUNCTIONS - printf("RESET - sms %p [%s] being reset\n", sms, sms->identity); +#if APR_DEBUG_SHOW_FUNCTIONS +# if APR_DEBUG_TAG_SMS + fprintf(dbg_file, "RESET - sms %p '%s' [%s] being reset\n", sms, + sms->tag, sms->identity); +# else + fprintf(dbg_file, "RESET - sms %p [%s] being reset\n", sms, sms->identity); +# endif #endif if (sms->sms_lock) @@ -414,13 +428,14 @@ struct apr_sms_cleanup *cleanup; struct apr_sms_cleanup *next_cleanup; -#if DEBUG_SHOW_FUNCTIONS - printf("DESTROY - sms %p [%s] being destroyed\n", sms, sms->identity); -#endif -#if DEBUG_SHOW_STRUCTURE - printf("WARNING! Destroying this SMS will also destroy:\n"); +#if APR_DEBUG_SHOW_FUNCTIONS + fprintf(dbg_file, "DESTROY - sms %p [%s] being destroyed\n", + sms, sms->identity); +#endif /* APR_DEBUG_SHOW_FUNCTIONS */ +#if APR_DEBUG_SHOW_STRUCTURE + fprintf(dbg_file, "The following SMS will be destroyed by this action:\n"); apr_sms_show_structure(sms, 0); -#endif /* DEBUG_SHOW_STRUCTURE */ +#endif /* APR_DEBUG_SHOW_STRUCTURE */ if (sms->sms_lock) apr_lock_acquire(sms->sms_lock); @@ -775,21 +790,28 @@ } #if APR_DEBUG_SHOW_STRUCTURE -static void add_sms(char *a, char *b, apr_sms_t *sms, apr_sms_t *caller, - int sib) +static void add_sms(char *a, char *b, char *c, apr_sms_t *sms, + apr_sms_t *caller, int sib) { - char tmp[20]; + char tmp[40]; if (sib == 1) { strcat(a, "="); strcat(b, " "); + strcat(c, " "); } sprintf(tmp, sms == caller ? "**%9p**" : " [%9p] ", sms); strcat(a, tmp); - sprintf(tmp, sms == caller ? " [%9s] " : " [%9s] ", sms->identity); +#if APR_DEBUG_TAG_SMS + sprintf(tmp, " '%9s' ", sms->tag); +#else + sprintf(tmp, " "); +#endif strcat(b, tmp); + sprintf(tmp, " [%9s] ", sms->identity); + strcat(c, tmp); } -static void add_tab(char *a, char *b, int level, apr_sms_t *sms) +static void add_tab(char *a, char *b, char *c, int level, apr_sms_t *sms) { char buffer[100]; int i; @@ -798,21 +820,30 @@ buffer[i] = '\0'; strcpy(a, buffer); strcpy(b, buffer); + strcpy(c, buffer); if (sms->parent) - printf("%s |\n", buffer); + fprintf(dbg_file, "%s |\n", buffer); + fflush(dbg_file); } -static void print_structure(char *l1, char *l2) +static void print_structure(char *l1, char *l2, char *l3) { - printf("%s\n%s\n", l1, l2); + fprintf(dbg_file, "%s\n%s\n%s\n", l1, l2, l3); + fflush(dbg_file); } +static void print_depth(int levels) +{ + fprintf(dbg_file, "Showing %d level%s of SMS\n", levels + 1, + levels == 0 ? "" : "s"); +} + APR_DECLARE(void) apr_sms_show_structure(apr_sms_t *sms, int direction) { apr_sms_t *thesms, *sibling; int levels = 0, i = 0; - char l1[100], l2[100]; - + char l1[256], l2[256], l3[256]; + if (direction == 1) { /* we're going up! */ thesms = sms; @@ -820,23 +851,19 @@ levels++; thesms = thesms->parent; } - if (levels == 0) { - printf("The SMS is a top-level SMS.\n"); - } else { - printf("The SMS is %d level(s) deep!\n", levels); - } + print_depth(levels); /* thesms now eqauls the top level... so start showing them! */ while (thesms) { - add_tab(l1, l2, i++, thesms); + add_tab(l1, l2, l3, i++, thesms); - add_sms(l1, l2, thesms, sms, 0); + add_sms(l1, l2, l3, thesms, sms, 0); sibling = thesms->sibling; while (sibling) { - add_sms(l1, l2, sibling, NULL, 1); + add_sms(l1, l2, l3, sibling, NULL, 1); sibling = sibling->sibling; } - print_structure(l1, l2); + print_structure(l1, l2, l3); thesms = thesms->child; } @@ -846,26 +873,26 @@ while (thesms->child) { levels++; thesms = thesms->child; - } - if (levels == 0) { - printf("The SMS is a bottom-level SMS with no descendants\n"); - } else { - printf("This SMS has %d descendants\n", levels); } + print_depth(levels); thesms = sms; while (thesms) { - add_tab(l1, l2, i++, thesms); + add_tab(l1, l2, l3, i++, thesms); /* add the child... */ - add_sms(l1, l2, thesms, sms, 0); - - /* add siblings... */ - sibling = thesms->sibling; - while (sibling != NULL) { - add_sms(l1, l2, sibling, sms, 1); - sibling = sibling->sibling; + add_sms(l1, l2, l3, thesms, sms, 0); + /* If we're destroying a sibling, then we won't be destroying + * the other siblings, just descendants of this SMS, so + * make sure what we show makes sense! + */ + if (thesms != sms && thesms->sibling) { + sibling = thesms->sibling; + while (sibling) { + add_sms(l1, l2, l3, sibling, NULL, 1); + sibling = sibling->sibling; + } } - print_structure(l1, l2); + print_structure(l1, l2, l3); thesms = thesms->child; } }