Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
eddc2e38
Commit
eddc2e38
authored
Dec 16, 2019
by
Iuri Matias
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update remix-debug syntax to use const, let and this
parent
e7c18fdd
Show whitespace changes
Inline
Side-by-side
Showing
34 changed files
with
498 additions
and
527 deletions
+498
-527
rdb
remix-debug/bin/rdb
+10
-10
index.js
remix-debug/index.js
+8
-8
Ethdebugger.js
remix-debug/src/Ethdebugger.js
+24
-25
contextManager.js
remix-debug/src/cmdline/contextManager.js
+12
-13
index.js
remix-debug/src/cmdline/index.js
+28
-33
VmDebugger.js
remix-debug/src/debugger/VmDebugger.js
+91
-100
debugger.js
remix-debug/src/debugger/debugger.js
+33
-36
solidityLocals.js
remix-debug/src/debugger/solidityLocals.js
+19
-21
solidityState.js
remix-debug/src/debugger/solidityState.js
+25
-28
stepManager.js
remix-debug/src/debugger/stepManager.js
+30
-33
astHelper.js
remix-debug/src/solidity-decoder/astHelper.js
+20
-20
decodeInfo.js
remix-debug/src/solidity-decoder/decodeInfo.js
+39
-39
index.js
remix-debug/src/solidity-decoder/index.js
+4
-4
internalCallTree.js
remix-debug/src/solidity-decoder/internalCallTree.js
+31
-32
localDecoder.js
remix-debug/src/solidity-decoder/localDecoder.js
+7
-7
solidityProxy.js
remix-debug/src/solidity-decoder/solidityProxy.js
+11
-11
stateDecoder.js
remix-debug/src/solidity-decoder/stateDecoder.js
+9
-9
Address.js
remix-debug/src/solidity-decoder/types/Address.js
+2
-2
ArrayType.js
remix-debug/src/solidity-decoder/types/ArrayType.js
+14
-14
Bool.js
remix-debug/src/solidity-decoder/types/Bool.js
+2
-2
DynamicByteArray.js
remix-debug/src/solidity-decoder/types/DynamicByteArray.js
+12
-12
Enum.js
remix-debug/src/solidity-decoder/types/Enum.js
+3
-3
FixedByteArray.js
remix-debug/src/solidity-decoder/types/FixedByteArray.js
+1
-1
Int.js
remix-debug/src/solidity-decoder/types/Int.js
+2
-2
Mapping.js
remix-debug/src/solidity-decoder/types/Mapping.js
+17
-17
RefType.js
remix-debug/src/solidity-decoder/types/RefType.js
+2
-2
StringType.js
remix-debug/src/solidity-decoder/types/StringType.js
+5
-5
Struct.js
remix-debug/src/solidity-decoder/types/Struct.js
+6
-6
Uint.js
remix-debug/src/solidity-decoder/types/Uint.js
+2
-2
ValueType.js
remix-debug/src/solidity-decoder/types/ValueType.js
+2
-2
util.js
remix-debug/src/solidity-decoder/types/util.js
+7
-7
mappingPreimages.js
remix-debug/src/storage/mappingPreimages.js
+11
-11
storageResolver.js
remix-debug/src/storage/storageResolver.js
+5
-6
storageViewer.js
remix-debug/src/storage/storageViewer.js
+4
-4
No files found.
remix-debug/bin/rdb
View file @
eddc2e38
...
@@ -25,15 +25,15 @@ program
...
@@ -25,15 +25,15 @@ program
.
option
(
'--node [url]'
,
'node to connect to'
)
.
option
(
'--node [url]'
,
'node to connect to'
)
.
parse
(
process
.
argv
)
.
parse
(
process
.
argv
)
var
CmdLine
=
require
(
'../src/cmdline/index.js'
)
const
CmdLine
=
require
(
'../src/cmdline/index.js'
)
var
solc
=
require
(
'solc'
)
const
solc
=
require
(
'solc'
)
var
fs
=
require
(
'fs'
)
const
fs
=
require
(
'fs'
)
var
filename
=
'test/sol/simple_storage.sol'
const
filename
=
'test/sol/simple_storage.sol'
var
shortFilename
=
'simple_storage.sol'
const
shortFilename
=
'simple_storage.sol'
var
inputJson
=
{
const
inputJson
=
{
language
:
'Solidity'
,
language
:
'Solidity'
,
sources
:
{
sources
:
{
},
},
...
@@ -55,17 +55,17 @@ inputJson.sources[shortFilename] = {content: fs.readFileSync(filename).toString(
...
@@ -55,17 +55,17 @@ inputJson.sources[shortFilename] = {content: fs.readFileSync(filename).toString(
console
.
log
(
'compiling...'
)
console
.
log
(
'compiling...'
)
le
t
compilationData
=
JSON
.
parse
(
solc
.
compileStandardWrapper
(
JSON
.
stringify
(
inputJson
)))
cons
t
compilationData
=
JSON
.
parse
(
solc
.
compileStandardWrapper
(
JSON
.
stringify
(
inputJson
)))
var
compilation
=
{}
const
compilation
=
{}
compilation
.
data
=
compilationData
compilation
.
data
=
compilationData
compilation
.
source
=
{
sources
:
inputJson
.
sources
}
compilation
.
source
=
{
sources
:
inputJson
.
sources
}
var
cmdLine
=
new
CmdLine
()
const
cmdLine
=
new
CmdLine
()
cmdLine
.
connect
(
'http'
,
'http://localhost:8545'
)
cmdLine
.
connect
(
'http'
,
'http://localhost:8545'
)
cmdLine
.
loadCompilationResult
(
compilation
)
cmdLine
.
loadCompilationResult
(
compilation
)
cmdLine
.
initDebugger
()
cmdLine
.
initDebugger
()
var
tx
=
'0xf510c4f0b1d9ee262d7b9e9e87b4262f275fe029c2c733feef7dfa1e2b1e32aa'
const
tx
=
'0xf510c4f0b1d9ee262d7b9e9e87b4262f275fe029c2c733feef7dfa1e2b1e32aa'
cmdLine
.
startDebug
(
tx
,
shortFilename
)
cmdLine
.
startDebug
(
tx
,
shortFilename
)
...
...
remix-debug/index.js
View file @
eddc2e38
'use strict'
'use strict'
var
EthDebugger
=
require
(
'./src/Ethdebugger'
)
const
EthDebugger
=
require
(
'./src/Ethdebugger'
)
var
TransactionDebugger
=
require
(
'./src/debugger/debugger'
)
const
TransactionDebugger
=
require
(
'./src/debugger/debugger'
)
var
CmdLine
=
require
(
'./src/cmdline'
)
const
CmdLine
=
require
(
'./src/cmdline'
)
var
StorageViewer
=
require
(
'./src/storage/storageViewer'
)
const
StorageViewer
=
require
(
'./src/storage/storageViewer'
)
var
StorageResolver
=
require
(
'./src/storage/storageResolver'
)
const
StorageResolver
=
require
(
'./src/storage/storageResolver'
)
var
SolidityDecoder
=
require
(
'./src/solidity-decoder'
)
const
SolidityDecoder
=
require
(
'./src/solidity-decoder'
)
var
remixLib
=
require
(
'remix-lib'
)
const
remixLib
=
require
(
'remix-lib'
)
var
BreakpointManager
=
remixLib
.
code
.
BreakpointManager
const
BreakpointManager
=
remixLib
.
code
.
BreakpointManager
/*
/*
Use of breakPointManager :
Use of breakPointManager :
...
...
remix-debug/src/Ethdebugger.js
View file @
eddc2e38
'use strict'
'use strict'
var
StorageViewer
=
require
(
'./storage/storageViewer'
)
const
StorageViewer
=
require
(
'./storage/storageViewer'
)
var
StorageResolver
=
require
(
'./storage/storageResolver'
)
const
StorageResolver
=
require
(
'./storage/storageResolver'
)
var
SolidityDecoder
=
require
(
'./solidity-decoder'
)
const
SolidityDecoder
=
require
(
'./solidity-decoder'
)
var
SolidityProxy
=
SolidityDecoder
.
SolidityProxy
const
SolidityProxy
=
SolidityDecoder
.
SolidityProxy
var
stateDecoder
=
SolidityDecoder
.
stateDecoder
const
stateDecoder
=
SolidityDecoder
.
stateDecoder
var
localDecoder
=
SolidityDecoder
.
localDecoder
const
localDecoder
=
SolidityDecoder
.
localDecoder
var
InternalCallTree
=
SolidityDecoder
.
InternalCallTree
const
InternalCallTree
=
SolidityDecoder
.
InternalCallTree
var
remixLib
=
require
(
'remix-lib'
)
const
remixLib
=
require
(
'remix-lib'
)
var
TraceManager
=
remixLib
.
trace
.
TraceManager
const
TraceManager
=
remixLib
.
trace
.
TraceManager
var
CodeManager
=
remixLib
.
code
.
CodeManager
const
CodeManager
=
remixLib
.
code
.
CodeManager
var
traceHelper
=
remixLib
.
helpers
.
trace
const
traceHelper
=
remixLib
.
helpers
.
trace
var
EventManager
=
remixLib
.
EventManager
const
EventManager
=
remixLib
.
EventManager
/**
/**
* Ethdebugger is a wrapper around a few classes that helps debugging a transaction
* Ethdebugger is a wrapper around a few classes that helps debugging a transaction
...
@@ -75,7 +75,7 @@ Ethdebugger.prototype.sourceLocationFromVMTraceIndex = function (address, stepIn
...
@@ -75,7 +75,7 @@ Ethdebugger.prototype.sourceLocationFromVMTraceIndex = function (address, stepIn
}
}
Ethdebugger
.
prototype
.
sourceLocationFromInstructionIndex
=
function
(
address
,
instIndex
,
callback
)
{
Ethdebugger
.
prototype
.
sourceLocationFromInstructionIndex
=
function
(
address
,
instIndex
,
callback
)
{
this
.
callTree
.
sourceLocationTracker
.
getSourceLocationFromInstructionIndex
(
address
,
instIndex
,
this
.
solidityProxy
.
contracts
,
function
(
error
,
rawLocation
)
{
this
.
callTree
.
sourceLocationTracker
.
getSourceLocationFromInstructionIndex
(
address
,
instIndex
,
this
.
solidityProxy
.
contracts
,
(
error
,
rawLocation
)
=>
{
callback
(
error
,
rawLocation
)
callback
(
error
,
rawLocation
)
})
})
}
}
...
@@ -98,10 +98,10 @@ Ethdebugger.prototype.decodeLocalsAt = function (step, sourceLocation, callback)
...
@@ -98,10 +98,10 @@ Ethdebugger.prototype.decodeLocalsAt = function (step, sourceLocation, callback)
step
,
step
,
(
error
,
result
)
=>
{
(
error
,
result
)
=>
{
if
(
!
error
)
{
if
(
!
error
)
{
var
stack
=
result
[
0
].
value
const
stack
=
result
[
0
].
value
var
memory
=
result
[
1
].
value
const
memory
=
result
[
1
].
value
try
{
try
{
var
storageViewer
=
new
StorageViewer
({
const
storageViewer
=
new
StorageViewer
({
stepIndex
:
step
,
stepIndex
:
step
,
tx
:
this
.
tx
,
tx
:
this
.
tx
,
address
:
result
[
2
].
value
address
:
result
[
2
].
value
...
@@ -124,7 +124,7 @@ Ethdebugger.prototype.decodeLocalsAt = function (step, sourceLocation, callback)
...
@@ -124,7 +124,7 @@ Ethdebugger.prototype.decodeLocalsAt = function (step, sourceLocation, callback)
/* decode state */
/* decode state */
Ethdebugger
.
prototype
.
extractStateAt
=
function
(
step
,
callback
)
{
Ethdebugger
.
prototype
.
extractStateAt
=
function
(
step
,
callback
)
{
this
.
solidityProxy
.
extractStateVariablesAt
(
step
,
function
(
error
,
stateVars
)
{
this
.
solidityProxy
.
extractStateVariablesAt
(
step
,
(
error
,
stateVars
)
=>
{
callback
(
error
,
stateVars
)
callback
(
error
,
stateVars
)
})
})
}
}
...
@@ -132,7 +132,7 @@ Ethdebugger.prototype.extractStateAt = function (step, callback) {
...
@@ -132,7 +132,7 @@ Ethdebugger.prototype.extractStateAt = function (step, callback) {
Ethdebugger
.
prototype
.
decodeStateAt
=
function
(
step
,
stateVars
,
callback
)
{
Ethdebugger
.
prototype
.
decodeStateAt
=
function
(
step
,
stateVars
,
callback
)
{
this
.
traceManager
.
getCurrentCalledAddressAt
(
step
,
(
error
,
address
)
=>
{
this
.
traceManager
.
getCurrentCalledAddressAt
(
step
,
(
error
,
address
)
=>
{
if
(
error
)
return
callback
(
error
)
if
(
error
)
return
callback
(
error
)
var
storageViewer
=
new
StorageViewer
({
const
storageViewer
=
new
StorageViewer
({
stepIndex
:
step
,
stepIndex
:
step
,
tx
:
this
.
tx
,
tx
:
this
.
tx
,
address
:
address
address
:
address
...
@@ -175,16 +175,15 @@ Ethdebugger.prototype.debug = function (tx) {
...
@@ -175,16 +175,15 @@ Ethdebugger.prototype.debug = function (tx) {
}
}
this
.
setCompilationResult
(
this
.
opts
.
compilationResult
())
this
.
setCompilationResult
(
this
.
opts
.
compilationResult
())
this
.
tx
=
tx
this
.
tx
=
tx
var
self
=
this
this
.
traceManager
.
resolveTrace
(
tx
,
(
error
,
result
)
=>
{
this
.
traceManager
.
resolveTrace
(
tx
,
function
(
error
,
result
)
{
if
(
result
)
{
if
(
result
)
{
self
.
event
.
trigger
(
'newTraceLoaded'
,
[
self
.
traceManager
.
trace
])
this
.
event
.
trigger
(
'newTraceLoaded'
,
[
this
.
traceManager
.
trace
])
if
(
self
.
breakpointManager
&&
self
.
breakpointManager
.
hasBreakpoint
())
{
if
(
this
.
breakpointManager
&&
this
.
breakpointManager
.
hasBreakpoint
())
{
self
.
breakpointManager
.
jumpNextBreakpoint
(
false
)
this
.
breakpointManager
.
jumpNextBreakpoint
(
false
)
}
}
self
.
storageResolver
=
new
StorageResolver
({
web3
:
self
.
traceManager
.
web3
})
this
.
storageResolver
=
new
StorageResolver
({
web3
:
this
.
traceManager
.
web3
})
}
else
{
}
else
{
self
.
statusMessage
=
error
?
error
.
message
:
'Trace not loaded'
this
.
statusMessage
=
error
?
error
.
message
:
'Trace not loaded'
}
}
})
})
}
}
...
...
remix-debug/src/cmdline/contextManager.js
View file @
eddc2e38
var
remixLib
=
require
(
'remix-lib'
)
const
remixLib
=
require
(
'remix-lib'
)
var
EventManager
=
remixLib
.
EventManager
const
EventManager
=
remixLib
.
EventManager
var
Web3Providers
=
remixLib
.
vm
.
Web3Providers
const
Web3Providers
=
remixLib
.
vm
.
Web3Providers
var
DummyProvider
=
remixLib
.
vm
.
DummyProvider
const
DummyProvider
=
remixLib
.
vm
.
DummyProvider
var
init
=
remixLib
.
init
const
init
=
remixLib
.
init
class
ContextManager
{
class
ContextManager
{
constructor
(
executionContext
)
{
constructor
(
executionContext
)
{
...
@@ -33,23 +33,22 @@ class ContextManager {
...
@@ -33,23 +33,22 @@ class ContextManager {
}
}
switchProvider
(
type
,
cb
)
{
switchProvider
(
type
,
cb
)
{
var
self
=
this
this
.
web3Providers
.
get
(
type
,
(
error
,
obj
)
=>
{
this
.
web3Providers
.
get
(
type
,
function
(
error
,
obj
)
{
if
(
error
)
{
if
(
error
)
{
// console.log('provider ' + type + ' not defined')
// console.log('provider ' + type + ' not defined')
}
else
{
}
else
{
self
.
web3
=
obj
this
.
web3
=
obj
self
.
executionContext
.
detectNetwork
((
error
,
network
)
=>
{
this
.
executionContext
.
detectNetwork
((
error
,
network
)
=>
{
if
(
error
||
!
network
)
{
if
(
error
||
!
network
)
{
self
.
web3
=
obj
this
.
web3
=
obj
}
else
{
}
else
{
var
webDebugNode
=
init
.
web3DebugNode
(
network
.
name
)
var
webDebugNode
=
init
.
web3DebugNode
(
network
.
name
)
self
.
web3
=
(
!
webDebugNode
?
obj
:
webDebugNode
)
this
.
web3
=
(
!
webDebugNode
?
obj
:
webDebugNode
)
}
}
self
.
event
.
trigger
(
'providerChanged'
,
[
type
,
self
.
web3
])
this
.
event
.
trigger
(
'providerChanged'
,
[
type
,
this
.
web3
])
if
(
cb
)
return
cb
()
if
(
cb
)
return
cb
()
})
})
self
.
event
.
trigger
(
'providerChanged'
,
[
type
,
self
.
web3
])
this
.
event
.
trigger
(
'providerChanged'
,
[
type
,
this
.
web3
])
}
}
})
})
}
}
...
...
remix-debug/src/cmdline/index.js
View file @
eddc2e38
var
Web3
=
require
(
'web3'
)
const
Web3
=
require
(
'web3'
)
var
Debugger
=
require
(
'../debugger/debugger.js'
)
const
Debugger
=
require
(
'../debugger/debugger.js'
)
var
ContextManager
=
require
(
'./contextManager.js'
)
const
ContextManager
=
require
(
'./contextManager.js'
)
var
EventManager
=
require
(
'events'
)
const
EventManager
=
require
(
'events'
)
var
remixLib
=
require
(
'remix-lib'
)
const
remixLib
=
require
(
'remix-lib'
)
var
executionContext
=
remixLib
.
execution
.
executionContext
const
executionContext
=
remixLib
.
execution
.
executionContext
class
CmdLine
{
class
CmdLine
{
...
@@ -20,7 +20,7 @@ class CmdLine {
...
@@ -20,7 +20,7 @@ class CmdLine {
}
}
loadCompilationData
(
inputJson
,
outputJson
)
{
loadCompilationData
(
inputJson
,
outputJson
)
{
le
t
data
=
{}
cons
t
data
=
{}
data
.
data
=
outputJson
data
.
data
=
outputJson
data
.
source
=
{
sources
:
inputJson
.
sources
}
data
.
source
=
{
sources
:
inputJson
.
sources
}
this
.
loadCompilationResult
(
data
)
this
.
loadCompilationResult
(
data
)
...
@@ -32,7 +32,6 @@ class CmdLine {
...
@@ -32,7 +32,6 @@ class CmdLine {
}
}
initDebugger
(
cb
)
{
initDebugger
(
cb
)
{
const
self
=
this
this
.
contextManager
=
new
ContextManager
(
this
.
executionContext
)
this
.
contextManager
=
new
ContextManager
(
this
.
executionContext
)
this
.
debugger
=
new
Debugger
({
this
.
debugger
=
new
Debugger
({
...
@@ -41,7 +40,7 @@ class CmdLine {
...
@@ -41,7 +40,7 @@ class CmdLine {
})
})
this
.
contextManager
.
event
.
register
(
'providerChanged'
,
()
=>
{
this
.
contextManager
.
event
.
register
(
'providerChanged'
,
()
=>
{
self
.
debugger
.
updateWeb3
(
self
.
contextManager
.
getWeb3
())
this
.
debugger
.
updateWeb3
(
this
.
contextManager
.
getWeb3
())
})
})
this
.
contextManager
.
initProviders
()
this
.
contextManager
.
initProviders
()
...
@@ -51,15 +50,13 @@ class CmdLine {
...
@@ -51,15 +50,13 @@ class CmdLine {
}
}
getSource
()
{
getSource
()
{
const
self
=
this
const
lineColumnPos
=
this
.
lineColumnPos
let
lineColumnPos
=
this
.
lineColumnPos
if
(
!
lineColumnPos
||
!
lineColumnPos
.
start
)
return
[]
if
(
!
lineColumnPos
||
!
lineColumnPos
.
start
)
return
[]
let
content
=
self
.
compilation
.
lastCompilationResult
.
source
.
sources
[
this
.
filename
].
content
.
split
(
'
\
n'
)
const
content
=
this
.
compilation
.
lastCompilationResult
.
source
.
sources
[
this
.
filename
].
content
.
split
(
'
\
n'
)
le
t
source
=
[]
cons
t
source
=
[]
let
line
let
line
line
=
content
[
lineColumnPos
.
start
.
line
-
2
]
line
=
content
[
lineColumnPos
.
start
.
line
-
2
]
...
@@ -71,13 +68,13 @@ class CmdLine {
...
@@ -71,13 +68,13 @@ class CmdLine {
source
.
push
(
' '
+
lineColumnPos
.
start
.
line
+
': '
+
line
)
source
.
push
(
' '
+
lineColumnPos
.
start
.
line
+
': '
+
line
)
}
}
le
t
currentLineNumber
=
lineColumnPos
.
start
.
line
cons
t
currentLineNumber
=
lineColumnPos
.
start
.
line
le
t
currentLine
=
content
[
currentLineNumber
]
cons
t
currentLine
=
content
[
currentLineNumber
]
source
.
push
(
'=> '
+
(
currentLineNumber
+
1
)
+
': '
+
currentLine
)
source
.
push
(
'=> '
+
(
currentLineNumber
+
1
)
+
': '
+
currentLine
)
le
t
startLine
=
lineColumnPos
.
start
.
line
cons
t
startLine
=
lineColumnPos
.
start
.
line
for
(
var
i
=
1
;
i
<
4
;
i
++
)
{
for
(
var
i
=
1
;
i
<
4
;
i
++
)
{
le
t
line
=
content
[
startLine
+
i
]
cons
t
line
=
content
[
startLine
+
i
]
source
.
push
(
' '
+
(
startLine
+
i
+
1
)
+
': '
+
line
)
source
.
push
(
' '
+
(
startLine
+
i
+
1
)
+
': '
+
line
)
}
}
...
@@ -85,34 +82,33 @@ class CmdLine {
...
@@ -85,34 +82,33 @@ class CmdLine {
}
}
getCurrentLine
()
{
getCurrentLine
()
{
le
t
lineColumnPos
=
this
.
lineColumnPos
cons
t
lineColumnPos
=
this
.
lineColumnPos
if
(
!
lineColumnPos
)
return
''
if
(
!
lineColumnPos
)
return
''
le
t
currentLineNumber
=
lineColumnPos
.
start
.
line
cons
t
currentLineNumber
=
lineColumnPos
.
start
.
line
le
t
content
=
this
.
compilation
.
lastCompilationResult
.
source
.
sources
[
this
.
filename
].
content
.
split
(
'
\
n'
)
cons
t
content
=
this
.
compilation
.
lastCompilationResult
.
source
.
sources
[
this
.
filename
].
content
.
split
(
'
\
n'
)
return
content
[
currentLineNumber
]
return
content
[
currentLineNumber
]
}
}
startDebug
(
txNumber
,
filename
,
cb
)
{
startDebug
(
txNumber
,
filename
,
cb
)
{
const
self
=
this
this
.
filename
=
filename
this
.
filename
=
filename
this
.
txHash
=
txNumber
this
.
txHash
=
txNumber
this
.
debugger
.
debug
(
null
,
txNumber
,
null
,
()
=>
{
this
.
debugger
.
debug
(
null
,
txNumber
,
null
,
()
=>
{
self
.
debugger
.
event
.
register
(
'newSourceLocation'
,
function
(
lineColumnPos
,
rawLocation
)
{
this
.
debugger
.
event
.
register
(
'newSourceLocation'
,
(
lineColumnPos
,
rawLocation
)
=>
{
self
.
lineColumnPos
=
lineColumnPos
this
.
lineColumnPos
=
lineColumnPos
self
.
rawLocation
=
rawLocation
this
.
rawLocation
=
rawLocation
self
.
events
.
emit
(
'source'
,
[
lineColumnPos
,
rawLocation
])
this
.
events
.
emit
(
'source'
,
[
lineColumnPos
,
rawLocation
])
})
})
self
.
debugger
.
vmDebuggerLogic
.
event
.
register
(
'solidityState'
,
(
data
)
=>
{
this
.
debugger
.
vmDebuggerLogic
.
event
.
register
(
'solidityState'
,
(
data
)
=>
{
self
.
solidityState
=
data
this
.
solidityState
=
data
self
.
events
.
emit
(
'globals'
,
data
)
this
.
events
.
emit
(
'globals'
,
data
)
})
})
// TODO: this doesnt work too well, it should request the data instead...
// TODO: this doesnt work too well, it should request the data instead...
self
.
debugger
.
vmDebuggerLogic
.
event
.
register
(
'solidityLocals'
,
(
data
)
=>
{
this
.
debugger
.
vmDebuggerLogic
.
event
.
register
(
'solidityLocals'
,
(
data
)
=>
{
if
(
JSON
.
stringify
(
data
)
===
'{}'
)
return
if
(
JSON
.
stringify
(
data
)
===
'{}'
)
return
self
.
solidityLocals
=
data
this
.
solidityLocals
=
data
self
.
events
.
emit
(
'locals'
,
data
)
this
.
events
.
emit
(
'locals'
,
data
)
})
})
if
(
cb
)
{
if
(
cb
)
{
...
@@ -215,4 +211,3 @@ class CmdLine {
...
@@ -215,4 +211,3 @@ class CmdLine {
}
}
module
.
exports
=
CmdLine
module
.
exports
=
CmdLine
remix-debug/src/debugger/VmDebugger.js
View file @
eddc2e38
var
remixLib
=
require
(
'remix-lib'
)
const
remixLib
=
require
(
'remix-lib'
)
var
EventManager
=
remixLib
.
EventManager
const
EventManager
=
remixLib
.
EventManager
var
ui
=
remixLib
.
helpers
.
ui
const
ui
=
remixLib
.
helpers
.
ui
var
StorageResolver
=
require
(
'../storage/storageResolver'
)
const
StorageResolver
=
require
(
'../storage/storageResolver'
)
var
StorageViewer
=
require
(
'../storage/storageViewer'
)
const
StorageViewer
=
require
(
'../storage/storageViewer'
)
var
DebuggerSolidityState
=
require
(
'./solidityState'
)
const
DebuggerSolidityState
=
require
(
'./solidityState'
)
var
DebuggerSolidityLocals
=
require
(
'./solidityLocals'
)
const
DebuggerSolidityLocals
=
require
(
'./solidityLocals'
)
class
VmDebuggerLogic
{
class
VmDebuggerLogic
{
...
@@ -36,151 +36,145 @@ class VmDebuggerLogic {
...
@@ -36,151 +36,145 @@ class VmDebuggerLogic {
}
}
listenToEvents
()
{
listenToEvents
()
{
const
self
=
this
this
.
debugger
.
event
.
register
(
'traceUnloaded'
,
()
=>
{
this
.
debugger
.
event
.
register
(
'traceUnloaded'
,
function
()
{
this
.
event
.
trigger
(
'traceUnloaded'
)
self
.
event
.
trigger
(
'traceUnloaded'
)
})
})
this
.
debugger
.
event
.
register
(
'newTraceLoaded'
,
function
()
{
this
.
debugger
.
event
.
register
(
'newTraceLoaded'
,
()
=>
{
self
.
event
.
trigger
(
'newTraceLoaded'
)
this
.
event
.
trigger
(
'newTraceLoaded'
)
})
})
}
}
listenToCodeManagerEvents
()
{
listenToCodeManagerEvents
()
{
const
self
=
this
this
.
_codeManager
.
event
.
register
(
'changed'
,
(
code
,
address
,
index
)
=>
{
this
.
_codeManager
.
event
.
register
(
'changed'
,
function
(
code
,
address
,
index
)
{
this
.
event
.
trigger
(
'codeManagerChanged'
,
[
code
,
address
,
index
])
self
.
event
.
trigger
(
'codeManagerChanged'
,
[
code
,
address
,
index
])
})
})
}
}
listenToTraceManagerEvents
()
{
listenToTraceManagerEvents
()
{
const
self
=
this
this
.
event
.
register
(
'indexChanged'
,
this
,
(
index
)
=>
{
this
.
event
.
register
(
'indexChanged'
,
this
,
function
(
index
)
{
if
(
index
<
0
)
return
if
(
index
<
0
)
return
if
(
self
.
stepManager
.
currentStepIndex
!==
index
)
return
if
(
this
.
stepManager
.
currentStepIndex
!==
index
)
return
self
.
event
.
trigger
(
'indexUpdate'
,
[
index
])
this
.
event
.
trigger
(
'indexUpdate'
,
[
index
])
self
.
_traceManager
.
getCallDataAt
(
index
,
function
(
error
,
calldata
)
{
this
.
_traceManager
.
getCallDataAt
(
index
,
(
error
,
calldata
)
=>
{
if
(
error
)
{
if
(
error
)
{
// console.log(error)
// console.log(error)
self
.
event
.
trigger
(
'traceManagerCallDataUpdate'
,
[{}])
this
.
event
.
trigger
(
'traceManagerCallDataUpdate'
,
[{}])
}
else
if
(
self
.
stepManager
.
currentStepIndex
===
index
)
{
}
else
if
(
this
.
stepManager
.
currentStepIndex
===
index
)
{
self
.
event
.
trigger
(
'traceManagerCallDataUpdate'
,
[
calldata
])
this
.
event
.
trigger
(
'traceManagerCallDataUpdate'
,
[
calldata
])
}
}
})
})
self
.
_traceManager
.
getMemoryAt
(
index
,
function
(
error
,
memory
)
{
this
.
_traceManager
.
getMemoryAt
(
index
,
(
error
,
memory
)
=>
{
if
(
error
)
{
if
(
error
)
{
// console.log(error)
// console.log(error)
self
.
event
.
trigger
(
'traceManagerMemoryUpdate'
,
[{}])
this
.
event
.
trigger
(
'traceManagerMemoryUpdate'
,
[{}])
}
else
if
(
self
.
stepManager
.
currentStepIndex
===
index
)
{
}
else
if
(
this
.
stepManager
.
currentStepIndex
===
index
)
{
self
.
event
.
trigger
(
'traceManagerMemoryUpdate'
,
[
ui
.
formatMemory
(
memory
,
16
)])
this
.
event
.
trigger
(
'traceManagerMemoryUpdate'
,
[
ui
.
formatMemory
(
memory
,
16
)])
}
}
})
})
self
.
_traceManager
.
getCallStackAt
(
index
,
function
(
error
,
callstack
)
{
this
.
_traceManager
.
getCallStackAt
(
index
,
(
error
,
callstack
)
=>
{
if
(
error
)
{
if
(
error
)
{
// console.log(error)
// console.log(error)
self
.
event
.
trigger
(
'traceManagerCallStackUpdate'
,
[{}])
this
.
event
.
trigger
(
'traceManagerCallStackUpdate'
,
[{}])
}
else
if
(
self
.
stepManager
.
currentStepIndex
===
index
)
{
}
else
if
(
this
.
stepManager
.
currentStepIndex
===
index
)
{
self
.
event
.
trigger
(
'traceManagerCallStackUpdate'
,
[
callstack
])
this
.
event
.
trigger
(
'traceManagerCallStackUpdate'
,
[
callstack
])
}
}
})
})
self
.
_traceManager
.
getStackAt
(
index
,
function
(
error
,
callstack
)
{
this
.
_traceManager
.
getStackAt
(
index
,
(
error
,
callstack
)
=>
{
if
(
error
)
{
if
(
error
)
{
// console.log(error)
// console.log(error)
self
.
event
.
trigger
(
'traceManagerStackUpdate'
,
[{}])
this
.
event
.
trigger
(
'traceManagerStackUpdate'
,
[{}])
}
else
if
(
self
.
stepManager
.
currentStepIndex
===
index
)
{
}
else
if
(
this
.
stepManager
.
currentStepIndex
===
index
)
{
self
.
event
.
trigger
(
'traceManagerStackUpdate'
,
[
callstack
])
this
.
event
.
trigger
(
'traceManagerStackUpdate'
,
[
callstack
])
}
}
})
})
self
.
_traceManager
.
getCurrentCalledAddressAt
(
index
,
(
error
,
address
)
=>
{
this
.
_traceManager
.
getCurrentCalledAddressAt
(
index
,
(
error
,
address
)
=>
{
if
(
error
)
return
if
(
error
)
return
if
(
!
self
.
storageResolver
)
return
if
(
!
this
.
storageResolver
)
return
var
storageViewer
=
new
StorageViewer
({
stepIndex
:
self
.
stepManager
.
currentStepIndex
,
tx
:
self
.
tx
,
address
:
address
},
self
.
storageResolver
,
self
.
_traceManager
)
var
storageViewer
=
new
StorageViewer
({
stepIndex
:
this
.
stepManager
.
currentStepIndex
,
tx
:
this
.
tx
,
address
:
address
},
this
.
storageResolver
,
this
.
_traceManager
)
storageViewer
.
storageRange
((
error
,
storage
)
=>
{
storageViewer
.
storageRange
((
error
,
storage
)
=>
{
if
(
error
)
{
if
(
error
)
{
// console.log(error)
// console.log(error)
self
.
event
.
trigger
(
'traceManagerStorageUpdate'
,
[{}])
this
.
event
.
trigger
(
'traceManagerStorageUpdate'
,
[{}])
}
else
if
(
self
.
stepManager
.
currentStepIndex
===
index
)
{
}
else
if
(
this
.
stepManager
.
currentStepIndex
===
index
)
{
var
header
=
storageViewer
.
isComplete
(
address
)
?
'completely loaded'
:
'partially loaded...'
var
header
=
storageViewer
.
isComplete
(
address
)
?
'completely loaded'
:
'partially loaded...'
self
.
event
.
trigger
(
'traceManagerStorageUpdate'
,
[
storage
,
header
])
this
.
event
.
trigger
(
'traceManagerStorageUpdate'
,
[
storage
,
header
])
}
}
})
})
})
})
self
.
_traceManager
.
getCurrentStep
(
index
,
function
(
error
,
step
)
{
this
.
_traceManager
.
getCurrentStep
(
index
,
(
error
,
step
)
=>
{
self
.
event
.
trigger
(
'traceCurrentStepUpdate'
,
[
error
,
step
])
this
.
event
.
trigger
(
'traceCurrentStepUpdate'
,
[
error
,
step
])
})
})
self
.
_traceManager
.
getMemExpand
(
index
,
function
(
error
,
addmem
)
{
this
.
_traceManager
.
getMemExpand
(
index
,
(
error
,
addmem
)
=>
{
self
.
event
.
trigger
(
'traceMemExpandUpdate'
,
[
error
,
addmem
])
this
.
event
.
trigger
(
'traceMemExpandUpdate'
,
[
error
,
addmem
])
})
})
self
.
_traceManager
.
getStepCost
(
index
,
function
(
error
,
gas
)
{
this
.
_traceManager
.
getStepCost
(
index
,
(
error
,
gas
)
=>
{
self
.
event
.
trigger
(
'traceStepCostUpdate'
,
[
error
,
gas
])
this
.
event
.
trigger
(
'traceStepCostUpdate'
,
[
error
,
gas
])
})
})
self
.
_traceManager
.
getCurrentCalledAddressAt
(
index
,
function
(
error
,
address
)
{
this
.
_traceManager
.
getCurrentCalledAddressAt
(
index
,
(
error
,
address
)
=>
{
self
.
event
.
trigger
(
'traceCurrentCalledAddressAtUpdate'
,
[
error
,
address
])
this
.
event
.
trigger
(
'traceCurrentCalledAddressAtUpdate'
,
[
error
,
address
])
})
})
self
.
_traceManager
.
getRemainingGas
(
index
,
function
(
error
,
remaining
)
{
this
.
_traceManager
.
getRemainingGas
(
index
,
(
error
,
remaining
)
=>
{
self
.
event
.
trigger
(
'traceRemainingGasUpdate'
,
[
error
,
remaining
])
this
.
event
.
trigger
(
'traceRemainingGasUpdate'
,
[
error
,
remaining
])
})
})
self
.
_traceManager
.
getReturnValue
(
index
,
function
(
error
,
returnValue
)
{
this
.
_traceManager
.
getReturnValue
(
index
,
(
error
,
returnValue
)
=>
{
if
(
error
)
{
if
(
error
)
{
self
.
event
.
trigger
(
'traceReturnValueUpdate'
,
[[
error
]])
this
.
event
.
trigger
(
'traceReturnValueUpdate'
,
[[
error
]])
}
else
if
(
self
.
stepManager
.
currentStepIndex
===
index
)
{
}
else
if
(
this
.
stepManager
.
currentStepIndex
===
index
)
{
self
.
event
.
trigger
(
'traceReturnValueUpdate'
,
[[
returnValue
]])
this
.
event
.
trigger
(
'traceReturnValueUpdate'
,
[[
returnValue
]])
}
}
})
})
})
})
}
}
listenToFullStorageChanges
()
{
listenToFullStorageChanges
()
{
const
self
=
this
this
.
address
=
[]
this
.
address
=
[]
this
.
traceLength
=
0
this
.
traceLength
=
0
self
.
debugger
.
event
.
register
(
'newTraceLoaded'
,
function
(
length
)
{
this
.
debugger
.
event
.
register
(
'newTraceLoaded'
,
(
length
)
=>
{
self
.
_traceManager
.
getAddresses
(
function
(
error
,
addresses
)
{
this
.
_traceManager
.
getAddresses
((
error
,
addresses
)
=>
{
if
(
error
)
return
if
(
error
)
return
self
.
event
.
trigger
(
'traceAddressesUpdate'
,
[
addresses
])
this
.
event
.
trigger
(
'traceAddressesUpdate'
,
[
addresses
])
self
.
addresses
=
addresses
this
.
addresses
=
addresses
})
})
self
.
_traceManager
.
getLength
(
function
(
error
,
length
)
{
this
.
_traceManager
.
getLength
((
error
,
length
)
=>
{
if
(
error
)
return
if
(
error
)
return
self
.
event
.
trigger
(
'traceLengthUpdate'
,
[
length
])
this
.
event
.
trigger
(
'traceLengthUpdate'
,
[
length
])
self
.
traceLength
=
length
this
.
traceLength
=
length
})
})
})
})
self
.
debugger
.
event
.
register
(
'indexChanged'
,
this
,
function
(
index
)
{
this
.
debugger
.
event
.
register
(
'indexChanged'
,
this
,
(
index
)
=>
{
if
(
index
<
0
)
return
if
(
index
<
0
)
return
if
(
self
.
stepManager
.
currentStepIndex
!==
index
)
return
if
(
this
.
stepManager
.
currentStepIndex
!==
index
)
return
if
(
!
self
.
storageResolver
)
return
if
(
!
this
.
storageResolver
)
return
// Clean up storage update
// Clean up storage update
if
(
index
===
self
.
traceLength
-
1
)
{
if
(
index
===
this
.
traceLength
-
1
)
{
return
self
.
event
.
trigger
(
'traceStorageUpdate'
,
[{}])
return
this
.
event
.
trigger
(
'traceStorageUpdate'
,
[{}])
}
}
var
storageJSON
=
{}
var
storageJSON
=
{}
for
(
var
k
in
self
.
addresses
)
{
for
(
var
k
in
this
.
addresses
)
{
var
address
=
self
.
addresses
[
k
]
var
address
=
this
.
addresses
[
k
]
var
storageViewer
=
new
StorageViewer
({
stepIndex
:
self
.
stepManager
.
currentStepIndex
,
tx
:
self
.
tx
,
address
:
address
},
self
.
storageResolver
,
self
.
_traceManager
)
var
storageViewer
=
new
StorageViewer
({
stepIndex
:
this
.
stepManager
.
currentStepIndex
,
tx
:
this
.
tx
,
address
:
address
},
this
.
storageResolver
,
this
.
_traceManager
)
storageViewer
.
storageRange
(
function
(
error
,
result
)
{
storageViewer
.
storageRange
(
(
error
,
result
)
=>
{
if
(
!
error
)
{
if
(
!
error
)
{
storageJSON
[
address
]
=
result
storageJSON
[
address
]
=
result
self
.
event
.
trigger
(
'traceStorageUpdate'
,
[
storageJSON
])
this
.
event
.
trigger
(
'traceStorageUpdate'
,
[
storageJSON
])
}
}
})
})
}
}
...
@@ -188,51 +182,48 @@ class VmDebuggerLogic {
...
@@ -188,51 +182,48 @@ class VmDebuggerLogic {
}
}
listenToNewChanges
()
{
listenToNewChanges
()
{
const
self
=
this
this
.
debugger
.
event
.
register
(
'newTraceLoaded'
,
this
,
()
=>
{
self
.
debugger
.
event
.
register
(
'newTraceLoaded'
,
this
,
function
()
{
this
.
storageResolver
=
new
StorageResolver
({
web3
:
this
.
debugger
.
web3
})
self
.
storageResolver
=
new
StorageResolver
({
web3
:
self
.
debugger
.
web3
})
this
.
debuggerSolidityState
.
storageResolver
=
this
.
storageResolver
self
.
debuggerSolidityState
.
storageResolver
=
self
.
storageResolver
this
.
debuggerSolidityLocals
.
storageResolver
=
this
.
storageResolver
self
.
debuggerSolidityLocals
.
storageResolver
=
self
.
storageResolver
this
.
event
.
trigger
(
'newTrace'
,
[])
self
.
event
.
trigger
(
'newTrace'
,
[])
})
})
self
.
debugger
.
callTree
.
event
.
register
(
'callTreeReady'
,
function
()
{
this
.
debugger
.
callTree
.
event
.
register
(
'callTreeReady'
,
()
=>
{
if
(
self
.
debugger
.
callTree
.
reducedTrace
.
length
)
{
if
(
this
.
debugger
.
callTree
.
reducedTrace
.
length
)
{
return
self
.
event
.
trigger
(
'newCallTree'
,
[])
return
this
.
event
.
trigger
(
'newCallTree'
,
[])
}
}
})
})
}
}
listenToSolidityStateEvents
()
{
listenToSolidityStateEvents
()
{
const
self
=
this
this
.
event
.
register
(
'indexChanged'
,
this
.
debuggerSolidityState
.
init
.
bind
(
this
.
debuggerSolidityState
))
this
.
event
.
register
(
'indexChanged'
,
this
.
debuggerSolidityState
.
init
.
bind
(
this
.
debuggerSolidityState
))
this
.
debuggerSolidityState
.
event
.
register
(
'solidityState'
,
function
(
state
)
{
this
.
debuggerSolidityState
.
event
.
register
(
'solidityState'
,
(
state
)
=>
{
self
.
event
.
trigger
(
'solidityState'
,
[
state
])
this
.
event
.
trigger
(
'solidityState'
,
[
state
])
})
})
this
.
debuggerSolidityState
.
event
.
register
(
'solidityStateMessage'
,
function
(
message
)
{
this
.
debuggerSolidityState
.
event
.
register
(
'solidityStateMessage'
,
(
message
)
=>
{
self
.
event
.
trigger
(
'solidityStateMessage'
,
[
message
])
this
.
event
.
trigger
(
'solidityStateMessage'
,
[
message
])
})
})
this
.
debuggerSolidityState
.
event
.
register
(
'solidityStateUpdating'
,
function
()
{
this
.
debuggerSolidityState
.
event
.
register
(
'solidityStateUpdating'
,
()
=>
{
self
.
event
.
trigger
(
'solidityStateUpdating'
,
[])
this
.
event
.
trigger
(
'solidityStateUpdating'
,
[])
})
})
this
.
event
.
register
(
'traceUnloaded'
,
this
.
debuggerSolidityState
.
reset
.
bind
(
this
.
debuggerSolidityState
))
this
.
event
.
register
(
'traceUnloaded'
,
this
.
debuggerSolidityState
.
reset
.
bind
(
this
.
debuggerSolidityState
))
this
.
event
.
register
(
'newTraceLoaded'
,
this
.
debuggerSolidityState
.
reset
.
bind
(
this
.
debuggerSolidityState
))
this
.
event
.
register
(
'newTraceLoaded'
,
this
.
debuggerSolidityState
.
reset
.
bind
(
this
.
debuggerSolidityState
))
}
}
listenToSolidityLocalsEvents
()
{
listenToSolidityLocalsEvents
()
{
const
self
=
this
this
.
event
.
register
(
'sourceLocationChanged'
,
this
.
debuggerSolidityLocals
.
init
.
bind
(
this
.
debuggerSolidityLocals
))
this
.
event
.
register
(
'sourceLocationChanged'
,
this
.
debuggerSolidityLocals
.
init
.
bind
(
this
.
debuggerSolidityLocals
))
this
.
debuggerSolidityLocals
.
event
.
register
(
'solidityLocals'
,
function
(
state
)
{
this
.
debuggerSolidityLocals
.
event
.
register
(
'solidityLocals'
,
(
state
)
=>
{
self
.
event
.
trigger
(
'solidityLocals'
,
[
state
])
this
.
event
.
trigger
(
'solidityLocals'
,
[
state
])
})
})
this
.
debuggerSolidityLocals
.
event
.
register
(
'solidityLocalsMessage'
,
function
(
message
)
{
this
.
debuggerSolidityLocals
.
event
.
register
(
'solidityLocalsMessage'
,
(
message
)
=>
{
self
.
event
.
trigger
(
'solidityLocalsMessage'
,
[
message
])
this
.
event
.
trigger
(
'solidityLocalsMessage'
,
[
message
])
})
})
this
.
debuggerSolidityLocals
.
event
.
register
(
'solidityLocalsUpdating'
,
function
()
{
this
.
debuggerSolidityLocals
.
event
.
register
(
'solidityLocalsUpdating'
,
()
=>
{
self
.
event
.
trigger
(
'solidityLocalsUpdating'
,
[])
this
.
event
.
trigger
(
'solidityLocalsUpdating'
,
[])
})
})
this
.
debuggerSolidityLocals
.
event
.
register
(
'traceReturnValueUpdate'
,
function
(
data
,
header
)
{
this
.
debuggerSolidityLocals
.
event
.
register
(
'traceReturnValueUpdate'
,
(
data
,
header
)
=>
{
self
.
event
.
trigger
(
'traceReturnValueUpdate'
,
[
data
,
header
])
this
.
event
.
trigger
(
'traceReturnValueUpdate'
,
[
data
,
header
])
})
})
}
}
...
...
remix-debug/src/debugger/debugger.js
View file @
eddc2e38
'use strict'
'use strict'
var
Ethdebugger
=
require
(
'../Ethdebugger'
)
const
Ethdebugger
=
require
(
'../Ethdebugger'
)
var
remixLib
=
require
(
'remix-lib'
)
const
remixLib
=
require
(
'remix-lib'
)
var
EventManager
=
remixLib
.
EventManager
const
EventManager
=
remixLib
.
EventManager
var
traceHelper
=
remixLib
.
helpers
.
trace
const
traceHelper
=
remixLib
.
helpers
.
trace
var
OffsetToColumnConverter
=
remixLib
.
OffsetToColumnConverter
const
OffsetToColumnConverter
=
remixLib
.
OffsetToColumnConverter
var
StepManager
=
require
(
'./stepManager'
)
const
StepManager
=
require
(
'./stepManager'
)
var
VmDebuggerLogic
=
require
(
'./VmDebugger'
)
const
VmDebuggerLogic
=
require
(
'./VmDebugger'
)
function
Debugger
(
options
)
{
function
Debugger
(
options
)
{
var
self
=
this
this
.
event
=
new
EventManager
()
this
.
event
=
new
EventManager
()
this
.
offsetToLineColumnConverter
=
options
.
offsetToLineColumnConverter
||
(
new
OffsetToColumnConverter
())
this
.
offsetToLineColumnConverter
=
options
.
offsetToLineColumnConverter
||
(
new
OffsetToColumnConverter
())
...
@@ -27,38 +26,37 @@ function Debugger (options) {
...
@@ -27,38 +26,37 @@ function Debugger (options) {
})
})
this
.
breakPointManager
=
new
remixLib
.
code
.
BreakpointManager
(
this
.
debugger
,
(
sourceLocation
)
=>
{
this
.
breakPointManager
=
new
remixLib
.
code
.
BreakpointManager
(
this
.
debugger
,
(
sourceLocation
)
=>
{
return
self
.
offsetToLineColumnConverter
.
offsetToLineColumn
(
sourceLocation
,
sourceLocation
.
file
,
this
.
compiler
.
lastCompilationResult
.
source
.
sources
,
this
.
compiler
.
lastCompilationResult
.
data
.
sources
)
return
this
.
offsetToLineColumnConverter
.
offsetToLineColumn
(
sourceLocation
,
sourceLocation
.
file
,
this
.
compiler
.
lastCompilationResult
.
source
.
sources
,
this
.
compiler
.
lastCompilationResult
.
data
.
sources
)
},
(
step
)
=>
{
},
(
step
)
=>
{
self
.
event
.
trigger
(
'breakpointStep'
,
[
step
])
this
.
event
.
trigger
(
'breakpointStep'
,
[
step
])
})
})
this
.
debugger
.
setBreakpointManager
(
this
.
breakPointManager
)
this
.
debugger
.
setBreakpointManager
(
this
.
breakPointManager
)
this
.
debugger
.
event
.
register
(
'newTraceLoaded'
,
this
,
function
()
{
this
.
debugger
.
event
.
register
(
'newTraceLoaded'
,
this
,
()
=>
{
self
.
event
.
trigger
(
'debuggerStatus'
,
[
true
])
this
.
event
.
trigger
(
'debuggerStatus'
,
[
true
])
})
})
this
.
debugger
.
event
.
register
(
'traceUnloaded'
,
this
,
function
()
{
this
.
debugger
.
event
.
register
(
'traceUnloaded'
,
this
,
()
=>
{
self
.
event
.
trigger
(
'debuggerStatus'
,
[
false
])
this
.
event
.
trigger
(
'debuggerStatus'
,
[
false
])
})
})
this
.
event
.
register
(
'breakpointStep'
,
function
(
step
)
{
this
.
event
.
register
(
'breakpointStep'
,
(
step
)
=>
{
self
.
step_manager
.
jumpTo
(
step
)
this
.
step_manager
.
jumpTo
(
step
)
})
})
}
}
Debugger
.
prototype
.
registerAndHighlightCodeItem
=
function
(
index
)
{
Debugger
.
prototype
.
registerAndHighlightCodeItem
=
function
(
index
)
{
const
self
=
this
// register selected code item, highlight the corresponding source location
// register selected code item, highlight the corresponding source location
if
(
!
self
.
compiler
.
lastCompilationResult
)
return
if
(
!
this
.
compiler
.
lastCompilationResult
)
return
self
.
debugger
.
traceManager
.
getCurrentCalledAddressAt
(
index
,
(
error
,
address
)
=>
{
this
.
debugger
.
traceManager
.
getCurrentCalledAddressAt
(
index
,
(
error
,
address
)
=>
{
if
(
error
)
return
console
.
log
(
error
)
if
(
error
)
return
console
.
log
(
error
)
self
.
debugger
.
callTree
.
sourceLocationTracker
.
getSourceLocationFromVMTraceIndex
(
address
,
index
,
self
.
compiler
.
lastCompilationResult
.
data
.
contracts
,
function
(
error
,
rawLocation
)
{
this
.
debugger
.
callTree
.
sourceLocationTracker
.
getSourceLocationFromVMTraceIndex
(
address
,
index
,
this
.
compiler
.
lastCompilationResult
.
data
.
contracts
,
(
error
,
rawLocation
)
=>
{
if
(
!
error
&&
self
.
compiler
.
lastCompilationResult
&&
self
.
compiler
.
lastCompilationResult
.
data
)
{
if
(
!
error
&&
this
.
compiler
.
lastCompilationResult
&&
this
.
compiler
.
lastCompilationResult
.
data
)
{
var
lineColumnPos
=
self
.
offsetToLineColumnConverter
.
offsetToLineColumn
(
rawLocation
,
rawLocation
.
file
,
self
.
compiler
.
lastCompilationResult
.
source
.
sources
,
self
.
compiler
.
lastCompilationResult
.
data
.
sources
)
var
lineColumnPos
=
this
.
offsetToLineColumnConverter
.
offsetToLineColumn
(
rawLocation
,
rawLocation
.
file
,
this
.
compiler
.
lastCompilationResult
.
source
.
sources
,
this
.
compiler
.
lastCompilationResult
.
data
.
sources
)
self
.
event
.
trigger
(
'newSourceLocation'
,
[
lineColumnPos
,
rawLocation
])
this
.
event
.
trigger
(
'newSourceLocation'
,
[
lineColumnPos
,
rawLocation
])
}
else
{
}
else
{
self
.
event
.
trigger
(
'newSourceLocation'
,
[
null
])
this
.
event
.
trigger
(
'newSourceLocation'
,
[
null
])
}
}
})
})
})
})
...
@@ -69,7 +67,7 @@ Debugger.prototype.updateWeb3 = function (web3) {
...
@@ -69,7 +67,7 @@ Debugger.prototype.updateWeb3 = function (web3) {
}
}
Debugger
.
prototype
.
debug
=
function
(
blockNumber
,
txNumber
,
tx
,
loadingCb
)
{
Debugger
.
prototype
.
debug
=
function
(
blockNumber
,
txNumber
,
tx
,
loadingCb
)
{
le
t
web3
=
this
.
debugger
.
web3
cons
t
web3
=
this
.
debugger
.
web3
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
this
.
debugger
.
traceManager
.
isLoading
)
{
if
(
this
.
debugger
.
traceManager
.
isLoading
)
{
...
@@ -106,13 +104,12 @@ Debugger.prototype.debug = function (blockNumber, txNumber, tx, loadingCb) {
...
@@ -106,13 +104,12 @@ Debugger.prototype.debug = function (blockNumber, txNumber, tx, loadingCb) {
}
}
Debugger
.
prototype
.
debugTx
=
function
(
tx
,
loadingCb
)
{
Debugger
.
prototype
.
debugTx
=
function
(
tx
,
loadingCb
)
{
const
self
=
this
this
.
step_manager
=
new
StepManager
(
this
.
debugger
,
this
.
debugger
.
traceManager
)
this
.
step_manager
=
new
StepManager
(
this
.
debugger
,
this
.
debugger
.
traceManager
)
this
.
debugger
.
codeManager
.
event
.
register
(
'changed'
,
this
,
(
code
,
address
,
instIndex
)
=>
{
this
.
debugger
.
codeManager
.
event
.
register
(
'changed'
,
this
,
(
code
,
address
,
instIndex
)
=>
{
self
.
debugger
.
callTree
.
sourceLocationTracker
.
getSourceLocationFromVMTraceIndex
(
address
,
this
.
step_manager
.
currentStepIndex
,
this
.
debugger
.
solidityProxy
.
contracts
,
(
error
,
sourceLocation
)
=>
{
this
.
debugger
.
callTree
.
sourceLocationTracker
.
getSourceLocationFromVMTraceIndex
(
address
,
this
.
step_manager
.
currentStepIndex
,
this
.
debugger
.
solidityProxy
.
contracts
,
(
error
,
sourceLocation
)
=>
{
if
(
!
error
)
{
if
(
!
error
)
{
self
.
vmDebuggerLogic
.
event
.
trigger
(
'sourceLocationChanged'
,
[
sourceLocation
])
this
.
vmDebuggerLogic
.
event
.
trigger
(
'sourceLocationChanged'
,
[
sourceLocation
])
}
}
})
})
})
})
...
@@ -120,16 +117,16 @@ Debugger.prototype.debugTx = function (tx, loadingCb) {
...
@@ -120,16 +117,16 @@ Debugger.prototype.debugTx = function (tx, loadingCb) {
this
.
vmDebuggerLogic
=
new
VmDebuggerLogic
(
this
.
debugger
,
tx
,
this
.
step_manager
,
this
.
debugger
.
traceManager
,
this
.
debugger
.
codeManager
,
this
.
debugger
.
solidityProxy
,
this
.
debugger
.
callTree
)
this
.
vmDebuggerLogic
=
new
VmDebuggerLogic
(
this
.
debugger
,
tx
,
this
.
step_manager
,
this
.
debugger
.
traceManager
,
this
.
debugger
.
codeManager
,
this
.
debugger
.
solidityProxy
,
this
.
debugger
.
callTree
)
this
.
vmDebuggerLogic
.
start
()
this
.
vmDebuggerLogic
.
start
()
this
.
step_manager
.
event
.
register
(
'stepChanged'
,
this
,
function
(
stepIndex
)
{
this
.
step_manager
.
event
.
register
(
'stepChanged'
,
this
,
(
stepIndex
)
=>
{
if
(
typeof
stepIndex
!==
'number'
||
stepIndex
>=
self
.
step_manager
.
traceLength
)
{
if
(
typeof
stepIndex
!==
'number'
||
stepIndex
>=
this
.
step_manager
.
traceLength
)
{
return
self
.
event
.
trigger
(
'endDebug'
)
return
this
.
event
.
trigger
(
'endDebug'
)
}
}
self
.
debugger
.
codeManager
.
resolveStep
(
stepIndex
,
tx
)
this
.
debugger
.
codeManager
.
resolveStep
(
stepIndex
,
tx
)
self
.
step_manager
.
event
.
trigger
(
'indexChanged'
,
[
stepIndex
])
this
.
step_manager
.
event
.
trigger
(
'indexChanged'
,
[
stepIndex
])
self
.
vmDebuggerLogic
.
event
.
trigger
(
'indexChanged'
,
[
stepIndex
])
this
.
vmDebuggerLogic
.
event
.
trigger
(
'indexChanged'
,
[
stepIndex
])
self
.
vmDebuggerLogic
.
debugger
.
event
.
trigger
(
'indexChanged'
,
[
stepIndex
])
this
.
vmDebuggerLogic
.
debugger
.
event
.
trigger
(
'indexChanged'
,
[
stepIndex
])
self
.
registerAndHighlightCodeItem
(
stepIndex
)
this
.
registerAndHighlightCodeItem
(
stepIndex
)
})
})
loadingCb
()
loadingCb
()
...
...
remix-debug/src/debugger/solidityLocals.js
View file @
eddc2e38
var
remixLib
=
require
(
'remix-lib'
)
const
remixLib
=
require
(
'remix-lib'
)
var
EventManager
=
remixLib
.
EventManager
const
EventManager
=
remixLib
.
EventManager
var
localDecoder
=
require
(
'../solidity-decoder/localDecoder'
)
const
localDecoder
=
require
(
'../solidity-decoder/localDecoder'
)
var
StorageViewer
=
require
(
'../storage/storageViewer'
)
const
StorageViewer
=
require
(
'../storage/storageViewer'
)
class
DebuggerSolidityLocals
{
class
DebuggerSolidityLocals
{
...
@@ -16,28 +16,26 @@ class DebuggerSolidityLocals {
...
@@ -16,28 +16,26 @@ class DebuggerSolidityLocals {
}
}
init
(
sourceLocation
)
{
init
(
sourceLocation
)
{
const
self
=
this
var
decodeTimeout
=
null
var
decodeTimeout
=
null
if
(
!
this
.
storageResolver
)
{
if
(
!
this
.
storageResolver
)
{
return
self
.
event
.
trigger
(
'solidityLocalsMessage'
,
[
'storage not ready'
])
return
this
.
event
.
trigger
(
'solidityLocalsMessage'
,
[
'storage not ready'
])
}
}
if
(
decodeTimeout
)
{
if
(
decodeTimeout
)
{
window
.
clearTimeout
(
decodeTimeout
)
window
.
clearTimeout
(
decodeTimeout
)
}
}
self
.
event
.
trigger
(
'solidityLocalsUpdating'
)
this
.
event
.
trigger
(
'solidityLocalsUpdating'
)
decodeTimeout
=
setTimeout
(
function
()
{
decodeTimeout
=
setTimeout
(
()
=>
{
self
.
decode
(
sourceLocation
)
this
.
decode
(
sourceLocation
)
},
500
)
},
500
)
}
}
decode
(
sourceLocation
)
{
decode
(
sourceLocation
)
{
const
self
=
this
this
.
event
.
trigger
(
'solidityLocalsMessage'
,
[
''
])
self
.
event
.
trigger
(
'solidityLocalsMessage'
,
[
''
])
this
.
traceManager
.
waterfall
([
self
.
traceManager
.
waterfall
([
this
.
traceManager
.
getStackAt
,
self
.
traceManager
.
getStackAt
,
this
.
traceManager
.
getMemoryAt
,
self
.
traceManager
.
getMemoryAt
,
this
.
traceManager
.
getCurrentCalledAddressAt
],
self
.
traceManager
.
getCurrentCalledAddressAt
],
this
.
stepManager
.
currentStepIndex
,
self
.
stepManager
.
currentStepIndex
,
(
error
,
result
)
=>
{
(
error
,
result
)
=>
{
if
(
error
)
{
if
(
error
)
{
return
error
return
error
...
@@ -45,17 +43,17 @@ class DebuggerSolidityLocals {
...
@@ -45,17 +43,17 @@ class DebuggerSolidityLocals {
var
stack
=
result
[
0
].
value
var
stack
=
result
[
0
].
value
var
memory
=
result
[
1
].
value
var
memory
=
result
[
1
].
value
try
{
try
{
var
storageViewer
=
new
StorageViewer
({
stepIndex
:
self
.
stepManager
.
currentStepIndex
,
tx
:
self
.
tx
,
address
:
result
[
2
].
value
},
self
.
storageResolver
,
self
.
traceManager
)
var
storageViewer
=
new
StorageViewer
({
stepIndex
:
this
.
stepManager
.
currentStepIndex
,
tx
:
this
.
tx
,
address
:
result
[
2
].
value
},
this
.
storageResolver
,
this
.
traceManager
)
localDecoder
.
solidityLocals
(
self
.
stepManager
.
currentStepIndex
,
self
.
internalTreeCall
,
stack
,
memory
,
storageViewer
,
sourceLocation
).
then
((
locals
)
=>
{
localDecoder
.
solidityLocals
(
this
.
stepManager
.
currentStepIndex
,
this
.
internalTreeCall
,
stack
,
memory
,
storageViewer
,
sourceLocation
).
then
((
locals
)
=>
{
if
(
!
locals
.
error
)
{
if
(
!
locals
.
error
)
{
self
.
event
.
trigger
(
'solidityLocals'
,
[
locals
])
this
.
event
.
trigger
(
'solidityLocals'
,
[
locals
])
}
}
if
(
!
Object
.
keys
(
locals
).
length
)
{
if
(
!
Object
.
keys
(
locals
).
length
)
{
self
.
event
.
trigger
(
'solidityLocalsMessage'
,
[
'no locals'
])
this
.
event
.
trigger
(
'solidityLocalsMessage'
,
[
'no locals'
])
}
}
})
})
}
catch
(
e
)
{
}
catch
(
e
)
{
self
.
event
.
trigger
(
'solidityLocalsMessage'
,
[
e
.
message
])
this
.
event
.
trigger
(
'solidityLocalsMessage'
,
[
e
.
message
])
}
}
})
})
}
}
...
...
remix-debug/src/debugger/solidityState.js
View file @
eddc2e38
var
remixLib
=
require
(
'remix-lib'
)
const
remixLib
=
require
(
'remix-lib'
)
var
EventManager
=
remixLib
.
EventManager
const
EventManager
=
remixLib
.
EventManager
var
stateDecoder
=
require
(
'../solidity-decoder/stateDecoder'
)
const
stateDecoder
=
require
(
'../solidity-decoder/stateDecoder'
)
var
StorageViewer
=
require
(
'../storage/storageViewer'
)
const
StorageViewer
=
require
(
'../storage/storageViewer'
)
class
DebuggerSolidityState
{
class
DebuggerSolidityState
{
...
@@ -17,28 +17,27 @@ class DebuggerSolidityState {
...
@@ -17,28 +17,27 @@ class DebuggerSolidityState {
}
}
init
(
index
)
{
init
(
index
)
{
var
self
=
this
let
decodeTimeout
=
null
var
decodeTimeout
=
null
if
(
index
<
0
)
{
if
(
index
<
0
)
{
return
self
.
event
.
trigger
(
'solidityStateMessage'
,
[
'invalid step index'
])
return
this
.
event
.
trigger
(
'solidityStateMessage'
,
[
'invalid step index'
])
}
}
if
(
self
.
stepManager
.
currentStepIndex
!==
index
)
return
if
(
this
.
stepManager
.
currentStepIndex
!==
index
)
return
if
(
!
self
.
solidityProxy
.
loaded
())
{
if
(
!
this
.
solidityProxy
.
loaded
())
{
return
self
.
event
.
trigger
(
'solidityStateMessage'
,
[
'invalid step index'
])
return
this
.
event
.
trigger
(
'solidityStateMessage'
,
[
'invalid step index'
])
}
}
if
(
!
self
.
storageResolver
)
{
if
(
!
this
.
storageResolver
)
{
return
return
}
}
if
(
decodeTimeout
)
{
if
(
decodeTimeout
)
{
window
.
clearTimeout
(
decodeTimeout
)
window
.
clearTimeout
(
decodeTimeout
)
}
}
self
.
event
.
trigger
(
'solidityStateUpdating'
)
this
.
event
.
trigger
(
'solidityStateUpdating'
)
decodeTimeout
=
setTimeout
(
function
()
{
decodeTimeout
=
setTimeout
(
()
=>
{
// necessary due to some states that can crash the debugger
// necessary due to some states that can crash the debugger
try
{
try
{
self
.
decode
(
index
)
this
.
decode
(
index
)
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
dir
(
'====> error'
)
console
.
dir
(
'====> error'
)
console
.
dir
(
err
)
console
.
dir
(
err
)
...
@@ -51,33 +50,31 @@ class DebuggerSolidityState {
...
@@ -51,33 +50,31 @@ class DebuggerSolidityState {
}
}
decode
(
index
)
{
decode
(
index
)
{
const
self
=
this
this
.
traceManager
.
getCurrentCalledAddressAt
(
this
.
stepManager
.
currentStepIndex
,
(
error
,
address
)
=>
{
self
.
traceManager
.
getCurrentCalledAddressAt
(
self
.
stepManager
.
currentStepIndex
,
function
(
error
,
address
)
{
if
(
error
)
{
if
(
error
)
{
return
self
.
event
.
trigger
(
'solidityState'
,
[{}])
return
this
.
event
.
trigger
(
'solidityState'
,
[{}])
}
}
if
(
self
.
stateVariablesByAddresses
[
address
])
{
if
(
this
.
stateVariablesByAddresses
[
address
])
{
return
self
.
extractStateVariables
(
self
.
stateVariablesByAddresses
[
address
],
address
)
return
this
.
extractStateVariables
(
this
.
stateVariablesByAddresses
[
address
],
address
)
}
}
self
.
solidityProxy
.
extractStateVariablesAt
(
index
,
function
(
error
,
stateVars
)
{
this
.
solidityProxy
.
extractStateVariablesAt
(
index
,
(
error
,
stateVars
)
=>
{
if
(
error
)
{
if
(
error
)
{
return
self
.
event
.
trigger
(
'solidityState'
,
[{}])
return
this
.
event
.
trigger
(
'solidityState'
,
[{}])
}
}
self
.
stateVariablesByAddresses
[
address
]
=
stateVars
this
.
stateVariablesByAddresses
[
address
]
=
stateVars
self
.
extractStateVariables
(
stateVars
,
address
)
this
.
extractStateVariables
(
stateVars
,
address
)
})
})
})
})
}
}
extractStateVariables
(
stateVars
,
address
)
{
extractStateVariables
(
stateVars
,
address
)
{
const
self
=
this
var
storageViewer
=
new
StorageViewer
({
stepIndex
:
this
.
stepManager
.
currentStepIndex
,
tx
:
this
.
tx
,
address
:
address
},
this
.
storageResolver
,
this
.
traceManager
)
var
storageViewer
=
new
StorageViewer
({
stepIndex
:
self
.
stepManager
.
currentStepIndex
,
tx
:
self
.
tx
,
address
:
address
},
self
.
storageResolver
,
self
.
traceManager
)
stateDecoder
.
decodeState
(
stateVars
,
storageViewer
).
then
((
result
)
=>
{
stateDecoder
.
decodeState
(
stateVars
,
storageViewer
).
then
((
result
)
=>
{
self
.
event
.
trigger
(
'solidityStateMessage'
,
[
''
])
this
.
event
.
trigger
(
'solidityStateMessage'
,
[
''
])
if
(
result
.
error
)
{
if
(
result
.
error
)
{
return
self
.
event
.
trigger
(
'solidityStateMessage'
,
[
result
.
error
])
return
this
.
event
.
trigger
(
'solidityStateMessage'
,
[
result
.
error
])
}
}
self
.
event
.
trigger
(
'solidityState'
,
[
result
])
this
.
event
.
trigger
(
'solidityState'
,
[
result
])
})
})
}
}
...
...
remix-debug/src/debugger/stepManager.js
View file @
eddc2e38
var
remixLib
=
require
(
'remix-lib'
)
const
remixLib
=
require
(
'remix-lib'
)
var
EventManager
=
remixLib
.
EventManager
const
EventManager
=
remixLib
.
EventManager
var
util
=
remixLib
.
util
const
util
=
remixLib
.
util
class
DebuggerStepManager
{
class
DebuggerStepManager
{
...
@@ -17,57 +17,54 @@ class DebuggerStepManager {
...
@@ -17,57 +17,54 @@ class DebuggerStepManager {
}
}
listenToEvents
()
{
listenToEvents
()
{
const
self
=
this
this
.
debugger
.
event
.
register
(
'newTraceLoaded'
,
this
,
()
=>
{
this
.
traceManager
.
getLength
((
error
,
newLength
)
=>
{
this
.
debugger
.
event
.
register
(
'newTraceLoaded'
,
this
,
function
()
{
self
.
traceManager
.
getLength
(
function
(
error
,
newLength
)
{
if
(
error
)
{
if
(
error
)
{
return
console
.
log
(
error
)
return
console
.
log
(
error
)
}
}
if
(
self
.
traceLength
!==
newLength
)
{
if
(
this
.
traceLength
!==
newLength
)
{
self
.
event
.
trigger
(
'traceLengthChanged'
,
[
newLength
])
this
.
event
.
trigger
(
'traceLengthChanged'
,
[
newLength
])
self
.
traceLength
=
newLength
this
.
traceLength
=
newLength
self
.
codeTraceLength
=
self
.
calculateCodeLength
()
this
.
codeTraceLength
=
this
.
calculateCodeLength
()
}
}
self
.
jumpTo
(
0
)
this
.
jumpTo
(
0
)
})
})
})
})
this
.
debugger
.
callTree
.
event
.
register
(
'callTreeReady'
,
()
=>
{
this
.
debugger
.
callTree
.
event
.
register
(
'callTreeReady'
,
()
=>
{
if
(
self
.
debugger
.
callTree
.
functionCallStack
.
length
)
{
if
(
this
.
debugger
.
callTree
.
functionCallStack
.
length
)
{
self
.
jumpTo
(
self
.
debugger
.
callTree
.
functionCallStack
[
0
])
this
.
jumpTo
(
this
.
debugger
.
callTree
.
functionCallStack
[
0
])
}
}
})
})
this
.
event
.
register
(
'indexChanged'
,
this
,
(
index
)
=>
{
this
.
event
.
register
(
'indexChanged'
,
this
,
(
index
)
=>
{
if
(
index
<
0
)
return
if
(
index
<
0
)
return
if
(
self
.
currentStepIndex
!==
index
)
return
if
(
this
.
currentStepIndex
!==
index
)
return
self
.
traceManager
.
buildCallPath
(
index
,
(
error
,
callsPath
)
=>
{
this
.
traceManager
.
buildCallPath
(
index
,
(
error
,
callsPath
)
=>
{
if
(
error
)
{
if
(
error
)
{
console
.
log
(
error
)
console
.
log
(
error
)
return
self
.
event
.
trigger
(
'revertWarning'
,
[
''
])
return
this
.
event
.
trigger
(
'revertWarning'
,
[
''
])
}
}
self
.
currentCall
=
callsPath
[
callsPath
.
length
-
1
]
this
.
currentCall
=
callsPath
[
callsPath
.
length
-
1
]
if
(
self
.
currentCall
.
reverted
)
{
if
(
this
.
currentCall
.
reverted
)
{
let
revertedReason
=
self
.
currentCall
.
outofgas
?
'outofgas'
:
''
let
revertedReason
=
this
.
currentCall
.
outofgas
?
'outofgas'
:
''
self
.
revertionPoint
=
self
.
currentCall
.
return
this
.
revertionPoint
=
this
.
currentCall
.
return
return
self
.
event
.
trigger
(
'revertWarning'
,
[
revertedReason
])
return
this
.
event
.
trigger
(
'revertWarning'
,
[
revertedReason
])
}
}
for
(
var
k
=
callsPath
.
length
-
2
;
k
>=
0
;
k
--
)
{
for
(
var
k
=
callsPath
.
length
-
2
;
k
>=
0
;
k
--
)
{
var
parent
=
callsPath
[
k
]
var
parent
=
callsPath
[
k
]
if
(
!
parent
.
reverted
)
continue
if
(
!
parent
.
reverted
)
continue
self
.
revertionPoint
=
parent
.
return
this
.
revertionPoint
=
parent
.
return
self
.
event
.
trigger
(
'revertWarning'
,
[
'parenthasthrown'
])
this
.
event
.
trigger
(
'revertWarning'
,
[
'parenthasthrown'
])
}
}
self
.
event
.
trigger
(
'revertWarning'
,
[
''
])
this
.
event
.
trigger
(
'revertWarning'
,
[
''
])
})
})
})
})
}
}
triggerStepChanged
(
step
)
{
triggerStepChanged
(
step
)
{
const
self
=
this
this
.
traceManager
.
getLength
((
error
,
length
)
=>
{
this
.
traceManager
.
getLength
(
function
(
error
,
length
)
{
let
stepState
=
'valid'
let
stepState
=
'valid'
if
(
error
)
{
if
(
error
)
{
...
@@ -78,15 +75,15 @@ class DebuggerStepManager {
...
@@ -78,15 +75,15 @@ class DebuggerStepManager {
stepState
=
'end'
stepState
=
'end'
}
}
let
jumpOutDisabled
=
(
step
===
self
.
traceManager
.
findStepOut
(
step
))
let
jumpOutDisabled
=
(
step
===
this
.
traceManager
.
findStepOut
(
step
))
self
.
event
.
trigger
(
'stepChanged'
,
[
step
,
stepState
,
jumpOutDisabled
])
this
.
event
.
trigger
(
'stepChanged'
,
[
step
,
stepState
,
jumpOutDisabled
])
})
})
}
}
stepIntoBack
(
solidityMode
)
{
stepIntoBack
(
solidityMode
)
{
if
(
!
this
.
traceManager
.
isLoaded
())
return
if
(
!
this
.
traceManager
.
isLoaded
())
return
var
step
=
this
.
currentStepIndex
-
1
let
step
=
this
.
currentStepIndex
-
1
this
.
currentStepIndex
=
step
this
.
currentStepIndex
=
step
if
(
solidityMode
)
{
if
(
solidityMode
)
{
step
=
this
.
resolveToReducedTrace
(
step
,
-
1
)
step
=
this
.
resolveToReducedTrace
(
step
,
-
1
)
...
@@ -99,7 +96,7 @@ class DebuggerStepManager {
...
@@ -99,7 +96,7 @@ class DebuggerStepManager {
stepIntoForward
(
solidityMode
)
{
stepIntoForward
(
solidityMode
)
{
if
(
!
this
.
traceManager
.
isLoaded
())
return
if
(
!
this
.
traceManager
.
isLoaded
())
return
var
step
=
this
.
currentStepIndex
+
1
let
step
=
this
.
currentStepIndex
+
1
this
.
currentStepIndex
=
step
this
.
currentStepIndex
=
step
if
(
solidityMode
)
{
if
(
solidityMode
)
{
step
=
this
.
resolveToReducedTrace
(
step
,
1
)
step
=
this
.
resolveToReducedTrace
(
step
,
1
)
...
@@ -112,7 +109,7 @@ class DebuggerStepManager {
...
@@ -112,7 +109,7 @@ class DebuggerStepManager {
stepOverBack
(
solidityMode
)
{
stepOverBack
(
solidityMode
)
{
if
(
!
this
.
traceManager
.
isLoaded
())
return
if
(
!
this
.
traceManager
.
isLoaded
())
return
var
step
=
this
.
traceManager
.
findStepOverBack
(
this
.
currentStepIndex
)
let
step
=
this
.
traceManager
.
findStepOverBack
(
this
.
currentStepIndex
)
if
(
solidityMode
)
{
if
(
solidityMode
)
{
step
=
this
.
resolveToReducedTrace
(
step
,
-
1
)
step
=
this
.
resolveToReducedTrace
(
step
,
-
1
)
}
}
...
@@ -122,7 +119,7 @@ class DebuggerStepManager {
...
@@ -122,7 +119,7 @@ class DebuggerStepManager {
stepOverForward
(
solidityMode
)
{
stepOverForward
(
solidityMode
)
{
if
(
!
this
.
traceManager
.
isLoaded
())
return
if
(
!
this
.
traceManager
.
isLoaded
())
return
var
step
=
this
.
currentStepIndex
+
1
let
step
=
this
.
currentStepIndex
+
1
let
scope
=
this
.
debugger
.
callTree
.
findScope
(
step
)
let
scope
=
this
.
debugger
.
callTree
.
findScope
(
step
)
if
(
scope
&&
scope
.
firstStep
===
step
)
{
if
(
scope
&&
scope
.
firstStep
===
step
)
{
step
=
scope
.
lastStep
+
1
step
=
scope
.
lastStep
+
1
...
...
remix-debug/src/solidity-decoder/astHelper.js
View file @
eddc2e38
'use strict'
'use strict'
var
remixLib
=
require
(
'remix-lib'
)
const
remixLib
=
require
(
'remix-lib'
)
var
AstWalker
=
remixLib
.
AstWalker
const
AstWalker
=
remixLib
.
AstWalker
/**
/**
* return all contract definitions of the given @astList
* return all contract definitions of the given @astList
...
@@ -9,14 +9,14 @@ var AstWalker = remixLib.AstWalker
...
@@ -9,14 +9,14 @@ var AstWalker = remixLib.AstWalker
* @return {Object} - returns a mapping from AST node ids to AST nodes for the contracts
* @return {Object} - returns a mapping from AST node ids to AST nodes for the contracts
*/
*/
function
extractContractDefinitions
(
sourcesList
)
{
function
extractContractDefinitions
(
sourcesList
)
{
var
ret
=
{
const
ret
=
{
contractsById
:
{},
contractsById
:
{},
contractsByName
:
{},
contractsByName
:
{},
sourcesByContract
:
{}
sourcesByContract
:
{}
}
}
var
walker
=
new
AstWalker
()
const
walker
=
new
AstWalker
()
for
(
var
k
in
sourcesList
)
{
for
(
let
k
in
sourcesList
)
{
walker
.
walk
(
sourcesList
[
k
].
legacyAST
,
{
'ContractDefinition'
:
function
(
node
)
{
walker
.
walk
(
sourcesList
[
k
].
legacyAST
,
{
'ContractDefinition'
:
(
node
)
=>
{
ret
.
contractsById
[
node
.
id
]
=
node
ret
.
contractsById
[
node
.
id
]
=
node
ret
.
sourcesByContract
[
node
.
id
]
=
k
ret
.
sourcesByContract
[
node
.
id
]
=
k
ret
.
contractsByName
[
k
+
':'
+
node
.
attributes
.
name
]
=
node
ret
.
contractsByName
[
k
+
':'
+
node
.
attributes
.
name
]
=
node
...
@@ -50,16 +50,16 @@ function extractStateDefinitions (contractName, sourcesList, contracts) {
...
@@ -50,16 +50,16 @@ function extractStateDefinitions (contractName, sourcesList, contracts) {
if
(
!
contracts
)
{
if
(
!
contracts
)
{
contracts
=
extractContractDefinitions
(
sourcesList
)
contracts
=
extractContractDefinitions
(
sourcesList
)
}
}
var
node
=
contracts
.
contractsByName
[
contractName
]
const
node
=
contracts
.
contractsByName
[
contractName
]
if
(
node
)
{
if
(
node
)
{
var
stateItems
=
[]
const
stateItems
=
[]
var
stateVar
=
[]
const
stateVar
=
[]
var
baseContracts
=
getLinearizedBaseContracts
(
node
.
id
,
contracts
.
contractsById
)
const
baseContracts
=
getLinearizedBaseContracts
(
node
.
id
,
contracts
.
contractsById
)
baseContracts
.
reverse
()
baseContracts
.
reverse
()
for
(
var
k
in
baseContracts
)
{
for
(
let
k
in
baseContracts
)
{
var
ctr
=
baseContracts
[
k
]
const
ctr
=
baseContracts
[
k
]
for
(
var
i
in
ctr
.
children
)
{
for
(
let
i
in
ctr
.
children
)
{
var
item
=
ctr
.
children
[
i
]
const
item
=
ctr
.
children
[
i
]
stateItems
.
push
(
item
)
stateItems
.
push
(
item
)
if
(
item
.
name
===
'VariableDeclaration'
)
{
if
(
item
.
name
===
'VariableDeclaration'
)
{
stateVar
.
push
(
item
)
stateVar
.
push
(
item
)
...
@@ -85,12 +85,12 @@ function extractStatesDefinitions (sourcesList, contracts) {
...
@@ -85,12 +85,12 @@ function extractStatesDefinitions (sourcesList, contracts) {
if
(
!
contracts
)
{
if
(
!
contracts
)
{
contracts
=
extractContractDefinitions
(
sourcesList
)
contracts
=
extractContractDefinitions
(
sourcesList
)
}
}
var
ret
=
{}
const
ret
=
{}
for
(
var
contract
in
contracts
.
contractsById
)
{
for
(
let
contract
in
contracts
.
contractsById
)
{
var
name
=
contracts
.
contractsById
[
contract
].
attributes
.
name
const
name
=
contracts
.
contractsById
[
contract
].
attributes
.
name
var
source
=
contracts
.
sourcesByContract
[
contract
]
const
source
=
contracts
.
sourcesByContract
[
contract
]
var
fullName
=
source
+
':'
+
name
const
fullName
=
source
+
':'
+
name
var
state
=
extractStateDefinitions
(
fullName
,
sourcesList
,
contracts
)
const
state
=
extractStateDefinitions
(
fullName
,
sourcesList
,
contracts
)
ret
[
fullName
]
=
state
ret
[
fullName
]
=
state
ret
[
name
]
=
state
// solc < 0.4.9
ret
[
name
]
=
state
// solc < 0.4.9
}
}
...
...
remix-debug/src/solidity-decoder/decodeInfo.js
View file @
eddc2e38
'use strict'
'use strict'
var
AddressType
=
require
(
'./types/Address'
)
const
AddressType
=
require
(
'./types/Address'
)
var
ArrayType
=
require
(
'./types/ArrayType'
)
const
ArrayType
=
require
(
'./types/ArrayType'
)
var
BoolType
=
require
(
'./types/Bool'
)
const
BoolType
=
require
(
'./types/Bool'
)
var
BytesType
=
require
(
'./types/DynamicByteArray'
)
const
BytesType
=
require
(
'./types/DynamicByteArray'
)
var
BytesXType
=
require
(
'./types/FixedByteArray'
)
const
BytesXType
=
require
(
'./types/FixedByteArray'
)
var
EnumType
=
require
(
'./types/Enum'
)
const
EnumType
=
require
(
'./types/Enum'
)
var
StringType
=
require
(
'./types/StringType'
)
const
StringType
=
require
(
'./types/StringType'
)
var
StructType
=
require
(
'./types/Struct'
)
const
StructType
=
require
(
'./types/Struct'
)
var
IntType
=
require
(
'./types/Int'
)
const
IntType
=
require
(
'./types/Int'
)
var
UintType
=
require
(
'./types/Uint'
)
const
UintType
=
require
(
'./types/Uint'
)
var
MappingType
=
require
(
'./types/Mapping'
)
const
MappingType
=
require
(
'./types/Mapping'
)
var
util
=
require
(
'./types/util'
)
const
util
=
require
(
'./types/util'
)
/**
/**
* mapping decode the given @arg type
* mapping decode the given @arg type
...
@@ -20,12 +20,12 @@ var util = require('./types/util')
...
@@ -20,12 +20,12 @@ var util = require('./types/util')
* @return {Object} returns decoded info about the current type: { storageBytes, typeName}
* @return {Object} returns decoded info about the current type: { storageBytes, typeName}
*/
*/
function
mapping
(
type
,
stateDefinitions
,
contractName
)
{
function
mapping
(
type
,
stateDefinitions
,
contractName
)
{
var
match
=
type
.
match
(
/mapping
\((
.*
?)
=>
(
.*
)\)
$/
)
const
match
=
type
.
match
(
/mapping
\((
.*
?)
=>
(
.*
)\)
$/
)
var
keyTypeName
=
match
[
1
].
trim
()
const
keyTypeName
=
match
[
1
].
trim
()
var
valueTypeName
=
match
[
2
].
trim
()
const
valueTypeName
=
match
[
2
].
trim
()
var
keyType
=
parseType
(
keyTypeName
,
stateDefinitions
,
contractName
,
'storage'
)
const
keyType
=
parseType
(
keyTypeName
,
stateDefinitions
,
contractName
,
'storage'
)
var
valueType
=
parseType
(
valueTypeName
,
stateDefinitions
,
contractName
,
'storage'
)
const
valueType
=
parseType
(
valueTypeName
,
stateDefinitions
,
contractName
,
'storage'
)
var
underlyingTypes
=
{
var
underlyingTypes
=
{
'keyType'
:
keyType
,
'keyType'
:
keyType
,
...
@@ -42,7 +42,7 @@ function mapping (type, stateDefinitions, contractName) {
...
@@ -42,7 +42,7 @@ function mapping (type, stateDefinitions, contractName) {
*/
*/
function
uint
(
type
)
{
function
uint
(
type
)
{
type
===
'uint'
?
'uint256'
:
type
type
===
'uint'
?
'uint256'
:
type
var
storageBytes
=
parseInt
(
type
.
replace
(
'uint'
,
''
))
/
8
const
storageBytes
=
parseInt
(
type
.
replace
(
'uint'
,
''
))
/
8
return
new
UintType
(
storageBytes
)
return
new
UintType
(
storageBytes
)
}
}
...
@@ -54,7 +54,7 @@ function uint (type) {
...
@@ -54,7 +54,7 @@ function uint (type) {
*/
*/
function
int
(
type
)
{
function
int
(
type
)
{
type
===
'int'
?
'int256'
:
type
type
===
'int'
?
'int256'
:
type
var
storageBytes
=
parseInt
(
type
.
replace
(
'int'
,
''
))
/
8
const
storageBytes
=
parseInt
(
type
.
replace
(
'int'
,
''
))
/
8
return
new
IntType
(
storageBytes
)
return
new
IntType
(
storageBytes
)
}
}
...
@@ -105,7 +105,7 @@ function dynamicByteArray (type, stateDefinitions, contractName, location) {
...
@@ -105,7 +105,7 @@ function dynamicByteArray (type, stateDefinitions, contractName, location) {
* @return {Object} returns decoded info about the current type: { storageBytes, typeName}
* @return {Object} returns decoded info about the current type: { storageBytes, typeName}
*/
*/
function
fixedByteArray
(
type
)
{
function
fixedByteArray
(
type
)
{
var
storageBytes
=
parseInt
(
type
.
replace
(
'bytes'
,
''
))
const
storageBytes
=
parseInt
(
type
.
replace
(
'bytes'
,
''
))
return
new
BytesXType
(
storageBytes
)
return
new
BytesXType
(
storageBytes
)
}
}
...
@@ -139,8 +139,8 @@ function stringType (type, stateDefinitions, contractName, location) {
...
@@ -139,8 +139,8 @@ function stringType (type, stateDefinitions, contractName, location) {
* @return {Object} returns decoded info about the current type: { storageBytes, typeName, arraySize, subArray}
* @return {Object} returns decoded info about the current type: { storageBytes, typeName, arraySize, subArray}
*/
*/
function
array
(
type
,
stateDefinitions
,
contractName
,
location
)
{
function
array
(
type
,
stateDefinitions
,
contractName
,
location
)
{
var
arraySize
let
arraySize
var
match
=
type
.
match
(
/
(
.*
)\[(
.*
?)\](
storage ref| storage pointer| memory| calldata
)?
$/
)
const
match
=
type
.
match
(
/
(
.*
)\[(
.*
?)\](
storage ref| storage pointer| memory| calldata
)?
$/
)
if
(
!
match
)
{
if
(
!
match
)
{
console
.
log
(
'unable to parse type '
+
type
)
console
.
log
(
'unable to parse type '
+
type
)
return
null
return
null
...
@@ -149,7 +149,7 @@ function array (type, stateDefinitions, contractName, location) {
...
@@ -149,7 +149,7 @@ function array (type, stateDefinitions, contractName, location) {
location
=
match
[
3
].
trim
()
location
=
match
[
3
].
trim
()
}
}
arraySize
=
match
[
2
]
===
''
?
'dynamic'
:
parseInt
(
match
[
2
])
arraySize
=
match
[
2
]
===
''
?
'dynamic'
:
parseInt
(
match
[
2
])
var
underlyingType
=
parseType
(
match
[
1
],
stateDefinitions
,
contractName
,
location
)
const
underlyingType
=
parseType
(
match
[
1
],
stateDefinitions
,
contractName
,
location
)
if
(
underlyingType
===
null
)
{
if
(
underlyingType
===
null
)
{
console
.
log
(
'unable to parse type '
+
type
)
console
.
log
(
'unable to parse type '
+
type
)
return
null
return
null
...
@@ -166,8 +166,8 @@ function array (type, stateDefinitions, contractName, location) {
...
@@ -166,8 +166,8 @@ function array (type, stateDefinitions, contractName, location) {
* @return {Object} returns decoded info about the current type: { storageBytes, typeName, enum}
* @return {Object} returns decoded info about the current type: { storageBytes, typeName, enum}
*/
*/
function
enumType
(
type
,
stateDefinitions
,
contractName
)
{
function
enumType
(
type
,
stateDefinitions
,
contractName
)
{
var
match
=
type
.
match
(
/enum
(
.*
)
/
)
const
match
=
type
.
match
(
/enum
(
.*
)
/
)
var
enumDef
=
getEnum
(
match
[
1
],
stateDefinitions
,
contractName
)
const
enumDef
=
getEnum
(
match
[
1
],
stateDefinitions
,
contractName
)
if
(
enumDef
===
null
)
{
if
(
enumDef
===
null
)
{
console
.
log
(
'unable to retrieve decode info of '
+
type
)
console
.
log
(
'unable to retrieve decode info of '
+
type
)
return
null
return
null
...
@@ -185,12 +185,12 @@ function enumType (type, stateDefinitions, contractName) {
...
@@ -185,12 +185,12 @@ function enumType (type, stateDefinitions, contractName) {
* @return {Object} returns decoded info about the current type: { storageBytes, typeName, members}
* @return {Object} returns decoded info about the current type: { storageBytes, typeName, members}
*/
*/
function
struct
(
type
,
stateDefinitions
,
contractName
,
location
)
{
function
struct
(
type
,
stateDefinitions
,
contractName
,
location
)
{
var
match
=
type
.
match
(
/struct
(\S
*
?)(
storage ref| storage pointer| memory| calldata
)?
$/
)
const
match
=
type
.
match
(
/struct
(\S
*
?)(
storage ref| storage pointer| memory| calldata
)?
$/
)
if
(
match
)
{
if
(
match
)
{
if
(
!
location
)
{
if
(
!
location
)
{
location
=
match
[
2
].
trim
()
location
=
match
[
2
].
trim
()
}
}
var
memberDetails
=
getStructMembers
(
match
[
1
],
stateDefinitions
,
contractName
,
location
)
// type is used to extract the ast struct definition
const
memberDetails
=
getStructMembers
(
match
[
1
],
stateDefinitions
,
contractName
,
location
)
// type is used to extract the ast struct definition
if
(
!
memberDetails
)
return
null
if
(
!
memberDetails
)
return
null
return
new
StructType
(
memberDetails
,
location
,
match
[
1
])
return
new
StructType
(
memberDetails
,
location
,
match
[
1
])
}
else
{
}
else
{
...
@@ -207,15 +207,15 @@ function struct (type, stateDefinitions, contractName, location) {
...
@@ -207,15 +207,15 @@ function struct (type, stateDefinitions, contractName, location) {
* @return {Array} - containing all value declaration of the current enum type
* @return {Array} - containing all value declaration of the current enum type
*/
*/
function
getEnum
(
type
,
stateDefinitions
,
contractName
)
{
function
getEnum
(
type
,
stateDefinitions
,
contractName
)
{
var
split
=
type
.
split
(
'.'
)
const
split
=
type
.
split
(
'.'
)
if
(
!
split
.
length
)
{
if
(
!
split
.
length
)
{
type
=
contractName
+
'.'
+
type
type
=
contractName
+
'.'
+
type
}
else
{
}
else
{
contractName
=
split
[
0
]
contractName
=
split
[
0
]
}
}
var
state
=
stateDefinitions
[
contractName
]
const
state
=
stateDefinitions
[
contractName
]
if
(
state
)
{
if
(
state
)
{
for
(
var
dec
of
state
.
stateDefinitions
)
{
for
(
let
dec
of
state
.
stateDefinitions
)
{
if
(
dec
.
attributes
&&
dec
.
attributes
.
name
&&
type
===
contractName
+
'.'
+
dec
.
attributes
.
name
)
{
if
(
dec
.
attributes
&&
dec
.
attributes
.
name
&&
type
===
contractName
+
'.'
+
dec
.
attributes
.
name
)
{
return
dec
return
dec
}
}
...
@@ -234,17 +234,17 @@ function getEnum (type, stateDefinitions, contractName) {
...
@@ -234,17 +234,17 @@ function getEnum (type, stateDefinitions, contractName) {
* @return {Array} containing all members of the current struct type
* @return {Array} containing all members of the current struct type
*/
*/
function
getStructMembers
(
type
,
stateDefinitions
,
contractName
,
location
)
{
function
getStructMembers
(
type
,
stateDefinitions
,
contractName
,
location
)
{
var
split
=
type
.
split
(
'.'
)
const
split
=
type
.
split
(
'.'
)
if
(
!
split
.
length
)
{
if
(
!
split
.
length
)
{
type
=
contractName
+
'.'
+
type
type
=
contractName
+
'.'
+
type
}
else
{
}
else
{
contractName
=
split
[
0
]
contractName
=
split
[
0
]
}
}
var
state
=
stateDefinitions
[
contractName
]
const
state
=
stateDefinitions
[
contractName
]
if
(
state
)
{
if
(
state
)
{
for
(
var
dec
of
state
.
stateDefinitions
)
{
for
(
let
dec
of
state
.
stateDefinitions
)
{
if
(
dec
.
name
===
'StructDefinition'
&&
type
===
contractName
+
'.'
+
dec
.
attributes
.
name
)
{
if
(
dec
.
name
===
'StructDefinition'
&&
type
===
contractName
+
'.'
+
dec
.
attributes
.
name
)
{
var
offsets
=
computeOffsets
(
dec
.
children
,
stateDefinitions
,
contractName
,
location
)
const
offsets
=
computeOffsets
(
dec
.
children
,
stateDefinitions
,
contractName
,
location
)
if
(
!
offsets
)
{
if
(
!
offsets
)
{
return
null
return
null
}
}
...
@@ -275,7 +275,7 @@ function typeClass (fullType) {
...
@@ -275,7 +275,7 @@ function typeClass (fullType) {
if
(
fullType
.
indexOf
(
' '
)
!==
-
1
)
{
if
(
fullType
.
indexOf
(
' '
)
!==
-
1
)
{
fullType
=
fullType
.
split
(
' '
)[
0
]
fullType
=
fullType
.
split
(
' '
)[
0
]
}
}
var
char
=
fullType
.
indexOf
(
'bytes'
)
===
0
?
'X'
:
''
const
char
=
fullType
.
indexOf
(
'bytes'
)
===
0
?
'X'
:
''
return
fullType
.
replace
(
/
[
0-9
]
+/g
,
char
)
return
fullType
.
replace
(
/
[
0-9
]
+/g
,
char
)
}
}
...
@@ -289,7 +289,7 @@ function typeClass (fullType) {
...
@@ -289,7 +289,7 @@ function typeClass (fullType) {
* @return {Object} - return the corresponding decoder or null on error
* @return {Object} - return the corresponding decoder or null on error
*/
*/
function
parseType
(
type
,
stateDefinitions
,
contractName
,
location
)
{
function
parseType
(
type
,
stateDefinitions
,
contractName
,
location
)
{
var
decodeInfos
=
{
const
decodeInfos
=
{
'contract'
:
address
,
'contract'
:
address
,
'address'
:
address
,
'address'
:
address
,
'array'
:
array
,
'array'
:
array
,
...
@@ -303,7 +303,7 @@ function parseType (type, stateDefinitions, contractName, location) {
...
@@ -303,7 +303,7 @@ function parseType (type, stateDefinitions, contractName, location) {
'uint'
:
uint
,
'uint'
:
uint
,
'mapping'
:
mapping
'mapping'
:
mapping
}
}
var
currentType
=
typeClass
(
type
)
const
currentType
=
typeClass
(
type
)
if
(
currentType
===
null
)
{
if
(
currentType
===
null
)
{
console
.
log
(
'unable to retrieve decode info of '
+
type
)
console
.
log
(
'unable to retrieve decode info of '
+
type
)
return
null
return
null
...
@@ -325,8 +325,8 @@ function parseType (type, stateDefinitions, contractName, location) {
...
@@ -325,8 +325,8 @@ function parseType (type, stateDefinitions, contractName, location) {
* @return {Array} - return an array of types item: {name, type, location}. location defines the byte offset and slot offset
* @return {Array} - return an array of types item: {name, type, location}. location defines the byte offset and slot offset
*/
*/
function
computeOffsets
(
types
,
stateDefinitions
,
contractName
,
location
)
{
function
computeOffsets
(
types
,
stateDefinitions
,
contractName
,
location
)
{
var
ret
=
[]
const
ret
=
[]
var
storagelocation
=
{
const
storagelocation
=
{
offset
:
0
,
offset
:
0
,
slot
:
0
slot
:
0
}
}
...
...
remix-debug/src/solidity-decoder/index.js
View file @
eddc2e38
var
SolidityProxy
=
require
(
'./solidityProxy'
)
const
SolidityProxy
=
require
(
'./solidityProxy'
)
var
stateDecoder
=
require
(
'./stateDecoder'
)
const
stateDecoder
=
require
(
'./stateDecoder'
)
var
localDecoder
=
require
(
'./localDecoder'
)
const
localDecoder
=
require
(
'./localDecoder'
)
var
InternalCallTree
=
require
(
'./internalCallTree'
)
const
InternalCallTree
=
require
(
'./internalCallTree'
)
module
.
exports
=
{
module
.
exports
=
{
SolidityProxy
:
SolidityProxy
,
SolidityProxy
:
SolidityProxy
,
...
...
remix-debug/src/solidity-decoder/internalCallTree.js
View file @
eddc2e38
'use strict'
'use strict'
var
remixLib
=
require
(
'remix-lib'
)
const
remixLib
=
require
(
'remix-lib'
)
var
SourceLocationTracker
=
remixLib
.
SourceLocationTracker
const
SourceLocationTracker
=
remixLib
.
SourceLocationTracker
var
AstWalker
=
remixLib
.
AstWalker
const
AstWalker
=
remixLib
.
AstWalker
var
EventManager
=
remixLib
.
EventManager
const
EventManager
=
remixLib
.
EventManager
var
decodeInfo
=
require
(
'./decodeInfo'
)
const
decodeInfo
=
require
(
'./decodeInfo'
)
var
util
=
remixLib
.
util
const
util
=
remixLib
.
util
var
traceHelper
=
remixLib
.
helpers
.
trace
const
traceHelper
=
remixLib
.
helpers
.
trace
var
typesUtil
=
require
(
'./types/util.js'
)
const
typesUtil
=
require
(
'./types/util.js'
)
/**
/**
* Tree representing internal jump into function.
* Tree representing internal jump into function.
...
@@ -79,15 +79,15 @@ class InternalCallTree {
...
@@ -79,15 +79,15 @@ class InternalCallTree {
* @param {Int} vmtraceIndex - index on the vm trace
* @param {Int} vmtraceIndex - index on the vm trace
*/
*/
findScope
(
vmtraceIndex
)
{
findScope
(
vmtraceIndex
)
{
var
scopes
=
Object
.
keys
(
this
.
scopeStarts
)
const
scopes
=
Object
.
keys
(
this
.
scopeStarts
)
if
(
!
scopes
.
length
)
{
if
(
!
scopes
.
length
)
{
return
null
return
null
}
}
var
scopeId
=
util
.
findLowerBoundValue
(
vmtraceIndex
,
scopes
)
let
scopeId
=
util
.
findLowerBoundValue
(
vmtraceIndex
,
scopes
)
scopeId
=
this
.
scopeStarts
[
scopeId
]
scopeId
=
this
.
scopeStarts
[
scopeId
]
var
scope
=
this
.
scopes
[
scopeId
]
let
scope
=
this
.
scopes
[
scopeId
]
while
(
scope
.
lastStep
&&
scope
.
lastStep
<
vmtraceIndex
&&
scope
.
firstStep
>
0
)
{
while
(
scope
.
lastStep
&&
scope
.
lastStep
<
vmtraceIndex
&&
scope
.
firstStep
>
0
)
{
var
matched
=
scopeId
.
match
(
/
(
.
\d
|
\d)
$/
)
const
matched
=
scopeId
.
match
(
/
(
.
\d
|
\d)
$/
)
scopeId
=
scopeId
.
replace
(
matched
[
1
],
''
)
scopeId
=
scopeId
.
replace
(
matched
[
1
],
''
)
scope
=
this
.
scopes
[
scopeId
]
scope
=
this
.
scopes
[
scopeId
]
}
}
...
@@ -95,11 +95,10 @@ class InternalCallTree {
...
@@ -95,11 +95,10 @@ class InternalCallTree {
}
}
extractSourceLocation
(
step
)
{
extractSourceLocation
(
step
)
{
var
self
=
this
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
this
.
traceManager
.
getCurrentCalledAddressAt
(
step
,
(
error
,
address
)
=>
{
self
.
traceManager
.
getCurrentCalledAddressAt
(
step
,
(
error
,
address
)
=>
{
if
(
!
error
)
{
if
(
!
error
)
{
self
.
sourceLocationTracker
.
getSourceLocationFromVMTraceIndex
(
address
,
step
,
self
.
solidityProxy
.
contracts
,
(
error
,
sourceLocation
)
=>
{
this
.
sourceLocationTracker
.
getSourceLocationFromVMTraceIndex
(
address
,
step
,
this
.
solidityProxy
.
contracts
,
(
error
,
sourceLocation
)
=>
{
if
(
!
error
)
{
if
(
!
error
)
{
return
resolve
(
sourceLocation
)
return
resolve
(
sourceLocation
)
}
else
{
}
else
{
...
@@ -135,11 +134,11 @@ async function buildTree (tree, step, scopeId, isExternalCall) {
...
@@ -135,11 +134,11 @@ async function buildTree (tree, step, scopeId, isExternalCall) {
included
.
file
===
source
.
file
)
included
.
file
===
source
.
file
)
}
}
var
currentSourceLocation
=
{
start
:
-
1
,
length
:
-
1
,
file
:
-
1
}
let
currentSourceLocation
=
{
start
:
-
1
,
length
:
-
1
,
file
:
-
1
}
var
previousSourceLocation
=
currentSourceLocation
let
previousSourceLocation
=
currentSourceLocation
while
(
step
<
tree
.
traceManager
.
trace
.
length
)
{
while
(
step
<
tree
.
traceManager
.
trace
.
length
)
{
var
sourceLocation
let
sourceLocation
var
newLocation
=
false
let
newLocation
=
false
try
{
try
{
sourceLocation
=
await
tree
.
extractSourceLocation
(
step
)
sourceLocation
=
await
tree
.
extractSourceLocation
(
step
)
if
(
!
includedSource
(
sourceLocation
,
currentSourceLocation
))
{
if
(
!
includedSource
(
sourceLocation
,
currentSourceLocation
))
{
...
@@ -153,11 +152,11 @@ async function buildTree (tree, step, scopeId, isExternalCall) {
...
@@ -153,11 +152,11 @@ async function buildTree (tree, step, scopeId, isExternalCall) {
if
(
!
sourceLocation
)
{
if
(
!
sourceLocation
)
{
return
{
outStep
:
step
,
error
:
'InternalCallTree - No source Location. '
+
step
}
return
{
outStep
:
step
,
error
:
'InternalCallTree - No source Location. '
+
step
}
}
}
var
isCallInstruction
=
traceHelper
.
isCallInstruction
(
tree
.
traceManager
.
trace
[
step
])
const
isCallInstruction
=
traceHelper
.
isCallInstruction
(
tree
.
traceManager
.
trace
[
step
])
// we are checking if we are jumping in a new CALL or in an internal function
// we are checking if we are jumping in a new CALL or in an internal function
if
(
isCallInstruction
||
sourceLocation
.
jump
===
'i'
)
{
if
(
isCallInstruction
||
sourceLocation
.
jump
===
'i'
)
{
try
{
try
{
var
externalCallResult
=
await
buildTree
(
tree
,
step
+
1
,
scopeId
===
''
?
subScope
.
toString
()
:
scopeId
+
'.'
+
subScope
,
isCallInstruction
)
const
externalCallResult
=
await
buildTree
(
tree
,
step
+
1
,
scopeId
===
''
?
subScope
.
toString
()
:
scopeId
+
'.'
+
subScope
,
isCallInstruction
)
if
(
externalCallResult
.
error
)
{
if
(
externalCallResult
.
error
)
{
return
{
outStep
:
step
,
error
:
'InternalCallTree - '
+
externalCallResult
.
error
}
return
{
outStep
:
step
,
error
:
'InternalCallTree - '
+
externalCallResult
.
error
}
}
else
{
}
else
{
...
@@ -190,7 +189,7 @@ function createReducedTrace (tree, index) {
...
@@ -190,7 +189,7 @@ function createReducedTrace (tree, index) {
}
}
function
includeVariableDeclaration
(
tree
,
step
,
sourceLocation
,
scopeId
,
newLocation
,
previousSourceLocation
)
{
function
includeVariableDeclaration
(
tree
,
step
,
sourceLocation
,
scopeId
,
newLocation
,
previousSourceLocation
)
{
var
variableDeclaration
=
resolveVariableDeclaration
(
tree
,
step
,
sourceLocation
)
const
variableDeclaration
=
resolveVariableDeclaration
(
tree
,
step
,
sourceLocation
)
// using the vm trace step, the current source location and the ast,
// using the vm trace step, the current source location and the ast,
// we check if the current vm trace step target a new ast node of type VariableDeclaration
// 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.
// that way we know that there is a new local variable from here.
...
@@ -218,7 +217,7 @@ function includeVariableDeclaration (tree, step, sourceLocation, scopeId, newLoc
...
@@ -218,7 +217,7 @@ function includeVariableDeclaration (tree, step, sourceLocation, scopeId, newLoc
}
}
// 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.
// if that is the case, we have to add to locals tree the inputs and output params
// if that is the case, we have to add to locals tree the inputs and output params
var
functionDefinition
=
resolveFunctionDefinition
(
tree
,
step
,
previousSourceLocation
)
const
functionDefinition
=
resolveFunctionDefinition
(
tree
,
step
,
previousSourceLocation
)
if
(
functionDefinition
&&
(
newLocation
&&
traceHelper
.
isJumpDestInstruction
(
tree
.
traceManager
.
trace
[
step
-
1
])
||
functionDefinition
.
attributes
.
isConstructor
))
{
if
(
functionDefinition
&&
(
newLocation
&&
traceHelper
.
isJumpDestInstruction
(
tree
.
traceManager
.
trace
[
step
-
1
])
||
functionDefinition
.
attributes
.
isConstructor
))
{
tree
.
functionCallStack
.
push
(
step
)
tree
.
functionCallStack
.
push
(
step
)
// means: the previous location was a function definition && JUMPDEST
// means: the previous location was a function definition && JUMPDEST
...
@@ -243,7 +242,7 @@ function includeVariableDeclaration (tree, step, sourceLocation, scopeId, newLoc
...
@@ -243,7 +242,7 @@ function includeVariableDeclaration (tree, step, sourceLocation, scopeId, newLoc
// and keep this in a cache
// and keep this in a cache
function
resolveVariableDeclaration
(
tree
,
step
,
sourceLocation
)
{
function
resolveVariableDeclaration
(
tree
,
step
,
sourceLocation
)
{
if
(
!
tree
.
variableDeclarationByFile
[
sourceLocation
.
file
])
{
if
(
!
tree
.
variableDeclarationByFile
[
sourceLocation
.
file
])
{
var
ast
=
tree
.
solidityProxy
.
ast
(
sourceLocation
)
const
ast
=
tree
.
solidityProxy
.
ast
(
sourceLocation
)
if
(
ast
)
{
if
(
ast
)
{
tree
.
variableDeclarationByFile
[
sourceLocation
.
file
]
=
extractVariableDeclarations
(
ast
,
tree
.
astWalker
)
tree
.
variableDeclarationByFile
[
sourceLocation
.
file
]
=
extractVariableDeclarations
(
ast
,
tree
.
astWalker
)
}
else
{
}
else
{
...
@@ -258,7 +257,7 @@ function resolveVariableDeclaration (tree, step, sourceLocation) {
...
@@ -258,7 +257,7 @@ function resolveVariableDeclaration (tree, step, sourceLocation) {
// and keep this in a cache
// and keep this in a cache
function
resolveFunctionDefinition
(
tree
,
step
,
sourceLocation
)
{
function
resolveFunctionDefinition
(
tree
,
step
,
sourceLocation
)
{
if
(
!
tree
.
functionDefinitionByFile
[
sourceLocation
.
file
])
{
if
(
!
tree
.
functionDefinitionByFile
[
sourceLocation
.
file
])
{
var
ast
=
tree
.
solidityProxy
.
ast
(
sourceLocation
)
const
ast
=
tree
.
solidityProxy
.
ast
(
sourceLocation
)
if
(
ast
)
{
if
(
ast
)
{
tree
.
functionDefinitionByFile
[
sourceLocation
.
file
]
=
extractFunctionDefinitions
(
ast
,
tree
.
astWalker
)
tree
.
functionDefinitionByFile
[
sourceLocation
.
file
]
=
extractFunctionDefinitions
(
ast
,
tree
.
astWalker
)
}
else
{
}
else
{
...
@@ -270,7 +269,7 @@ function resolveFunctionDefinition (tree, step, sourceLocation) {
...
@@ -270,7 +269,7 @@ function resolveFunctionDefinition (tree, step, sourceLocation) {
}
}
function
extractVariableDeclarations
(
ast
,
astWalker
)
{
function
extractVariableDeclarations
(
ast
,
astWalker
)
{
var
ret
=
{}
const
ret
=
{}
astWalker
.
walk
(
ast
,
(
node
)
=>
{
astWalker
.
walk
(
ast
,
(
node
)
=>
{
if
(
node
.
name
===
'VariableDeclaration'
)
{
if
(
node
.
name
===
'VariableDeclaration'
)
{
ret
[
node
.
src
]
=
node
ret
[
node
.
src
]
=
node
...
@@ -281,7 +280,7 @@ function extractVariableDeclarations (ast, astWalker) {
...
@@ -281,7 +280,7 @@ function extractVariableDeclarations (ast, astWalker) {
}
}
function
extractFunctionDefinitions
(
ast
,
astWalker
)
{
function
extractFunctionDefinitions
(
ast
,
astWalker
)
{
var
ret
=
{}
const
ret
=
{}
astWalker
.
walk
(
ast
,
(
node
)
=>
{
astWalker
.
walk
(
ast
,
(
node
)
=>
{
if
(
node
.
name
===
'FunctionDefinition'
)
{
if
(
node
.
name
===
'FunctionDefinition'
)
{
ret
[
node
.
src
]
=
node
ret
[
node
.
src
]
=
node
...
@@ -292,11 +291,11 @@ function extractFunctionDefinitions (ast, astWalker) {
...
@@ -292,11 +291,11 @@ function extractFunctionDefinitions (ast, astWalker) {
}
}
function
addParams
(
parameterList
,
tree
,
scopeId
,
states
,
contractName
,
sourceLocation
,
stackLength
,
stackPosition
,
dir
)
{
function
addParams
(
parameterList
,
tree
,
scopeId
,
states
,
contractName
,
sourceLocation
,
stackLength
,
stackPosition
,
dir
)
{
for
(
var
inputParam
in
parameterList
.
children
)
{
for
(
let
inputParam
in
parameterList
.
children
)
{
var
param
=
parameterList
.
children
[
inputParam
]
const
param
=
parameterList
.
children
[
inputParam
]
var
stackDepth
=
stackLength
+
(
dir
*
stackPosition
)
const
stackDepth
=
stackLength
+
(
dir
*
stackPosition
)
if
(
stackDepth
>=
0
)
{
if
(
stackDepth
>=
0
)
{
var
location
=
typesUtil
.
extractLocationFromAstVariable
(
param
)
let
location
=
typesUtil
.
extractLocationFromAstVariable
(
param
)
location
=
location
===
'default'
?
'memory'
:
location
location
=
location
===
'default'
?
'memory'
:
location
tree
.
scopes
[
scopeId
].
locals
[
param
.
attributes
.
name
]
=
{
tree
.
scopes
[
scopeId
].
locals
[
param
.
attributes
.
name
]
=
{
name
:
param
.
attributes
.
name
,
name
:
param
.
attributes
.
name
,
...
...
remix-debug/src/solidity-decoder/localDecoder.js
View file @
eddc2e38
'use strict'
'use strict'
async
function
solidityLocals
(
vmtraceIndex
,
internalTreeCall
,
stack
,
memory
,
storageResolver
,
currentSourceLocation
)
{
async
function
solidityLocals
(
vmtraceIndex
,
internalTreeCall
,
stack
,
memory
,
storageResolver
,
currentSourceLocation
)
{
var
scope
=
internalTreeCall
.
findScope
(
vmtraceIndex
)
const
scope
=
internalTreeCall
.
findScope
(
vmtraceIndex
)
if
(
!
scope
)
{
if
(
!
scope
)
{
var
error
=
{
'message'
:
'Can
\'
t display locals. reason: compilation result might not have been provided'
}
const
error
=
{
'message'
:
'Can
\'
t display locals. reason: compilation result might not have been provided'
}
throw
error
throw
error
}
}
var
locals
=
{}
const
locals
=
{}
memory
=
formatMemory
(
memory
)
memory
=
formatMemory
(
memory
)
var
anonymousIncr
=
1
let
anonymousIncr
=
1
for
(
var
local
in
scope
.
locals
)
{
for
(
let
local
in
scope
.
locals
)
{
var
variable
=
scope
.
locals
[
local
]
const
variable
=
scope
.
locals
[
local
]
if
(
variable
.
stackDepth
<
stack
.
length
&&
variable
.
sourceLocation
.
start
<=
currentSourceLocation
.
start
)
{
if
(
variable
.
stackDepth
<
stack
.
length
&&
variable
.
sourceLocation
.
start
<=
currentSourceLocation
.
start
)
{
var
name
=
variable
.
name
let
name
=
variable
.
name
if
(
name
===
''
)
{
if
(
name
===
''
)
{
name
=
'<'
+
anonymousIncr
+
'>'
name
=
'<'
+
anonymousIncr
+
'>'
anonymousIncr
++
anonymousIncr
++
...
...
remix-debug/src/solidity-decoder/solidityProxy.js
View file @
eddc2e38
'use strict'
'use strict'
var
remixLib
=
require
(
'remix-lib'
)
const
remixLib
=
require
(
'remix-lib'
)
var
traceHelper
=
remixLib
.
helpers
.
trace
const
traceHelper
=
remixLib
.
helpers
.
trace
var
stateDecoder
=
require
(
'./stateDecoder'
)
const
stateDecoder
=
require
(
'./stateDecoder'
)
var
astHelper
=
require
(
'./astHelper'
)
const
astHelper
=
require
(
'./astHelper'
)
var
util
=
remixLib
.
util
const
util
=
remixLib
.
util
class
SolidityProxy
{
class
SolidityProxy
{
constructor
(
traceManager
,
codeManager
)
{
constructor
(
traceManager
,
codeManager
)
{
...
@@ -51,7 +51,7 @@ class SolidityProxy {
...
@@ -51,7 +51,7 @@ class SolidityProxy {
if
(
error
)
{
if
(
error
)
{
cb
(
error
)
cb
(
error
)
}
else
{
}
else
{
var
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
)
cb
(
null
,
contractName
)
}
}
...
@@ -113,7 +113,7 @@ class SolidityProxy {
...
@@ -113,7 +113,7 @@ class SolidityProxy {
* @return {Object} - AST of the current file
* @return {Object} - AST of the current file
*/
*/
ast
(
sourceLocation
)
{
ast
(
sourceLocation
)
{
var
file
=
this
.
fileNameFromIndex
(
sourceLocation
.
file
)
const
file
=
this
.
fileNameFromIndex
(
sourceLocation
.
file
)
if
(
this
.
sources
[
file
])
{
if
(
this
.
sources
[
file
])
{
return
this
.
sources
[
file
].
legacyAST
return
this
.
sources
[
file
].
legacyAST
}
else
{
}
else
{
...
@@ -134,10 +134,10 @@ class SolidityProxy {
...
@@ -134,10 +134,10 @@ class SolidityProxy {
}
}
function
contractNameFromCode
(
contracts
,
code
,
address
)
{
function
contractNameFromCode
(
contracts
,
code
,
address
)
{
var
isCreation
=
traceHelper
.
isContractCreation
(
address
)
const
isCreation
=
traceHelper
.
isContractCreation
(
address
)
for
(
var
file
in
contracts
)
{
for
(
let
file
in
contracts
)
{
for
(
var
contract
in
contracts
[
file
])
{
for
(
let
contract
in
contracts
[
file
])
{
var
bytecode
=
isCreation
?
contracts
[
file
][
contract
].
evm
.
bytecode
.
object
:
contracts
[
file
][
contract
].
evm
.
deployedBytecode
.
object
const
bytecode
=
isCreation
?
contracts
[
file
][
contract
].
evm
.
bytecode
.
object
:
contracts
[
file
][
contract
].
evm
.
deployedBytecode
.
object
if
(
util
.
compareByteCode
(
code
,
'0x'
+
bytecode
))
{
if
(
util
.
compareByteCode
(
code
,
'0x'
+
bytecode
))
{
return
contract
return
contract
}
}
...
...
remix-debug/src/solidity-decoder/stateDecoder.js
View file @
eddc2e38
var
astHelper
=
require
(
'./astHelper'
)
const
astHelper
=
require
(
'./astHelper'
)
var
decodeInfo
=
require
(
'./decodeInfo'
)
const
decodeInfo
=
require
(
'./decodeInfo'
)
/**
/**
* decode the contract state storage
* decode the contract state storage
...
@@ -9,11 +9,11 @@ var decodeInfo = require('./decodeInfo')
...
@@ -9,11 +9,11 @@ var decodeInfo = require('./decodeInfo')
* @return {Map} - decoded state variable
* @return {Map} - decoded state variable
*/
*/
async
function
decodeState
(
stateVars
,
storageResolver
)
{
async
function
decodeState
(
stateVars
,
storageResolver
)
{
var
ret
=
{}
const
ret
=
{}
for
(
var
k
in
stateVars
)
{
for
(
var
k
in
stateVars
)
{
var
stateVar
=
stateVars
[
k
]
const
stateVar
=
stateVars
[
k
]
try
{
try
{
var
decoded
=
await
stateVar
.
type
.
decodeFromStorage
(
stateVar
.
storagelocation
,
storageResolver
)
const
decoded
=
await
stateVar
.
type
.
decodeFromStorage
(
stateVar
.
storagelocation
,
storageResolver
)
decoded
.
constant
=
stateVar
.
constant
decoded
.
constant
=
stateVar
.
constant
if
(
decoded
.
constant
)
{
if
(
decoded
.
constant
)
{
decoded
.
value
=
'<constant>'
decoded
.
value
=
'<constant>'
...
@@ -35,12 +35,12 @@ async function decodeState (stateVars, storageResolver) {
...
@@ -35,12 +35,12 @@ async function decodeState (stateVars, storageResolver) {
* @return {Object} - return the location of all contract variables in the storage
* @return {Object} - return the location of all contract variables in the storage
*/
*/
function
extractStateVariables
(
contractName
,
sourcesList
)
{
function
extractStateVariables
(
contractName
,
sourcesList
)
{
var
states
=
astHelper
.
extractStatesDefinitions
(
sourcesList
)
const
states
=
astHelper
.
extractStatesDefinitions
(
sourcesList
)
if
(
!
states
[
contractName
])
{
if
(
!
states
[
contractName
])
{
return
[]
return
[]
}
}
var
types
=
states
[
contractName
].
stateVariables
const
types
=
states
[
contractName
].
stateVariables
var
offsets
=
decodeInfo
.
computeOffsets
(
types
,
states
,
contractName
,
'storage'
)
const
offsets
=
decodeInfo
.
computeOffsets
(
types
,
states
,
contractName
,
'storage'
)
if
(
!
offsets
)
{
if
(
!
offsets
)
{
return
[]
// TODO should maybe return an error
return
[]
// TODO should maybe return an error
}
}
...
@@ -56,7 +56,7 @@ function extractStateVariables (contractName, sourcesList) {
...
@@ -56,7 +56,7 @@ function extractStateVariables (contractName, sourcesList) {
* @return {Map} - return the state of the contract
* @return {Map} - return the state of the contract
*/
*/
async
function
solidityState
(
storageResolver
,
astList
,
contractName
)
{
async
function
solidityState
(
storageResolver
,
astList
,
contractName
)
{
var
stateVars
=
extractStateVariables
(
contractName
,
astList
)
const
stateVars
=
extractStateVariables
(
contractName
,
astList
)
try
{
try
{
return
await
decodeState
(
stateVars
,
storageResolver
)
return
await
decodeState
(
stateVars
,
storageResolver
)
}
catch
(
e
)
{
}
catch
(
e
)
{
...
...
remix-debug/src/solidity-decoder/types/Address.js
View file @
eddc2e38
'use strict'
'use strict'
var
util
=
require
(
'./util'
)
const
util
=
require
(
'./util'
)
var
ValueType
=
require
(
'./ValueType'
)
const
ValueType
=
require
(
'./ValueType'
)
class
Address
extends
ValueType
{
class
Address
extends
ValueType
{
constructor
()
{
constructor
()
{
...
...
remix-debug/src/solidity-decoder/types/ArrayType.js
View file @
eddc2e38
'use strict'
'use strict'
var
util
=
require
(
'./util'
)
const
util
=
require
(
'./util'
)
var
remixLib
=
require
(
'remix-lib'
)
const
remixLib
=
require
(
'remix-lib'
)
var
sha3256
=
remixLib
.
util
.
sha3_256
const
sha3256
=
remixLib
.
util
.
sha3_256
var
BN
=
require
(
'ethereumjs-util'
).
BN
const
BN
=
require
(
'ethereumjs-util'
).
BN
var
RefType
=
require
(
'./RefType'
)
const
RefType
=
require
(
'./RefType'
)
class
ArrayType
extends
RefType
{
class
ArrayType
extends
RefType
{
constructor
(
underlyingType
,
arraySize
,
location
)
{
constructor
(
underlyingType
,
arraySize
,
location
)
{
var
storageSlots
=
null
let
storageSlots
=
null
if
(
arraySize
===
'dynamic'
)
{
if
(
arraySize
===
'dynamic'
)
{
storageSlots
=
1
storageSlots
=
1
}
else
{
}
else
{
if
(
underlyingType
.
storageBytes
<
32
)
{
if
(
underlyingType
.
storageBytes
<
32
)
{
var
itemPerSlot
=
Math
.
floor
(
32
/
underlyingType
.
storageBytes
)
const
itemPerSlot
=
Math
.
floor
(
32
/
underlyingType
.
storageBytes
)
storageSlots
=
Math
.
ceil
(
arraySize
/
itemPerSlot
)
storageSlots
=
Math
.
ceil
(
arraySize
/
itemPerSlot
)
}
else
{
}
else
{
storageSlots
=
arraySize
*
underlyingType
.
storageSlots
storageSlots
=
arraySize
*
underlyingType
.
storageSlots
}
}
}
}
var
size
=
arraySize
!==
'dynamic'
?
arraySize
:
''
const
size
=
arraySize
!==
'dynamic'
?
arraySize
:
''
super
(
storageSlots
,
32
,
underlyingType
.
typeName
+
'['
+
size
+
']'
,
location
)
super
(
storageSlots
,
32
,
underlyingType
.
typeName
+
'['
+
size
+
']'
,
location
)
this
.
underlyingType
=
underlyingType
this
.
underlyingType
=
underlyingType
this
.
arraySize
=
arraySize
this
.
arraySize
=
arraySize
}
}
async
decodeFromStorage
(
location
,
storageResolver
)
{
async
decodeFromStorage
(
location
,
storageResolver
)
{
var
ret
=
[]
const
ret
=
[]
var
size
=
null
let
size
=
null
var
slotValue
let
slotValue
try
{
try
{
slotValue
=
await
util
.
extractHexValue
(
location
,
storageResolver
,
this
.
storageBytes
)
slotValue
=
await
util
.
extractHexValue
(
location
,
storageResolver
,
this
.
storageBytes
)
}
catch
(
e
)
{
}
catch
(
e
)
{
...
@@ -38,7 +38,7 @@ class ArrayType extends RefType {
...
@@ -38,7 +38,7 @@ class ArrayType extends RefType {
type
:
this
.
typeName
type
:
this
.
typeName
}
}
}
}
var
currentLocation
=
{
const
currentLocation
=
{
offset
:
0
,
offset
:
0
,
slot
:
location
.
slot
slot
:
location
.
slot
}
}
...
@@ -77,8 +77,8 @@ class ArrayType extends RefType {
...
@@ -77,8 +77,8 @@ class ArrayType extends RefType {
}
}
decodeFromMemoryInternal
(
offset
,
memory
)
{
decodeFromMemoryInternal
(
offset
,
memory
)
{
var
ret
=
[]
const
ret
=
[]
var
length
=
this
.
arraySize
let
length
=
this
.
arraySize
if
(
this
.
arraySize
===
'dynamic'
)
{
if
(
this
.
arraySize
===
'dynamic'
)
{
length
=
memory
.
substr
(
2
*
offset
,
64
)
length
=
memory
.
substr
(
2
*
offset
,
64
)
length
=
parseInt
(
length
,
16
)
length
=
parseInt
(
length
,
16
)
...
...
remix-debug/src/solidity-decoder/types/Bool.js
View file @
eddc2e38
'use strict'
'use strict'
var
ValueType
=
require
(
'./ValueType'
)
const
ValueType
=
require
(
'./ValueType'
)
var
util
=
require
(
'./util'
)
const
util
=
require
(
'./util'
)
class
Bool
extends
ValueType
{
class
Bool
extends
ValueType
{
constructor
()
{
constructor
()
{
...
...
remix-debug/src/solidity-decoder/types/DynamicByteArray.js
View file @
eddc2e38
'use strict'
'use strict'
var
util
=
require
(
'./util'
)
const
util
=
require
(
'./util'
)
var
remixLib
=
require
(
'remix-lib'
)
const
remixLib
=
require
(
'remix-lib'
)
var
sha3256
=
remixLib
.
util
.
sha3_256
const
sha3256
=
remixLib
.
util
.
sha3_256
var
BN
=
require
(
'ethereumjs-util'
).
BN
const
BN
=
require
(
'ethereumjs-util'
).
BN
var
RefType
=
require
(
'./RefType'
)
const
RefType
=
require
(
'./RefType'
)
class
DynamicByteArray
extends
RefType
{
class
DynamicByteArray
extends
RefType
{
constructor
(
location
)
{
constructor
(
location
)
{
...
@@ -11,7 +11,7 @@ class DynamicByteArray extends RefType {
...
@@ -11,7 +11,7 @@ class DynamicByteArray extends RefType {
}
}
async
decodeFromStorage
(
location
,
storageResolver
)
{
async
decodeFromStorage
(
location
,
storageResolver
)
{
var
value
=
'0x0'
let
value
=
'0x0'
try
{
try
{
value
=
await
util
.
extractHexValue
(
location
,
storageResolver
,
this
.
storageBytes
)
value
=
await
util
.
extractHexValue
(
location
,
storageResolver
,
this
.
storageBytes
)
}
catch
(
e
)
{
}
catch
(
e
)
{
...
@@ -21,12 +21,12 @@ class DynamicByteArray extends RefType {
...
@@ -21,12 +21,12 @@ class DynamicByteArray extends RefType {
type
:
this
.
typeName
type
:
this
.
typeName
}
}
}
}
var
bn
=
new
BN
(
value
,
16
)
const
bn
=
new
BN
(
value
,
16
)
if
(
bn
.
testn
(
0
))
{
if
(
bn
.
testn
(
0
))
{
var
length
=
bn
.
div
(
new
BN
(
2
))
const
length
=
bn
.
div
(
new
BN
(
2
))
var
dataPos
=
new
BN
(
sha3256
(
location
.
slot
).
replace
(
'0x'
,
''
),
16
)
let
dataPos
=
new
BN
(
sha3256
(
location
.
slot
).
replace
(
'0x'
,
''
),
16
)
var
ret
=
''
let
ret
=
''
var
currentSlot
=
'0x'
let
currentSlot
=
'0x'
try
{
try
{
currentSlot
=
await
util
.
readFromStorage
(
dataPos
,
storageResolver
)
currentSlot
=
await
util
.
readFromStorage
(
dataPos
,
storageResolver
)
}
catch
(
e
)
{
}
catch
(
e
)
{
...
@@ -67,7 +67,7 @@ class DynamicByteArray extends RefType {
...
@@ -67,7 +67,7 @@ class DynamicByteArray extends RefType {
decodeFromMemoryInternal
(
offset
,
memory
)
{
decodeFromMemoryInternal
(
offset
,
memory
)
{
offset
=
2
*
offset
offset
=
2
*
offset
var
length
=
memory
.
substr
(
offset
,
64
)
let
length
=
memory
.
substr
(
offset
,
64
)
length
=
2
*
parseInt
(
length
,
16
)
length
=
2
*
parseInt
(
length
,
16
)
return
{
return
{
length
:
'0x'
+
length
.
toString
(
16
),
length
:
'0x'
+
length
.
toString
(
16
),
...
...
remix-debug/src/solidity-decoder/types/Enum.js
View file @
eddc2e38
'use strict'
'use strict'
var
ValueType
=
require
(
'./ValueType'
)
const
ValueType
=
require
(
'./ValueType'
)
class
Enum
extends
ValueType
{
class
Enum
extends
ValueType
{
constructor
(
enumDef
)
{
constructor
(
enumDef
)
{
var
storageBytes
=
0
let
storageBytes
=
0
var
length
=
enumDef
.
children
.
length
let
length
=
enumDef
.
children
.
length
while
(
length
>
1
)
{
while
(
length
>
1
)
{
length
=
length
/
256
length
=
length
/
256
storageBytes
++
storageBytes
++
...
...
remix-debug/src/solidity-decoder/types/FixedByteArray.js
View file @
eddc2e38
'use strict'
'use strict'
var
ValueType
=
require
(
'./ValueType'
)
const
ValueType
=
require
(
'./ValueType'
)
class
FixedByteArray
extends
ValueType
{
class
FixedByteArray
extends
ValueType
{
constructor
(
storageBytes
)
{
constructor
(
storageBytes
)
{
...
...
remix-debug/src/solidity-decoder/types/Int.js
View file @
eddc2e38
'use strict'
'use strict'
var
util
=
require
(
'./util'
)
const
util
=
require
(
'./util'
)
var
ValueType
=
require
(
'./ValueType'
)
const
ValueType
=
require
(
'./ValueType'
)
class
Int
extends
ValueType
{
class
Int
extends
ValueType
{
constructor
(
storageBytes
)
{
constructor
(
storageBytes
)
{
...
...
remix-debug/src/solidity-decoder/types/Mapping.js
View file @
eddc2e38
'use strict'
'use strict'
var
RefType
=
require
(
'./RefType'
)
const
RefType
=
require
(
'./RefType'
)
var
util
=
require
(
'./util'
)
const
util
=
require
(
'./util'
)
var
ethutil
=
require
(
'ethereumjs-util'
)
const
ethutil
=
require
(
'ethereumjs-util'
)
class
Mapping
extends
RefType
{
class
Mapping
extends
RefType
{
constructor
(
underlyingTypes
,
location
,
fullType
)
{
constructor
(
underlyingTypes
,
location
,
fullType
)
{
...
@@ -12,9 +12,9 @@ class Mapping extends RefType {
...
@@ -12,9 +12,9 @@ class Mapping extends RefType {
}
}
async
decodeFromStorage
(
location
,
storageResolver
)
{
async
decodeFromStorage
(
location
,
storageResolver
)
{
var
corrections
=
this
.
valueType
.
members
?
this
.
valueType
.
members
.
map
((
value
)
=>
{
return
value
.
storagelocation
})
:
[]
const
corrections
=
this
.
valueType
.
members
?
this
.
valueType
.
members
.
map
((
value
)
=>
{
return
value
.
storagelocation
})
:
[]
if
(
!
this
.
initialDecodedState
)
{
// cache the decoded initial storage
if
(
!
this
.
initialDecodedState
)
{
// cache the decoded initial storage
var
mappingsInitialPreimages
let
mappingsInitialPreimages
try
{
try
{
mappingsInitialPreimages
=
await
storageResolver
.
initialMappingsLocation
(
corrections
)
mappingsInitialPreimages
=
await
storageResolver
.
initialMappingsLocation
(
corrections
)
this
.
initialDecodedState
=
await
this
.
decodeMappingsLocation
(
mappingsInitialPreimages
,
location
,
storageResolver
)
this
.
initialDecodedState
=
await
this
.
decodeMappingsLocation
(
mappingsInitialPreimages
,
location
,
storageResolver
)
...
@@ -25,8 +25,8 @@ class Mapping extends RefType {
...
@@ -25,8 +25,8 @@ class Mapping extends RefType {
}
}
}
}
}
}
var
mappingPreimages
=
await
storageResolver
.
mappingsLocation
(
corrections
)
const
mappingPreimages
=
await
storageResolver
.
mappingsLocation
(
corrections
)
var
ret
=
await
this
.
decodeMappingsLocation
(
mappingPreimages
,
location
,
storageResolver
)
// fetch mapping storage changes
let
ret
=
await
this
.
decodeMappingsLocation
(
mappingPreimages
,
location
,
storageResolver
)
// fetch mapping storage changes
ret
=
Object
.
assign
({},
this
.
initialDecodedState
,
ret
)
// merge changes
ret
=
Object
.
assign
({},
this
.
initialDecodedState
,
ret
)
// merge changes
return
{
return
{
value
:
ret
,
value
:
ret
,
...
@@ -45,14 +45,14 @@ class Mapping extends RefType {
...
@@ -45,14 +45,14 @@ class Mapping extends RefType {
}
}
async
decodeMappingsLocation
(
preimages
,
location
,
storageResolver
)
{
async
decodeMappingsLocation
(
preimages
,
location
,
storageResolver
)
{
var
mapSlot
=
util
.
normalizeHex
(
ethutil
.
bufferToHex
(
location
.
slot
))
const
mapSlot
=
util
.
normalizeHex
(
ethutil
.
bufferToHex
(
location
.
slot
))
if
(
!
preimages
[
mapSlot
])
{
if
(
!
preimages
[
mapSlot
])
{
return
{}
return
{}
}
}
var
ret
=
{}
const
ret
=
{}
for
(
var
i
in
preimages
[
mapSlot
])
{
for
(
let
i
in
preimages
[
mapSlot
])
{
var
mapLocation
=
getMappingLocation
(
i
,
location
.
slot
)
const
mapLocation
=
getMappingLocation
(
i
,
location
.
slot
)
var
globalLocation
=
{
const
globalLocation
=
{
offset
:
location
.
offset
,
offset
:
location
.
offset
,
slot
:
mapLocation
slot
:
mapLocation
}
}
...
@@ -68,12 +68,12 @@ function getMappingLocation (key, position) {
...
@@ -68,12 +68,12 @@ function getMappingLocation (key, position) {
// > the value corresponding to a mapping key k is located at keccak256(k . p) where . is concatenation.
// > the value corresponding to a mapping key k is located at keccak256(k . p) where . is concatenation.
// key should be a hex string, and position an int
// key should be a hex string, and position an int
var
mappingK
=
ethutil
.
toBuffer
(
'0x'
+
key
)
const
mappingK
=
ethutil
.
toBuffer
(
'0x'
+
key
)
var
mappingP
=
ethutil
.
intToBuffer
(
position
)
let
mappingP
=
ethutil
.
intToBuffer
(
position
)
mappingP
=
ethutil
.
setLengthLeft
(
mappingP
,
32
)
mappingP
=
ethutil
.
setLengthLeft
(
mappingP
,
32
)
var
mappingKeyBuf
=
concatTypedArrays
(
mappingK
,
mappingP
)
const
mappingKeyBuf
=
concatTypedArrays
(
mappingK
,
mappingP
)
var
mappingKeyPreimage
=
'0x'
+
mappingKeyBuf
.
toString
(
'hex'
)
const
mappingKeyPreimage
=
'0x'
+
mappingKeyBuf
.
toString
(
'hex'
)
var
mappingStorageLocation
=
ethutil
.
keccak
(
mappingKeyPreimage
)
let
mappingStorageLocation
=
ethutil
.
keccak
(
mappingKeyPreimage
)
mappingStorageLocation
=
new
ethutil
.
BN
(
mappingStorageLocation
,
16
)
mappingStorageLocation
=
new
ethutil
.
BN
(
mappingStorageLocation
,
16
)
return
mappingStorageLocation
return
mappingStorageLocation
}
}
...
...
remix-debug/src/solidity-decoder/types/RefType.js
View file @
eddc2e38
'use strict'
'use strict'
var
util
=
require
(
'./util'
)
const
util
=
require
(
'./util'
)
class
RefType
{
class
RefType
{
constructor
(
storageSlots
,
storageBytes
,
typeName
,
location
)
{
constructor
(
storageSlots
,
storageBytes
,
typeName
,
location
)
{
...
@@ -26,7 +26,7 @@ class RefType {
...
@@ -26,7 +26,7 @@ class RefType {
type
:
this
.
typeName
type
:
this
.
typeName
}
}
}
}
var
offset
=
stack
[
stack
.
length
-
1
-
stackDepth
]
let
offset
=
stack
[
stack
.
length
-
1
-
stackDepth
]
if
(
this
.
isInStorage
())
{
if
(
this
.
isInStorage
())
{
offset
=
util
.
toBN
(
offset
)
offset
=
util
.
toBN
(
offset
)
try
{
try
{
...
...
remix-debug/src/solidity-decoder/types/StringType.js
View file @
eddc2e38
'use strict'
'use strict'
var
DynamicBytes
=
require
(
'./DynamicByteArray'
)
const
DynamicBytes
=
require
(
'./DynamicByteArray'
)
class
StringType
extends
DynamicBytes
{
class
StringType
extends
DynamicBytes
{
constructor
(
location
)
{
constructor
(
location
)
{
...
@@ -8,7 +8,7 @@ class StringType extends DynamicBytes {
...
@@ -8,7 +8,7 @@ class StringType extends DynamicBytes {
}
}
async
decodeFromStorage
(
location
,
storageResolver
)
{
async
decodeFromStorage
(
location
,
storageResolver
)
{
var
decoded
=
'0x'
let
decoded
=
'0x'
try
{
try
{
decoded
=
await
super
.
decodeFromStorage
(
location
,
storageResolver
)
decoded
=
await
super
.
decodeFromStorage
(
location
,
storageResolver
)
}
catch
(
e
)
{
}
catch
(
e
)
{
...
@@ -28,7 +28,7 @@ class StringType extends DynamicBytes {
...
@@ -28,7 +28,7 @@ class StringType extends DynamicBytes {
}
}
decodeFromMemoryInternal
(
offset
,
memory
)
{
decodeFromMemoryInternal
(
offset
,
memory
)
{
var
decoded
=
super
.
decodeFromMemoryInternal
(
offset
,
memory
)
const
decoded
=
super
.
decodeFromMemoryInternal
(
offset
,
memory
)
return
format
(
decoded
)
return
format
(
decoded
)
}
}
}
}
...
@@ -37,9 +37,9 @@ function format (decoded) {
...
@@ -37,9 +37,9 @@ function format (decoded) {
if
(
decoded
.
error
)
{
if
(
decoded
.
error
)
{
return
decoded
return
decoded
}
}
var
value
=
decoded
.
value
let
value
=
decoded
.
value
value
=
value
.
replace
(
'0x'
,
''
).
replace
(
/
(
..
)
/g
,
'%$1'
)
value
=
value
.
replace
(
'0x'
,
''
).
replace
(
/
(
..
)
/g
,
'%$1'
)
var
ret
=
{
const
ret
=
{
length
:
decoded
.
length
,
length
:
decoded
.
length
,
raw
:
decoded
.
value
,
raw
:
decoded
.
value
,
type
:
'string'
type
:
'string'
...
...
remix-debug/src/solidity-decoder/types/Struct.js
View file @
eddc2e38
'use strict'
'use strict'
var
util
=
require
(
'./util'
)
const
util
=
require
(
'./util'
)
var
RefType
=
require
(
'./RefType'
)
const
RefType
=
require
(
'./RefType'
)
class
Struct
extends
RefType
{
class
Struct
extends
RefType
{
constructor
(
memberDetails
,
location
,
fullType
)
{
constructor
(
memberDetails
,
location
,
fullType
)
{
...
@@ -9,10 +9,10 @@ class Struct extends RefType {
...
@@ -9,10 +9,10 @@ class Struct extends RefType {
}
}
async
decodeFromStorage
(
location
,
storageResolver
)
{
async
decodeFromStorage
(
location
,
storageResolver
)
{
var
ret
=
{}
const
ret
=
{}
for
(
var
k
in
this
.
members
)
{
for
(
var
k
in
this
.
members
)
{
var
item
=
this
.
members
[
k
]
const
item
=
this
.
members
[
k
]
var
globalLocation
=
{
const
globalLocation
=
{
offset
:
location
.
offset
+
item
.
storagelocation
.
offset
,
offset
:
location
.
offset
+
item
.
storagelocation
.
offset
,
slot
:
util
.
add
(
location
.
slot
,
item
.
storagelocation
.
slot
)
slot
:
util
.
add
(
location
.
slot
,
item
.
storagelocation
.
slot
)
}
}
...
@@ -30,7 +30,7 @@ class Struct extends RefType {
...
@@ -30,7 +30,7 @@ class Struct extends RefType {
}
}
decodeFromMemoryInternal
(
offset
,
memory
)
{
decodeFromMemoryInternal
(
offset
,
memory
)
{
var
ret
=
{}
const
ret
=
{}
this
.
members
.
map
((
item
,
i
)
=>
{
this
.
members
.
map
((
item
,
i
)
=>
{
var
contentOffset
=
offset
var
contentOffset
=
offset
var
member
=
item
.
type
.
decodeFromMemory
(
contentOffset
,
memory
)
var
member
=
item
.
type
.
decodeFromMemory
(
contentOffset
,
memory
)
...
...
remix-debug/src/solidity-decoder/types/Uint.js
View file @
eddc2e38
'use strict'
'use strict'
var
util
=
require
(
'./util'
)
const
util
=
require
(
'./util'
)
var
ValueType
=
require
(
'./ValueType'
)
const
ValueType
=
require
(
'./ValueType'
)
class
Uint
extends
ValueType
{
class
Uint
extends
ValueType
{
constructor
(
storageBytes
)
{
constructor
(
storageBytes
)
{
...
...
remix-debug/src/solidity-decoder/types/ValueType.js
View file @
eddc2e38
...
@@ -41,7 +41,7 @@ class ValueType {
...
@@ -41,7 +41,7 @@ class ValueType {
* @return {Object} - decoded value
* @return {Object} - decoded value
*/
*/
async
decodeFromStack
(
stackDepth
,
stack
,
memory
)
{
async
decodeFromStack
(
stackDepth
,
stack
,
memory
)
{
var
value
let
value
if
(
stackDepth
>=
stack
.
length
)
{
if
(
stackDepth
>=
stack
.
length
)
{
value
=
this
.
decodeValue
(
''
)
value
=
this
.
decodeValue
(
''
)
}
else
{
}
else
{
...
@@ -61,7 +61,7 @@ class ValueType {
...
@@ -61,7 +61,7 @@ class ValueType {
* @return {Object} - decoded value
* @return {Object} - decoded value
*/
*/
decodeFromMemory
(
offset
,
memory
)
{
decodeFromMemory
(
offset
,
memory
)
{
var
value
=
memory
.
substr
(
2
*
offset
,
64
)
let
value
=
memory
.
substr
(
2
*
offset
,
64
)
return
{
return
{
value
:
this
.
decodeValue
(
value
),
value
:
this
.
decodeValue
(
value
),
type
:
this
.
typeName
type
:
this
.
typeName
...
...
remix-debug/src/solidity-decoder/types/util.js
View file @
eddc2e38
'use strict'
'use strict'
var
ethutil
=
require
(
'ethereumjs-util'
)
const
ethutil
=
require
(
'ethereumjs-util'
)
var
BN
=
require
(
'ethereumjs-util'
).
BN
const
BN
=
require
(
'ethereumjs-util'
).
BN
module
.
exports
=
{
module
.
exports
=
{
readFromStorage
:
readFromStorage
,
readFromStorage
:
readFromStorage
,
...
@@ -17,7 +17,7 @@ module.exports = {
...
@@ -17,7 +17,7 @@ module.exports = {
}
}
function
decodeIntFromHex
(
value
,
byteLength
,
signed
)
{
function
decodeIntFromHex
(
value
,
byteLength
,
signed
)
{
var
bigNumber
=
new
BN
(
value
,
16
)
let
bigNumber
=
new
BN
(
value
,
16
)
if
(
signed
)
{
if
(
signed
)
{
bigNumber
=
bigNumber
.
fromTwos
(
8
*
byteLength
)
bigNumber
=
bigNumber
.
fromTwos
(
8
*
byteLength
)
}
}
...
@@ -25,7 +25,7 @@ function decodeIntFromHex (value, byteLength, signed) {
...
@@ -25,7 +25,7 @@ function decodeIntFromHex (value, byteLength, signed) {
}
}
function
readFromStorage
(
slot
,
storageResolver
)
{
function
readFromStorage
(
slot
,
storageResolver
)
{
var
hexSlot
=
'0x'
+
normalizeHex
(
ethutil
.
bufferToHex
(
slot
))
const
hexSlot
=
'0x'
+
normalizeHex
(
ethutil
.
bufferToHex
(
slot
))
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
storageResolver
.
storageSlot
(
hexSlot
,
(
error
,
slot
)
=>
{
storageResolver
.
storageSlot
(
hexSlot
,
(
error
,
slot
)
=>
{
if
(
error
)
{
if
(
error
)
{
...
@@ -51,7 +51,7 @@ function readFromStorage (slot, storageResolver) {
...
@@ -51,7 +51,7 @@ function readFromStorage (slot, storageResolver) {
* @param {Int} offsetFromLSB - byte distance from the right end slot value to the right end of the byte slice
* @param {Int} offsetFromLSB - byte distance from the right end slot value to the right end of the byte slice
*/
*/
function
extractHexByteSlice
(
slotValue
,
byteLength
,
offsetFromLSB
)
{
function
extractHexByteSlice
(
slotValue
,
byteLength
,
offsetFromLSB
)
{
var
offset
=
slotValue
.
length
-
2
*
offsetFromLSB
-
2
*
byteLength
const
offset
=
slotValue
.
length
-
2
*
offsetFromLSB
-
2
*
byteLength
return
slotValue
.
substr
(
offset
,
2
*
byteLength
)
return
slotValue
.
substr
(
offset
,
2
*
byteLength
)
}
}
...
@@ -63,7 +63,7 @@ function extractHexByteSlice (slotValue, byteLength, offsetFromLSB) {
...
@@ -63,7 +63,7 @@ function extractHexByteSlice (slotValue, byteLength, offsetFromLSB) {
* @param {Int} byteLength - Length of the byte slice to extract
* @param {Int} byteLength - Length of the byte slice to extract
*/
*/
async
function
extractHexValue
(
location
,
storageResolver
,
byteLength
)
{
async
function
extractHexValue
(
location
,
storageResolver
,
byteLength
)
{
var
slotvalue
let
slotvalue
try
{
try
{
slotvalue
=
await
readFromStorage
(
location
.
slot
,
storageResolver
)
slotvalue
=
await
readFromStorage
(
location
.
slot
,
storageResolver
)
}
catch
(
e
)
{
}
catch
(
e
)
{
...
@@ -97,7 +97,7 @@ function removeLocation (type) {
...
@@ -97,7 +97,7 @@ function removeLocation (type) {
}
}
function
extractLocation
(
type
)
{
function
extractLocation
(
type
)
{
var
match
=
type
.
match
(
/
(
storage ref| storage pointer| memory| calldata
)?
$/
)
let
match
=
type
.
match
(
/
(
storage ref| storage pointer| memory| calldata
)?
$/
)
if
(
match
[
1
]
!==
''
)
{
if
(
match
[
1
]
!==
''
)
{
return
match
[
1
].
trim
()
return
match
[
1
].
trim
()
}
else
{
}
else
{
...
...
remix-debug/src/storage/mappingPreimages.js
View file @
eddc2e38
var
util
=
require
(
'../solidity-decoder/types/util'
)
const
util
=
require
(
'../solidity-decoder/types/util'
)
module
.
exports
=
{
module
.
exports
=
{
decodeMappingsKeys
:
decodeMappingsKeys
decodeMappingsKeys
:
decodeMappingsKeys
...
@@ -14,14 +14,14 @@ module.exports = {
...
@@ -14,14 +14,14 @@ module.exports = {
* @return {Map} - solidity mapping location (e.g { "<mapping_slot>" : { "<mapping-key1>": preimageOf1 }, { "<mapping-key2>": preimageOf2 }, ... })
* @return {Map} - solidity mapping location (e.g { "<mapping_slot>" : { "<mapping-key1>": preimageOf1 }, { "<mapping-key2>": preimageOf2 }, ... })
*/
*/
async
function
decodeMappingsKeys
(
web3
,
storage
,
corrections
,
callback
)
{
async
function
decodeMappingsKeys
(
web3
,
storage
,
corrections
,
callback
)
{
var
ret
=
{}
const
ret
=
{}
if
(
!
corrections
.
length
)
corrections
.
push
({
offset
:
0
,
slot
:
0
})
if
(
!
corrections
.
length
)
corrections
.
push
({
offset
:
0
,
slot
:
0
})
for
(
var
hashedLoc
in
storage
)
{
for
(
let
hashedLoc
in
storage
)
{
var
preimage
let
preimage
try
{
try
{
var
key
=
storage
[
hashedLoc
].
key
const
key
=
storage
[
hashedLoc
].
key
for
(
var
k
in
corrections
)
{
for
(
let
k
in
corrections
)
{
var
corrected
=
util
.
sub
(
key
,
corrections
[
k
].
slot
).
toString
(
16
)
const
corrected
=
util
.
sub
(
key
,
corrections
[
k
].
slot
).
toString
(
16
)
preimage
=
await
getPreimage
(
web3
,
'0x'
+
corrected
)
preimage
=
await
getPreimage
(
web3
,
'0x'
+
corrected
)
if
(
preimage
)
break
if
(
preimage
)
break
}
}
...
@@ -30,9 +30,9 @@ async function decodeMappingsKeys (web3, storage, corrections, callback) {
...
@@ -30,9 +30,9 @@ async function decodeMappingsKeys (web3, storage, corrections, callback) {
if
(
preimage
)
{
if
(
preimage
)
{
// got preimage!
// got preimage!
// get mapping position (i.e. storage slot), its the last 32 bytes
// get mapping position (i.e. storage slot), its the last 32 bytes
var
slotByteOffset
=
preimage
.
length
-
64
const
slotByteOffset
=
preimage
.
length
-
64
var
mappingSlot
=
preimage
.
substr
(
slotByteOffset
)
const
mappingSlot
=
preimage
.
substr
(
slotByteOffset
)
var
mappingKey
=
preimage
.
substr
(
0
,
slotByteOffset
)
const
mappingKey
=
preimage
.
substr
(
0
,
slotByteOffset
)
if
(
!
ret
[
mappingSlot
])
{
if
(
!
ret
[
mappingSlot
])
{
ret
[
mappingSlot
]
=
{}
ret
[
mappingSlot
]
=
{}
}
}
...
@@ -50,7 +50,7 @@ async function decodeMappingsKeys (web3, storage, corrections, callback) {
...
@@ -50,7 +50,7 @@ async function decodeMappingsKeys (web3, storage, corrections, callback) {
*/
*/
function
getPreimage
(
web3
,
key
)
{
function
getPreimage
(
web3
,
key
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
web3
.
debug
.
preimage
(
key
.
indexOf
(
'0x'
)
===
0
?
key
:
'0x'
+
key
,
function
(
error
,
preimage
)
{
web3
.
debug
.
preimage
(
key
.
indexOf
(
'0x'
)
===
0
?
key
:
'0x'
+
key
,
(
error
,
preimage
)
=>
{
if
(
error
)
{
if
(
error
)
{
resolve
(
null
)
resolve
(
null
)
}
else
{
}
else
{
...
...
remix-debug/src/storage/storageResolver.js
View file @
eddc2e38
'use strict'
'use strict'
var
remixLib
=
require
(
'remix-lib'
)
const
remixLib
=
require
(
'remix-lib'
)
var
traceHelper
=
remixLib
.
helpers
.
trace
const
traceHelper
=
remixLib
.
helpers
.
trace
var
mappingPreimages
=
require
(
'./mappingPreimages'
)
const
mappingPreimages
=
require
(
'./mappingPreimages'
)
/**
/**
* Basically one instance is created for one debugging session.
* Basically one instance is created for one debugging session.
...
@@ -40,7 +40,6 @@ class StorageResolver {
...
@@ -40,7 +40,6 @@ class StorageResolver {
* @return {Function} - callback
* @return {Function} - callback
*/
*/
initialPreimagesMappings
(
tx
,
stepIndex
,
address
,
corrections
,
callback
)
{
initialPreimagesMappings
(
tx
,
stepIndex
,
address
,
corrections
,
callback
)
{
const
self
=
this
if
(
this
.
preimagesMappingByAddress
[
address
])
{
if
(
this
.
preimagesMappingByAddress
[
address
])
{
return
callback
(
null
,
this
.
preimagesMappingByAddress
[
address
])
return
callback
(
null
,
this
.
preimagesMappingByAddress
[
address
])
}
}
...
@@ -48,7 +47,7 @@ class StorageResolver {
...
@@ -48,7 +47,7 @@ class StorageResolver {
if
(
error
)
{
if
(
error
)
{
return
callback
(
error
)
return
callback
(
error
)
}
}
mappingPreimages
.
decodeMappingsKeys
(
self
.
web3
,
storage
,
corrections
,
(
error
,
mappings
)
=>
{
mappingPreimages
.
decodeMappingsKeys
(
this
.
web3
,
storage
,
corrections
,
(
error
,
mappings
)
=>
{
if
(
error
)
{
if
(
error
)
{
callback
(
error
)
callback
(
error
)
}
else
{
}
else
{
...
@@ -69,7 +68,7 @@ class StorageResolver {
...
@@ -69,7 +68,7 @@ class StorageResolver {
* @param {Function} - callback - {key, hashedKey, value} -
* @param {Function} - callback - {key, hashedKey, value} -
*/
*/
storageSlot
(
slot
,
tx
,
stepIndex
,
address
,
callback
)
{
storageSlot
(
slot
,
tx
,
stepIndex
,
address
,
callback
)
{
this
.
storageRangeInternal
(
this
,
slot
,
tx
,
stepIndex
,
address
,
function
(
error
,
storage
)
{
this
.
storageRangeInternal
(
this
,
slot
,
tx
,
stepIndex
,
address
,
(
error
,
storage
)
=>
{
if
(
error
)
{
if
(
error
)
{
callback
(
error
)
callback
(
error
)
}
else
{
}
else
{
...
...
remix-debug/src/storage/storageViewer.js
View file @
eddc2e38
'use strict'
'use strict'
var
remixLib
=
require
(
'remix-lib'
)
const
remixLib
=
require
(
'remix-lib'
)
var
util
=
remixLib
.
util
const
util
=
remixLib
.
util
var
mappingPreimages
=
require
(
'./mappingPreimages'
)
const
mappingPreimages
=
require
(
'./mappingPreimages'
)
/**
/**
* easier access to the storage resolver
* easier access to the storage resolver
...
@@ -46,7 +46,7 @@ class StorageViewer {
...
@@ -46,7 +46,7 @@ class StorageViewer {
* @param {Function} - callback - {key, hashedKey, value} -
* @param {Function} - callback - {key, hashedKey, value} -
*/
*/
storageSlot
(
slot
,
callback
)
{
storageSlot
(
slot
,
callback
)
{
var
hashed
=
util
.
sha3_256
(
slot
)
const
hashed
=
util
.
sha3_256
(
slot
)
if
(
this
.
storageChanges
[
hashed
])
{
if
(
this
.
storageChanges
[
hashed
])
{
return
callback
(
null
,
this
.
storageChanges
[
hashed
])
return
callback
(
null
,
this
.
storageChanges
[
hashed
])
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment