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
fa5b9ebc
Unverified
Commit
fa5b9ebc
authored
Aug 14, 2020
by
yann300
Committed by
GitHub
Aug 14, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #60 from ethereum/refactor_remix_debug1b
remove unneded if-elses; refactor; convert callbacks to promises
parents
e8e41586
297e3320
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
124 additions
and
139 deletions
+124
-139
VmDebugger.js
libs/remix-debug/src/debugger/VmDebugger.js
+18
-9
stepManager.js
libs/remix-debug/src/debugger/stepManager.js
+3
-3
breakpointManager.js
libs/remix-lib/src/code/breakpointManager.js
+11
-12
codeManager.js
libs/remix-lib/src/code/codeManager.js
+22
-31
codeResolver.js
libs/remix-lib/src/code/codeResolver.js
+11
-15
disassembler.js
libs/remix-lib/src/code/disassembler.js
+1
-2
traceHelper.js
libs/remix-lib/src/helpers/traceHelper.js
+1
-2
traceAnalyser.js
libs/remix-lib/src/trace/traceAnalyser.js
+2
-2
traceCache.js
libs/remix-lib/src/trace/traceCache.js
+2
-4
traceManager.js
libs/remix-lib/src/trace/traceManager.js
+38
-37
traceStepManager.js
libs/remix-lib/src/trace/traceStepManager.js
+3
-7
traceManager.js
libs/remix-lib/test/traceManager.js
+12
-15
No files found.
libs/remix-debug/src/debugger/VmDebugger.js
View file @
fa5b9ebc
...
@@ -117,21 +117,30 @@ class VmDebuggerLogic {
...
@@ -117,21 +117,30 @@ class VmDebuggerLogic {
this
.
event
.
trigger
(
'traceCurrentStepUpdate'
,
[
error
,
step
])
this
.
event
.
trigger
(
'traceCurrentStepUpdate'
,
[
error
,
step
])
})
})
this
.
_traceManager
.
getMemExpand
(
index
,
(
error
,
addmem
)
=>
{
try
{
this
.
event
.
trigger
(
'traceMemExpandUpdate'
,
[
error
,
addmem
])
const
addmem
=
this
.
_traceManager
.
getMemExpand
(
index
)
})
this
.
event
.
trigger
(
'traceMemExpandUpdate'
,
[
null
,
addmem
])
}
catch
(
error
)
{
this
.
event
.
trigger
(
'traceMemExpandUpdate'
,
[
error
])
}
this
.
_traceManager
.
getStepCost
(
index
,
(
error
,
gas
)
=>
{
try
{
this
.
event
.
trigger
(
'traceStepCostUpdate'
,
[
error
,
gas
])
const
gas
=
this
.
_traceManager
.
getStepCost
(
index
)
})
this
.
event
.
trigger
(
'traceStepCostUpdate'
,
[
null
,
gas
])
}
catch
(
error
)
{
this
.
event
.
trigger
(
'traceStepCostUpdate'
,
[
error
])
}
this
.
_traceManager
.
getCurrentCalledAddressAt
(
index
,
(
error
,
address
)
=>
{
this
.
_traceManager
.
getCurrentCalledAddressAt
(
index
,
(
error
,
address
)
=>
{
this
.
event
.
trigger
(
'traceCurrentCalledAddressAtUpdate'
,
[
error
,
address
])
this
.
event
.
trigger
(
'traceCurrentCalledAddressAtUpdate'
,
[
error
,
address
])
})
})
this
.
_traceManager
.
getRemainingGas
(
index
,
(
error
,
remaining
)
=>
{
try
{
this
.
event
.
trigger
(
'traceRemainingGasUpdate'
,
[
error
,
remaining
])
const
remaining
=
this
.
_traceManager
.
getRemainingGas
(
index
)
})
this
.
event
.
trigger
(
'traceRemainingGasUpdate'
,
[
null
,
remaining
])
}
catch
(
error
)
{
this
.
event
.
trigger
(
'traceRemainingGasUpdate'
,
[
error
])
}
this
.
_traceManager
.
getReturnValue
(
index
,
(
error
,
returnValue
)
=>
{
this
.
_traceManager
.
getReturnValue
(
index
,
(
error
,
returnValue
)
=>
{
if
(
error
)
{
if
(
error
)
{
...
...
libs/remix-debug/src/debugger/stepManager.js
View file @
fa5b9ebc
...
@@ -191,7 +191,9 @@ class DebuggerStepManager {
...
@@ -191,7 +191,9 @@ class DebuggerStepManager {
}
}
resolveToReducedTrace
(
value
,
incr
)
{
resolveToReducedTrace
(
value
,
incr
)
{
if
(
this
.
debugger
.
callTree
.
reducedTrace
.
length
)
{
if
(
!
this
.
debugger
.
callTree
.
reducedTrace
.
length
)
{
return
value
}
var
nextSource
=
util
.
findClosestIndex
(
value
,
this
.
debugger
.
callTree
.
reducedTrace
)
var
nextSource
=
util
.
findClosestIndex
(
value
,
this
.
debugger
.
callTree
.
reducedTrace
)
nextSource
=
nextSource
+
incr
nextSource
=
nextSource
+
incr
if
(
nextSource
<=
0
)
{
if
(
nextSource
<=
0
)
{
...
@@ -201,8 +203,6 @@ class DebuggerStepManager {
...
@@ -201,8 +203,6 @@ class DebuggerStepManager {
}
}
return
this
.
debugger
.
callTree
.
reducedTrace
[
nextSource
]
return
this
.
debugger
.
callTree
.
reducedTrace
[
nextSource
]
}
}
return
value
}
}
}
...
...
libs/remix-lib/src/code/breakpointManager.js
View file @
fa5b9ebc
...
@@ -67,12 +67,11 @@ class BreakpointManager {
...
@@ -67,12 +67,11 @@ class BreakpointManager {
(
sourceLocation
.
start
<=
previousSourceLocation
.
start
&&
(
sourceLocation
.
start
<=
previousSourceLocation
.
start
&&
sourceLocation
.
start
+
sourceLocation
.
length
>=
previousSourceLocation
.
start
+
previousSourceLocation
.
length
))
{
sourceLocation
.
start
+
sourceLocation
.
length
>=
previousSourceLocation
.
start
+
previousSourceLocation
.
length
))
{
return
false
return
false
}
else
{
}
self
.
jumpToCallback
(
currentStep
)
self
.
jumpToCallback
(
currentStep
)
self
.
event
.
trigger
(
'breakpointHit'
,
[
sourceLocation
,
currentStep
])
self
.
event
.
trigger
(
'breakpointHit'
,
[
sourceLocation
,
currentStep
])
return
true
return
true
}
}
}
let
sourceLocation
let
sourceLocation
let
previousSourceLocation
let
previousSourceLocation
...
@@ -97,24 +96,23 @@ class BreakpointManager {
...
@@ -97,24 +96,23 @@ class BreakpointManager {
this
.
previousLine
=
lineColumn
.
start
.
line
this
.
previousLine
=
lineColumn
.
start
.
line
if
(
this
.
hasBreakpointAtLine
(
sourceLocation
.
file
,
lineColumn
.
start
.
line
))
{
if
(
this
.
hasBreakpointAtLine
(
sourceLocation
.
file
,
lineColumn
.
start
.
line
))
{
lineHadBreakpoint
=
true
lineHadBreakpoint
=
true
if
(
direction
===
1
)
{
if
(
direction
===
1
&&
hitLine
(
currentStep
,
sourceLocation
,
previousSourceLocation
,
this
))
{
if
(
hitLine
(
currentStep
,
sourceLocation
,
previousSourceLocation
,
this
))
{
return
return
}
}
}
}
}
}
}
currentStep
+=
direction
currentStep
+=
direction
}
}
this
.
event
.
trigger
(
'NoBreakpointHit'
,
[])
this
.
event
.
trigger
(
'NoBreakpointHit'
,
[])
if
(
defaultToLimit
)
{
if
(
!
defaultToLimit
)
{
return
}
if
(
direction
===
-
1
)
{
if
(
direction
===
-
1
)
{
this
.
jumpToCallback
(
0
)
this
.
jumpToCallback
(
0
)
}
else
if
(
direction
===
1
)
{
}
else
if
(
direction
===
1
)
{
this
.
jumpToCallback
(
this
.
debugger
.
traceManager
.
trace
.
length
-
1
)
this
.
jumpToCallback
(
this
.
debugger
.
traceManager
.
trace
.
length
-
1
)
}
}
}
}
}
/**
/**
* check the given pair fileIndex/line against registered breakpoints
* check the given pair fileIndex/line against registered breakpoints
...
@@ -125,7 +123,9 @@ class BreakpointManager {
...
@@ -125,7 +123,9 @@ class BreakpointManager {
*/
*/
hasBreakpointAtLine
(
fileIndex
,
line
)
{
hasBreakpointAtLine
(
fileIndex
,
line
)
{
const
filename
=
this
.
debugger
.
solidityProxy
.
fileNameFromIndex
(
fileIndex
)
const
filename
=
this
.
debugger
.
solidityProxy
.
fileNameFromIndex
(
fileIndex
)
if
(
filename
&&
this
.
breakpoints
[
filename
])
{
if
(
!
(
filename
&&
this
.
breakpoints
[
filename
]))
{
return
false
}
const
sources
=
this
.
breakpoints
[
filename
]
const
sources
=
this
.
breakpoints
[
filename
]
for
(
let
k
in
sources
)
{
for
(
let
k
in
sources
)
{
const
source
=
sources
[
k
]
const
source
=
sources
[
k
]
...
@@ -134,8 +134,6 @@ class BreakpointManager {
...
@@ -134,8 +134,6 @@ class BreakpointManager {
}
}
}
}
}
}
return
false
}
/**
/**
* return true if current manager has breakpoint
* return true if current manager has breakpoint
...
@@ -170,8 +168,10 @@ class BreakpointManager {
...
@@ -170,8 +168,10 @@ class BreakpointManager {
* @param {Object} sourceLocation - position of the breakpoint { file: '<file index>', row: '<line number' }
* @param {Object} sourceLocation - position of the breakpoint { file: '<file index>', row: '<line number' }
*/
*/
remove
(
sourceLocation
)
{
remove
(
sourceLocation
)
{
if
(
this
.
breakpoints
[
sourceLocation
.
fileName
])
{
var
sources
=
this
.
breakpoints
[
sourceLocation
.
fileName
]
var
sources
=
this
.
breakpoints
[
sourceLocation
.
fileName
]
if
(
!
sources
)
{
return
}
for
(
let
k
in
sources
)
{
for
(
let
k
in
sources
)
{
const
source
=
sources
[
k
]
const
source
=
sources
[
k
]
if
(
sourceLocation
.
row
===
source
.
row
)
{
if
(
sourceLocation
.
row
===
source
.
row
)
{
...
@@ -181,7 +181,6 @@ class BreakpointManager {
...
@@ -181,7 +181,6 @@ class BreakpointManager {
}
}
}
}
}
}
}
}
}
module
.
exports
=
BreakpointManager
module
.
exports
=
BreakpointManager
libs/remix-lib/src/code/codeManager.js
View file @
fa5b9ebc
...
@@ -37,16 +37,14 @@ CodeManager.prototype.resolveStep = function (stepIndex, tx) {
...
@@ -37,16 +37,14 @@ CodeManager.prototype.resolveStep = function (stepIndex, tx) {
if
(
stepIndex
<
0
)
return
if
(
stepIndex
<
0
)
return
this
.
event
.
trigger
(
'resolvingStep'
)
this
.
event
.
trigger
(
'resolvingStep'
)
if
(
stepIndex
===
0
)
{
if
(
stepIndex
===
0
)
{
retrieveCodeAndTrigger
(
this
,
tx
.
to
,
stepIndex
,
tx
)
ret
urn
ret
rieveCodeAndTrigger
(
this
,
tx
.
to
,
stepIndex
,
tx
)
}
else
{
}
this
.
traceManager
.
getCurrentCalledAddressAt
(
stepIndex
,
(
error
,
address
)
=>
{
this
.
traceManager
.
getCurrentCalledAddressAt
(
stepIndex
,
(
error
,
address
)
=>
{
if
(
error
)
{
if
(
error
)
{
console
.
log
(
error
)
return
console
.
log
(
error
)
}
else
{
retrieveCodeAndTrigger
(
this
,
address
,
stepIndex
,
tx
)
}
}
retrieveCodeAndTrigger
(
this
,
address
,
stepIndex
,
tx
)
})
})
}
}
}
/**
/**
...
@@ -56,23 +54,21 @@ CodeManager.prototype.resolveStep = function (stepIndex, tx) {
...
@@ -56,23 +54,21 @@ CodeManager.prototype.resolveStep = function (stepIndex, tx) {
* @param {Function} cb - callback function, return the bytecode
* @param {Function} cb - callback function, return the bytecode
*/
*/
CodeManager
.
prototype
.
getCode
=
function
(
address
,
cb
)
{
CodeManager
.
prototype
.
getCode
=
function
(
address
,
cb
)
{
if
(
traceHelper
.
isContractCreation
(
address
))
{
if
(
!
traceHelper
.
isContractCreation
(
address
))
{
return
this
.
codeResolver
.
resolveCode
(
address
).
then
((
code
)
=>
{
cb
(
null
,
code
)
})
}
var
codes
=
this
.
codeResolver
.
getExecutingCodeFromCache
(
address
)
var
codes
=
this
.
codeResolver
.
getExecutingCodeFromCache
(
address
)
if
(
!
codes
)
{
if
(
codes
)
{
return
cb
(
null
,
codes
)
}
this
.
traceManager
.
getContractCreationCode
(
address
,
(
error
,
hexCode
)
=>
{
this
.
traceManager
.
getContractCreationCode
(
address
,
(
error
,
hexCode
)
=>
{
if
(
!
error
)
{
if
(
!
error
)
{
codes
=
this
.
codeResolver
.
cacheExecutingCode
(
address
,
hexCode
)
codes
=
this
.
codeResolver
.
cacheExecutingCode
(
address
,
hexCode
)
cb
(
null
,
codes
)
cb
(
null
,
codes
)
}
}
})
})
}
else
{
cb
(
null
,
codes
)
}
}
else
{
this
.
codeResolver
.
resolveCode
(
address
,
(
address
,
code
)
=>
{
cb
(
null
,
code
)
})
}
}
}
/**
/**
...
@@ -88,16 +84,14 @@ CodeManager.prototype.getFunctionFromStep = function (stepIndex, sourceMap, ast)
...
@@ -88,16 +84,14 @@ CodeManager.prototype.getFunctionFromStep = function (stepIndex, sourceMap, ast)
if
(
error
)
{
if
(
error
)
{
console
.
log
(
error
)
console
.
log
(
error
)
return
{
error
:
'Cannot retrieve current address for '
+
stepIndex
}
return
{
error
:
'Cannot retrieve current address for '
+
stepIndex
}
}
else
{
}
this
.
traceManager
.
getCurrentPC
(
stepIndex
,
(
error
,
pc
)
=>
{
this
.
traceManager
.
getCurrentPC
(
stepIndex
,
(
error
,
pc
)
=>
{
if
(
error
)
{
if
(
error
)
{
console
.
log
(
error
)
console
.
log
(
error
)
return
{
error
:
'Cannot retrieve current PC for '
+
stepIndex
}
return
{
error
:
'Cannot retrieve current PC for '
+
stepIndex
}
}
else
{
return
this
.
getFunctionFromPC
(
address
,
pc
,
sourceMap
,
ast
)
}
}
return
this
.
getFunctionFromPC
(
address
,
pc
,
sourceMap
,
ast
)
})
})
}
})
})
}
}
...
@@ -112,11 +106,10 @@ CodeManager.prototype.getInstructionIndex = function (address, step, callback) {
...
@@ -112,11 +106,10 @@ CodeManager.prototype.getInstructionIndex = function (address, step, callback) {
this
.
traceManager
.
getCurrentPC
(
step
,
(
error
,
pc
)
=>
{
this
.
traceManager
.
getCurrentPC
(
step
,
(
error
,
pc
)
=>
{
if
(
error
)
{
if
(
error
)
{
console
.
log
(
error
)
console
.
log
(
error
)
callback
(
'Cannot retrieve current PC for '
+
step
,
null
)
return
callback
(
'Cannot retrieve current PC for '
+
step
,
null
)
}
else
{
}
const
itemIndex
=
this
.
codeResolver
.
getInstructionIndex
(
address
,
pc
)
const
itemIndex
=
this
.
codeResolver
.
getInstructionIndex
(
address
,
pc
)
callback
(
null
,
itemIndex
)
callback
(
null
,
itemIndex
)
}
})
})
}
}
...
@@ -136,21 +129,19 @@ CodeManager.prototype.getFunctionFromPC = function (address, pc, sourceMap, ast)
...
@@ -136,21 +129,19 @@ CodeManager.prototype.getFunctionFromPC = function (address, pc, sourceMap, ast)
function
retrieveCodeAndTrigger
(
codeMananger
,
address
,
stepIndex
,
tx
)
{
function
retrieveCodeAndTrigger
(
codeMananger
,
address
,
stepIndex
,
tx
)
{
codeMananger
.
getCode
(
address
,
(
error
,
result
)
=>
{
codeMananger
.
getCode
(
address
,
(
error
,
result
)
=>
{
if
(
!
error
)
{
if
(
error
)
{
retrieveIndexAndTrigger
(
codeMananger
,
address
,
stepIndex
,
result
.
instructions
)
return
console
.
log
(
error
)
}
else
{
console
.
log
(
error
)
}
}
retrieveIndexAndTrigger
(
codeMananger
,
address
,
stepIndex
,
result
.
instructions
)
})
})
}
}
function
retrieveIndexAndTrigger
(
codeMananger
,
address
,
step
,
code
)
{
function
retrieveIndexAndTrigger
(
codeMananger
,
address
,
step
,
code
)
{
codeMananger
.
getInstructionIndex
(
address
,
step
,
(
error
,
result
)
=>
{
codeMananger
.
getInstructionIndex
(
address
,
step
,
(
error
,
result
)
=>
{
if
(
!
error
)
{
if
(
error
)
{
codeMananger
.
event
.
trigger
(
'changed'
,
[
code
,
address
,
result
])
return
console
.
log
(
error
)
}
else
{
console
.
log
(
error
)
}
}
codeMananger
.
event
.
trigger
(
'changed'
,
[
code
,
address
,
result
])
})
})
}
}
...
...
libs/remix-lib/src/code/codeResolver.js
View file @
fa5b9ebc
...
@@ -15,24 +15,20 @@ CodeResolver.prototype.clear = function () {
...
@@ -15,24 +15,20 @@ CodeResolver.prototype.clear = function () {
this
.
instructionsIndexByBytesOffset
=
{}
this
.
instructionsIndexByBytesOffset
=
{}
}
}
CodeResolver
.
prototype
.
resolveCode
=
function
(
address
,
callBack
)
{
CodeResolver
.
prototype
.
resolveCode
=
async
function
(
address
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
cache
=
this
.
getExecutingCodeFromCache
(
address
)
const
cache
=
this
.
getExecutingCodeFromCache
(
address
)
if
(
cache
)
{
if
(
cache
)
{
return
callBack
(
address
,
cache
)
return
resolve
(
cache
)
}
}
this
.
loadCode
(
address
,
(
code
)
=>
{
this
.
web3
.
eth
.
getCode
(
address
,
(
error
,
code
)
=>
{
callBack
(
address
,
this
.
cacheExecutingCode
(
address
,
code
))
})
}
CodeResolver
.
prototype
.
loadCode
=
function
(
address
,
callback
)
{
this
.
web3
.
eth
.
getCode
(
address
,
(
error
,
result
)
=>
{
if
(
error
)
{
if
(
error
)
{
console
.
log
(
error
)
// return console.log(error)
}
else
{
return
reject
(
error
)
callback
(
result
)
}
}
return
resolve
(
this
.
cacheExecutingCode
(
address
,
code
))
})
})
})
}
}
...
@@ -53,14 +49,14 @@ CodeResolver.prototype.formatCode = function (hexCode) {
...
@@ -53,14 +49,14 @@ CodeResolver.prototype.formatCode = function (hexCode) {
}
}
CodeResolver
.
prototype
.
getExecutingCodeFromCache
=
function
(
address
)
{
CodeResolver
.
prototype
.
getExecutingCodeFromCache
=
function
(
address
)
{
if
(
this
.
instructionsByAddress
[
address
])
{
if
(
!
this
.
instructionsByAddress
[
address
])
{
return
null
}
return
{
return
{
instructions
:
this
.
instructionsByAddress
[
address
],
instructions
:
this
.
instructionsByAddress
[
address
],
instructionsIndexByBytesOffset
:
this
.
instructionsIndexByBytesOffset
[
address
],
instructionsIndexByBytesOffset
:
this
.
instructionsIndexByBytesOffset
[
address
],
bytecode
:
this
.
bytecodeByAddress
[
address
]
bytecode
:
this
.
bytecodeByAddress
[
address
]
}
}
}
return
null
}
}
CodeResolver
.
prototype
.
getInstructionIndex
=
function
(
address
,
pc
)
{
CodeResolver
.
prototype
.
getInstructionIndex
=
function
(
address
,
pc
)
{
...
...
libs/remix-lib/src/code/disassembler.js
View file @
fa5b9ebc
...
@@ -41,9 +41,8 @@ const toString = function (expr) {
...
@@ -41,9 +41,8 @@ const toString = function (expr) {
return
expr
.
label
+
':'
return
expr
.
label
+
':'
}
else
if
(
expr
.
args
)
{
}
else
if
(
expr
.
args
)
{
return
expr
.
name
.
toLowerCase
()
+
'('
+
expr
.
args
.
reverse
().
map
(
toString
).
join
(
', '
)
+
')'
return
expr
.
name
.
toLowerCase
()
+
'('
+
expr
.
args
.
reverse
().
map
(
toString
).
join
(
', '
)
+
')'
}
else
{
return
expr
.
name
.
toLowerCase
()
}
}
return
expr
.
name
.
toLowerCase
()
}
}
const
disassemble
=
function
(
input
)
{
const
disassemble
=
function
(
input
)
{
...
...
libs/remix-lib/src/helpers/traceHelper.js
View file @
fa5b9ebc
...
@@ -55,9 +55,8 @@ module.exports = {
...
@@ -55,9 +55,8 @@ module.exports = {
const
step
=
trace
[
index
]
const
step
=
trace
[
index
]
if
(
this
.
isCallInstruction
(
step
))
{
if
(
this
.
isCallInstruction
(
step
))
{
return
index
+
1
<
trace
.
length
&&
trace
[
index
+
1
].
stack
.
length
!==
0
return
index
+
1
<
trace
.
length
&&
trace
[
index
+
1
].
stack
.
length
!==
0
}
else
{
return
false
}
}
return
false
},
},
contractCreationToken
:
function
(
index
)
{
contractCreationToken
:
function
(
index
)
{
...
...
libs/remix-lib/src/trace/traceAnalyser.js
View file @
fa5b9ebc
...
@@ -6,7 +6,7 @@ function TraceAnalyser (_cache) {
...
@@ -6,7 +6,7 @@ function TraceAnalyser (_cache) {
this
.
trace
=
null
this
.
trace
=
null
}
}
TraceAnalyser
.
prototype
.
analyse
=
function
(
trace
,
tx
,
callback
)
{
TraceAnalyser
.
prototype
.
analyse
=
function
(
trace
,
tx
)
{
this
.
trace
=
trace
this
.
trace
=
trace
this
.
traceCache
.
pushStoreChanges
(
0
,
tx
.
to
)
this
.
traceCache
.
pushStoreChanges
(
0
,
tx
.
to
)
let
context
=
{
let
context
=
{
...
@@ -27,7 +27,7 @@ TraceAnalyser.prototype.analyse = function (trace, tx, callback) {
...
@@ -27,7 +27,7 @@ TraceAnalyser.prototype.analyse = function (trace, tx, callback) {
context
=
this
.
buildStorage
(
k
,
step
,
context
)
context
=
this
.
buildStorage
(
k
,
step
,
context
)
this
.
buildReturnValues
(
k
,
step
)
this
.
buildReturnValues
(
k
,
step
)
}
}
callback
(
null
,
true
)
return
true
}
}
TraceAnalyser
.
prototype
.
buildReturnValues
=
function
(
index
,
step
)
{
TraceAnalyser
.
prototype
.
buildReturnValues
=
function
(
index
,
step
)
{
...
...
libs/remix-lib/src/trace/traceCache.js
View file @
fa5b9ebc
...
@@ -39,16 +39,15 @@ TraceCache.prototype.pushMemoryChanges = function (value) {
...
@@ -39,16 +39,15 @@ TraceCache.prototype.pushMemoryChanges = function (value) {
// in the vm/geth/eth. TODO add the error property (with about the error in all clients)
// in the vm/geth/eth. TODO add the error property (with about the error in all clients)
TraceCache
.
prototype
.
pushCall
=
function
(
step
,
index
,
address
,
callStack
,
reverted
)
{
TraceCache
.
prototype
.
pushCall
=
function
(
step
,
index
,
address
,
callStack
,
reverted
)
{
let
validReturnStep
=
step
.
op
===
'RETURN'
||
step
.
op
===
'STOP'
let
validReturnStep
=
step
.
op
===
'RETURN'
||
step
.
op
===
'STOP'
if
(
validReturnStep
||
reverted
)
{
if
((
validReturnStep
||
reverted
)
&&
(
this
.
currentCall
))
{
if
(
this
.
currentCall
)
{
this
.
currentCall
.
call
.
return
=
index
-
1
this
.
currentCall
.
call
.
return
=
index
-
1
if
(
!
validReturnStep
)
{
if
(
!
validReturnStep
)
{
this
.
currentCall
.
call
.
reverted
=
reverted
this
.
currentCall
.
call
.
reverted
=
reverted
}
}
var
parent
=
this
.
currentCall
.
parent
var
parent
=
this
.
currentCall
.
parent
this
.
currentCall
=
parent
?
{
call
:
parent
.
call
,
parent
:
parent
.
parent
}
:
null
this
.
currentCall
=
parent
?
{
call
:
parent
.
call
,
parent
:
parent
.
parent
}
:
null
return
}
}
}
else
{
let
call
=
{
let
call
=
{
op
:
step
.
op
,
op
:
step
.
op
,
address
:
address
,
address
:
address
,
...
@@ -63,7 +62,6 @@ TraceCache.prototype.pushCall = function (step, index, address, callStack, rever
...
@@ -63,7 +62,6 @@ TraceCache.prototype.pushCall = function (step, index, address, callStack, rever
this
.
callsTree
=
{
call
:
call
}
this
.
callsTree
=
{
call
:
call
}
}
}
this
.
currentCall
=
{
call
:
call
,
parent
:
this
.
currentCall
}
this
.
currentCall
=
{
call
:
call
,
parent
:
this
.
currentCall
}
}
}
}
TraceCache
.
prototype
.
pushReturnValue
=
function
(
step
,
value
)
{
TraceCache
.
prototype
.
pushReturnValue
=
function
(
step
,
value
)
{
...
...
libs/remix-lib/src/trace/traceManager.js
View file @
fa5b9ebc
'use strict'
'use strict'
const
TraceAnalyser
=
require
(
'./traceAnalyser'
)
const
TraceAnalyser
=
require
(
'./traceAnalyser'
)
const
TraceRetriever
=
require
(
'./traceRetriever'
)
const
TraceCache
=
require
(
'./traceCache'
)
const
TraceCache
=
require
(
'./traceCache'
)
const
TraceStepManager
=
require
(
'./traceStepManager'
)
const
TraceStepManager
=
require
(
'./traceStepManager'
)
...
@@ -13,43 +12,49 @@ function TraceManager (options) {
...
@@ -13,43 +12,49 @@ function TraceManager (options) {
this
.
trace
=
null
this
.
trace
=
null
this
.
traceCache
=
new
TraceCache
()
this
.
traceCache
=
new
TraceCache
()
this
.
traceAnalyser
=
new
TraceAnalyser
(
this
.
traceCache
)
this
.
traceAnalyser
=
new
TraceAnalyser
(
this
.
traceCache
)
this
.
traceRetriever
=
new
TraceRetriever
({
web3
:
this
.
web3
})
this
.
traceStepManager
=
new
TraceStepManager
(
this
.
traceAnalyser
)
this
.
traceStepManager
=
new
TraceStepManager
(
this
.
traceAnalyser
)
this
.
tx
this
.
tx
}
}
// init section
// init section
TraceManager
.
prototype
.
resolveTrace
=
function
(
tx
,
callback
)
{
TraceManager
.
prototype
.
resolveTrace
=
async
function
(
tx
,
callback
)
{
this
.
tx
=
tx
this
.
tx
=
tx
this
.
init
()
this
.
init
()
if
(
!
this
.
web3
)
callback
(
'web3 not loaded'
,
false
)
if
(
!
this
.
web3
)
callback
(
'web3 not loaded'
,
false
)
this
.
isLoading
=
true
this
.
isLoading
=
true
var
self
=
this
try
{
this
.
traceRetriever
.
getTrace
(
tx
.
hash
,
(
error
,
result
)
=>
{
const
result
=
await
this
.
getTrace
(
tx
.
hash
)
if
(
error
)
{
console
.
log
(
error
)
self
.
isLoading
=
false
callback
(
error
,
false
)
}
else
{
if
(
result
.
structLogs
.
length
>
0
)
{
if
(
result
.
structLogs
.
length
>
0
)
{
self
.
trace
=
result
.
structLogs
this
.
trace
=
result
.
structLogs
self
.
traceAnalyser
.
analyse
(
result
.
structLogs
,
tx
,
function
(
error
,
result
)
{
if
(
error
)
{
this
.
traceAnalyser
.
analyse
(
result
.
structLogs
,
tx
)
self
.
isLoading
=
false
this
.
isLoading
=
false
console
.
log
(
error
)
return
callback
(
null
,
true
)
callback
(
error
,
false
)
}
else
{
self
.
isLoading
=
false
callback
(
null
,
true
)
}
}
})
}
else
{
var
mes
=
tx
.
hash
+
' is not a contract invocation or contract creation.'
var
mes
=
tx
.
hash
+
' is not a contract invocation or contract creation.'
console
.
log
(
mes
)
console
.
log
(
mes
)
self
.
isLoading
=
false
this
.
isLoading
=
false
callback
(
mes
,
false
)
callback
(
mes
,
false
)
}
catch
(
error
)
{
console
.
log
(
error
)
this
.
isLoading
=
false
callback
(
error
,
false
)
}
}
}
TraceManager
.
prototype
.
getTrace
=
function
(
txHash
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
options
=
{
disableStorage
:
true
,
disableMemory
:
false
,
disableStack
:
false
,
fullStorage
:
false
}
}
this
.
web3
.
debug
.
traceTransaction
(
txHash
,
options
,
function
(
error
,
result
)
{
if
(
error
)
return
reject
(
error
)
resolve
(
result
)
})
})
})
}
}
...
@@ -206,28 +211,24 @@ TraceManager.prototype.getCurrentStep = function (stepIndex, callback) {
...
@@ -206,28 +211,24 @@ TraceManager.prototype.getCurrentStep = function (stepIndex, callback) {
callback
(
null
,
this
.
traceCache
.
steps
[
stepIndex
])
callback
(
null
,
this
.
traceCache
.
steps
[
stepIndex
])
}
}
TraceManager
.
prototype
.
getMemExpand
=
function
(
stepIndex
,
callback
)
{
TraceManager
.
prototype
.
getMemExpand
=
function
(
stepIndex
)
{
const
check
=
this
.
checkRequestedStep
(
stepIndex
)
return
(
this
.
getStepProperty
(
stepIndex
,
'memexpand'
)
||
''
)
if
(
check
)
{
return
callback
(
check
,
null
)
}
callback
(
null
,
this
.
trace
[
stepIndex
].
memexpand
?
this
.
trace
[
stepIndex
].
memexpand
:
''
)
}
}
TraceManager
.
prototype
.
getStepCost
=
function
(
stepIndex
,
callback
)
{
TraceManager
.
prototype
.
getStepCost
=
function
(
stepIndex
)
{
const
check
=
this
.
checkRequestedStep
(
stepIndex
)
return
this
.
getStepProperty
(
stepIndex
,
'gasCost'
)
if
(
check
)
{
return
callback
(
check
,
null
)
}
callback
(
null
,
this
.
trace
[
stepIndex
].
gasCost
)
}
}
TraceManager
.
prototype
.
getRemainingGas
=
function
(
stepIndex
,
callback
)
{
TraceManager
.
prototype
.
getRemainingGas
=
function
(
stepIndex
)
{
return
this
.
getStepProperty
(
stepIndex
,
'gas'
)
}
TraceManager
.
prototype
.
getStepProperty
=
function
(
stepIndex
,
property
)
{
const
check
=
this
.
checkRequestedStep
(
stepIndex
)
const
check
=
this
.
checkRequestedStep
(
stepIndex
)
if
(
check
)
{
if
(
check
)
{
return
callback
(
check
,
null
)
throw
new
Error
(
check
)
}
}
callback
(
null
,
this
.
trace
[
stepIndex
].
gas
)
return
this
.
trace
[
stepIndex
][
property
]
}
}
TraceManager
.
prototype
.
isCreationStep
=
function
(
stepIndex
)
{
TraceManager
.
prototype
.
isCreationStep
=
function
(
stepIndex
)
{
...
...
libs/remix-lib/src/trace/traceStepManager.js
View file @
fa5b9ebc
...
@@ -21,18 +21,16 @@ TraceStepManager.prototype.findStepOverBack = function (currentStep) {
...
@@ -21,18 +21,16 @@ TraceStepManager.prototype.findStepOverBack = function (currentStep) {
if
(
this
.
isReturnInstruction
(
currentStep
))
{
if
(
this
.
isReturnInstruction
(
currentStep
))
{
const
call
=
util
.
findCall
(
currentStep
,
this
.
traceAnalyser
.
traceCache
.
callsTree
.
call
)
const
call
=
util
.
findCall
(
currentStep
,
this
.
traceAnalyser
.
traceCache
.
callsTree
.
call
)
return
call
.
start
>
0
?
call
.
start
-
1
:
0
return
call
.
start
>
0
?
call
.
start
-
1
:
0
}
else
{
return
currentStep
>
0
?
currentStep
-
1
:
0
}
}
return
currentStep
>
0
?
currentStep
-
1
:
0
}
}
TraceStepManager
.
prototype
.
findStepOverForward
=
function
(
currentStep
)
{
TraceStepManager
.
prototype
.
findStepOverForward
=
function
(
currentStep
)
{
if
(
this
.
isCallInstruction
(
currentStep
))
{
if
(
this
.
isCallInstruction
(
currentStep
))
{
const
call
=
util
.
findCall
(
currentStep
+
1
,
this
.
traceAnalyser
.
traceCache
.
callsTree
.
call
)
const
call
=
util
.
findCall
(
currentStep
+
1
,
this
.
traceAnalyser
.
traceCache
.
callsTree
.
call
)
return
call
.
return
+
1
<
this
.
traceAnalyser
.
trace
.
length
?
call
.
return
+
1
:
this
.
traceAnalyser
.
trace
.
length
-
1
return
call
.
return
+
1
<
this
.
traceAnalyser
.
trace
.
length
?
call
.
return
+
1
:
this
.
traceAnalyser
.
trace
.
length
-
1
}
else
{
return
this
.
traceAnalyser
.
trace
.
length
>=
currentStep
+
1
?
currentStep
+
1
:
currentStep
}
}
return
this
.
traceAnalyser
.
trace
.
length
>=
currentStep
+
1
?
currentStep
+
1
:
currentStep
}
}
TraceStepManager
.
prototype
.
findNextCall
=
function
(
currentStep
)
{
TraceStepManager
.
prototype
.
findNextCall
=
function
(
currentStep
)
{
...
@@ -42,12 +40,10 @@ TraceStepManager.prototype.findNextCall = function (currentStep) {
...
@@ -42,12 +40,10 @@ TraceStepManager.prototype.findNextCall = function (currentStep) {
var
callStart
=
util
.
findLowerBound
(
currentStep
,
subCalls
)
+
1
var
callStart
=
util
.
findLowerBound
(
currentStep
,
subCalls
)
+
1
if
(
subCalls
.
length
>
callStart
)
{
if
(
subCalls
.
length
>
callStart
)
{
return
subCalls
[
callStart
]
-
1
return
subCalls
[
callStart
]
-
1
}
else
{
return
currentStep
}
}
}
else
{
return
currentStep
return
currentStep
}
}
return
currentStep
}
}
TraceStepManager
.
prototype
.
findStepOut
=
function
(
currentStep
)
{
TraceStepManager
.
prototype
.
findStepOut
=
function
(
currentStep
)
{
...
...
libs/remix-lib/test/traceManager.js
View file @
fa5b9ebc
...
@@ -239,40 +239,37 @@ tape('TraceManager', function (t) {
...
@@ -239,40 +239,37 @@ tape('TraceManager', function (t) {
})
})
t
.
test
(
'TraceManager.getMemExpand'
,
function
(
st
)
{
t
.
test
(
'TraceManager.getMemExpand'
,
function
(
st
)
{
traceManager
.
getMemExpand
(
2
,
function
(
error
,
result
)
{
try
{
const
result
=
traceManager
.
getMemExpand
(
2
)
console
.
log
(
result
)
console
.
log
(
result
)
if
(
error
)
{
st
.
fail
(
error
)
}
else
{
st
.
ok
(
result
===
'3'
)
st
.
ok
(
result
===
'3'
)
st
.
end
()
st
.
end
()
}
catch
(
error
)
{
st
.
fail
(
error
)
}
}
})
})
})
t
.
test
(
'TraceManager.getStepCost'
,
function
(
st
)
{
t
.
test
(
'TraceManager.getStepCost'
,
function
(
st
)
{
traceManager
.
getStepCost
(
34
,
function
(
error
,
result
)
{
try
{
const
result
=
traceManager
.
getStepCost
(
23
)
console
.
log
(
result
)
console
.
log
(
result
)
if
(
error
)
{
st
.
fail
(
error
)
}
else
{
st
.
ok
(
result
===
'3'
)
st
.
ok
(
result
===
'3'
)
st
.
end
()
st
.
end
()
}
catch
(
error
)
{
st
.
fail
(
error
)
}
}
})
})
})
t
.
test
(
'TraceManager.getRemainingGas'
,
function
(
st
)
{
t
.
test
(
'TraceManager.getRemainingGas'
,
function
(
st
)
{
traceManager
.
getRemainingGas
(
55
,
function
(
error
,
result
)
{
try
{
const
result
=
traceManager
.
getRemainingGas
(
55
)
console
.
log
(
result
)
console
.
log
(
result
)
if
(
error
)
{
st
.
fail
(
error
)
}
else
{
st
.
ok
(
result
===
'79306'
)
st
.
ok
(
result
===
'79306'
)
st
.
end
()
st
.
end
()
}
catch
(
error
)
{
st
.
fail
(
error
)
}
}
})
})
})
t
.
test
(
'TraceManager.findStepOverBack'
,
function
(
st
)
{
t
.
test
(
'TraceManager.findStepOverBack'
,
function
(
st
)
{
const
result
=
traceManager
.
findStepOverBack
(
116
)
const
result
=
traceManager
.
findStepOverBack
(
116
)
...
...
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