associate stack trace for function call with sequence number

This commit is contained in:
Andrey Sidorov 2011-09-11 23:02:53 +10:00
parent d6bc4d5c32
commit 9e0b53c793

View file

@ -59,7 +59,8 @@ function XClient(stream, displayNum, screenNum)
this.rcrc_id = 0; // generated for each new resource
this.seq_num = 0; // incremented in each request. (even if we don't expect reply)
this.seq2stack = {}; // debug: map seq_num to stack at the moment request was issued
// in/out packets indexed by sequence ID
//this.requests = {};
this.replies = {};
@ -104,6 +105,12 @@ XClient.prototype.importRequestsFromTemplates = function(target, reqs)
target[r] = (function(reqName) {
var reqFunc = function req_proxy() {
client.seq_num++; // TODO: handle overflow (seq should be last 15 (?) bits of the number
var err = new Error;
err.name = r;
Error.captureStackTrace(err, arguments.callee);
client.seq2stack[client.seq_num] = err.stack;
// is it fast?
var args = Array.prototype.slice.call(req_proxy.arguments);
@ -221,9 +228,10 @@ XClient.prototype.expectReplyHeader = function()
{
var error_code = res[1];
var error = {};
error.code = error_code;
error.error = error_code;
error.seq = seq_num;
error.message = xerrors.errorText[error_code];
error.stack = client.seq2stack[error.seq]
// unpack error packet (32 bytes for all error types, 8 of them in CCSL header)
client.pack_stream.get(24, function(buf) {
@ -240,6 +248,9 @@ XClient.prototype.expectReplyHeader = function()
if (handler) {
var callback = handler[1];
callback(error);
if (!error.handled)
client.emit('error', error);
delete client.seq2stack[seq_num];
delete client.replies[seq_num];
} else
client.emit('error', error);