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. |
(...skipping 25 matching lines...) Expand all Loading... |
36 | 36 |
37 #include "Compiler.h" | 37 #include "Compiler.h" |
38 #include "OwnPtr.h" | 38 #include "OwnPtr.h" |
39 #include "PassOwnPtr.h" | 39 #include "PassOwnPtr.h" |
40 | 40 |
41 #include <stdio.h> | 41 #include <stdio.h> |
42 #include <stdarg.h> | 42 #include <stdarg.h> |
43 #include <stdlib.h> | 43 #include <stdlib.h> |
44 #include <string.h> | 44 #include <string.h> |
45 | 45 |
46 #if HAVE(SIGNAL_H) | |
47 #include <signal.h> | |
48 #endif | |
49 | |
50 #if USE(CF) | 46 #if USE(CF) |
51 #include <AvailabilityMacros.h> | 47 #include <AvailabilityMacros.h> |
52 #include <CoreFoundation/CFString.h> | 48 #include <CoreFoundation/CFString.h> |
53 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 | 49 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 |
54 #define WTF_USE_APPLE_SYSTEM_LOG 1 | 50 #define WTF_USE_APPLE_SYSTEM_LOG 1 |
55 #include <asl.h> | 51 #include <asl.h> |
56 #endif | 52 #endif |
57 #endif // USE(CF) | 53 #endif // USE(CF) |
58 | 54 |
59 #if COMPILER(MSVC) | 55 #if COMPILER(MSVC) |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 for (int i = 0; i < size; ++i) { | 284 for (int i = 0; i < size; ++i) { |
289 FrameToNameScope frameToName(stack[i]); | 285 FrameToNameScope frameToName(stack[i]); |
290 const int frameNumber = i + 1; | 286 const int frameNumber = i + 1; |
291 if (frameToName.nullableName()) | 287 if (frameToName.nullableName()) |
292 printf_stderr_common("%-3d %p %s\n", frameNumber, stack[i], frameToN
ame.nullableName()); | 288 printf_stderr_common("%-3d %p %s\n", frameNumber, stack[i], frameToN
ame.nullableName()); |
293 else | 289 else |
294 printf_stderr_common("%-3d %p\n", frameNumber, stack[i]); | 290 printf_stderr_common("%-3d %p\n", frameNumber, stack[i]); |
295 } | 291 } |
296 } | 292 } |
297 | 293 |
298 static WTFCrashHookFunction globalHook = 0; | |
299 | |
300 void WTFSetCrashHook(WTFCrashHookFunction function) | |
301 { | |
302 globalHook = function; | |
303 } | |
304 | |
305 void WTFInvokeCrashHook() | |
306 { | |
307 if (globalHook) | |
308 globalHook(); | |
309 } | |
310 | |
311 #if HAVE(SIGNAL_H) | |
312 static NO_RETURN void dumpBacktraceSignalHandler(int sig) | |
313 { | |
314 WTFReportBacktrace(); | |
315 exit(128 + sig); | |
316 } | |
317 | |
318 static void installSignalHandlersForFatalErrors(void (*handler)(int)) | |
319 { | |
320 signal(SIGILL, handler); // 4: illegal instruction (not reset when caught
). | |
321 signal(SIGTRAP, handler); // 5: trace trap (not reset when caught). | |
322 signal(SIGFPE, handler); // 8: floating point exception. | |
323 signal(SIGBUS, handler); // 10: bus error. | |
324 signal(SIGSEGV, handler); // 11: segmentation violation. | |
325 signal(SIGSYS, handler); // 12: bad argument to system call. | |
326 signal(SIGPIPE, handler); // 13: write on a pipe with no reader. | |
327 signal(SIGXCPU, handler); // 24: exceeded CPU time limit. | |
328 signal(SIGXFSZ, handler); // 25: exceeded file size limit. | |
329 } | |
330 | |
331 static void resetSignalHandlersForFatalErrors() | |
332 { | |
333 installSignalHandlersForFatalErrors(SIG_DFL); | |
334 } | |
335 #endif | |
336 | |
337 void WTFInstallReportBacktraceOnCrashHook() | |
338 { | |
339 #if HAVE(SIGNAL_H) | |
340 // Needed otherwise we are going to dump the stack trace twice | |
341 // in case we hit an assertion. | |
342 WTFSetCrashHook(&resetSignalHandlersForFatalErrors); | |
343 installSignalHandlersForFatalErrors(&dumpBacktraceSignalHandler); | |
344 #endif | |
345 } | |
346 | |
347 void WTFReportFatalError(const char* file, int line, const char* function, const
char* format, ...) | 294 void WTFReportFatalError(const char* file, int line, const char* function, const
char* format, ...) |
348 { | 295 { |
349 va_list args; | 296 va_list args; |
350 va_start(args, format); | 297 va_start(args, format); |
351 vprintf_stderr_with_prefix("FATAL ERROR: ", format, args); | 298 vprintf_stderr_with_prefix("FATAL ERROR: ", format, args); |
352 va_end(args); | 299 va_end(args); |
353 printf_stderr_common("\n"); | 300 printf_stderr_common("\n"); |
354 printCallSite(file, line, function); | 301 printCallSite(file, line, function); |
355 } | 302 } |
356 | 303 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 } | 336 } |
390 | 337 |
391 void WTFLogAlways(const char* format, ...) | 338 void WTFLogAlways(const char* format, ...) |
392 { | 339 { |
393 va_list args; | 340 va_list args; |
394 va_start(args, format); | 341 va_start(args, format); |
395 vprintf_stderr_with_trailing_newline(format, args); | 342 vprintf_stderr_with_trailing_newline(format, args); |
396 va_end(args); | 343 va_end(args); |
397 } | 344 } |
398 | 345 |
OLD | NEW |