| 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 namespace { | 26 namespace { | 
| 26 // VS 2012 does not have support for variadic templates, which would eliminate the need for an argument class. | 27 // VS 2012 does not have support for variadic templates, which would eliminate the need for an argument class. | 
| 
 
sergei
2015/03/06 13:51:12
I don't think we need this comment.
 
Eric
2015/03/06 17:29:59
This comment and the one like it below use the mar
 
 | |
| 27 struct LogHandlersArguments | 28 struct LogHandlersArguments | 
| 28 { | 29 { | 
| 29 bool isEntryPoint; | 30 bool isEntryPoint; | 
| 30 std::string name; | 31 std::string name; | 
| 31 }; | 32 }; | 
| 32 | 33 | 
| 33 std::string DefaultLogMessage(const LogHandlersArguments& x, const std::string &exceptionType) | 34 std::string DefaultLogMessage(const LogHandlersArguments& x, const std::string &exceptionType) | 
| 34 { | 35 { | 
| 35 std::string s = x.isEntryPoint ? "ENTRY POINT '" : "'"; | 36 std::string s = x.isEntryPoint ? "ENTRY POINT '" : "'"; | 
| 36 s += x.name; | 37 s += x.name; | 
| 37 s += "' caught default "; | 38 s += "' caught default "; | 
| 38 s += exceptionType; | 39 s += exceptionType; | 
| 39 return s; | 40 return s; | 
| 40 } | 41 } | 
| 41 | 42 | 
| 42 struct LogHandlers | 43 struct LogHandlers | 
| 43 { | 44 { | 
| 44 static void Unknown(LogHandlersArguments& x) | 45 static void Unknown(const LogHandlersArguments& args) | 
| 
 
sergei
2015/03/06 13:51:12
Would it be better to rename `x` to something else
 
Eric
2015/03/06 17:29:59
Added 'const'. Renamed 'x' to 'args'.
 
 | |
| 45 { | 46 { | 
| 46 CPluginDebug::Debug(DefaultLogMessage(x, "Unknown exception")); | 47 CPluginDebug::Debug(DefaultLogMessage(args, "Unknown exception")); | 
| 47 } | 48 } | 
| 48 static void Exception(std::exception& ex, LogHandlersArguments& x) | 49 static void Exception(const std::exception& ex, LogHandlersArguments& args) | 
| 49 { | 50 { | 
| 50 CPluginDebug::DebugOrdinaryException(ex, | 51 CPluginDebug::DebugOrdinaryException(ex, | 
| 51 PLUGIN_ERROR_ENTRY_POINT, PLUGIN_ERROR_ENTRY_POINT_CATCHALL_EXCEPTION, | 52 PLUGIN_ERROR_ENTRY_POINT, PLUGIN_ERROR_ENTRY_POINT_CATCHALL_EXCEPTION, | 
| 52 DefaultLogMessage(x, "std::exception")); | 53 DefaultLogMessage(args, "std::exception")); | 
| 53 } | 54 } | 
| 54 static void LogicError(std::logic_error& ex, LogHandlersArguments& x) | 55 static void LogicError(const std::logic_error& ex, LogHandlersArguments& arg s) | 
| 55 { | 56 { | 
| 56 CPluginDebug::DebugOrdinaryException(ex, | 57 CPluginDebug::DebugOrdinaryException(ex, | 
| 57 PLUGIN_ERROR_ENTRY_POINT, PLUGIN_ERROR_ENTRY_POINT_CATCHALL_EXCEPTION, | 58 PLUGIN_ERROR_ENTRY_POINT, PLUGIN_ERROR_ENTRY_POINT_CATCHALL_EXCEPTION, | 
| 58 DefaultLogMessage(x, "std::logic_error")); | 59 DefaultLogMessage(args, "std::logic_error")); | 
| 59 } | 60 } | 
| 60 static void RuntimeError(std::runtime_error& ex, LogHandlersArguments& x) | 61 static void RuntimeError(const std::runtime_error& ex, LogHandlersArguments& args) | 
| 61 { | 62 { | 
| 62 CPluginDebug::DebugOrdinaryException(ex, | 63 CPluginDebug::DebugOrdinaryException(ex, | 
| 63 PLUGIN_ERROR_ENTRY_POINT, PLUGIN_ERROR_ENTRY_POINT_CATCHALL_EXCEPTION, | 64 PLUGIN_ERROR_ENTRY_POINT, PLUGIN_ERROR_ENTRY_POINT_CATCHALL_EXCEPTION, | 
| 64 DefaultLogMessage(x, "std::runtime_error")); | 65 DefaultLogMessage(args, "std::runtime_error")); | 
| 65 } | 66 } | 
| 66 static void SystemError(std::system_error& ex, LogHandlersArguments& x) | 67 static void SystemError(const std::system_error& ex, LogHandlersArguments& a rgs) | 
| 67 { | 68 { | 
| 68 CPluginDebug::DebugSystemException(ex, | 69 CPluginDebug::DebugSystemException(ex, | 
| 69 PLUGIN_ERROR_ENTRY_POINT, PLUGIN_ERROR_ENTRY_POINT_CATCHALL_EXCEPTION, | 70 PLUGIN_ERROR_ENTRY_POINT, PLUGIN_ERROR_ENTRY_POINT_CATCHALL_EXCEPTION, | 
| 70 DefaultLogMessage(x, "std::std::system_error")); | 71 DefaultLogMessage(args, "std::std::system_error")); | 
| 71 } | 72 } | 
| 72 }; | 73 }; | 
| 73 } | 74 } | 
| 74 #endif | 75 #endif | 
| 75 | 76 | 
| 76 void EntryPointExceptionDefault(const std::string& name) | 77 void EntryPointExceptionDefault(const std::string& name) | 
| 77 { | 78 { | 
| 78 #if (defined ENABLE_DEBUG_INFO) | 79 #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 // VS 2012 does not have support for brace initializer lists; otherwise this c ould be a single line | 
| 
 
sergei
2015/03/06 13:51:12
I would remove this comment because it's useless h
 
Eric
2015/03/06 17:29:59
I agree. The virtue of naming the structure elemen
 
sergei
2015/03/31 14:30:51
Sorry, it's not clear for me why you want to have
 
Eric
2015/05/14 14:42:50
The comments about variadic templates stay. It's i
 
sergei
2015/05/15 13:13:24
There are another more reliable technics how to fi
 
 | |
| 80 LogHandlersArguments x; | 81 LogHandlersArguments x; | 
| 81 x.isEntryPoint = true; | 82 x.isEntryPoint = true; | 
| 82 x.name = name; | 83 x.name = name; | 
| 83 CatchAllVoid<LogHandlers>::Handler(x); | 84 CatchAllVoid<LogHandlers>::Handler(x); | 
| 84 #endif | 85 #endif | 
| 85 } | 86 } | 
| 86 | 87 | 
| 87 void ExceptionDefault(const std::string& name) | 88 void ExceptionDefault(const std::string& name) | 
| 88 { | 89 { | 
| 89 #if (defined ENABLE_DEBUG_INFO) | 90 #if (defined ENABLE_DEBUG_INFO) | 
| (...skipping 30 matching lines...) Expand all Loading... | |
| 120 { | 121 { | 
| 121 std::string message = description + ", " + ex.code().message() + ", " + ex.wha t(); | 122 std::string message = description + ", " + ex.code().message() + ", " + ex.wha t(); | 
| 122 DEBUG_ERROR_LOG(ex.code().value(), errorId, errorSubid, message); | 123 DEBUG_ERROR_LOG(ex.code().value(), errorId, errorSubid, message); | 
| 123 } | 124 } | 
| 124 | 125 | 
| 125 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) | 
| 126 { | 127 { | 
| 127 std::string message = description + ", " + ex.what(); | 128 std::string message = description + ", " + ex.what(); | 
| 128 DEBUG_ERROR_LOG(0, errorId, errorSubid, message); | 129 DEBUG_ERROR_LOG(0, errorId, errorSubid, message); | 
| 129 } | 130 } | 
| 130 | |
| 131 | |
| 
 
sergei
2015/03/06 13:51:12
two additional lines
 
Eric
2015/03/06 17:29:59
Done.
 
 | |
| 132 | 131 | 
| 133 #ifdef ENABLE_DEBUG_INFO | 132 #ifdef ENABLE_DEBUG_INFO | 
| 134 | 133 | 
| 135 void DebugLegacy(const CString& text, DWORD dwProcessId, DWORD dwThreadId) | 134 void DebugLegacy(const CString& text, DWORD dwProcessId, DWORD dwThreadId) | 
| 136 { | 135 { | 
| 137 #ifdef USE_CONSOLE | 136 #ifdef USE_CONSOLE | 
| 138 CONSOLE("%s", CT2A(text.GetString(), CP_UTF8)); | 137 CONSOLE("%s", CT2A(text.GetString(), CP_UTF8)); | 
| 139 #endif | 138 #endif | 
| 140 | 139 | 
| 141 if (CPluginSettings::HasInstance()) | 140 if (CPluginSettings::HasInstance()) | 
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 330 srcTrunc = srcTrunc.Left(67) + L"..." + srcTrunc.Right(30); | 329 srcTrunc = srcTrunc.Left(67) + L"..." + srcTrunc.Right(30); | 
| 331 } | 330 } | 
| 332 | 331 | 
| 333 CString blocking; | 332 CString blocking; | 
| 334 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); | 
| 335 | 334 | 
| 336 DebugResultLegacy(blocking); | 335 DebugResultLegacy(blocking); | 
| 337 } | 336 } | 
| 338 | 337 | 
| 339 #endif // ENABLE_DEBUG_RESULT_IGNORED | 338 #endif // ENABLE_DEBUG_RESULT_IGNORED | 
| LEFT | RIGHT |