OLD | NEW |
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 | |
20 #include "PluginDebug.h" | 19 #include "PluginDebug.h" |
| 20 #include "Exception.h" |
21 #include "PluginMutex.h" | 21 #include "PluginMutex.h" |
22 #include "PluginSettings.h" | 22 #include "PluginSettings.h" |
23 | 23 |
| 24 #if (defined ENABLE_DEBUG_INFO) |
| 25 namespace { |
| 26 // VS 2012 does not have support for variadic templates, which would eliminate
the need for an argument class. |
| 27 struct LogHandlersArguments |
| 28 { |
| 29 bool isEntryPoint; |
| 30 std::string name; |
| 31 }; |
| 32 |
| 33 std::string DefaultLogMessage(const LogHandlersArguments& x, const std::string
&exceptionType) |
| 34 { |
| 35 std::string s = x.isEntryPoint ? "ENTRY POINT '" : "'"; |
| 36 s += x.name; |
| 37 s += "' caught default "; |
| 38 s += exceptionType; |
| 39 return s; |
| 40 } |
| 41 |
| 42 struct LogHandlers |
| 43 { |
| 44 static void Unknown(const LogHandlersArguments& args) |
| 45 { |
| 46 CPluginDebug::Debug(DefaultLogMessage(args, "Unknown exception")); |
| 47 } |
| 48 static void Exception(std::exception& ex, LogHandlersArguments& args) |
| 49 { |
| 50 CPluginDebug::DebugOrdinaryException(ex, |
| 51 PLUGIN_ERROR_ENTRY_POINT, PLUGIN_ERROR_ENTRY_POINT_CATCHALL_EXCEPTION, |
| 52 DefaultLogMessage(args, "std::exception")); |
| 53 } |
| 54 static void LogicError(std::logic_error& ex, LogHandlersArguments& args) |
| 55 { |
| 56 CPluginDebug::DebugOrdinaryException(ex, |
| 57 PLUGIN_ERROR_ENTRY_POINT, PLUGIN_ERROR_ENTRY_POINT_CATCHALL_EXCEPTION, |
| 58 DefaultLogMessage(args, "std::logic_error")); |
| 59 } |
| 60 static void RuntimeError(std::runtime_error& ex, LogHandlersArguments& args) |
| 61 { |
| 62 CPluginDebug::DebugOrdinaryException(ex, |
| 63 PLUGIN_ERROR_ENTRY_POINT, PLUGIN_ERROR_ENTRY_POINT_CATCHALL_EXCEPTION, |
| 64 DefaultLogMessage(args, "std::runtime_error")); |
| 65 } |
| 66 static void SystemError(std::system_error& ex, LogHandlersArguments& args) |
| 67 { |
| 68 CPluginDebug::DebugSystemException(ex, |
| 69 PLUGIN_ERROR_ENTRY_POINT, PLUGIN_ERROR_ENTRY_POINT_CATCHALL_EXCEPTION, |
| 70 DefaultLogMessage(args, "std::std::system_error")); |
| 71 } |
| 72 }; |
| 73 } |
| 74 #endif |
| 75 |
| 76 void EntryPointExceptionDefault(const std::string& name) |
| 77 { |
| 78 #if (defined ENABLE_DEBUG_INFO) |
| 79 // VS 2012 does not have support for brace initializer lists; otherwise this c
ould be a single line |
| 80 LogHandlersArguments x; |
| 81 x.isEntryPoint = true; |
| 82 x.name = name; |
| 83 CatchAllVoid<LogHandlers>::Handler(x); |
| 84 #endif |
| 85 } |
| 86 |
| 87 void ExceptionDefault(const std::string& name) |
| 88 { |
| 89 #if (defined ENABLE_DEBUG_INFO) |
| 90 LogHandlersArguments x; |
| 91 x.isEntryPoint = false; |
| 92 x.name = name; |
| 93 CatchAllVoid<LogHandlers>::Handler(x); |
| 94 #endif |
| 95 } |
| 96 |
24 class CPluginDebugLock : public CPluginMutex | 97 class CPluginDebugLock : public CPluginMutex |
25 { | 98 { |
26 | 99 |
27 private: | 100 private: |
28 | 101 |
29 static CComAutoCriticalSection s_criticalSectionDebugLock; | 102 static CComAutoCriticalSection s_criticalSectionDebugLock; |
30 | 103 |
31 public: | 104 public: |
32 | 105 |
33 CPluginDebugLock() : CPluginMutex(L"DebugFile", PLUGIN_ERROR_MUTEX_DEBUG_FILE) | 106 CPluginDebugLock() : CPluginMutex(L"DebugFile", PLUGIN_ERROR_MUTEX_DEBUG_FILE) |
34 { | 107 { |
35 s_criticalSectionDebugLock.Lock(); | 108 s_criticalSectionDebugLock.Lock(); |
36 } | 109 } |
37 | 110 |
38 ~CPluginDebugLock() | 111 ~CPluginDebugLock() |
39 { | 112 { |
40 s_criticalSectionDebugLock.Unlock(); | 113 s_criticalSectionDebugLock.Unlock(); |
41 } | 114 } |
42 }; | 115 }; |
43 | 116 |
44 CComAutoCriticalSection CPluginDebugLock::s_criticalSectionDebugLock; | 117 CComAutoCriticalSection CPluginDebugLock::s_criticalSectionDebugLock; |
45 | 118 |
46 void CPluginDebug::DebugSystemException(const std::system_error& ex, int errorId
, int errorSubid, const std::string& description) | 119 void CPluginDebug::DebugSystemException(const std::system_error& ex, int errorId
, int errorSubid, const std::string& description) |
47 { | 120 { |
48 std::string message = description + ", " + ex.code().message() + ", " + ex.wha
t(); | 121 std::string message = description + ", " + ex.code().message() + ", " + ex.wha
t(); |
49 DEBUG_ERROR_LOG(ex.code().value(), errorId, errorSubid, message); | 122 DEBUG_ERROR_LOG(ex.code().value(), errorId, errorSubid, message); |
50 } | 123 } |
51 | 124 |
| 125 void CPluginDebug::DebugOrdinaryException(const std::exception& ex, int errorId,
int errorSubid, const std::string& description) |
| 126 { |
| 127 std::string message = description + ", " + ex.what(); |
| 128 DEBUG_ERROR_LOG(0, errorId, errorSubid, message); |
| 129 } |
| 130 |
52 #ifdef ENABLE_DEBUG_INFO | 131 #ifdef ENABLE_DEBUG_INFO |
53 | 132 |
54 void DebugLegacy(const CString& text, DWORD dwProcessId, DWORD dwThreadId) | 133 void DebugLegacy(const CString& text, DWORD dwProcessId, DWORD dwThreadId) |
55 { | 134 { |
56 #ifdef USE_CONSOLE | 135 #ifdef USE_CONSOLE |
57 CONSOLE("%s", CT2A(text.GetString(), CP_UTF8)); | 136 CONSOLE("%s", CT2A(text.GetString(), CP_UTF8)); |
58 #endif | 137 #endif |
59 | 138 |
60 if (CPluginSettings::HasInstance()) | 139 if (CPluginSettings::HasInstance()) |
61 { | 140 { |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 srcTrunc = srcTrunc.Left(67) + L"..." + srcTrunc.Right(30); | 328 srcTrunc = srcTrunc.Left(67) + L"..." + srcTrunc.Right(30); |
250 } | 329 } |
251 | 330 |
252 CString blocking; | 331 CString blocking; |
253 blocking.Format(L"Ignored %-12s %s %s", ToCString(type), domain.empty()? L"
-" : ToCString(domain), srcTrunc); | 332 blocking.Format(L"Ignored %-12s %s %s", ToCString(type), domain.empty()? L"
-" : ToCString(domain), srcTrunc); |
254 | 333 |
255 DebugResultLegacy(blocking); | 334 DebugResultLegacy(blocking); |
256 } | 335 } |
257 | 336 |
258 #endif // ENABLE_DEBUG_RESULT_IGNORED | 337 #endif // ENABLE_DEBUG_RESULT_IGNORED |
OLD | NEW |