Bug 173625 - Web Inspector: Should be able to pause and debug a StackOverflow Exception
Summary: Web Inspector: Should be able to pause and debug a StackOverflow Exception
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2017-06-20 16:57 PDT by Joseph Pecoraro
Modified: 2017-06-21 22:27 PDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph Pecoraro 2017-06-20 16:57:19 PDT
Summary:
Should be able to pause and debug a StackOverflow Exception

Test:
<script>
function a() { f(); }
function b() { f(); }
function f() { f(); }
if (Math.random() < 0.5)
    a();
else
    b();
</script>

Steps to reproduce:
1. Inspect test page
2. Enable: Pause on All Exceptions
3. Reload the page
  => Should pause on Stack Overflow Exception
  => Should be able to ultimately see the start of the stack (`a` or `b`)
  => Should be able to evaluate in console
Comment 1 Joseph Pecoraro 2017-06-20 17:30:07 PDT
Steps:

• Improve the performance of pausing with large callstacks
  - Profile to see where time is spent and address it
  - We can lazily gather scope information instead of sending it all up front
  - We can paginate the # of call frames. We don't need to send 1000 up front

• When Inspector Debugging is enabled Swizzle the VM's stackLimit with one that has space for debugging frames (say 10kb)
  - When hitting stack overflow + pausing replace the stackLimit with the original
  - User should be able to evaluate + debug things to a reasonable degree
  - When continuing go back to the swizzled stackLimit
  - When inspector debugger detaches go back to the original stackLimit
Comment 2 Radar WebKit Bug Importer 2017-06-20 17:36:57 PDT
<rdar://problem/32887643>
Comment 3 Mark Lam 2017-06-21 22:27:38 PDT
FYI, you should take a look at JSC's Options::softReservedZoneSize() and Options::reservedZoneSize().

Under normal circumstances, JS stack usage is bounded by stack size - reserved zone size.  Stack size is determined by the lower of Options::maxPerThreadStackUsage() or system stack size.  The reserved zone size (or commonly known in OS parlance as the stack red zone size) is normally set to Options::softReservedZoneSize().  However, when handling an exception (e.g. when creating Error objects), the VM reduces the reserved zone size to Options::reservedZoneSize().  This gives the error code a little more room to play in.  The default difference between Options::softReservedZoneSize() and Options::reservedZoneSize() is 64K.

In order to not overflow the stack again while handling a StackOverflow, the Inspector code needs to play within this 64K range.  Note, not all of the 64K is available to the inspector.  The VM and native host code also uses some stack space.