source: src/libcfa/libhdr/libdebug.h @ aa3d77b

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since aa3d77b was aa3d77b, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

added support for inline decls of buffer for debug prints
added support for multiple statements/declarations inside lib_debug_do

  • Property mode set to 100644
File size: 2.8 KB
RevLine 
[78b3f52]1//
2// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// libdebug.h --
8//
9// Author           : Thierry Delisle
10// Created On       : Mon Nov 28 12:27:26 2016
11// Last Modified By : Thierry Delisle
12// Last Modified On : Mon Nov 28 12:27:26 2016
13// Update Count     : 0
14//
15
16#ifndef __LIB_DEBUG_H__
17#define __LIB_DEBUG_H__
18
19#ifdef __CFA_DEBUG__
[aa3d77b]20        #define LIB_DEBUG_DO(...) __VA_ARGS__
21        #define LIB_NO_DEBUG_DO(...)
[78b3f52]22#else
[aa3d77b]23        #define LIB_DEBUG_DO(...)
24        #define LIB_NO_DEBUG_DO(...) __VA_ARGS__
[78b3f52]25#endif
26
[4aa2fb2]27#if !defined(NDEBUG) && (defined(__CFA_DEBUG__) || defined(__CFA_VERIFY__))
28        #define verify(x) assert(x)
29        #define verifyf(x, ...) assertf(x, __VA_ARGS__)
30#else
31        #define verify(x)
32        #define verifyf(x, ...)
33#endif
34
35
[9d944b2]36#ifdef __cforall
37extern "C" {
38#endif
39      #include <stdarg.h>
40
41      extern void __lib_debug_write( int fd, const char *buffer, int len );
42      extern void __lib_debug_acquire();
43      extern void __lib_debug_release();
44      extern void __lib_debug_print_safe  ( const char fmt[], ... ) __attribute__(( format (printf, 1, 2) ));
45      extern void __lib_debug_print_nolock( const char fmt[], ... ) __attribute__(( format (printf, 1, 2) ));
46      extern void __lib_debug_print_vararg( const char fmt[], va_list arg );
47      extern void __lib_debug_print_buffer( char buffer[], int buffer_size, const char fmt[], ... ) __attribute__(( format (printf, 3, 4) ));
48#ifdef __cforall
49}
50#endif
51
[d9c44c3]52#ifdef __CFA_DEBUG_PRINT__
[aa3d77b]53        #define LIB_DEBUG_WRITE( fd, buffer, len )     __lib_debug_write( fd, buffer, len )
54        #define LIB_DEBUG_ACQUIRE()                    __lib_debug_acquire()
55        #define LIB_DEBUG_RELEASE()                    __lib_debug_release()
56        #define LIB_DEBUG_PRINT_SAFE(...)              __lib_debug_print_safe   (__VA_ARGS__)
57        #define LIB_DEBUG_PRINT_NOLOCK(...)            __lib_debug_print_nolock (__VA_ARGS__)
58        #define LIB_DEBUG_PRINT_BUFFER(...)            __lib_debug_print_buffer (__VA_ARGS__)
59        #define LIB_DEBUG_PRINT_BUFFER_DECL(fd, ...)   char text[256]; int len = snprintf( text, 256, __VA_ARGS__ ); __lib_debug_write( fd, text, len );
60        #define LIB_DEBUG_PRINT_BUFFER_LOCAL(fd, ...)  len = snprintf( text, 256, __VA_ARGS__ ); __lib_debug_write( fd, text, len );
[d9c44c3]61#else
[aa3d77b]62        #define LIB_DEBUG_WRITE(...)               ((void)0)
63        #define LIB_DEBUG_ACQUIRE()                ((void)0)
64        #define LIB_DEBUG_RELEASE()                ((void)0)
65        #define LIB_DEBUG_PRINT_SAFE(...)          ((void)0)
66        #define LIB_DEBUG_PRINT_NOLOCK(...)        ((void)0)
67        #define LIB_DEBUG_PRINT_BUFFER(...)        ((void)0)
68        #define LIB_DEBUG_PRINT_BUFFER_DECL(...)   ((void)0)
69        #define LIB_DEBUG_PRINT_BUFFER_LOCAL(...)  ((void)0)
[d9c44c3]70#endif
71
[78b3f52]72#endif //__LIB_DEBUG_H__
73
74// Local Variables: //
75// mode: c //
76// tab-width: 4 //
77// End: //
Note: See TracBrowser for help on using the repository browser.