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
ed5c07c6
Commit
ed5c07c6
authored
Dec 06, 2016
by
yann300
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use solidityproxy to send statevar to localdecoder
parent
cbc01ef5
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
183 additions
and
114 deletions
+183
-114
sourceLocationTracker.js
src/code/sourceLocationTracker.js
+29
-24
localDecoder.js
src/solidity/localDecoder.js
+47
-46
solidityProxy.js
src/solidity/solidityProxy.js
+90
-0
Ethdebugger.js
src/ui/Ethdebugger.js
+6
-13
SolidityState.js
src/ui/SolidityState.js
+5
-28
VmDebugger.js
src/ui/VmDebugger.js
+2
-2
localDecoder.js
test/solidity/localDecoder.js
+4
-1
No files found.
src/code/sourceLocationTracker.js
View file @
ed5c07c6
...
...
@@ -20,18 +20,13 @@ function SourceLocationTracker (_codeManager) {
* @param {Object} contractDetails - AST of compiled contracts
* @param {Function} cb - callback function
*/
SourceLocationTracker
.
prototype
.
getSourceLocation
=
function
(
address
,
index
,
contracts
,
cb
)
{
SourceLocationTracker
.
prototype
.
getSourceLocation
FromInstructionIndex
=
function
(
address
,
index
,
contracts
,
cb
)
{
var
self
=
this
this
.
codeManager
.
getCode
(
address
,
function
(
error
,
result
)
{
if
(
!
error
)
{
var
sourceMap
=
getSourceMap
(
address
,
result
.
bytecode
,
contracts
)
if
(
sourceMap
)
{
cb
(
null
,
self
.
sourceMappingDecoder
.
atIndex
(
index
,
sourceMap
))
}
else
{
cb
(
'no srcmap associated with the code '
+
address
)
}
}
else
{
extractSourceMap
(
this
.
codeManager
,
address
,
contracts
,
function
(
error
,
sourceMap
)
{
if
(
error
)
{
cb
(
error
)
}
else
{
cb
(
null
,
self
.
sourceMappingDecoder
.
atIndex
(
index
,
sourceMap
))
}
})
}
...
...
@@ -44,22 +39,17 @@ SourceLocationTracker.prototype.getSourceLocation = function (address, index, co
* @param {Object} contractDetails - AST of compiled contracts
* @param {Function} cb - callback function
*/
SourceLocationTracker
.
prototype
.
getSourceLocation
=
function
(
address
,
vmtraceStepIndex
,
contracts
,
cb
)
{
SourceLocationTracker
.
prototype
.
getSourceLocation
FromVMTraceIndex
=
function
(
address
,
vmtraceStepIndex
,
contracts
,
cb
)
{
var
self
=
this
this
.
codeManager
.
getCode
(
address
,
function
(
error
,
result
)
{
extractSourceMap
(
this
.
codeManager
,
address
,
contracts
,
function
(
error
,
sourceMap
)
{
if
(
!
error
)
{
var
sourceMap
=
getSourceMap
(
address
,
result
.
bytecode
,
contracts
)
if
(
sourceMap
)
{
self
.
codeManager
.
getInstructionIndex
(
address
,
vmtraceStepIndex
,
function
(
error
,
index
)
{
if
(
error
)
{
cb
(
error
)
}
else
{
cb
(
null
,
self
.
sourceMappingDecoder
.
atIndex
(
index
,
sourceMap
))
}
})
}
else
{
cb
(
'no srcmap associated with the code '
+
address
)
}
self
.
codeManager
.
getInstructionIndex
(
address
,
vmtraceStepIndex
,
function
(
error
,
index
)
{
if
(
error
)
{
cb
(
error
)
}
else
{
cb
(
null
,
self
.
sourceMappingDecoder
.
atIndex
(
index
,
sourceMap
))
}
})
}
else
{
cb
(
error
)
}
...
...
@@ -84,4 +74,19 @@ function getSourceMap (address, code, contracts) {
return
null
}
function
extractSourceMap
(
codeManager
,
address
,
contracts
,
cb
)
{
codeManager
.
getCode
(
address
,
function
(
error
,
result
)
{
if
(
!
error
)
{
var
sourceMap
=
getSourceMap
(
address
,
result
.
bytecode
,
contracts
)
if
(
sourceMap
)
{
cb
(
null
,
sourceMap
)
}
else
{
cb
(
'no srcmap associated with the code '
+
address
)
}
}
else
{
cb
(
error
)
}
})
}
module
.
exports
=
SourceLocationTracker
src/solidity/localDecoder.js
View file @
ed5c07c6
...
...
@@ -3,56 +3,57 @@ var SourceLocationTracker = require('../code/sourceLocationTracker')
var
AstWalker
=
require
(
'../util/astWalker'
)
var
decodeInfo
=
require
(
'../solidity/decodeInfo'
)
function
LocalDecoder
(
parent
,
codeManager
,
traceAnalyserEvent
)
{
this
.
astWalker
=
new
AstWalker
()
this
.
codeManager
=
codeManager
this
.
parent
=
parent
this
.
locals
=
{}
this
.
loading
=
false
this
.
sourceLocationTracker
=
new
SourceLocationTracker
(
this
.
codeManager
)
var
self
=
this
traceAnalyserEvent
.
register
(
'startAnalysing'
,
function
(
step
)
{
self
.
clear
()
})
traceAnalyserEvent
.
register
(
'onOp'
,
function
(
index
,
step
,
callStack
,
cache
)
{
self
.
push
(
index
,
step
,
callStack
,
cache
)
})
traceAnalyserEvent
.
register
(
'finishAnalysing'
,
function
(
index
,
step
)
{
self
.
loading
=
true
})
}
LocalDecoder
.
prototype
.
push
=
function
(
index
,
step
,
callStack
,
cache
)
{
if
(
!
this
.
parent
.
sources
)
return
if
(
step
.
op
.
indexOf
(
'PUSH'
)
===
0
)
{
class
LocalDecoder
{
constructor
(
codeManager
,
traceAnalyserEvent
,
solidityProxy
)
{
this
.
astWalker
=
new
AstWalker
()
this
.
sourceLocationTracker
=
new
SourceLocationTracker
(
codeManager
)
this
.
solidityProxy
=
solidityProxy
this
.
locals
=
{}
var
self
=
this
var
compiledContracts
=
this
.
parent
.
contracts
var
address
=
callStack
[
callStack
.
length
-
1
]
this
.
sourceLocationTracker
.
getSourceLocation
(
address
,
index
,
compiledContracts
,
function
(
error
,
result
)
{
if
(
error
)
{
console
.
log
(
error
)
}
else
{
var
file
=
self
.
parent
.
sourceList
[
result
.
file
]
var
ast
=
self
.
parent
.
sources
[
file
].
AST
self
.
astWalker
.
walk
(
ast
,
function
(
node
)
{
if
(
node
.
name
===
'VariableDeclaration'
&&
node
.
src
.
indexOf
(
result
.
start
+
':'
+
result
.
length
)
===
0
)
{
self
.
locals
[
node
.
attributes
.
name
]
=
{
type
:
decodeInfo
.
parseType
(
node
.
attributes
.
type
,
[]),
stack
:
step
.
stack
}
return
false
}
else
{
return
true
}
})
}
traceAnalyserEvent
.
register
(
'startAnalysing'
,
function
(
step
)
{
self
.
clear
()
})
traceAnalyserEvent
.
register
(
'onOp'
,
function
(
index
,
step
,
callStack
,
cache
)
{
self
.
push
(
index
,
step
,
callStack
,
cache
)
})
traceAnalyserEvent
.
register
(
'finishAnalysing'
,
function
(
index
,
step
)
{
})
}
}
LocalDecoder
.
prototype
.
clear
=
function
()
{
this
.
loading
=
false
this
.
locals
=
{}
push
(
index
,
step
,
callStack
,
cache
)
{
if
(
!
this
.
solidityProxy
.
loaded
())
return
if
(
step
.
op
.
indexOf
(
'PUSH'
)
===
0
)
{
var
address
=
callStack
[
callStack
.
length
-
1
]
this
.
sourceLocationTracker
.
getSourceLocationFromVMTraceIndex
(
address
,
index
,
this
.
solidityProxy
.
contracts
,
(
error
,
result
)
=>
{
if
(
error
)
{
console
.
log
(
error
)
}
else
{
var
ast
=
this
.
solidityProxy
.
ast
(
result
)
this
.
solidityProxy
.
extractStateVariablesAt
(
index
,
(
error
,
stateVars
)
=>
{
// cached
if
(
error
)
{
console
.
log
(
error
)
}
else
{
this
.
astWalker
.
walk
(
ast
,
(
node
)
=>
{
if
(
node
.
name
===
'VariableDeclaration'
&&
node
.
src
.
indexOf
(
result
.
start
+
':'
+
result
.
length
)
===
0
)
{
this
.
locals
[
node
.
attributes
.
name
]
=
{
type
:
decodeInfo
.
parseType
(
node
.
attributes
.
type
,
stateVars
),
stack
:
step
.
stack
}
return
false
}
else
{
return
true
}
})
}
})
}
})
}
}
clear
()
{
this
.
locals
=
{}
}
}
module
.
exports
=
LocalDecoder
src/solidity/solidityProxy.js
0 → 100644
View file @
ed5c07c6
'use strict'
var
traceHelper
=
require
(
'../helpers/traceHelper'
)
var
stateDecoder
=
require
(
'./stateDecoder'
)
class
SolidityProxy
{
constructor
(
traceManager
,
codeManager
)
{
this
.
cache
=
new
Cache
()
this
.
reset
({})
this
.
traceManager
=
traceManager
this
.
codeManager
=
codeManager
}
reset
(
compilationResult
)
{
this
.
sources
=
compilationResult
.
sources
this
.
sourceList
=
compilationResult
.
sourceList
this
.
contracts
=
compilationResult
.
contracts
this
.
cache
.
reset
()
}
loaded
()
{
return
this
.
contracts
!==
undefined
}
contractNameAt
(
vmTraceIndex
,
cb
)
{
this
.
traceManager
.
getCurrentCalledAddressAt
(
vmTraceIndex
,
(
error
,
address
)
=>
{
if
(
error
)
{
cb
(
error
)
}
else
{
if
(
this
.
cache
.
contractNameByAddress
[
address
])
{
cb
(
null
,
this
.
cache
.
contractNameByAddress
[
address
])
}
else
{
this
.
codeManager
.
getCode
(
address
,
(
error
,
code
)
=>
{
if
(
error
)
{
cb
(
error
)
}
else
{
var
contractName
=
contractNameFromCode
(
this
.
contracts
,
code
.
bytecode
,
address
)
this
.
cache
.
contractNameByAddress
[
address
]
=
contractName
cb
(
null
,
contractName
)
}
})
}
}
})
}
extractStateVariables
(
contractName
)
{
if
(
!
this
.
cache
.
stateVariablesByContractName
[
contractName
])
{
this
.
cache
.
stateVariablesByContractName
[
contractName
]
=
stateDecoder
.
extractStateVariables
(
contractName
,
this
.
sources
)
}
return
this
.
cache
.
stateVariablesByContractName
[
contractName
]
}
extractStateVariablesAt
(
vmtraceIndex
,
cb
)
{
this
.
contractNameAt
(
vmtraceIndex
,
(
error
,
contractName
)
=>
{
if
(
error
)
{
cb
(
error
)
}
else
{
cb
(
null
,
this
.
extractStateVariables
(
contractName
))
}
})
}
ast
(
sourceLocation
)
{
var
file
=
this
.
sourceList
[
sourceLocation
.
file
]
return
this
.
sources
[
file
].
AST
}
}
function
contractNameFromCode
(
contracts
,
code
,
address
)
{
var
isCreation
=
traceHelper
.
isContractCreation
(
address
)
var
byteProp
=
isCreation
?
'bytecode'
:
'runtimeBytecode'
for
(
var
k
in
contracts
)
{
if
(
'0x'
+
contracts
[
k
][
byteProp
]
===
code
)
{
return
k
}
}
return
null
}
class
Cache
{
constructor
()
{
this
.
reset
()
}
reset
()
{
this
.
contractNameByAddress
=
{}
this
.
stateVariablesByContractName
=
{}
}
}
module
.
exports
=
SolidityProxy
src/ui/Ethdebugger.js
View file @
ed5c07c6
...
...
@@ -11,16 +11,14 @@ var ui = require('../helpers/ui')
var
Web3Providers
=
require
(
'../web3Provider/web3Providers'
)
var
DummyProvider
=
require
(
'../web3Provider/dummyProvider'
)
var
CodeManager
=
require
(
'../code/codeManager'
)
var
SourceLocationTracker
=
require
(
'../code/sourceLocationTracker'
)
var
LocalDecoder
=
require
(
'../solidity/localDecoder'
)
var
SolidityProxy
=
require
(
'../solidity/solidityProxy'
)
function
Ethdebugger
()
{
this
.
event
=
new
EventManager
()
this
.
currentStepIndex
=
-
1
this
.
tx
this
.
sources
this
.
contracts
this
.
statusMessage
=
''
this
.
view
...
...
@@ -29,9 +27,8 @@ function Ethdebugger () {
this
.
switchProvider
(
'DUMMYWEB3'
)
this
.
traceManager
=
new
TraceManager
()
this
.
codeManager
=
new
CodeManager
(
this
.
traceManager
)
this
.
sourceLocationTracker
=
new
SourceLocationTracker
(
this
.
codeManager
)
this
.
locals
=
new
LocalDecoder
(
this
,
this
.
codeManager
,
this
.
traceManager
.
traceAnalyser
.
event
)
this
.
solidityProxy
=
new
SolidityProxy
(
this
.
traceManager
,
this
.
codeManager
)
this
.
locals
=
new
LocalDecoder
(
this
.
codeManager
,
this
.
traceManager
.
traceAnalyser
.
event
,
this
.
solidityProxy
)
var
self
=
this
this
.
event
.
register
(
'indexChanged'
,
this
,
function
(
index
)
{
self
.
codeManager
.
resolveStep
(
index
,
self
.
tx
)
...
...
@@ -51,7 +48,7 @@ function Ethdebugger () {
this
.
stepManager
.
event
.
register
(
'stepChanged'
,
this
,
function
(
stepIndex
)
{
self
.
stepChanged
(
stepIndex
)
})
this
.
vmDebugger
=
new
VmDebugger
(
this
,
this
.
traceManager
,
this
.
codeManager
)
this
.
vmDebugger
=
new
VmDebugger
(
this
,
this
.
traceManager
,
this
.
codeManager
,
this
.
solidityProxy
)
}
Ethdebugger
.
prototype
.
web3
=
function
()
{
...
...
@@ -77,13 +74,9 @@ Ethdebugger.prototype.switchProvider = function (type) {
Ethdebugger
.
prototype
.
setCompilationResult
=
function
(
compilationResult
)
{
if
(
compilationResult
&&
compilationResult
.
sources
&&
compilationResult
.
contracts
)
{
this
.
sources
=
compilationResult
.
sources
this
.
sourceList
=
compilationResult
.
sourceList
this
.
contracts
=
compilationResult
.
contracts
this
.
solidityProxy
.
reset
(
compilationResult
)
}
else
{
this
.
sources
=
null
this
.
contracts
=
null
this
.
sourceList
=
null
this
.
solidityProxy
.
reset
({})
}
}
...
...
src/ui/SolidityState.js
View file @
ed5c07c6
'use strict'
var
DropdownPanel
=
require
(
'./DropdownPanel'
)
var
traceHelper
=
require
(
'../helpers/traceHelper'
)
var
stateDecoder
=
require
(
'../solidity/stateDecoder'
)
var
yo
=
require
(
'yo-yo'
)
function
SolidityState
(
_parent
,
_traceManager
,
_codeManager
)
{
function
SolidityState
(
_parent
,
_traceManager
,
_codeManager
,
_solidityProxy
)
{
this
.
parent
=
_parent
this
.
traceManager
=
_traceManager
this
.
codeManager
=
_codeManager
this
.
solidityProxy
=
_solidityProxy
this
.
basicPanel
=
new
DropdownPanel
(
'Solidity State'
)
this
.
init
()
}
...
...
@@ -24,7 +24,7 @@ SolidityState.prototype.init = function () {
return
}
if
(
self
.
parent
.
currentStepIndex
!==
index
)
return
if
(
!
this
.
parent
.
contracts
||
!
this
.
parent
.
sources
)
{
if
(
!
this
.
solidityProxy
.
loaded
()
)
{
self
.
basicPanel
.
update
({
info
:
'no source has been specified'
})
return
}
...
...
@@ -33,23 +33,11 @@ SolidityState.prototype.init = function () {
if
(
error
)
{
self
.
basicPanel
.
update
({
info
:
error
})
}
else
{
self
.
traceManager
.
getCurrentCalledAddressAt
(
index
,
function
(
error
,
addres
s
)
{
self
.
solidityProxy
.
extractStateVariablesAt
(
index
,
function
(
error
,
stateVar
s
)
{
if
(
error
)
{
self
.
basicPanel
.
update
({
info
:
error
})
}
else
{
self
.
codeManager
.
getCode
(
address
,
function
(
error
,
code
)
{
if
(
error
)
{
self
.
basicPanel
.
update
({
info
:
error
})
}
else
{
var
contractName
=
contractNameFromCode
(
self
.
parent
.
contracts
,
code
.
bytecode
,
address
)
if
(
contractName
===
null
)
{
self
.
basicPanel
.
update
({
info
:
'could not find compiled contract with address '
+
address
})
}
else
{
var
state
=
stateDecoder
.
solidityState
(
storage
,
self
.
parent
.
sources
,
contractName
)
self
.
basicPanel
.
update
(
state
)
}
}
})
self
.
basicPanel
.
update
(
stateDecoder
.
decodeState
(
stateVars
,
storage
))
}
})
}
...
...
@@ -57,15 +45,4 @@ SolidityState.prototype.init = function () {
})
}
function
contractNameFromCode
(
contracts
,
code
,
address
)
{
var
isCreation
=
traceHelper
.
isContractCreation
(
address
)
var
byteProp
=
isCreation
?
'bytecode'
:
'runtimeBytecode'
for
(
var
k
in
contracts
)
{
if
(
'0x'
+
contracts
[
k
][
byteProp
]
===
code
)
{
return
k
}
}
return
null
}
module
.
exports
=
SolidityState
src/ui/VmDebugger.js
View file @
ed5c07c6
...
...
@@ -11,7 +11,7 @@ var DropdownPanel = require('./DropdownPanel')
var
SolidityState
=
require
(
'./SolidityState'
)
var
yo
=
require
(
'yo-yo'
)
function
VmDebugger
(
_parent
,
_traceManager
,
_codeManager
)
{
function
VmDebugger
(
_parent
,
_traceManager
,
_codeManager
,
_solidityProxy
)
{
this
.
asmCode
=
new
CodeListView
(
_parent
,
_codeManager
)
this
.
stackPanel
=
new
StackPanel
(
_parent
,
_traceManager
)
this
.
storagePanel
=
new
StoragePanel
(
_parent
,
_traceManager
)
...
...
@@ -19,7 +19,7 @@ function VmDebugger (_parent, _traceManager, _codeManager) {
this
.
calldataPanel
=
new
CalldataPanel
(
_parent
,
_traceManager
)
this
.
callstackPanel
=
new
CallstackPanel
(
_parent
,
_traceManager
)
this
.
stepDetail
=
new
StepDetail
(
_parent
,
_traceManager
)
this
.
solidityState
=
new
SolidityState
(
_parent
,
_traceManager
,
_codeManager
)
this
.
solidityState
=
new
SolidityState
(
_parent
,
_traceManager
,
_codeManager
,
_solidityProxy
)
/* Return values - */
this
.
returnValuesPanel
=
new
DropdownPanel
(
'Return Value'
)
...
...
test/solidity/localDecoder.js
View file @
ed5c07c6
...
...
@@ -13,6 +13,7 @@ var Web3Providers = require('../../src/web3Provider/web3Providers')
var
traceHelper
=
require
(
'../../src/helpers/traceHelper'
)
var
util
=
require
(
'../../src/helpers/global'
)
var
LocalDecoder
=
require
(
'../../src/solidity/localDecoder'
)
var
SolidityProxy
=
require
(
'../../src/solidity/solidityProxy'
)
tape
(
'solidity'
,
function
(
t
)
{
t
.
test
(
'local decoder'
,
function
(
st
)
{
...
...
@@ -32,7 +33,9 @@ tape('solidity', function (t) {
tx
.
to
=
traceHelper
.
contractCreationToken
(
'0'
)
var
traceManager
=
new
TraceManager
()
var
codeManager
=
new
CodeManager
(
traceManager
)
var
localDecoder
=
new
LocalDecoder
(
output
,
codeManager
,
traceManager
.
traceAnalyser
.
event
)
var
solidityProxy
=
new
SolidityProxy
(
traceManager
,
codeManager
)
solidityProxy
.
reset
(
output
)
var
localDecoder
=
new
LocalDecoder
(
codeManager
,
traceManager
.
traceAnalyser
.
event
,
solidityProxy
)
traceManager
.
resolveTrace
(
tx
,
function
(
error
,
result
)
{
if
(
error
)
{
st
.
fail
(
error
)
...
...
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