| 1 | // =============================================================== // |
|---|
| 2 | // // |
|---|
| 3 | // File : arb_debug.h // |
|---|
| 4 | // Purpose : some debugging tools // |
|---|
| 5 | // // |
|---|
| 6 | // Coded by Ralf Westram (coder@reallysoft.de) in May 2007 // |
|---|
| 7 | // Institute of Microbiology (Technical University Munich) // |
|---|
| 8 | // http://www.arb-home.de/ // |
|---|
| 9 | // // |
|---|
| 10 | // =============================================================== // |
|---|
| 11 | #ifndef ARB_DEBUG_H |
|---|
| 12 | #define ARB_DEBUG_H |
|---|
| 13 | |
|---|
| 14 | #if defined(DEBUG) |
|---|
| 15 | |
|---|
| 16 | // if you get the valgrind warning |
|---|
| 17 | // "Conditional jump or move depends on uninitialized value" |
|---|
| 18 | // for a complex statement, use TEST_EXPR_INITIALIZED to find out |
|---|
| 19 | // which part of the statement is the cause. |
|---|
| 20 | |
|---|
| 21 | #define TEST_EXPR_INITIALIZED(expr) do { \ |
|---|
| 22 | static bool t_i_b; \ |
|---|
| 23 | \ |
|---|
| 24 | if (expr) t_i_b = false; \ |
|---|
| 25 | else t_i_b = true; \ |
|---|
| 26 | } while (0) |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | template <int OFF, int SIZE> |
|---|
| 30 | static void CHECK_CMEM_INITIALIZED(const char *ptr) { |
|---|
| 31 | arb_assert(SIZE); // SIZE == 0 is invalid |
|---|
| 32 | if (SIZE == 1) { |
|---|
| 33 | TEST_EXPR_INITIALIZED(ptr[OFF]); |
|---|
| 34 | } |
|---|
| 35 | else { |
|---|
| 36 | const int HALF = SIZE/2; |
|---|
| 37 | CHECK_CMEM_INITIALIZED<OFF,HALF>(ptr); |
|---|
| 38 | CHECK_CMEM_INITIALIZED<OFF+HALF,SIZE-HALF>(ptr); |
|---|
| 39 | } |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | template <int SIZE> |
|---|
| 43 | static void CHECK_MEM_INITIALIZED(const void *ptr) { |
|---|
| 44 | CHECK_CMEM_INITIALIZED<0,SIZE>((const char*)ptr); |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | #define TEST_INITIALIZED(data) CHECK_MEM_INITIALIZED< sizeof(data) >( &(data) ) |
|---|
| 48 | |
|---|
| 49 | #else |
|---|
| 50 | |
|---|
| 51 | // create warning for forgotten debug code |
|---|
| 52 | #define TEST_EXPR_INITIALIZED(expr) { int TEST_EXPR_INITIALIZED; } |
|---|
| 53 | #define TEST_INITIALIZED(data) { int TEST_INITIALIZED; } |
|---|
| 54 | #define THROW_VALGRIND_WARNING() { int THROW_VALGRIND_WARNING; } |
|---|
| 55 | |
|---|
| 56 | #endif // DEBUG |
|---|
| 57 | |
|---|
| 58 | #else |
|---|
| 59 | #error arb_debug.h included twice |
|---|
| 60 | #endif // ARB_DEBUG_H |
|---|
| 61 | |
|---|