summaryrefslogtreecommitdiff
path: root/lib/_debugger.js
diff options
context:
space:
mode:
authorMiroslav Bajtoš <miro.bajtos@gmail.com>2013-04-26 08:05:33 +0200
committerBen Noordhuis <info@bnoordhuis.nl>2013-04-27 12:51:22 +0200
commit5db936d2aecaddb5d539855a150813e36df45b66 (patch)
treed759739fe02f5f89ca996761480e78087b112f41 /lib/_debugger.js
parentfd9e01c031ac843955532af4dd87b5caec38ba73 (diff)
downloadnode-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.js55
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() {