diff options
| author | Miroslav Bajtoš <miro.bajtos@gmail.com> | 2013-04-26 08:05:33 +0200 |
|---|---|---|
| committer | Ben Noordhuis <info@bnoordhuis.nl> | 2013-04-27 12:51:22 +0200 |
| commit | 5db936d2aecaddb5d539855a150813e36df45b66 (patch) | |
| tree | d759739fe02f5f89ca996761480e78087b112f41 /lib/_debugger.js | |
| parent | fd9e01c031ac843955532af4dd87b5caec38ba73 (diff) | |
| download | node-5db936d2aecaddb5d539855a150813e36df45b66.tar.gz | |
debugger: breakpoints in scripts not loaded yet
When developer calls setBreakpoint with an unknown script name,
we convert the script name into regular expression matching all
paths ending with given name (name can be a relative path too).
To create such breakpoint in V8, we use type `scriptRegEx`
instead of `scriptId` for `setbreakpoint` request.
To restore such breakpoint, we save the original script name
send by the user. We use this original name to set (restore)
breakpoint in the new child process.
Diffstat (limited to 'lib/_debugger.js')
| -rw-r--r-- | lib/_debugger.js | 55 |
1 files changed, 34 insertions, 21 deletions
diff --git a/lib/_debugger.js b/lib/_debugger.js index 106e55cb5..170f5e7e6 100644 --- a/lib/_debugger.js +++ b/lib/_debugger.js @@ -1385,16 +1385,28 @@ Interface.prototype.setBreakpoint = function(script, line, scriptId = script; } - if (!scriptId) return this.error('Script : ' + script + ' not found'); if (ambiguous) return this.error('Script name is ambiguous'); if (line <= 0) return this.error('Line should be a positive value'); - var req = { - type: 'scriptId', - target: scriptId, - line: line - 1, - condition: condition - }; + var req; + if (scriptId) { + req = { + type: 'scriptId', + target: scriptId, + line: line - 1, + condition: condition + }; + } else { + this.print('Warning: script \'' + script + '\' was not loaded yet.'); + var normalizedPath = script.replace('([/.?*])', '\\$1'); + var scriptPathRegex = '^(.*[\\/\\\\])?' + normalizedPath + '$'; + req = { + type: 'scriptRegExp', + target: scriptPathRegex, + line: line - 1, + condition: condition + }; + } } self.pause(); @@ -1411,20 +1423,18 @@ Interface.prototype.setBreakpoint = function(script, line, // Try load scriptId and line from response if (!scriptId) { scriptId = res.script_id; - line = res.line; - } - - // If we finally have one - remember this breakpoint - if (scriptId) { - self.client.breakpoints.push({ - id: res.breakpoint, - scriptId: scriptId, - script: (self.client.scripts[scriptId] || {}).name, - line: line, - condition: condition - }); + line = res.line + 1; } + // Remember this breakpoint even if scriptId is not resolved yet + self.client.breakpoints.push({ + id: res.breakpoint, + scriptId: scriptId, + script: (self.client.scripts[scriptId] || {}).name, + line: line, + condition: condition, + scriptReq: script + }); } self.resume(); }); @@ -1439,7 +1449,9 @@ Interface.prototype.clearBreakpoint = function(script, line) { index; this.client.breakpoints.some(function(bp, i) { - if (bp.scriptId === script || bp.script.indexOf(script) !== -1) { + if (bp.scriptId === script || + bp.scriptReq === script || + (bp.script && bp.script.indexOf(script) !== -1)) { if (index !== undefined) { ambiguous = true; } @@ -1657,7 +1669,8 @@ Interface.prototype.trySpawn = function(cb) { // Restore breakpoints breakpoints.forEach(function(bp) { - self.setBreakpoint(bp.scriptId, bp.line, bp.condition, true); + self.print('Restoring breakpoint ' + bp.scriptReq + ':' + bp.line); + self.setBreakpoint(bp.scriptReq, bp.line, bp.condition, true); }); client.on('close', function() { |
