Skip to content
This repository was archived by the owner on Feb 1, 2022. It is now read-only.

Commit 89e6e08

Browse files
author
Jan Krems
committed
feat: Add backtrace command
1 parent f8f51d7 commit 89e6e08

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lib/node-inspect.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ function createCommandContext(inspector) {
465465

466466
let currentSourceLocation = undefined;
467467
let currentFrame = undefined;
468+
let currentBacktrace = undefined;
468469

469470
const scripts = {};
470471
const watchedExpressions = [];
@@ -544,6 +545,16 @@ function createCommandContext(inspector) {
544545
return Debugger.pause();
545546
},
546547

548+
get backtrace() {
549+
currentBacktrace.forEach((callFrame, idx) => {
550+
const { location: { scriptId, lineNumber, columnNumber }, functionName } = callFrame;
551+
const script = scripts[scriptId];
552+
const relativeUrl = (script && getRelativePath(script && script.url)) || '<unknown>';
553+
const name = functionName || '(anonymous)';
554+
print(`#${idx} ${name} ${relativeUrl}:${lineNumber + 1}:${columnNumber}`);
555+
});
556+
},
557+
547558
// List source code
548559
list(delta = 5) {
549560
const { scriptId, lineNumber, columnNumber } = currentSourceLocation;
@@ -619,6 +630,7 @@ function createCommandContext(inspector) {
619630

620631
Debugger.on('paused', ({ callFrames, reason /* , hitBreakpoints */ }) => {
621632
// Save execution context's data
633+
currentBacktrace = callFrames;
622634
const topFrame = callFrames[0];
623635
const { scriptId, lineNumber } = currentSourceLocation = topFrame.location;
624636
currentFrame = topFrame.callFrameId;

0 commit comments

Comments
 (0)