X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fwatchpoint.h;h=488238cb15b1680f130c1ceba136bbaebcba5d34;hb=0cc042d0d2b3e81eabc05600d1e4d26bf3d9691f;hp=d8c593ec595cce88e30bf1ff58aaf3d9bc9c1b4a;hpb=7c7750f02368b570353ea109f23a0ea26d226e02;p=m6w6%2Flibmemcached diff --git a/libmemcached/watchpoint.h b/libmemcached/watchpoint.h index d8c593ec..488238cb 100644 --- a/libmemcached/watchpoint.h +++ b/libmemcached/watchpoint.h @@ -1,5 +1,5 @@ /* LibMemcached - * Copyright (C) 2006-2009 Brian Aker + * Copyright (C) 2006-2009 Brian Aker * All rights reserved. * * Use and distribution licensed under the BSD license. See @@ -9,24 +9,52 @@ * */ -#ifndef LIBMEMCACHED_MEMCACHED_WATCHPOINT_H -#define LIBMEMCACHED_MEMCACHED_WATCHPOINT_H +#ifndef __LIBMEMCACHED_WATCHPOINT_H__ +#define __LIBMEMCACHED_WATCHPOINT_H__ /* Some personal debugging functions */ #if defined(DEBUG) +#ifdef TARGET_OS_LINUX +static inline void __stack_dump(void) +{ + void *array[10]; + int size; + char **strings; + + size= backtrace(array, 10); + strings= backtrace_symbols(array, size); + + fprintf(stderr, "Found %d stack frames.\n", size); + + for (int x= 0; x < size; x++) + fprintf(stderr, "%s\n", strings[x]); + + free (strings); + + fflush(stderr); +} + +#else + +static inline void __stack_dump(void) +{ } + +#endif // __stack_dump() + #include -#define WATCHPOINT fprintf(stderr, "\nWATCHPOINT %s:%d (%s)\n", __FILE__, __LINE__,__func__);fflush(stdout); -#define WATCHPOINT_ERROR(A) fprintf(stderr, "\nWATCHPOINT %s:%d %s\n", __FILE__, __LINE__, memcached_strerror(NULL, A));fflush(stdout); -#define WATCHPOINT_IFERROR(A) if(A != MEMCACHED_SUCCESS)fprintf(stderr, "\nWATCHPOINT %s:%d %s\n", __FILE__, __LINE__, memcached_strerror(NULL, A));fflush(stdout); -#define WATCHPOINT_STRING(A) fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %s\n", __FILE__, __LINE__,__func__,A);fflush(stdout); -#define WATCHPOINT_STRING_LENGTH(A,B) fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %.*s\n", __FILE__, __LINE__,__func__,(int)B,A);fflush(stdout); -#define WATCHPOINT_NUMBER(A) fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %zu\n", __FILE__, __LINE__,__func__,(size_t)(A));fflush(stdout); -#define WATCHPOINT_ERRNO(A) fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %s\n", __FILE__, __LINE__,__func__, strerror(A));fflush(stdout); -#define WATCHPOINT_ASSERT_PRINT(A,B,C) if(!(A)){fprintf(stderr, "\nWATCHPOINT ASSERT %s:%d (%s) ", __FILE__, __LINE__,__func__);fprintf(stderr, (B),(C));fprintf(stderr,"\n");fflush(stdout);}assert((A)); -#define WATCHPOINT_ASSERT(A) assert((A)); -#define WATCHPOINT_ASSERT_INITIALIZED(A) (memcached_is_initialized((A)); +#define WATCHPOINT do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s)\n", __FILE__, __LINE__,__func__);fflush(stdout); } while (0) +#define WATCHPOINT_ERROR(A) do {fprintf(stderr, "\nWATCHPOINT %s:%d %s\n", __FILE__, __LINE__, memcached_strerror(NULL, A));fflush(stdout); } while (0) +#define WATCHPOINT_IFERROR(A) do { if(A != MEMCACHED_SUCCESS)fprintf(stderr, "\nWATCHPOINT %s:%d %s\n", __FILE__, __LINE__, memcached_strerror(NULL, A));fflush(stdout); } while (0) +#define WATCHPOINT_STRING(A) do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %s\n", __FILE__, __LINE__,__func__,A);fflush(stdout); } while (0) +#define WATCHPOINT_STRING_LENGTH(A,B) do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %.*s\n", __FILE__, __LINE__,__func__,(int)B,A);fflush(stdout); } while (0) +#define WATCHPOINT_NUMBER(A) do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %zu\n", __FILE__, __LINE__,__func__,(size_t)(A));fflush(stdout); } while (0) +#define WATCHPOINT_ERRNO(A) do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %s\n", __FILE__, __LINE__,__func__, strerror(A));fflush(stdout); } while (0) +#define WATCHPOINT_ASSERT_PRINT(A,B,C) do { if(!(A)){fprintf(stderr, "\nWATCHPOINT ASSERT %s:%d (%s) ", __FILE__, __LINE__,__func__);fprintf(stderr, (B),(C));fprintf(stderr,"\n");fflush(stdout); __stack_dump(); } assert((A)); } while (0) +#define WATCHPOINT_ASSERT(A) do { if (! (A)) {__stack_dump();} assert((A)); } while (0) +#define WATCHPOINT_ASSERT_INITIALIZED(A) do { if (! (A)) { __stack_dump(); } assert(memcached_is_initialized((A))); } while (0); +#define WATCHPOINT_SET(A) do { A; } while(0); #else @@ -39,7 +67,8 @@ #define WATCHPOINT_ASSERT_PRINT(A,B,C) #define WATCHPOINT_ASSERT(A) #define WATCHPOINT_ASSERT_INITIALIZED(A) +#define WATCHPOINT_SET(A) #endif /* DEBUG */ -#endif /* LIBMEMCACHED_MEMCACHED_WATCHPOINT_H */ +#endif /* __LIBMEMCACHED_WATCHPOINT_H__ */