Confirmed users
231
edits
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
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]. | 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]. | ||
= Starting the Debugger<br> = | == 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> | 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() | <pre>function startDebugger() | ||
{ | { | ||
| Line 18: | Line 18: | ||
// Attach listeners for client events. | // Attach listeners for client events. | ||
client.addListener("tabNavigated", onTab); | client.addListener("tabNavigated", onTab); | ||
client.addListener("newScript", | client.addListener("newScript", onScript); | ||
client.ready(function(aType, aTraits) { | client.ready(function(aType, aTraits) { | ||
// Now the client is conected to the server. | // Now the client is conected to the server. | ||
| Line 24: | Line 24: | ||
}); | }); | ||
} | } | ||
</pre> | </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> | 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() | <pre>function serverStartDebugger() | ||
{ | { | ||
| Line 39: | Line 39: | ||
function clientStartDebugger() | function clientStartDebugger() | ||
{ | { | ||
let transport = debuggerSocketConnect( | let transport = debuggerSocketConnect("localhost", 2929); | ||
// Start the client. | // Start the client. | ||
| Line 45: | Line 45: | ||
// Attach listeners for client events. | // Attach listeners for client events. | ||
client.addListener("tabNavigated", onTab); | client.addListener("tabNavigated", onTab); | ||
client.addListener("newScript", | client.addListener("newScript", onScript); | ||
client.ready(function(aType, aTraits) { | client.ready(function(aType, aTraits) { | ||
// Now the client is conected to the server. | // Now the client is conected to the server. | ||
| Line 51: | Line 51: | ||
}); | }); | ||
} | } | ||
</pre> | </pre> | ||
= Shutting down the Debugger<br> = | == 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: | |||
<pre>function shutdownDebugger() | <pre>function shutdownDebugger() | ||
{ | { | ||
client.close(); | client.close(); | ||
} | }</pre> | ||
== Debugging a browser tab<br> == | |||
Debugging a browser tab requires enumerating the available tabs, attaching to the current one, and then attaching to its thread. Threads in the debugger client API represent contexts.<br> | |||
<pre>function debugTab() | |||
function debugTab() | |||
{ | { | ||
// Get the list of tabs to find the one to attach to. | // Get the list of tabs to find the one to attach to. | ||
| Line 97: | Line 90: | ||
}); | }); | ||
} | } | ||
</pre> | |||
boo | |||
<br> | |||
<pre>function onTab() | |||
function onTab() | |||
{ | { | ||
// Detach from the previous thread. | // Detach from the previous thread. | ||