[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 | // |
---|
[73abe95] | 7 | // debug.hfa -- |
---|
[78b3f52] | 8 | // |
---|
| 9 | // Author : Thierry Delisle |
---|
| 10 | // Created On : Mon Nov 28 12:27:26 2016 |
---|
[16cc9f7] | 11 | // Last Modified By : Peter A. Buhr |
---|
| 12 | // Last Modified On : Fri Apr 22 18:21:56 2022 |
---|
| 13 | // Update Count : 11 |
---|
[78b3f52] | 14 | // |
---|
| 15 | |
---|
[6b0b624] | 16 | #pragma once |
---|
[78b3f52] | 17 | |
---|
[3e2b9c9] | 18 | #include <assert.h> |
---|
| 19 | |
---|
[78b3f52] | 20 | #ifdef __CFA_DEBUG__ |
---|
[36982fc] | 21 | #define __cfaabi_dbg_debug_do(...) __VA_ARGS__ |
---|
| 22 | #define __cfaabi_dbg_no_debug_do(...) |
---|
| 23 | #define __cfaabi_dbg_ctx __PRETTY_FUNCTION__ |
---|
| 24 | #define __cfaabi_dbg_ctx2 , __PRETTY_FUNCTION__ |
---|
[96ef156] | 25 | #define __cfaabi_dbg_ctx_param __attribute__((unused)) const char caller[] |
---|
| 26 | #define __cfaabi_dbg_ctx_param2 , __attribute__((unused)) const char caller[] |
---|
[ae66348] | 27 | #define __cfaabi_dbg_ctx_fwd caller |
---|
| 28 | #define __cfaabi_dbg_ctx_fwd2 , caller |
---|
[78b3f52] | 29 | #else |
---|
[36982fc] | 30 | #define __cfaabi_dbg_debug_do(...) |
---|
| 31 | #define __cfaabi_dbg_no_debug_do(...) __VA_ARGS__ |
---|
| 32 | #define __cfaabi_dbg_ctx |
---|
| 33 | #define __cfaabi_dbg_ctx2 |
---|
| 34 | #define __cfaabi_dbg_ctx_param |
---|
| 35 | #define __cfaabi_dbg_ctx_param2 |
---|
[ae66348] | 36 | #define __cfaabi_dbg_ctx_fwd |
---|
| 37 | #define __cfaabi_dbg_ctx_fwd2 |
---|
[4aa2fb2] | 38 | #endif |
---|
| 39 | |
---|
[9d944b2] | 40 | #ifdef __cforall |
---|
| 41 | extern "C" { |
---|
| 42 | #endif |
---|
[6a5be52] | 43 | #include <stdarg.h> |
---|
[9d944b2] | 44 | |
---|
[e3fea42] | 45 | extern void __cfaabi_bits_write( int fd, const char buffer[], int len ); |
---|
[1c40091] | 46 | extern void __cfaabi_bits_acquire(); |
---|
| 47 | extern void __cfaabi_bits_release(); |
---|
[16cc9f7] | 48 | extern int __cfaabi_bits_print_safe ( int fd, const char fmt[], ... ) __attribute__(( format(printf, 2, 3) )); |
---|
| 49 | extern int __cfaabi_bits_print_nolock( int fd, const char fmt[], ... ) __attribute__(( format(printf, 2, 3) )); |
---|
| 50 | extern int __cfaabi_bits_print_vararg( int fd, const char fmt[], va_list arg ); |
---|
| 51 | extern int __cfaabi_bits_print_buffer( int fd, char buffer[], int buffer_size, const char fmt[], ... ) __attribute__(( format(printf, 4, 5) )); |
---|
[851fd92] | 52 | |
---|
[c1581a0] | 53 | #if defined(__CFA_DEBUG_PRINT__) \ |
---|
| 54 | || defined(__CFA_DEBUG_PRINT_IO__) || defined(__CFA_DEBUG_PRINT_IO_CORE__) \ |
---|
[851fd92] | 55 | || defined(__CFA_DEBUG_PRINT_MONITOR__) || defined(__CFA_DEBUG_PRINT_PREEMPTION__) \ |
---|
[504a7dc] | 56 | || defined(__CFA_DEBUG_PRINT_RUNTIME_CORE__) || defined(__CFA_DEBUG_PRINT_EXCEPTION__) \ |
---|
| 57 | || defined(__CFA_DEBUG_PRINT_READY_QUEUE__) |
---|
[851fd92] | 58 | #include <stdio.h> |
---|
| 59 | #include <unistd.h> |
---|
| 60 | #endif |
---|
[9d944b2] | 61 | #ifdef __cforall |
---|
| 62 | } |
---|
| 63 | #endif |
---|
| 64 | |
---|
[851fd92] | 65 | // Deprecated: Use the versions with the new module names. |
---|
[d9c44c3] | 66 | #ifdef __CFA_DEBUG_PRINT__ |
---|
[1c40091] | 67 | #define __cfaabi_dbg_write( buffer, len ) __cfaabi_bits_write( STDERR_FILENO, buffer, len ) |
---|
| 68 | #define __cfaabi_dbg_acquire() __cfaabi_bits_acquire() |
---|
| 69 | #define __cfaabi_dbg_release() __cfaabi_bits_release() |
---|
[93ace83] | 70 | #define __cfaabi_dbg_print_safe(...) __cfaabi_bits_print_safe ( STDERR_FILENO, __VA_ARGS__ ) |
---|
| 71 | #define __cfaabi_dbg_print_nolock(...) __cfaabi_bits_print_nolock ( STDERR_FILENO, __VA_ARGS__ ) |
---|
| 72 | #define __cfaabi_dbg_print_buffer(...) __cfaabi_bits_print_buffer ( STDERR_FILENO, __VA_ARGS__ ) |
---|
| 73 | #define __cfaabi_dbg_print_buffer_decl(...) char __dbg_text[256]; int __dbg_len = snprintf( __dbg_text, 256, __VA_ARGS__ ); __cfaabi_bits_write( STDERR_FILENO, __dbg_text, __dbg_len ); |
---|
| 74 | #define __cfaabi_dbg_print_buffer_local(...) __dbg_len = snprintf( __dbg_text, 256, __VA_ARGS__ ); __cfaabi_dbg_write( STDERR_FILENO, __dbg_text, __dbg_len ); |
---|
[d9c44c3] | 75 | #else |
---|
[36982fc] | 76 | #define __cfaabi_dbg_write(...) ((void)0) |
---|
| 77 | #define __cfaabi_dbg_acquire() ((void)0) |
---|
| 78 | #define __cfaabi_dbg_release() ((void)0) |
---|
| 79 | #define __cfaabi_dbg_print_safe(...) ((void)0) |
---|
| 80 | #define __cfaabi_dbg_print_nolock(...) ((void)0) |
---|
| 81 | #define __cfaabi_dbg_print_buffer(...) ((void)0) |
---|
| 82 | #define __cfaabi_dbg_print_buffer_decl(...) ((void)0) |
---|
| 83 | #define __cfaabi_dbg_print_buffer_local(...) ((void)0) |
---|
[d9c44c3] | 84 | #endif |
---|
| 85 | |
---|
[851fd92] | 86 | // Debug print functions and statements: |
---|
| 87 | // Most are wrappers around the bits printing function but are not always used. |
---|
| 88 | // If they are used depends if the group (first argument) is active or not. The group must be one |
---|
| 89 | // defined belowe. The other arguments depend on the wrapped function. |
---|
| 90 | #define __cfadbg_write(group, buffer, len) \ |
---|
| 91 | __CFADBG_PRINT_GROUP_##group(__cfaabi_bits_write(STDERR_FILENO, buffer, len)) |
---|
| 92 | #define __cfadbg_acquire(group) \ |
---|
| 93 | __CFADBG_PRINT_GROUP_##group(__cfaabi_bits_acquire()) |
---|
| 94 | #define __cfadbg_release(group) \ |
---|
| 95 | __CFADBG_PRINT_GROUP_##group(__cfaabi_bits_release()) |
---|
| 96 | #define __cfadbg_print_safe(group, ...) \ |
---|
| 97 | __CFADBG_PRINT_GROUP_##group(__cfaabi_bits_print_safe(STDERR_FILENO, __VA_ARGS__)) |
---|
| 98 | #define __cfadbg_print_nolock(group, ...) \ |
---|
| 99 | __CFADBG_PRINT_GROUP_##group(__cfaabi_bits_print_nolock(STDERR_FILENO, __VA_ARGS__)) |
---|
| 100 | #define __cfadbg_print_buffer(group, ...) \ |
---|
| 101 | __CFADBG_PRINT_GROUP_##group(__cfaabi_bits_print_buffer(STDERR_FILENO, __VA_ARGS__)) |
---|
| 102 | #define __cfadbg_print_buffer_decl(group, ...) \ |
---|
[8e85344] | 103 | __CFADBG_PRINT_GROUP_##group(char __dbg_text[256]; int __dbg_len = snprintf( __dbg_text, 256, __VA_ARGS__ ); __cfaabi_bits_write( STDERR_FILENO, __dbg_text, __dbg_len )) |
---|
[851fd92] | 104 | #define __cfadbg_print_buffer_local(group, ...) \ |
---|
| 105 | __CFADBG_PRINT_GROUP_##group(__dbg_len = snprintf( __dbg_text, 256, __VA_ARGS__ ); __cfaabi_bits_write(STDERR_FILENO, __dbg_text, __dbg_len)) |
---|
| 106 | |
---|
| 107 | // The debug print groups: |
---|
| 108 | #if defined(__CFA_DEBUG_PRINT__) || defined(__CFA_DEBUG_PRINT_IO__) |
---|
| 109 | # define __CFADBG_PRINT_GROUP_io(...) __VA_ARGS__ |
---|
| 110 | #else |
---|
| 111 | # define __CFADBG_PRINT_GROUP_io(...) ((void)0) |
---|
| 112 | #endif |
---|
[0a805f2] | 113 | #if defined(__CFA_DEBUG_PRINT__) || defined(__CFA_DEBUG_PRINT_IO__) || defined(__CFA_DEBUG_PRINT_IO_CORE__) |
---|
| 114 | # define __CFADBG_PRINT_GROUP_io_core(...) __VA_ARGS__ |
---|
| 115 | #else |
---|
| 116 | # define __CFADBG_PRINT_GROUP_io_core(...) ((void)0) |
---|
| 117 | #endif |
---|
[851fd92] | 118 | #if defined(__CFA_DEBUG_PRINT__) || defined(__CFA_DEBUG_PRINT_MONITOR__) |
---|
| 119 | # define __CFADBG_PRINT_GROUP_monitor(...) __VA_ARGS__ |
---|
| 120 | #else |
---|
| 121 | # define __CFADBG_PRINT_GROUP_monitor(...) ((void)0) |
---|
| 122 | #endif |
---|
| 123 | #if defined(__CFA_DEBUG_PRINT__) || defined(__CFA_DEBUG_PRINT_PREEMPTION__) |
---|
| 124 | # define __CFADBG_PRINT_GROUP_preemption(...) __VA_ARGS__ |
---|
| 125 | #else |
---|
| 126 | # define __CFADBG_PRINT_GROUP_preemption(...) ((void)0) |
---|
| 127 | #endif |
---|
| 128 | #if defined(__CFA_DEBUG_PRINT__) || defined(__CFA_DEBUG_PRINT_RUNTIME_CORE__) |
---|
| 129 | # define __CFADBG_PRINT_GROUP_runtime_core(...) __VA_ARGS__ |
---|
| 130 | #else |
---|
| 131 | # define __CFADBG_PRINT_GROUP_runtime_core(...) ((void)0) |
---|
| 132 | #endif |
---|
| 133 | #if defined(__CFA_DEBUG_PRINT__) || defined(__CFA_DEBUG_PRINT_READY_QUEUE__) |
---|
| 134 | # define __CFADBG_PRINT_GROUP_ready_queue(...) __VA_ARGS__ |
---|
| 135 | #else |
---|
| 136 | # define __CFADBG_PRINT_GROUP_ready_queue(...) ((void)0) |
---|
| 137 | #endif |
---|
| 138 | #if defined(__CFA_DEBUG_PRINT__) || defined(__CFA_DEBUG_PRINT_EXCEPTION__) |
---|
| 139 | # define __CFADBG_PRINT_GROUP_exception(...) __VA_ARGS__ |
---|
| 140 | #else |
---|
| 141 | # define __CFADBG_PRINT_GROUP_exception(...) ((void)0) |
---|
| 142 | #endif |
---|
| 143 | |
---|
[78b3f52] | 144 | // Local Variables: // |
---|
| 145 | // mode: c // |
---|
| 146 | // tab-width: 4 // |
---|
| 147 | // End: // |
---|