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_CPP_API_INLINES_H_
34#define MICRO_OS_PLUS_DIAG_TRACE_CPP_API_INLINES_H_
42#if defined(MICRO_OS_PLUS_DIAG_TRACE_ENABLED)
51#ifndef MICRO_OS_PLUS_DIAG_TRACE_PRINTF_BUFFER_ARRAY_SIZE_INTEGER
52#define MICRO_OS_PLUS_DIAG_TRACE_PRINTF_BUFFER_ARRAY_SIZE_INTEGER (200)
57#pragma GCC diagnostic push
59#pragma clang diagnostic ignored "-Wc++98-compat"
60#pragma clang diagnostic ignored "-Wpre-c++17-compat"
77 template <trace_policy T>
81 std::va_list arguments;
82 va_start (arguments, format);
84#pragma GCC diagnostic push
86#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
88 int ret =
vprintf (format, arguments);
89#pragma GCC diagnostic pop
95 template <trace_policy T>
106#pragma GCC diagnostic push
107#pragma GCC diagnostic ignored "-Wformat-nonliteral"
108#if defined(__clang__)
109#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
111 ssize_t ret = ::vsnprintf (buf,
sizeof (buf), format, arguments);
112#pragma GCC diagnostic pop
121 static_cast<size_t> (std::min (
122 ret,
static_cast<ssize_t
> (
sizeof (buf) - 1))));
124#pragma GCC diagnostic push
125#if defined(__GNUC__) && !defined(__clang__)
126#pragma GCC diagnostic ignored "-Wuseless-cast"
129 return static_cast<int> (ret);
130#pragma GCC diagnostic pop
133 template <trace_policy T>
137#pragma GCC diagnostic push
138#if defined(__clang__)
139#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
141 ssize_t ret =
write (s, std::strlen (s));
142#pragma GCC diagnostic pop
145 ssize_t ret2 =
write (
"\n", 1);
157#pragma GCC diagnostic push
158#if defined(__GNUC__) && !defined(__clang__)
159#pragma GCC diagnostic ignored "-Wuseless-cast"
162 return static_cast<int> (ret);
163#pragma GCC diagnostic pop
171 template <trace_policy T>
175 char ch =
static_cast<char> (c);
176 ssize_t ret =
write (&ch, 1);
187#pragma GCC diagnostic push
188#if defined(__clang__)
189#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
191 template <trace_policy T>
195 printf (
"%s(argc=%d, argv=[", name, argc);
196 for (
int i = 0; i < argc; ++i)
202 printf (
"\"%s\"", argv[i]);
206#pragma GCC diagnostic pop
223 write (
const void* buf, std::size_t nbyte)
noexcept
235 printf (
const char* format, ...) noexcept
237 std::va_list arguments;
238 va_start (arguments, format);
239#pragma GCC diagnostic push
240#if defined(__clang__)
241#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
245#pragma GCC diagnostic pop
251 vprintf (
const char* format, std::va_list arguments)
noexcept
253#pragma GCC diagnostic push
254#if defined(__clang__)
255#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
258#pragma GCC diagnostic pop
264#pragma GCC diagnostic push
265#if defined(__clang__)
266#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
269#pragma GCC diagnostic pop
279 dump_args (
int argc,
char* argv[],
const char* name)
noexcept
286#pragma GCC diagnostic pop
294#pragma GCC diagnostic push
295#if defined(__clang__)
296#pragma clang diagnostic ignored "-Wc++98-compat"
297#pragma clang diagnostic ignored "-Wpre-c++17-compat"
305 inline __attribute__ ((always_inline))
void
310 inline __attribute__ ((always_inline)) ssize_t
311 write (
const void* , std::size_t nbyte)
noexcept
313 return static_cast<ssize_t
> (nbyte);
316 inline __attribute__ ((always_inline))
void
317 flush (
void)
noexcept
323 inline __attribute__ ((always_inline))
int
324 printf (
const char* , ...) noexcept
329 inline __attribute__ ((always_inline))
int
330 vprintf (
const char* , std::va_list )
noexcept
335 inline __attribute__ ((always_inline))
int
336 puts (
const char* )
noexcept
341 inline __attribute__ ((always_inline))
int
347 inline __attribute__ ((always_inline))
void
349 const char* )
noexcept
355#pragma GCC diagnostic pop
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 void flush(void) noexcept(noexcept(T::flush()))
Flush 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(noexcept(T::write(buf, nbyte)))
Write the given number of bytes to the trace output channel.
static void initialise(void) noexcept(noexcept(T::initialise()))
Initialise the trace output channel.
static int putchar(int c) noexcept
Write the single character to the trace output channel.
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.
#define MICRO_OS_PLUS_DIAG_TRACE_PRINTF_BUFFER_ARRAY_SIZE_INTEGER