| 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) 2007-2009 Torch Mobile, Inc. | 3 * Copyright (C) 2007-2009 Torch Mobile, Inc. |
| 4 * Copyright (C) 2011 University of Szeged. All rights reserved. | 4 * Copyright (C) 2011 University of Szeged. All rights reserved. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| 11 * 2. Redistributions in binary form must reproduce the above copyright | 11 * 2. Redistributions in binary form must reproduce the above copyright |
| 12 * notice, this list of conditions and the following disclaimer in the | 12 * notice, this list of conditions and the following disclaimer in the |
| 13 * documentation and/or other materials provided with the distribution. | 13 * documentation and/or other materials provided with the distribution. |
| 14 * | 14 * |
| 15 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 15 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
| 16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
| 19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 // The vprintf_stderr_common function triggers this error in the Mac build. | 28 // The vprintf_stderr_common function triggers this error in the Mac build. |
| 29 // Feel free to remove this pragma if this file builds on Mac. | 29 // Feel free to remove this pragma if this file builds on Mac. |
| 30 // According to http://gcc.gnu.org/onlinedocs/gcc-4.2.1/gcc/Diagnostic-Pragmas.h
tml#Diagnostic-Pragmas | 30 // According to |
| 31 // http://gcc.gnu.org/onlinedocs/gcc-4.2.1/gcc/Diagnostic-Pragmas.html#Diagnosti
c-Pragmas |
| 31 // we need to place this directive before any data or functions are defined. | 32 // we need to place this directive before any data or functions are defined. |
| 32 #pragma GCC diagnostic ignored "-Wmissing-format-attribute" | 33 #pragma GCC diagnostic ignored "-Wmissing-format-attribute" |
| 33 | 34 |
| 34 #include "wtf/Assertions.h" | 35 #include "wtf/Assertions.h" |
| 35 | 36 |
| 36 #include "wtf/Compiler.h" | 37 #include "wtf/Compiler.h" |
| 37 #include "wtf/PtrUtil.h" | 38 #include "wtf/PtrUtil.h" |
| 38 #include "wtf/ThreadSpecific.h" | 39 #include "wtf/ThreadSpecific.h" |
| 39 #include "wtf/Threading.h" | 40 #include "wtf/Threading.h" |
| 40 #include <memory> | 41 #include <memory> |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 va_list args; | 137 va_list args; |
| 137 va_start(args, format); | 138 va_start(args, format); |
| 138 vprintf_stderr_common(format, args); | 139 vprintf_stderr_common(format, args); |
| 139 va_end(args); | 140 va_end(args); |
| 140 } | 141 } |
| 141 | 142 |
| 142 static void printCallSite(const char* file, int line, const char* function) { | 143 static void printCallSite(const char* file, int line, const char* function) { |
| 143 #if OS(WIN) && defined(_DEBUG) | 144 #if OS(WIN) && defined(_DEBUG) |
| 144 _CrtDbgReport(_CRT_WARN, file, line, nullptr, "%s\n", function); | 145 _CrtDbgReport(_CRT_WARN, file, line, nullptr, "%s\n", function); |
| 145 #else | 146 #else |
| 146 // By using this format, which matches the format used by MSVC for compiler er
rors, developers | 147 // By using this format, which matches the format used by MSVC for compiler |
| 147 // using Visual Studio can double-click the file/line number in the Output Win
dow to have the | 148 // errors, developers using Visual Studio can double-click the file/line |
| 148 // editor navigate to that line of code. It seems fine for other developers, t
oo. | 149 // number in the Output Window to have the editor navigate to that line of |
| 150 // code. It seems fine for other developers, too. |
| 149 printf_stderr_common("%s(%d) : %s\n", file, line, function); | 151 printf_stderr_common("%s(%d) : %s\n", file, line, function); |
| 150 #endif | 152 #endif |
| 151 } | 153 } |
| 152 | 154 |
| 153 void WTFReportAssertionFailure(const char* file, | 155 void WTFReportAssertionFailure(const char* file, |
| 154 int line, | 156 int line, |
| 155 const char* function, | 157 const char* function, |
| 156 const char* assertion) { | 158 const char* assertion) { |
| 157 if (assertion) | 159 if (assertion) |
| 158 printf_stderr_common("ASSERTION FAILED: %s\n", assertion); | 160 printf_stderr_common("ASSERTION FAILED: %s\n", assertion); |
| 159 else | 161 else |
| 160 printf_stderr_common("SHOULD NEVER BE REACHED\n"); | 162 printf_stderr_common("SHOULD NEVER BE REACHED\n"); |
| 161 printCallSite(file, line, function); | 163 printCallSite(file, line, function); |
| 162 } | 164 } |
| 163 | 165 |
| 164 void WTFGetBacktrace(void** stack, int* size) { | 166 void WTFGetBacktrace(void** stack, int* size) { |
| 165 #if OS(MACOSX) || (OS(LINUX) && !defined(__UCLIBC__)) | 167 #if OS(MACOSX) || (OS(LINUX) && !defined(__UCLIBC__)) |
| 166 *size = backtrace(stack, *size); | 168 *size = backtrace(stack, *size); |
| 167 #elif OS(WIN) | 169 #elif OS(WIN) |
| 168 // The CaptureStackBackTrace function is available in XP, but it is not define
d | 170 // The CaptureStackBackTrace function is available in XP, but it is not |
| 169 // in the Windows Server 2003 R2 Platform SDK. So, we'll grab the function | 171 // defined in the Windows Server 2003 R2 Platform SDK. So, we'll grab the |
| 170 // through GetProcAddress. | 172 // function through GetProcAddress. |
| 171 typedef WORD(NTAPI * RtlCaptureStackBackTraceFunc)(DWORD, DWORD, PVOID*, | 173 typedef WORD(NTAPI * RtlCaptureStackBackTraceFunc)(DWORD, DWORD, PVOID*, |
| 172 PDWORD); | 174 PDWORD); |
| 173 HMODULE kernel32 = ::GetModuleHandleW(L"Kernel32.dll"); | 175 HMODULE kernel32 = ::GetModuleHandleW(L"Kernel32.dll"); |
| 174 if (!kernel32) { | 176 if (!kernel32) { |
| 175 *size = 0; | 177 *size = 0; |
| 176 return; | 178 return; |
| 177 } | 179 } |
| 178 RtlCaptureStackBackTraceFunc captureStackBackTraceFunc = | 180 RtlCaptureStackBackTraceFunc captureStackBackTraceFunc = |
| 179 reinterpret_cast<RtlCaptureStackBackTraceFunc>( | 181 reinterpret_cast<RtlCaptureStackBackTraceFunc>( |
| 180 ::GetProcAddress(kernel32, "RtlCaptureStackBackTrace")); | 182 ::GetProcAddress(kernel32, "RtlCaptureStackBackTrace")); |
| 181 if (captureStackBackTraceFunc) | 183 if (captureStackBackTraceFunc) |
| 182 *size = captureStackBackTraceFunc(0, *size, stack, 0); | 184 *size = captureStackBackTraceFunc(0, *size, stack, 0); |
| 183 else | 185 else |
| 184 *size = 0; | 186 *size = 0; |
| 185 #else | 187 #else |
| 186 *size = 0; | 188 *size = 0; |
| 187 #endif | 189 #endif |
| 188 } | 190 } |
| 189 | 191 |
| 190 void WTFReportBacktrace(int framesToShow) { | 192 void WTFReportBacktrace(int framesToShow) { |
| 191 static const int framesToSkip = 2; | 193 static const int framesToSkip = 2; |
| 192 // Use alloca to allocate on the stack since this function is used in OOM situ
ations. | 194 // Use alloca to allocate on the stack since this function is used in OOM |
| 195 // situations. |
| 193 void** samples = static_cast<void**>( | 196 void** samples = static_cast<void**>( |
| 194 alloca((framesToShow + framesToSkip) * sizeof(void*))); | 197 alloca((framesToShow + framesToSkip) * sizeof(void*))); |
| 195 int frames = framesToShow + framesToSkip; | 198 int frames = framesToShow + framesToSkip; |
| 196 | 199 |
| 197 WTFGetBacktrace(samples, &frames); | 200 WTFGetBacktrace(samples, &frames); |
| 198 WTFPrintBacktrace(samples + framesToSkip, frames - framesToSkip); | 201 WTFPrintBacktrace(samples + framesToSkip, frames - framesToSkip); |
| 199 } | 202 } |
| 200 | 203 |
| 201 namespace { | 204 namespace { |
| 202 | 205 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 printf_stderr_common("%-3d %p\n", frameNumber, stack[i]); | 333 printf_stderr_common("%-3d %p\n", frameNumber, stack[i]); |
| 331 } | 334 } |
| 332 } | 335 } |
| 333 | 336 |
| 334 void WTFLogAlways(const char* format, ...) { | 337 void WTFLogAlways(const char* format, ...) { |
| 335 va_list args; | 338 va_list args; |
| 336 va_start(args, format); | 339 va_start(args, format); |
| 337 vprintf_stderr_with_trailing_newline(format, args); | 340 vprintf_stderr_with_trailing_newline(format, args); |
| 338 va_end(args); | 341 va_end(args); |
| 339 } | 342 } |
| OLD | NEW |