Revision: 14762
Author: adrian.chadd
Date: Tue Aug 24 01:38:54 2010
Log: CBDATA debugging fixes

* Fix the hashed cbdata code to compile once again
* Fix the debug cbdata stuff to compile once again
* Implement --enable-cbdata-debug which enables both hashed cbdata and
  cbdata debugging.


http://code.google.com/p/lusca-cache/source/detail?r=14762

Modified:
 /branches/LUSCA_HEAD/configure.in
 /branches/LUSCA_HEAD/libcb/cbdata.c
 /branches/LUSCA_HEAD/libcb/cbdata.h
 /branches/LUSCA_HEAD/src/cbdata.c

=======================================
--- /branches/LUSCA_HEAD/configure.in   Sun May 23 00:33:46 2010
+++ /branches/LUSCA_HEAD/configure.in   Tue Aug 24 01:38:54 2010
@@ -294,6 +294,26 @@
   fi
 ])

+AC_ARG_ENABLE(cbdata-debug,
+[ --enable-cbdata-debug Enable cbdata debugging (note slows proxy performance],
+[ case $enableval in
+  yes)
+       cbdata_debug=1
+       ;;
+  no)
+       cbdata_debug=
+       ;;
+  *)
+       cbdata_debug=
+       ;;
+  esac
+  if test $cbdata_debug; then
+       AC_DEFINE(CBDATA_DEBUG, 1, [callback data debugging support])
+ AC_DEFINE(HASHED_CBDATA, 1, [use hashed cbdata support (required for debugging)])
+       echo "Valgrind debug support enabled"
+  fi
+])
+
 AC_ARG_ENABLE(mempool-debug,
 [  --enable-mempool-debug  Include MemPool debug verifications])
 if test "$enable_mempool_debug" = yes; then
=======================================
--- /branches/LUSCA_HEAD/libcb/cbdata.c Mon Apr 19 05:44:32 2010
+++ /branches/LUSCA_HEAD/libcb/cbdata.c Tue Aug 24 01:38:54 2010
@@ -97,38 +97,14 @@

 int cbdataCount = 0;

-typedef struct _cbdata {
-#if HASHED_CBDATA
-    hash_link hash;
-#endif
-    int valid;
-    int locks;
-    int type;
-#if CBDATA_DEBUG
-    const char *file;
-    int line;
-#endif
-    void *y;                   /* cookie used while debugging */
-#if !HASHED_CBDATA
-    union {
-       void *pointer;
-       double double_float;
-       int integer;
-    } data;
-#endif
-} cbdata;
-
 #if HASHED_CBDATA
 static MemPool *cbdata_pool = NULL;
-static hash_table *cbdata_htable = NULL;
+hash_table *cbdata_htable = NULL;
 static HASHCMP cbdata_cmp;
 static HASHHASH cbdata_hash;
 #endif

-struct {
-    MemPool *pool;
-    FREE *free_func;
-}     *cbdata_index = NULL;
+struct cbdata_index_struct *cbdata_index = NULL;
 int cbdata_types = 0;

 #if HASHED_CBDATA
=======================================
--- /branches/LUSCA_HEAD/libcb/cbdata.h Sat Mar 28 14:39:53 2009
+++ /branches/LUSCA_HEAD/libcb/cbdata.h Tue Aug 24 01:38:54 2010
@@ -1,17 +1,9 @@
 #ifndef        __LIBCB_CBDATA_H__
 #define        __LIBCB_CBDATA_H__

-#define CREATE_CBDATA(type) cbdataInitType(CBDATA_##type, #type, sizeof(type), NULL) -#define CREATE_CBDATA_FREE(type, free_func) cbdataInitType(CBDATA_##type, #type, sizeof(type), free_func)
-#define CBDATA_COOKIE(p) ((void *)((unsigned long)(p) ^ 0xDEADBEEF))
-
-/* cbdata macros */
-#define cbdataAlloc(type) ((type *)cbdataInternalAlloc(CBDATA_##type))
-#define cbdataFree(var) (var = (var != NULL ? cbdataInternalFree(var): NULL))
-#define CBDATA_TYPE(type)       static cbdata_type CBDATA_##type = 0
-#define CBDATA_GLOBAL_TYPE(type)        cbdata_type CBDATA_##type
-#define CBDATA_INIT_TYPE(type) (CBDATA_##type ? 0 : (CBDATA_##type = cbdataAddType(CBDATA_##type, #type, sizeof(type), NULL))) -#define CBDATA_INIT_TYPE_FREECB(type, free_func) (CBDATA_##type ? 0 : (CBDATA_##type = cbdataAddType(CBDATA_##type, #type, sizeof(type), free_func)))
+#if CBDATA_DEBUG
+#include "../include/hash.h"
+#endif

 /*
  * cbdata types. similar to the MEM_* types above, but managed
@@ -26,15 +18,61 @@
     CBDATA_FIRST_CUSTOM_TYPE = 1000
 } cbdata_type;

+struct cbdata_index_struct {
+    MemPool *pool;
+    FREE *free_func;
+};
+
+typedef struct _cbdata {
+#if HASHED_CBDATA
+    hash_link hash;
+#endif
+    int valid;
+    int locks;
+    int type;
+#if CBDATA_DEBUG
+    const char *file;
+    int line;
+#endif
+    void *y;                    /* cookie used while debugging */
+#if !HASHED_CBDATA
+    union {
+        void *pointer;
+        double double_float;
+        int integer;
+    } data;
+#endif
+} cbdata;
+
+#define CREATE_CBDATA(type) cbdataInitType(CBDATA_##type, #type, sizeof(type), NULL) +#define CREATE_CBDATA_FREE(type, free_func) cbdataInitType(CBDATA_##type, #type, sizeof(type), free_func)
+#define CBDATA_COOKIE(p) ((void *)((unsigned long)(p) ^ 0xDEADBEEF))
+
+#if CBDATA_DEBUG
+#define cbdataAlloc(type) cbdataInternalAllocDbg(CBDATA_##type,__FILE__,__LINE__)
+#define cbdataLock(a)           cbdataLockDbg(a,__FILE__,__LINE__)
+#define cbdataUnlock(a)         cbdataUnlockDbg(a,__FILE__,__LINE__)
+#else
+#define cbdataAlloc(type) ((type *)cbdataInternalAlloc(CBDATA_##type))
+extern void cbdataLock(const void *p);
+extern void cbdataUnlock(const void *p);
+#endif
+
+#define cbdataFree(var) (var = (var != NULL ? cbdataInternalFree(var): NULL))
+#define CBDATA_TYPE(type)       static cbdata_type CBDATA_##type = 0
+#define CBDATA_GLOBAL_TYPE(type)        cbdata_type CBDATA_##type
+#define CBDATA_INIT_TYPE(type) (CBDATA_##type ? 0 : (CBDATA_##type = cbdataAddType(CBDATA_##type, #type, sizeof(type), NULL))) +#define CBDATA_INIT_TYPE_FREECB(type, free_func) (CBDATA_##type ? 0 : (CBDATA_##type = cbdataAddType(CBDATA_##type, #type, sizeof(type), free_func)))
+
+extern struct cbdata_index_struct *cbdata_index;
+
 extern void cbdataInit(void);
 #if CBDATA_DEBUG
-extern void *cbdataInternalAllocDbg(cbdata_type type, int, const char *);
+extern void *cbdataInternalAllocDbg(cbdata_type type, const char *, int);
 extern void cbdataLockDbg(const void *p, const char *, int);
 extern void cbdataUnlockDbg(const void *p, const char *, int);
 #else
 extern void *cbdataInternalAlloc(cbdata_type type);
-extern void cbdataLock(const void *p);
-extern void cbdataUnlock(const void *p);
 #endif
 /* Note: Allocations is done using the cbdataAlloc macro */
 extern void *cbdataInternalFree(void *p);
@@ -45,11 +83,8 @@
 extern int cbdataInUseCount(cbdata_type type);

 extern int cbdataCount;
-
-#if CBDATA_DEBUG
-#define cbdataAlloc(a,b)        cbdataAllocDbg(a,b,__FILE__,__LINE__)
-#define cbdataLock(a)           cbdataLockDbg(a,__FILE__,__LINE__)
-#define cbdataUnlock(a)         cbdataUnlockDbg(a,__FILE__,__LINE__)
+#if HASHED_CBDATA
+extern hash_table *cbdata_htable;
 #endif

 /* Generic cbdata stuff */
=======================================
--- /branches/LUSCA_HEAD/src/cbdata.c   Tue May 27 05:49:29 2008
+++ /branches/LUSCA_HEAD/src/cbdata.c   Tue Aug 24 01:38:54 2010
@@ -66,7 +66,6 @@

 #include "squid.h"

-
 static OBJH cbdataDump;

 void
@@ -78,9 +77,30 @@
        cbdataDump, 0, 1);
 }

+#if HASHED_CBDATA
 static void
 cbdataDump(StoreEntry * sentry)
 {
+    cbdata *n;
+
+    hash_first(cbdata_htable);
+    while ((n = (cbdata *) hash_next(cbdata_htable))) {
+#if CBDATA_DEBUG
+ storeAppendPrintf(sentry, "cbdata=%p key=%p type=%s locks=%d valid=%d %s:%d\n", + n, n->hash.key, cbdata_index[n->type].pool->label, n->locks, n->valid, n->file, n->line);
+#else
+ storeAppendPrintf(sentry, "cbdata=%p key=%p type=%d locks=%d valid=%d\n",
+         n, n->hash.key, cbdata_index[n->type].pool->label, n->locks, 
n->valid);
+#endif
+    }
+
+    storeAppendPrintf(sentry, "%d cbdata entries\n", cbdataCount);
+}
+#else
+static void
+cbdataDump(StoreEntry * sentry)
+{
     storeAppendPrintf(sentry, "%d cbdata entries\n", cbdataCount);
     storeAppendPrintf(sentry, "see also memory pools section\n");
 }
+#endif

--
You received this message because you are subscribed to the Google Groups 
"lusca-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/lusca-commit?hl=en.

Reply via email to