Skip to content

Commit 50ecfe4

Browse files
author
Jan Krems
committed
src: Only allow --debug-brk w/ --inspect
1 parent 3426b93 commit 50ecfe4

File tree

6 files changed

+87
-4
lines changed

6 files changed

+87
-4
lines changed

src/node.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3955,6 +3955,12 @@ static void ParseArgs(int* argc,
39553955
exit(9);
39563956
}
39573957

3958+
if (debug_options.debug_brk_used() && !debug_options.inspector_enabled()) {
3959+
fprintf(stderr,
3960+
"%s: Using --debug-brk without --inspect is no longer supported\n", argv[0]);
3961+
exit(9);
3962+
}
3963+
39583964
// Copy remaining arguments.
39593965
const unsigned int args_left = nargs - index;
39603966

src/node_debug_options.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ DebugOptions::DebugOptions() :
5959
#if HAVE_INSPECTOR
6060
inspector_enabled_(false),
6161
#endif // HAVE_INSPECTOR
62+
debug_brk_used_(false),
6263
wait_connect_(false), http_enabled_(false),
6364
host_name_("127.0.0.1"), port_(-1) { }
6465

@@ -79,10 +80,12 @@ bool DebugOptions::ParseOption(const std::string& option) {
7980

8081
if (option_name == "--inspect") {
8182
enable_inspector = true;
82-
} else if (option_name == "--inspect-brk" || option_name == "--debug-brk") {
83-
debugger_enabled_ = true;
83+
} else if (option_name == "--inspect-brk") {
8484
enable_inspector = true;
8585
wait_connect_ = true;
86+
} else if (option_name == "--debug-brk") {
87+
debug_brk_used_ = true;
88+
wait_connect_ = true;
8689
} else if (option_name == "--inspect-port" || option_name == "--debug-port") {
8790
if (!has_argument) return false;
8891
} else {

src/node_debug_options.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class DebugOptions {
1717
return false;
1818
#endif // HAVE_INSPECTOR
1919
}
20+
bool debug_brk_used() const {
21+
return debug_brk_used_;
22+
}
2023
bool ToolsServerEnabled();
2124
bool wait_for_connect() const { return wait_connect_; }
2225
std::string host_name() const { return host_name_; }
@@ -26,6 +29,7 @@ class DebugOptions {
2629
private:
2730
#if HAVE_INSPECTOR
2831
bool inspector_enabled_;
32+
bool debug_brk_used_;
2933
#endif // HAVE_INSPECTOR
3034
bool wait_connect_; // --inspect-brk
3135
bool http_enabled_;

test/inspector/inspector-helper.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,9 @@ Harness.prototype.kill = function() {
442442
};
443443

444444
exports.startNodeForInspectorTest = function(callback,
445-
inspectorFlag = '--inspect-brk',
445+
inspectorFlags = ['--inspect-brk'],
446446
opt_script_contents) {
447-
const args = [inspectorFlag];
447+
const args = [].concat(inspectorFlags);
448448
if (opt_script_contents) {
449449
args.push('-e', opt_script_contents);
450450
} else {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
const assert = require('assert');
3+
const execFile = require('child_process').execFile;
4+
const path = require('path');
5+
6+
const common = require('../common');
7+
8+
const mainScript = path.join(common.fixturesDir, 'loop.js');
9+
10+
execFile(process.execPath, [ '--debug-brk', mainScript ], common.mustCall((error, stdout, stderr) => {
11+
assert.equal(error.code, 9);
12+
assert.notEqual(stderr.indexOf('Using --debug-brk without --inspect is no longer supported', -1));
13+
}));
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
'use strict';
2+
const common = require('../common');
3+
common.skipIfInspectorDisabled();
4+
const assert = require('assert');
5+
const helper = require('./inspector-helper.js');
6+
7+
function setupExpectBreakOnLine(line, url, session, scopeIdCallback) {
8+
return function(message) {
9+
if ('Debugger.paused' === message['method']) {
10+
const callFrame = message['params']['callFrames'][0];
11+
const location = callFrame['location'];
12+
assert.strictEqual(url, session.scriptUrlForId(location['scriptId']));
13+
assert.strictEqual(line, location['lineNumber']);
14+
scopeIdCallback &&
15+
scopeIdCallback(callFrame['scopeChain'][0]['object']['objectId']);
16+
return true;
17+
}
18+
};
19+
}
20+
21+
function testBreakpointOnStart(session) {
22+
const commands = [
23+
{ 'method': 'Runtime.enable' },
24+
{ 'method': 'Debugger.enable' },
25+
{ 'method': 'Debugger.setPauseOnExceptions',
26+
'params': {'state': 'none'} },
27+
{ 'method': 'Debugger.setAsyncCallStackDepth',
28+
'params': {'maxDepth': 0} },
29+
{ 'method': 'Profiler.enable' },
30+
{ 'method': 'Profiler.setSamplingInterval',
31+
'params': {'interval': 100} },
32+
{ 'method': 'Debugger.setBlackboxPatterns',
33+
'params': {'patterns': []} },
34+
{ 'method': 'Runtime.runIfWaitingForDebugger' }
35+
];
36+
37+
session
38+
.sendInspectorCommands(commands)
39+
.expectMessages(setupExpectBreakOnLine(0, session.mainScriptPath, session));
40+
}
41+
42+
function testWaitsForFrontendDisconnect(session, harness) {
43+
console.log('[test]', 'Verify node waits for the frontend to disconnect');
44+
session.sendInspectorCommands({ 'method': 'Debugger.resume'})
45+
.expectStderrOutput('Waiting for the debugger to disconnect...')
46+
.disconnect(true);
47+
}
48+
49+
function runTests(harness) {
50+
harness
51+
.runFrontendSession([
52+
testBreakpointOnStart,
53+
testWaitsForFrontendDisconnect
54+
]).expectShutDown(55);
55+
}
56+
57+
helper.startNodeForInspectorTest(runTests, ['--inspect', '--debug-brk']);

0 commit comments

Comments
 (0)