jaulib v1.5.0
Jau Support Library (C++, Java, ..)
Loading...
Searching...
No Matches
debug.hpp File Reference
#include <cstdlib>
#include <cstdint>
#include <cstring>
#include <string>
#include <cstdio>
#include <cstdarg>
#include <string_view>
#include <jau/cpp_lang_util.hpp>
#include <jau/environment.hpp>
#include <jau/string_util.hpp>
#include <jau/string_cfmt.hpp>
Include dependency graph for debug.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  jau
 __pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
 

Macros

#define jau_ABORT(...)
 Use for unconditional ::abort() call with given messages, prefix '[elapsed_time] ABORT @ file:line func: '.
 
#define jau_COND_PRINT(C, ...)
 Use for conditional plain messages, prefix '[elapsed_time] '.
 
#define jau_DBG_ERR_PRINT(...)
 Use for environment-variable environment::DEBUG conditional error messages, prefix '[elapsed_time] Debug @ FILE:LINE FUNC: '.
 
#define jau_DBG_JNI_PRINT(...)
 Use for environment-variable environment::DEBUG_JNI conditional debug messages, prefix '[elapsed_time] Debug: '.
 
#define jau_DBG_PRINT(fmt, ...)
 Use for environment-variable environment::DEBUG conditional debug messages, prefix '[elapsed_time] Debug: '.
 
#define jau_DBG_PRINT_LINE(fmt, ...)
 
#define jau_DBG_WARN_PRINT(...)
 Use for environment-variable environment::DEBUG conditional warning messages, prefix '[elapsed_time] Warning @ FILE:LINE FUNC: '.
 
#define jau_dbgPrint1(out, printPrefix, msg, fmt, ...)
 
#define jau_dbgPrint1Line(out, printPrefix, msg, fmt, ...)
 
#define jau_dbgPrint2(out, msg, addErrno, addBacktrace, func, file, line, fmt, ...)
 
#define jau_dbgPrint2Line(out, msg, addErrno, addBacktrace, func, file, line, fmt, ...)
 
#define jau_ERR_PRINT(...)
 Use for unconditional error messages, prefix '[elapsed_time] Error @ FILE:LINE FUNC: '.
 
#define jau_ERR_PRINT2(...)
 Use for unconditional error messages, prefix '[elapsed_time] Error @ FILE:LINE FUNC: '.
 
#define jau_ERR_PRINT3(...)
 Use for unconditional error messages, prefix '[elapsed_time] Error @ FILE:LINE FUNC: '.
 
#define jau_fprintf_td(stream, fmt, ...)
 
#define jau_fprintf_td2(elapsed_ms, stream, fmt, ...)
 
#define jau_INFO_PRINT(fmt, ...)
 Use for unconditional informal messages, prefix '[elapsed_time] Info: '.
 
#define jau_INFO_PRINT_LINE(fmt, ...)
 
#define jau_IRQ_PRINT(...)
 Use for unconditional interruption messages, prefix '[elapsed_time] Interrupted @ FILE:LINE FUNC: '.
 
#define jau_PERF2_TS_T0()
 
#define jau_PERF2_TS_TD(m)
 
#define jau_PERF3_TS_T0()
 
#define jau_PERF3_TS_TD(m)
 
#define jau_PERF_TS_T0()
 
#define jau_PERF_TS_T0_BASE()
 
#define jau_PERF_TS_TD(m)
 
#define jau_PERF_TS_TD_BASE(m)
 
#define jau_PLAIN_PRINT(printPrefix, fmt, ...)
 Use for unconditional plain messages, prefix '[elapsed_time] ' if printPrefix == true.
 
#define jau_WARN_PRINT(...)
 Use for unconditional warning messages, prefix '[elapsed_time] Warning @ FILE:LINE FUNC: '.
 
#define jau_WORDY_PRINT(...)
 Use for environment-variable environment::VERBOSE conditional verbose messages, prefix '[elapsed_time] Wordy: '.
 

Functions

template<typename... Args>
int jau::fprintf_td (const uint64_t elapsed_ms, FILE *stream, std::string_view format, const Args &...args) noexcept
 Convenient fprintf() invocation, prepending the given elapsed_ms timestamp.
 
template<typename... Args>
int jau::fprintf_td (FILE *stream, std::string_view format, const Args &...args) noexcept
 Convenient fprintf() invocation, prepending the environment::getElapsedMillisecond() timestamp.
 
template<class List>
void jau::printSharedPtrList (const std::string &prefix, List &list) noexcept
 

Macro Definition Documentation

◆ jau_dbgPrint1

#define jau_dbgPrint1 ( out,
printPrefix,
msg,
fmt,
... )
Value:
jau::impl::dbgPrint1((out), (printPrefix), (msg), (fmt) __VA_OPT__(,) __VA_ARGS__); \
static_assert(0 <= jau::cfmt::check2< JAU_FOR_EACH1_LIST(JAU_NOREF_DECLTYPE_VALUE, __VA_ARGS__) >(fmt));
#define JAU_NOREF_DECLTYPE_VALUE(type)
#define JAU_FOR_EACH1_LIST(macro,...)
consteval_cxx20 ssize_t check2(std::string_view fmt) noexcept
Strict compile-time type validation of explicit argument-types against the format string.

Definition at line 83 of file debug.hpp.

◆ jau_dbgPrint1Line

#define jau_dbgPrint1Line ( out,
printPrefix,
msg,
fmt,
... )
Value:
jau::impl::dbgPrint1((out), (printPrefix), (msg), (fmt) __VA_OPT__(,) __VA_ARGS__); \
static_assert(0 == jau::cfmt::check2Line< JAU_FOR_EACH1_LIST(JAU_NOREF_DECLTYPE_VALUE, __VA_ARGS__) >(fmt));
consteval_cxx20 int check2Line(std::string_view fmt) noexcept
Strict compile-time type validation of explicit argument-types against the format string.

Definition at line 87 of file debug.hpp.

◆ jau_dbgPrint2

#define jau_dbgPrint2 ( out,
msg,
addErrno,
addBacktrace,
func,
file,
line,
fmt,
... )
Value:
jau::impl::dbgPrint2((out), (msg), (addErrno), (addBacktrace), (func), (file), (line), (fmt) __VA_OPT__(,) __VA_ARGS__); \
static_assert(0 <= jau::cfmt::check2< JAU_FOR_EACH1_LIST(JAU_NOREF_DECLTYPE_VALUE, __VA_ARGS__) >(fmt));

Definition at line 91 of file debug.hpp.

◆ jau_dbgPrint2Line

#define jau_dbgPrint2Line ( out,
msg,
addErrno,
addBacktrace,
func,
file,
line,
fmt,
... )
Value:
jau::impl::dbgPrint2((out), (msg), (addErrno), (addBacktrace), (func), (file), (line), (fmt) __VA_OPT__(,) __VA_ARGS__); \
static_assert(0 == jau::cfmt::check2Line< JAU_FOR_EACH1_LIST(JAU_NOREF_DECLTYPE_VALUE, __VA_ARGS__) >(fmt));

Definition at line 95 of file debug.hpp.

◆ jau_DBG_PRINT

#define jau_DBG_PRINT ( fmt,
... )
Value:
{ if( jau::environment::get().debug ) { jau_dbgPrint1(stderr, true, "Debug", fmt __VA_OPT__(,) __VA_ARGS__); } }
static environment & get(const std::string &root_prefix_domain="jau") noexcept
Static singleton initialization of this project's environment with the given global root prefix_domai...
#define jau_dbgPrint1(out, printPrefix, msg, fmt,...)
Definition debug.hpp:83

Use for environment-variable environment::DEBUG conditional debug messages, prefix '[elapsed_time] Debug: '.

Definition at line 100 of file debug.hpp.

◆ jau_DBG_PRINT_LINE

#define jau_DBG_PRINT_LINE ( fmt,
... )
Value:
{ if( jau::environment::get().debug ) { jau_dbgPrint1Line(stderr, true, "Debug", fmt __VA_OPT__(,) __VA_ARGS__); } }
#define jau_dbgPrint1Line(out, printPrefix, msg, fmt,...)
Definition debug.hpp:87

Definition at line 101 of file debug.hpp.

◆ jau_DBG_JNI_PRINT

#define jau_DBG_JNI_PRINT ( ...)
Value:
{ if( jau::environment::get().debug_jni ) { jau_dbgPrint1(stderr, true, "Debug", __VA_ARGS__); } }

Use for environment-variable environment::DEBUG_JNI conditional debug messages, prefix '[elapsed_time] Debug: '.

Definition at line 104 of file debug.hpp.

◆ jau_DBG_WARN_PRINT

#define jau_DBG_WARN_PRINT ( ...)
Value:
{ if( jau::environment::get().debug ) { jau_dbgPrint2(stderr, "Warning", false /* errno */, false /* backtrace */, __func__, __FILE__, __LINE__, __VA_ARGS__); } }
#define jau_dbgPrint2(out, msg, addErrno, addBacktrace, func, file, line, fmt,...)
Definition debug.hpp:91

Use for environment-variable environment::DEBUG conditional warning messages, prefix '[elapsed_time] Warning @ FILE:LINE FUNC: '.

Definition at line 107 of file debug.hpp.

◆ jau_DBG_ERR_PRINT

#define jau_DBG_ERR_PRINT ( ...)
Value:
{ if( jau::environment::get().debug ) { jau_dbgPrint2(stderr, "Debug", true /* errno */, true /* backtrace */, __func__, __FILE__, __LINE__, __VA_ARGS__); } }

Use for environment-variable environment::DEBUG conditional error messages, prefix '[elapsed_time] Debug @ FILE:LINE FUNC: '.

Function also appends last errno, strerror(errno) and full backtrace

Definition at line 110 of file debug.hpp.

◆ jau_WORDY_PRINT

#define jau_WORDY_PRINT ( ...)
Value:
{ if( jau::environment::get().verbose ) { jau_dbgPrint1(stderr, true, "Wordy", __VA_ARGS__); } }

Use for environment-variable environment::VERBOSE conditional verbose messages, prefix '[elapsed_time] Wordy: '.

'Wordy' is the shorter English form of the Latin word 'verbosus', from which the word 'verbosity' is sourced.

Definition at line 118 of file debug.hpp.

◆ jau_PERF_TS_T0_BASE

#define jau_PERF_TS_T0_BASE ( )
Value:
const uint64_t _t0 = jau::getCurrentMilliseconds()
uint64_t getCurrentMilliseconds() noexcept
Returns current monotonic time in milliseconds.

Definition at line 120 of file debug.hpp.

◆ jau_PERF_TS_TD_BASE

#define jau_PERF_TS_TD_BASE ( m)
Value:
{ const uint64_t _td = jau::getCurrentMilliseconds() - _t0; \
fprintf(stderr, "[%s] PERF %s done in %d ms,\n", jau::to_decstring(jau::environment::getElapsedMillisecond(), ',', 9).c_str(), (m), (int)_td); }
static uint64_t getElapsedMillisecond() noexcept
Returns current elapsed monotonic time in milliseconds since module startup, see startupTimeMilliseco...
std::string to_decstring(const value_type &v, const char separator='\'', const nsize_t min_width=0) noexcept
Produces a decimal integer string representation of an integral integer value with given radix.

Definition at line 122 of file debug.hpp.

◆ jau_PERF_TS_T0

#define jau_PERF_TS_T0 ( )

Definition at line 128 of file debug.hpp.

◆ jau_PERF_TS_TD

#define jau_PERF_TS_TD ( m)

Definition at line 129 of file debug.hpp.

◆ jau_PERF2_TS_T0

#define jau_PERF2_TS_T0 ( )

Definition at line 135 of file debug.hpp.

◆ jau_PERF2_TS_TD

#define jau_PERF2_TS_TD ( m)

Definition at line 136 of file debug.hpp.

◆ jau_PERF3_TS_T0

#define jau_PERF3_TS_T0 ( )

Definition at line 142 of file debug.hpp.

◆ jau_PERF3_TS_TD

#define jau_PERF3_TS_TD ( m)

Definition at line 143 of file debug.hpp.

◆ jau_ABORT

#define jau_ABORT ( ...)
Value:
{ jau_dbgPrint2(stderr, "ABORT", true /* errno */, true /* backtrace */, __func__, __FILE__, __LINE__, __VA_ARGS__); abort(); }

Use for unconditional ::abort() call with given messages, prefix '[elapsed_time] ABORT @ file:line func: '.

Function also appends last errno and strerror(errno).

Definition at line 147 of file debug.hpp.

◆ jau_ERR_PRINT

#define jau_ERR_PRINT ( ...)
Value:
{ jau_dbgPrint2(stderr, "Error", true /* errno */, true /* backtrace */, __func__, __FILE__, __LINE__, __VA_ARGS__); }

Use for unconditional error messages, prefix '[elapsed_time] Error @ FILE:LINE FUNC: '.

Function also appends last errno, strerror(errno) and full backtrace

Definition at line 150 of file debug.hpp.

◆ jau_ERR_PRINT2

#define jau_ERR_PRINT2 ( ...)
Value:
{ jau_dbgPrint2(stderr, "Error", true /* errno */, false /* backtrace */, __func__, __FILE__, __LINE__, __VA_ARGS__); }

Use for unconditional error messages, prefix '[elapsed_time] Error @ FILE:LINE FUNC: '.

Function also appends last errno and strerror(errno). No backtrace.

Definition at line 153 of file debug.hpp.

◆ jau_ERR_PRINT3

#define jau_ERR_PRINT3 ( ...)
Value:
{ jau_dbgPrint2(stderr, "Error", true /* errno */, true /* backtrace */, __func__, __FILE__, __LINE__, __VA_ARGS__); }

Use for unconditional error messages, prefix '[elapsed_time] Error @ FILE:LINE FUNC: '.

Function also appends last errno and strerror(errno). Full backtrace.

Examples
test_stringfmt_check.cpp.

Definition at line 156 of file debug.hpp.

◆ jau_IRQ_PRINT

#define jau_IRQ_PRINT ( ...)
Value:
{ jau_dbgPrint2(stderr, "Interrupted", true /* errno */, false /* backtrace */, __func__, __FILE__, __LINE__, __VA_ARGS__); }

Use for unconditional interruption messages, prefix '[elapsed_time] Interrupted @ FILE:LINE FUNC: '.

Function also appends last errno and strerror(errno).

Definition at line 159 of file debug.hpp.

◆ jau_WARN_PRINT

#define jau_WARN_PRINT ( ...)
Value:
{ jau_dbgPrint2(stderr, "Warning", false /* errno */, false /* backtrace */, __func__, __FILE__, __LINE__, __VA_ARGS__); }

Use for unconditional warning messages, prefix '[elapsed_time] Warning @ FILE:LINE FUNC: '.

Definition at line 162 of file debug.hpp.

◆ jau_INFO_PRINT

#define jau_INFO_PRINT ( fmt,
... )
Value:
{ jau_dbgPrint1(stderr, true, "Info", fmt __VA_OPT__(,) __VA_ARGS__); }

Use for unconditional informal messages, prefix '[elapsed_time] Info: '.

Examples
test_stringfmt_check.cpp.

Definition at line 165 of file debug.hpp.

◆ jau_INFO_PRINT_LINE

#define jau_INFO_PRINT_LINE ( fmt,
... )
Value:
{ jau_dbgPrint1Line(stderr, true, "Info", fmt __VA_OPT__(,) __VA_ARGS__); }

Definition at line 166 of file debug.hpp.

◆ jau_PLAIN_PRINT

#define jau_PLAIN_PRINT ( printPrefix,
fmt,
... )
Value:
{ jau_dbgPrint1(stderr, (printPrefix), nullptr, fmt __VA_OPT__(,) __VA_ARGS__); }

Use for unconditional plain messages, prefix '[elapsed_time] ' if printPrefix == true.

Definition at line 169 of file debug.hpp.

◆ jau_COND_PRINT

#define jau_COND_PRINT ( C,
... )
Value:
{ if( C ) { jau::impl::dbgPrint0(stderr, false, false, __VA_ARGS__); } }

Use for conditional plain messages, prefix '[elapsed_time] '.

Definition at line 172 of file debug.hpp.

◆ jau_fprintf_td2

#define jau_fprintf_td2 ( elapsed_ms,
stream,
fmt,
... )
Value:
jau::fprintf_td((elapsed_ms), (stream), (fmt) __VA_OPT__(,) __VA_ARGS__); \
static_assert(0 <= jau::cfmt::check2< JAU_FOR_EACH1_LIST(JAU_NOREF_DECLTYPE_VALUE, __VA_ARGS__) >(fmt));
int fprintf_td(const uint64_t elapsed_ms, FILE *stream, std::string_view format, const Args &...args) noexcept
Convenient fprintf() invocation, prepending the given elapsed_ms timestamp.
Definition debug.hpp:184

Definition at line 221 of file debug.hpp.

◆ jau_fprintf_td

#define jau_fprintf_td ( stream,
fmt,
... )
Value:
jau::fprintf_td((stream), (fmt) __VA_OPT__(,) __VA_ARGS__); \
static_assert(0 <= jau::cfmt::check2< JAU_FOR_EACH1_LIST(JAU_NOREF_DECLTYPE_VALUE, __VA_ARGS__) >(fmt));
Examples
test_basictypeconv.cpp.

Definition at line 225 of file debug.hpp.