31    #define UNW_LOCAL_ONLY 
   32    #include <libunwind.h> 
   44#if defined(__GNUC__) && ! defined(__clang__) 
   45    #pragma GCC push_options 
   46    #pragma GCC optimize("-O0") 
   58    const size_t len = ::strlen(mangled_name);
 
   59    if( 
nullptr == mangled_name || 0 == len ) {
 
   63        if( len > ctti_name_prefix->length()+2 &&
 
   64            mangled_name == ::strstr(mangled_name, ctti_name_prefix->c_str()) )
 
   66            std::string r( mangled_name + ctti_name_prefix->length() );
 
   67            r.resize(r.length() - 1);
 
   79    char* real_name = abi::__cxa_demangle(mangled_name, 
nullptr, 
nullptr, &status);
 
   80    if ( 
nullptr == real_name ) {
 
   81        return std::string(mangled_name); 
 
   84        if( 0 != status || 0 == ::strlen(real_name) ) {
 
   85            res = std::string(mangled_name);    
 
   87            res = std::string(real_name);
 
 
  109    if( 0 != ( res = unw_getcontext(&uc) ) ) {
 
  113    if( 0 != ( res = unw_init_local(&cursor, &uc) ) ) {
 
  117    bool last_frame_anon = 
false;
 
  118    while( unw_step(&cursor) > 0 && ( 0 > max_frames || ( max_frames + skip_frames ) > ( frame + 1 ) ) ) {
 
  120        if( skip_frames > frame ) {
 
  124        snprintf(cstr, 
sizeof(cstr), 
"%3zd: ", (ssize_t)frame);
 
  125        std::string line(cstr);
 
  127        if( 0 != ( res = unw_get_reg(&cursor, UNW_REG_IP, &ip) ) ) { 
 
  128            INFO_PRINT(
"unw_get_reg(IP): frame %zd, ERR %d\n", frame, res);
 
  131        if( 0 != ( res = unw_get_reg(&cursor, UNW_REG_SP, &sp) ) ) { 
 
  132            INFO_PRINT(
"unw_get_reg(SP): frame %zd, ERR %d\n", frame, res);
 
  135        if( 0 == unw_get_proc_name(&cursor, cstr, 
sizeof(cstr), &offset) ) {
 
  138            cstr[
sizeof(cstr) -1] = 0; 
 
  139            if ( (real_name = abi::__cxa_demangle(cstr, 
nullptr, 
nullptr, &status)) == 
nullptr ) {
 
  142                line.append(real_name);
 
  145            snprintf(cstr, 
sizeof(cstr), 
" + 0x%lx @ ip %p, sp %p", (
unsigned long)offset, (
void*)ip, (
void*)sp); 
 
  147            last_frame_anon = 
false;
 
  150            snprintf(cstr, 
sizeof(cstr), 
"__no_proc_name__ @ ip %p, sp %p", (
void*)ip, (
void*)sp); 
 
  151            append_line = !skip_anon_frames || !last_frame_anon;
 
  152            last_frame_anon = 
true;
 
  161    (void)skip_anon_frames;
 
  164    out.append(
"0: backtrace disabled\n");
 
 
  169#if defined(__GNUC__) && ! defined(__clang__) 
  170    #pragma GCC pop_options 
  174    fprintf(stderr, 
"%s", 
get_backtrace(skip_anon_frames, max_frames, skip_frames).c_str());
 
 
  180    fprintf(stderr, 
"%s\n", s);
 
 
  187    va_start (args, format);
 
  188    vfprintf(stderr, format, args); 
 
  190    fprintf(stderr, 
"\n");
 
 
  197    va_start (args, format);
 
  198    vfprintf(stderr, format, args); 
 
  200    fprintf(stderr, 
"\n");
 
 
  207    va_start (args, format);
 
  208    vfprintf(stderr, format, args); 
 
  210    fprintf(stderr, 
"; last errno %d %s\n", errno, strerror(errno));
 
 
  216void jau::ERR_PRINTv(
const char *
func, 
const char *file, 
const int line, 
const char * format, va_list args) 
noexcept {
 
  218    vfprintf(stderr, format, args);
 
  219    fprintf(stderr, 
"; last errno %d %s\n", errno, strerror(errno));
 
 
  227    va_start (args, format);
 
  228    vfprintf(stderr, format, args); 
 
  230    fprintf(stderr, 
"; last errno %d %s\n", errno, strerror(errno));
 
 
  237void jau::WARN_PRINTv(
const char *
func, 
const char *file, 
const int line, 
const char * format, va_list args) 
noexcept {
 
  239    vfprintf(stderr, format, args);
 
  240    fprintf(stderr, 
"\n");
 
 
  247    va_start (args, format);
 
  248    vfprintf(stderr, format, args); 
 
  250    fprintf(stderr, 
"\n");
 
 
  257    va_start (args, format);
 
  258    vfprintf(stderr, format, args); 
 
  260    fprintf(stderr, 
"\n");
 
 
  269    va_start (args, format);
 
  270    vfprintf(stderr, format, args); 
 
  272    fprintf(stderr, 
"\n");
 
 
  276int jau::fprintf_td(
const uint64_t elapsed_ms, FILE* stream, 
const char * format, ...) noexcept {
 
  277    int res = ::fprintf(stream, 
"[%s] ", 
jau::to_decstring(elapsed_ms, 
',', 9).c_str());
 
  279    va_start (args, format);
 
  280    res += ::vfprintf(stream, format, args); 
 
 
  287    va_start (args, format);
 
  288    res += ::vfprintf(stream, format, args); 
 
 
  296    va_start (args, format);
 
  297    vfprintf(stderr, format, args); 
 
  299    fprintf(stderr, 
"\n");
 
 
static uint64_t getElapsedMillisecond() noexcept
Returns current elapsed monotonic time in milliseconds since module startup, see startupTimeMilliseco...
 
static const std::string ctti_name_prefix_clang1
 
int jaulib_id_entryfunc()
 
static const std::string ctti_name_prefix_gcc1
On aarch64 using g++ (Debian 10.2.1-6) 10.2.1 20210110 optimization of jau::get_backtrace(....
 
static const std::string * ctti_name_prefixes[]
 
std::string demangle_name(const char *mangled_name) noexcept
Returns the demangled given mangled_name if successful, otherwise the mangled_name.
 
sint_bytes_t< sizeof(long int)> snsize_t
Natural 'ssize_t' alternative using int<XX>_t with xx = sizeof(long int)*8 as its natural sized type,...
 
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.
 
void abortImpl(const char *func, const char *file, const int line, const char *format,...) noexcept
Use for unconditional ::abort() call with given messages, prefix '[elapsed_time] ABORT @ file:line fu...
 
void wordyPrint(const char *format,...) noexcept
 
void dbgPrint1(const char *format,...) noexcept
 
void dbgPrint2(const char *s) noexcept
 
void errPrint(const char *prefix, const bool backtrace, const char *func, const char *file, const int line, const char *format,...) noexcept
 
void warnPrint(const char *func, const char *file, const int line, const char *format,...) noexcept
 
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
 
void PLAIN_PRINT(const bool printPrefix, const char *format,...) noexcept
Use for unconditional plain messages, prefix '[elapsed_time] ' if printPrefix == true.
 
void ERR_PRINTv(const char *func, const char *file, const int line, const char *format, va_list args) noexcept
Use for unconditional error messages, prefix '[elapsed_time] Error @ file:line func: '.
 
std::string get_backtrace(const bool skip_anon_frames, const jau::snsize_t max_frames=-1, const jau::snsize_t skip_frames=1) noexcept
Returns a de-mangled backtrace string separated by newline excluding this function.
 
void INFO_PRINT(const char *format,...) noexcept
Use for unconditional informal messages, prefix '[elapsed_time] Info: '.
 
int fprintf_td(const uint64_t elapsed_ms, FILE *stream, const char *format,...) noexcept
Convenient fprintf() invocation, prepending the given elapsed_ms timestamp.
 
void WARN_PRINTv(const char *func, const char *file, const int line, const char *format, va_list args) noexcept
Use for unconditional warning messages, prefix '[elapsed_time] Warning @ file:line func: '.
 
void COND_PRINT_impl(const char *format,...) noexcept
 
void print_backtrace(const bool skip_anon_frames, const jau::snsize_t max_frames=-1, const jau::snsize_t skip_frames=2) noexcept
Prints the de-mangled backtrace string separated by newline excluding this function to stderr,...