Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

multiple ui instances can now connect to a single debug session. firs…

…t step toward collaborative debugging
  • Loading branch information...
commit b7fd43e1b0ce2ff68b8a9e13a059eee32389f1ca 1 parent 61dfe89
@dannycoates dannycoates authored
View
76 bin/session.js
@@ -46,21 +46,89 @@ exports.createSession = function(options) {
var httpServer = http.createServer(staticFile);
var wsServer = ws.createServer(null, httpServer);
var debug = null;
+ var breakpoints = {};
+ var pending = {};
+ var direct = ['scripts',
+ 'scope',
+ 'lookup',
+ 'evaluate',
+ 'backtrace',
+ 'listbreakpoints'];
+
+ function breakpointReturnFilter(msg) {
+ switch (msg.command) {
+ case 'setbreakpoint':
+ case 'clearbreakpoint':
+ case 'changebreakpoint':
+ msg.arguments = breakpoints[msg.request_seq];
+ delete breakpoints[msg.request_seq];
+ break;
+ default:
+ break;
+ }
+ return msg;
+ }
+
+ function breakpointRequestFilter(msg) {
+ switch (msg.command) {
+ case 'setbreakpoint':
+ case 'clearbreakpoint':
+ case 'changebreakpoint':
+ breakpoints[msg.seq] = msg.arguments;
+ break;
+ default:
+ break;
+ }
+ return msg;
+ }
+
+ function getConnection(msg) {
+ var conn = pending[msg.request_seq];
+ delete pending[msg.request_seq];
+ return conn;
+ }
+
+ function handleRequest(conn, data) {
+ var msg = JSON.parse(data);
+ if (direct.indexOf(msg.command) > -1) {
+ pending[msg.seq] = conn;
+ }
+ else {
+ breakpointRequestFilter(msg);
+ }
+ debug.request(data);
+ }
+
+ function handleMessage(msg) {
+ if (msg.type === 'response' && direct.indexOf(msg.command) > -1) {
+ var conn = getConnection(msg);
+ if (conn) {
+ conn.write(JSON.stringify(msg));
+ }
+ else {
+ console.error('forgot who to reply to');
+ }
+ }
+ else {
+ var bmsg = breakpointReturnFilter(msg);
+ wsServer.broadcast(JSON.stringify(bmsg));
+ }
+ }
wsServer.on('connection', function(conn) {
if (!debug) {
// first connection
debug = debugr.attachDebugger(settings.debugPort);
- debug.on('data', function(data) {
- wsServer.broadcast(JSON.stringify(data));
+ debug.on('data', function(msg) {
+ handleMessage(msg);
});
debug.on('close', function() {
debug = null;
session.close();
});
}
- conn.on('message', function(msg) {
- debug.request(msg);
+ conn.on('message', function(data) {
+ handleRequest(conn, data);
});
session.emit('connection', conn);
});
View
21 front-end/node/Debugger.js
@@ -1,6 +1,5 @@
WebInspector.nodeDebugger = (function() {
var socket = null;
- var seq = 1;
var callbacks = {};
var breakpoints = {};
var listeners = {};
@@ -24,7 +23,7 @@ WebInspector.nodeDebugger = (function() {
function makeRequest(command, params) {
var msg = {
- seq: seq++,
+ seq: Math.floor((Math.random() * 999999999999)),
type: 'request',
command: command
}
@@ -86,7 +85,8 @@ WebInspector.nodeDebugger = (function() {
arguments: {
breakpoint: bp,
enabled: enabled,
- condition: condition}});
+ condition: condition,
+ id: sourceID + ':' + line}}, callId);
}
else {
sendRequest('setbreakpoint',{
@@ -96,13 +96,14 @@ WebInspector.nodeDebugger = (function() {
line: line - 1,
enabled: enabled,
condition: condition
- }}, {id: sourceID + ':' + line, line: line, callId: callId});
+ }}, callId);
}
},
clearBreakpoint: function(sourceID, line) {
var id = sourceID + ':' + line;
sendRequest('clearbreakpoint', {
- arguments: { breakpoint: breakpoints[id] }}, id);
+ arguments: { breakpoint: breakpoints[id],
+ id: id }}, id);
},
listBreakpoints: function() {
sendRequest('listbreakpoints');
@@ -147,11 +148,17 @@ WebInspector.nodeDebugger = (function() {
};
debugr.on('setbreakpoint', function(msg) {
- breakpoints[msg.callId.id] = msg.body.breakpoint;
+ if (msg.arguments) {
+ var a = msg.arguments;
+ breakpoints[a.target + ':' + (a.line + 1)] = msg.body.breakpoint;
+ }
});
debugr.on('clearbreakpoint', function(msg) {
- delete breakpoints[msg.callId];
+ if (msg.arguments) {
+ var a = msg.arguments;
+ delete breakpoints[a.id]
+ }
});
debugr.on('listbreakpoints', function(msg) {
View
49 front-end/node/InspectorFrontendHostStub.js
@@ -30,6 +30,9 @@
if (!window.InspectorFrontendHost) {
+//FIXME temporary hack for the taskbar color
+WebInspector._platformFlavor = WebInspector.PlatformFlavor.MacTiger;
+
WebInspector.InspectorFrontendHostStub = function()
{
this._attachedWindowHeight = 0;
@@ -46,7 +49,7 @@ WebInspector.InspectorFrontendHostStub = function()
});
}
};
- //TODO find a place for these
+ //TODO find a place for these
function _valueOf(value) {
var p = {};
switch (value.type) {
@@ -80,14 +83,14 @@ WebInspector.InspectorFrontendHostStub = function()
};
function _property(prop) {
- var p = controller._valueOf(prop.value);
+ var p = _valueOf(prop.value);
p.name = String(prop.name);
return p;
};
function refToProperties(ref) {
if (ref) {
- return ref.properties.map(controller._property);
+ return ref.properties.map(_property);
}
};
@@ -97,6 +100,9 @@ WebInspector.InspectorFrontendHostStub = function()
WebInspector.parsedScriptSource(s.id, s.name, s.source, s.lineOffset, 0);
});
debugr.listBreakpoints();
+ if (!msg.running) {
+ debugr.getBacktrace();
+ }
});
debugr.on('scope', function(msg) {
WebInspector.Callback.processCallback(msg.callId, refToProperties(msg.body.object));
@@ -108,7 +114,7 @@ WebInspector.InspectorFrontendHostStub = function()
});
debugr.on('lookup', function(msg) {
var ref = msg.body[Object.keys(msg.body)[0]];
- WebInspector.Callback.processCallback(msg.callId, controller.refToProperties(ref));
+ WebInspector.Callback.processCallback(msg.callId, refToProperties(ref));
});
debugr.on('evaluate', function(msg) {
if (msg.success) {
@@ -119,10 +125,34 @@ WebInspector.InspectorFrontendHostStub = function()
}
});
debugr.on('setbreakpoint', function(msg) {
- WebInspector.didSetBreakpoint(msg.callId.callId, true, msg.callId.line);
+ if (msg.callId) {
+ var a = msg.arguments;
+ WebInspector.didSetBreakpoint(msg.callId, true, a.line + 1);
+ }
+ else {
+ // a different window set a breakpoint
+ debugr.listBreakpoints();
+ }
});
debugr.on('clearbreakpoint', function(msg) {
-
+ var bp = WebInspector.breakpointManager._breakpoints[msg.arguments.id];
+ if (bp) {
+ WebInspector.breakpointManager._removeBreakpoint(bp);
+ }
+ });
+ debugr.on('changebreakpoint', function(msg) {
+ if (msg.callId == null) {
+ var bp = WebInspector.breakpointManager._breakpoints[msg.arguments.id];
+ if (bp) {
+ bp._enabled = msg.arguments.enabled;
+ if(bp.enabled) {
+ bp.dispatchEventToListeners("enabled");
+ }
+ else {
+ bp.dispatchEventToListeners("disabled");
+ }
+ }
+ }
});
debugr.on('listbreakpoints', function(msg) {
WebInspector.breakpointManager.reset();
@@ -174,7 +204,12 @@ WebInspector.InspectorFrontendHostStub = function()
WebInspector.pausedScript(callFrames);
});
debugr.on('continue', function(msg) {
-
+ if(WebInspector.panels.scripts._paused) {
+ var panel = WebInspector.panels.scripts;
+ panel._paused = false;
+ panel._waitingToPause = false;
+ panel._clearInterface();
+ }
});
debugr.on('frame', function(msg) {
View
12 readme.md
@@ -6,6 +6,7 @@ Node Inspector is a debugger interface for nodeJS using the WebKit Web Inspector
* [nodeJS](http://github.com/ry/node)
- versions: 0.1.100 - 0.1.101
+* A WebKit based browser: Chrome, Safari, OmniWeb, etc.
### Setup
@@ -18,7 +19,7 @@ Node Inspector is a debugger interface for nodeJS using the WebKit Web Inspector
### Debugging
-(NEW) There are two ways to use node-inspector. First I'll describe the easy way.
+There are two ways to use node-inspector. First I'll describe the easy way.
As an example lets debug test/hello.js, from the root project directory (node-inspector)
1. start the inspector like this:
@@ -43,6 +44,8 @@ external node process.
3. open http://127.0.0.1:8000
+For more information on getting started see the [wiki](http://wiki.github.com/dannycoates/node-inspector/getting-started-from-scratch)
+
## Options
--start=[file] starts [file] in a child process with node_g --debug
@@ -53,7 +56,7 @@ external node process.
## Extensions
-This project started as a Chrome extension. For more info see the wiki.
+This project started as a Chrome extension. For more info see the [wiki](http://wiki.github.com/dannycoates/node-inspector/google-chrome-extension).
## Cool stuff
@@ -63,12 +66,11 @@ This project started as a Chrome extension. For more info see the wiki.
## Known Issues
-This is pre-alpha quality code, so use at your own risk:
+This is alpha quality code, so use at your own risk:
* while not stopped at a breakpoint the console doesn't always behave as you might expect
* pause on exceptions doesn't play nice with the node event loop
* closing the inspector does not stop debugging, you must stop inspector.js manually
-* opening more than one inspector window causes trouble
## Other Ideas
@@ -79,10 +81,8 @@ This is pre-alpha quality code, so use at your own risk:
## TODOS
* save application settings
-* single instance only
* debug-agent needs a lot of work
* try out live edit
-* Safari 5 extension
## Thanks
View
2  test/hello.js
@@ -6,5 +6,5 @@ http.createServer(function (req, res) {
x += 1;
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World ' + x);
-}).listen(8124, "127.0.0.1");
+}).listen(8124);
console.log('Server running at http://127.0.0.1:8124/');
Please sign in to comment.
Something went wrong with that request. Please try again.