Bug 866278: Remote debugging protocol: show sequence numbers with packets. r=past

This commit is contained in:
Jim Blandy 2013-04-29 16:16:14 -07:00
parent beb4258cf0
commit ec464eb0fd

View File

@ -205,6 +205,13 @@ this.LocalDebuggerTransport = function LocalDebuggerTransport(aOther)
{
this.other = aOther;
this.hooks = null;
/*
* A packet number, shared between this and this.other. This isn't used
* by the protocol at all, but it makes the packet traces a lot easier to
* follow.
*/
this._serial = this.other ? this.other._serial : { count: 0 };
}
LocalDebuggerTransport.prototype = {
@ -214,15 +221,23 @@ LocalDebuggerTransport.prototype = {
*/
send: function LDT_send(aPacket) {
try {
// Avoid the cost of JSON.stringify() when logging is disabled.
let serial = this._serial.count++;
if (wantLogging) {
dumpn("Got: " + JSON.stringify(aPacket, null, 2));
if (aPacket.to) {
dumpn("Packet " + serial + " sent to " + uneval(aPacket.to));
} else if (aPacket.from) {
dumpn("Packet " + serial + " sent from " + uneval(aPacket.from));
}
}
this._deepFreeze(aPacket);
let other = this.other;
Services.tm.currentThread.dispatch({run: function() {
Services.tm.currentThread.dispatch(function() {
// Avoid the cost of JSON.stringify() when logging is disabled.
if (wantLogging) {
dumpn("Received packet " + serial + ": " + JSON.stringify(aPacket, null, 2));
}
other.hooks.onPacket(aPacket);
}}, 0);
}, 0);
} catch(e) {
let msg = "Error handling incoming packet: " + e + " - " + e.stack;
if (Cu.reportError) {