Skip to content

Remove debug links to printf/exit in NDEBUG builds #3881

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions platform/mbed_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,49 @@
*/
#ifndef MBED_DEBUG_H
#define MBED_DEBUG_H
#include "device.h"
#if DEVICE_STDIO_MESSAGES
#include <stdio.h>
#include <stdarg.h>
#endif

#ifdef __cplusplus
extern "C" {
#endif

#if DEVICE_STDIO_MESSAGES
#include <stdio.h>
#include <stdarg.h>

/** Output a debug message
*
* @param format printf-style format string, followed by variables
*/
static inline void debug(const char *format, ...) {
#if DEVICE_STDIO_MESSAGES && !defined(NDEBUG)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checking - is NDEBUG defined in the default profile = not breaking for mbed 2 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NDEBUG is not defined in the default profile, not sure how that affects mbed 2
https://github.com/ARMmbed/mbed-os/blob/master/tools/profiles/develop.json

va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
#endif
}


/** Conditionally output a debug message
*
* NOTE: If the condition is constant false (!= 1) and the compiler optimization
* NOTE: If the condition is constant false (== 0) and the compiler optimization
* level is greater than 0, then the whole function will be compiled away.
*
* @param condition output only if condition is true (== 1)
* @param condition output only if condition is true (!= 0)
* @param format printf-style format string, followed by variables
*/
static inline void debug_if(int condition, const char *format, ...) {
if (condition == 1) {
#if DEVICE_STDIO_MESSAGES && !defined(NDEBUG)
if (condition) {
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
}
#endif
}

#else
static inline void debug(const char *format, ...) {}
static inline void debug_if(int condition, const char *format, ...) {}

#endif

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion rtos/rtx/TARGET_CORTEX_M/RTX_Conf_CM.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
*---------------------------------------------------------------------------*/

#include "cmsis_os.h"
#include "mbed_error.h"


/*----------------------------------------------------------------------------
Expand Down Expand Up @@ -244,7 +245,6 @@ void os_idle_demon (void) {
/*----------------------------------------------------------------------------
* RTX Errors
*---------------------------------------------------------------------------*/
extern void error(const char* format, ...);
extern osThreadId svcThreadGetId (void);

void os_error (uint32_t err_code) {
Expand Down