UNPKG

minidump

Version:
93 lines (82 loc) 2.88 kB
const fs = require('fs') const path = require('path') const spawn = require('child_process').spawn const format = require('./format') const exe = process.platform === 'win32' ? '.exe' : '' const commands = { minidump_stackwalk: path.resolve(__dirname, '..', 'build', 'src', 'processor', 'minidump_stackwalk') + exe, dump_syms: (() => { if (process.platform === 'darwin') { return path.resolve(__dirname, '..', 'build', 'src', 'tools', 'mac', 'dump_syms', 'dump_syms_mac') } else if (process.platform === 'linux') { return path.resolve(__dirname, '..', 'build', 'src', 'tools', 'linux', 'dump_syms', 'dump_syms') } })() } function execute (command, args, callback) { var stdout = Buffer.alloc(0) var stderr = Buffer.alloc(0) var child = spawn(command, args) child.stdout.on('data', function (chunk) { stdout = Buffer.concat([stdout, chunk]) }) child.stderr.on('data', function (chunk) { stderr = Buffer.concat([stderr, chunk]) }) child.on('close', function (code) { if (code !== 0) { callback(stderr ? new Error(stderr.toString()) : new Error('Command `' + command + '` failed: ' + code)) } else { callback(null, stdout) } }) } var globalSymbolPaths = [] module.exports.addSymbolPath = Array.prototype.push.bind(globalSymbolPaths) module.exports.moduleList = function (minidump, callback) { fs.readFile(minidump, (err, data) => { if (err) return callback(err) const { streams } = format.readMinidump(data) const moduleList = streams.find(s => s.type === format.streamTypes.MD_MODULE_LIST_STREAM) if (!moduleList) return callback(new Error('minidump does not contain module list')) const modules = moduleList.modules.map(m => { const mod = { version: m.version, name: m.name } if (m.cv_record) { mod.pdb_file_name = m.cv_record.pdb_file_name mod.debug_identifier = m.cv_record.debug_file_id } return mod }) callback(null, modules) }) } module.exports.walkStack = function (minidump, symbolPaths, callback, commandArgs) { if (!callback) { callback = symbolPaths symbolPaths = [] } var stackwalk = commands.minidump_stackwalk if (!stackwalk) { callback(new Error('Unable to find "minidump_stackwalk"')) return } var args = [minidump].concat(symbolPaths, globalSymbolPaths) args = commandArgs ? [commandArgs].concat(args) : args execute(stackwalk, args, callback) } module.exports.dumpSymbol = function (binary, callback) { var dumpsyms = commands.dump_syms if (!dumpsyms) { callback(new Error('Unable to find "dump_syms"')) return } // Search for binary.dSYM on OS X. var dsymPath = binary + '.dSYM' if (process.platform === 'darwin' && fs.existsSync(dsymPath)) { binary = dsymPath } execute(dumpsyms, ['-r', '-c', binary], callback) }