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 libmemcached_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
]);
41 static inline void libmemcached_stack_dump(void)
44 printstack(fileno(stderr
));
49 static inline void libmemcached_stack_dump(void)
52 #endif // libmemcached_stack_dump()
56 #define WATCHPOINT do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s)\n", __FILE__, __LINE__,__func__);fflush(stdout); } while (0)
57 #define WATCHPOINT_ERROR(A) do {fprintf(stderr, "\nWATCHPOINT %s:%d %s\n", __FILE__, __LINE__, memcached_strerror(NULL, A));fflush(stdout); } while (0)
58 #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)
59 #define WATCHPOINT_STRING(A) do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %s\n", __FILE__, __LINE__,__func__,A);fflush(stdout); } while (0)
60 #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)
61 #define WATCHPOINT_NUMBER(A) do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %lu\n", __FILE__, __LINE__,__func__,(unsigned long)(A));fflush(stdout); } while (0)
62 #define WATCHPOINT_LABELED_NUMBER(A,B) do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %s:%lu\n", __FILE__, __LINE__,__func__,(A),(unsigned long)(B));fflush(stdout); } while (0)
63 #define WATCHPOINT_IF_LABELED_NUMBER(A,B,C) do { if(A) {fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %s:%lu\n", __FILE__, __LINE__,__func__,(B),(unsigned long)(C));fflush(stdout);} } while (0)
64 #define WATCHPOINT_ERRNO(A) do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %s\n", __FILE__, __LINE__,__func__, strerror(A));fflush(stdout); } while (0)
65 #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); libmemcached_stack_dump(); } assert((A)); } while (0)
66 #define WATCHPOINT_ASSERT(A) do { if (! (A)) {libmemcached_stack_dump();} assert((A)); } while (0)
67 #define WATCHPOINT_ASSERT_INITIALIZED(A) do { if (! (A)) { libmemcached_stack_dump(); } assert(memcached_is_initialized((A))); } while (0);
68 #define WATCHPOINT_SET(A) do { A; } while(0);
73 #define WATCHPOINT_ERROR(A)
74 #define WATCHPOINT_IFERROR(A)
75 #define WATCHPOINT_STRING(A)
76 #define WATCHPOINT_NUMBER(A)
77 #define WATCHPOINT_LABELED_NUMBER(A,B)
78 #define WATCHPOINT_IF_LABELED_NUMBER(A,B,C)
79 #define WATCHPOINT_ERRNO(A)
80 #define WATCHPOINT_ASSERT_PRINT(A,B,C)
81 #define WATCHPOINT_ASSERT(A)
82 #define WATCHPOINT_ASSERT_INITIALIZED(A)
83 #define WATCHPOINT_SET(A)
87 #endif /* __LIBMEMCACHED_WATCHPOINT_H__ */