Skip to content

Commit d1be5bd

Browse files
authored
Merge pull request #1750 from matthijskooijman/print-and-debug-improvements
Print and debug improvements
2 parents a4e4377 + b014a94 commit d1be5bd

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

Diff for: cores/arduino/Print.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,17 @@ int Print::printf(const __FlashStringHelper *format, ...)
277277
return retval;
278278
}
279279

280+
int Print::vprintf(const char *format, va_list ap)
281+
{
282+
return vdprintf((int)this, format, ap);
283+
}
284+
285+
int Print::vprintf(const __FlashStringHelper *format, va_list ap)
286+
{
287+
return vdprintf((int)this, (const char *)format, ap);
288+
}
289+
290+
280291
// Private Methods /////////////////////////////////////////////////////////////
281292

282293
size_t Print::printNumber(unsigned long n, uint8_t base)

Diff for: cores/arduino/Print.h

+2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ class Print {
106106

107107
int printf(const char *format, ...);
108108
int printf(const __FlashStringHelper *format, ...);
109+
int vprintf(const __FlashStringHelper *format, va_list ap);
110+
int vprintf(const char *format, va_list ap);
109111

110112
virtual void flush() { /* Empty implementation for backward compatibility */ }
111113
};

Diff for: cores/arduino/core_debug.c

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "core_debug.h"
2+
3+
// Ensure inline functions have a definition emitted for when they are
4+
// not inlined (needed for C functions only)
5+
extern void core_debug(const char *format, ...);
6+
extern void vcore_debug(const char *format, va_list args);

Diff for: cores/arduino/core_debug.h

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#ifndef _CORE_DEBUG_H
22
#define _CORE_DEBUG_H
3+
4+
#include <stdarg.h>
35
#if !defined(NDEBUG)
46
#include <stdio.h>
5-
#include <stdarg.h>
67
#endif /* NDEBUG */
78

89
#ifdef __cplusplus
@@ -16,7 +17,7 @@ extern "C" {
1617
* the code, use a lot of stack. An alternative, will be to implement a tiny
1718
* and limited functionality implementation of printf.
1819
*/
19-
static inline void core_debug(const char *format, ...)
20+
inline void core_debug(const char *format, ...)
2021
{
2122
#if !defined(NDEBUG)
2223
va_list args;
@@ -28,6 +29,16 @@ static inline void core_debug(const char *format, ...)
2829
#endif /* NDEBUG */
2930
}
3031

32+
inline void vcore_debug(const char *format, va_list args)
33+
{
34+
#if !defined(NDEBUG)
35+
vfprintf(stderr, format, args);
36+
#else
37+
(void)(format);
38+
(void)(args);
39+
#endif /* NDEBUG */
40+
}
41+
3142
#ifdef __cplusplus
3243
}
3344
#endif

0 commit comments

Comments
 (0)