30 #define UNW_LOCAL_ONLY
31 #include <libunwind.h>
50 unw_init_local(&cursor, &uc);
51 bool last_frame_anon =
false;
52 while( unw_step(&cursor) > 0 && ( max_frames - skip_frames ) > frame ) {
54 if( skip_frames > frame ) {
58 snprintf(cstr,
sizeof(cstr),
"%3zu: ", (
size_t)frame);
59 std::string line(cstr);
61 unw_get_reg(&cursor, UNW_REG_IP, &ip);
62 unw_get_reg(&cursor, UNW_REG_SP, &sp);
63 if( 0 == ( res = unw_get_proc_name(&cursor, cstr,
sizeof(cstr), &offset) ) ) {
66 cstr[
sizeof(cstr) -1] = 0;
67 if ( (real_name = abi::__cxa_demangle(cstr,
nullptr,
nullptr, &status)) == nullptr ) {
70 line.append(real_name);
73 snprintf(cstr,
sizeof(cstr),
" + 0x%lx @ ip %p, sp %p", (
unsigned long)offset, (
void*)ip, (
void*)sp);
75 last_frame_anon =
false;
78 snprintf(cstr,
sizeof(cstr),
"__no_proc_name__ @ ip %p, sp %p", (
void*)ip, (
void*)sp);
79 append_line = !skip_anon_frames || !last_frame_anon;
80 last_frame_anon =
true;
92 fprintf(stderr,
"%s",
get_backtrace(skip_anon_frames, max_frames, skip_frames).c_str());
99 va_start (args, format);
100 vfprintf(stderr, format, args);
102 fprintf(stderr,
"\n");
109 va_start (args, format);
110 vfprintf(stderr, format, args);
112 fprintf(stderr,
"\n");
116 void jau::ABORT_impl(
const char *func,
const char *file,
const int line,
const char * format, ...) noexcept {
119 va_start (args, format);
120 vfprintf(stderr, format, args);
122 fprintf(stderr,
"; last errno %d %s\n", errno, strerror(errno));
128 void jau::ERR_PRINTv(
const char *func,
const char *file,
const int line,
const char * format, va_list args) noexcept {
130 vfprintf(stderr, format, args);
131 fprintf(stderr,
"; last errno %d %s\n", errno, strerror(errno));
136 void jau::ERR_PRINT_impl(
const char *prefix,
const bool backtrace,
const char *func,
const char *file,
const int line,
const char * format, ...) noexcept {
139 va_start (args, format);
140 vfprintf(stderr, format, args);
142 fprintf(stderr,
"; last errno %d %s\n", errno, strerror(errno));
149 void jau::WARN_PRINTv(
const char *func,
const char *file,
const int line,
const char * format, va_list args) noexcept {
151 vfprintf(stderr, format, args);
152 fprintf(stderr,
"\n");
156 void jau::WARN_PRINT_impl(
const char *func,
const char *file,
const int line,
const char * format, ...) noexcept {
159 va_start (args, format);
160 vfprintf(stderr, format, args);
162 fprintf(stderr,
"\n");
169 va_start (args, format);
170 vfprintf(stderr, format, args);
172 fprintf(stderr,
"\n");
181 va_start (args, format);
182 vfprintf(stderr, format, args);
184 fprintf(stderr,
"\n");
191 va_start (args, format);
192 res += ::vfprintf(stream, format, args);
200 va_start (args, format);
201 vfprintf(stderr, format, args);
203 fprintf(stderr,
"\n");