diff --git a/libs/remix-debug/src/Ethdebugger.js b/libs/remix-debug/src/Ethdebugger.js index 9203147dfe..2cebaeb149 100644 --- a/libs/remix-debug/src/Ethdebugger.js +++ b/libs/remix-debug/src/Ethdebugger.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) diff --git a/libs/remix-debug/src/debugger/VmDebugger.js b/libs/remix-debug/src/debugger/VmDebugger.js index 0cec534b75..b96092085b 100644 --- a/libs/remix-debug/src/debugger/VmDebugger.js +++ b/libs/remix-debug/src/debugger/VmDebugger.js @@ -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) diff --git a/libs/remix-debug/src/debugger/solidityLocals.js b/libs/remix-debug/src/debugger/solidityLocals.js index 13f974692f..c45eab6d19 100644 --- a/libs/remix-debug/src/debugger/solidityLocals.js +++ b/libs/remix-debug/src/debugger/solidityLocals.js @@ -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) diff --git a/libs/remix-debug/src/solidity-decoder/internalCallTree.js b/libs/remix-debug/src/solidity-decoder/internalCallTree.js index 9b18a383d4..de2f66bebe 100644 --- a/libs/remix-debug/src/solidity-decoder/internalCallTree.js +++ b/libs/remix-debug/src/solidity-decoder/internalCallTree.js @@ -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) { } }) diff --git a/libs/remix-debug/src/solidity-decoder/solidityProxy.js b/libs/remix-debug/src/solidity-decoder/solidityProxy.js index e6640fae7c..ee3fd5beac 100644 --- a/libs/remix-debug/src/solidity-decoder/solidityProxy.js +++ b/libs/remix-debug/src/solidity-decoder/solidityProxy.js @@ -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) }) } diff --git a/libs/remix-debug/test/decoder/localsTests/helper.js b/libs/remix-debug/test/decoder/localsTests/helper.js index f2b3cce9f8..ac22436b9c 100644 --- a/libs/remix-debug/test/decoder/localsTests/helper.js +++ b/libs/remix-debug/test/decoder/localsTests/helper.js @@ -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) { diff --git a/libs/remix-lib/src/trace/traceManager.js b/libs/remix-lib/src/trace/traceManager.js index cddb116f60..0c30281b6f 100644 --- a/libs/remix-lib/src/trace/traceManager.js +++ b/libs/remix-lib/src/trace/traceManager.js @@ -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) { diff --git a/libs/remix-lib/test/traceManager.js b/libs/remix-lib/test/traceManager.js index 4a8a963faf..44e2705a19 100644 --- a/libs/remix-lib/test/traceManager.js +++ b/libs/remix-lib/test/traceManager.js @@ -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) {