Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-08-27 09:37:30

0001 /**
0002  * \file debug.h
0003  *
0004  * \brief Functions for controlling and providing debug output from the library.
0005  */
0006 /*
0007  *  Copyright The Mbed TLS Contributors
0008  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
0009  */
0010 #ifndef MBEDTLS_DEBUG_H
0011 #define MBEDTLS_DEBUG_H
0012 
0013 #include "mbedtls/build_info.h"
0014 
0015 #include "mbedtls/ssl.h"
0016 
0017 #if defined(MBEDTLS_ECP_C)
0018 #include "mbedtls/ecp.h"
0019 #endif
0020 
0021 #if defined(MBEDTLS_DEBUG_C)
0022 
0023 #define MBEDTLS_DEBUG_STRIP_PARENS(...)   __VA_ARGS__
0024 
0025 #define MBEDTLS_SSL_DEBUG_MSG(level, args)                    \
0026     mbedtls_debug_print_msg(ssl, level, __FILE__, __LINE__,    \
0027                             MBEDTLS_DEBUG_STRIP_PARENS args)
0028 
0029 #define MBEDTLS_SSL_DEBUG_RET(level, text, ret)                \
0030     mbedtls_debug_print_ret(ssl, level, __FILE__, __LINE__, text, ret)
0031 
0032 #define MBEDTLS_SSL_DEBUG_BUF(level, text, buf, len)           \
0033     mbedtls_debug_print_buf(ssl, level, __FILE__, __LINE__, text, buf, len)
0034 
0035 #if defined(MBEDTLS_BIGNUM_C)
0036 #define MBEDTLS_SSL_DEBUG_MPI(level, text, X)                  \
0037     mbedtls_debug_print_mpi(ssl, level, __FILE__, __LINE__, text, X)
0038 #endif
0039 
0040 #if defined(MBEDTLS_ECP_C)
0041 #define MBEDTLS_SSL_DEBUG_ECP(level, text, X)                  \
0042     mbedtls_debug_print_ecp(ssl, level, __FILE__, __LINE__, text, X)
0043 #endif
0044 
0045 #if defined(MBEDTLS_X509_CRT_PARSE_C)
0046 #if !defined(MBEDTLS_X509_REMOVE_INFO)
0047 #define MBEDTLS_SSL_DEBUG_CRT(level, text, crt)                \
0048     mbedtls_debug_print_crt(ssl, level, __FILE__, __LINE__, text, crt)
0049 #else
0050 #define MBEDTLS_SSL_DEBUG_CRT(level, text, crt)       do { } while (0)
0051 #endif /* MBEDTLS_X509_REMOVE_INFO */
0052 #endif /* MBEDTLS_X509_CRT_PARSE_C */
0053 
0054 #if defined(MBEDTLS_ECDH_C)
0055 #define MBEDTLS_SSL_DEBUG_ECDH(level, ecdh, attr)               \
0056     mbedtls_debug_printf_ecdh(ssl, level, __FILE__, __LINE__, ecdh, attr)
0057 #endif
0058 
0059 #else /* MBEDTLS_DEBUG_C */
0060 
0061 #define MBEDTLS_SSL_DEBUG_MSG(level, args)            do { } while (0)
0062 #define MBEDTLS_SSL_DEBUG_RET(level, text, ret)       do { } while (0)
0063 #define MBEDTLS_SSL_DEBUG_BUF(level, text, buf, len)  do { } while (0)
0064 #define MBEDTLS_SSL_DEBUG_MPI(level, text, X)         do { } while (0)
0065 #define MBEDTLS_SSL_DEBUG_ECP(level, text, X)         do { } while (0)
0066 #define MBEDTLS_SSL_DEBUG_CRT(level, text, crt)       do { } while (0)
0067 #define MBEDTLS_SSL_DEBUG_ECDH(level, ecdh, attr)     do { } while (0)
0068 
0069 #endif /* MBEDTLS_DEBUG_C */
0070 
0071 /**
0072  * \def MBEDTLS_PRINTF_ATTRIBUTE
0073  *
0074  * Mark a function as having printf attributes, and thus enable checking
0075  * via -wFormat and other flags. This does nothing on builds with compilers
0076  * that do not support the format attribute
0077  *
0078  * Module:  library/debug.c
0079  * Caller:
0080  *
0081  * This module provides debugging functions.
0082  */
0083 #if defined(__has_attribute)
0084 #if __has_attribute(format)
0085 #if defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 1
0086 #define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check)    \
0087     __attribute__((__format__(gnu_printf, string_index, first_to_check)))
0088 #else /* defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 1 */
0089 #define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check)    \
0090     __attribute__((format(printf, string_index, first_to_check)))
0091 #endif
0092 #else /* __has_attribute(format) */
0093 #define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check)
0094 #endif /* __has_attribute(format) */
0095 #else /* defined(__has_attribute) */
0096 #define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check)
0097 #endif
0098 
0099 /**
0100  * \def MBEDTLS_PRINTF_SIZET
0101  *
0102  * MBEDTLS_PRINTF_xxx: Due to issues with older window compilers
0103  * and MinGW we need to define the printf specifier for size_t
0104  * and long long per platform.
0105  *
0106  * Module:  library/debug.c
0107  * Caller:
0108  *
0109  * This module provides debugging functions.
0110  */
0111 #if (defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 0) || (defined(_MSC_VER) && _MSC_VER < 1800)
0112    #include <inttypes.h>
0113    #define MBEDTLS_PRINTF_SIZET     PRIuPTR
0114    #define MBEDTLS_PRINTF_LONGLONG  "I64d"
0115 #else \
0116     /* (defined(__MINGW32__)  && __USE_MINGW_ANSI_STDIO == 0) || (defined(_MSC_VER) && _MSC_VER < 1800) */
0117    #define MBEDTLS_PRINTF_SIZET     "zu"
0118    #define MBEDTLS_PRINTF_LONGLONG  "lld"
0119 #endif \
0120     /* (defined(__MINGW32__)  && __USE_MINGW_ANSI_STDIO == 0) || (defined(_MSC_VER) && _MSC_VER < 1800) */
0121 
0122 #if !defined(MBEDTLS_PRINTF_MS_TIME)
0123 #include <inttypes.h>
0124 #if !defined(PRId64)
0125 #define MBEDTLS_PRINTF_MS_TIME MBEDTLS_PRINTF_LONGLONG
0126 #else
0127 #define MBEDTLS_PRINTF_MS_TIME PRId64
0128 #endif
0129 #endif /* MBEDTLS_PRINTF_MS_TIME */
0130 
0131 #ifdef __cplusplus
0132 extern "C" {
0133 #endif
0134 
0135 /**
0136  * \brief   Set the threshold error level to handle globally all debug output.
0137  *          Debug messages that have a level over the threshold value are
0138  *          discarded.
0139  *          (Default value: 0 = No debug )
0140  *
0141  * \param threshold     threshold level of messages to filter on. Messages at a
0142  *                      higher level will be discarded.
0143  *                          - Debug levels
0144  *                              - 0 No debug
0145  *                              - 1 Error
0146  *                              - 2 State change
0147  *                              - 3 Informational
0148  *                              - 4 Verbose
0149  */
0150 void mbedtls_debug_set_threshold(int threshold);
0151 
0152 #ifdef __cplusplus
0153 }
0154 #endif
0155 
0156 #endif /* MBEDTLS_DEBUG_H */