-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: parse --stack-trace-limit and use it in --trace-* flags
Previously, --trace-exit and --trace-sync-io doesn't take care of --stack-trace-limit and always print a stack trace with maximum size of 10. This patch parses --stack-trace-limit during initialization and use the value in --trace-* flags. PR-URL: #55121 Fixes: #55100 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]>
- Loading branch information
1 parent
a57c8ba
commit b229083
Showing
8 changed files
with
88 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
// This is meant to be run with --trace-exit. | ||
|
||
const depth = parseInt(process.env.STACK_DEPTH) || 30; | ||
let counter = 1; | ||
function recurse() { | ||
if (counter++ < depth) { | ||
recurse(); | ||
} else { | ||
process.exit(0); | ||
} | ||
} | ||
|
||
recurse(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'use strict'; | ||
|
||
// This tests that --stack-trace-limit can be used to tweak the stack trace size of --trace-exit. | ||
require('../common'); | ||
const fixture = require('../common/fixtures'); | ||
const { spawnSyncAndAssert } = require('../common/child_process'); | ||
const assert = require('assert'); | ||
|
||
// When the stack trace limit is bigger than the stack trace size, it should output them all. | ||
spawnSyncAndAssert( | ||
process.execPath, | ||
['--trace-exit', '--stack-trace-limit=50', fixture.path('deep-exit.js')], | ||
{ | ||
env: { | ||
...process.env, | ||
STACK_DEPTH: 30 | ||
} | ||
}, | ||
{ | ||
stderr(output) { | ||
const matches = [...output.matchAll(/at recurse/g)]; | ||
assert.strictEqual(matches.length, 30); | ||
} | ||
}); | ||
|
||
// When the stack trace limit is smaller than the stack trace size, it should truncate the stack size. | ||
spawnSyncAndAssert( | ||
process.execPath, | ||
['--trace-exit', '--stack-trace-limit=30', fixture.path('deep-exit.js')], | ||
{ | ||
env: { | ||
...process.env, | ||
STACK_DEPTH: 30 | ||
} | ||
}, | ||
{ | ||
stderr(output) { | ||
const matches = [...output.matchAll(/at recurse/g)]; | ||
// The top frame is process.exit(), so one frame from recurse() is truncated. | ||
assert.strictEqual(matches.length, 29); | ||
} | ||
}); |