2 * Copyright (C) 2006-2009 Brian Aker
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
8 * Summary: Localized copy of WATCHPOINT debug symbols
12 #ifndef __LIBMEMCACHED_WATCHPOINT_H__
13 #define __LIBMEMCACHED_WATCHPOINT_H__
15 /* Some personal debugging functions */
18 #ifdef TARGET_OS_LINUX
19 static inline void __stack_dump(void)
25 size
= backtrace(array
, 10);
26 strings
= backtrace_symbols(array
, size
);
28 fprintf(stderr
, "Found %d stack frames.\n", size
);
30 for (int x
= 0; x
< size
; x
++)
31 fprintf(stderr
, "%s\n", strings
[x
]);
40 static inline void __stack_dump(void)
43 #endif // __stack_dump()
47 #define WATCHPOINT do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s)\n", __FILE__, __LINE__,__func__);fflush(stdout); } while (0)
48 #define WATCHPOINT_ERROR(A) do {fprintf(stderr, "\nWATCHPOINT %s:%d %s\n", __FILE__, __LINE__, memcached_strerror(NULL, A));fflush(stdout); } while (0)
49 #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)
50 #define WATCHPOINT_STRING(A) do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %s\n", __FILE__, __LINE__,__func__,A);fflush(stdout); } while (0)
51 #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)
52 #define WATCHPOINT_NUMBER(A) do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %zu\n", __FILE__, __LINE__,__func__,(size_t)(A));fflush(stdout); } while (0)
53 #define WATCHPOINT_ERRNO(A) do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %s\n", __FILE__, __LINE__,__func__, strerror(A));fflush(stdout); } while (0)
54 #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)
55 #define WATCHPOINT_ASSERT(A) do { if (! (A)) {__stack_dump();} assert((A)); } while (0)
56 #define WATCHPOINT_ASSERT_INITIALIZED(A) do { if (! (A)) { __stack_dump(); } assert(memcached_is_initialized((A))); } while (0);
57 #define WATCHPOINT_SET(A) do { A; } while(0);
62 #define WATCHPOINT_ERROR(A)
63 #define WATCHPOINT_IFERROR(A)
64 #define WATCHPOINT_STRING(A)
65 #define WATCHPOINT_NUMBER(A)
66 #define WATCHPOINT_ERRNO(A)
67 #define WATCHPOINT_ASSERT_PRINT(A,B,C)
68 #define WATCHPOINT_ASSERT(A)
69 #define WATCHPOINT_ASSERT_INITIALIZED(A)
70 #define WATCHPOINT_SET(A)
74 #endif /* __LIBMEMCACHED_WATCHPOINT_H__ */