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

Side by Side Diff: src/plugin/PluginDebug.cpp

Issue 5137721374801920: Issue #1173 - Default behavior for catch-all blocks
Patch Set: Add ExceptionDefault() Created March 5, 2015, 2:56 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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.
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 {
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(LogHandlersArguments& x)
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 CPluginDebug::Debug(DefaultLogMessage(x, "Unknown exception"));
47 }
48 static void Exception(std::exception& ex, LogHandlersArguments& x)
49 {
50 CPluginDebug::DebugOrdinaryException(ex,
51 PLUGIN_ERROR_ENTRY_POINT, PLUGIN_ERROR_ENTRY_POINT_CATCHALL_EXCEPTION,
52 DefaultLogMessage(x, "std::exception"));
53 }
54 static void LogicError(std::logic_error& ex, LogHandlersArguments& x)
55 {
56 CPluginDebug::DebugOrdinaryException(ex,
57 PLUGIN_ERROR_ENTRY_POINT, PLUGIN_ERROR_ENTRY_POINT_CATCHALL_EXCEPTION,
58 DefaultLogMessage(x, "std::logic_error"));
59 }
60 static void RuntimeError(std::runtime_error& ex, LogHandlersArguments& x)
61 {
62 CPluginDebug::DebugOrdinaryException(ex,
63 PLUGIN_ERROR_ENTRY_POINT, PLUGIN_ERROR_ENTRY_POINT_CATCHALL_EXCEPTION,
64 DefaultLogMessage(x, "std::runtime_error"));
65 }
66 static void SystemError(std::system_error& ex, LogHandlersArguments& x)
67 {
68 CPluginDebug::DebugSystemException(ex,
69 PLUGIN_ERROR_ENTRY_POINT, PLUGIN_ERROR_ENTRY_POINT_CATCHALL_EXCEPTION,
70 DefaultLogMessage(x, "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
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 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
131
sergei 2015/03/06 13:51:12 two additional lines
Eric 2015/03/06 17:29:59 Done.
132
52 #ifdef ENABLE_DEBUG_INFO 133 #ifdef ENABLE_DEBUG_INFO
53 134
54 void DebugLegacy(const CString& text, DWORD dwProcessId, DWORD dwThreadId) 135 void DebugLegacy(const CString& text, DWORD dwProcessId, DWORD dwThreadId)
55 { 136 {
56 #ifdef USE_CONSOLE 137 #ifdef USE_CONSOLE
57 CONSOLE("%s", CT2A(text.GetString(), CP_UTF8)); 138 CONSOLE("%s", CT2A(text.GetString(), CP_UTF8));
58 #endif 139 #endif
59 140
60 if (CPluginSettings::HasInstance()) 141 if (CPluginSettings::HasInstance())
61 { 142 {
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 srcTrunc = srcTrunc.Left(67) + L"..." + srcTrunc.Right(30); 330 srcTrunc = srcTrunc.Left(67) + L"..." + srcTrunc.Right(30);
250 } 331 }
251 332
252 CString blocking; 333 CString blocking;
253 blocking.Format(L"Ignored %-12s %s %s", ToCString(type), domain.empty()? L" -" : ToCString(domain), srcTrunc); 334 blocking.Format(L"Ignored %-12s %s %s", ToCString(type), domain.empty()? L" -" : ToCString(domain), srcTrunc);
254 335
255 DebugResultLegacy(blocking); 336 DebugResultLegacy(blocking);
256 } 337 }
257 338
258 #endif // ENABLE_DEBUG_RESULT_IGNORED 339 #endif // ENABLE_DEBUG_RESULT_IGNORED
OLDNEW

Powered by Google App Engine
This is Rietveld