Title: [217233] trunk/Source/WTF
Revision
217233
Author
bb...@apple.com
Date
2017-05-22 11:49:02 -0700 (Mon, 22 May 2017)

Log Message

Add a debugging macro that sleeps a thread until a debugger attaches
https://bugs.webkit.org/show_bug.cgi?id=171575

Reviewed by Mark Lam.

This is really useful for debugging early errors if for some reason you can't
launch a process directly from the debugger easily, such as Web Content processes.

* WTF.xcodeproj/project.pbxproj:
* wtf/Assertions.h:
Always define the WTFBreakpointTrap() macro. Still make it an error if the CPU
type isn't supported for OS(DARWIN); if used on other platforms, cause a WTFCrash()
with a comment that indicates this is not implemented.

* wtf/DebugUtilities.h: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (217232 => 217233)


--- trunk/Source/WTF/ChangeLog	2017-05-22 18:38:57 UTC (rev 217232)
+++ trunk/Source/WTF/ChangeLog	2017-05-22 18:49:02 UTC (rev 217233)
@@ -1,3 +1,21 @@
+2017-05-22  Brian Burg  <bb...@apple.com>
+
+        Add a debugging macro that sleeps a thread until a debugger attaches
+        https://bugs.webkit.org/show_bug.cgi?id=171575
+
+        Reviewed by Mark Lam.
+
+        This is really useful for debugging early errors if for some reason you can't
+        launch a process directly from the debugger easily, such as Web Content processes.
+
+        * WTF.xcodeproj/project.pbxproj:
+        * wtf/Assertions.h:
+        Always define the WTFBreakpointTrap() macro. Still make it an error if the CPU
+        type isn't supported for OS(DARWIN); if used on other platforms, cause a WTFCrash()
+        with a comment that indicates this is not implemented.
+
+        * wtf/DebugUtilities.h: Added.
+
 2017-05-19  Don Olmstead  <don.olmst...@am.sony.com>
 
         [WTF] Remove PLATFORM(WIN) references

Modified: trunk/Source/WTF/WTF.xcodeproj/project.pbxproj (217232 => 217233)


--- trunk/Source/WTF/WTF.xcodeproj/project.pbxproj	2017-05-22 18:38:57 UTC (rev 217232)
+++ trunk/Source/WTF/WTF.xcodeproj/project.pbxproj	2017-05-22 18:49:02 UTC (rev 217233)
@@ -337,6 +337,7 @@
 		93DDE9311CDC052D00FD3491 /* dyldSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = dyldSPI.h; sourceTree = "<group>"; };
 		93F1993D19D7958D00C2390B /* StringView.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringView.cpp; sourceTree = "<group>"; };
 		974CFC8D16A4F327006D5404 /* WeakPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WeakPtr.h; sourceTree = "<group>"; };
+		996B17841EBA441C007E10EB /* DebugUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DebugUtilities.h; sourceTree = "<group>"; };
 		9BC70F04176C379D00101DEC /* AtomicStringTable.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AtomicStringTable.cpp; sourceTree = "<group>"; };
 		9BD8F40A176C2AD80002D865 /* AtomicStringTable.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AtomicStringTable.h; sourceTree = "<group>"; };
 		9C67C542589348E285B49699 /* IndexedContainerIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IndexedContainerIterator.h; sourceTree = "<group>"; };
@@ -759,6 +760,7 @@
 				A8A47278151A825A004123FF /* DataLog.h */,
 				A8A47279151A825A004123FF /* DateMath.cpp */,
 				A8A4727A151A825A004123FF /* DateMath.h */,
+				996B17841EBA441C007E10EB /* DebugUtilities.h */,
 				A8A4727B151A825A004123FF /* DecimalNumber.cpp */,
 				A8A4727C151A825A004123FF /* DecimalNumber.h */,
 				E3E158251EADA53C004A079D /* SystemFree.h */,

Modified: trunk/Source/WTF/wtf/Assertions.h (217232 => 217233)


--- trunk/Source/WTF/wtf/Assertions.h	2017-05-22 18:38:57 UTC (rev 217232)
+++ trunk/Source/WTF/wtf/Assertions.h	2017-05-22 18:49:02 UTC (rev 217233)
@@ -189,9 +189,6 @@
 
 WTF_EXPORT_PRIVATE bool WTFIsDebuggerAttached();
 
-#ifndef CRASH
-
-#if defined(NDEBUG) && OS(DARWIN)
 #if CPU(X86_64) || CPU(X86)
 #define WTFBreakpointTrap()  __asm__ volatile ("int3")
 #elif CPU(ARM_THUMB2)
@@ -199,9 +196,12 @@
 #elif CPU(ARM64)
 #define WTFBreakpointTrap()  __asm__ volatile ("brk #0")
 #else
-#error "Unsupported CPU".
+#define WTFBreakpointTrap() WTFCrash() // Not implemented.
 #endif
 
+#ifndef CRASH
+
+#if defined(NDEBUG) && OS(DARWIN)
 // Crash with a SIGTRAP i.e EXC_BREAKPOINT.
 // We are not using __builtin_trap because it is only guaranteed to abort, but not necessarily
 // trigger a SIGTRAP. Instead, we use inline asm to ensure that we trigger the SIGTRAP.
@@ -213,7 +213,7 @@
 #define CRASH() WTFCrash()
 #endif
 
-#endif // CRASH
+#endif // !defined(CRASH)
 
 WTF_EXPORT_PRIVATE NO_RETURN_DUE_TO_CRASH void WTFCrash();
 

Added: trunk/Source/WTF/wtf/DebugUtilities.h (0 => 217233)


--- trunk/Source/WTF/wtf/DebugUtilities.h	                        (rev 0)
+++ trunk/Source/WTF/wtf/DebugUtilities.h	2017-05-22 18:49:02 UTC (rev 217233)
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WTF_DebugUtilities_h
+#define WTF_DebugUtilities_h
+
+#include <wtf/Assertions.h>
+
+#define SLEEP_THREAD_FOR_DEBUGGER() \
+do { \
+    do { \
+        sleep(1); \
+        if (WTFIsDebuggerAttached()) \
+            break; \
+    } while (1); \
+    WTFBreakpointTrap(); \
+} while (0)
+
+#endif /* WTF_DebugUtilities_h */
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to