@@ -27,6 +27,7 @@ static std::vector<ExceptionRange> ignoredExceptionRange;
27
27
static std::map<unsigned int , const char *> exceptionNames;
28
28
static SIZE_T cachePrivateUsage = 0 ;
29
29
static HANDLE hEvent = 0 ;
30
+ static String lastDebugText;
30
31
31
32
// Superglobal variables
32
33
char szFileName[MAX_PATH] = " " ;
@@ -957,6 +958,7 @@ static void cbUnloadDll(UNLOAD_DLL_DEBUG_INFO* UnloadDll)
957
958
958
959
static void cbOutputDebugString (OUTPUT_DEBUG_STRING_INFO* DebugString)
959
960
{
961
+
960
962
hActiveThread = threadgethandle (((DEBUG_EVENT*)GetDebugData ())->dwThreadId );
961
963
PLUG_CB_OUTPUTDEBUGSTRING callbackInfo;
962
964
callbackInfo.DebugString = DebugString;
@@ -967,46 +969,15 @@ static void cbOutputDebugString(OUTPUT_DEBUG_STRING_INFO* DebugString)
967
969
Memory<char *> DebugText (DebugString->nDebugStringLength + 1 , " cbOutputDebugString:DebugText" );
968
970
if (memread (fdProcessInfo->hProcess , DebugString->lpDebugStringData , DebugText, DebugString->nDebugStringLength , 0 ))
969
971
{
970
- int len = (int )strlen (DebugText);
971
- int escape_count = 0 ;
972
- for (int i = 0 ; i < len; i++)
973
- if (DebugText[i] == ' \\ ' or DebugText[i] == ' \" ' or !isprint (DebugText[i]))
974
- escape_count++;
975
- Memory<char *> DebugTextEscaped (len + escape_count * 3 + 1 , " cbOutputDebugString:DebugTextEscaped" );
976
- for (int i = 0 , j = 0 ; i < len; i++)
972
+ String str = String (DebugText);
973
+ if (str != lastDebugText) // fix for every string being printed twice
977
974
{
978
- switch (DebugText[i])
979
- {
980
- case ' \t ' :
981
- j += sprintf (DebugTextEscaped + j, " \\ t" );
982
- break ;
983
- case ' \f ' :
984
- j += sprintf (DebugTextEscaped + j, " \\ f" );
985
- break ;
986
- case ' \v ' :
987
- j += sprintf (DebugTextEscaped + j, " \\ v" );
988
- break ;
989
- case ' \n ' :
990
- j += sprintf (DebugTextEscaped + j, " \\ n" );
991
- break ;
992
- case ' \r ' :
993
- j += sprintf (DebugTextEscaped + j, " \\ r" );
994
- break ;
995
- case ' \\ ' :
996
- j += sprintf (DebugTextEscaped + j, " \\\\ " );
997
- break ;
998
- case ' \" ' :
999
- j += sprintf (DebugTextEscaped + j, " \\\" " );
1000
- break ;
1001
- default :
1002
- if (!isprint (DebugText[i])) // unknown unprintable character
1003
- j += sprintf (DebugTextEscaped + j, " \\ %.2x" , DebugText[i]);
1004
- else
1005
- j += sprintf (DebugTextEscaped + j, " %c" , DebugText[i]);
1006
- break ;
1007
- }
975
+ if (str != " \n " )
976
+ dprintf (" DebugString: \" %s\"\n " , StringUtils::Escape (str).c_str ());
977
+ lastDebugText = str;
1008
978
}
1009
- dprintf (" DebugString: \" %s\"\n " , DebugTextEscaped ());
979
+ else
980
+ lastDebugText = " " ;
1010
981
}
1011
982
}
1012
983
@@ -1078,47 +1049,9 @@ static void cbException(EXCEPTION_DEBUG_INFO* ExceptionData)
1078
1049
Memory<char *> ThreadName (MAX_THREAD_NAME_SIZE, " cbException:ThreadName" );
1079
1050
if (memread (fdProcessInfo->hProcess , nameInfo.szName , ThreadName, MAX_THREAD_NAME_SIZE - 1 , 0 ))
1080
1051
{
1081
- int len = (int )strlen (ThreadName);
1082
- int escape_count = 0 ;
1083
- for (int i = 0 ; i < len; i++)
1084
- if (ThreadName[i] == ' \\ ' or ThreadName[i] == ' \" ' or !isprint (ThreadName[i]))
1085
- escape_count++;
1086
- Memory<char *> ThreadNameEscaped (len + escape_count * 3 + 1 , " cbException:ThreadNameEscaped" );
1087
- for (int i = 0 , j = 0 ; i < len; i++)
1088
- {
1089
- switch (ThreadName[i])
1090
- {
1091
- case ' \t ' :
1092
- j += sprintf (ThreadNameEscaped + j, " \\ t" );
1093
- break ;
1094
- case ' \f ' :
1095
- j += sprintf (ThreadNameEscaped + j, " \\ f" );
1096
- break ;
1097
- case ' \v ' :
1098
- j += sprintf (ThreadNameEscaped + j, " \\ v" );
1099
- break ;
1100
- case ' \n ' :
1101
- j += sprintf (ThreadNameEscaped + j, " \\ n" );
1102
- break ;
1103
- case ' \r ' :
1104
- j += sprintf (ThreadNameEscaped + j, " \\ r" );
1105
- break ;
1106
- case ' \\ ' :
1107
- j += sprintf (ThreadNameEscaped + j, " \\\\ " );
1108
- break ;
1109
- case ' \" ' :
1110
- j += sprintf (ThreadNameEscaped + j, " \\\" " );
1111
- break ;
1112
- default :
1113
- if (!isprint (ThreadName[i])) // unknown unprintable character
1114
- j += sprintf (ThreadNameEscaped + j, " \\ %.2x" , ThreadName[i]);
1115
- else
1116
- j += sprintf (ThreadNameEscaped + j, " %c" , ThreadName[i]);
1117
- break ;
1118
- }
1119
- }
1120
- dprintf (" SetThreadName(%X, \" %s\" )\n " , nameInfo.dwThreadID , ThreadNameEscaped ());
1121
- threadsetname (nameInfo.dwThreadID , ThreadNameEscaped);
1052
+ String ThreadNameEscaped = StringUtils::Escape (ThreadName);
1053
+ dprintf (" SetThreadName(%X, \" %s\" )\n " , nameInfo.dwThreadID , ThreadNameEscaped.c_str ());
1054
+ threadsetname (nameInfo.dwThreadID , ThreadNameEscaped.c_str ());
1122
1055
}
1123
1056
}
1124
1057
}
0 commit comments