Debugger Client API: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
Line 1: Line 1:
Besides the low-level [https://developer.mozilla.org/en/SpiderMonkey/JS_Debugger_API_Guide JS Debugger API], there is a debugger client module that allows one to write an application that uses the [https://wiki.mozilla.org/Remote_Debugging_Protocol Remote Debugging Protocol] to drive the debugger.
Besides the "low-level", direct [https://developer.mozilla.org/en/SpiderMonkey/JS_Debugger_API_Guide JS Debugger API], there is a debugger client module that allows applications to be written that control the debugger using the [https://wiki.mozilla.org/Remote_Debugging_Protocol Remote Debugging Protocol].  
<pre>/*
* Debugger API demo.
* Try it in Scratchpad with Environment -&gt; Browser, using
* http://htmlpad.org/debugger/ as the current page.
*/
let client;
let threadClient;


function startDebugger()
= Starting the Debugger<br>  =
 
In order to communicate with the Debugger, a client and a server instance must be created and a protocol connection must be established. The connection can be either over a TCP socket or an nsIPipe. The startDebugger function displayed below establishes an nsIPipe-backed connection:<br>
<pre>function startDebugger()
{
{
   // Start the server.
   // Start the server.
Line 17: Line 13:
   // Listen to an nsIPipe
   // Listen to an nsIPipe
   let transport = DebuggerServer.connectPipe();
   let transport = DebuggerServer.connectPipe();
 
  // Start the client.
  client = new DebuggerClient(transport);
  // Attach listeners for client events.
  client.addListener("tabNavigated", onTab);
  client.addListener("newScript", fooListener);
  client.ready(function(aType, aTraits) {
    // Now the client is conected to the server.
    debugTab();
  });
}
</pre>
If a TCP socket is required, the function should be split in two parts, a server-side and a client-side, like this:<br>
<pre>function serverStartDebugger()
{
  // Start the server.
  if (!DebuggerServer.initialized) {
    DebuggerServer.init();
    DebuggerServer.addBrowserActors();
  }
   // For an nsIServerSocket we do this:
   // For an nsIServerSocket we do this:
   // DebuggerServer.openListener(aPort, aLocalOnly);
   DebuggerServer.openListener(2929, true); // A localhost-only connection on port 2929.
  // ...and this at the client:
}
   // let transport = debuggerSocketConnect(aHost, aPort);
 
function clientStartDebugger()
{
   let transport = debuggerSocketConnect(aHost, aPort);
    
    
   // Start the client.
   // Start the client.
Line 32: Line 51:
   });
   });
}
}
</pre>
= Shutting down the Debugger<br> =
When the application is finished, it has to notify the client to shut down the protocol connection. This makes sure that memory leaks are avoided and the server is terminated in an orderly fashion. Shutting down is as simple as it gets:
foo
boo


function shutdownDebugger()
<pre>function shutdownDebugger()
{
{
   client.close();
   client.close();
Confirmed users
231

edits

Navigation menu