Skip to content

Commit 7ace0cb

Browse files
Merge pull request #3881 from geky/log-no-io
Remove debug links to printf/exit in NDEBUG builds
2 parents 7e03d8f + cfc223c commit 7ace0cb

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

platform/mbed_debug.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,49 +18,49 @@
1818
*/
1919
#ifndef MBED_DEBUG_H
2020
#define MBED_DEBUG_H
21-
#include "device.h"
21+
#if DEVICE_STDIO_MESSAGES
22+
#include <stdio.h>
23+
#include <stdarg.h>
24+
#endif
2225

2326
#ifdef __cplusplus
2427
extern "C" {
2528
#endif
2629

27-
#if DEVICE_STDIO_MESSAGES
28-
#include <stdio.h>
29-
#include <stdarg.h>
3030

3131
/** Output a debug message
3232
*
3333
* @param format printf-style format string, followed by variables
3434
*/
3535
static inline void debug(const char *format, ...) {
36+
#if DEVICE_STDIO_MESSAGES && !defined(NDEBUG)
3637
va_list args;
3738
va_start(args, format);
3839
vfprintf(stderr, format, args);
3940
va_end(args);
41+
#endif
4042
}
4143

44+
4245
/** Conditionally output a debug message
4346
*
44-
* NOTE: If the condition is constant false (!= 1) and the compiler optimization
47+
* NOTE: If the condition is constant false (== 0) and the compiler optimization
4548
* level is greater than 0, then the whole function will be compiled away.
4649
*
47-
* @param condition output only if condition is true (== 1)
50+
* @param condition output only if condition is true (!= 0)
4851
* @param format printf-style format string, followed by variables
4952
*/
5053
static inline void debug_if(int condition, const char *format, ...) {
51-
if (condition == 1) {
54+
#if DEVICE_STDIO_MESSAGES && !defined(NDEBUG)
55+
if (condition) {
5256
va_list args;
5357
va_start(args, format);
5458
vfprintf(stderr, format, args);
5559
va_end(args);
5660
}
61+
#endif
5762
}
5863

59-
#else
60-
static inline void debug(const char *format, ...) {}
61-
static inline void debug_if(int condition, const char *format, ...) {}
62-
63-
#endif
6464

6565
#ifdef __cplusplus
6666
}

rtos/rtx/TARGET_CORTEX_M/RTX_Conf_CM.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
*---------------------------------------------------------------------------*/
3434

3535
#include "cmsis_os.h"
36+
#include "mbed_error.h"
3637

3738

3839
/*----------------------------------------------------------------------------
@@ -244,7 +245,6 @@ void os_idle_demon (void) {
244245
/*----------------------------------------------------------------------------
245246
* RTX Errors
246247
*---------------------------------------------------------------------------*/
247-
extern void error(const char* format, ...);
248248
extern osThreadId svcThreadGetId (void);
249249

250250
void os_error (uint32_t err_code) {

0 commit comments

Comments
 (0)