Home | History | Annotate | Download | only in tests
      1 // These counters are used to get a delta between leak counts at startup
      2 // (eg. due to libc) and later on.  Necessary to get reliable leak tests
      3 // across different platforms.
      4 #define DECLARE_LEAK_COUNTERS \
      5    long L0_bytes = 0, L_bytes = 0, L0_blocks = 0, L_blocks = 0; \
      6    long D0_bytes = 0, D_bytes = 0, D0_blocks = 0, D_blocks = 0; \
      7    long R0_bytes = 0, R_bytes = 0, R0_blocks = 0, R_blocks = 0; \
      8    long S0_bytes = 0, S_bytes = 0, S0_blocks = 0, S_blocks = 0
      9 
     10 // Set a baseline, in case allocations have already happened.
     11 #define GET_INITIAL_LEAK_COUNTS \
     12    do { \
     13       VALGRIND_DO_QUICK_LEAK_CHECK; \
     14       VALGRIND_COUNT_LEAKS(      L0_bytes,  D0_bytes,  R0_bytes,  S0_bytes );\
     15       VALGRIND_COUNT_LEAK_BLOCKS(L0_blocks, D0_blocks, R0_blocks, S0_blocks); \
     16    } while (0)
     17 
     18 // Set a baseline, in case allocations have already happened.
     19 #define GET_FINAL_LEAK_COUNTS \
     20    do { \
     21       VALGRIND_DO_QUICK_LEAK_CHECK; \
     22       VALGRIND_COUNT_LEAKS(      L_bytes,  D_bytes,  R_bytes,  S_bytes ); \
     23       VALGRIND_COUNT_LEAK_BLOCKS(L_blocks, D_blocks, R_blocks, S_blocks); \
     24       L_bytes -= L0_bytes;  L_blocks -= L0_blocks; \
     25       D_bytes -= D0_bytes;  D_blocks -= D0_blocks; \
     26       R_bytes -= R0_bytes;  R_blocks -= R0_blocks; \
     27       S_bytes -= S0_bytes;  S_blocks -= S0_blocks; \
     28    } while (0)
     29 
     30 // Print leak counts.  When used in conjunction with -q the normal counts
     31 // aren't shown, which is what we want.
     32 #define PRINT_LEAK_COUNTS(where) \
     33    do { \
     34       fprintf(where,"leaked:     %3ld bytes in %2ld blocks\n", \
     35                      L_bytes,L_blocks); \
     36       fprintf(where,"dubious:    %3ld bytes in %2ld blocks\n", \
     37                      D_bytes,D_blocks); \
     38       fprintf(where,"reachable:  %3ld bytes in %2ld blocks\n", \
     39                      R_bytes,R_blocks); \
     40       fprintf(where,"suppressed: %3ld bytes in %2ld blocks\n", \
     41                      S_bytes,S_blocks); \
     42    } while (0)
     43 
     44 /* Upon a call to a function, some architectures store pointers into
     45  * into registers.  Valgrind may consider these registers when determining
     46  * whether an address is reachable, so we need to zero-out these registers
     47  * as needed.
     48  */
     49 #if defined __powerpc__
     50 #define CLEAR_CALLER_SAVED_REGS \
     51   do { \
     52    __asm__ __volatile__( "li 3, 0" : : :/*trash*/"r3" ); \
     53    __asm__ __volatile__( "li 4, 0" : : :/*trash*/"r4" ); \
     54    __asm__ __volatile__( "li 5, 0" : : :/*trash*/"r5" ); \
     55    __asm__ __volatile__( "li 6, 0" : : :/*trash*/"r6" ); \
     56    __asm__ __volatile__( "li 7, 0" : : :/*trash*/"r7" ); \
     57    __asm__ __volatile__( "li 8, 0" : : :/*trash*/"r8" ); \
     58    __asm__ __volatile__( "li 9, 0" : : :/*trash*/"r9" ); \
     59    __asm__ __volatile__( "li 10, 0" : : :/*trash*/"r10" ); \
     60    __asm__ __volatile__( "li 11, 0" : : :/*trash*/"r11" ); \
     61    __asm__ __volatile__( "li 12, 0" : : :/*trash*/"r12" ); \
     62   } while (0)
     63 #else
     64 #define CLEAR_CALLER_SAVED_REGS  /*nothing*/
     65 #endif
     66 
     67 
     68