27#if !defined(MICRO_OS_PLUS_DIAG_TRACE_H_)
28#error "Do not include this file directly; use "micro-os-plus/diag/trace.h"."
33#ifndef MICRO_OS_PLUS_DIAG_TRACE_INLINES_CPP_API_INLINES_H_
34#define MICRO_OS_PLUS_DIAG_TRACE_INLINES_CPP_API_INLINES_H_
38#if defined(__cplusplus)
42#if defined(MICRO_OS_PLUS_DIAG_TRACE_ENABLED)
52#pragma GCC diagnostic push
55#pragma clang diagnostic ignored "-Wc++98-compat"
56#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
74 template <trace_policy T>
78 std::va_list arguments;
79 va_start (arguments, format);
81 int ret =
vprintf (format, arguments);
87 template <trace_policy T>
98#pragma GCC diagnostic push
100#pragma GCC diagnostic ignored "-Wformat-nonliteral"
104 ssize_t ret = ::vsnprintf (buf,
sizeof (buf), format, arguments);
107#pragma GCC diagnostic pop
118 static_cast<size_t> (std::min (
119 ret,
static_cast<ssize_t
> (
sizeof (buf) - 1))));
123#pragma GCC diagnostic push
125#if defined(__clang__)
126#elif defined(__GNUC__)
127#pragma GCC diagnostic ignored "-Wuseless-cast"
132 return static_cast<int> (ret);
135#pragma GCC diagnostic pop
139 template <trace_policy T>
143 std::size_t len = std::strlen (s);
144 ssize_t ret =
write (s, len);
148 if (ret >= 0 &&
static_cast<std::size_t
> (ret) == len)
150 ssize_t ret2 =
write (
"\n", 1);
163#pragma GCC diagnostic push
165#if defined(__clang__)
166#elif defined(__GNUC__)
167#pragma GCC diagnostic ignored "-Wuseless-cast"
172 return static_cast<int> (ret);
175#pragma GCC diagnostic pop
184 template <trace_policy T>
188 auto ch =
static_cast<unsigned char> (c);
189 ssize_t ret =
write (&ch, 1);
201#pragma GCC diagnostic push
203#if defined(__clang__)
204#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
208 template <trace_policy T>
212 printf (
"%s(argc=%d, argv=[", name, argc);
213 for (
int i = 0; i < argc; ++i)
219 printf (
"\"%s\"", argv[i]);
225#pragma GCC diagnostic pop
242 write (
const void* buf, std::size_t nbyte)
noexcept
254 printf (
const char* format, ...) noexcept
256 std::va_list arguments;
257 va_start (arguments, format);
267 vprintf (
const char* format, std::va_list arguments)
noexcept
285 dump_args (
int argc,
char* argv[],
const char* name)
noexcept
293#pragma GCC diagnostic pop
303#pragma GCC diagnostic push
305#if defined(__clang__)
306#pragma clang diagnostic ignored "-Wc++98-compat"
315 inline __attribute__ ((always_inline))
void
320 inline __attribute__ ((always_inline)) ssize_t
321 write (
const void* , std::size_t nbyte)
noexcept
323 return static_cast<ssize_t
> (nbyte);
326 inline __attribute__ ((always_inline))
void
327 flush (
void)
noexcept
333 inline __attribute__ ((always_inline, format (
printf, 1, 2))) int
334 printf (const
char* , ...) noexcept
339 inline __attribute__ ((always_inline, format (
printf, 1, 0))) int
340 vprintf (const
char* , std::va_list ) noexcept
345 inline __attribute__ ((always_inline))
int
346 puts (
const char* )
noexcept
351 inline __attribute__ ((always_inline))
int
357 inline __attribute__ ((always_inline))
void
359 const char* )
noexcept
366#pragma GCC diagnostic pop
static void initialise(void) noexcept
Initialise the trace output channel.
static int puts(const char *s="") noexcept
Write the string and a line terminator to the trace output channel.
static int vprintf(const char *format, std::va_list arguments) noexcept
Write a formatted variable arguments list to the trace output channel.
static void dump_args(int argc, char *argv[], const char *name="main") noexcept
Send the argv[] array to the trace output channel.
static int printf(const char *format,...) noexcept
Write a formatted string to the trace output channel.
static ssize_t write(const void *buf, std::size_t nbyte) noexcept
Write the given number of bytes to the trace output channel.
static void flush(void) noexcept
Flush the trace output channel.
static int putchar(int c) noexcept
Write the single character to the trace output channel.
#define MICRO_OS_PLUS_DIAG_TRACE_PRINTF_BUFFER_ARRAY_SIZE_INTEGER
The size, in bytes, of the stack buffer used to format trace messages.
void initialise(void) noexcept
Initialise the trace output channel.
ssize_t write(const void *buf, std::size_t nbyte) noexcept
Write the given number of bytes to the trace output channel.
void flush(void) noexcept
Flush the trace output channel.
int printf(const char *format,...) noexcept
Write a formatted string to the trace output channel.
int puts(const char *s="") noexcept
Write the string and a line terminator to the trace output channel.
int putchar(int c) noexcept
Write the single character to the trace output channel.
int vprintf(const char *format, std::va_list arguments) noexcept
Write a formatted variable arguments list to the trace output channel.
Implementation details namespace.
Tracing support namespace.