apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dr...@apache.org
Subject cvs commit: apr/memory/unix apr_sms.c
Date Mon, 02 Jul 2001 08:01:06 GMT
dreid       01/07/02 01:01:06

  Modified:    include  apr_sms.h
               memory/unix apr_sms.c
  Log:
  Add some debugging to sms...
  
  - add an option to print out when we create/reset/destroy an sms
  - add an option to allow us to print out a tree of the sms's showing
    the inter-relationships
  
  Revision  Changes    Path
  1.20      +59 -7     apr/include/apr_sms.h
  
  Index: apr_sms.h
  ===================================================================
  RCS file: /home/cvs/apr/include/apr_sms.h,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- apr_sms.h	2001/06/30 08:21:50	1.19
  +++ apr_sms.h	2001/07/02 08:01:03	1.20
  @@ -72,21 +72,51 @@
   extern "C" {
   #endif
   
  +
  +/**********************************************************************
  + ** Defines 
  + **********************************************************************/
  +
   /* The various types of cleanup's we can offer */
   #define APR_ALL_CLEANUPS      0x0000
   #define APR_CHILD_CLEANUP     0x0001
   #define APR_PARENT_CLEANUP    0x0002
   
  -/* Alignment macro's
  - *
  - * APR_ALIGN is only to be used to align on a power
  - * of two boundary
  - */
  +/* Alignment macro's */
   #define APR_ALIGN(size, boundary) \
  -    (((size) + ((boundary) - 1)) & ~((boundary) - 1))
  +    ((size) + (((boundary) - ((size) & ((boundary) - 1))) & ((boundary) - 1)))
   
   #define APR_ALIGN_DEFAULT(size) APR_ALIGN(size, 8)
   
  +/**********************************************************************
  + ** Debug options
  + **********************************************************************/
  +/* 
  + * One of the aims of SMS is to provide a large range of debugging
  + * options.
  + *
  + * The options are normally turned off by having the define commented out.
  + * To use, simply remove the define and rebuild!
  + *
  + * Function definitions are at the end of the file...
  + */
  +
  +/* 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 DEBUG_SHOW_STRUCTURE      1 */
  +
  +/* DEBUG_SHOW_FUNCTIONS
  + * This turns on debug printing of every call to i
  + *    apr_sms_create
  + *    apr_sms_destroy
  + *    apr_sms_reset
  + *
  + * Format of output is
  + *    CREATE - sms 0x0000000 [STANDARD] has been created
  + */
  +/* #define DEBUG_SHOW_FUNCTIONS     1 */
   
   /**
    * @package APR memory system
  @@ -195,13 +225,14 @@
    */
   APR_DECLARE(apr_status_t) apr_sms_post_init(apr_sms_t *sms);
   
  +#ifdef APR_ASSERT_MEMORY
  +
   /**
    * Check if a memory system is obeying all rules. 
    * @caution Call this function as the last statement before returning a new
    *          memory system from your apr_xxx_sms_create.
    * @deffunc void apr_sms_validate(apr_sms_t *sms)
    */
  -#ifdef APR_ASSERT_MEMORY
   APR_DECLARE(void) apr_sms_assert(apr_sms_t *sms);
   #else
   #ifdef apr_sms_assert
  @@ -336,12 +367,33 @@
   APR_DECLARE(apr_status_t) apr_sms_cleanup_run_type(apr_sms_t *sms, 
                                                      apr_int32_t type);
   
  +/**********************************************************************
  + ** Standard SMS module
  + **********************************************************************/
  +
   /**
    * Create a standard malloc/realloc/free memory system
    * @param sms A pointer to the created apr_sms_t*
    * @deffunc apr_status_t apr_sms_std_create(apr_sms_t **sms);
    */
   APR_DECLARE(apr_status_t) apr_sms_std_create(apr_sms_t **sms);
  +
  +
  +/**********************************************************************
  + ** Debug routines
  + **********************************************************************/
  +
  +/* NB These are only available if the debugging option has been turned on. */
  +
  +#if DEBUG_SHOW_STRUCTURE
  +/**
  + * Show the heirachy of the sms
  + * @param sms The sms to show the information for
  + * @param direction Do we show up (to parent) or down (to children)
  + */
  +APR_DECLARE(void) apr_sms_show_structure(apr_sms_t *sms, int direction);
  +#endif /* DEBUG_SHOW_STRUCTURE */
  +
   
   #ifdef __cplusplus
   }
  
  
  
  1.29      +126 -4    apr/memory/unix/apr_sms.c
  
  Index: apr_sms.c
  ===================================================================
  RCS file: /home/cvs/apr/memory/unix/apr_sms.c,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- apr_sms.c	2001/07/01 13:56:29	1.28
  +++ apr_sms.c	2001/07/02 08:01:04	1.29
  @@ -232,19 +232,29 @@
   
   APR_DECLARE(apr_status_t) apr_sms_post_init(apr_sms_t *sms)
   {
  -    apr_sms_assert(sms);
  -    
       /* We do things here as these may potentially make calls
        * to the sms that we're creating, and if we make the calls
        * in the sms_init phase we haven't yet added the function
        * pointers so we'll segfault!
        */
  +    apr_status_t rv;
  +
  +    apr_sms_assert(sms);
   
       /* Create the sms framework lock we'll use. */
  -    return apr_lock_create(&sms->sms_lock, APR_MUTEX, APR_LOCKALL,
  -                           NULL, sms->pool);
  +    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);
  +#endif
  +#if DEBUG_SHOW_STRUCTURE
  +    apr_sms_show_structure(sms, 1);
  +#endif /* DEBUG_SHOW_STRUCTURE */
  +
  +    return rv;
   }
   
  +
   #ifdef APR_ASSERT_MEMORY
   APR_DECLARE(void) apr_sms_assert(apr_sms_t *sms)
   {
  @@ -355,6 +365,10 @@
       if (!sms->reset_fn)
           return APR_ENOTIMPL;
   
  +#if DEBUG_SHOW_FUNCTIONS
  +    printf("RESET - sms %p [%s] being reset\n", sms, sms->identity);
  +#endif
  +
       if (sms->sms_lock)
           apr_lock_acquire(sms->sms_lock);
       
  @@ -396,6 +410,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");
  +    apr_sms_show_structure(sms, 0);
  +#endif /* DEBUG_SHOW_STRUCTURE */
  +
       if (sms->sms_lock)
           apr_lock_acquire(sms->sms_lock);
       
  @@ -747,3 +769,103 @@
   {
       return sms->parent;
   }
  +
  +#if DEBUG_SHOW_STRUCTURE
  +static void add_sms(char *a, char *b, apr_sms_t *sms, apr_sms_t *caller,
  +                    int sib)
  +{
  +    char tmp[20];
  +    if (sib == 1) {
  +        strcat(a, "=");
  +        strcat(b, " ");
  +    }
  +    sprintf(tmp, sms == caller ? "**%9p**" : " [%9p] ", sms);
  +    strcat(a, tmp);
  +    sprintf(tmp, sms == caller ? " [%9s] " : " [%9s] ", sms->identity);
  +    strcat(b, tmp);
  +}
  +
  +static void add_tab(char *a, char *b, int level, apr_sms_t *sms) 
  +{
  +    char buffer[100];
  +    int i;
  +    for(i=0;i < level * 2;i++) 
  +        buffer[i] = ' ';
  +    buffer[i] = '\0';
  +    strcpy(a, buffer);
  +    strcpy(b, buffer);
  +    if (sms->parent)
  +        printf("%s     |\n", buffer);
  +}
  +
  +static void print_structure(char *l1, char *l2)
  +{
  +    printf("%s\n%s\n", l1, l2);
  +}
  +
  +APR_DECLARE(void) apr_sms_show_structure(apr_sms_t *sms, int direction)
  +{
  +    apr_sms_t *thesms, *sibling;
  +    int levels = 0, i = 0, j = 0;
  +    char l1[100], l2[100];
  + 
  +    if (direction == 1) {
  +        /* we're going up! */
  +        thesms = sms;
  +        while (thesms->parent != NULL) {
  +            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);
  +        }
  +        /* thesms now eqauls the top level... so start showing them! */
  +        while (thesms) {
  +            add_tab(l1, l2, i++, thesms);
  +
  +            add_sms(l1, l2, thesms, sms, 0);
  +            
  +            sibling = thesms->sibling;
  +            while (sibling) {
  +                add_sms(l1, l2, sibling, NULL, 1);
  +                sibling = sibling->sibling;
  +            }
  +            print_structure(l1, l2);
  +
  +            thesms = thesms->child;
  +        }
  +    } else {
  +        /* we go down!  i.e. show our descendants */
  +        thesms = sms;
  +        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);
  +        }
  +        thesms = sms;
  +        while (thesms) {
  +            add_tab(l1, l2, 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;
  +            }
  +            print_structure(l1, l2);
  +            thesms = thesms->child;
  +        }
  +    }
  +}
  +#endif /* DEBUG_SHOW_STRUCTURE */
  +
  +
  
  
  

Mime
View raw message