| 759 | } |
| 760 | |
| 761 | void _debugBacktrace(code_part part) |
| 762 | { |
| 763 | #if defined(WZ_OS_LINUX) && defined(__GLIBC__) |
| 764 | void *btv[20]; |
| 765 | unsigned num = backtrace(btv, sizeof(btv) / sizeof(*btv)); |
| 766 | char **btc = backtrace_symbols(btv, num); |
| 767 | unsigned i; |
| 768 | auto trim = [](const char *in, char *out) { |
| 769 | const char *begin = strchr(in, '_'); |
| 770 | if (begin) |
| 771 | { |
| 772 | const char *end = strchr(begin, '+'); |
| 773 | if (end) |
| 774 | { |
| 775 | memcpy(out, begin, end - begin); |
| 776 | out[end - begin] = '\0'; |
| 777 | } |
| 778 | } |
| 779 | }; |
| 780 | for (i = 1; i + 2 < num; ++i) |
| 781 | { |
| 782 | int status = -1; |
| 783 | char buf[1024]; |
| 784 | const char *p = btc[i]; |
| 785 | trim(p, buf); |
| 786 | char *readableName = abi::__cxa_demangle(buf, NULL, NULL, &status); |
| 787 | if (status == 0) |
| 788 | { |
| 789 | _debug(0, part, "BT", "%s", readableName); |
| 790 | } |
| 791 | else |
| 792 | { |
| 793 | _debug(0, part, "BT", "%s [status: %i]", btc[i], status); |
| 794 | } |
| 795 | } |
| 796 | free(btc); |
| 797 | #else |
| 798 | // debugBacktrace not implemented. |
| 799 | #endif |
| 800 | } |
| 801 | |
| 802 | bool debugPartEnabled(code_part codePart) |
| 803 | { |