From 2639b6b0beab497ddf4802b56223f895750ea1d7 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 6 Dec 2016 11:38:50 +0100 Subject: [PATCH] add getSourceLocation from stepindex --- src/code/sourceLocationTracker.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/code/sourceLocationTracker.js b/src/code/sourceLocationTracker.js index d312a868e6..401fa21156 100644 --- a/src/code/sourceLocationTracker.js +++ b/src/code/sourceLocationTracker.js @@ -36,6 +36,36 @@ SourceLocationTracker.prototype.getSourceLocation = function (address, index, co }) } +/** + * Return the source location associated with the given @arg pc + * + * @param {String} address - contract address from which the source location is retrieved + * @param {Int} vmtraceStepIndex - index of the current code in the vmtrace + * @param {Object} contractDetails - AST of compiled contracts + * @param {Function} cb - callback function + */ +SourceLocationTracker.prototype.getSourceLocation = function (address, vmtraceStepIndex, contractsDetails, cb) { + var self = this + this.codeManager.getCode(address, function (error, result) { + if (!error) { + var sourceMap = getSourceMap(address, result.bytecode, contractsDetails) + if (sourceMap) { + self.codeManager.getInstructionIndex(address, vmtraceStepIndex, function (error, index) { + if (error) { + cb(error) + } else { + cb(null, self.sourceMappingDecoder.atIndex(index, sourceMap)) + } + }) + } else { + cb('no srcmap associated with the code ' + address) + } + } else { + cb(error) + } + }) +} + /** * backwards compatibility - attribute name will certainly be changed */