Commit 39efcc85 authored by yann300's avatar yann300 Committed by Iuri Matias

function stack trace

parent 29c4f59c
......@@ -7,7 +7,7 @@
"scripts": {
"diff": "lerna diff",
"updated": "lerna updated",
"bootstrap": "npm run build-ts-packages; lerna bootstrap",
"bootstrap": "lerna bootstrap; npm run build-ts-packages",
"build-ts-packages": "lerna run --scope 'remix-analyzer' --scope 'remix-astwalker' --scope 'remix-solidity' --scope 'remix-tests' --scope 'remix-url-resolver' build",
"publish": "npm run build-ts-packages; lerna publish",
"release": "lerna bootstrap; lerna publish;",
......
......@@ -58,6 +58,8 @@ class VmDebuggerLogic {
this.event.trigger('indexUpdate', [index])
this.event.trigger('functionsStackUpdate', [this._callTree.retrieveFunctionsStack(index)])
this._traceManager.getCallDataAt(index, (error, calldata) => {
if (error) {
// console.log(error)
......
......@@ -66,6 +66,7 @@ class InternalCallTree {
*/
this.sourceLocationTracker.clearCache()
this.functionCallStack = []
this.functionDefinitionsByScope = {}
this.scopeStarts = {}
this.variableDeclarationByFile = {}
this.functionDefinitionByFile = {}
......@@ -79,21 +80,43 @@ class InternalCallTree {
* @param {Int} vmtraceIndex - index on the vm trace
*/
findScope (vmtraceIndex) {
const scopes = Object.keys(this.scopeStarts)
if (!scopes.length) {
return null
}
let scopeId = util.findLowerBoundValue(vmtraceIndex, scopes)
scopeId = this.scopeStarts[scopeId]
let scopeId = this.findScopeId(vmtraceIndex)
if (!scopeId) return null
let scope = this.scopes[scopeId]
while (scope.lastStep && scope.lastStep < vmtraceIndex && scope.firstStep > 0) {
const matched = scopeId.match(/(.\d|\d)$/)
scopeId = scopeId.replace(matched[1], '')
scopeId = this.parentScope(scopeId)
scope = this.scopes[scopeId]
}
return scope
}
parentScope (scopeId) {
const matched = scopeId.match(/(.\d|\d)$/)
return scopeId.replace(matched[1], '')
}
findScopeId (vmtraceIndex) {
const scopes = Object.keys(this.scopeStarts)
if (!scopes.length) return null
const scopeStart = util.findLowerBoundValue(vmtraceIndex, scopes)
return this.scopeStarts[scopeStart]
}
retrieveFunctionsStack (vmtraceIndex) {
let scope = this.findScope(vmtraceIndex)
if (!scope) return []
let scopeId = this.scopeStarts[scope.firstStep]
let functions = []
if (!scopeId) return functions
while (true) {
functions.push(this.functionDefinitionsByScope[scopeId])
let parent = this.parentScope(scopeId)
if (!parent) break
else scopeId = parent
}
return functions
}
extractSourceLocation (step) {
return new Promise((resolve, reject) => {
this.traceManager.getCurrentCalledAddressAt(step, (error, address) => {
......@@ -220,6 +243,7 @@ function includeVariableDeclaration (tree, step, sourceLocation, scopeId, newLoc
const functionDefinition = resolveFunctionDefinition(tree, step, previousSourceLocation)
if (functionDefinition && (newLocation && traceHelper.isJumpDestInstruction(tree.traceManager.trace[step - 1]) || functionDefinition.attributes.isConstructor)) {
tree.functionCallStack.push(step)
const functionDefinitionAndInputs = {functionDefinition, inputs: []}
// means: the previous location was a function definition && JUMPDEST
// => we are at the beginning of the function and input/output are setup
tree.solidityProxy.contractNameAt(step, (error, contractName) => { // cached
......@@ -240,7 +264,9 @@ function includeVariableDeclaration (tree, step, sourceLocation, scopeId, newLoc
}
}
// input params
if (inputs) addParams(inputs, tree, scopeId, states, contractName, previousSourceLocation, stack.length, inputs.children.length, -1)
if (inputs) {
functionDefinitionAndInputs.inputs.push(addParams(inputs, tree, scopeId, states, contractName, previousSourceLocation, stack.length, inputs.children.length, -1))
}
// output params
if (outputs) addParams(outputs, tree, scopeId, states, contractName, previousSourceLocation, stack.length, 0, 1)
}
......@@ -248,6 +274,7 @@ function includeVariableDeclaration (tree, step, sourceLocation, scopeId, newLoc
})
}
})
tree.functionDefinitionsByScope[scopeId] = functionDefinitionAndInputs
}
}
......@@ -304,6 +331,7 @@ function extractFunctionDefinitions (ast, astWalker) {
}
function addParams (parameterList, tree, scopeId, states, contractName, sourceLocation, stackLength, stackPosition, dir) {
let params = []
for (let inputParam in parameterList.children) {
const param = parameterList.children[inputParam]
const stackDepth = stackLength + (dir * stackPosition)
......@@ -317,9 +345,11 @@ function addParams (parameterList, tree, scopeId, states, contractName, sourceLo
stackDepth: stackDepth,
sourceLocation: sourceLocation
}
params.push(attributesName)
}
stackPosition += dir
}
return params
}
module.exports = InternalCallTree
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment