| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 Eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 #include "PluginStdAfx.h" | 18 #include "PluginStdAfx.h" |
| 19 | |
| 19 #include "PluginDebug.h" | 20 #include "PluginDebug.h" |
| 20 #include "Exception.h" | 21 #include "Exception.h" |
| 21 #include "PluginMutex.h" | 22 #include "PluginMutex.h" |
| 22 #include "PluginSettings.h" | 23 #include "PluginSettings.h" |
| 23 | 24 |
| 24 #if (defined ENABLE_DEBUG_INFO) | 25 #if (defined ENABLE_DEBUG_INFO) |
| 25 struct EntryPointHandlers | 26 namespace { |
| 26 { | 27 // VS 2012 does not have support for variadic templates, which would eliminate the need for an argument class. |
| 27 static void Unknown(std::string name) | 28 struct LogHandlersArguments |
| 28 { | 29 { |
| 29 CPluginDebug::Debug("Unknown exception in catch-all for entry point " + name ); | 30 bool isEntryPoint; |
| 30 } | 31 std::string name; |
| 31 static void Exception(std::exception& ex, std::string name) | 32 }; |
| 32 { | 33 |
| 33 CPluginDebug::DebugOrdinaryException(ex, | 34 std::string DefaultLogMessage(const LogHandlersArguments& x, const std::string &exceptionType) |
| 34 PLUGIN_ERROR_ENTRY_POINT, PLUGIN_ERROR_ENTRY_POINT_CATCHALL_EXCEPTION, | 35 { |
| 35 "std::exception in catch-all for entry point " + name); | 36 std::string s = x.isEntryPoint ? "ENTRY POINT '" : "'"; |
| 36 } | 37 s += x.name; |
| 37 static void LogicError(std::logic_error& ex, std::string name) | 38 s += "' caught default "; |
| 38 { | 39 s += exceptionType; |
| 39 CPluginDebug::DebugOrdinaryException(ex, | 40 return s; |
| 40 PLUGIN_ERROR_ENTRY_POINT, PLUGIN_ERROR_ENTRY_POINT_CATCHALL_EXCEPTION, | 41 } |
| 41 "std::logic_error in catch-all for entry point " + name); | 42 |
| 42 } | 43 struct LogHandlers |
| 43 static void RuntimeError(std::runtime_error& ex, std::string name) | 44 { |
| 44 { | 45 static void Unknown(const LogHandlersArguments& args) |
| 45 CPluginDebug::DebugOrdinaryException(ex, | 46 { |
| 46 PLUGIN_ERROR_ENTRY_POINT, PLUGIN_ERROR_ENTRY_POINT_CATCHALL_EXCEPTION, | 47 CPluginDebug::Debug(DefaultLogMessage(args, "Unknown exception")); |
| 47 "std::runtime_error in catch-all for entry point " + name); | 48 } |
| 48 } | 49 static void Exception(const std::exception& ex, LogHandlersArguments& args) |
| 49 static void SystemError(std::system_error& ex, std::string name) | 50 { |
| 50 { | 51 CPluginDebug::DebugOrdinaryException(ex, |
| 51 CPluginDebug::DebugSystemException(ex, | 52 PLUGIN_ERROR_ENTRY_POINT, PLUGIN_ERROR_ENTRY_POINT_CATCHALL_EXCEPTION, |
| 52 PLUGIN_ERROR_ENTRY_POINT, PLUGIN_ERROR_ENTRY_POINT_CATCHALL_EXCEPTION, | 53 DefaultLogMessage(args, "std::exception")); |
| 53 "std::system_error in catch-all for entry point " + name); | 54 } |
| 54 } | 55 static void LogicError(const std::logic_error& ex, LogHandlersArguments& arg s) |
| 55 }; | 56 { |
| 56 #endif | 57 CPluginDebug::DebugOrdinaryException(ex, |
| 57 | 58 PLUGIN_ERROR_ENTRY_POINT, PLUGIN_ERROR_ENTRY_POINT_CATCHALL_EXCEPTION, |
| 58 void EntryPointExceptionDefault(std::string name) | 59 DefaultLogMessage(args, "std::logic_error")); |
|
Oleksandr
2015/03/05 07:18:55
I'd prefer 'DefaultExceptionHander' instead. This
Eric
2015/03/05 14:58:04
As a small point of language, there's no need to u
| |
| 60 } | |
| 61 static void RuntimeError(const std::runtime_error& ex, LogHandlersArguments& args) | |
| 62 { | |
| 63 CPluginDebug::DebugOrdinaryException(ex, | |
| 64 PLUGIN_ERROR_ENTRY_POINT, PLUGIN_ERROR_ENTRY_POINT_CATCHALL_EXCEPTION, | |
| 65 DefaultLogMessage(args, "std::runtime_error")); | |
| 66 } | |
| 67 static void SystemError(const std::system_error& ex, LogHandlersArguments& a rgs) | |
| 68 { | |
| 69 CPluginDebug::DebugSystemException(ex, | |
| 70 PLUGIN_ERROR_ENTRY_POINT, PLUGIN_ERROR_ENTRY_POINT_CATCHALL_EXCEPTION, | |
| 71 DefaultLogMessage(args, "std::std::system_error")); | |
| 72 } | |
| 73 }; | |
| 74 } | |
| 75 #endif | |
| 76 | |
| 77 void EntryPointExceptionDefault(const std::string& name) | |
| 59 { | 78 { |
| 60 #if (defined ENABLE_DEBUG_INFO) | 79 #if (defined ENABLE_DEBUG_INFO) |
| 61 CatchAllVoid<EntryPointHandlers>::Handler(name); | 80 // VS 2012 does not have support for brace initializer lists; otherwise this c ould be a single line |
| 62 #endif | 81 LogHandlersArguments x; |
| 63 } | 82 x.isEntryPoint = true; |
| 64 | 83 x.name = name; |
| 84 CatchAllVoid<LogHandlers>::Handler(x); | |
| 85 #endif | |
| 86 } | |
| 87 | |
| 88 void ExceptionDefault(const std::string& name) | |
| 89 { | |
| 90 #if (defined ENABLE_DEBUG_INFO) | |
| 91 LogHandlersArguments x; | |
| 92 x.isEntryPoint = false; | |
| 93 x.name = name; | |
| 94 CatchAllVoid<LogHandlers>::Handler(x); | |
| 95 #endif | |
| 96 } | |
| 65 | 97 |
| 66 class CPluginDebugLock : public CPluginMutex | 98 class CPluginDebugLock : public CPluginMutex |
| 67 { | 99 { |
| 68 | 100 |
| 69 private: | 101 private: |
| 70 | 102 |
| 71 static CComAutoCriticalSection s_criticalSectionDebugLock; | 103 static CComAutoCriticalSection s_criticalSectionDebugLock; |
| 72 | 104 |
| 73 public: | 105 public: |
| 74 | 106 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 89 { | 121 { |
| 90 std::string message = description + ", " + ex.code().message() + ", " + ex.wha t(); | 122 std::string message = description + ", " + ex.code().message() + ", " + ex.wha t(); |
| 91 DEBUG_ERROR_LOG(ex.code().value(), errorId, errorSubid, message); | 123 DEBUG_ERROR_LOG(ex.code().value(), errorId, errorSubid, message); |
| 92 } | 124 } |
| 93 | 125 |
| 94 void CPluginDebug::DebugOrdinaryException(const std::exception& ex, int errorId, int errorSubid, const std::string& description) | 126 void CPluginDebug::DebugOrdinaryException(const std::exception& ex, int errorId, int errorSubid, const std::string& description) |
| 95 { | 127 { |
| 96 std::string message = description + ", " + ex.what(); | 128 std::string message = description + ", " + ex.what(); |
| 97 DEBUG_ERROR_LOG(0, errorId, errorSubid, message); | 129 DEBUG_ERROR_LOG(0, errorId, errorSubid, message); |
| 98 } | 130 } |
| 99 | |
| 100 | |
| 101 | 131 |
| 102 #ifdef ENABLE_DEBUG_INFO | 132 #ifdef ENABLE_DEBUG_INFO |
| 103 | 133 |
| 104 void DebugLegacy(const CString& text, DWORD dwProcessId, DWORD dwThreadId) | 134 void DebugLegacy(const CString& text, DWORD dwProcessId, DWORD dwThreadId) |
| 105 { | 135 { |
| 106 #ifdef USE_CONSOLE | 136 #ifdef USE_CONSOLE |
| 107 CONSOLE("%s", CT2A(text.GetString(), CP_UTF8)); | 137 CONSOLE("%s", CT2A(text.GetString(), CP_UTF8)); |
| 108 #endif | 138 #endif |
| 109 | 139 |
| 110 if (CPluginSettings::HasInstance()) | 140 if (CPluginSettings::HasInstance()) |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 { | 228 { |
| 199 CString errorCodeText; | 229 CString errorCodeText; |
| 200 errorCodeText.Format(L"%u (0x%8.8x)", errorCode, errorCode); | 230 errorCodeText.Format(L"%u (0x%8.8x)", errorCode, errorCode); |
| 201 | 231 |
| 202 CString finalError = error + L". error=" + errorCodeText; | 232 CString finalError = error + L". error=" + errorCodeText; |
| 203 | 233 |
| 204 #ifdef ENABLE_DEBUG_ERROR | 234 #ifdef ENABLE_DEBUG_ERROR |
| 205 DebugLegacy(finalError, dwProcessId, dwThreadId); | 235 DebugLegacy(finalError, dwProcessId, dwThreadId); |
| 206 #endif | 236 #endif |
| 207 | 237 |
| 208 DEBUG_SELFTEST(L"************************************************************* *******************\n" + finalError + "\ n************************************** ******************************************") | 238 DEBUG_SELFTEST(L"************************************************************* *******************\n" + finalError + "\n*************************************** *****************************************") |
| 209 } | 239 } |
| 210 | 240 |
| 211 void CPluginDebug::DebugErrorCode(DWORD errorCode, const std::string& error, DWO RD processId, DWORD threadId) | 241 void CPluginDebug::DebugErrorCode(DWORD errorCode, const std::string& error, DWO RD processId, DWORD threadId) |
| 212 { | 242 { |
| 213 DebugErrorCodeLegacy(errorCode, CString(error.c_str()), processId, threadId); | 243 DebugErrorCodeLegacy(errorCode, CString(error.c_str()), processId, threadId); |
| 214 } | 244 } |
| 215 | 245 |
| 216 #endif | 246 #endif |
| 217 | 247 |
| 218 // ============================================================================ | 248 // ============================================================================ |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 299 srcTrunc = srcTrunc.Left(67) + L"..." + srcTrunc.Right(30); | 329 srcTrunc = srcTrunc.Left(67) + L"..." + srcTrunc.Right(30); |
| 300 } | 330 } |
| 301 | 331 |
| 302 CString blocking; | 332 CString blocking; |
| 303 blocking.Format(L"Ignored %-12s %s %s", ToCString(type), domain.empty()? L" -" : ToCString(domain), srcTrunc); | 333 blocking.Format(L"Ignored %-12s %s %s", ToCString(type), domain.empty()? L" -" : ToCString(domain), srcTrunc); |
| 304 | 334 |
| 305 DebugResultLegacy(blocking); | 335 DebugResultLegacy(blocking); |
| 306 } | 336 } |
| 307 | 337 |
| 308 #endif // ENABLE_DEBUG_RESULT_IGNORED | 338 #endif // ENABLE_DEBUG_RESULT_IGNORED |
| LEFT | RIGHT |