Mistake on this page?
Report an issue in GitHub or email us
mbed_debug.h
1 /* mbed Microcontroller Library
2  * Copyright (c) 2006-2019 ARM Limited
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 #ifndef MBED_DEBUG_H
18 #define MBED_DEBUG_H
19 #if DEVICE_STDIO_MESSAGES
20 #include <stdio.h>
21 #include <stdarg.h>
22 #endif
23 #include "platform/mbed_toolchain.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 /** \addtogroup platform-public-api */
30 /** @{*/
31 
32 /**
33  * \defgroup platform_debug Debug functions
34  * @{
35  */
36 
37 static inline void debug(const char *format, ...) MBED_PRINTF(1, 2);
38 static inline void debug_if(int condition, const char *format, ...) MBED_PRINTF(2, 3);
39 
40 /** Output a debug message
41  *
42  * @param format printf-style format string, followed by variables
43  */
44 static inline void debug(const char *format, ...)
45 {
46 #if DEVICE_STDIO_MESSAGES && !defined(NDEBUG)
47  va_list args;
48  va_start(args, format);
49  vfprintf(stderr, format, args);
50  va_end(args);
51 #endif
52 }
53 
54 
55 /** Conditionally output a debug message
56  *
57  * NOTE: If the condition is constant false (== 0) and the compiler optimization
58  * level is greater than 0, then the whole function will be compiled away.
59  *
60  * @param condition output only if condition is true (!= 0)
61  * @param format printf-style format string, followed by variables
62  */
63 static inline void debug_if(int condition, const char *format, ...)
64 {
65 #if DEVICE_STDIO_MESSAGES && !defined(NDEBUG)
66  if (condition) {
67  va_list args;
68  va_start(args, format);
69  vfprintf(stderr, format, args);
70  va_end(args);
71  }
72 #endif
73 }
74 
75 
76 #ifdef __cplusplus
77 }
78 #endif
79 
80 #endif
81 
82 /**@}*/
83 
84 /**@}*/
85 
static void static void debug_if(int condition, const char *format,...) MBED_PRINTF(2
Conditionally output a debug message.
Definition: mbed_debug.h:63
static void debug(const char *format,...) MBED_PRINTF(1
Output a debug message.
Definition: mbed_debug.h:44
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.