eina: improve logging and debugging infra for Eina_Cow.

This commit is contained in:
Cedric BAIL 2013-03-04 11:08:21 +09:00
parent ddfd471c71
commit 1c9470e071
1 changed files with 19 additions and 2 deletions

View File

@ -37,7 +37,7 @@
#define EINA_COW_MAGIC 0xDEADBEEF #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 #ifdef MOO
# define EINA_COW_PTR_MAGIC 0xBEEFE00 # define EINA_COW_PTR_MAGIC 0xBEEFE00
#endif #endif
@ -45,10 +45,19 @@
typedef struct _Eina_Cow_Ptr Eina_Cow_Ptr; typedef struct _Eina_Cow_Ptr Eina_Cow_Ptr;
typedef struct _Eina_Cow_GC Eina_Cow_GC; 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 struct _Eina_Cow_Ptr
{ {
#ifdef MOO #ifdef MOO
EINA_MAGIC; EINA_MAGIC;
# ifdef HAVE_BACKTRACE
Eina_Bt_Func writer_bt[EINA_DEBUG_BT_NUM];
int writer_bt_num;
# endif
#endif #endif
int refcount; int refcount;
@ -374,7 +383,7 @@ eina_cow_write(Eina_Cow *cow,
ref = EINA_COW_PTR_GET(*data); ref = EINA_COW_PTR_GET(*data);
#ifndef NVALGRIND #ifndef NVALGRIND
VALGRIND_MAKE_MEM_DEFINED(ref, sizeof (ref)); VALGRIND_MAKE_MEM_DEFINED(ref, sizeof (ref));
#endif #endif
if (ref->refcount == 1) if (ref->refcount == 1)
{ {
@ -383,6 +392,10 @@ eina_cow_write(Eina_Cow *cow,
if (ref->writing) if (ref->writing)
{ {
ERR("Request writing on an pointer that is already in a writing process %p\n", data); 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; return NULL;
} }
@ -414,6 +427,10 @@ eina_cow_write(Eina_Cow *cow,
end: end:
#ifndef NVALGRIND #ifndef NVALGRIND
VALGRIND_MAKE_MEM_DEFINED(ref, sizeof (ref)); 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 #endif
ref->writing = EINA_TRUE; ref->writing = EINA_TRUE;
#ifndef NVALGRIND #ifndef NVALGRIND