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
80b87ef2
Commit
80b87ef2
authored
Dec 14, 2020
by
aniket-engg
Committed by
Aniket
Dec 21, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
traceManager and traceStepManager updated
parent
d2161740
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
97 additions
and
86 deletions
+97
-86
traceManager.ts
libs/remix-debug/src/trace/traceManager.ts
+78
-70
traceStepManager.ts
libs/remix-debug/src/trace/traceStepManager.ts
+19
-16
No files found.
libs/remix-debug/src/trace/traceManager.ts
View file @
80b87ef2
...
...
@@ -7,18 +7,27 @@ const traceHelper = require('./traceHelper')
const
remixLib
=
require
(
'@remix-project/remix-lib'
)
const
util
=
remixLib
.
util
function
TraceManager
(
options
)
{
export
class
TraceManager
{
web3
isLoading
:
boolean
trace
traceCache
traceAnalyser
traceStepManager
tx
constructor
(
options
)
{
this
.
web3
=
options
.
web3
this
.
isLoading
=
false
this
.
trace
=
null
this
.
traceCache
=
new
TraceCache
()
this
.
traceAnalyser
=
new
TraceAnalyser
(
this
.
traceCache
)
this
.
traceStepManager
=
new
TraceStepManager
(
this
.
traceAnalyser
)
this
.
tx
}
}
// init section
TraceManager
.
prototype
.
resolveTrace
=
async
function
(
tx
)
{
// init section
async
resolveTrace
(
tx
)
{
this
.
tx
=
tx
this
.
init
()
if
(
!
this
.
web3
)
throw
new
Error
(
'web3 not loaded'
)
...
...
@@ -26,10 +35,10 @@ TraceManager.prototype.resolveTrace = async function (tx) {
try
{
const
result
=
await
this
.
getTrace
(
tx
.
hash
)
if
(
result
.
structLogs
.
length
>
0
)
{
this
.
trace
=
result
.
structLogs
if
(
result
[
'structLogs'
]
.
length
>
0
)
{
this
.
trace
=
result
[
'structLogs'
]
this
.
traceAnalyser
.
analyse
(
result
.
structLogs
,
tx
)
this
.
traceAnalyser
.
analyse
(
result
[
'structLogs'
]
,
tx
)
this
.
isLoading
=
false
return
true
}
...
...
@@ -42,9 +51,9 @@ TraceManager.prototype.resolveTrace = async function (tx) {
this
.
isLoading
=
false
throw
new
Error
(
error
)
}
}
}
TraceManager
.
prototype
.
getTrace
=
function
(
txHash
)
{
getTrace
(
txHash
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
options
=
{
disableStorage
:
true
,
...
...
@@ -57,39 +66,39 @@ TraceManager.prototype.getTrace = function (txHash) {
resolve
(
result
)
})
})
}
}
TraceManager
.
prototype
.
init
=
function
()
{
init
()
{
this
.
trace
=
null
this
.
traceCache
.
init
()
}
}
// API section
TraceManager
.
prototype
.
inRange
=
function
(
step
)
{
// API section
inRange
(
step
)
{
return
this
.
isLoaded
()
&&
step
>=
0
&&
step
<
this
.
trace
.
length
}
}
TraceManager
.
prototype
.
isLoaded
=
function
()
{
isLoaded
()
{
return
!
this
.
isLoading
&&
this
.
trace
!==
null
}
}
TraceManager
.
prototype
.
getLength
=
function
(
callback
)
{
getLength
(
callback
)
{
if
(
!
this
.
trace
)
{
callback
(
'no trace available'
,
null
)
}
else
{
callback
(
null
,
this
.
trace
.
length
)
}
}
}
TraceManager
.
prototype
.
accumulateStorageChanges
=
function
(
index
,
address
,
storageOrigin
)
{
accumulateStorageChanges
(
index
,
address
,
storageOrigin
)
{
return
this
.
traceCache
.
accumulateStorageChanges
(
index
,
address
,
storageOrigin
)
}
}
TraceManager
.
prototype
.
getAddresses
=
function
()
{
getAddresses
()
{
return
this
.
traceCache
.
addresses
}
}
TraceManager
.
prototype
.
getCallDataAt
=
function
(
stepIndex
)
{
getCallDataAt
(
stepIndex
)
{
try
{
this
.
checkRequestedStep
(
stepIndex
)
}
catch
(
check
)
{
...
...
@@ -100,9 +109,9 @@ TraceManager.prototype.getCallDataAt = function (stepIndex) {
throw
new
Error
(
'no calldata found'
)
}
return
[
this
.
traceCache
.
callsData
[
callDataChange
]]
}
}
TraceManager
.
prototype
.
buildCallPath
=
async
function
(
stepIndex
)
{
async
buildCallPath
(
stepIndex
)
{
try
{
this
.
checkRequestedStep
(
stepIndex
)
}
catch
(
check
)
{
...
...
@@ -111,9 +120,9 @@ TraceManager.prototype.buildCallPath = async function (stepIndex) {
const
callsPath
=
util
.
buildCallPath
(
stepIndex
,
this
.
traceCache
.
callsTree
.
call
)
if
(
callsPath
===
null
)
throw
new
Error
(
'no call path built'
)
return
callsPath
}
}
TraceManager
.
prototype
.
getCallStackAt
=
function
(
stepIndex
)
{
getCallStackAt
(
stepIndex
)
{
try
{
this
.
checkRequestedStep
(
stepIndex
)
}
catch
(
check
)
{
...
...
@@ -124,9 +133,9 @@ TraceManager.prototype.getCallStackAt = function (stepIndex) {
throw
new
Error
(
'no callstack found'
)
}
return
call
.
callStack
}
}
TraceManager
.
prototype
.
getStackAt
=
function
(
stepIndex
)
{
getStackAt
(
stepIndex
)
{
this
.
checkRequestedStep
(
stepIndex
)
if
(
this
.
trace
[
stepIndex
]
&&
this
.
trace
[
stepIndex
].
stack
)
{
// there's always a stack
let
stack
=
this
.
trace
[
stepIndex
].
stack
.
slice
(
0
)
...
...
@@ -135,9 +144,9 @@ TraceManager.prototype.getStackAt = function (stepIndex) {
}
else
{
throw
new
Error
(
'no stack found'
)
}
}
}
TraceManager
.
prototype
.
getLastCallChangeSince
=
function
(
stepIndex
)
{
getLastCallChangeSince
(
stepIndex
)
{
try
{
this
.
checkRequestedStep
(
stepIndex
)
}
catch
(
check
)
{
...
...
@@ -149,9 +158,9 @@ TraceManager.prototype.getLastCallChangeSince = function (stepIndex) {
return
0
}
return
callChange
}
}
TraceManager
.
prototype
.
getCurrentCalledAddressAt
=
function
(
stepIndex
)
{
getCurrentCalledAddressAt
(
stepIndex
)
{
try
{
this
.
checkRequestedStep
(
stepIndex
)
const
resp
=
this
.
getLastCallChangeSince
(
stepIndex
)
...
...
@@ -162,34 +171,34 @@ TraceManager.prototype.getCurrentCalledAddressAt = function (stepIndex) {
}
catch
(
error
)
{
throw
new
Error
(
error
)
}
}
}
TraceManager
.
prototype
.
getContractCreationCode
=
function
(
token
)
{
getContractCreationCode
(
token
)
{
if
(
!
this
.
traceCache
.
contractCreation
[
token
])
{
throw
new
Error
(
'no contract creation named '
+
token
)
}
return
this
.
traceCache
.
contractCreation
[
token
]
}
}
TraceManager
.
prototype
.
getMemoryAt
=
function
(
stepIndex
)
{
getMemoryAt
(
stepIndex
)
{
this
.
checkRequestedStep
(
stepIndex
)
const
lastChanges
=
util
.
findLowerBoundValue
(
stepIndex
,
this
.
traceCache
.
memoryChanges
)
if
(
lastChanges
===
null
)
{
throw
new
Error
(
'no memory found'
)
}
return
this
.
trace
[
lastChanges
].
memory
}
}
TraceManager
.
prototype
.
getCurrentPC
=
function
(
stepIndex
)
{
getCurrentPC
(
stepIndex
)
{
try
{
this
.
checkRequestedStep
(
stepIndex
)
}
catch
(
check
)
{
throw
new
Error
(
check
)
}
return
this
.
trace
[
stepIndex
].
pc
}
}
TraceManager
.
prototype
.
getReturnValue
=
function
(
stepIndex
)
{
getReturnValue
(
stepIndex
)
{
try
{
this
.
checkRequestedStep
(
stepIndex
)
}
catch
(
check
)
{
...
...
@@ -199,68 +208,68 @@ TraceManager.prototype.getReturnValue = function (stepIndex) {
throw
new
Error
(
'current step is not a return step'
)
}
return
this
.
traceCache
.
returnValues
[
stepIndex
]
}
}
TraceManager
.
prototype
.
getCurrentStep
=
function
(
stepIndex
)
{
getCurrentStep
(
stepIndex
)
{
try
{
this
.
checkRequestedStep
(
stepIndex
)
}
catch
(
check
)
{
throw
new
Error
(
check
)
}
return
this
.
traceCache
.
steps
[
stepIndex
]
}
}
TraceManager
.
prototype
.
getMemExpand
=
function
(
stepIndex
)
{
getMemExpand
(
stepIndex
)
{
return
(
this
.
getStepProperty
(
stepIndex
,
'memexpand'
)
||
''
)
}
}
TraceManager
.
prototype
.
getStepCost
=
function
(
stepIndex
)
{
getStepCost
(
stepIndex
)
{
return
this
.
getStepProperty
(
stepIndex
,
'gasCost'
)
}
}
TraceManager
.
prototype
.
getRemainingGas
=
function
(
stepIndex
)
{
getRemainingGas
(
stepIndex
)
{
return
this
.
getStepProperty
(
stepIndex
,
'gas'
)
}
}
TraceManager
.
prototype
.
getStepProperty
=
function
(
stepIndex
,
property
)
{
getStepProperty
(
stepIndex
,
property
)
{
try
{
this
.
checkRequestedStep
(
stepIndex
)
}
catch
(
check
)
{
throw
new
Error
(
check
)
}
return
this
.
trace
[
stepIndex
][
property
]
}
}
TraceManager
.
prototype
.
isCreationStep
=
function
(
stepIndex
)
{
isCreationStep
(
stepIndex
)
{
return
traceHelper
.
isCreateInstruction
(
this
.
trace
[
stepIndex
])
}
}
// step section
TraceManager
.
prototype
.
findStepOverBack
=
function
(
currentStep
)
{
// step section
findStepOverBack
(
currentStep
)
{
return
this
.
traceStepManager
.
findStepOverBack
(
currentStep
)
}
}
TraceManager
.
prototype
.
findStepOverForward
=
function
(
currentStep
)
{
findStepOverForward
(
currentStep
)
{
return
this
.
traceStepManager
.
findStepOverForward
(
currentStep
)
}
}
TraceManager
.
prototype
.
findNextCall
=
function
(
currentStep
)
{
findNextCall
(
currentStep
)
{
return
this
.
traceStepManager
.
findNextCall
(
currentStep
)
}
}
TraceManager
.
prototype
.
findStepOut
=
function
(
currentStep
)
{
findStepOut
(
currentStep
)
{
return
this
.
traceStepManager
.
findStepOut
(
currentStep
)
}
}
TraceManager
.
prototype
.
checkRequestedStep
=
function
(
stepIndex
)
{
checkRequestedStep
(
stepIndex
)
{
if
(
!
this
.
trace
)
{
throw
new
Error
(
'trace not loaded'
)
}
else
if
(
stepIndex
>=
this
.
trace
.
length
)
{
throw
new
Error
(
'trace smaller than requested'
)
}
}
}
TraceManager
.
prototype
.
waterfall
=
function
(
calls
,
stepindex
,
cb
)
{
waterfall
(
calls
,
stepindex
,
cb
)
{
let
ret
=
[]
let
retError
=
null
for
(
var
call
in
calls
)
{
...
...
@@ -270,6 +279,5 @@ TraceManager.prototype.waterfall = function (calls, stepindex, cb) {
}])
}
cb
(
retError
,
ret
)
}
}
module
.
exports
=
TraceManager
libs/remix-debug/src/trace/traceStepManager.ts
View file @
80b87ef2
...
...
@@ -4,52 +4,55 @@ const traceHelper = require('./traceHelper')
const
remixLib
=
require
(
'@remix-project/remix-lib'
)
const
util
=
remixLib
.
util
function
TraceStepManager
(
_traceAnalyser
)
{
export
class
TraceStepManager
{
traceAnalyser
constructor
(
_traceAnalyser
)
{
this
.
traceAnalyser
=
_traceAnalyser
}
}
TraceStepManager
.
prototype
.
isCallInstruction
=
fun
ction
(
index
)
{
isCallInstru
ction
(
index
)
{
const
state
=
this
.
traceAnalyser
.
trace
[
index
]
return
traceHelper
.
isCallInstruction
(
state
)
&&
!
traceHelper
.
isCallToPrecompiledContract
(
index
,
this
.
traceAnalyser
.
trace
)
}
}
TraceStepManager
.
prototype
.
isReturnInstruction
=
fun
ction
(
index
)
{
isReturnInstru
ction
(
index
)
{
const
state
=
this
.
traceAnalyser
.
trace
[
index
]
return
traceHelper
.
isReturnInstruction
(
state
)
}
}
TraceStepManager
.
prototype
.
findStepOverBack
=
function
(
currentStep
)
{
findStepOverBack
(
currentStep
)
{
if
(
this
.
isReturnInstruction
(
currentStep
))
{
const
call
=
util
.
findCall
(
currentStep
,
this
.
traceAnalyser
.
traceCache
.
callsTree
.
call
)
return
call
.
start
>
0
?
call
.
start
-
1
:
0
}
return
currentStep
>
0
?
currentStep
-
1
:
0
}
}
TraceStepManager
.
prototype
.
findStepOverForward
=
function
(
currentStep
)
{
findStepOverForward
(
currentStep
)
{
if
(
this
.
isCallInstruction
(
currentStep
))
{
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
this
.
traceAnalyser
.
trace
.
length
>=
currentStep
+
1
?
currentStep
+
1
:
currentStep
}
}
TraceStepManager
.
prototype
.
findNextCall
=
function
(
currentStep
)
{
findNextCall
(
currentStep
)
{
const
call
=
util
.
findCall
(
currentStep
,
this
.
traceAnalyser
.
traceCache
.
callsTree
.
call
)
const
subCalls
=
Object
.
keys
(
call
.
calls
)
if
(
subCalls
.
length
)
{
var
callStart
=
util
.
findLowerBound
(
currentStep
,
subCalls
)
+
1
if
(
subCalls
.
length
>
callStart
)
{
return
subCalls
[
callStart
]
-
1
return
parseInt
(
subCalls
[
callStart
])
-
1
}
return
currentStep
}
return
currentStep
}
}
TraceStepManager
.
prototype
.
findStepOut
=
function
(
currentStep
)
{
findStepOut
(
currentStep
)
{
const
call
=
util
.
findCall
(
currentStep
,
this
.
traceAnalyser
.
traceCache
.
callsTree
.
call
)
return
call
.
return
}
}
module
.
exports
=
TraceStepManager
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