Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/plugin/PluginDebug.cpp

Issue 5137721374801920: Issue #1173 - Default behavior for catch-all blocks
Patch Set: rebase Created March 3, 2015, 8:06 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/plugin/PluginDebug.h ('k') | src/plugin/PluginDebugMacros.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/plugin/PluginDebug.cpp
===================================================================
--- a/src/plugin/PluginDebug.cpp
+++ b/src/plugin/PluginDebug.cpp
@@ -16,11 +16,52 @@
*/
#include "PluginStdAfx.h"
-
#include "PluginDebug.h"
+#include "Exception.h"
#include "PluginMutex.h"
#include "PluginSettings.h"
+#if (defined ENABLE_DEBUG_INFO)
+struct EntryPointHandlers
+{
+ static void Unknown(std::string name)
+ {
+ CPluginDebug::Debug("Unknown exception in catch-all for entry point " + name);
+ }
+ static void Exception(std::exception& ex, std::string name)
+ {
+ CPluginDebug::DebugOrdinaryException(ex,
+ PLUGIN_ERROR_ENTRY_POINT, PLUGIN_ERROR_ENTRY_POINT_CATCHALL_EXCEPTION,
+ "std::exception in catch-all for entry point " + name);
+ }
+ static void LogicError(std::logic_error& ex, std::string name)
+ {
+ CPluginDebug::DebugOrdinaryException(ex,
+ PLUGIN_ERROR_ENTRY_POINT, PLUGIN_ERROR_ENTRY_POINT_CATCHALL_EXCEPTION,
+ "std::logic_error in catch-all for entry point " + name);
+ }
+ static void RuntimeError(std::runtime_error& ex, std::string name)
+ {
+ CPluginDebug::DebugOrdinaryException(ex,
+ PLUGIN_ERROR_ENTRY_POINT, PLUGIN_ERROR_ENTRY_POINT_CATCHALL_EXCEPTION,
+ "std::runtime_error in catch-all for entry point " + name);
+ }
+ static void SystemError(std::system_error& ex, std::string name)
+ {
+ CPluginDebug::DebugSystemException(ex,
+ PLUGIN_ERROR_ENTRY_POINT, PLUGIN_ERROR_ENTRY_POINT_CATCHALL_EXCEPTION,
+ "std::system_error in catch-all for entry point " + name);
+ }
+};
+#endif
+
+void EntryPointExceptionDefault(std::string name)
+{
+#if (defined ENABLE_DEBUG_INFO)
+ CatchAllVoid<EntryPointHandlers>::Handler(name);
+#endif
+}
+
class CPluginDebugLock : public CPluginMutex
{
@@ -44,10 +85,23 @@
CComAutoCriticalSection CPluginDebugLock::s_criticalSectionDebugLock;
+void CPluginDebug::DebugSystemException(const std::system_error& ex, int errorId, int errorSubid, const std::string& description)
+{
+ std::string message = description + ", " + ex.code().message() + ", " + ex.what();
+ DEBUG_ERROR_LOG(ex.code().value(), errorId, errorSubid, message);
+}
+
+void CPluginDebug::DebugOrdinaryException(const std::exception& ex, int errorId, int errorSubid, const std::string& description)
+{
+ std::string message = description + ", " + ex.what();
+ DEBUG_ERROR_LOG(0, errorId, errorSubid, message);
+}
+
+
#ifdef ENABLE_DEBUG_INFO
-void CPluginDebug::Debug(const CString& text, DWORD dwProcessId, DWORD dwThreadId)
+void DebugLegacy(const CString& text, DWORD dwProcessId, DWORD dwThreadId)
{
#ifdef USE_CONSOLE
CONSOLE("%s", CT2A(text.GetString(), CP_UTF8));
@@ -116,30 +170,23 @@
}
}
-void CPluginDebug::DebugClear()
+void CPluginDebug::Debug(const std::string& text, DWORD processId, DWORD threadId)
{
- CPluginDebugLock lock;
- if (lock.IsLocked())
- {
- DeleteFileW(GetDataPath(L"debug.txt").c_str());
- DeleteFileW(GetDataPath(L"debug_main_ui.txt").c_str());
- DeleteFileW(GetDataPath(L"debug_main_thread.txt").c_str());
+ DebugLegacy(CString(text.c_str()), processId, threadId);
+}
- for (int i = 1; i <= 10; i++)
- {
- std::wstring x = std::to_wstring(i);
- DeleteFileW(GetDataPath(L"debug_tab" + x + L"_ui.txt").c_str());
- DeleteFileW(GetDataPath(L"debug_tab" + x + L"_thread.txt").c_str());
- }
- }
+void CPluginDebug::Debug(const std::wstring& text, DWORD processId, DWORD threadId)
+{
+ DebugLegacy(ToCString(text), processId, threadId);
}
#endif
-#if (defined ENABLE_DEBUG_INFO || defined ENABLE_DEBUG_SELFTEST)
+#if (defined ENABLE_DEBUG_INFO)
-void CPluginDebug::DebugError(const CString& error)
+void CPluginDebug::DebugException(const std::exception& ex)
{
+ auto error = std::string("!!! Exception:") + ex.what();
#ifdef ENABLE_DEBUG_ERROR
Debug(error);
#endif
@@ -147,7 +194,7 @@
DEBUG_SELFTEST("********************************************************************************\n" + error + "\n********************************************************************************")
}
-void CPluginDebug::DebugErrorCode(DWORD errorCode, const CString& error, DWORD dwProcessId, DWORD dwThreadId)
+void DebugErrorCodeLegacy(DWORD errorCode, const CString& error, DWORD dwProcessId, DWORD dwThreadId)
{
CString errorCodeText;
errorCodeText.Format(L"%u (0x%8.8x)", errorCode, errorCode);
@@ -155,10 +202,15 @@
CString finalError = error + L". error=" + errorCodeText;
#ifdef ENABLE_DEBUG_ERROR
- Debug(finalError, dwProcessId, dwThreadId);
+ DebugLegacy(finalError, dwProcessId, dwThreadId);
#endif
- DEBUG_SELFTEST(L"********************************************************************************\n" + finalError + "\n********************************************************************************")
+ DEBUG_SELFTEST(L"********************************************************************************\n" + finalError + "\ n********************************************************************************")
+}
+
+void CPluginDebug::DebugErrorCode(DWORD errorCode, const std::string& error, DWORD processId, DWORD threadId)
+{
+ DebugErrorCodeLegacy(errorCode, CString(error.c_str()), processId, threadId);
}
#endif
@@ -169,7 +221,7 @@
#ifdef ENABLE_DEBUG_RESULT
-void CPluginDebug::DebugResult(const CString& text)
+void DebugResultLegacy(const CString& text)
{
SYSTEMTIME st;
::GetSystemTime(&st);
@@ -192,7 +244,12 @@
}
}
-void CPluginDebug::DebugResultDomain(const CString& domain)
+void CPluginDebug::DebugResult(const std::wstring& text)
+{
+ DebugResultLegacy(ToCString(text));
+}
+
+void CPluginDebug::DebugResultDomain(const std::wstring& domain)
{
DebugResult(L"===========================================================================================================================================================================================");
DebugResult(domain);
@@ -200,7 +257,7 @@
}
-void CPluginDebug::DebugResultBlocking(const CString& type, const std::wstring& src, const std::wstring& domain)
+void CPluginDebug::DebugResultBlocking(const std::wstring& type, const std::wstring& src, const std::wstring& domain)
{
CString srcTrunc = ToCString(src);
if (src.length() > 100)
@@ -209,34 +266,24 @@
}
CString blocking;
- blocking.Format(L"Blocked %-12s %-20s %s", type, domain.empty()? L"-" : ToCString(domain), srcTrunc);
+ blocking.Format(L"Blocked %-12s %-20s %s", ToCString(type), domain.empty()? L"-" : ToCString(domain), srcTrunc);
- DebugResult(blocking);
+ DebugResultLegacy(blocking);
}
-void CPluginDebug::DebugResultHiding(const CString& tag, const CString& id, const CString& filter)
+void CPluginDebug::DebugResultHiding(const std::wstring& tag, const std::wstring& id, const std::wstring& filter)
{
- CString srcTrunc = id;
+ CString srcTrunc = ToCString(id);
if (srcTrunc.GetLength() > 100)
{
srcTrunc = srcTrunc.Left(67) + L"..." + srcTrunc.Right(30);
}
CString blocking;
- blocking.Format(L"Hidden %-12s - %s %s", tag, srcTrunc, filter);
+ blocking.Format(L"Hidden %-12s - %s %s", ToCString(tag), srcTrunc, ToCString(filter));
- DebugResult(blocking);
-}
-
-
-void CPluginDebug::DebugResultClear()
-{
- CPluginDebugLock lock;
- if (lock.IsLocked())
- {
- DeleteFileW(GetDataPath(L"debug_result.txt").c_str());
- }
+ DebugResultLegacy(blocking);
}
#endif // ENABLE_DEBUG_RESULT
@@ -244,7 +291,7 @@
#ifdef ENABLE_DEBUG_RESULT_IGNORED
-void CPluginDebug::DebugResultIgnoring(const CString& type, const std::wstring& src, const std::wstring& domain)
+void CPluginDebug::DebugResultIgnoring(const std::wstring& type, const std::wstring& src, const std::wstring& domain)
{
CString srcTrunc = ToCString(src);
if (src.length() > 100)
@@ -253,9 +300,9 @@
}
CString blocking;
- blocking.Format(L"Ignored %-12s %s %s", type, domain.empty()? L"-" : ToCString(domain), srcTrunc);
+ blocking.Format(L"Ignored %-12s %s %s", ToCString(type), domain.empty()? L"-" : ToCString(domain), srcTrunc);
- DebugResult(blocking);
+ DebugResultLegacy(blocking);
}
#endif // ENABLE_DEBUG_RESULT_IGNORED
« no previous file with comments | « src/plugin/PluginDebug.h ('k') | src/plugin/PluginDebugMacros.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld