jaulib v1.4.1-17-gd77ace3-dirty
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.
 
namespace  jau::impl
 

Macros

#define ABORT(...)
 Use for unconditional ::abort() call with given messages, prefix '[elapsed_time] ABORT @ file:line func: '.
 
#define COND_PRINT(C, ...)
 Use for conditional plain messages, prefix '[elapsed_time] '.
 
#define DBG_ERR_PRINT(...)
 Use for environment-variable environment::DEBUG conditional error messages, prefix '[elapsed_time] Debug @ FILE:LINE FUNC: '.
 
#define DBG_JNI_PRINT(...)
 Use for environment-variable environment::DEBUG_JNI conditional debug messages, prefix '[elapsed_time] Debug: '.
 
#define DBG_PRINT(fmt, ...)
 Use for environment-variable environment::DEBUG conditional debug messages, prefix '[elapsed_time] Debug: '.
 
#define DBG_PRINT_LINE(fmt, ...)
 
#define DBG_WARN_PRINT(...)
 Use for environment-variable environment::DEBUG conditional warning messages, prefix '[elapsed_time] Warning @ FILE:LINE FUNC: '.
 
#define ERR_PRINT(...)
 Use for unconditional error messages, prefix '[elapsed_time] Error @ FILE:LINE FUNC: '.
 
#define ERR_PRINT2(...)
 Use for unconditional error messages, prefix '[elapsed_time] Error @ FILE:LINE FUNC: '.
 
#define ERR_PRINT3(...)
 Use for unconditional error messages, prefix '[elapsed_time] Error @ FILE:LINE FUNC: '.
 
#define INFO_PRINT(fmt, ...)
 Use for unconditional informal messages, prefix '[elapsed_time] Info: '.
 
#define INFO_PRINT_LINE(fmt, ...)
 
#define IRQ_PRINT(...)
 Use for unconditional interruption messages, prefix '[elapsed_time] Interrupted @ 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 PERF2_TS_T0()
 
#define PERF2_TS_TD(m)
 
#define PERF3_TS_T0()
 
#define PERF3_TS_TD(m)
 
#define PERF_TS_T0()
 
#define PERF_TS_T0_BASE()
 
#define PERF_TS_TD(m)
 
#define PERF_TS_TD_BASE(m)
 
#define PLAIN_PRINT(printPrefix, fmt, ...)
 Use for unconditional plain messages, prefix '[elapsed_time] ' if printPrefix == true.
 
#define WARN_PRINT(...)
 Use for unconditional warning messages, prefix '[elapsed_time] Warning @ FILE:LINE FUNC: '.
 
#define WORDY_PRINT(...)
 Use for environment-variable environment::VERBOSE conditional verbose messages, prefix '[elapsed_time] Wordy: '.
 

Functions

template<typename... Args>
void jau::impl::dbgPrint0 (FILE *out, bool addErrno, bool addBacktrace, std::string_view format, const Args &...args) noexcept
 
template<typename... Args>
void jau::impl::dbgPrint1 (FILE *out, bool printPrefix, const char *msg, std::string_view format, const Args &...args) noexcept
 
template<typename... Args>
void jau::impl::dbgPrint2 (FILE *out, const char *msg, bool addErrno, bool addBacktrace, const char *func, const char *file, const int line, std::string_view format, const Args &...args) noexcept
 
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_DECLTYPE_VALUE, __VA_ARGS__) >(fmt));
#define JAU_FOR_EACH1_LIST(macro,...)
#define JAU_DECLTYPE_VALUE(type)
consteval_cxx20 ssize_t check2(std::string_view fmt) noexcept
Strict compile-time type validation of explicit argument-types against the format string.
void dbgPrint1(FILE *out, bool printPrefix, const char *msg, std::string_view format, const Args &...args) noexcept
Definition debug.hpp:71

Definition at line 111 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_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 115 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_DECLTYPE_VALUE, __VA_ARGS__) >(fmt));
void dbgPrint2(FILE *out, const char *msg, bool addErrno, bool addBacktrace, const char *func, const char *file, const int line, std::string_view format, const Args &...args) noexcept
Definition debug.hpp:91

Definition at line 119 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_DECLTYPE_VALUE, __VA_ARGS__) >(fmt));

Definition at line 123 of file debug.hpp.

◆ DBG_PRINT

#define 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:111

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

Definition at line 128 of file debug.hpp.

◆ DBG_PRINT_LINE

#define 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:115

Definition at line 129 of file debug.hpp.

◆ DBG_JNI_PRINT

#define 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 132 of file debug.hpp.

◆ DBG_WARN_PRINT

#define 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:119

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

Definition at line 135 of file debug.hpp.

◆ DBG_ERR_PRINT

#define 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 138 of file debug.hpp.

◆ WORDY_PRINT

#define 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 146 of file debug.hpp.

◆ PERF_TS_T0_BASE

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

Definition at line 148 of file debug.hpp.

◆ PERF_TS_TD_BASE

#define 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 width=0) noexcept
Produce a decimal string representation of an integral integer value.

Definition at line 150 of file debug.hpp.

◆ PERF_TS_T0

#define PERF_TS_T0 ( )

Definition at line 156 of file debug.hpp.

◆ PERF_TS_TD

#define PERF_TS_TD ( m)

Definition at line 157 of file debug.hpp.

◆ PERF2_TS_T0

#define PERF2_TS_T0 ( )

Definition at line 163 of file debug.hpp.

◆ PERF2_TS_TD

#define PERF2_TS_TD ( m)

Definition at line 164 of file debug.hpp.

◆ PERF3_TS_T0

#define PERF3_TS_T0 ( )

Definition at line 170 of file debug.hpp.

◆ PERF3_TS_TD

#define PERF3_TS_TD ( m)

Definition at line 171 of file debug.hpp.

◆ ABORT

#define 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 175 of file debug.hpp.

◆ ERR_PRINT

#define 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 178 of file debug.hpp.

◆ ERR_PRINT2

#define 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 181 of file debug.hpp.

◆ ERR_PRINT3

#define 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 184 of file debug.hpp.

◆ IRQ_PRINT

#define 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 187 of file debug.hpp.

◆ WARN_PRINT

#define 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 190 of file debug.hpp.

◆ INFO_PRINT

#define 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 193 of file debug.hpp.

◆ INFO_PRINT_LINE

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

Definition at line 194 of file debug.hpp.

◆ PLAIN_PRINT

#define 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 197 of file debug.hpp.

◆ COND_PRINT

#define COND_PRINT ( C,
... )
Value:
{ if( C ) { jau::impl::dbgPrint0(stderr, false, false, __VA_ARGS__); } }
void dbgPrint0(FILE *out, bool addErrno, bool addBacktrace, std::string_view format, const Args &...args) noexcept
Definition debug.hpp:50

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

Definition at line 234 of file debug.hpp.