Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
459e045
refactor getSourceLocationFromVMTraceIndex to a promise
iurimatias Jul 5, 2020
74b2e29
refactor getCallStackAt
iurimatias Jul 5, 2020
0d96664
refactor extractStateVariablesAt
iurimatias Jul 5, 2020
d1dc081
refactor getLastCallChangeSince
iurimatias Jul 5, 2020
2db6ff8
refactor checkRequestedStep
iurimatias Jul 5, 2020
22ac28f
refactor getCurrentCalledAddressAt
iurimatias Jul 6, 2020
bf705bb
refactor extractStateVariablesAt
iurimatias Jul 5, 2020
f788b8d
refactor getLastCallChangeSince
iurimatias Jul 5, 2020
3866faa
refactor getStackAt
iurimatias Jul 17, 2020
826855f
refacto getMemoryAt
iurimatias Jul 17, 2020
6f411db
refactor extractSourceMap
iurimatias Jul 17, 2020
5c81c76
refactor decodeMappingsKeys
iurimatias Jul 17, 2020
e411be3
refactor storageRangeInternal
iurimatias Jul 19, 2020
d8c64f7
refactor storageRange and initialMappingsLocation
iurimatias Jul 19, 2020
ad8cfc9
refactor storageSlot
iurimatias Jul 19, 2020
b36dd7a
refactor storageRangeWeb3Call
iurimatias Jul 19, 2020
076cde2
refactor storageRange
iurimatias Jul 19, 2020
79c516c
refactor accumulateStorageChanges
iurimatias Jul 19, 2020
97a19aa
refactor getAddresses
iurimatias Jul 19, 2020
a2056a4
refactor getCallDataAt
iurimatias Jul 19, 2020
98494c3
refactor buildCallPath
iurimatias Jul 22, 2020
13fe9cb
refactor getContractCreationCode
iurimatias Jul 22, 2020
68b4b82
refactor getReturnValue value
iurimatias Jul 22, 2020
b87ae77
refactor getCurrentStep
iurimatias Jul 22, 2020
b457d7d
remove some unnecessary elses
iurimatias Jul 22, 2020
ef09d85
update for new linter rules
iurimatias Aug 21, 2020
98fde56
lint fix by tracking error
Aniket-Engg Aug 25, 2020
2350efb
fix some of the e2e tests
iurimatias Aug 25, 2020
9a2d127
Update solidityLocals.js
yann300 Aug 26, 2020
a7e918e
remove e2e timeout
yann300 Aug 26, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions libs/remix-debug/src/Ethdebugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,23 @@ Ethdebugger.prototype.extractLocalsAt = function (step, callback) {
Ethdebugger.prototype.decodeLocalsAt = function (step, sourceLocation, callback) {
const self = this
this.traceManager.waterfall([
this.traceManager.getStackAt,
this.traceManager.getMemoryAt,
function getStackAt (stepIndex, callback) {
try {
const result = self.traceManager.getStackAt(stepIndex)
callback(null, result)
} catch (error) {
callback(error)
}
},
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)
Expand Down
82 changes: 41 additions & 41 deletions libs/remix-debug/src/debugger/VmDebugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,23 @@ class VmDebuggerLogic {

this.event.trigger('functionsStackUpdate', [this._callTree.retrieveFunctionsStack(index)])

this._traceManager.getCallDataAt(index, (error, calldata) => {
if (error) {
// console.log(error)
this.event.trigger('traceManagerCallDataUpdate', [{}])
} else if (this.stepManager.currentStepIndex === index) {
try {
const calldata = this._traceManager.getCallDataAt(index)
if (this.stepManager.currentStepIndex === index) {
this.event.trigger('traceManagerCallDataUpdate', [calldata])
}
})
} catch (error) {
this.event.trigger('traceManagerCallDataUpdate', [{}])
}

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)
Expand All @@ -87,36 +87,39 @@ class VmDebuggerLogic {
this.event.trigger('traceManagerCallStackUpdate', [{}])
}

this._traceManager.getStackAt(index, (error, callstack) => {
if (error) {
// console.log(error)
this.event.trigger('traceManagerStackUpdate', [{}])
} else if (this.stepManager.currentStepIndex === index) {
try {
const callstack = this._traceManager.getStackAt(index)
if (this.stepManager.currentStepIndex === index) {
this.event.trigger('traceManagerStackUpdate', [callstack])
}
})
} catch (error) {
this.event.trigger('traceManagerStackUpdate', [{}])
}

try {
const address = this._traceManager.getCurrentCalledAddressAt(index)
if (!this.storageResolver) return

var storageViewer = new StorageViewer({ stepIndex: this.stepManager.currentStepIndex, tx: this.tx, address: address }, this.storageResolver, this._traceManager)

storageViewer.storageRange((error, storage) => {
if (error) {
this.event.trigger('traceManagerStorageUpdate', [{}])
} else if (this.stepManager.currentStepIndex === index) {
storageViewer.storageRange().then((storage) => {
if (this.stepManager.currentStepIndex === index) {
var header = storageViewer.isComplete(address) ? '[Completely Loaded]' : '[Partially Loaded]'
this.event.trigger('traceManagerStorageUpdate', [storage, header])
}
}).catch((_error) => {
this.event.trigger('traceManagerStorageUpdate', [{}])
})
} catch (error) {
console.log(error)
this.event.trigger('traceManagerStorageUpdate', [{}])
}

this._traceManager.getCurrentStep(index, (error, step) => {
this.event.trigger('traceCurrentStepUpdate', [error, step])
})
try {
const step = this._traceManager.getCurrentStep(index)
this.event.trigger('traceCurrentStepUpdate', [null, step])
} catch (error) {
this.event.trigger('traceCurrentStepUpdate', [error])
}

try {
const addmem = this._traceManager.getMemExpand(index)
Expand Down Expand Up @@ -146,13 +149,14 @@ class VmDebuggerLogic {
this.event.trigger('traceRemainingGasUpdate', [error])
}

this._traceManager.getReturnValue(index, (error, returnValue) => {
if (error) {
this.event.trigger('traceReturnValueUpdate', [[error]])
} else if (this.stepManager.currentStepIndex === index) {
try {
const returnValue = this._traceManager.getReturnValue(index)
if (this.stepManager.currentStepIndex === index) {
this.event.trigger('traceReturnValueUpdate', [[returnValue]])
}
})
} catch (error) {
this.event.trigger('traceReturnValueUpdate', [[error]])
}
})
}

Expand All @@ -161,11 +165,9 @@ class VmDebuggerLogic {
this.traceLength = 0

this.debugger.event.register('newTraceLoaded', (length) => {
this._traceManager.getAddresses((error, addresses) => {
if (error) return
this.event.trigger('traceAddressesUpdate', [addresses])
this.addresses = addresses
})
const addresses = this._traceManager.getAddresses()
this.event.trigger('traceAddressesUpdate', [addresses])
this.addresses = addresses

this._traceManager.getLength((error, length) => {
if (error) return
Expand All @@ -186,11 +188,9 @@ class VmDebuggerLogic {
for (var k in this.addresses) {
var address = this.addresses[k]
var storageViewer = new StorageViewer({ stepIndex: this.stepManager.currentStepIndex, tx: this.tx, address: address }, this.storageResolver, this._traceManager)
storageViewer.storageRange((error, result) => {
if (!error) {
storageJSON[address] = result
this.event.trigger('traceStorageUpdate', [storageJSON])
}
storageViewer.storageRange().then((result) => {
storageJSON[address] = result
this.event.trigger('traceStorageUpdate', [storageJSON])
})
}
})
Expand Down
23 changes: 19 additions & 4 deletions libs/remix-debug/src/debugger/solidityLocals.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,28 @@ class DebuggerSolidityLocals {
}

decode (sourceLocation) {
const self = this
this.event.trigger('solidityLocalsMessage', [''])
this.traceManager.waterfall([
this.traceManager.getStackAt,
this.traceManager.getMemoryAt,
(stepIndex, next) => {
function getStackAt (stepIndex, callback) {
try {
const address = this.traceManager.getCurrentCalledAddressAt(stepIndex)
const result = self.traceManager.getStackAt(stepIndex)
callback(null, result)
} catch (error) {
callback(error)
}
},
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)
next(null, address)
} catch (error) {
next(error)
Expand Down
9 changes: 4 additions & 5 deletions libs/remix-debug/src/debugger/stepManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ class DebuggerStepManager {
if (index < 0) return
if (this.currentStepIndex !== index) return

this.traceManager.buildCallPath(index, (error, callsPath) => {
if (error) {
console.log(error)
return this.event.trigger('revertWarning', [''])
}
this.traceManager.buildCallPath(index).then((callsPath) => {
this.currentCall = callsPath[callsPath.length - 1]
if (this.currentCall.reverted) {
let revertedReason = this.currentCall.outofgas ? 'outofgas' : ''
Expand All @@ -59,6 +55,9 @@ class DebuggerStepManager {
this.event.trigger('revertWarning', ['parenthasthrown'])
}
this.event.trigger('revertWarning', [''])
}).catch((error) => {
console.log(error)
this.event.trigger('revertWarning', [''])
})
})
}
Expand Down
33 changes: 15 additions & 18 deletions libs/remix-debug/src/solidity-decoder/astHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,24 @@ function extractStateDefinitions (contractName, sourcesList, contracts) {
contracts = extractContractDefinitions(sourcesList)
}
const node = contracts.contractsByName[contractName]
if (node) {
const stateItems = []
const stateVar = []
const baseContracts = getLinearizedBaseContracts(node.id, contracts.contractsById)
baseContracts.reverse()
for (let k in baseContracts) {
const ctr = baseContracts[k]
for (let i in ctr.children) {
const item = ctr.children[i]
stateItems.push(item)
if (item.name === 'VariableDeclaration') {
stateVar.push(item)
}
if (!node) {
return null
}
const stateItems = []
const stateVar = []
const baseContracts = getLinearizedBaseContracts(node.id, contracts.contractsById)
baseContracts.reverse()
for (let k in baseContracts) {
const ctr = baseContracts[k]
for (let i in ctr.children) {
const item = ctr.children[i]
stateItems.push(item)
if (item.name === 'VariableDeclaration') {
stateVar.push(item)
}
}
return {
stateDefinitions: stateItems,
stateVariables: stateVar
}
}
return null
return {stateDefinitions: stateItems, stateVariables: stateVar}
}

/**
Expand Down
80 changes: 41 additions & 39 deletions libs/remix-debug/src/solidity-decoder/internalCallTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,26 +224,27 @@ function includeVariableDeclaration (tree, step, sourceLocation, scopeId, newLoc
// we check if the current vm trace step target a new ast node of type VariableDeclaration
// that way we know that there is a new local variable from here.
if (variableDeclaration && !tree.scopes[scopeId].locals[variableDeclaration.attributes.name]) {
tree.traceManager.getStackAt(step, (error, stack) => {
try {
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.
if (!error) {
tree.solidityProxy.contractNameAt(step, (error, contractName) => { // cached
if (!error && variableDeclaration.attributes.name !== '') {
var states = tree.solidityProxy.extractStatesDefinitions()
var location = typesUtil.extractLocationFromAstVariable(variableDeclaration)
location = location === 'default' ? 'storage' : location
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
// we push the new local variable in our tree
tree.scopes[scopeId].locals[variableDeclaration.attributes.name] = {
name: variableDeclaration.attributes.name,
type: decodeInfo.parseType(variableDeclaration.attributes.type, states, contractName, location),
stackDepth: stack.length,
sourceLocation: sourceLocation
}
tree.scopes[scopeId].locals[variableDeclaration.attributes.name] = {
name: variableDeclaration.attributes.name,
type: decodeInfo.parseType(variableDeclaration.attributes.type, states, contractName, location),
stackDepth: stack.length,
sourceLocation: sourceLocation
}
})
}
})
}
})
} catch (error) {
console.log(error)
}
}
// we check here if we are at the beginning inside a new function.
// if that is the case, we have to add to locals tree the inputs and output params
Expand All @@ -253,34 +254,35 @@ function includeVariableDeclaration (tree, step, sourceLocation, scopeId, newLoc
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
if (!error) {
tree.traceManager.getStackAt(step, (error, stack) => {
if (!error) {
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)

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
}
// output params
if (outputs) addParams(outputs, tree, scopeId, states, contractName, previousSourceLocation, stack.length, 0, 1)
}
}
})
// 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) {
console.log(error)
}
})

tree.functionDefinitionsByScope[scopeId] = functionDefinitionAndInputs
}
}
Expand Down
Loading