Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 #define ENABLE_ASSERT 0 | 53 #define ENABLE_ASSERT 0 |
| 54 #else | 54 #else |
| 55 #define ENABLE_ASSERT 1 | 55 #define ENABLE_ASSERT 1 |
| 56 #endif /* defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) */ | 56 #endif /* defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) */ |
| 57 #endif | 57 #endif |
| 58 | 58 |
| 59 #ifndef LOG_DISABLED | 59 #ifndef LOG_DISABLED |
| 60 #define LOG_DISABLED !ENABLE(ASSERT) | 60 #define LOG_DISABLED !ENABLE(ASSERT) |
| 61 #endif | 61 #endif |
| 62 | 62 |
| 63 #if COMPILER(GCC) | |
| 64 #define WTF_ATTRIBUTE_PRINTF(formatStringArgument, extraArguments) \ | |
| 65 __attribute__((__format__(printf, formatStringArgument, extraArguments))) | |
| 66 #else | |
| 67 #define WTF_ATTRIBUTE_PRINTF(formatStringArgument, extraArguments) | |
| 68 #endif | |
|
Yuta Kitamura
2016/11/21 08:58:39
Can you explicitly include base/compiler_specific.
tkent
2016/11/21 09:12:30
The Blink counterpart of base/compiler_specific.h
Yuta Kitamura
2016/11/21 09:27:48
That's okay, too.
tkent
2016/11/22 02:15:18
Uploaded Patch Set 2.
| |
| 69 | |
| 70 // These helper functions are always declared, but not necessarily always | 63 // These helper functions are always declared, but not necessarily always |
| 71 // defined if the corresponding function is disabled. | 64 // defined if the corresponding function is disabled. |
| 72 | 65 |
| 73 WTF_EXPORT void WTFReportAssertionFailure(const char* file, | 66 WTF_EXPORT void WTFReportAssertionFailure(const char* file, |
| 74 int line, | 67 int line, |
| 75 const char* function, | 68 const char* function, |
| 76 const char* assertion); | 69 const char* assertion); |
| 77 // WTFLogAlways() is deprecated. crbug.com/638849 | 70 // WTFLogAlways() is deprecated. crbug.com/638849 |
| 78 WTF_EXPORT void WTFLogAlways(const char* format, ...) | 71 WTF_EXPORT PRINTF_FORMAT(1, 2) void WTFLogAlways(const char* format, ...); |
| 79 WTF_ATTRIBUTE_PRINTF(1, 2); | |
| 80 WTF_EXPORT void WTFReportBacktrace(int framesToShow = 31); | 72 WTF_EXPORT void WTFReportBacktrace(int framesToShow = 31); |
| 81 | 73 |
| 82 namespace WTF { | 74 namespace WTF { |
| 83 | 75 |
| 84 #if LOG_DISABLED | 76 #if LOG_DISABLED |
| 85 | 77 |
| 86 #define WTF_CREATE_SCOPED_LOGGER(...) ((void)0) | 78 #define WTF_CREATE_SCOPED_LOGGER(...) ((void)0) |
| 87 #define WTF_CREATE_SCOPED_LOGGER_IF(...) ((void)0) | 79 #define WTF_CREATE_SCOPED_LOGGER_IF(...) ((void)0) |
| 88 #define WTF_APPEND_SCOPED_LOGGER(...) ((void)0) | 80 #define WTF_APPEND_SCOPED_LOGGER(...) ((void)0) |
| 89 | 81 |
| 90 #else | 82 #else |
| 91 | 83 |
| 92 // ScopedLogger wraps log messages in parentheses, with indentation proportional | 84 // ScopedLogger wraps log messages in parentheses, with indentation proportional |
| 93 // to the number of instances. This makes it easy to see the flow of control in | 85 // to the number of instances. This makes it easy to see the flow of control in |
| 94 // the output, particularly when instrumenting recursive functions. | 86 // the output, particularly when instrumenting recursive functions. |
| 95 // | 87 // |
| 96 // NOTE: This class is a debugging tool, not intended for use by checked-in | 88 // NOTE: This class is a debugging tool, not intended for use by checked-in |
| 97 // code. Please do not remove it. | 89 // code. Please do not remove it. |
| 98 // | 90 // |
| 99 class WTF_EXPORT ScopedLogger { | 91 class WTF_EXPORT ScopedLogger { |
| 100 WTF_MAKE_NONCOPYABLE(ScopedLogger); | 92 WTF_MAKE_NONCOPYABLE(ScopedLogger); |
| 101 | 93 |
| 102 public: | 94 public: |
| 103 // The first message is passed to the constructor. Additional messages for | 95 // The first message is passed to the constructor. Additional messages for |
| 104 // the same scope can be added with log(). If condition is false, produce no | 96 // the same scope can be added with log(). If condition is false, produce no |
| 105 // output and do not create a scope. | 97 // output and do not create a scope. |
| 106 ScopedLogger(bool condition, const char* format, ...) | 98 PRINTF_FORMAT(3, 4) ScopedLogger(bool condition, const char* format, ...); |
| 107 WTF_ATTRIBUTE_PRINTF(3, 4); | |
| 108 ~ScopedLogger(); | 99 ~ScopedLogger(); |
| 109 void log(const char* format, ...) WTF_ATTRIBUTE_PRINTF(2, 3); | 100 PRINTF_FORMAT(2, 3) void log(const char* format, ...); |
| 110 | 101 |
| 111 private: | 102 private: |
| 112 FRIEND_TEST_ALL_PREFIXES(AssertionsTest, ScopedLogger); | 103 FRIEND_TEST_ALL_PREFIXES(AssertionsTest, ScopedLogger); |
| 113 using PrintFunctionPtr = void (*)(const char* format, va_list args); | 104 using PrintFunctionPtr = void (*)(const char* format, va_list args); |
| 114 static void setPrintFuncForTests(PrintFunctionPtr p) { | 105 static void setPrintFuncForTests(PrintFunctionPtr p) { |
| 115 m_printFunc = p; | 106 m_printFunc = p; |
| 116 } // Note: not thread safe. | 107 } // Note: not thread safe. |
| 117 | 108 |
| 118 void init(const char* format, va_list args); | 109 void init(const char* format, va_list args); |
| 119 void writeNewlineIfNeeded(); | 110 void writeNewlineIfNeeded(); |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 return static_cast<thisType&>(argumentName); \ | 297 return static_cast<thisType&>(argumentName); \ |
| 307 } \ | 298 } \ |
| 308 inline const thisType& to##thisType(const argumentType& argumentName) { \ | 299 inline const thisType& to##thisType(const argumentType& argumentName) { \ |
| 309 SECURITY_DCHECK(referencePredicate); \ | 300 SECURITY_DCHECK(referencePredicate); \ |
| 310 return static_cast<const thisType&>(argumentName); \ | 301 return static_cast<const thisType&>(argumentName); \ |
| 311 } \ | 302 } \ |
| 312 void to##thisType(const thisType*); \ | 303 void to##thisType(const thisType*); \ |
| 313 void to##thisType(const thisType&) | 304 void to##thisType(const thisType&) |
| 314 | 305 |
| 315 #endif // WTF_Assertions_h | 306 #endif // WTF_Assertions_h |
| OLD | NEW |