Platform/JSDebugv2: Difference between revisions

Jump to navigation Jump to search
m (→‎Design Summary: Make first reference to debugging protocol a link.)
Line 51: Line 51:
documentation.)</i>
documentation.)</i>


Debugger user interfaces communicate with debuggee threads using a [[Remote Debugging Protocol|remote
Debugger user interfaces communicate with the application being debugged via a [[Remote Debugging Protocol|remote debugging protocol]]. The protocol is JSON-based, with clients and servers typically implemented in JavaScript. The protocol is actor-oriented: each packet is directed to or received from a specific actor, representing a thread, breakpoint, JavaScript object, or the like.
debugging protocol]]. The protocol client (between debugger UI and protocol)
and server (between protocol and debuggee) are implemented in JavaScript,
built on a Web IDL interface available to other extensions as well. All inter-thread debugging uses the remote protocol.


The Web IDL interface, jsd2IDebuggerService, is an alternative to the
Every server provides a root actor that can provide global information about the application ("I am a web browser"), and enumerate the potential debuggees present in the application&mdash;tabs, worker threads, chrome, and so on&mdash;each represented by its own actor.
existing jsdIDebuggerService, wrapping a new C++ API whose classes are
defined in the js::dbg2 namespace.


The js::dbg2 facilities fall into three categories:
Actors representing individual JavaScript threads use the jsd2IDebuggerService Web IDL interface to inspect and manipulate the debuggee they represent. jsd2IDebuggerService is an alternative to the existing jsdIDebuggerService, implemented in terms of the js::dbg2 C++ interfaces.
<ul>
 
<li><b>Discovery facilities</b> allow the debugger UI to enumerate the
The code implementing thread actors runs in the threads they represent; the server routes debugging protocol packets to actors appropriately. All inter-thread communication is handled this way, so thread actors and the interfaces they use can be single-threaded.
browsing contexts, web workers, and so on available to be debugged in a given application.
 
<li><b>Dispatch facilities</b> identify events of interest to the debugger
The jsd2IDebuggerService Web IDL interface presents js::dbg2's facilities to JavaScript.  jsd2IDebuggerService is an alternative to the existing jsdIDebuggerService.
and dispatch them to the appropriate handlers.
 
<li><b>Inspection facilities</b> provide stack inspection, value inspection, and other traditional debugger tools.
The js::dbg2 interface provides functions to:
</ul>
 
* select code of interest to the developer (everything in a tab; a selected frame within a tab; chrome; and so on),
 
* establish breakpoints, watchpoints, and other sorts of monitoring, and be notified when events of interest occur,
 
* inspect and manipulate stack frames, scope chains, objects, and other such members of the JavaScript menagerie.


[[File:remote-dbg.png]]
[[File:Architecture-new.png]]


=== Remote debugging ===
=== Debugging Protocol ===


[[Remote Debugging Protocol|Remote debugging]], in which the debugger's user interface runs in a separate process from the debuggee and communicates with the debuggee over a stream connection, addresses many of our goals in one step:
[[Remote Debugging Protocol|Remote debugging]], in which the debugger's user interface can run in a separate process from the debuggee and communicates with the debuggee over a stream connection, addresses many of our goals at once:
<ul>
<ul>
<li><b>A remote debugger is easier to make robust.</b> The debugger's user
<li><b>A debugger running in a separate process from the debuggee is easier to make robust.</b> The debugger's user interface and the debuggee need not share an event loop or a chrome DOM tree.
interface and the debuggee do not share an event loop or a chrome DOM tree.
<li><b>Remote debugging eases mobile development.</b> The debugger could run on a desktop computer, and operate on a debuggee on a mobile device.
<li><b>Remote debugging eases mobile development.</b> The debugger can
<li><b>The remote protocol can handle almost all inter-thread communication.</b> Each actor runs on the same thread as the debuggee it represents, so actor/debuggee interactions are intra-thread, and need not worry about synchronization or shared state. Actors and the application's main server interact only by exchanging protocol packets. The debugger
run on a desktop computer, and operate on a debuggee on a mobile device.
user interface simply needs to be able to talk to more than one agent at a time.<p>(Note that some operations are inherently cross-thread: enumerating
<li><b>The remote protocol can handle almost all communication with worker
threads.</b> The "server" for the remote protocol will be lightweight
enough that each thread will be able to run its own instance. The debugger
user interface will then simply be responsible for being a client to
multiple debug servers at once. All cross-thread interaction will be
mediated by the remote protocol, greatly simplifying the implementation.
<p>(Note that some operations are inherently cross-thread: enumerating
currently running threads; thread creation notifications; the initial
currently running threads; thread creation notifications; the initial
attachment of the debugger to a thread. But once a thread has been attached
attachment of the debugger to a thread. But once a thread has been attached
Line 91: Line 84:
</ul>
</ul>


=== jsd2IDebuggerService and the js::dbg2 Interfaces ===
=== The js::dbg2 Interfaces and jsd2IDebuggerService ===


The [[js::dbg2|js::dbg2 interfaces]], wrapped for JavaScript as the
The [[js::dbg2|js::dbg2 interfaces]], wrapped for JavaScript as the jsd2IDebuggerService, allow the debugger to select the code to debug, set breakpoints and watchpoints and otherwise express interest in debuggee
jsd2IDebuggerService, allow the debugger to discover and select debuggees,
behaviors, and inspect the debuggee's state.
set breakpoints and watchpoints and otherwise express interest in debuggee
behaviors, and inspect a debuggee's state.


Whereas the existing jsd interface works in terms of the original
The js::dbg2 interfaces operate at a higher level than jsd. Whereas jsd works in terms of the original SpiderMonkey bytecode interpreter&mdash;JSScript objects, bytecode offsets, JSStackFrame objects, and so on&mdash;the js::dbg2 interfaces operate at the JavaScript source code and value level, and avoid referring to
SpiderMonkey bytecode interpreter&mdash;JSScript objects, bytecode offsets,
JSStackFrame objects, and so on&mdash;the js::dbg2 interfaces operate at
the JavaScript source code and value level, and avoid referring to
specifics of the implementation. This makes it easier to support debugging
specifics of the implementation. This makes it easier to support debugging
of TraceMonkey- and JägerMonkey-compiled code: such code need not present
of TraceMonkey- and JägerMonkey-compiled code: such code need not present
Line 107: Line 95:
use.
use.


Like jsd, js::dbg2 provides proxy objects that refer to values in the
Like jsd, js::dbg2 provides <i>grip</i> objects that refer to values in the
debuggee. These prevent the debugger code from accidentally invoking
debuggee. The debugger can inspect the object's properties, their attributes, and so on via the grip without accidentally invoking getters or setters, making it easier to write secure and robust debuggers.
getters or setters, making it easier to write secure and robust debuggers.


Again like jsd, js::dbg2 provides proxy objects referring to JavaScript
Also like jsd, js::dbg2 provides grip objects referring to JavaScript stack frames. However, there is no necessary correspondence between js::dbg2 stack frame grips and SpiderMonkey's internal JSStackFrame objects. SpiderMonkey's JITs are free to report the current function activations to js::dbg2 in whatever way is most convenient to them; they are not required to synthesize JSStackFrame objects, which must satisfy complex internal constraints.
stack frames. However, there is no necessary correspondence between
js::dbg2 stack frame proxies and SpiderMonkey's internal JSStackFrame
objects. SpiderMonkey's JITs are free to report the current function
activations to js::dbg2 in whatever way is most convenient to them; they
are not required to synthesize JSStackFrame objects, which must satisfy
complex internal constraints.
 
The js::dbg2 interfaces provide a flexible way for debuggers to specify
what they are interested in debugging. A debugging <i>sphere</i> recognizes
events of interest and dispatches them to handlers. js::dbg2 provides
the following sphere types:
<ul>
<li>the top-level browsing context of a tab
<li>the tab's top-level browsing context, and any descendant browsing contexts
<li>chrome scripts
<li>specific worker threads
</ul>
We will add sphere types for new uses as we identify them: segregating out
particular pieces of mashups; ignoring advertisement iframes; and so on.


= Tasks and Estimates =
= Tasks and Estimates =
Confirmed users
496

edits

Navigation menu