MCPcopy Create free account
hub / github.com/Warzone2100/warzone2100 / _debug

Function _debug

lib/framework/debug.cpp:644–759  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

642}
643
644void _debug(int line, code_part part, const char *function, const char *str, ...)
645{
646 char outputBuffer[MAX_LEN_LOG_LINE];
647 thread_local std::array<std::vector<char>, 2> inputBuffer = {std::vector<char>(MAX_LEN_LOG_LINE, 0), std::vector<char>(MAX_LEN_LOG_LINE, 0)};
648 thread_local unsigned int repeated = 0; /* times current message repeated */
649 thread_local unsigned int next = 2; /* next total to print update */
650 thread_local unsigned int prev = 0; /* total on last update */
651
652 va_list ap;
653 va_start(ap, str);
654 vssprintf(outputBuffer, str, ap);
655 va_end(ap);
656
657 if (part == LOG_WARNING)
658 {
659 bool addedNew = false;
660 {
661 std::lock_guard<std::mutex> guard(warning_list_mutex);
662 addedNew = warning_list.insert(std::pair<std::string, int>(std::string(function) + "-" + std::string(outputBuffer), line)).second;
663 }
664 if (addedNew)
665 {
666 auto& currInputBuffer = inputBuffer[useInputBuffer1 ? 1 : 0];
667 snprintf(currInputBuffer.data(), currInputBuffer.size(), "[%s:%d] %s (**Further warnings of this type are suppressed.)", function, line, outputBuffer);
668 }
669 else
670 {
671 return; // don't bother adding any more
672 }
673 }
674 else
675 {
676 auto& currInputBuffer = inputBuffer[useInputBuffer1 ? 1 : 0];
677 snprintf(currInputBuffer.data(), currInputBuffer.size(), "[%s:%d] %s", function, line, outputBuffer);
678 }
679
680 if (strncmp(inputBuffer[0].data(), inputBuffer[1].data(), std::min(inputBuffer[0].size(), inputBuffer[1].size())) == 0)
681 {
682 // Received again the same line
683 repeated++;
684 if (repeated == next)
685 {
686 if (repeated > 2)
687 {
688 ssprintf(outputBuffer, "last message repeated %u times (total %u repeats)", repeated - prev, repeated);
689 }
690 else
691 {
692 ssprintf(outputBuffer, "last message repeated %u times", repeated - prev);
693 }
694 printToDebugCallbacks(outputBuffer, part);
695 prev = repeated;
696 next *= 2;
697 }
698 }
699 else
700 {
701 // Received another line, cleanup the old

Callers 7

_debugBacktraceFunction · 0.85
_debug_multilineFunction · 0.85
_wzGLCheckErrorsFunction · 0.85
_MiniupnpcLogCallbackFunction · 0.85
PlumLogCallbackFunction · 0.85
printLogMethod · 0.85
printLogMethod · 0.85

Calls 10

stringFunction · 0.85
printToDebugCallbacksFunction · 0.85
getLocalTimeFunction · 0.85
sstrcpyFunction · 0.85
wzDisplayDialogFunction · 0.85
vssprintfFunction · 0.70
insertMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected