浏览代码

LastInternalException counter

Source commit: 67dab5dfd530e28530afce52831d473bb9c52a69
Martin Prikryl 9 年之前
父节点
当前提交
a4ec2a56dd
共有 3 个文件被更改,包括 36 次插入0 次删除
  1. 3 0
      source/core/Exceptions.cpp
  2. 1 0
      source/core/Interface.h
  3. 32 0
      source/windows/WinInterface.cpp

+ 3 - 0
source/core/Exceptions.cpp

@@ -163,6 +163,9 @@ static bool __fastcall ExceptionMessage(Exception * E, bool Count,
   if (Count && (CounterName != NULL) && (Configuration->Usage != NULL))
   {
     Configuration->Usage->Inc(CounterName);
+    UnicodeString ExceptionDebugInfo =
+      E->ClassName() + L":" + GetExceptionDebugInfo();
+    Configuration->Usage->Set(L"LastInternalException", ExceptionDebugInfo);
   }
 
   return Result;

+ 1 - 0
source/core/Interface.h

@@ -34,6 +34,7 @@ TOptions * __fastcall GetGlobalOptions();
 void __fastcall ShowExtendedException(Exception * E);
 bool __fastcall AppendExceptionStackTraceAndForget(TStrings *& MoreMessages);
 void __fastcall IgnoreException(const std::type_info & ExceptionType);
+UnicodeString __fastcall GetExceptionDebugInfo();
 
 UnicodeString __fastcall GetCompanyRegistryKey();
 UnicodeString __fastcall GetRegistryKey();

+ 32 - 0
source/windows/WinInterface.cpp

@@ -571,6 +571,38 @@ static std::unique_ptr<TCriticalSection> StackTraceCriticalSection(new TCritical
 typedef std::map<DWORD, TStrings *> TStackTraceMap;
 static TStackTraceMap StackTraceMap;
 //---------------------------------------------------------------------------
+UnicodeString __fastcall GetExceptionDebugInfo()
+{
+  UnicodeString Result;
+  TGuard Guard(StackTraceCriticalSection.get());
+  TStackTraceMap::iterator Iterator = StackTraceMap.find(GetCurrentThreadId());
+  if (Iterator != StackTraceMap.end())
+  {
+    TStrings * StackTrace = Iterator->second;
+    for (int Index = 0; Index < StackTrace->Count; Index++)
+    {
+      UnicodeString Frame = StackTrace->Strings[Index];
+      int P = Frame.Pos(L")");
+      if (DebugAlwaysTrue(P > 0))
+      {
+        UnicodeString Symbol = Frame.SubString(P + 1, Frame.Length() - P).Trim();
+
+        if ((Symbol != L"KERNELBASE.dll.RaiseException") &&
+            (Symbol != L"Jclhookexcept::JclAddExceptNotifier") &&
+            (Symbol != L"_ReThrowException") &&
+            (Symbol != L"____ExceptionHandler") &&
+            (Symbol != L"__ExceptionHandler") &&
+            (Symbol != L"___doGlobalUnwind") &&
+            (Symbol != L"_ThrowExceptionLDTC"))
+        {
+          AddToList(Result, Symbol, L";");
+        }
+      }
+    }
+  }
+  return Result;
+}
+//---------------------------------------------------------------------------
 bool __fastcall AppendExceptionStackTraceAndForget(TStrings *& MoreMessages)
 {
   bool Result = false;