Mbed OS Reference
Loading...
Searching...
No Matches
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#include <stdio.h>
20#include <stdarg.h>
21#include "platform/mbed_toolchain.h"
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27/** \addtogroup platform-public-api */
28/** @{*/
29
30/**
31 * \defgroup platform_debug Debug functions
32 * @{
33 */
34
35static inline void debug(const char *format, ...) MBED_PRINTF(1, 2);
36static inline void debug_if(int condition, const char *format, ...) MBED_PRINTF(2, 3);
37
38/** Output a debug message
39 *
40 * @param format printf-style format string, followed by variables
41 */
42static inline void debug(const char *format, ...)
43{
44#if !defined(NDEBUG)
45 va_list args;
46 va_start(args, format);
47 vfprintf(stderr, format, args);
48 va_end(args);
49#endif
50}
51
52
53/** Conditionally output a debug message
54 *
55 * NOTE: If the condition is constant false (== 0) and the compiler optimization
56 * level is greater than 0, then the whole function will be compiled away.
57 *
58 * @param condition output only if condition is true (!= 0)
59 * @param format printf-style format string, followed by variables
60 */
61static inline void debug_if(int condition, const char *format, ...)
62{
63#if !defined(NDEBUG)
64 if (condition) {
65 va_list args;
66 va_start(args, format);
67 vfprintf(stderr, format, args);
68 va_end(args);
69 }
70#endif
71}
72
73
74#ifdef __cplusplus
75}
76#endif
77
78#endif
79
80/**@}*/
81
82/**@}*/
83