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
137b6a7c
Commit
137b6a7c
authored
Dec 11, 2020
by
aniket-engg
Committed by
Aniket
Dec 21, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
breakpointManager and codeManager updated
parent
02e12cdc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
138 additions
and
125 deletions
+138
-125
breakpointManager.ts
libs/remix-debug/src/code/breakpointManager.ts
+10
-3
codeManager.ts
libs/remix-debug/src/code/codeManager.ts
+128
-122
No files found.
libs/remix-debug/src/code/breakpointManager.ts
View file @
137b6a7c
...
@@ -8,7 +8,16 @@ const helper = require('../trace/traceHelper')
...
@@ -8,7 +8,16 @@ const helper = require('../trace/traceHelper')
*
*
* Trigger events: breakpointHit, breakpointAdded, breakpointRemoved
* Trigger events: breakpointHit, breakpointAdded, breakpointRemoved
*/
*/
class
BreakpointManager
{
export
class
BreakpointManager
{
event
traceManager
callTree
solidityProxy
breakpoints
locationToRowConverter
previousLine
/**
/**
* constructor
* constructor
*
*
...
@@ -189,5 +198,3 @@ class BreakpointManager {
...
@@ -189,5 +198,3 @@ class BreakpointManager {
}
}
}
}
}
}
module
.
exports
=
BreakpointManager
libs/remix-debug/src/code/codeManager.ts
View file @
137b6a7c
...
@@ -12,141 +12,147 @@ const CodeResolver = require('./codeResolver')
...
@@ -12,141 +12,147 @@ const CodeResolver = require('./codeResolver')
- resolvingStep: when CodeManager resolves code/selected instruction of a new step
- resolvingStep: when CodeManager resolves code/selected instruction of a new step
*/
*/
function
CodeManager
(
_traceManager
)
{
export
class
CodeManager
{
this
.
event
=
new
EventManager
()
this
.
isLoading
=
false
this
.
traceManager
=
_traceManager
this
.
codeResolver
=
new
CodeResolver
({
getCode
:
async
(
address
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
traceManager
.
web3
.
eth
.
getCode
(
address
,
(
error
,
code
)
=>
{
if
(
error
)
{
return
reject
(
error
)
}
return
resolve
(
code
)
})
})
}})
}
/**
* clear the cache
*
*/
CodeManager
.
prototype
.
clear
=
function
()
{
this
.
codeResolver
.
clear
()
}
/**
event
* resolve the code of the given @arg stepIndex and trigger appropriate event
isLoading
:
boolean
*
traceManager
* @param {String} stepIndex - vm trace step
codeResolver
* @param {Object} tx - transaction (given by web3)
*/
constructor
(
_traceManager
)
{
CodeManager
.
prototype
.
resolveStep
=
function
(
stepIndex
,
tx
)
{
this
.
event
=
new
EventManager
()
if
(
stepIndex
<
0
)
return
this
.
isLoading
=
false
this
.
event
.
trigger
(
'resolvingStep'
)
this
.
traceManager
=
_traceManager
if
(
stepIndex
===
0
)
{
this
.
codeResolver
=
new
CodeResolver
({
getCode
:
async
(
address
)
=>
{
return
retrieveCodeAndTrigger
(
this
,
tx
.
to
,
stepIndex
,
tx
)
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
traceManager
.
web3
.
eth
.
getCode
(
address
,
(
error
,
code
)
=>
{
if
(
error
)
{
return
reject
(
error
)
}
return
resolve
(
code
)
})
})
}})
}
}
try
{
const
address
=
this
.
traceManager
.
getCurrentCalledAddressAt
(
stepIndex
)
/**
retrieveCodeAndTrigger
(
this
,
address
,
stepIndex
,
tx
)
* clear the cache
}
catch
(
error
)
{
*
return
console
.
log
(
error
)
*/
clear
()
{
this
.
codeResolver
.
clear
()
}
}
}
/**
/**
* Retrieve the code located at the given @arg address
* resolve the code of the given @arg stepIndex and trigger appropriate event
*
*
* @param {String} address - address of the contract to get the code from
* @param {String} stepIndex - vm trace step
* @param {Function} cb - callback function, return the bytecode
* @param {Object} tx - transaction (given by web3)
*/
*/
CodeManager
.
prototype
.
getCode
=
async
function
(
address
)
{
resolveStep
(
stepIndex
,
tx
)
{
if
(
!
traceHelper
.
isContractCreation
(
address
))
{
if
(
stepIndex
<
0
)
return
const
code
=
await
this
.
codeResolver
.
resolveCode
(
address
)
this
.
event
.
trigger
(
'resolvingStep'
)
return
code
if
(
stepIndex
===
0
)
{
return
this
.
retrieveCodeAndTrigger
(
this
,
tx
.
to
,
stepIndex
,
tx
)
}
try
{
const
address
=
this
.
traceManager
.
getCurrentCalledAddressAt
(
stepIndex
)
this
.
retrieveCodeAndTrigger
(
this
,
address
,
stepIndex
,
tx
)
}
catch
(
error
)
{
return
console
.
log
(
error
)
}
}
}
var
codes
=
this
.
codeResolver
.
getExecutingCodeFromCache
(
address
)
if
(
codes
)
{
/**
* Retrieve the code located at the given @arg address
*
* @param {String} address - address of the contract to get the code from
* @param {Function} cb - callback function, return the bytecode
*/
async
getCode
(
address
)
{
if
(
!
traceHelper
.
isContractCreation
(
address
))
{
const
code
=
await
this
.
codeResolver
.
resolveCode
(
address
)
return
code
}
var
codes
=
this
.
codeResolver
.
getExecutingCodeFromCache
(
address
)
if
(
codes
)
{
return
codes
}
const
hexCode
=
this
.
traceManager
.
getContractCreationCode
(
address
)
codes
=
this
.
codeResolver
.
cacheExecutingCode
(
address
,
hexCode
)
return
codes
return
codes
}
}
const
hexCode
=
this
.
traceManager
.
getContractCreationCode
(
address
)
codes
=
this
.
codeResolver
.
cacheExecutingCode
(
address
,
hexCode
)
return
codes
}
/**
/**
* Retrieve the called function for the current vm step for the given @arg address
* Retrieve the called function for the current vm step for the given @arg address
*
*
* @param {String} stepIndex - vm trace step
* @param {String} stepIndex - vm trace step
* @param {String} sourceMap - source map given byt the compilation result
* @param {String} sourceMap - source map given byt the compilation result
* @param {Object} ast - ast given by the compilation result
* @param {Object} ast - ast given by the compilation result
* @return {Object} return the ast node of the function
* @return {Object} return the ast node of the function
*/
*/
CodeManager
.
prototype
.
getFunctionFromStep
=
function
(
stepIndex
,
sourceMap
,
ast
)
{
getFunctionFromStep
(
stepIndex
,
sourceMap
,
ast
)
{
try
{
try
{
const
address
=
this
.
traceManager
.
getCurrentCalledAddressAt
(
stepIndex
)
const
address
=
this
.
traceManager
.
getCurrentCalledAddressAt
(
stepIndex
)
const
pc
=
this
.
traceManager
.
getCurrentPC
(
stepIndex
)
const
pc
=
this
.
traceManager
.
getCurrentPC
(
stepIndex
)
return
this
.
getFunctionFromPC
(
address
,
pc
,
sourceMap
,
ast
)
return
this
.
getFunctionFromPC
(
address
,
pc
,
sourceMap
,
ast
)
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
error
)
console
.
log
(
error
)
return
{
error
:
'Cannot retrieve current address or PC for '
+
stepIndex
}
return
{
error
:
'Cannot retrieve current address or PC for '
+
stepIndex
}
}
}
}
}
/**
/**
* Retrieve the instruction index of the given @arg step
* Retrieve the instruction index of the given @arg step
*
*
* @param {String} address - address of the current context
* @param {String} address - address of the current context
* @param {String} step - vm trace step
* @param {String} step - vm trace step
* @param {Function} callback - instruction index
* @param {Function} callback - instruction index
*/
*/
CodeManager
.
prototype
.
getInstructionIndex
=
function
(
address
,
step
)
{
getInstructionIndex
(
address
,
step
)
{
try
{
try
{
const
pc
=
this
.
traceManager
.
getCurrentPC
(
step
)
const
pc
=
this
.
traceManager
.
getCurrentPC
(
step
)
const
itemIndex
=
this
.
codeResolver
.
getInstructionIndex
(
address
,
pc
)
const
itemIndex
=
this
.
codeResolver
.
getInstructionIndex
(
address
,
pc
)
return
itemIndex
return
itemIndex
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
error
)
console
.
log
(
error
)
throw
new
Error
(
'Cannot retrieve current PC for '
+
step
)
throw
new
Error
(
'Cannot retrieve current PC for '
+
step
)
}
}
}
}
/**
/**
* Retrieve the called function for the given @arg pc and @arg address
* Retrieve the called function for the given @arg pc and @arg address
*
*
* @param {String} address - address of the current context (used to resolve instruction index)
* @param {String} address - address of the current context (used to resolve instruction index)
* @param {String} pc - pc that point to the instruction index
* @param {String} pc - pc that point to the instruction index
* @param {String} sourceMap - source map given byt the compilation result
* @param {String} sourceMap - source map given byt the compilation result
* @param {Object} ast - ast given by the compilation result
* @param {Object} ast - ast given by the compilation result
* @return {Object} return the ast node of the function
* @return {Object} return the ast node of the function
*/
*/
CodeManager
.
prototype
.
getFunctionFromPC
=
function
(
address
,
pc
,
sourceMap
,
ast
)
{
getFunctionFromPC
(
address
,
pc
,
sourceMap
,
ast
)
{
const
instIndex
=
this
.
codeResolver
.
getInstructionIndex
(
address
,
pc
)
const
instIndex
=
this
.
codeResolver
.
getInstructionIndex
(
address
,
pc
)
return
SourceMappingDecoder
.
findNodeAtInstructionIndex
(
'FunctionDefinition'
,
instIndex
,
sourceMap
,
ast
)
return
SourceMappingDecoder
.
findNodeAtInstructionIndex
(
'FunctionDefinition'
,
instIndex
,
sourceMap
,
ast
)
}
}
function
retrieveCodeAndTrigger
(
codeMananger
,
address
,
stepIndex
,
tx
)
{
private
retrieveCodeAndTrigger
(
codeMananger
,
address
,
stepIndex
,
tx
)
{
codeMananger
.
getCode
(
address
).
then
((
result
)
=>
{
codeMananger
.
getCode
(
address
).
then
((
result
)
=>
{
retrieveIndexAndTrigger
(
codeMananger
,
address
,
stepIndex
,
result
.
instructions
)
this
.
retrieveIndexAndTrigger
(
codeMananger
,
address
,
stepIndex
,
result
.
instructions
)
}).
catch
((
error
)
=>
{
}).
catch
((
error
)
=>
{
return
console
.
log
(
error
)
return
console
.
log
(
error
)
})
})
}
}
function
retrieveIndexAndTrigger
(
codeMananger
,
address
,
step
,
code
)
{
private
retrieveIndexAndTrigger
(
codeMananger
,
address
,
step
,
code
)
{
let
result
let
result
try
{
try
{
result
=
codeMananger
.
getInstructionIndex
(
address
,
step
)
result
=
codeMananger
.
getInstructionIndex
(
address
,
step
)
}
catch
(
error
)
{
}
catch
(
error
)
{
return
console
.
log
(
error
)
return
console
.
log
(
error
)
}
try
{
codeMananger
.
event
.
trigger
(
'changed'
,
[
code
,
address
,
result
])
}
catch
(
e
)
{
console
.
log
(
'dispatching event failed'
,
e
)
}
}
}
try
{
codeMananger
.
event
.
trigger
(
'changed'
,
[
code
,
address
,
result
])
}
catch
(
e
)
{
console
.
log
(
'dispatching event failed'
,
e
)
}
}
}
module
.
exports
=
CodeManager
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