Commit 826855f3 authored by Iuri Matias's avatar Iuri Matias Committed by aniket-engg

refacto getMemoryAt

parent 3866faa9
...@@ -98,7 +98,15 @@ Ethdebugger.prototype.decodeLocalsAt = function (step, sourceLocation, callback) ...@@ -98,7 +98,15 @@ Ethdebugger.prototype.decodeLocalsAt = function (step, sourceLocation, callback)
callback(error) 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) { function getCurrentCalledAddressAt (stepIndex, next) {
try { try {
const address = self.traceManager.getCurrentCalledAddressAt(stepIndex) const address = self.traceManager.getCurrentCalledAddressAt(stepIndex)
......
...@@ -69,14 +69,14 @@ class VmDebuggerLogic { ...@@ -69,14 +69,14 @@ class VmDebuggerLogic {
} }
}) })
this._traceManager.getMemoryAt(index, (error, memory) => { try {
if (error) { const memory = this._traceManager.getMemoryAt(index)
// console.log(error) if (this.stepManager.currentStepIndex === index) {
this.event.trigger('traceManagerMemoryUpdate', [{}])
} else if (this.stepManager.currentStepIndex === index) {
this.event.trigger('traceManagerMemoryUpdate', [ui.formatMemory(memory, 16)]) this.event.trigger('traceManagerMemoryUpdate', [ui.formatMemory(memory, 16)])
} }
}) } catch (error) {
this.event.trigger('traceManagerMemoryUpdate', [{}])
}
try { try {
const callstack = this._traceManager.getCallStackAt(index) const callstack = this._traceManager.getCallStackAt(index)
......
...@@ -41,7 +41,14 @@ class DebuggerSolidityLocals { ...@@ -41,7 +41,14 @@ class DebuggerSolidityLocals {
callback(error) 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) { function getCurrentCalledAddressAt (stepIndex, next) {
try { try {
const address = this.traceManager.getCurrentCalledAddressAt(stepIndex) const address = this.traceManager.getCurrentCalledAddressAt(stepIndex)
......
...@@ -228,8 +228,8 @@ function includeVariableDeclaration (tree, step, sourceLocation, scopeId, newLoc ...@@ -228,8 +228,8 @@ function includeVariableDeclaration (tree, step, sourceLocation, scopeId, newLoc
const stack = tree.traceManager.getStackAt(step) const stack = tree.traceManager.getStackAt(step)
// the stack length at this point is where the value of the new local variable will be stored. // 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. // so, either this is the direct value, or the offset in memory. That depends on the type.
tree.solidityProxy.contractNameAt(step, (error, contractName) => { // cached tree.solidityProxy.contractNameAt(step).then((contractName) => {
if (!error && variableDeclaration.attributes.name !== '') { if (variableDeclaration.attributes.name !== '') {
var states = tree.solidityProxy.extractStatesDefinitions() var states = tree.solidityProxy.extractStatesDefinitions()
var location = typesUtil.extractLocationFromAstVariable(variableDeclaration) var location = typesUtil.extractLocationFromAstVariable(variableDeclaration)
location = location === 'default' ? 'storage' : location location = location === 'default' ? 'storage' : location
...@@ -242,7 +242,7 @@ function includeVariableDeclaration (tree, step, sourceLocation, scopeId, newLoc ...@@ -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. // we check here if we are at the beginning inside a new function.
...@@ -254,8 +254,7 @@ function includeVariableDeclaration (tree, step, sourceLocation, scopeId, newLoc ...@@ -254,8 +254,7 @@ function includeVariableDeclaration (tree, step, sourceLocation, scopeId, newLoc
// means: the previous location was a function definition && JUMPDEST // means: the previous location was a function definition && JUMPDEST
// => we are at the beginning of the function and input/output are setup // => we are at the beginning of the function and input/output are setup
tree.solidityProxy.contractNameAt(step, (error, contractName) => { // cached tree.solidityProxy.contractNameAt(step).then((contractName) => { // cached
if (!error) {
try { try {
const stack = tree.traceManager.getStackAt(step) const stack = tree.traceManager.getStackAt(step)
var states = tree.solidityProxy.extractStatesDefinitions() var states = tree.solidityProxy.extractStatesDefinitions()
...@@ -278,8 +277,7 @@ function includeVariableDeclaration (tree, step, sourceLocation, scopeId, newLoc ...@@ -278,8 +277,7 @@ function includeVariableDeclaration (tree, step, sourceLocation, scopeId, newLoc
// output params // output params
if (outputs) addParams(outputs, tree, scopeId, states, contractName, previousSourceLocation, stack.length, 0, 1) if (outputs) addParams(outputs, tree, scopeId, states, contractName, previousSourceLocation, stack.length, 0, 1)
} }
} catch (error) { } catch (_error) {
}
} }
}) })
......
...@@ -39,26 +39,25 @@ class SolidityProxy { ...@@ -39,26 +39,25 @@ class SolidityProxy {
* @param {Int} vmTraceIndex - index in the vm trave where to resolve the executed contract name * @param {Int} vmTraceIndex - index in the vm trave where to resolve the executed contract name
* @param {Function} cb - callback returns (error, contractName) * @param {Function} cb - callback returns (error, contractName)
*/ */
contractNameAt (vmTraceIndex, cb) { contractNameAt (vmTraceIndex) {
return new Promise((resolve, reject) => {
try { try {
const address = this.traceManager.getCurrentCalledAddressAt(vmTraceIndex) const address = this.traceManager.getCurrentCalledAddressAt(vmTraceIndex)
if (this.cache.contractNameByAddress[address]) { if (this.cache.contractNameByAddress[address]) {
cb(null, this.cache.contractNameByAddress[address]) return resolve(this.cache.contractNameByAddress[address])
} else { }
this.codeManager.getCode(address, (error, code) => { this.codeManager.getCode(address, (error, code) => {
if (error) { if (error) {
cb(error) return reject(error)
} else { }
const contractName = contractNameFromCode(this.contracts, code.bytecode, address) const contractName = contractNameFromCode(this.contracts, code.bytecode, address)
this.cache.contractNameByAddress[address] = contractName this.cache.contractNameByAddress[address] = contractName
cb(null, contractName) resolve(contractName)
}
}) })
}
} catch (error) { } catch (error) {
cb(error) reject(error)
} }
})
} }
/** /**
...@@ -98,12 +97,9 @@ class SolidityProxy { ...@@ -98,12 +97,9 @@ class SolidityProxy {
*/ */
extractStateVariablesAt (vmtraceIndex) { extractStateVariablesAt (vmtraceIndex) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.contractNameAt(vmtraceIndex, (error, contractName) => { this.contractNameAt(vmtraceIndex).then((contractName) => {
if (error) { resolve(this.extractStateVariables(contractName))
return reject(error) }).catch(reject)
}
return resolve(this.extractStateVariables(contractName))
})
}) })
} }
......
...@@ -15,7 +15,14 @@ function decodeLocal (st, index, traceManager, callTree, verifier) { ...@@ -15,7 +15,14 @@ function decodeLocal (st, index, traceManager, callTree, verifier) {
callback(error) callback(error)
} }
}, },
traceManager.getMemoryAt], function getMemoryAt (stepIndex, callback) {
try {
const result = traceManager.getMemoryAt(stepIndex)
callback(null, result)
} catch (error) {
callback(error)
}
}],
index, index,
function (error, result) { function (error, result) {
if (!error) { if (!error) {
......
...@@ -170,15 +170,13 @@ TraceManager.prototype.getContractCreationCode = function (token, callback) { ...@@ -170,15 +170,13 @@ TraceManager.prototype.getContractCreationCode = function (token, callback) {
} }
} }
TraceManager.prototype.getMemoryAt = function (stepIndex, callback) { TraceManager.prototype.getMemoryAt = function (stepIndex) {
try {
this.checkRequestedStep(stepIndex) this.checkRequestedStep(stepIndex)
} catch (check) {
return callback(check, null)
}
const lastChanges = util.findLowerBoundValue(stepIndex, this.traceCache.memoryChanges) const lastChanges = util.findLowerBoundValue(stepIndex, this.traceCache.memoryChanges)
if (lastChanges === null) return callback('no memory found', null) if (lastChanges === null) {
callback(null, this.trace[lastChanges].memory) throw new Error('no memory found')
}
return this.trace[lastChanges].memory
} }
TraceManager.prototype.getCurrentPC = function (stepIndex, callback) { TraceManager.prototype.getCurrentPC = function (stepIndex, callback) {
......
...@@ -186,25 +186,23 @@ tape('TraceManager', function (t) { ...@@ -186,25 +186,23 @@ tape('TraceManager', function (t) {
t.test('TraceManager.getMemoryAt', function (st) { t.test('TraceManager.getMemoryAt', function (st) {
st.plan(3) st.plan(3)
traceManager.getMemoryAt(0, function (error, result) { try {
const result = traceManager.getMemoryAt(0)
console.log(result) 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) console.log(result)
if (error) {
st.fail(error)
} else {
st.ok(result.length === 3) st.ok(result.length === 3)
st.ok(result[2] === '0000000000000000000000000000000000000000000000000000000000000060') st.ok(result[2] === '0000000000000000000000000000000000000000000000000000000000000060')
} catch (error) {
st.fail(error)
} }
}) })
})
t.test('TraceManager.getCurrentPC', function (st) { t.test('TraceManager.getCurrentPC', function (st) {
traceManager.getCurrentPC(13, function (error, result) { traceManager.getCurrentPC(13, function (error, result) {
......
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