diff --git a/cli.js b/cli.js index b363f4a..8100cb2 100755 --- a/cli.js +++ b/cli.js @@ -3,11 +3,11 @@ const {argv} = require('yargs') const atos = require('./index') -atos(argv, (error, symbols) => { +atos(argv, (error, symbolicated) => { if (error != null) { console.error(error.stack || error.message) process.exit(1) } else { - console.log(symbols.join('\n')) + console.log(symbolicated.join('\n')) } }) diff --git a/index.js b/index.js index 6adf02a..2e3db37 100644 --- a/index.js +++ b/index.js @@ -8,11 +8,11 @@ const extractZip = require('extract-zip') const mapLimit = require('async/mapLimit') module.exports = (options, callback) => { - const {version, quiet, file, content, mas, force} = options + const {version, quiet, file, mas, force} = options const platform = options.mas ? 'mas' : 'darwin' const directory = path.join(__dirname, 'cache', version + '-' + platform) - - const addresses = parseAddresses(content != null ? content : fs.readFileSync(file, 'utf-8')) + const content = options.content != null ? options.content : fs.readFileSync(file, 'utf-8') + const addresses = parseAddresses(content) download({version, quiet, directory, platform, force}, (error) => { if (error != null) return callback(error) @@ -30,8 +30,11 @@ module.exports = (options, callback) => { }, (err, syms) => { if (err) callback(err) const concatted = syms.reduce((m, o) => m.concat(o), []) - const sorted = concatted.sort((a, b) => a.i - b.i) - callback(null, sorted.map(x => x.symbol)) + let split = content.split('\n') + concatted.map((sym) => { + split[sym.i] = sym.symbol + }) + callback(null, split) }) }) } @@ -122,7 +125,9 @@ module.exports.testing = {parseAddress, parseAddresses} // 13 com.github.electron.framework 0x00000001016ee77f atom::api::WebContents::LoadURL(GURL const&, mate::Dictionary const&) + 831 const parseStackTraceAddress = (line) => { const segments = line.split(/\s+/) - + const index = parseInt(segments[0]) + if (!isFinite(index)) return + const library = segments[1] const address = segments[2] const image = segments[3] diff --git a/spec/__snapshots__/symbolication.spec.js.snap b/spec/__snapshots__/symbolication.spec.js.snap index 6095366..c9ed3e9 100644 --- a/spec/__snapshots__/symbolication.spec.js.snap +++ b/spec/__snapshots__/symbolication.spec.js.snap @@ -22,6 +22,17 @@ Array [ ] `; +exports[`atos returns content with addresses symbolicated 1`] = ` +Array [ + "content::RenderProcessHostImpl::Cleanup() (in Electron Framework) (render_process_host_impl.cc:1908)", + "content::ServiceWorkerProcessManager::Shutdown() (in Electron Framework) (service_worker_process_manager.cc:79)", + "", + "Thread 1 Crashed:: Chrome_IOThread", + "worker (in libnode.dylib) (threadpool.c:76)", + "uv__thread_start (in libnode.dylib) (thread.c:54)", +] +`; + exports[`atos returns an array of symbols for partially symbolicated addresses 1`] = ` Array [ "content::RenderProcessHostImpl::Cleanup() (in Electron Framework) (render_process_host_impl.cc:1908)", diff --git a/spec/symbolication.spec.js b/spec/symbolication.spec.js index 111804f..f3f5fb8 100644 --- a/spec/symbolication.spec.js +++ b/spec/symbolication.spec.js @@ -34,6 +34,15 @@ const post4Addresses = ` 47 libdyld.dylib 0x00007fff7a6513d5 start + 1 `.trim() +const fullReportFixture = ` +0 com.github.electron.framework 0x000000010d01fad3 0x10c497000 + 12094163 +1 com.github.electron.framework 0x000000010d095014 0x10c497000 + 12574740 + +Thread 1 Crashed:: Chrome_IOThread +3 libnode.dylib 0x000000010ab5c383 0x10aa09000 + 1389443 +4 libnode.dylib 0x000000010ab678e9 0x10aa09000 + 1435881 +`.trim() + const TIMEOUT = 120000; describe('atos', function () { @@ -73,6 +82,18 @@ describe('atos', function () { }) }, TIMEOUT) + it('returns content with addresses symbolicated', (done) => { + atos({ + content: fullReportFixture, + quiet: true, + version: '1.4.14' + }, (error, symbols) => { + if (error != null) return done(error) + expect(symbols).toMatchSnapshot() + done() + }) + }, TIMEOUT) + it('returns an array of symbols for addresses taken from sampling', (done) => { atos({ content: samplingFixture,