Skip to content

Print and debug improvements #1750

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 3 commits into from
Jun 29, 2022
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
11 changes: 11 additions & 0 deletions cores/arduino/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions cores/arduino/Print.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */ }
};
Expand Down
6 changes: 6 additions & 0 deletions cores/arduino/core_debug.c
Original file line number Diff line number Diff line change
@@ -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);
15 changes: 13 additions & 2 deletions cores/arduino/core_debug.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#ifndef _CORE_DEBUG_H
#define _CORE_DEBUG_H

#include <stdarg.h>
#if !defined(NDEBUG)
#include <stdio.h>
#include <stdarg.h>
#endif /* NDEBUG */

#ifdef __cplusplus
Expand All @@ -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;
Expand All @@ -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
Expand Down