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 */