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

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

Issue 1840693002: Restore ScopedLogger and add documentation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address review comments Created 4 years, 8 months 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/wtf/Assertions.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 22 matching lines...) Expand all
33 Note, this file uses many GCC extensions, but it should be compatible with 33 Note, this file uses many GCC extensions, but it should be compatible with
34 C, Objective C, C++, and Objective C++. 34 C, Objective C, C++, and Objective C++.
35 35
36 For non-debug builds, everything is disabled by default, except for the 36 For non-debug builds, everything is disabled by default, except for the
37 RELEASE_ASSERT family of macros. 37 RELEASE_ASSERT family of macros.
38 38
39 Defining any of the symbols explicitly prevents this from having any effect. 39 Defining any of the symbols explicitly prevents this from having any effect.
40 40
41 */ 41 */
42 42
43 #include "base/gtest_prod_util.h"
43 #include "base/logging.h" 44 #include "base/logging.h"
44 #include "wtf/Compiler.h" 45 #include "wtf/Compiler.h"
45 #include "wtf/Noncopyable.h" 46 #include "wtf/Noncopyable.h"
46 #include "wtf/WTFExport.h" 47 #include "wtf/WTFExport.h"
47 #include "wtf/build_config.h" 48 #include "wtf/build_config.h"
48 #include <stdarg.h> 49 #include <stdarg.h>
49 50
50 // Users must test "#if ENABLE(ASSERT)", which helps ensure that code 51 // Users must test "#if ENABLE(ASSERT)", which helps ensure that code
51 // testing this macro has included this header. 52 // testing this macro has included this header.
52 #ifndef ENABLE_ASSERT 53 #ifndef ENABLE_ASSERT
(...skipping 29 matching lines...) Expand all
82 83
83 WTF_EXPORT void WTFReportAssertionFailure(const char* file, int line, const char * function, const char* assertion); 84 WTF_EXPORT void WTFReportAssertionFailure(const char* file, int line, const char * function, const char* assertion);
84 WTF_EXPORT void WTFLog(WTFLogChannel*, const char* format, ...) WTF_ATTRIBUTE_PR INTF(2, 3); 85 WTF_EXPORT void WTFLog(WTFLogChannel*, const char* format, ...) WTF_ATTRIBUTE_PR INTF(2, 3);
85 WTF_EXPORT void WTFLogVerbose(const char* file, int line, const char* function, WTFLogChannel*, const char* format, ...) WTF_ATTRIBUTE_PRINTF(5, 6); 86 WTF_EXPORT void WTFLogVerbose(const char* file, int line, const char* function, WTFLogChannel*, const char* format, ...) WTF_ATTRIBUTE_PRINTF(5, 6);
86 WTF_EXPORT void WTFLogAlways(const char* format, ...) WTF_ATTRIBUTE_PRINTF(1, 2) ; 87 WTF_EXPORT void WTFLogAlways(const char* format, ...) WTF_ATTRIBUTE_PRINTF(1, 2) ;
87 88
88 WTF_EXPORT void WTFGetBacktrace(void** stack, int* size); 89 WTF_EXPORT void WTFGetBacktrace(void** stack, int* size);
89 WTF_EXPORT void WTFReportBacktrace(int framesToShow = 31); 90 WTF_EXPORT void WTFReportBacktrace(int framesToShow = 31);
90 WTF_EXPORT void WTFPrintBacktrace(void** stack, int size); 91 WTF_EXPORT void WTFPrintBacktrace(void** stack, int size);
91 92
93 namespace WTF {
94
95 #if LOG_DISABLED
96
97 #define WTF_CREATE_SCOPED_LOGGER(...) ((void) 0)
98 #define WTF_CREATE_SCOPED_LOGGER_IF(...) ((void) 0)
99 #define WTF_APPEND_SCOPED_LOGGER(...) ((void) 0)
100
101 #else
102
103 // ScopedLogger wraps log messages in parentheses, with indentation proportional
104 // to the number of instances. This makes it easy to see the flow of control in
105 // the output, particularly when instrumenting recursive functions.
106 //
107 // NOTE: This class is a debugging tool, not intended for use by checked-in
108 // code. Please do not remove it.
109 //
110 class WTF_EXPORT ScopedLogger {
111 WTF_MAKE_NONCOPYABLE(ScopedLogger);
112 public:
113 // The first message is passed to the constructor. Additional messages for
114 // the same scope can be added with log(). If condition is false, produce no
115 // output and do not create a scope.
116 ScopedLogger(bool condition, const char* format, ...) WTF_ATTRIBUTE_PRINTF(3 , 4);
117 ~ScopedLogger();
118 void log(const char* format, ...) WTF_ATTRIBUTE_PRINTF(2, 3);
119
120 private:
121 FRIEND_TEST_ALL_PREFIXES(AssertionsTest, ScopedLogger);
122 using PrintFunctionPtr = void (*)(const char* format, va_list args);
123 static void setPrintFuncForTests(PrintFunctionPtr p) { m_printFunc = p; } // Note: not thread safe.
124
125 void init(const char* format, va_list args);
126 void writeNewlineIfNeeded();
127 void indent();
128 void print(const char* format, ...);
129 void printIndent();
130 static ScopedLogger*& current();
131
132 ScopedLogger* const m_parent;
133 bool m_multiline; // The ')' will go on the same line if there is only one e ntry.
134 static PrintFunctionPtr m_printFunc;
135 };
136
137 #define WTF_CREATE_SCOPED_LOGGER(name, ...) WTF::ScopedLogger name(true, __VA_AR GS__)
138 #define WTF_CREATE_SCOPED_LOGGER_IF(name, condition, ...) WTF::ScopedLogger name (condition, __VA_ARGS__)
139 #define WTF_APPEND_SCOPED_LOGGER(name, ...) (name.log(__VA_ARGS__))
140
141 #endif // LOG_DISABLED
142
143 } // namespace WTF
144
92 /* IMMEDIATE_CRASH() - Like CRASH() below but crashes in the fastest, simplest p ossible way with no attempt at logging. */ 145 /* IMMEDIATE_CRASH() - Like CRASH() below but crashes in the fastest, simplest p ossible way with no attempt at logging. */
93 #ifndef IMMEDIATE_CRASH 146 #ifndef IMMEDIATE_CRASH
94 #if COMPILER(GCC) || COMPILER(CLANG) 147 #if COMPILER(GCC) || COMPILER(CLANG)
95 #define IMMEDIATE_CRASH() __builtin_trap() 148 #define IMMEDIATE_CRASH() __builtin_trap()
96 #else 149 #else
97 #define IMMEDIATE_CRASH() ((void)(*(volatile char*)0 = 0)) 150 #define IMMEDIATE_CRASH() ((void)(*(volatile char*)0 = 0))
98 #endif 151 #endif
99 #endif 152 #endif
100 153
101 /* CRASH() - Raises a fatal error resulting in program termination and triggerin g either the debugger or the crash reporter. 154 /* CRASH() - Raises a fatal error resulting in program termination and triggerin g either the debugger or the crash reporter.
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 } \ 315 } \
263 inline const thisType& to##thisType(const argumentType& argumentName) \ 316 inline const thisType& to##thisType(const argumentType& argumentName) \
264 { \ 317 { \
265 ASSERT_WITH_SECURITY_IMPLICATION(referencePredicate); \ 318 ASSERT_WITH_SECURITY_IMPLICATION(referencePredicate); \
266 return static_cast<const thisType&>(argumentName); \ 319 return static_cast<const thisType&>(argumentName); \
267 } \ 320 } \
268 void to##thisType(const thisType*); \ 321 void to##thisType(const thisType*); \
269 void to##thisType(const thisType&) 322 void to##thisType(const thisType&)
270 323
271 #endif /* WTF_Assertions_h */ 324 #endif /* WTF_Assertions_h */
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/wtf/Assertions.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698