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