refacto getMemoryAt

pull/5370/head
Iuri Matias 4 years ago committed by aniket-engg
parent c05ca38903
commit d87754df8d
  1. 10
      libs/remix-debug/src/Ethdebugger.js
  2. 12
      libs/remix-debug/src/debugger/VmDebugger.js
  3. 9
      libs/remix-debug/src/debugger/solidityLocals.js
  4. 48
      libs/remix-debug/src/solidity-decoder/internalCallTree.js
  5. 38
      libs/remix-debug/src/solidity-decoder/solidityProxy.js
  6. 9
      libs/remix-debug/test/decoder/localsTests/helper.js
  7. 14
      libs/remix-lib/src/trace/traceManager.js
  8. 28
      libs/remix-lib/test/traceManager.js

@ -98,7 +98,15 @@ Ethdebugger.prototype.decodeLocalsAt = function (step, sourceLocation, callback)
callback(error)
}
},
this.traceManager.getMemoryAt,
function getMemoryAt (stepIndex, callback) {
try {
const result = self.traceManager.getMemoryAt(stepIndex)
callback(null, result)
} catch (error) {
callback(error)
}
},
function getCurrentCalledAddressAt (stepIndex, next) {
try {
const address = self.traceManager.getCurrentCalledAddressAt(stepIndex)

@ -69,14 +69,14 @@ class VmDebuggerLogic {
}
})
this._traceManager.getMemoryAt(index, (error, memory) => {
if (error) {
// console.log(error)
this.event.trigger('traceManagerMemoryUpdate', [{}])
} else if (this.stepManager.currentStepIndex === index) {
try {
const memory = this._traceManager.getMemoryAt(index)
if (this.stepManager.currentStepIndex === index) {
this.event.trigger('traceManagerMemoryUpdate', [ui.formatMemory(memory, 16)])
}
})
} catch (error) {
this.event.trigger('traceManagerMemoryUpdate', [{}])
}
try {
const callstack = this._traceManager.getCallStackAt(index)

@ -41,7 +41,14 @@ class DebuggerSolidityLocals {
callback(error)
}
},
this.traceManager.getMemoryAt,
function getMemoryAt (stepIndex, callback) {
try {
const result = self.traceManager.getMemoryAt(stepIndex)
callback(null, result)
} catch (error) {
callback(error)
}
},
function getCurrentCalledAddressAt (stepIndex, next) {
try {
const address = this.traceManager.getCurrentCalledAddressAt(stepIndex)

@ -228,8 +228,8 @@ function includeVariableDeclaration (tree, step, sourceLocation, scopeId, newLoc
const stack = tree.traceManager.getStackAt(step)
// the stack length at this point is where the value of the new local variable will be stored.
// so, either this is the direct value, or the offset in memory. That depends on the type.
tree.solidityProxy.contractNameAt(step, (error, contractName) => { // cached
if (!error && variableDeclaration.attributes.name !== '') {
tree.solidityProxy.contractNameAt(step).then((contractName) => {
if (variableDeclaration.attributes.name !== '') {
var states = tree.solidityProxy.extractStatesDefinitions()
var location = typesUtil.extractLocationFromAstVariable(variableDeclaration)
location = location === 'default' ? 'storage' : location
@ -242,7 +242,7 @@ function includeVariableDeclaration (tree, step, sourceLocation, scopeId, newLoc
}
}
})
} catch (error) {
} catch (_error) {
}
}
// we check here if we are at the beginning inside a new function.
@ -254,32 +254,30 @@ function includeVariableDeclaration (tree, step, sourceLocation, scopeId, newLoc
// 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
if (!error) {
try {
const stack = tree.traceManager.getStackAt(step)
var states = tree.solidityProxy.extractStatesDefinitions()
if (functionDefinition.children && functionDefinition.children.length) {
let inputs
let outputs
for (const element of functionDefinition.children) {
if (element.name === 'ParameterList') {
if (!inputs) inputs = element
else {
outputs = element
break
}
tree.solidityProxy.contractNameAt(step).then((contractName) => { // cached
try {
const stack = tree.traceManager.getStackAt(step)
var states = tree.solidityProxy.extractStatesDefinitions()
if (functionDefinition.children && functionDefinition.children.length) {
let inputs
let outputs
for (const element of functionDefinition.children) {
if (element.name === 'ParameterList') {
if (!inputs) inputs = element
else {
outputs = element
break
}
}
// input params
if (inputs) {
functionDefinitionAndInputs.inputs = 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)
}
} catch (error) {
// input params
if (inputs) {
functionDefinitionAndInputs.inputs = 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)
}
} catch (_error) {
}
})

@ -39,26 +39,25 @@ class SolidityProxy {
* @param {Int} vmTraceIndex - index in the vm trave where to resolve the executed contract name
* @param {Function} cb - callback returns (error, contractName)
*/
contractNameAt (vmTraceIndex, cb) {
try {
const address = this.traceManager.getCurrentCalledAddressAt(vmTraceIndex)
if (this.cache.contractNameByAddress[address]) {
cb(null, this.cache.contractNameByAddress[address])
} else {
contractNameAt (vmTraceIndex) {
return new Promise((resolve, reject) => {
try {
const address = this.traceManager.getCurrentCalledAddressAt(vmTraceIndex)
if (this.cache.contractNameByAddress[address]) {
return resolve(this.cache.contractNameByAddress[address])
}
this.codeManager.getCode(address, (error, code) => {
if (error) {
cb(error)
} else {
const contractName = contractNameFromCode(this.contracts, code.bytecode, address)
this.cache.contractNameByAddress[address] = contractName
cb(null, contractName)
return reject(error)
}
const contractName = contractNameFromCode(this.contracts, code.bytecode, address)
this.cache.contractNameByAddress[address] = contractName
resolve(contractName)
})
} catch (error) {
reject(error)
}
} catch (error) {
cb(error)
}
})
}
/**
@ -98,12 +97,9 @@ class SolidityProxy {
*/
extractStateVariablesAt (vmtraceIndex) {
return new Promise((resolve, reject) => {
this.contractNameAt(vmtraceIndex, (error, contractName) => {
if (error) {
return reject(error)
}
return resolve(this.extractStateVariables(contractName))
})
this.contractNameAt(vmtraceIndex).then((contractName) => {
resolve(this.extractStateVariables(contractName))
}).catch(reject)
})
}

@ -15,7 +15,14 @@ function decodeLocal (st, index, traceManager, callTree, verifier) {
callback(error)
}
},
traceManager.getMemoryAt],
function getMemoryAt (stepIndex, callback) {
try {
const result = traceManager.getMemoryAt(stepIndex)
callback(null, result)
} catch (error) {
callback(error)
}
}],
index,
function (error, result) {
if (!error) {

@ -170,15 +170,13 @@ TraceManager.prototype.getContractCreationCode = function (token, callback) {
}
}
TraceManager.prototype.getMemoryAt = function (stepIndex, callback) {
try {
this.checkRequestedStep(stepIndex)
} catch (check) {
return callback(check, null)
}
TraceManager.prototype.getMemoryAt = function (stepIndex) {
this.checkRequestedStep(stepIndex)
const lastChanges = util.findLowerBoundValue(stepIndex, this.traceCache.memoryChanges)
if (lastChanges === null) return callback('no memory found', null)
callback(null, this.trace[lastChanges].memory)
if (lastChanges === null) {
throw new Error('no memory found')
}
return this.trace[lastChanges].memory
}
TraceManager.prototype.getCurrentPC = function (stepIndex, callback) {

@ -186,24 +186,22 @@ tape('TraceManager', function (t) {
t.test('TraceManager.getMemoryAt', function (st) {
st.plan(3)
traceManager.getMemoryAt(0, function (error, result) {
try {
const result = traceManager.getMemoryAt(0)
console.log(result)
if (error) {
st.fail(error)
} else {
st.ok(result.length === 0)
}
})
st.ok(result.length === 0)
} catch (error) {
st.fail(error)
}
traceManager.getMemoryAt(34, function (error, result) {
try {
const result = traceManager.getMemoryAt(34)
console.log(result)
if (error) {
st.fail(error)
} else {
st.ok(result.length === 3)
st.ok(result[2] === '0000000000000000000000000000000000000000000000000000000000000060')
}
})
st.ok(result.length === 3)
st.ok(result[2] === '0000000000000000000000000000000000000000000000000000000000000060')
} catch (error) {
st.fail(error)
}
})
t.test('TraceManager.getCurrentPC', function (st) {

Loading…
Cancel
Save