Bug 171575 - Add a debugging macro that sleeps a thread until a debugger attaches
Summary: Add a debugging macro that sleeps a thread until a debugger attaches
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Template Framework (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: BJ Burg
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-05-02 14:48 PDT by BJ Burg
Modified: 2017-05-22 11:49 PDT (History)
8 users (show)

See Also:


Attachments
Patch (7.99 KB, patch)
2017-05-03 09:56 PDT, BJ Burg
no flags Details | Formatted Diff | Diff
Patch (6.50 KB, patch)
2017-05-03 10:03 PDT, BJ Burg
no flags Details | Formatted Diff | Diff
Patch (6.38 KB, patch)
2017-05-03 11:43 PDT, BJ Burg
no flags Details | Formatted Diff | Diff
For Landing (6.33 KB, patch)
2017-05-04 12:56 PDT, BJ Burg
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description BJ Burg 2017-05-02 14:48:50 PDT
I use this all the time, might as well check it in.
Comment 1 BJ Burg 2017-05-03 09:56:39 PDT
Created attachment 308917 [details]
Patch
Comment 2 BJ Burg 2017-05-03 10:03:52 PDT
Created attachment 308919 [details]
Patch
Comment 3 Build Bot 2017-05-03 10:04:36 PDT
Attachment 308919 [details] did not pass style-queue:


ERROR: Source/WTF/wtf/DebugUtilities.h:26:  Use #pragma once instead of #ifndef for header guard.  [build/header_guard] [5]
Total errors found: 1 in 4 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 4 Mark Lam 2017-05-03 11:03:37 PDT
Comment on attachment 308919 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=308919&action=review

> Source/WTF/wtf/Assertions.h:197
> -#if defined(NDEBUG) && OS(DARWIN)
>  #if CPU(X86_64) || CPU(X86)
>  #define WTFBreakpointTrap()  __asm__ volatile ("int3")
>  #elif CPU(ARM_THUMB2)
>  #define WTFBreakpointTrap()  __asm__ volatile ("bkpt #0")
>  #elif CPU(ARM64)
>  #define WTFBreakpointTrap()  __asm__ volatile ("brk #0")

I've only validated these asm statements on OS(DARWIN).  Are you sure they work for non-Darwin ports?
Comment 5 BJ Burg 2017-05-03 11:43:56 PDT
Created attachment 308932 [details]
Patch
Comment 6 Build Bot 2017-05-03 11:45:21 PDT
Attachment 308932 [details] did not pass style-queue:


ERROR: Source/WTF/wtf/DebugUtilities.h:26:  Use #pragma once instead of #ifndef for header guard.  [build/header_guard] [5]
Total errors found: 1 in 4 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 7 BJ Burg 2017-05-03 11:54:44 PDT
(In reply to Mark Lam from comment #4)
> Comment on attachment 308919 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=308919&action=review
> 
> > Source/WTF/wtf/Assertions.h:197
> > -#if defined(NDEBUG) && OS(DARWIN)
> >  #if CPU(X86_64) || CPU(X86)
> >  #define WTFBreakpointTrap()  __asm__ volatile ("int3")
> >  #elif CPU(ARM_THUMB2)
> >  #define WTFBreakpointTrap()  __asm__ volatile ("bkpt #0")
> >  #elif CPU(ARM64)
> >  #define WTFBreakpointTrap()  __asm__ volatile ("brk #0")
> 
> I've only validated these asm statements on OS(DARWIN).  Are you sure they
> work for non-Darwin ports?

I am unsure how they would differ. Software breakpoint instructions are a detail of the ISA, not the OS. Right?
Comment 8 Mark Lam 2017-05-03 12:00:58 PDT
(In reply to Brian Burg from comment #7)
> (In reply to Mark Lam from comment #4)
> > Comment on attachment 308919 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=308919&action=review
> > 
> > > Source/WTF/wtf/Assertions.h:197
> > > -#if defined(NDEBUG) && OS(DARWIN)
> > >  #if CPU(X86_64) || CPU(X86)
> > >  #define WTFBreakpointTrap()  __asm__ volatile ("int3")
> > >  #elif CPU(ARM_THUMB2)
> > >  #define WTFBreakpointTrap()  __asm__ volatile ("bkpt #0")
> > >  #elif CPU(ARM64)
> > >  #define WTFBreakpointTrap()  __asm__ volatile ("brk #0")
> > 
> > I've only validated these asm statements on OS(DARWIN).  Are you sure they
> > work for non-Darwin ports?
> 
> I am unsure how they would differ. Software breakpoint instructions are a
> detail of the ISA, not the OS. Right?

Yes, but inline asm statement syntax?
Comment 9 BJ Burg 2017-05-03 12:24:23 PDT
(In reply to Mark Lam from comment #8)
> (In reply to Brian Burg from comment #7)
> > (In reply to Mark Lam from comment #4)
> > > Comment on attachment 308919 [details]
> > > Patch
> > > 
> > > View in context:
> > > https://bugs.webkit.org/attachment.cgi?id=308919&action=review
> > > 
> > > > Source/WTF/wtf/Assertions.h:197
> > > > -#if defined(NDEBUG) && OS(DARWIN)
> > > >  #if CPU(X86_64) || CPU(X86)
> > > >  #define WTFBreakpointTrap()  __asm__ volatile ("int3")
> > > >  #elif CPU(ARM_THUMB2)
> > > >  #define WTFBreakpointTrap()  __asm__ volatile ("bkpt #0")
> > > >  #elif CPU(ARM64)
> > > >  #define WTFBreakpointTrap()  __asm__ volatile ("brk #0")
> > > 
> > > I've only validated these asm statements on OS(DARWIN).  Are you sure they
> > > work for non-Darwin ports?
> > 
> > I am unsure how they would differ. Software breakpoint instructions are a
> > detail of the ISA, not the OS. Right?
> 
> Yes, but inline asm statement syntax?

Oh, yeah, I have no idea. We seem to use the same macros in bmalloc (BAssert.h) and those are not specific to OS(DARWIN). Some of the 3rd-party libraries we use for WebRTC also use __asm__ volatile ("...") syntax. My understanding is that those build for GTK port as well.

In any case, this patch does not add new clients of these macros. If it is indeed broken with another compiler – something I can't verify myself – then the macros can be generalized in a later patch if it does not fail EWS.
Comment 10 Mark Lam 2017-05-04 10:22:55 PDT
Comment on attachment 308932 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=308932&action=review

r=me with suggested improvement.

> Source/WTF/wtf/Assertions.h:202
> +#define WTFBreakpointTrap()

Hmmm.  If we want to make WTFBreakpointTrap() an API for more general use, I question whether it's wise to allow it to fail silently like this if it's not defined.  Instead, how about defining it as:

#define WTFBreakpointTrap() WTFCrash() // Not implemented

If someone tries to use it, they will crash and the trail will lead to the "Not implemented" comment.
Comment 11 BJ Burg 2017-05-04 11:12:20 PDT
(In reply to Mark Lam from comment #10)
> Comment on attachment 308932 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=308932&action=review
> 
> r=me with suggested improvement.
> 
> > Source/WTF/wtf/Assertions.h:202
> > +#define WTFBreakpointTrap()
> 
> Hmmm.  If we want to make WTFBreakpointTrap() an API for more general use, I
> question whether it's wise to allow it to fail silently like this if it's
> not defined.  Instead, how about defining it as:
> 
> #define WTFBreakpointTrap() WTFCrash() // Not implemented
> 
> If someone tries to use it, they will crash and the trail will lead to the
> "Not implemented" comment.

OK
Comment 12 BJ Burg 2017-05-04 12:56:58 PDT
Created attachment 309093 [details]
For Landing
Comment 13 Build Bot 2017-05-04 12:58:13 PDT
Attachment 309093 [details] did not pass style-queue:


ERROR: Source/WTF/wtf/DebugUtilities.h:26:  Use #pragma once instead of #ifndef for header guard.  [build/header_guard] [5]
Total errors found: 1 in 4 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 14 BJ Burg 2017-05-22 11:49:09 PDT
Committed r217233: <http://trac.webkit.org/changeset/217233>
Comment 15 BJ Burg 2017-05-22 11:49:28 PDT
Comment on attachment 309093 [details]
For Landing

Landed manually.