Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(196)

Side by Side Diff: third_party/WebKit/Source/wtf/Assertions.h

Issue 2288473002: Implement Dump-on-DCHECK (via a new LogSeverity). (Closed)
Patch Set: Migrate some tests to EXPECT_DCHECK_DEATH Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2013 Google Inc. All rights reserved. 3 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "wtf/build_config.h" 42 #include "wtf/build_config.h"
43 #include <stdarg.h> 43 #include <stdarg.h>
44 44
45 #if OS(WIN) 45 #if OS(WIN)
46 #include <windows.h> 46 #include <windows.h>
47 #endif 47 #endif
48 48
49 // Users must test "#if ENABLE(ASSERT)", which helps ensure that code 49 // Users must test "#if ENABLE(ASSERT)", which helps ensure that code
50 // testing this macro has included this header. 50 // testing this macro has included this header.
51 #ifndef ENABLE_ASSERT 51 #ifndef ENABLE_ASSERT
52 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) 52 #define ENABLE_ASSERT DCHECK_IS_ON()
53 /* Disable ASSERT* macros in release mode by default. */
54 #define ENABLE_ASSERT 0
55 #else
56 #define ENABLE_ASSERT 1
57 #endif /* defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) */
58 #endif 53 #endif
59 54
60 #ifndef LOG_DISABLED 55 #ifndef LOG_DISABLED
61 #define LOG_DISABLED !ENABLE(ASSERT) 56 #define LOG_DISABLED !ENABLE(ASSERT)
62 #endif 57 #endif
63 58
64 // These helper functions are always declared, but not necessarily always 59 // These helper functions are always declared, but not necessarily always
65 // defined if the corresponding function is disabled. 60 // defined if the corresponding function is disabled.
66 61
67 WTF_EXPORT void WTFReportAssertionFailure(const char* file, 62 WTF_EXPORT void WTFReportAssertionFailure(const char* file,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 // Expressions inside them are evaluated in debug builds only. 145 // Expressions inside them are evaluated in debug builds only.
151 // They are deprecated. We should use: 146 // They are deprecated. We should use:
152 // - DCHECK() for ASSERT() 147 // - DCHECK() for ASSERT()
153 // - NOTREACHED() for ASSERT_NOT_REACHED() 148 // - NOTREACHED() for ASSERT_NOT_REACHED()
154 #if OS(WIN) 149 #if OS(WIN)
155 // FIXME: Change to use something other than ASSERT to avoid this conflict with 150 // FIXME: Change to use something other than ASSERT to avoid this conflict with
156 // the underlying platform. 151 // the underlying platform.
157 #undef ASSERT 152 #undef ASSERT
158 #endif 153 #endif
159 154
155 // If DCHECK is configured to dump-without-crashing then enable assertions,
156 // but also configure them to dump-without-crashing.
157 #if defined(DCHECK_IS_DUMP_WITHOUT_CRASH)
158
159 #define ASSERT(assertion) DCHECK(assertion)
160 #define ASSERT_NOT_REACHED() NOTREACHED()
Wez 2016/12/19 23:57:46 Note that this has significant performance implica
esprehn 2016/12/20 03:16:29 What was the perf change? Not sure I understand ho
Wez 2017/01/07 00:18:47 Earlier versions of the patch left Blink assertion
161
162 // |file| and |line| won't actually be logged, but must be referenced.
163 #define DCHECK_AT(assertion, file, line) DCHECK(assertion) << file << line
164
165 #else // defined(DCHECK_IS_DUMP_WITHOUT_CRASH)
166
160 #define DCHECK_AT(assertion, file, line) \ 167 #define DCHECK_AT(assertion, file, line) \
161 LAZY_STREAM(logging::LogMessage(file, line, #assertion).stream(), \ 168 LAZY_STREAM(logging::LogMessage(file, line, #assertion).stream(), \
162 DCHECK_IS_ON() ? !(assertion) : false) 169 DCHECK_IS_ON() ? !(assertion) : false)
163 170
164 #if ENABLE(ASSERT) 171 #if ENABLE(ASSERT)
165 172
166 #define ASSERT(assertion) \ 173 #define ASSERT(assertion) \
167 (!(assertion) ? (WTFReportAssertionFailure(__FILE__, __LINE__, \ 174 (!(assertion) ? (WTFReportAssertionFailure(__FILE__, __LINE__, \
168 WTF_PRETTY_FUNCTION, #assertion), \ 175 WTF_PRETTY_FUNCTION, #assertion), \
169 CRASH()) \ 176 CRASH()) \
170 : (void)0) 177 : (void)0)
171 178
172 #define ASSERT_NOT_REACHED() \ 179 #define ASSERT_NOT_REACHED() \
173 do { \ 180 do { \
174 WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, 0); \ 181 WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, 0); \
175 CRASH(); \ 182 CRASH(); \
176 } while (0) 183 } while (0)
177 184
178 #else 185 #else
179 186
180 #define ASSERT(assertion) ((void)0) 187 #define ASSERT(assertion) ((void)0)
181 #define ASSERT_NOT_REACHED() ((void)0) 188 #define ASSERT_NOT_REACHED() ((void)0)
182 189
183 #endif 190 #endif
184 191
192 #endif // defined(DCHECK_ALWAYS_ON)
193
185 // Users must test "#if ENABLE(SECURITY_ASSERT)", which helps ensure 194 // Users must test "#if ENABLE(SECURITY_ASSERT)", which helps ensure
186 // that code testing this macro has included this header. 195 // that code testing this macro has included this header.
187 #if defined(ADDRESS_SANITIZER) || ENABLE(ASSERT) 196 #if defined(ADDRESS_SANITIZER) || ENABLE(ASSERT)
188 #define ENABLE_SECURITY_ASSERT 1 197 #define ENABLE_SECURITY_ASSERT 1
189 #else 198 #else
190 #define ENABLE_SECURITY_ASSERT 0 199 #define ENABLE_SECURITY_ASSERT 0
191 #endif 200 #endif
192 201
193 // SECURITY_DCHECK and SECURITY_CHECK 202 // SECURITY_DCHECK and SECURITY_CHECK
194 // Use in places where failure of the assertion indicates a possible security 203 // Use in places where failure of the assertion indicates a possible security
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 return static_cast<thisType&>(argument); \ 301 return static_cast<thisType&>(argument); \
293 } \ 302 } \
294 inline const thisType& to##thisType##OrDie(const argumentType& argument) { \ 303 inline const thisType& to##thisType##OrDie(const argumentType& argument) { \
295 CHECK(referencePredicate); \ 304 CHECK(referencePredicate); \
296 return static_cast<const thisType&>(argument); \ 305 return static_cast<const thisType&>(argument); \
297 } \ 306 } \
298 void to##thisType##OrDie(const thisType*); \ 307 void to##thisType##OrDie(const thisType*); \
299 void to##thisType##OrDie(const thisType&) 308 void to##thisType##OrDie(const thisType&)
300 309
301 #endif // WTF_Assertions_h 310 #endif // WTF_Assertions_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698