Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file debug.h |
Paul Bakker | e0ccd0a | 2009-01-04 16:27:10 +0000 | [diff] [blame] | 3 | * |
Simon Butcher | 7ef5cf3 | 2016-02-13 22:20:04 +0000 | [diff] [blame] | 4 | * \brief Functions for controlling and providing debug output from the library. |
Darryl Green | a40a101 | 2018-01-05 15:33:17 +0000 | [diff] [blame] | 5 | */ |
| 6 | /* |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 7 | * Copyright The Mbed TLS Contributors |
Dave Rodgman | 16799db | 2023-11-02 19:47:20 +0000 | [diff] [blame] | 8 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 9 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 10 | #ifndef MBEDTLS_DEBUG_H |
| 11 | #define MBEDTLS_DEBUG_H |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 12 | |
Bence Szépkúti | c662b36 | 2021-05-27 11:25:03 +0200 | [diff] [blame] | 13 | #include "mbedtls/build_info.h" |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 14 | |
Jaeden Amero | 6609aef | 2019-07-04 20:01:14 +0100 | [diff] [blame] | 15 | #include "mbedtls/ssl.h" |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 16 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 17 | #if defined(MBEDTLS_ECP_C) |
Jaeden Amero | 6609aef | 2019-07-04 20:01:14 +0100 | [diff] [blame] | 18 | #include "mbedtls/ecp.h" |
Paul Bakker | 41c83d3 | 2013-03-20 14:39:14 +0100 | [diff] [blame] | 19 | #endif |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 20 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 21 | #if defined(MBEDTLS_DEBUG_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 22 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 23 | #define MBEDTLS_DEBUG_STRIP_PARENS(...) __VA_ARGS__ |
Manuel Pégourié-Gonnard | b74c245 | 2015-06-29 20:08:23 +0200 | [diff] [blame] | 24 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 25 | #define MBEDTLS_SSL_DEBUG_MSG(level, args) \ |
| 26 | mbedtls_debug_print_msg(ssl, level, __FILE__, __LINE__, \ |
| 27 | MBEDTLS_DEBUG_STRIP_PARENS args) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 28 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 29 | #define MBEDTLS_SSL_DEBUG_RET(level, text, ret) \ |
| 30 | mbedtls_debug_print_ret(ssl, level, __FILE__, __LINE__, text, ret) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 31 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 32 | #define MBEDTLS_SSL_DEBUG_BUF(level, text, buf, len) \ |
| 33 | mbedtls_debug_print_buf(ssl, level, __FILE__, __LINE__, text, buf, len) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 34 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 35 | #if defined(MBEDTLS_BIGNUM_C) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 36 | #define MBEDTLS_SSL_DEBUG_MPI(level, text, X) \ |
| 37 | mbedtls_debug_print_mpi(ssl, level, __FILE__, __LINE__, text, X) |
Paul Bakker | ed27a04 | 2013-04-18 22:46:23 +0200 | [diff] [blame] | 38 | #endif |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 39 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 40 | #if defined(MBEDTLS_X509_CRT_PARSE_C) |
Hanno Becker | 612a2f1 | 2020-10-09 09:19:39 +0100 | [diff] [blame] | 41 | #if !defined(MBEDTLS_X509_REMOVE_INFO) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 42 | #define MBEDTLS_SSL_DEBUG_CRT(level, text, crt) \ |
| 43 | mbedtls_debug_print_crt(ssl, level, __FILE__, __LINE__, text, crt) |
Peter Kolbus | 9a969b6 | 2018-12-11 13:55:56 -0600 | [diff] [blame] | 44 | #else |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 45 | #define MBEDTLS_SSL_DEBUG_CRT(level, text, crt) do { } while (0) |
Hanno Becker | 612a2f1 | 2020-10-09 09:19:39 +0100 | [diff] [blame] | 46 | #endif /* MBEDTLS_X509_REMOVE_INFO */ |
Peter Kolbus | 9a969b6 | 2018-12-11 13:55:56 -0600 | [diff] [blame] | 47 | #endif /* MBEDTLS_X509_CRT_PARSE_C */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 48 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 49 | #else /* MBEDTLS_DEBUG_C */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 50 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 51 | #define MBEDTLS_SSL_DEBUG_MSG(level, args) do { } while (0) |
| 52 | #define MBEDTLS_SSL_DEBUG_RET(level, text, ret) do { } while (0) |
| 53 | #define MBEDTLS_SSL_DEBUG_BUF(level, text, buf, len) do { } while (0) |
| 54 | #define MBEDTLS_SSL_DEBUG_MPI(level, text, X) do { } while (0) |
| 55 | #define MBEDTLS_SSL_DEBUG_ECP(level, text, X) do { } while (0) |
| 56 | #define MBEDTLS_SSL_DEBUG_CRT(level, text, crt) do { } while (0) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 57 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 58 | #endif /* MBEDTLS_DEBUG_C */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 59 | |
Paul Elliott | 4e58970 | 2020-12-09 14:38:01 +0000 | [diff] [blame] | 60 | /** |
| 61 | * \def MBEDTLS_PRINTF_ATTRIBUTE |
| 62 | * |
| 63 | * Mark a function as having printf attributes, and thus enable checking |
Paul Elliott | aa5e132 | 2021-03-05 15:52:25 +0000 | [diff] [blame] | 64 | * via -wFormat and other flags. This does nothing on builds with compilers |
| 65 | * that do not support the format attribute |
Paul Elliott | 4e58970 | 2020-12-09 14:38:01 +0000 | [diff] [blame] | 66 | * |
| 67 | * Module: library/debug.c |
| 68 | * Caller: |
| 69 | * |
| 70 | * This module provides debugging functions. |
| 71 | */ |
Paul Elliott | aa5e132 | 2021-03-05 15:52:25 +0000 | [diff] [blame] | 72 | #if defined(__has_attribute) |
| 73 | #if __has_attribute(format) |
eugene | e42a50d | 2021-05-12 12:33:36 -0400 | [diff] [blame] | 74 | #if defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 1 |
Paul Elliott | 4e58970 | 2020-12-09 14:38:01 +0000 | [diff] [blame] | 75 | #define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check) \ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 76 | __attribute__((__format__(gnu_printf, string_index, first_to_check))) |
eugene | e42a50d | 2021-05-12 12:33:36 -0400 | [diff] [blame] | 77 | #else /* defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 1 */ |
| 78 | #define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check) \ |
| 79 | __attribute__((format(printf, string_index, first_to_check))) |
| 80 | #endif |
Paul Elliott | aa5e132 | 2021-03-05 15:52:25 +0000 | [diff] [blame] | 81 | #else /* __has_attribute(format) */ |
| 82 | #define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check) |
| 83 | #endif /* __has_attribute(format) */ |
| 84 | #else /* defined(__has_attribute) */ |
Paul Elliott | abb3af7 | 2020-12-18 16:43:22 +0000 | [diff] [blame] | 85 | #define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check) |
Paul Elliott | 4e58970 | 2020-12-09 14:38:01 +0000 | [diff] [blame] | 86 | #endif |
| 87 | |
Paul Elliott | d48d5c6 | 2021-01-07 14:47:05 +0000 | [diff] [blame] | 88 | /** |
| 89 | * \def MBEDTLS_PRINTF_SIZET |
| 90 | * |
| 91 | * MBEDTLS_PRINTF_xxx: Due to issues with older window compilers |
| 92 | * and MinGW we need to define the printf specifier for size_t |
| 93 | * and long long per platform. |
| 94 | * |
| 95 | * Module: library/debug.c |
| 96 | * Caller: |
| 97 | * |
| 98 | * This module provides debugging functions. |
| 99 | */ |
Bence Szépkúti | cd1ece7 | 2025-03-07 17:22:40 +0100 | [diff] [blame] | 100 | #if defined(__MINGW32__) || (defined(_MSC_VER) && _MSC_VER < 1900) |
Paul Elliott | 48438c7 | 2021-01-08 17:05:25 +0000 | [diff] [blame] | 101 | #include <inttypes.h> |
| 102 | #define MBEDTLS_PRINTF_SIZET PRIuPTR |
| 103 | #define MBEDTLS_PRINTF_LONGLONG "I64d" |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 104 | #else \ |
Bence Szépkúti | 011b6cb | 2025-03-08 01:02:37 +0100 | [diff] [blame] | 105 | /* defined(__MINGW32__) || (defined(_MSC_VER) && _MSC_VER < 1900) */ |
Paul Elliott | d48d5c6 | 2021-01-07 14:47:05 +0000 | [diff] [blame] | 106 | #define MBEDTLS_PRINTF_SIZET "zu" |
| 107 | #define MBEDTLS_PRINTF_LONGLONG "lld" |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 108 | #endif \ |
Bence Szépkúti | 011b6cb | 2025-03-08 01:02:37 +0100 | [diff] [blame] | 109 | /* defined(__MINGW32__) || (defined(_MSC_VER) && _MSC_VER < 1900) */ |
Paul Elliott | d48d5c6 | 2021-01-07 14:47:05 +0000 | [diff] [blame] | 110 | |
Jerry Yu | eba0ab5 | 2022-12-15 17:41:41 +0800 | [diff] [blame] | 111 | #if !defined(MBEDTLS_PRINTF_MS_TIME) |
Jerry Yu | 03511b0 | 2023-02-27 10:48:41 +0800 | [diff] [blame] | 112 | #include <inttypes.h> |
| 113 | #if !defined(PRId64) |
| 114 | #define MBEDTLS_PRINTF_MS_TIME MBEDTLS_PRINTF_LONGLONG |
| 115 | #else |
Jerry Yu | 041c8c1 | 2023-02-03 13:15:09 +0800 | [diff] [blame] | 116 | #define MBEDTLS_PRINTF_MS_TIME PRId64 |
Jerry Yu | 03511b0 | 2023-02-27 10:48:41 +0800 | [diff] [blame] | 117 | #endif |
Jerry Yu | eba0ab5 | 2022-12-15 17:41:41 +0800 | [diff] [blame] | 118 | #endif /* MBEDTLS_PRINTF_MS_TIME */ |
| 119 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 120 | #ifdef __cplusplus |
| 121 | extern "C" { |
| 122 | #endif |
| 123 | |
Paul Bakker | c73079a | 2014-04-25 16:34:30 +0200 | [diff] [blame] | 124 | /** |
Simon Butcher | 7ef5cf3 | 2016-02-13 22:20:04 +0000 | [diff] [blame] | 125 | * \brief Set the threshold error level to handle globally all debug output. |
| 126 | * Debug messages that have a level over the threshold value are |
| 127 | * discarded. |
| 128 | * (Default value: 0 = No debug ) |
Paul Bakker | c73079a | 2014-04-25 16:34:30 +0200 | [diff] [blame] | 129 | * |
Shaun Case | 8b0ecbc | 2021-12-20 21:14:10 -0800 | [diff] [blame] | 130 | * \param threshold threshold level of messages to filter on. Messages at a |
Simon Butcher | 7ef5cf3 | 2016-02-13 22:20:04 +0000 | [diff] [blame] | 131 | * higher level will be discarded. |
| 132 | * - Debug levels |
| 133 | * - 0 No debug |
| 134 | * - 1 Error |
| 135 | * - 2 State change |
| 136 | * - 3 Informational |
| 137 | * - 4 Verbose |
Paul Bakker | c73079a | 2014-04-25 16:34:30 +0200 | [diff] [blame] | 138 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 139 | void mbedtls_debug_set_threshold(int threshold); |
Paul Bakker | c73079a | 2014-04-25 16:34:30 +0200 | [diff] [blame] | 140 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 141 | #ifdef __cplusplus |
| 142 | } |
| 143 | #endif |
| 144 | |
Valerio Setti | b4f5076 | 2024-01-17 10:24:52 +0100 | [diff] [blame] | 145 | #endif /* MBEDTLS_DEBUG_H */ |