Skip to content

Commit bc07612

Browse files
addaleaxtargos
authored andcommitted
src: fix --prof-process CLI argument handling
Make sure that options after `--prof-process` are not treated as Node.js options. Fixes: #22786 PR-URL: #22790 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Bryan English <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent 24a35f9 commit bc07612

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

lib/internal/bootstrap/node.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -642,9 +642,11 @@
642642
for (const [ from, expansion ] of aliases) {
643643
let isAccepted = true;
644644
for (const to of expansion) {
645-
if (!to.startsWith('-')) continue;
645+
if (!to.startsWith('-') || to === '--') continue;
646646
const recursiveExpansion = aliases.get(to);
647647
if (recursiveExpansion) {
648+
if (recursiveExpansion[0] === to)
649+
recursiveExpansion.splice(0, 1);
648650
expansion.push(...recursiveExpansion);
649651
continue;
650652
}

src/node_options.cc

+2
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
108108
AddOption("--prof-process",
109109
"process V8 profiler output generated using --prof",
110110
&EnvironmentOptions::prof_process);
111+
// Options after --prof-process are passed through to the prof processor.
112+
AddAlias("--prof-process", { "--prof-process", "--" });
111113
AddOption("--redirect-warnings",
112114
"write warnings to file instead of stderr",
113115
&EnvironmentOptions::redirect_warnings,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
const common = require('../common');
3+
const tmpdir = require('../common/tmpdir');
4+
const fs = require('fs');
5+
const assert = require('assert');
6+
const { spawnSync } = require('child_process');
7+
8+
if (!common.isMainThread)
9+
common.skip('chdir not available in workers');
10+
if (!common.enoughTestMem)
11+
common.skip('skipped due to memory requirements');
12+
if (common.isAIX)
13+
common.skip('does not work on AIX');
14+
15+
tmpdir.refresh();
16+
process.chdir(tmpdir.path);
17+
18+
// Generate log file.
19+
spawnSync(process.execPath, [ '--prof', '-p', '42' ]);
20+
21+
const logfile = fs.readdirSync('.').filter((name) => name.endsWith('.log'))[0];
22+
assert(logfile);
23+
24+
// Make sure that the --preprocess argument is passed through correctly,
25+
// as an example flag listed in deps/v8/tools/tickprocessor.js.
26+
// Any of the other flags there should work for this test too, if --preprocess
27+
// is ever removed.
28+
const { stdout } = spawnSync(
29+
process.execPath,
30+
[ '--prof-process', '--preprocess', logfile ],
31+
{ encoding: 'utf8' });
32+
33+
// Make sure that the result is valid JSON.
34+
JSON.parse(stdout);

0 commit comments

Comments
 (0)