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
59319229
Commit
59319229
authored
Mar 21, 2018
by
yann300
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor EthDebugger
parent
bb0ecccb
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
93 additions
and
15 deletions
+93
-15
Ethdebugger.js
remix-debug/src/Ethdebugger.js
+93
-15
No files found.
remix-debug/src/Ethdebugger.js
View file @
59319229
'use strict'
'use strict'
var
remixCore
=
require
(
'remix-core'
)
var
remixCore
=
require
(
'remix-core'
)
var
TraceManager
=
remixCore
.
trace
.
TraceManager
var
TraceManager
=
remixCore
.
trace
.
TraceManager
var
StorageViewer
=
remixCore
.
storage
.
StorageViewer
var
remixLib
=
require
(
'remix-lib'
)
var
remixLib
=
require
(
'remix-lib'
)
var
traceHelper
=
remixLib
.
helpers
.
trace
var
global
=
remixLib
.
global
var
global
=
remixLib
.
global
var
init
=
remixLib
.
init
var
init
=
remixLib
.
init
var
executionContext
=
remixLib
.
execution
.
executionContext
var
executionContext
=
remixLib
.
execution
.
executionContext
...
@@ -11,7 +13,10 @@ var DummyProvider = remixLib.vm.DummyProvider
...
@@ -11,7 +13,10 @@ var DummyProvider = remixLib.vm.DummyProvider
var
CodeManager
=
remixCore
.
code
.
CodeManager
var
CodeManager
=
remixCore
.
code
.
CodeManager
var
remixSolidity
=
require
(
'remix-solidity'
)
var
remixSolidity
=
require
(
'remix-solidity'
)
var
SolidityProxy
=
remixSolidity
.
SolidityProxy
var
SolidityProxy
=
remixSolidity
.
SolidityProxy
var
stateDecoder
=
remixSolidity
.
stateDecoder
var
localDecoder
=
remixSolidity
.
localDecoder
var
InternalCallTree
=
remixSolidity
.
InternalCallTree
var
InternalCallTree
=
remixSolidity
.
InternalCallTree
var
StorageResolver
=
remixCore
.
storage
.
StorageResolver
/**
/**
* 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
...
@@ -22,6 +27,7 @@ var InternalCallTree = remixSolidity.InternalCallTree
...
@@ -22,6 +27,7 @@ var InternalCallTree = remixSolidity.InternalCallTree
* - SolidityProxy - Basically used to extract state variable from AST
* - SolidityProxy - Basically used to extract state variable from AST
* - Breakpoint Manager - Used to add / remove / jumpto breakpoint
* - Breakpoint Manager - Used to add / remove / jumpto breakpoint
* - InternalCallTree - Used to retrieved local variables
* - InternalCallTree - Used to retrieved local variables
* - StorageResolver - Help resolving the storage accross different steps
*
*
* @param {Map} opts - { function compilationResult } //
* @param {Map} opts - { function compilationResult } //
*/
*/
...
@@ -29,7 +35,6 @@ function Ethdebugger (opts) {
...
@@ -29,7 +35,6 @@ function Ethdebugger (opts) {
this
.
opts
=
opts
||
{}
this
.
opts
=
opts
||
{}
if
(
!
this
.
opts
.
compilationResult
)
this
.
opts
.
compilationResult
=
()
=>
{
return
null
}
if
(
!
this
.
opts
.
compilationResult
)
this
.
opts
.
compilationResult
=
()
=>
{
return
null
}
var
self
=
this
this
.
event
=
new
EventManager
()
this
.
event
=
new
EventManager
()
this
.
tx
this
.
tx
...
@@ -41,14 +46,24 @@ function Ethdebugger (opts) {
...
@@ -41,14 +46,24 @@ function Ethdebugger (opts) {
this
.
traceManager
=
new
TraceManager
()
this
.
traceManager
=
new
TraceManager
()
this
.
codeManager
=
new
CodeManager
(
this
.
traceManager
)
this
.
codeManager
=
new
CodeManager
(
this
.
traceManager
)
this
.
solidityProxy
=
new
SolidityProxy
(
this
.
traceManager
,
this
.
codeManager
)
this
.
solidityProxy
=
new
SolidityProxy
(
this
.
traceManager
,
this
.
codeManager
)
this
.
storageResolver
=
null
this
.
callTree
=
new
InternalCallTree
(
this
.
event
,
this
.
traceManager
,
this
.
solidityProxy
,
this
.
codeManager
,
{
includeLocalVariables
:
true
})
this
.
callTree
=
new
InternalCallTree
(
this
.
event
,
this
.
traceManager
,
this
.
solidityProxy
,
this
.
codeManager
,
{
includeLocalVariables
:
true
})
}
this
.
event
.
register
(
'indexChanged'
,
this
,
function
(
index
)
{
Ethdebugger
.
prototype
.
resolveStep
=
function
(
index
)
{
self
.
codeManager
.
resolveStep
(
index
,
self
.
tx
)
this
.
codeManager
.
resolveStep
(
index
,
this
.
tx
)
})
}
Ethdebugger
.
prototype
.
setCompilationResult
=
function
(
compilationResult
)
{
if
(
compilationResult
&&
compilationResult
.
sources
&&
compilationResult
.
contracts
)
{
this
.
solidityProxy
.
reset
(
compilationResult
)
}
else
{
this
.
solidityProxy
.
reset
({})
}
}
}
/* resolve source location */
Ethdebugger
.
prototype
.
sourceLocationFromVMTraceIndex
=
function
(
address
,
stepIndex
,
callback
)
{
Ethdebugger
.
prototype
.
sourceLocationFromVMTraceIndex
=
function
(
address
,
stepIndex
,
callback
)
{
this
.
callTree
.
sourceLocationTracker
.
getSourceLocationFromVMTraceIndex
(
address
,
stepIndex
,
this
.
solidityProxy
.
contracts
,
(
error
,
rawLocation
)
=>
{
this
.
callTree
.
sourceLocationTracker
.
getSourceLocationFromVMTraceIndex
(
address
,
stepIndex
,
this
.
solidityProxy
.
contracts
,
(
error
,
rawLocation
)
=>
{
callback
(
error
,
rawLocation
)
callback
(
error
,
rawLocation
)
...
@@ -61,14 +76,81 @@ Ethdebugger.prototype.sourceLocationFromInstructionIndex = function (address, in
...
@@ -61,14 +76,81 @@ Ethdebugger.prototype.sourceLocationFromInstructionIndex = function (address, in
})
})
}
}
/* breakpoint */
Ethdebugger
.
prototype
.
setBreakpointManager
=
function
(
breakpointManager
)
{
Ethdebugger
.
prototype
.
setBreakpointManager
=
function
(
breakpointManager
)
{
this
.
breakpointManager
=
breakpointManager
this
.
breakpointManager
=
breakpointManager
}
}
Ethdebugger
.
prototype
.
resolveStep
=
function
(
index
)
{
/* decode locals */
this
.
codeManager
.
resolveStep
(
index
,
this
.
tx
)
Ethdebugger
.
prototype
.
extractLocalsAt
=
function
(
step
,
callback
)
{
callback
(
null
,
this
.
callTree
.
findScope
(
step
))
}
Ethdebugger
.
prototype
.
decodeLocalsAt
=
function
(
step
,
sourceLocation
,
callback
)
{
this
.
traceManager
.
waterfall
([
this
.
traceManager
.
getStackAt
,
this
.
traceManager
.
getMemoryAt
,
this
.
traceManager
.
getCurrentCalledAddressAt
],
step
,
(
error
,
result
)
=>
{
if
(
!
error
)
{
var
stack
=
result
[
0
].
value
var
memory
=
result
[
1
].
value
try
{
var
storageViewer
=
new
StorageViewer
({
stepIndex
:
step
,
tx
:
this
.
tx
,
address
:
result
[
2
].
value
},
this
.
storageResolver
,
this
.
traceManager
)
localDecoder
.
solidityLocals
(
step
,
this
.
callTree
,
stack
,
memory
,
storageViewer
,
sourceLocation
).
then
((
locals
)
=>
{
if
(
!
locals
.
error
)
{
callback
(
null
,
locals
)
}
else
{
callback
(
locals
.
error
)
}
})
}
catch
(
e
)
{
callback
(
e
.
message
)
}
}
else
{
callback
(
error
)
}
})
}
/* decode state */
Ethdebugger
.
prototype
.
extractStateAt
=
function
(
step
,
callback
)
{
this
.
solidityProxy
.
extractStateVariablesAt
(
step
,
function
(
error
,
stateVars
)
{
callback
(
error
,
stateVars
)
})
}
Ethdebugger
.
prototype
.
decodeStateAt
=
function
(
step
,
stateVars
,
callback
)
{
this
.
traceManager
.
getCurrentCalledAddressAt
(
step
,
(
error
,
address
)
=>
{
if
(
error
)
return
callback
(
error
)
var
storageViewer
=
new
StorageViewer
({
stepIndex
:
step
,
tx
:
this
.
tx
,
address
:
address
},
this
.
storageResolver
,
this
.
traceManager
)
stateDecoder
.
decodeState
(
stateVars
,
storageViewer
).
then
((
result
)
=>
{
if
(
!
result
.
error
)
{
callback
(
null
,
result
)
}
else
{
callback
(
result
.
error
)
}
})
})
}
}
Ethdebugger
.
prototype
.
storageViewAt
=
function
(
step
,
address
)
{
return
new
StorageViewer
({
stepIndex
:
step
,
tx
:
this
.
tx
,
address
:
address
},
this
.
storageResolver
,
this
.
traceManager
)
}
/* set env */
Ethdebugger
.
prototype
.
web3
=
function
()
{
Ethdebugger
.
prototype
.
web3
=
function
()
{
return
global
.
web3
return
global
.
web3
}
}
...
@@ -98,14 +180,6 @@ Ethdebugger.prototype.switchProvider = function (type) {
...
@@ -98,14 +180,6 @@ Ethdebugger.prototype.switchProvider = function (type) {
})
})
}
}
Ethdebugger
.
prototype
.
setCompilationResult
=
function
(
compilationResult
)
{
if
(
compilationResult
&&
compilationResult
.
sources
&&
compilationResult
.
contracts
)
{
this
.
solidityProxy
.
reset
(
compilationResult
)
}
else
{
this
.
solidityProxy
.
reset
({})
}
}
Ethdebugger
.
prototype
.
debug
=
function
(
tx
)
{
Ethdebugger
.
prototype
.
debug
=
function
(
tx
)
{
this
.
setCompilationResult
(
this
.
opts
.
compilationResult
())
this
.
setCompilationResult
(
this
.
opts
.
compilationResult
())
if
(
tx
instanceof
Object
)
{
if
(
tx
instanceof
Object
)
{
...
@@ -122,10 +196,13 @@ Ethdebugger.prototype.unLoad = function () {
...
@@ -122,10 +196,13 @@ Ethdebugger.prototype.unLoad = function () {
this
.
event
.
trigger
(
'traceUnloaded'
)
this
.
event
.
trigger
(
'traceUnloaded'
)
}
}
Ethdebugger
.
prototype
.
debug
=
function
(
blockNumber
,
txIndex
,
tx
)
{
Ethdebugger
.
prototype
.
debug
=
function
(
tx
)
{
if
(
this
.
traceManager
.
isLoading
)
{
if
(
this
.
traceManager
.
isLoading
)
{
return
return
}
}
if
(
!
tx
.
to
)
{
tx
.
to
=
traceHelper
.
contractCreationToken
(
'0'
)
}
this
.
setCompilationResult
(
this
.
opts
.
compilationResult
())
this
.
setCompilationResult
(
this
.
opts
.
compilationResult
())
console
.
log
(
'loading trace...'
)
console
.
log
(
'loading trace...'
)
this
.
tx
=
tx
this
.
tx
=
tx
...
@@ -137,6 +214,7 @@ Ethdebugger.prototype.debug = function (blockNumber, txIndex, tx) {
...
@@ -137,6 +214,7 @@ Ethdebugger.prototype.debug = function (blockNumber, txIndex, tx) {
if
(
self
.
breakpointManager
&&
self
.
breakpointManager
.
hasBreakpoint
())
{
if
(
self
.
breakpointManager
&&
self
.
breakpointManager
.
hasBreakpoint
())
{
self
.
breakpointManager
.
jumpNextBreakpoint
(
false
)
self
.
breakpointManager
.
jumpNextBreakpoint
(
false
)
}
}
self
.
storageResolver
=
new
StorageResolver
()
}
else
{
}
else
{
self
.
statusMessage
=
error
?
error
.
message
:
'Trace not loaded'
self
.
statusMessage
=
error
?
error
.
message
:
'Trace not loaded'
}
}
...
...
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