| 558 | } |
| 559 | |
| 560 | void _syncDebugBacktrace(const char* function) |
| 561 | { |
| 562 | #ifdef WZ_CC_MSVC |
| 563 | char const* f = function; while (*f != '\0') if (*f++ == ':') |
| 564 | { |
| 565 | function = f; // Strip "Class::" from "Class::myFunction". |
| 566 | } |
| 567 | #endif |
| 568 | |
| 569 | uint32_t backupCrc = syncDebugLog[syncDebugNext].getCrc(); // Ignore CRC changes from _syncDebug(), since identical backtraces can be printed differently. |
| 570 | |
| 571 | #if defined(WZ_OS_LINUX) && defined(__GLIBC__) |
| 572 | void* btv[20]; |
| 573 | unsigned num = backtrace(btv, sizeof(btv) / sizeof(*btv)); |
| 574 | char** btc = backtrace_symbols(btv, num); |
| 575 | unsigned i; |
| 576 | for (i = 1; i + 2 < num; ++i) // =1: Don't print "src/warzone2100(syncDebugBacktrace+0x16) [0x6312d1]". +2: Don't print last two lines of backtrace such as "/lib/libc.so.6(__libc_start_main+0xe6) [0x7f91e040ea26]", since the address varies (even with the same binary). |
| 577 | { |
| 578 | _syncDebug("BT", "%s", btc[i]); |
| 579 | } |
| 580 | free(btc); |
| 581 | #else |
| 582 | _syncDebug("BT", "Sorry, syncDebugBacktrace() not implemented on your system. Called from %s.", function); |
| 583 | #endif |
| 584 | |
| 585 | // Use CRC of something platform-independent, to avoid false positive desynchs. |
| 586 | backupCrc = ~wz::crc_update(~backupCrc, function, strlen(function) + 1); |
| 587 | syncDebugLog[syncDebugNext].setCrc(backupCrc); |
| 588 | } |
| 589 | |
| 590 | uint32_t syncDebugGetCrc() |
| 591 | { |
nothing calls this directly
no test coverage detected