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

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: 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
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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 82
83 WTF_EXPORT void WTFReportAssertionFailure(const char* file, int line, const char * function, const char* assertion); 83 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); 84 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); 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 WTFLogAlways(const char* format, ...) WTF_ATTRIBUTE_PRINTF(1, 2) ; 86 WTF_EXPORT void WTFLogAlways(const char* format, ...) WTF_ATTRIBUTE_PRINTF(1, 2) ;
87 87
88 WTF_EXPORT void WTFGetBacktrace(void** stack, int* size); 88 WTF_EXPORT void WTFGetBacktrace(void** stack, int* size);
89 WTF_EXPORT void WTFReportBacktrace(int framesToShow = 31); 89 WTF_EXPORT void WTFReportBacktrace(int framesToShow = 31);
90 WTF_EXPORT void WTFPrintBacktrace(void** stack, int size); 90 WTF_EXPORT void WTFPrintBacktrace(void** stack, int size);
91 91
92 namespace WTF {
93
94 // ScopedLogger wraps log messages in parentheses, with indentation proportional
95 // to the number of instances. This makes it easy to see the flow of control in
96 // the output, particularly when instrumenting recursive functions.
tkent 2016/03/28 23:16:30 Please add a comment that this class is not used i
skobes 2016/03/29 18:23:40 Done.
97 class WTF_EXPORT ScopedLogger {
98 WTF_MAKE_NONCOPYABLE(ScopedLogger);
99 public:
100 // The first message is passed to the constructor. Additional messages for
101 // the same scope can be added with log(). If condition is false, produce no
102 // output and do not create a scope.
103 ScopedLogger(bool condition, const char* format, ...) WTF_ATTRIBUTE_PRINTF(3 , 4);
104 ~ScopedLogger();
105 void log(const char* format, ...) WTF_ATTRIBUTE_PRINTF(2, 3);
106
107 private:
108 friend class AssertionsTest;
tkent 2016/03/28 23:16:30 Please use FRIEND_TEST_ALL_PREFIXES defined in bas
skobes 2016/03/29 18:23:40 Done.
109 using PrintFunctionPtr = void (*)(const char* format, va_list args);
110 static void setPrintFuncForTests(PrintFunctionPtr p) { m_printFunc = p; } // Note: not thread safe.
111
112 void init(const char* format, va_list args);
113 void writeNewlineIfNeeded();
114 void indent();
115 void print(const char* format, ...);
116 static ScopedLogger*& current();
117
118 ScopedLogger* const m_parent;
119 bool m_multiline; // The ')' will go on the same line if there is only one e ntry.
120 static PrintFunctionPtr m_printFunc;
121 };
122
123 #if LOG_DISABLED
tkent 2016/03/28 23:16:30 We'd like to remove LOG_DISABLED macro. Can you m
skobes 2016/03/29 18:23:40 That breaks blink_logging_always_on.
124 #define WTF_CREATE_SCOPED_LOGGER(...) ((void) 0)
125 #define WTF_CREATE_SCOPED_LOGGER_IF(...) ((void) 0)
126 #define WTF_APPEND_SCOPED_LOGGER(...) ((void) 0)
127 #else
128 #define WTF_CREATE_SCOPED_LOGGER(name, ...) ScopedLogger name(true, __VA_ARGS__)
tkent 2016/03/28 23:16:30 ScopedLogger class should be declared here to avoi
skobes 2016/03/29 18:23:40 Done.
129 #define WTF_CREATE_SCOPED_LOGGER_IF(name, condition, ...) ScopedLogger name(cond ition, __VA_ARGS__)
130 #define WTF_APPEND_SCOPED_LOGGER(name, ...) (name.log(__VA_ARGS__))
131 #endif
132
133 } // namespace WTF
134
135 using WTF::ScopedLogger;
136
92 /* IMMEDIATE_CRASH() - Like CRASH() below but crashes in the fastest, simplest p ossible way with no attempt at logging. */ 137 /* IMMEDIATE_CRASH() - Like CRASH() below but crashes in the fastest, simplest p ossible way with no attempt at logging. */
93 #ifndef IMMEDIATE_CRASH 138 #ifndef IMMEDIATE_CRASH
94 #if COMPILER(GCC) || COMPILER(CLANG) 139 #if COMPILER(GCC) || COMPILER(CLANG)
95 #define IMMEDIATE_CRASH() __builtin_trap() 140 #define IMMEDIATE_CRASH() __builtin_trap()
96 #else 141 #else
97 #define IMMEDIATE_CRASH() ((void)(*(volatile char*)0 = 0)) 142 #define IMMEDIATE_CRASH() ((void)(*(volatile char*)0 = 0))
98 #endif 143 #endif
99 #endif 144 #endif
100 145
101 /* CRASH() - Raises a fatal error resulting in program termination and triggerin g either the debugger or the crash reporter. 146 /* 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 } \ 307 } \
263 inline const thisType& to##thisType(const argumentType& argumentName) \ 308 inline const thisType& to##thisType(const argumentType& argumentName) \
264 { \ 309 { \
265 ASSERT_WITH_SECURITY_IMPLICATION(referencePredicate); \ 310 ASSERT_WITH_SECURITY_IMPLICATION(referencePredicate); \
266 return static_cast<const thisType&>(argumentName); \ 311 return static_cast<const thisType&>(argumentName); \
267 } \ 312 } \
268 void to##thisType(const thisType*); \ 313 void to##thisType(const thisType*); \
269 void to##thisType(const thisType&) 314 void to##thisType(const thisType&)
270 315
271 #endif /* WTF_Assertions_h */ 316 #endif /* WTF_Assertions_h */
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/wtf/Assertions.cpp » ('j') | third_party/WebKit/Source/wtf/Assertions.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698