Bug 142914 - Web Inspector: Add Function Breakpoints/Tracepoints (like Symbolic Breakpoints)
Summary: Web Inspector: Add Function Breakpoints/Tracepoints (like Symbolic Breakpoints)
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Devin Rousso
URL:
Keywords: InRadar
Depends on:
Blocks: 243717 244642 243716 244717
  Show dependency treegraph
 
Reported: 2015-03-20 11:50 PDT by Joseph Pecoraro
Modified: 2022-09-02 10:38 PDT (History)
7 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 2015-03-20 11:50:02 PDT
* SUMMARY
Add Function Breakpoints/Tracepoints (like Symbolic Breakpoints).

Often something you want to do is "pause when window.focus is called", or "do a console.trace every time Element.prototype.querySelector is called". It is possible to swizzle these functions out and get the functionality but that is cumbersome and doesn't play well with the inspector.

It would be awesome if you could create a function breakpoint in Web Inspector's UI. Or via the console like `debug(window.focus)` or `trace(Element.prototype, "querySelector")` which would show up as a Breakpoint in Web Inspector and managed by Web Inspector. We may be able to avoid swizzling if the feature is in the engine.

By having Web Inspector know about and manage these function breakpoints it has the opportunity to persist the breakpoints, carry them forward through navigations so you don't need to re-set them, and apply them to sub-frames automatically.
- If the function breakpoints is set on a Native Function that is not a JSBoundFunction, then e should be able to restore the breakpoint immediately after navigation (when the global object is cleared).
- Tricky with native getters/setters (Object.getOwnPropertyDescriptor(MouseEvent.prototype, "altKey").get) but that could be made to work.

* NOTES
Existing snippets that do things like this:
- https://github.com/NV/captureCalls.js
- https://gist.github.com/NV/5376464
- https://github.com/paulirish/break-on-access
Comment 1 Radar WebKit Bug Importer 2015-03-20 11:50:24 PDT
<rdar://problem/20242025>
Comment 2 Joseph Pecoraro 2015-03-20 11:56:13 PDT
> - https://github.com/paulirish/break-on-access

I believe this will even swizzle out a value descriptor with a getter/setter so that you can break on any access to the original property. That also sounds useful.

Also, integration with the text editor to quickly set these breakpoints on member variables sounds useful as well.
Comment 3 Joseph Pecoraro 2017-02-20 19:03:51 PST
Mark mentioned this may be easy with Native functions by inserting a middle thunk into the JITCode entry for Native Functions. This wouldn't work for built-in / Intrinsic functions though.
Comment 4 Devin Rousso 2022-08-08 22:14:53 PDT
Pull request: https://github.com/WebKit/WebKit/pull/3140
Comment 5 EWS 2022-08-12 02:17:29 PDT
Committed 253374@main (631ebd578bab): <https://commits.webkit.org/253374@main>

Reviewed commits have been landed. Closing PR #3140 and removing active labels.