diff --git a/cores/arduino/Print.cpp b/cores/arduino/Print.cpp index f0a0dc8f50..8b41f7c1ba 100644 --- a/cores/arduino/Print.cpp +++ b/cores/arduino/Print.cpp @@ -277,6 +277,17 @@ int Print::printf(const __FlashStringHelper *format, ...) return retval; } +int Print::vprintf(const char *format, va_list ap) +{ + return vdprintf((int)this, format, ap); +} + +int Print::vprintf(const __FlashStringHelper *format, va_list ap) +{ + return vdprintf((int)this, (const char *)format, ap); +} + + // Private Methods ///////////////////////////////////////////////////////////// size_t Print::printNumber(unsigned long n, uint8_t base) diff --git a/cores/arduino/Print.h b/cores/arduino/Print.h index f7bae65254..036fd5347b 100644 --- a/cores/arduino/Print.h +++ b/cores/arduino/Print.h @@ -106,6 +106,8 @@ class Print { int printf(const char *format, ...); int printf(const __FlashStringHelper *format, ...); + int vprintf(const __FlashStringHelper *format, va_list ap); + int vprintf(const char *format, va_list ap); virtual void flush() { /* Empty implementation for backward compatibility */ } }; diff --git a/cores/arduino/core_debug.c b/cores/arduino/core_debug.c new file mode 100644 index 0000000000..8899b4c4d9 --- /dev/null +++ b/cores/arduino/core_debug.c @@ -0,0 +1,6 @@ +#include "core_debug.h" + +// Ensure inline functions have a definition emitted for when they are +// not inlined (needed for C functions only) +extern void core_debug(const char *format, ...); +extern void vcore_debug(const char *format, va_list args); diff --git a/cores/arduino/core_debug.h b/cores/arduino/core_debug.h index 98219db022..f5a74e62f3 100644 --- a/cores/arduino/core_debug.h +++ b/cores/arduino/core_debug.h @@ -1,8 +1,9 @@ #ifndef _CORE_DEBUG_H #define _CORE_DEBUG_H + +#include #if !defined(NDEBUG) #include - #include #endif /* NDEBUG */ #ifdef __cplusplus @@ -16,7 +17,7 @@ extern "C" { * the code, use a lot of stack. An alternative, will be to implement a tiny * and limited functionality implementation of printf. */ -static inline void core_debug(const char *format, ...) +inline void core_debug(const char *format, ...) { #if !defined(NDEBUG) va_list args; @@ -28,6 +29,16 @@ static inline void core_debug(const char *format, ...) #endif /* NDEBUG */ } +inline void vcore_debug(const char *format, va_list args) +{ +#if !defined(NDEBUG) + vfprintf(stderr, format, args); +#else + (void)(format); + (void)(args); +#endif /* NDEBUG */ +} + #ifdef __cplusplus } #endif