1010#include < Windows.h>
1111#include < DbgHelp.h>
1212
13- // stati volatile long s_debugLineCount;
13+ // static volatile long s_debugLineCount;
1414
1515
1616
1717volatile long *allocateLineCount ()
1818{
19- static volatile long *lineCount;
19+ static volatile long *lineCount;
2020
21- lineCount = (long *)_aligned_malloc (sizeof (long ), 32 );
22- *lineCount = 0 ;
23- return lineCount;
21+ lineCount = (long *)_aligned_malloc (sizeof (long ), 32 );
22+ *lineCount = 0 ;
23+ return lineCount;
2424}
2525
2626void printStack ()
2727{
28- unsigned int i;
29- void * stack[ 100 ];
30- unsigned short frames;
31- SYMBOL_INFO * symbol;
32- HANDLE process;
33- char buffer[500 ]{};
34- int bufferRemaining = 500 ;
35- int usedBuffer;
36- char *output = buffer;
37-
38- process = GetCurrentProcess ();
39-
40- SymInitialize ( process, NULL , TRUE );
41-
42- frames = CaptureStackBackTrace ( 1 , 15 , stack, NULL );
43- symbol = ( SYMBOL_INFO * )calloc ( sizeof ( SYMBOL_INFO ) + 256 * sizeof ( char ), 1 );
44- symbol->MaxNameLen = 255 ;
45- symbol->SizeOfStruct = sizeof ( SYMBOL_INFO );
46-
47-
48- for ( i = 0 ; i < frames; i++ )
49- {
50- SymFromAddr ( process, ( DWORD64 )( stack[ i ] ), 0 , symbol );
51-
52- usedBuffer = _snprintf_s (output, bufferRemaining, bufferRemaining, " %i: %s - 0x%I64X\n " , frames - i - 1 , symbol->Name , symbol->Address );
53- bufferRemaining -= usedBuffer;
54- output += usedBuffer;
55- }
56-
57- debugTraceVars (" STACK %s" , buffer);
58-
59- free ( symbol );
28+ unsigned int i;
29+ void * stack[ 100 ];
30+ unsigned short frames;
31+ SYMBOL_INFO * symbol;
32+ HANDLE process;
33+ char buffer[500 ]{};
34+ int bufferRemaining = 500 ;
35+ int usedBuffer;
36+ char *output = buffer;
37+
38+ process = GetCurrentProcess ();
39+
40+ SymInitialize ( process, NULL , TRUE );
41+
42+ frames = CaptureStackBackTrace ( 1 , 15 , stack, NULL );
43+ symbol = ( SYMBOL_INFO * )calloc ( sizeof ( SYMBOL_INFO ) + 256 * sizeof ( char ), 1 );
44+ symbol->MaxNameLen = 255 ;
45+ symbol->SizeOfStruct = sizeof ( SYMBOL_INFO );
46+
47+
48+ for ( i = 0 ; i < frames; i++ )
49+ {
50+ SymFromAddr ( process, ( DWORD64 )( stack[ i ] ), 0 , symbol );
51+
52+ usedBuffer = _snprintf_s (output, bufferRemaining, bufferRemaining, " %i: %s - 0x%I64X\n " , frames - i - 1 , symbol->Name , symbol->Address );
53+ bufferRemaining -= usedBuffer;
54+ output += usedBuffer;
55+ }
56+
57+ debugTraceVars (" STACK %s" , buffer);
58+
59+ free ( symbol );
6060}
6161
6262void debugTraceStr (const std::wstringstream& item)
6363{
64- static volatile long *lineCount = allocateLineCount ();
65- FILETIME timestamp;
66- GetSystemTimeAsFileTime (×tamp);
64+ static volatile long *lineCount = allocateLineCount ();
65+ FILETIME timestamp;
66+ GetSystemTimeAsFileTime (×tamp);
6767
68-
69- long currentLine = InterlockedIncrement (lineCount);
70- std::wstringstream debug;
68+
69+ long currentLine = InterlockedIncrement (lineCount);
70+ std::wstringstream debug;
7171 debug << L" PY>" << std::setfill (L' 0' ) << std::setw (5 ) << ::GetCurrentThreadId ()
72- << L" " << std::setw (5 ) << std::setfill (L' ' ) << currentLine
72+ << L" " << std::setw (5 ) << std::setfill (L' ' ) << currentLine
7373 << L" " << std::setw (8 ) << std::setfill (L' ' ) << timestamp.dwLowDateTime
7474 << L" " << item.str ();
7575
@@ -78,13 +78,13 @@ void debugTraceStr(const std::wstringstream& item)
7878
7979void debugTraceVars (const char *format, ...)
8080{
81- va_list args;
82- va_start ( args, format );
83- char buffer[500 ];
84- vsprintf_s<500 >(buffer, format, args);
85- std::wstringstream result;
81+ va_list args;
82+ va_start ( args, format );
83+ char buffer[500 ];
84+ vsprintf_s<500 >(buffer, format, args);
85+ std::wstringstream result;
8686 result << buffer;
87- debugTraceStr (result);
87+ debugTraceStr (result);
8888}
8989
9090
0 commit comments