node-minidump-stackwalk
Version:
Node.js wrapper for Breakpad's minidump-stackwalk
81 lines (80 loc) • 3.05 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.minidumpStackwalkSync = exports.minidumpStackwalk = exports.Platform = void 0;
const child_process_1 = require("child_process");
const fs_1 = require("fs");
const path_1 = __importDefault(require("path"));
var Platform;
(function (Platform) {
Platform["darwin"] = "darwin";
Platform["bullseye"] = "bullseye";
Platform["win32"] = "win32";
})(Platform = exports.Platform || (exports.Platform = {}));
async function minidumpStackwalk(minidumpPath, symbolPaths, platform = Platform.bullseye, options = {}) {
const { command, args } = createCommandArgs(minidumpPath, symbolPaths, platform, options);
return new Promise((resolve, reject) => {
const process = (0, child_process_1.spawn)(command, args);
let stdout = '';
let stderr = '';
process.stdout.on('data', (data) => {
stdout += data.toString();
});
process.stderr.on('data', (data) => {
stderr += data.toString();
});
process.on('close', (code) => {
if (code === 0) {
resolve({ stdout, stderr });
}
else {
reject(new Error(`Process exited with code ${code}\n${stderr}`));
}
});
process.on('error', (err) => {
reject(err);
});
});
}
exports.minidumpStackwalk = minidumpStackwalk;
function minidumpStackwalkSync(minidumpPath, symbolPaths, platform = Platform.bullseye, options = {}) {
const { command, args } = createCommandArgs(minidumpPath, symbolPaths, platform, options);
const result = (0, child_process_1.spawnSync)(command, args);
if (result.error) {
throw result.error;
}
if (result.status !== 0) {
throw new Error(`Process exited with code ${result.status}\n${result.stderr}`);
}
return result.stdout;
}
exports.minidumpStackwalkSync = minidumpStackwalkSync;
function createCommandArgs(minidumpPath, symbolPaths, platform = Platform.bullseye, options) {
const minidumpStackwalkFileName = platform === Platform.win32 ? 'minidump_stackwalk.exe' : 'minidump_stackwalk';
const minidumpStackwalkPath = path_1.default.join(__dirname, `../bin/${platform}/${minidumpStackwalkFileName}`);
if (!(0, fs_1.existsSync)(minidumpStackwalkPath)) {
throw new Error(`Platform: ${platform} is not supported`);
}
const args = [];
if (options.machineReadable) {
args.push('-m');
}
if (options.stackContents) {
args.push('-s');
}
if (options.dumpingThreadOnly) {
args.push('-c');
}
if (options.threadBrief) {
args.push('-b');
}
// Add the minidump path and symbol paths as separate arguments
args.push(minidumpPath);
args.push(...symbolPaths);
return {
command: minidumpStackwalkPath,
args
};
}