From 1c9470e0716b26059a5eb83b9f213beba11c6cc5 Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Mon, 4 Mar 2013 11:08:21 +0900 Subject: [PATCH] eina: improve logging and debugging infra for Eina_Cow. --- src/lib/eina/eina_cow.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/lib/eina/eina_cow.c b/src/lib/eina/eina_cow.c index a31c36c..51c01d3 100644 --- a/src/lib/eina/eina_cow.c +++ b/src/lib/eina/eina_cow.c @@ -37,7 +37,7 @@ #define EINA_COW_MAGIC 0xDEADBEEF -// #define MOO // Define that one if you want magic debug for Eina_Cow_Ptr +//#define MOO // Define that one if you want magic debug for Eina_Cow_Ptr #ifdef MOO # define EINA_COW_PTR_MAGIC 0xBEEFE00 #endif @@ -45,10 +45,19 @@ typedef struct _Eina_Cow_Ptr Eina_Cow_Ptr; typedef struct _Eina_Cow_GC Eina_Cow_GC; +#ifdef HAVE_BACKTRACE +#define EINA_DEBUG_BT_NUM 64 +typedef void (*Eina_Bt_Func) (); +#endif + struct _Eina_Cow_Ptr { #ifdef MOO EINA_MAGIC; +# ifdef HAVE_BACKTRACE + Eina_Bt_Func writer_bt[EINA_DEBUG_BT_NUM]; + int writer_bt_num; +# endif #endif int refcount; @@ -374,7 +383,7 @@ eina_cow_write(Eina_Cow *cow, ref = EINA_COW_PTR_GET(*data); #ifndef NVALGRIND - VALGRIND_MAKE_MEM_DEFINED(ref, sizeof (ref)); + VALGRIND_MAKE_MEM_DEFINED(ref, sizeof (ref)); #endif if (ref->refcount == 1) { @@ -383,6 +392,10 @@ eina_cow_write(Eina_Cow *cow, if (ref->writing) { ERR("Request writing on an pointer that is already in a writing process %p\n", data); +#if defined(MOO) && defined(HAVE_BACKTRACE) + backtrace_symbols_fd((void **) ref->writer_bt, + ref->writer_bt_num, 1); +#endif return NULL; } @@ -415,6 +428,10 @@ eina_cow_write(Eina_Cow *cow, #ifndef NVALGRIND VALGRIND_MAKE_MEM_DEFINED(ref, sizeof (ref)); #endif +#if defined(MOO) && defined(HAVE_BACKTRACE) + ref->writer_bt_num = backtrace((void **)(ref->writer_bt), + EINA_DEBUG_BT_NUM); +#endif ref->writing = EINA_TRUE; #ifndef NVALGRIND VALGRIND_MAKE_MEM_NOACCESS(ref, sizeof (ref)); -- 2.7.4