Mistake on this page?
Report an issue in GitHub or email us
mbed_debug.h
1 
2 /** \addtogroup platform */
3 /** @{*/
4 /**
5  * \defgroup platform_debug Debug functions
6  * @{
7  */
8 
9 /* mbed Microcontroller Library
10  * Copyright (c) 2006-2013 ARM Limited
11  * SPDX-License-Identifier: Apache-2.0
12  *
13  * Licensed under the Apache License, Version 2.0 (the "License");
14  * you may not use this file except in compliance with the License.
15  * You may obtain a copy of the License at
16  *
17  * http://www.apache.org/licenses/LICENSE-2.0
18  *
19  * Unless required by applicable law or agreed to in writing, software
20  * distributed under the License is distributed on an "AS IS" BASIS,
21  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22  * See the License for the specific language governing permissions and
23  * limitations under the License.
24  */
25 #ifndef MBED_DEBUG_H
26 #define MBED_DEBUG_H
27 #if DEVICE_STDIO_MESSAGES
28 #include <stdio.h>
29 #include <stdarg.h>
30 #endif
31 #include "mbed_toolchain.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
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 debug_if(int condition, const char *format,...)
Conditionally output a debug message.
Definition: mbed_debug.h:63
static void debug(const char *format,...)
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.