Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
debugger: setBreakpoint('fn()')
Fixes #1777
  • Loading branch information
indutny authored and ry committed Sep 27, 2011
1 parent fa2eaea commit f4124e1
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 31 deletions.
77 changes: 49 additions & 28 deletions lib/_debugger.js
Expand Up @@ -1217,47 +1217,68 @@ Interface.prototype.setBreakpoint = function(script, line,
line = this.client.currentSourceLine + 1;
}

if (script != +script && !this.client.scripts[script]) {
Object.keys(this.client.scripts).forEach(function(id) {
if (self.client.scripts[id].name.indexOf(script) !== -1) {
if (scriptId) {
ambiguous = true;
}
scriptId = id;
}
});
if (/\(\)$/.test(script)) {
// setBreakpoint('functionname()');
var req = {
type: 'function',
target: script.replace(/\(\)$/, ''),
condition: condition
};
} else {
scriptId = script;
}
// setBreakpoint('scriptname')
if (script != +script && !this.client.scripts[script]) {
var scripts = this.client.scripts;
Object.keys(scripts).forEach(function(id) {
if (scripts[id] && scripts[id].name.indexOf(script) !== -1) {
if (scriptId) {
ambiguous = true;
}
scriptId = id;
}
});
} else {
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');
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 = {
type: 'scriptId',
target: scriptId,
line: line - 1,
condition: condition
};
}

self.pause();
self.client.setBreakpoint(req, function(res) {
if (res.success) {
if (!silent) {
self.list(5);
}
self.client.breakpoints.push({
id: res.body.breakpoint,
scriptId: scriptId,
script: (self.client.scripts[scriptId] || {}).name,
line: line,
condition: condition
});

// Try load scriptId and line from response
if (!scriptId) {
scriptId = res.body.script_id;
line = res.body.line;
}

// If we finally have one - remember this breakpoint
if (scriptId) {
self.client.breakpoints.push({
id: res.body.breakpoint,
scriptId: scriptId,
script: (self.client.scripts[scriptId] || {}).name,
line: line,
condition: condition
});
}

} else {
if (!silent) {
self.print(req.message || 'error!');
self.print(res.message || 'error!');
}
}
self.resume();
Expand Down
28 changes: 25 additions & 3 deletions test/simple/test-debugger-repl.js
Expand Up @@ -43,7 +43,6 @@ child.stderr.pipe(process.stdout);
var expected = [];

child.on('line', function(line) {
console.log(JSON.stringify(line));
assert.ok(expected.length > 0, 'Got unexpected line: ' + line);

var expectedLine = expected[0].lines.shift();
Expand All @@ -60,8 +59,6 @@ function addTest(input, output) {
function next() {
if (expected.length > 0) {
child.stdin.write(expected[0].input + '\n');
console.log('---');
console.log('>>', expected[0].input);
} else {
finish();
}
Expand Down Expand Up @@ -121,6 +118,31 @@ addTest('c', [
"\b 9 };"
]);

// Set breakpoint by function name
addTest('sb("setInterval()", "!(setInterval.flag++)")', [
"debug> \b 2 debugger;",
"\b 3 debugger;",
"\b 4 function a(x) {",
"\b 5 var i = 10;",
"\b 6 while (--i != 0);",
"\b 7 debugger;",
"\b 8 return i;",
"\b 9 };",
"\b 10 function b() {",
"\b 11 return ['hello', 'world'].join(' ');",
"\b 12 };"
]);

// Continue
addTest('c', [
"debug> debug> debug> debug> \bbreak in node.js:150",
"\b*148 ",
"\b 149 global.setInterval = function() {",
"\b 150 var t = NativeModule.require('timers');",
"\b 151 return t.setInterval.apply(this, arguments);",
"\b 152 };"
]);

// Continue
addTest('c, bt', [
"debug> \bCan't request backtrace now"
Expand Down

0 comments on commit f4124e1

Please sign in to comment.