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
399a57d8
Commit
399a57d8
authored
Dec 15, 2020
by
aniket-engg
Committed by
Aniket
Dec 21, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
linting working fine
parent
3e7477d0
Show whitespace changes
Inline
Side-by-side
Showing
40 changed files
with
173 additions
and
205 deletions
+173
-205
.eslintrc
libs/remix-debug/.eslintrc
+2
-1
Ethdebugger.ts
libs/remix-debug/src/Ethdebugger.ts
+11
-12
index.ts
libs/remix-debug/src/cmdline/index.ts
+2
-3
breakpointManager.ts
libs/remix-debug/src/code/breakpointManager.ts
+7
-9
codeManager.ts
libs/remix-debug/src/code/codeManager.ts
+5
-4
codeResolver.ts
libs/remix-debug/src/code/codeResolver.ts
+2
-3
codeUtils.ts
libs/remix-debug/src/code/codeUtils.ts
+4
-5
opcodes.ts
libs/remix-debug/src/code/opcodes.ts
+1
-1
VmDebugger.ts
libs/remix-debug/src/debugger/VmDebugger.ts
+1
-3
debugger.ts
libs/remix-debug/src/debugger/debugger.ts
+13
-9
solidityLocals.ts
libs/remix-debug/src/debugger/solidityLocals.ts
+2
-3
solidityState.ts
libs/remix-debug/src/debugger/solidityState.ts
+2
-3
stepManager.ts
libs/remix-debug/src/debugger/stepManager.ts
+5
-7
eventManager.ts
libs/remix-debug/src/eventManager.ts
+3
-4
init.ts
libs/remix-debug/src/init.ts
+5
-6
astHelper.ts
libs/remix-debug/src/solidity-decoder/astHelper.ts
+5
-6
decodeInfo.ts
libs/remix-debug/src/solidity-decoder/decodeInfo.ts
+19
-20
internalCallTree.ts
libs/remix-debug/src/solidity-decoder/internalCallTree.ts
+8
-9
localDecoder.ts
libs/remix-debug/src/solidity-decoder/localDecoder.ts
+2
-2
solidityProxy.ts
libs/remix-debug/src/solidity-decoder/solidityProxy.ts
+4
-5
ArrayType.ts
libs/remix-debug/src/solidity-decoder/types/ArrayType.ts
+1
-2
DynamicByteArray.ts
...emix-debug/src/solidity-decoder/types/DynamicByteArray.ts
+6
-7
Enum.ts
libs/remix-debug/src/solidity-decoder/types/Enum.ts
+0
-1
Mapping.ts
libs/remix-debug/src/solidity-decoder/types/Mapping.ts
+6
-7
RefType.ts
libs/remix-debug/src/solidity-decoder/types/RefType.ts
+3
-4
StringType.ts
libs/remix-debug/src/solidity-decoder/types/StringType.ts
+3
-4
Struct.ts
libs/remix-debug/src/solidity-decoder/types/Struct.ts
+2
-3
ValueType.ts
libs/remix-debug/src/solidity-decoder/types/ValueType.ts
+5
-6
util.ts
libs/remix-debug/src/solidity-decoder/types/util.ts
+2
-2
offsetToLineColumnConverter.ts
libs/remix-debug/src/source/offsetToLineColumnConverter.ts
+2
-3
sourceLocationTracker.ts
libs/remix-debug/src/source/sourceLocationTracker.ts
+6
-7
sourceMappingDecoder.ts
libs/remix-debug/src/source/sourceMappingDecoder.ts
+13
-14
mappingPreimages.ts
libs/remix-debug/src/storage/mappingPreimages.ts
+3
-3
storageResolver.ts
libs/remix-debug/src/storage/storageResolver.ts
+2
-3
storageViewer.ts
libs/remix-debug/src/storage/storageViewer.ts
+1
-2
traceAnalyser.ts
libs/remix-debug/src/trace/traceAnalyser.ts
+1
-3
traceCache.ts
libs/remix-debug/src/trace/traceCache.ts
+7
-9
traceHelper.ts
libs/remix-debug/src/trace/traceHelper.ts
+1
-2
traceManager.ts
libs/remix-debug/src/trace/traceManager.ts
+6
-7
traceStepManager.ts
libs/remix-debug/src/trace/traceStepManager.ts
+0
-1
No files found.
libs/remix-debug/.eslintrc
View file @
399a57d8
...
@@ -3,7 +3,8 @@
...
@@ -3,7 +3,8 @@
"rules": {
"rules": {
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-this-alias": "off"
"@typescript-eslint/no-this-alias": "off",
"camelcase": "off"
},
},
"env": {
"env": {
"browser": true,
"browser": true,
...
...
libs/remix-debug/src/Ethdebugger.ts
View file @
399a57d8
...
@@ -22,7 +22,6 @@ import { SolidityProxy, stateDecoder, localDecoder, InternalCallTree } from './s
...
@@ -22,7 +22,6 @@ import { SolidityProxy, stateDecoder, localDecoder, InternalCallTree } from './s
* @param {Map} opts - { function compilationResult } //
* @param {Map} opts - { function compilationResult } //
*/
*/
export
class
Ethdebugger
{
export
class
Ethdebugger
{
compilationResult
compilationResult
web3
web3
opts
opts
...
@@ -42,9 +41,9 @@ export class Ethdebugger {
...
@@ -42,9 +41,9 @@ export class Ethdebugger {
this
.
opts
=
opts
this
.
opts
=
opts
this
.
event
=
new
EventManager
()
this
.
event
=
new
EventManager
()
this
.
traceManager
=
new
TraceManager
({
web3
:
this
.
web3
})
this
.
traceManager
=
new
TraceManager
({
web3
:
this
.
web3
})
this
.
codeManager
=
new
CodeManager
(
this
.
traceManager
)
this
.
codeManager
=
new
CodeManager
(
this
.
traceManager
)
this
.
solidityProxy
=
new
SolidityProxy
({
getCurrentCalledAddressAt
:
this
.
traceManager
.
getCurrentCalledAddressAt
.
bind
(
this
.
traceManager
),
getCode
:
this
.
codeManager
.
getCode
.
bind
(
this
.
codeManager
)
})
this
.
solidityProxy
=
new
SolidityProxy
({
getCurrentCalledAddressAt
:
this
.
traceManager
.
getCurrentCalledAddressAt
.
bind
(
this
.
traceManager
),
getCode
:
this
.
codeManager
.
getCode
.
bind
(
this
.
codeManager
)
})
this
.
storageResolver
=
null
this
.
storageResolver
=
null
const
includeLocalVariables
=
true
const
includeLocalVariables
=
true
...
@@ -52,13 +51,13 @@ export class Ethdebugger {
...
@@ -52,13 +51,13 @@ export class Ethdebugger {
this
.
traceManager
,
this
.
traceManager
,
this
.
solidityProxy
,
this
.
solidityProxy
,
this
.
codeManager
,
this
.
codeManager
,
{
...
opts
,
includeLocalVariables
})
{
...
opts
,
includeLocalVariables
})
}
}
setManagers
()
{
setManagers
()
{
this
.
traceManager
=
new
TraceManager
({
web3
:
this
.
web3
})
this
.
traceManager
=
new
TraceManager
({
web3
:
this
.
web3
})
this
.
codeManager
=
new
CodeManager
(
this
.
traceManager
)
this
.
codeManager
=
new
CodeManager
(
this
.
traceManager
)
this
.
solidityProxy
=
new
SolidityProxy
({
getCurrentCalledAddressAt
:
this
.
traceManager
.
getCurrentCalledAddressAt
.
bind
(
this
.
traceManager
),
getCode
:
this
.
codeManager
.
getCode
.
bind
(
this
.
codeManager
)
})
this
.
solidityProxy
=
new
SolidityProxy
({
getCurrentCalledAddressAt
:
this
.
traceManager
.
getCurrentCalledAddressAt
.
bind
(
this
.
traceManager
),
getCode
:
this
.
codeManager
.
getCode
.
bind
(
this
.
codeManager
)
})
this
.
storageResolver
=
null
this
.
storageResolver
=
null
const
includeLocalVariables
=
true
const
includeLocalVariables
=
true
...
@@ -66,7 +65,7 @@ export class Ethdebugger {
...
@@ -66,7 +65,7 @@ export class Ethdebugger {
this
.
traceManager
,
this
.
traceManager
,
this
.
solidityProxy
,
this
.
solidityProxy
,
this
.
codeManager
,
this
.
codeManager
,
{
...
this
.
opts
,
includeLocalVariables
})
{
...
this
.
opts
,
includeLocalVariables
})
this
.
event
.
trigger
(
'managersChanged'
)
this
.
event
.
trigger
(
'managersChanged'
)
}
}
...
@@ -108,8 +107,8 @@ export class Ethdebugger {
...
@@ -108,8 +107,8 @@ export class Ethdebugger {
try
{
try
{
const
storageViewer
=
new
StorageViewer
({
stepIndex
:
step
,
tx
:
this
.
tx
,
address
:
address
},
this
.
storageResolver
,
this
.
traceManager
)
const
storageViewer
=
new
StorageViewer
({
stepIndex
:
step
,
tx
:
this
.
tx
,
address
:
address
},
this
.
storageResolver
,
this
.
traceManager
)
const
locals
=
await
localDecoder
.
solidityLocals
(
step
,
this
.
callTree
,
stack
,
memory
,
storageViewer
,
sourceLocation
,
null
)
const
locals
=
await
localDecoder
.
solidityLocals
(
step
,
this
.
callTree
,
stack
,
memory
,
storageViewer
,
sourceLocation
,
null
)
if
(
locals
[
'error'
]
)
{
if
(
locals
.
error
)
{
return
callback
(
locals
[
'error'
]
)
return
callback
(
locals
.
error
)
}
}
return
callback
(
null
,
locals
)
return
callback
(
null
,
locals
)
}
catch
(
e
)
{
}
catch
(
e
)
{
...
@@ -128,7 +127,7 @@ export class Ethdebugger {
...
@@ -128,7 +127,7 @@ export class Ethdebugger {
async
decodeStateAt
(
step
,
stateVars
,
callback
)
{
async
decodeStateAt
(
step
,
stateVars
,
callback
)
{
try
{
try
{
const
address
=
this
.
traceManager
.
getCurrentCalledAddressAt
(
step
)
const
address
=
this
.
traceManager
.
getCurrentCalledAddressAt
(
step
)
const
storageViewer
=
new
StorageViewer
({
stepIndex
:
step
,
tx
:
this
.
tx
,
address
:
address
},
this
.
storageResolver
,
this
.
traceManager
)
const
storageViewer
=
new
StorageViewer
({
stepIndex
:
step
,
tx
:
this
.
tx
,
address
:
address
},
this
.
storageResolver
,
this
.
traceManager
)
const
result
=
await
stateDecoder
.
decodeState
(
stateVars
,
storageViewer
)
const
result
=
await
stateDecoder
.
decodeState
(
stateVars
,
storageViewer
)
return
result
return
result
}
catch
(
error
)
{
}
catch
(
error
)
{
...
@@ -137,7 +136,7 @@ export class Ethdebugger {
...
@@ -137,7 +136,7 @@ export class Ethdebugger {
}
}
storageViewAt
(
step
,
address
)
{
storageViewAt
(
step
,
address
)
{
return
new
StorageViewer
({
stepIndex
:
step
,
tx
:
this
.
tx
,
address
:
address
},
this
.
storageResolver
,
this
.
traceManager
)
return
new
StorageViewer
({
stepIndex
:
step
,
tx
:
this
.
tx
,
address
:
address
},
this
.
storageResolver
,
this
.
traceManager
)
}
}
updateWeb3
(
web3
)
{
updateWeb3
(
web3
)
{
...
@@ -164,7 +163,7 @@ export class Ethdebugger {
...
@@ -164,7 +163,7 @@ export class Ethdebugger {
if
(
this
.
breakpointManager
&&
this
.
breakpointManager
.
hasBreakpoint
())
{
if
(
this
.
breakpointManager
&&
this
.
breakpointManager
.
hasBreakpoint
())
{
this
.
breakpointManager
.
jumpNextBreakpoint
(
false
)
this
.
breakpointManager
.
jumpNextBreakpoint
(
false
)
}
}
this
.
storageResolver
=
new
StorageResolver
({
web3
:
this
.
traceManager
.
web3
})
this
.
storageResolver
=
new
StorageResolver
({
web3
:
this
.
traceManager
.
web3
})
}).
catch
((
error
)
=>
{
}).
catch
((
error
)
=>
{
this
.
statusMessage
=
error
?
error
.
message
:
'Trace not loaded'
this
.
statusMessage
=
error
?
error
.
message
:
'Trace not loaded'
})
})
...
...
libs/remix-debug/src/cmdline/index.ts
View file @
399a57d8
...
@@ -3,7 +3,6 @@ import { Debugger } from '../debugger/debugger.js'
...
@@ -3,7 +3,6 @@ import { Debugger } from '../debugger/debugger.js'
import
{
EventEmitter
}
from
'events'
import
{
EventEmitter
}
from
'events'
export
class
CmdLine
{
export
class
CmdLine
{
events
events
lineColumnPos
lineColumnPos
rawLocation
rawLocation
...
@@ -28,8 +27,8 @@ export class CmdLine {
...
@@ -28,8 +27,8 @@ export class CmdLine {
loadCompilationData
(
inputJson
,
outputJson
)
{
loadCompilationData
(
inputJson
,
outputJson
)
{
const
data
=
{}
const
data
=
{}
data
[
'data'
]
=
outputJson
data
.
data
=
outputJson
data
[
'source'
]
=
{
sources
:
inputJson
.
sources
}
data
.
source
=
{
sources
:
inputJson
.
sources
}
this
.
loadCompilationResult
(
data
)
this
.
loadCompilationResult
(
data
)
}
}
...
...
libs/remix-debug/src/code/breakpointManager.ts
View file @
399a57d8
...
@@ -9,7 +9,6 @@ import { isJumpDestInstruction } from '../trace/traceHelper'
...
@@ -9,7 +9,6 @@ import { isJumpDestInstruction } from '../trace/traceHelper'
* Trigger events: breakpointHit, breakpointAdded, breakpointRemoved
* Trigger events: breakpointHit, breakpointAdded, breakpointRemoved
*/
*/
export
class
BreakpointManager
{
export
class
BreakpointManager
{
event
event
traceManager
traceManager
callTree
callTree
...
@@ -24,17 +23,16 @@ export class BreakpointManager {
...
@@ -24,17 +23,16 @@ export class BreakpointManager {
* @param {Object} _debugger - type of EthDebugger
* @param {Object} _debugger - type of EthDebugger
* @return {Function} _locationToRowConverter - function implemented by editor which return a column/line position for a char source location
* @return {Function} _locationToRowConverter - function implemented by editor which return a column/line position for a char source location
*/
*/
constructor
({
traceManager
,
callTree
,
solidityProxy
,
locationToRowConverter
})
{
constructor
({
traceManager
,
callTree
,
solidityProxy
,
locationToRowConverter
})
{
this
.
event
=
new
EventManager
()
this
.
event
=
new
EventManager
()
this
.
traceManager
=
traceManager
this
.
traceManager
=
traceManager
this
.
callTree
=
callTree
this
.
callTree
=
callTree
this
.
solidityProxy
=
solidityProxy
this
.
solidityProxy
=
solidityProxy
this
.
breakpoints
=
{}
this
.
breakpoints
=
{}
this
.
locationToRowConverter
=
locationToRowConverter
this
.
locationToRowConverter
=
locationToRowConverter
this
.
previousLine
}
}
setManagers
({
traceManager
,
callTree
,
solidityProxy
})
{
setManagers
({
traceManager
,
callTree
,
solidityProxy
})
{
this
.
traceManager
=
traceManager
this
.
traceManager
=
traceManager
this
.
callTree
=
callTree
this
.
callTree
=
callTree
this
.
solidityProxy
=
solidityProxy
this
.
solidityProxy
=
solidityProxy
...
@@ -68,7 +66,7 @@ export class BreakpointManager {
...
@@ -68,7 +66,7 @@ export class BreakpointManager {
return
trace
[
step
].
depth
!==
trace
[
step
-
1
].
depth
return
trace
[
step
].
depth
!==
trace
[
step
-
1
].
depth
}
}
hitLine
(
currentStep
,
sourceLocation
,
previousSourceLocation
,
trace
)
{
hitLine
(
currentStep
,
sourceLocation
,
previousSourceLocation
,
trace
)
{
// isJumpDestInstruction -> returning from a internal function call
// isJumpDestInstruction -> returning from a internal function call
// depthChange -> returning from an external call
// depthChange -> returning from an external call
// sourceLocation.start <= previousSourceLocation.start && ... -> previous src is contained in the current one
// sourceLocation.start <= previousSourceLocation.start && ... -> previous src is contained in the current one
...
@@ -101,7 +99,7 @@ export class BreakpointManager {
...
@@ -101,7 +99,7 @@ export class BreakpointManager {
}
catch
(
e
)
{
}
catch
(
e
)
{
return
console
.
log
(
'cannot jump to breakpoint '
+
e
)
return
console
.
log
(
'cannot jump to breakpoint '
+
e
)
}
}
le
t
lineColumn
=
await
this
.
locationToRowConverter
(
sourceLocation
)
cons
t
lineColumn
=
await
this
.
locationToRowConverter
(
sourceLocation
)
if
(
this
.
previousLine
!==
lineColumn
.
start
.
line
)
{
if
(
this
.
previousLine
!==
lineColumn
.
start
.
line
)
{
if
(
direction
===
-
1
&&
lineHadBreakpoint
)
{
// TODO : improve this when we will build the correct structure before hand
if
(
direction
===
-
1
&&
lineHadBreakpoint
)
{
// TODO : improve this when we will build the correct structure before hand
lineHadBreakpoint
=
false
lineHadBreakpoint
=
false
...
@@ -143,7 +141,7 @@ export class BreakpointManager {
...
@@ -143,7 +141,7 @@ export class BreakpointManager {
return
false
return
false
}
}
const
sources
=
this
.
breakpoints
[
filename
]
const
sources
=
this
.
breakpoints
[
filename
]
for
(
le
t
k
in
sources
)
{
for
(
cons
t
k
in
sources
)
{
const
source
=
sources
[
k
]
const
source
=
sources
[
k
]
if
(
line
===
source
.
row
)
{
if
(
line
===
source
.
row
)
{
return
true
return
true
...
@@ -157,7 +155,7 @@ export class BreakpointManager {
...
@@ -157,7 +155,7 @@ export class BreakpointManager {
* @return {Bool} true if breapoint registered
* @return {Bool} true if breapoint registered
*/
*/
hasBreakpoint
()
{
hasBreakpoint
()
{
for
(
le
t
k
in
this
.
breakpoints
)
{
for
(
cons
t
k
in
this
.
breakpoints
)
{
if
(
this
.
breakpoints
[
k
].
length
)
{
if
(
this
.
breakpoints
[
k
].
length
)
{
return
true
return
true
}
}
...
@@ -188,7 +186,7 @@ export class BreakpointManager {
...
@@ -188,7 +186,7 @@ export class BreakpointManager {
if
(
!
sources
)
{
if
(
!
sources
)
{
return
return
}
}
for
(
le
t
k
in
sources
)
{
for
(
cons
t
k
in
sources
)
{
const
source
=
sources
[
k
]
const
source
=
sources
[
k
]
if
(
sourceLocation
.
row
===
source
.
row
)
{
if
(
sourceLocation
.
row
===
source
.
row
)
{
sources
.
splice
(
k
,
1
)
sources
.
splice
(
k
,
1
)
...
...
libs/remix-debug/src/code/codeManager.ts
View file @
399a57d8
...
@@ -13,17 +13,17 @@ import { CodeResolver } from './codeResolver'
...
@@ -13,17 +13,17 @@ import { CodeResolver } from './codeResolver'
*/
*/
export
class
CodeManager
{
export
class
CodeManager
{
event
event
isLoading
:
boolean
isLoading
:
boolean
traceManager
traceManager
codeResolver
codeResolver
constructor
(
_traceManager
)
{
constructor
(
_traceManager
)
{
this
.
event
=
new
EventManager
()
this
.
event
=
new
EventManager
()
this
.
isLoading
=
false
this
.
isLoading
=
false
this
.
traceManager
=
_traceManager
this
.
traceManager
=
_traceManager
this
.
codeResolver
=
new
CodeResolver
({
getCode
:
async
(
address
)
=>
{
this
.
codeResolver
=
new
CodeResolver
({
getCode
:
async
(
address
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
traceManager
.
web3
.
eth
.
getCode
(
address
,
(
error
,
code
)
=>
{
this
.
traceManager
.
web3
.
eth
.
getCode
(
address
,
(
error
,
code
)
=>
{
if
(
error
)
{
if
(
error
)
{
...
@@ -32,7 +32,8 @@ export class CodeManager {
...
@@ -32,7 +32,8 @@ export class CodeManager {
return
resolve
(
code
)
return
resolve
(
code
)
})
})
})
})
}})
}
})
}
}
/**
/**
...
...
libs/remix-debug/src/code/codeResolver.ts
View file @
399a57d8
...
@@ -2,13 +2,12 @@
...
@@ -2,13 +2,12 @@
import
{
nameOpCodes
}
from
'./codeUtils'
import
{
nameOpCodes
}
from
'./codeUtils'
export
class
CodeResolver
{
export
class
CodeResolver
{
getCode
getCode
bytecodeByAddress
bytecodeByAddress
instructionsByAddress
instructionsByAddress
instructionsIndexByBytesOffset
instructionsIndexByBytesOffset
constructor
({
getCode
})
{
constructor
({
getCode
})
{
this
.
getCode
=
getCode
this
.
getCode
=
getCode
this
.
bytecodeByAddress
=
{}
// bytes code by contract addesses
this
.
bytecodeByAddress
=
{}
// bytes code by contract addesses
this
.
instructionsByAddress
=
{}
// assembly items instructions list by contract addesses
this
.
instructionsByAddress
=
{}
// assembly items instructions list by contract addesses
...
@@ -41,7 +40,7 @@ export class CodeResolver {
...
@@ -41,7 +40,7 @@ export class CodeResolver {
formatCode
(
hexCode
)
{
formatCode
(
hexCode
)
{
const
[
code
,
instructionsIndexByBytesOffset
]
=
nameOpCodes
(
Buffer
.
from
(
hexCode
.
substring
(
2
),
'hex'
))
const
[
code
,
instructionsIndexByBytesOffset
]
=
nameOpCodes
(
Buffer
.
from
(
hexCode
.
substring
(
2
),
'hex'
))
return
{
code
,
instructionsIndexByBytesOffset
}
return
{
code
,
instructionsIndexByBytesOffset
}
}
}
getExecutingCodeFromCache
(
address
)
{
getExecutingCodeFromCache
(
address
)
{
...
...
libs/remix-debug/src/code/codeUtils.ts
View file @
399a57d8
...
@@ -22,7 +22,7 @@ export function nameOpCodes (raw) {
...
@@ -22,7 +22,7 @@ export function nameOpCodes (raw) {
code
.
push
(
this
.
pad
(
pc
,
this
.
roundLog
(
raw
.
length
,
10
))
+
' '
+
curOpCode
+
data
)
code
.
push
(
this
.
pad
(
pc
,
this
.
roundLog
(
raw
.
length
,
10
))
+
' '
+
curOpCode
+
data
)
pushData
=
''
pushData
=
''
}
}
return
[
code
,
codeMap
]
return
[
code
,
codeMap
]
}
}
/**
/**
...
@@ -35,11 +35,11 @@ export function parseCode (raw) {
...
@@ -35,11 +35,11 @@ export function parseCode (raw) {
const
opcode
=
opcodes
(
raw
[
i
],
true
)
const
opcode
=
opcodes
(
raw
[
i
],
true
)
if
(
opcode
.
name
.
slice
(
0
,
4
)
===
'PUSH'
)
{
if
(
opcode
.
name
.
slice
(
0
,
4
)
===
'PUSH'
)
{
const
length
=
raw
[
i
]
-
0x5f
const
length
=
raw
[
i
]
-
0x5f
opcode
[
'pushData'
]
=
raw
.
slice
(
i
+
1
,
i
+
length
+
1
)
opcode
.
pushData
=
raw
.
slice
(
i
+
1
,
i
+
length
+
1
)
// in case pushdata extends beyond code
// in case pushdata extends beyond code
if
(
i
+
1
+
length
>
raw
.
length
)
{
if
(
i
+
1
+
length
>
raw
.
length
)
{
for
(
let
j
=
opcode
[
'pushData'
]
.
length
;
j
<
length
;
j
++
)
{
for
(
let
j
=
opcode
.
pushData
.
length
;
j
<
length
;
j
++
)
{
opcode
[
'pushData'
]
.
push
(
0
)
opcode
.
pushData
.
push
(
0
)
}
}
}
}
i
+=
length
i
+=
length
...
@@ -62,4 +62,3 @@ export function log (num, base) {
...
@@ -62,4 +62,3 @@ export function log (num, base) {
export
function
roundLog
(
num
,
base
)
{
export
function
roundLog
(
num
,
base
)
{
return
Math
.
ceil
(
this
.
log
(
num
,
base
))
return
Math
.
ceil
(
this
.
log
(
num
,
base
))
}
}
libs/remix-debug/src/code/opcodes.ts
View file @
399a57d8
...
@@ -189,5 +189,5 @@ export default function (op, full) {
...
@@ -189,5 +189,5 @@ export default function (op, full) {
}
}
}
}
return
{
name
:
opcode
,
fee
:
code
[
1
],
in
:
code
[
2
],
out
:
code
[
3
],
dynamic
:
code
[
4
],
async
:
code
[
5
]
}
return
{
name
:
opcode
,
fee
:
code
[
1
],
in
:
code
[
2
],
out
:
code
[
3
],
dynamic
:
code
[
4
],
async
:
code
[
5
]
}
}
}
libs/remix-debug/src/debugger/VmDebugger.ts
View file @
399a57d8
...
@@ -7,7 +7,6 @@ import { DebuggerSolidityLocals } from './solidityLocals'
...
@@ -7,7 +7,6 @@ import { DebuggerSolidityLocals } from './solidityLocals'
const
{
ui
}
=
helpers
const
{
ui
}
=
helpers
export
class
VmDebuggerLogic
{
export
class
VmDebuggerLogic
{
event
event
debugger
debugger
stepManager
stepManager
...
@@ -212,7 +211,7 @@ export class VmDebuggerLogic {
...
@@ -212,7 +211,7 @@ export class VmDebuggerLogic {
listenToNewChanges
()
{
listenToNewChanges
()
{
this
.
debugger
.
event
.
register
(
'newTraceLoaded'
,
this
,
()
=>
{
this
.
debugger
.
event
.
register
(
'newTraceLoaded'
,
this
,
()
=>
{
this
.
storageResolver
=
new
StorageResolver
({
web3
:
this
.
debugger
.
web3
})
this
.
storageResolver
=
new
StorageResolver
({
web3
:
this
.
debugger
.
web3
})
this
.
debuggerSolidityState
.
storageResolver
=
this
.
storageResolver
this
.
debuggerSolidityState
.
storageResolver
=
this
.
storageResolver
this
.
debuggerSolidityLocals
.
storageResolver
=
this
.
storageResolver
this
.
debuggerSolidityLocals
.
storageResolver
=
this
.
storageResolver
this
.
event
.
trigger
(
'newTrace'
,
[])
this
.
event
.
trigger
(
'newTrace'
,
[])
...
@@ -259,5 +258,4 @@ export class VmDebuggerLogic {
...
@@ -259,5 +258,4 @@ export class VmDebuggerLogic {
this
.
event
.
trigger
(
'traceReturnValueUpdate'
,
[
data
,
header
])
this
.
event
.
trigger
(
'traceReturnValueUpdate'
,
[
data
,
header
])
})
})
}
}
}
}
libs/remix-debug/src/debugger/debugger.ts
View file @
399a57d8
...
@@ -7,7 +7,6 @@ import { DebuggerStepManager } from './stepManager'
...
@@ -7,7 +7,6 @@ import { DebuggerStepManager } from './stepManager'
import
{
VmDebuggerLogic
}
from
'./VmDebugger'
import
{
VmDebuggerLogic
}
from
'./VmDebugger'
export
class
Debugger
{
export
class
Debugger
{
event
event
offsetToLineColumnConverter
offsetToLineColumnConverter
compilationResult
compilationResult
...
@@ -27,19 +26,24 @@ export class Debugger {
...
@@ -27,19 +26,24 @@ export class Debugger {
this
.
debugger
=
new
Ethdebugger
({
this
.
debugger
=
new
Ethdebugger
({
web3
:
options
.
web3
,
web3
:
options
.
web3
,
debugWithGeneratedSources
:
options
.
debugWithGeneratedSources
,
debugWithGeneratedSources
:
options
.
debugWithGeneratedSources
,
compilationResult
:
this
.
compilationResult
,
compilationResult
:
this
.
compilationResult
})
})
const
{
traceManager
,
callTree
,
solidityProxy
}
=
this
.
debugger
const
{
traceManager
,
callTree
,
solidityProxy
}
=
this
.
debugger
this
.
breakPointManager
=
new
BreakpointManager
({
traceManager
,
callTree
,
solidityProxy
,
locationToRowConverter
:
async
(
sourceLocation
)
=>
{
this
.
breakPointManager
=
new
BreakpointManager
({
traceManager
,
callTree
,
solidityProxy
,
locationToRowConverter
:
async
(
sourceLocation
)
=>
{
const
compilationResult
=
await
this
.
compilationResult
()
const
compilationResult
=
await
this
.
compilationResult
()
if
(
!
compilationResult
)
return
{
start
:
null
,
end
:
null
}
if
(
!
compilationResult
)
return
{
start
:
null
,
end
:
null
}
return
this
.
offsetToLineColumnConverter
.
offsetToLineColumn
(
sourceLocation
,
sourceLocation
.
file
,
compilationResult
.
source
.
sources
,
compilationResult
.
data
.
sources
)
return
this
.
offsetToLineColumnConverter
.
offsetToLineColumn
(
sourceLocation
,
sourceLocation
.
file
,
compilationResult
.
source
.
sources
,
compilationResult
.
data
.
sources
)
}})
}
})
this
.
breakPointManager
.
event
.
register
(
'managersChanged'
,
()
=>
{
this
.
breakPointManager
.
event
.
register
(
'managersChanged'
,
()
=>
{
const
{
traceManager
,
callTree
,
solidityProxy
}
=
this
.
debugger
const
{
traceManager
,
callTree
,
solidityProxy
}
=
this
.
debugger
this
.
breakPointManager
.
setManagers
({
traceManager
,
callTree
,
solidityProxy
})
this
.
breakPointManager
.
setManagers
({
traceManager
,
callTree
,
solidityProxy
})
})
})
this
.
breakPointManager
.
event
.
register
(
'breakpointStep'
,
(
step
)
=>
{
this
.
breakPointManager
.
event
.
register
(
'breakpointStep'
,
(
step
)
=>
{
...
@@ -115,14 +119,14 @@ export class Debugger {
...
@@ -115,14 +119,14 @@ export class Debugger {
if
(
txNumber
.
indexOf
(
'0x'
)
!==
-
1
)
{
if
(
txNumber
.
indexOf
(
'0x'
)
!==
-
1
)
{
return
web3
.
eth
.
getTransaction
(
txNumber
,
(
_error
,
tx
)
=>
{
return
web3
.
eth
.
getTransaction
(
txNumber
,
(
_error
,
tx
)
=>
{
if
(
_error
)
return
reject
(
_error
)
if
(
_error
)
return
reject
(
_error
)
if
(
!
tx
)
return
reject
(
'cannot find transaction '
+
txNumber
)
if
(
!
tx
)
return
reject
(
new
Error
(
'cannot find transaction '
+
txNumber
)
)
this
.
debugTx
(
tx
,
loadingCb
)
this
.
debugTx
(
tx
,
loadingCb
)
return
resolve
()
return
resolve
()
})
})
}
}
web3
.
eth
.
getTransactionFromBlock
(
blockNumber
,
txNumber
,
(
_error
,
tx
)
=>
{
web3
.
eth
.
getTransactionFromBlock
(
blockNumber
,
txNumber
,
(
_error
,
tx
)
=>
{
if
(
_error
)
return
reject
(
_error
)
if
(
_error
)
return
reject
(
_error
)
if
(
!
tx
)
return
reject
(
'cannot find transaction '
+
blockNumber
+
' '
+
txNumber
)
if
(
!
tx
)
return
reject
(
new
Error
(
'cannot find transaction '
+
blockNumber
+
' '
+
txNumber
)
)
this
.
debugTx
(
tx
,
loadingCb
)
this
.
debugTx
(
tx
,
loadingCb
)
return
resolve
()
return
resolve
()
})
})
...
...
libs/remix-debug/src/debugger/solidityLocals.ts
View file @
399a57d8
...
@@ -3,7 +3,6 @@ import { solidityLocals } from '../solidity-decoder/localDecoder'
...
@@ -3,7 +3,6 @@ import { solidityLocals } from '../solidity-decoder/localDecoder'
import
{
StorageViewer
}
from
'../storage/storageViewer'
import
{
StorageViewer
}
from
'../storage/storageViewer'
export
class
DebuggerSolidityLocals
{
export
class
DebuggerSolidityLocals
{
event
event
stepManager
stepManager
internalTreeCall
internalTreeCall
...
@@ -75,14 +74,14 @@ export class DebuggerSolidityLocals {
...
@@ -75,14 +74,14 @@ export class DebuggerSolidityLocals {
var
storageViewer
=
new
StorageViewer
({
stepIndex
:
this
.
stepManager
.
currentStepIndex
,
tx
:
this
.
tx
,
address
:
result
[
2
].
value
},
this
.
storageResolver
,
this
.
traceManager
)
var
storageViewer
=
new
StorageViewer
({
stepIndex
:
this
.
stepManager
.
currentStepIndex
,
tx
:
this
.
tx
,
address
:
result
[
2
].
value
},
this
.
storageResolver
,
this
.
traceManager
)
solidityLocals
(
this
.
stepManager
.
currentStepIndex
,
this
.
internalTreeCall
,
stack
,
memory
,
storageViewer
,
sourceLocation
,
cursor
).
then
((
locals
)
=>
{
solidityLocals
(
this
.
stepManager
.
currentStepIndex
,
this
.
internalTreeCall
,
stack
,
memory
,
storageViewer
,
sourceLocation
,
cursor
).
then
((
locals
)
=>
{
if
(
!
cursor
)
{
if
(
!
cursor
)
{
if
(
!
locals
[
'error'
]
)
{
if
(
!
locals
.
error
)
{
this
.
event
.
trigger
(
'solidityLocals'
,
[
locals
])
this
.
event
.
trigger
(
'solidityLocals'
,
[
locals
])
}
}
if
(
!
Object
.
keys
(
locals
).
length
)
{
if
(
!
Object
.
keys
(
locals
).
length
)
{
this
.
event
.
trigger
(
'solidityLocalsMessage'
,
[
'no locals'
])
this
.
event
.
trigger
(
'solidityLocalsMessage'
,
[
'no locals'
])
}
}
}
else
{
}
else
{
if
(
!
locals
[
'error'
]
)
{
if
(
!
locals
.
error
)
{
this
.
event
.
trigger
(
'solidityLocalsLoadMoreCompleted'
,
[
locals
])
this
.
event
.
trigger
(
'solidityLocalsLoadMoreCompleted'
,
[
locals
])
}
}
}
}
...
...
libs/remix-debug/src/debugger/solidityState.ts
View file @
399a57d8
...
@@ -3,7 +3,6 @@ import { decodeState } from '../solidity-decoder/stateDecoder'
...
@@ -3,7 +3,6 @@ import { decodeState } from '../solidity-decoder/stateDecoder'
import
{
StorageViewer
}
from
'../storage/storageViewer'
import
{
StorageViewer
}
from
'../storage/storageViewer'
export
class
DebuggerSolidityState
{
export
class
DebuggerSolidityState
{
event
event
storageResolver
storageResolver
stepManager
stepManager
...
@@ -78,8 +77,8 @@ export class DebuggerSolidityState {
...
@@ -78,8 +77,8 @@ export class DebuggerSolidityState {
const
storageViewer
=
new
StorageViewer
({
stepIndex
:
this
.
stepManager
.
currentStepIndex
,
tx
:
this
.
tx
,
address
:
address
},
this
.
storageResolver
,
this
.
traceManager
)
const
storageViewer
=
new
StorageViewer
({
stepIndex
:
this
.
stepManager
.
currentStepIndex
,
tx
:
this
.
tx
,
address
:
address
},
this
.
storageResolver
,
this
.
traceManager
)
decodeState
(
stateVars
,
storageViewer
).
then
((
result
)
=>
{
decodeState
(
stateVars
,
storageViewer
).
then
((
result
)
=>
{
this
.
event
.
trigger
(
'solidityStateMessage'
,
[
''
])
this
.
event
.
trigger
(
'solidityStateMessage'
,
[
''
])
if
(
result
[
'error'
]
)
{
if
(
result
.
error
)
{
return
this
.
event
.
trigger
(
'solidityStateMessage'
,
[
result
[
'error'
]
])
return
this
.
event
.
trigger
(
'solidityStateMessage'
,
[
result
.
error
])
}
}
this
.
event
.
trigger
(
'solidityState'
,
[
result
])
this
.
event
.
trigger
(
'solidityState'
,
[
result
])
})
})
...
...
libs/remix-debug/src/debugger/stepManager.ts
View file @
399a57d8
...
@@ -2,7 +2,6 @@ import { util } from '@remix-project/remix-lib'
...
@@ -2,7 +2,6 @@ import { util } from '@remix-project/remix-lib'
import
{
EventManager
}
from
'../eventManager'
import
{
EventManager
}
from
'../eventManager'
export
class
DebuggerStepManager
{
export
class
DebuggerStepManager
{
event
event
debugger
debugger
traceManager
traceManager
...
@@ -52,7 +51,7 @@ export class DebuggerStepManager {
...
@@ -52,7 +51,7 @@ export class DebuggerStepManager {
this
.
traceManager
.
buildCallPath
(
index
).
then
((
callsPath
)
=>
{
this
.
traceManager
.
buildCallPath
(
index
).
then
((
callsPath
)
=>
{
this
.
currentCall
=
callsPath
[
callsPath
.
length
-
1
]
this
.
currentCall
=
callsPath
[
callsPath
.
length
-
1
]
if
(
this
.
currentCall
.
reverted
)
{
if
(
this
.
currentCall
.
reverted
)
{
le
t
revertedReason
=
this
.
currentCall
.
outofgas
?
'outofgas'
:
''
cons
t
revertedReason
=
this
.
currentCall
.
outofgas
?
'outofgas'
:
''
this
.
revertionPoint
=
this
.
currentCall
.
return
this
.
revertionPoint
=
this
.
currentCall
.
return
return
this
.
event
.
trigger
(
'revertWarning'
,
[
revertedReason
])
return
this
.
event
.
trigger
(
'revertWarning'
,
[
revertedReason
])
}
}
...
@@ -82,7 +81,7 @@ export class DebuggerStepManager {
...
@@ -82,7 +81,7 @@ export class DebuggerStepManager {
stepState
=
'end'
stepState
=
'end'
}
}
le
t
jumpOutDisabled
=
(
step
===
this
.
traceManager
.
findStepOut
(
step
))
cons
t
jumpOutDisabled
=
(
step
===
this
.
traceManager
.
findStepOut
(
step
))
this
.
event
.
trigger
(
'stepChanged'
,
[
step
,
stepState
,
jumpOutDisabled
])
this
.
event
.
trigger
(
'stepChanged'
,
[
step
,
stepState
,
jumpOutDisabled
])
})
})
...
@@ -128,7 +127,7 @@ export class DebuggerStepManager {
...
@@ -128,7 +127,7 @@ export class DebuggerStepManager {
if
(
!
this
.
traceManager
.
isLoaded
())
return
if
(
!
this
.
traceManager
.
isLoaded
())
return
if
(
this
.
currentStepIndex
>=
this
.
traceLength
-
1
)
return
if
(
this
.
currentStepIndex
>=
this
.
traceLength
-
1
)
return
let
step
=
this
.
currentStepIndex
+
1
let
step
=
this
.
currentStepIndex
+
1
le
t
scope
=
this
.
debugger
.
callTree
.
findScope
(
step
)
cons
t
scope
=
this
.
debugger
.
callTree
.
findScope
(
step
)
if
(
scope
&&
scope
.
firstStep
===
step
)
{
if
(
scope
&&
scope
.
firstStep
===
step
)
{
step
=
scope
.
lastStep
+
1
step
=
scope
.
lastStep
+
1
}
}
...
@@ -168,7 +167,7 @@ export class DebuggerStepManager {
...
@@ -168,7 +167,7 @@ export class DebuggerStepManager {
}
}
calculateFirstStep
()
{
calculateFirstStep
()
{
le
t
step
=
this
.
resolveToReducedTrace
(
0
,
1
)
cons
t
step
=
this
.
resolveToReducedTrace
(
0
,
1
)
return
this
.
resolveToReducedTrace
(
step
,
1
)
return
this
.
resolveToReducedTrace
(
step
,
1
)
}
}
...
@@ -176,7 +175,7 @@ export class DebuggerStepManager {
...
@@ -176,7 +175,7 @@ export class DebuggerStepManager {
let
step
=
0
let
step
=
0
let
steps
=
[]
let
steps
=
[]
while
(
step
<
this
.
traceLength
)
{
while
(
step
<
this
.
traceLength
)
{
le
t
_step
=
this
.
resolveToReducedTrace
(
step
,
1
)
cons
t
_step
=
this
.
resolveToReducedTrace
(
step
,
1
)
if
(
!
_step
)
break
if
(
!
_step
)
break
steps
.
push
(
_step
)
steps
.
push
(
_step
)
step
+=
1
step
+=
1
...
@@ -211,5 +210,4 @@ export class DebuggerStepManager {
...
@@ -211,5 +210,4 @@ export class DebuggerStepManager {
}
}
return
this
.
debugger
.
callTree
.
reducedTrace
[
nextSource
]
return
this
.
debugger
.
callTree
.
reducedTrace
[
nextSource
]
}
}
}
}
libs/remix-debug/src/eventManager.ts
View file @
399a57d8
'use strict'
'use strict'
export
class
EventManager
{
export
class
EventManager
{
registered
registered
anonymous
anonymous
constructor
()
{
constructor
()
{
this
.
registered
=
{}
this
.
registered
=
{}
this
.
anonymous
=
{}
this
.
anonymous
=
{}
}
}
...
@@ -26,7 +25,7 @@ export class EventManager {
...
@@ -26,7 +25,7 @@ export class EventManager {
func
=
obj
func
=
obj
obj
=
this
.
anonymous
obj
=
this
.
anonymous
}
}
for
(
le
t
reg
in
this
.
registered
[
eventName
])
{
for
(
cons
t
reg
in
this
.
registered
[
eventName
])
{
if
(
this
.
registered
[
eventName
][
reg
].
obj
===
obj
&&
this
.
registered
[
eventName
][
reg
].
func
===
func
)
{
if
(
this
.
registered
[
eventName
][
reg
].
obj
===
obj
&&
this
.
registered
[
eventName
][
reg
].
func
===
func
)
{
this
.
registered
[
eventName
].
splice
(
reg
,
1
)
this
.
registered
[
eventName
].
splice
(
reg
,
1
)
}
}
...
@@ -66,7 +65,7 @@ export class EventManager {
...
@@ -66,7 +65,7 @@ export class EventManager {
if
(
!
this
.
registered
[
eventName
])
{
if
(
!
this
.
registered
[
eventName
])
{
return
return
}
}
for
(
le
t
listener
in
this
.
registered
[
eventName
])
{
for
(
cons
t
listener
in
this
.
registered
[
eventName
])
{
const
l
=
this
.
registered
[
eventName
][
listener
]
const
l
=
this
.
registered
[
eventName
][
listener
]
l
.
func
.
apply
(
l
.
obj
===
this
.
anonymous
?
{}
:
l
.
obj
,
args
)
l
.
func
.
apply
(
l
.
obj
===
this
.
anonymous
?
{}
:
l
.
obj
,
args
)
}
}
...
...
libs/remix-debug/src/init.ts
View file @
399a57d8
...
@@ -19,11 +19,11 @@ export function setProvider (web3, url) {
...
@@ -19,11 +19,11 @@ export function setProvider (web3, url) {
export
function
web3DebugNode
(
network
)
{
export
function
web3DebugNode
(
network
)
{
const
web3DebugNodes
=
{
const
web3DebugNodes
=
{
'Main'
:
'https://rpc.archivenode.io/e50zmkroshle2e2e50zm0044i7ao04ym'
,
Main
:
'https://rpc.archivenode.io/e50zmkroshle2e2e50zm0044i7ao04ym'
,
'Rinkeby'
:
'https://remix-rinkeby.ethdevops.io'
,
Rinkeby
:
'https://remix-rinkeby.ethdevops.io'
,
'Ropsten'
:
'https://remix-ropsten.ethdevops.io'
,
Ropsten
:
'https://remix-ropsten.ethdevops.io'
,
'Goerli'
:
'https://remix-goerli.ethdevops.io'
,
Goerli
:
'https://remix-goerli.ethdevops.io'
,
'Kovan'
:
'https://remix-kovan.ethdevops.io'
Kovan
:
'https://remix-kovan.ethdevops.io'
}
}
if
(
web3DebugNodes
[
network
])
{
if
(
web3DebugNodes
[
network
])
{
return
loadWeb3
(
web3DebugNodes
[
network
])
return
loadWeb3
(
web3DebugNodes
[
network
])
...
@@ -71,4 +71,3 @@ export function extend (web3) {
...
@@ -71,4 +71,3 @@ export function extend (web3) {
})
})
}
}
}
}
libs/remix-debug/src/solidity-decoder/astHelper.ts
View file @
399a57d8
...
@@ -14,7 +14,7 @@ export function extractContractDefinitions (sourcesList) {
...
@@ -14,7 +14,7 @@ export function extractContractDefinitions (sourcesList) {
sourcesByContract
:
{}
sourcesByContract
:
{}
}
}
const
walker
=
new
AstWalker
()
const
walker
=
new
AstWalker
()
for
(
le
t
k
in
sourcesList
)
{
for
(
cons
t
k
in
sourcesList
)
{
walker
.
walkFull
(
sourcesList
[
k
].
ast
,
(
node
)
=>
{
walker
.
walkFull
(
sourcesList
[
k
].
ast
,
(
node
)
=>
{
if
(
node
.
nodeType
===
'ContractDefinition'
)
{
if
(
node
.
nodeType
===
'ContractDefinition'
)
{
ret
.
contractsById
[
node
.
id
]
=
node
ret
.
contractsById
[
node
.
id
]
=
node
...
@@ -58,9 +58,9 @@ export function extractStateDefinitions (contractName, sourcesList, contracts) {
...
@@ -58,9 +58,9 @@ export function extractStateDefinitions (contractName, sourcesList, contracts) {
const
stateVar
=
[]
const
stateVar
=
[]
const
baseContracts
=
getLinearizedBaseContracts
(
node
.
id
,
contracts
.
contractsById
)
const
baseContracts
=
getLinearizedBaseContracts
(
node
.
id
,
contracts
.
contractsById
)
baseContracts
.
reverse
()
baseContracts
.
reverse
()
for
(
le
t
k
in
baseContracts
)
{
for
(
cons
t
k
in
baseContracts
)
{
const
ctr
=
baseContracts
[
k
]
const
ctr
=
baseContracts
[
k
]
for
(
le
t
i
in
ctr
.
nodes
)
{
for
(
cons
t
i
in
ctr
.
nodes
)
{
const
item
=
ctr
.
nodes
[
i
]
const
item
=
ctr
.
nodes
[
i
]
stateItems
.
push
(
item
)
stateItems
.
push
(
item
)
if
(
item
.
nodeType
===
'VariableDeclaration'
)
{
if
(
item
.
nodeType
===
'VariableDeclaration'
)
{
...
@@ -68,7 +68,7 @@ export function extractStateDefinitions (contractName, sourcesList, contracts) {
...
@@ -68,7 +68,7 @@ export function extractStateDefinitions (contractName, sourcesList, contracts) {
}
}
}
}
}
}
return
{
stateDefinitions
:
stateItems
,
stateVariables
:
stateVar
}
return
{
stateDefinitions
:
stateItems
,
stateVariables
:
stateVar
}
}
}
/**
/**
...
@@ -83,7 +83,7 @@ export function extractStatesDefinitions (sourcesList, contracts) {
...
@@ -83,7 +83,7 @@ export function extractStatesDefinitions (sourcesList, contracts) {
contracts
=
extractContractDefinitions
(
sourcesList
)
contracts
=
extractContractDefinitions
(
sourcesList
)
}
}
const
ret
=
{}
const
ret
=
{}
for
(
le
t
contract
in
contracts
.
contractsById
)
{
for
(
cons
t
contract
in
contracts
.
contractsById
)
{
const
name
=
contracts
.
contractsById
[
contract
].
name
const
name
=
contracts
.
contractsById
[
contract
].
name
const
source
=
contracts
.
sourcesByContract
[
contract
]
const
source
=
contracts
.
sourcesByContract
[
contract
]
const
fullName
=
source
+
':'
+
name
const
fullName
=
source
+
':'
+
name
...
@@ -93,4 +93,3 @@ export function extractStatesDefinitions (sourcesList, contracts) {
...
@@ -93,4 +93,3 @@ export function extractStatesDefinitions (sourcesList, contracts) {
}
}
return
ret
return
ret
}
}
libs/remix-debug/src/solidity-decoder/decodeInfo.ts
View file @
399a57d8
...
@@ -28,8 +28,8 @@ function mapping (type, stateDefinitions, contractName) {
...
@@ -28,8 +28,8 @@ function mapping (type, stateDefinitions, contractName) {
const
valueType
=
parseType
(
valueTypeName
,
stateDefinitions
,
contractName
,
'storage'
)
const
valueType
=
parseType
(
valueTypeName
,
stateDefinitions
,
contractName
,
'storage'
)
var
underlyingTypes
=
{
var
underlyingTypes
=
{
'keyType'
:
keyType
,
keyType
:
keyType
,
'valueType'
:
valueType
valueType
:
valueType
}
}
return
new
MappingType
(
underlyingTypes
,
'location'
,
removeLocation
(
type
))
return
new
MappingType
(
underlyingTypes
,
'location'
,
removeLocation
(
type
))
}
}
...
@@ -41,7 +41,7 @@ function mapping (type, stateDefinitions, contractName) {
...
@@ -41,7 +41,7 @@ function mapping (type, stateDefinitions, contractName) {
* @return {Object} returns decoded info about the current type: { storageBytes, typeName}
* @return {Object} returns decoded info about the current type: { storageBytes, typeName}
*/
*/
function
uint
(
type
)
{
function
uint
(
type
)
{
type
===
'uint'
?
'uint256'
:
type
type
=
type
=
==
'uint'
?
'uint256'
:
type
const
storageBytes
=
parseInt
(
type
.
replace
(
'uint'
,
''
))
/
8
const
storageBytes
=
parseInt
(
type
.
replace
(
'uint'
,
''
))
/
8
return
new
UintType
(
storageBytes
)
return
new
UintType
(
storageBytes
)
}
}
...
@@ -53,7 +53,7 @@ function uint (type) {
...
@@ -53,7 +53,7 @@ function uint (type) {
* @return {Object} returns decoded info about the current type: { storageBytes, typeName}
* @return {Object} returns decoded info about the current type: { storageBytes, typeName}
*/
*/
function
int
(
type
)
{
function
int
(
type
)
{
type
===
'int'
?
'int256'
:
type
type
=
type
=
==
'int'
?
'int256'
:
type
const
storageBytes
=
parseInt
(
type
.
replace
(
'int'
,
''
))
/
8
const
storageBytes
=
parseInt
(
type
.
replace
(
'int'
,
''
))
/
8
return
new
IntType
(
storageBytes
)
return
new
IntType
(
storageBytes
)
}
}
...
@@ -139,7 +139,6 @@ function stringType (type, stateDefinitions, contractName, location) {
...
@@ -139,7 +139,6 @@ function stringType (type, stateDefinitions, contractName, location) {
* @return {Object} returns decoded info about the current type: { storageBytes, typeName, arraySize, subArray}
* @return {Object} returns decoded info about the current type: { storageBytes, typeName, arraySize, subArray}
*/
*/
function
array
(
type
,
stateDefinitions
,
contractName
,
location
)
{
function
array
(
type
,
stateDefinitions
,
contractName
,
location
)
{
let
arraySize
const
match
=
type
.
match
(
/
(
.*
)\[(
.*
?)\](
storage ref| storage pointer| memory| calldata
)?
$/
)
const
match
=
type
.
match
(
/
(
.*
)\[(
.*
?)\](
storage ref| storage pointer| memory| calldata
)?
$/
)
if
(
!
match
)
{
if
(
!
match
)
{
console
.
log
(
'unable to parse type '
+
type
)
console
.
log
(
'unable to parse type '
+
type
)
...
@@ -148,7 +147,7 @@ function array (type, stateDefinitions, contractName, location) {
...
@@ -148,7 +147,7 @@ function array (type, stateDefinitions, contractName, location) {
if
(
!
location
)
{
if
(
!
location
)
{
location
=
match
[
3
].
trim
()
location
=
match
[
3
].
trim
()
}
}
arraySize
=
match
[
2
]
===
''
?
'dynamic'
:
parseInt
(
match
[
2
])
const
arraySize
=
match
[
2
]
===
''
?
'dynamic'
:
parseInt
(
match
[
2
])
const
underlyingType
=
parseType
(
match
[
1
],
stateDefinitions
,
contractName
,
location
)
const
underlyingType
=
parseType
(
match
[
1
],
stateDefinitions
,
contractName
,
location
)
if
(
underlyingType
===
null
)
{
if
(
underlyingType
===
null
)
{
console
.
log
(
'unable to parse type '
+
type
)
console
.
log
(
'unable to parse type '
+
type
)
...
@@ -215,7 +214,7 @@ function getEnum (type, stateDefinitions, contractName) {
...
@@ -215,7 +214,7 @@ function getEnum (type, stateDefinitions, contractName) {
}
}
const
state
=
stateDefinitions
[
contractName
]
const
state
=
stateDefinitions
[
contractName
]
if
(
state
)
{
if
(
state
)
{
for
(
le
t
dec
of
state
.
stateDefinitions
)
{
for
(
cons
t
dec
of
state
.
stateDefinitions
)
{
if
(
dec
&&
dec
.
name
&&
type
===
contractName
+
'.'
+
dec
.
name
)
{
if
(
dec
&&
dec
.
name
&&
type
===
contractName
+
'.'
+
dec
.
name
)
{
return
dec
return
dec
}
}
...
@@ -242,7 +241,7 @@ function getStructMembers (type, stateDefinitions, contractName, location) {
...
@@ -242,7 +241,7 @@ function getStructMembers (type, stateDefinitions, contractName, location) {
}
}
const
state
=
stateDefinitions
[
contractName
]
const
state
=
stateDefinitions
[
contractName
]
if
(
state
)
{
if
(
state
)
{
for
(
le
t
dec
of
state
.
stateDefinitions
)
{
for
(
cons
t
dec
of
state
.
stateDefinitions
)
{
if
(
dec
.
nodeType
===
'StructDefinition'
&&
type
===
contractName
+
'.'
+
dec
.
name
)
{
if
(
dec
.
nodeType
===
'StructDefinition'
&&
type
===
contractName
+
'.'
+
dec
.
name
)
{
const
offsets
=
computeOffsets
(
dec
.
members
,
stateDefinitions
,
contractName
,
location
)
const
offsets
=
computeOffsets
(
dec
.
members
,
stateDefinitions
,
contractName
,
location
)
if
(
!
offsets
)
{
if
(
!
offsets
)
{
...
@@ -290,18 +289,18 @@ function typeClass (fullType) {
...
@@ -290,18 +289,18 @@ function typeClass (fullType) {
*/
*/
function
parseType
(
type
,
stateDefinitions
,
contractName
,
location
)
{
function
parseType
(
type
,
stateDefinitions
,
contractName
,
location
)
{
const
decodeInfos
=
{
const
decodeInfos
=
{
'contract'
:
address
,
contract
:
address
,
'address'
:
address
,
address
:
address
,
'array'
:
array
,
array
:
array
,
'bool'
:
bool
,
bool
:
bool
,
'bytes'
:
dynamicByteArray
,
bytes
:
dynamicByteArray
,
'bytesX'
:
fixedByteArray
,
bytesX
:
fixedByteArray
,
'enum'
:
enumType
,
enum
:
enumType
,
'string'
:
stringType
,
string
:
stringType
,
'struct'
:
struct
,
struct
:
struct
,
'int'
:
int
,
int
:
int
,
'uint'
:
uint
,
uint
:
uint
,
'mapping'
:
mapping
mapping
:
mapping
}
}
const
currentType
=
typeClass
(
type
)
const
currentType
=
typeClass
(
type
)
if
(
currentType
===
null
)
{
if
(
currentType
===
null
)
{
...
...
libs/remix-debug/src/solidity-decoder/internalCallTree.ts
View file @
399a57d8
...
@@ -13,7 +13,6 @@ import { extractLocationFromAstVariable } from './types/util.js'
...
@@ -13,7 +13,6 @@ import { extractLocationFromAstVariable } from './types/util.js'
* Triggers `callTreeBuildFailed` event when tree fails to build
* Triggers `callTreeBuildFailed` event when tree fails to build
*/
*/
export
class
InternalCallTree
{
export
class
InternalCallTree
{
includeLocalVariables
includeLocalVariables
debugWithGeneratedSources
debugWithGeneratedSources
event
event
...
@@ -121,21 +120,21 @@ export class InternalCallTree {
...
@@ -121,21 +120,21 @@ export class InternalCallTree {
}
}
retrieveFunctionsStack
(
vmtraceIndex
)
{
retrieveFunctionsStack
(
vmtraceIndex
)
{
le
t
scope
=
this
.
findScope
(
vmtraceIndex
)
cons
t
scope
=
this
.
findScope
(
vmtraceIndex
)
if
(
!
scope
)
return
[]
if
(
!
scope
)
return
[]
let
scopeId
=
this
.
scopeStarts
[
scope
.
firstStep
]
let
scopeId
=
this
.
scopeStarts
[
scope
.
firstStep
]
le
t
functions
=
[]
cons
t
functions
=
[]
if
(
!
scopeId
)
return
functions
if
(
!
scopeId
)
return
functions
let
i
=
0
let
i
=
0
// eslint-disable-next-line no-constant-condition
// eslint-disable-next-line no-constant-condition
while
(
true
)
{
while
(
true
)
{
i
+=
1
i
+=
1
if
(
i
>
1000
)
throw
new
Error
(
'retrieFunctionStack: recursion too deep'
)
if
(
i
>
1000
)
throw
new
Error
(
'retrieFunctionStack: recursion too deep'
)
le
t
functionDefinition
=
this
.
functionDefinitionsByScope
[
scopeId
]
cons
t
functionDefinition
=
this
.
functionDefinitionsByScope
[
scopeId
]
if
(
functionDefinition
!==
undefined
)
{
if
(
functionDefinition
!==
undefined
)
{
functions
.
push
(
functionDefinition
)
functions
.
push
(
functionDefinition
)
}
}
le
t
parent
=
this
.
parentScope
(
scopeId
)
cons
t
parent
=
this
.
parentScope
(
scopeId
)
if
(
!
parent
)
break
if
(
!
parent
)
break
else
scopeId
=
parent
else
scopeId
=
parent
}
}
...
@@ -294,8 +293,8 @@ async function includeVariableDeclaration (tree, step, sourceLocation, scopeId,
...
@@ -294,8 +293,8 @@ async function includeVariableDeclaration (tree, step, sourceLocation, scopeId,
const
stack
=
tree
.
traceManager
.
getStackAt
(
step
)
const
stack
=
tree
.
traceManager
.
getStackAt
(
step
)
states
=
tree
.
solidityProxy
.
extractStatesDefinitions
()
states
=
tree
.
solidityProxy
.
extractStatesDefinitions
()
if
(
functionDefinition
.
parameters
)
{
if
(
functionDefinition
.
parameters
)
{
le
t
inputs
=
functionDefinition
.
parameters
cons
t
inputs
=
functionDefinition
.
parameters
le
t
outputs
=
functionDefinition
.
returnParameters
cons
t
outputs
=
functionDefinition
.
returnParameters
// for (const element of functionDefinition.parameters) {
// for (const element of functionDefinition.parameters) {
// if (element.nodeType === 'ParameterList') {
// if (element.nodeType === 'ParameterList') {
// if (!inputs) inputs = element
// if (!inputs) inputs = element
...
@@ -369,8 +368,8 @@ function extractFunctionDefinitions (ast, astWalker) {
...
@@ -369,8 +368,8 @@ function extractFunctionDefinitions (ast, astWalker) {
}
}
function
addParams
(
parameterList
,
tree
,
scopeId
,
states
,
contractName
,
sourceLocation
,
stackLength
,
stackPosition
,
dir
)
{
function
addParams
(
parameterList
,
tree
,
scopeId
,
states
,
contractName
,
sourceLocation
,
stackLength
,
stackPosition
,
dir
)
{
le
t
params
=
[]
cons
t
params
=
[]
for
(
le
t
inputParam
in
parameterList
.
parameters
)
{
for
(
cons
t
inputParam
in
parameterList
.
parameters
)
{
const
param
=
parameterList
.
parameters
[
inputParam
]
const
param
=
parameterList
.
parameters
[
inputParam
]
const
stackDepth
=
stackLength
+
(
dir
*
stackPosition
)
const
stackDepth
=
stackLength
+
(
dir
*
stackPosition
)
if
(
stackDepth
>=
0
)
{
if
(
stackDepth
>=
0
)
{
...
...
libs/remix-debug/src/solidity-decoder/localDecoder.ts
View file @
399a57d8
...
@@ -3,13 +3,13 @@
...
@@ -3,13 +3,13 @@
export
async
function
solidityLocals
(
vmtraceIndex
,
internalTreeCall
,
stack
,
memory
,
storageResolver
,
currentSourceLocation
,
cursor
)
{
export
async
function
solidityLocals
(
vmtraceIndex
,
internalTreeCall
,
stack
,
memory
,
storageResolver
,
currentSourceLocation
,
cursor
)
{
const
scope
=
internalTreeCall
.
findScope
(
vmtraceIndex
)
const
scope
=
internalTreeCall
.
findScope
(
vmtraceIndex
)
if
(
!
scope
)
{
if
(
!
scope
)
{
const
error
=
{
'message'
:
'Can
\'
t display locals. reason: compilation result might not have been provided'
}
const
error
=
{
message
:
'Can
\'
t display locals. reason: compilation result might not have been provided'
}
throw
error
throw
error
}
}
const
locals
=
{}
const
locals
=
{}
memory
=
formatMemory
(
memory
)
memory
=
formatMemory
(
memory
)
let
anonymousIncr
=
1
let
anonymousIncr
=
1
for
(
le
t
local
in
scope
.
locals
)
{
for
(
cons
t
local
in
scope
.
locals
)
{
var
variable
=
scope
.
locals
[
local
]
var
variable
=
scope
.
locals
[
local
]
if
(
variable
.
stackDepth
<
stack
.
length
&&
variable
.
sourceLocation
.
start
<=
currentSourceLocation
.
start
)
{
if
(
variable
.
stackDepth
<
stack
.
length
&&
variable
.
sourceLocation
.
start
<=
currentSourceLocation
.
start
)
{
let
name
=
variable
.
name
let
name
=
variable
.
name
...
...
libs/remix-debug/src/solidity-decoder/solidityProxy.ts
View file @
399a57d8
...
@@ -5,14 +5,13 @@ import { extractStateVariables } from './stateDecoder'
...
@@ -5,14 +5,13 @@ import { extractStateVariables } from './stateDecoder'
import
{
extractContractDefinitions
,
extractStatesDefinitions
}
from
'./astHelper'
import
{
extractContractDefinitions
,
extractStatesDefinitions
}
from
'./astHelper'
export
class
SolidityProxy
{
export
class
SolidityProxy
{
cache
cache
getCurrentCalledAddressAt
getCurrentCalledAddressAt
getCode
getCode
sources
sources
contracts
contracts
constructor
({
getCurrentCalledAddressAt
,
getCode
})
{
constructor
({
getCurrentCalledAddressAt
,
getCode
})
{
this
.
cache
=
new
Cache
()
this
.
cache
=
new
Cache
()
this
.
reset
({})
this
.
reset
({})
this
.
getCurrentCalledAddressAt
=
getCurrentCalledAddressAt
this
.
getCurrentCalledAddressAt
=
getCurrentCalledAddressAt
...
@@ -127,8 +126,8 @@ export class SolidityProxy {
...
@@ -127,8 +126,8 @@ export class SolidityProxy {
function
contractObjectFromCode
(
contracts
,
code
,
address
)
{
function
contractObjectFromCode
(
contracts
,
code
,
address
)
{
const
isCreation
=
isContractCreation
(
address
)
const
isCreation
=
isContractCreation
(
address
)
for
(
le
t
file
in
contracts
)
{
for
(
cons
t
file
in
contracts
)
{
for
(
le
t
contract
in
contracts
[
file
])
{
for
(
cons
t
contract
in
contracts
[
file
])
{
const
bytecode
=
isCreation
?
contracts
[
file
][
contract
].
evm
.
bytecode
.
object
:
contracts
[
file
][
contract
].
evm
.
deployedBytecode
.
object
const
bytecode
=
isCreation
?
contracts
[
file
][
contract
].
evm
.
bytecode
.
object
:
contracts
[
file
][
contract
].
evm
.
deployedBytecode
.
object
if
(
util
.
compareByteCode
(
code
,
'0x'
+
bytecode
))
{
if
(
util
.
compareByteCode
(
code
,
'0x'
+
bytecode
))
{
return
{
name
:
contract
,
contract
:
contracts
[
file
][
contract
]
}
return
{
name
:
contract
,
contract
:
contracts
[
file
][
contract
]
}
...
@@ -139,7 +138,6 @@ function contractObjectFromCode (contracts, code, address) {
...
@@ -139,7 +138,6 @@ function contractObjectFromCode (contracts, code, address) {
}
}
class
Cache
{
class
Cache
{
contractObjectByAddress
contractObjectByAddress
stateVariablesByContractName
stateVariablesByContractName
contractDeclarations
contractDeclarations
...
@@ -148,6 +146,7 @@ class Cache {
...
@@ -148,6 +146,7 @@ class Cache {
constructor
()
{
constructor
()
{
this
.
reset
()
this
.
reset
()
}
}
reset
()
{
reset
()
{
this
.
contractObjectByAddress
=
{}
this
.
contractObjectByAddress
=
{}
this
.
stateVariablesByContractName
=
{}
this
.
stateVariablesByContractName
=
{}
...
...
libs/remix-debug/src/solidity-decoder/types/ArrayType.ts
View file @
399a57d8
...
@@ -6,7 +6,6 @@ import { RefType } from './RefType'
...
@@ -6,7 +6,6 @@ import { RefType } from './RefType'
const
sha3256
=
util
.
sha3_256
const
sha3256
=
util
.
sha3_256
export
class
ArrayType
extends
RefType
{
export
class
ArrayType
extends
RefType
{
underlyingType
underlyingType
arraySize
arraySize
...
@@ -72,7 +71,7 @@ export class ArrayType extends RefType {
...
@@ -72,7 +71,7 @@ export class ArrayType extends RefType {
currentLocation
.
offset
=
0
currentLocation
.
offset
=
0
}
}
}
}
return
{
value
:
ret
,
length
:
'0x'
+
size
.
toString
(
16
),
type
:
this
.
typeName
}
return
{
value
:
ret
,
length
:
'0x'
+
size
.
toString
(
16
),
type
:
this
.
typeName
}
}
}
decodeFromMemoryInternal
(
offset
,
memory
,
skip
)
{
decodeFromMemoryInternal
(
offset
,
memory
,
skip
)
{
...
...
libs/remix-debug/src/solidity-decoder/types/DynamicByteArray.ts
View file @
399a57d8
...
@@ -16,7 +16,7 @@ export class DynamicByteArray extends RefType {
...
@@ -16,7 +16,7 @@ export class DynamicByteArray extends RefType {
value
=
await
extractHexValue
(
location
,
storageResolver
,
this
.
storageBytes
)
value
=
await
extractHexValue
(
location
,
storageResolver
,
this
.
storageBytes
)
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
log
(
e
)
console
.
log
(
e
)
return
{
value
:
'<decoding failed - '
+
e
.
message
+
'>'
,
type
:
this
.
typeName
}
return
{
value
:
'<decoding failed - '
+
e
.
message
+
'>'
,
type
:
this
.
typeName
}
}
}
const
bn
=
new
BN
(
value
,
16
)
const
bn
=
new
BN
(
value
,
16
)
if
(
bn
.
testn
(
0
))
{
if
(
bn
.
testn
(
0
))
{
...
@@ -28,7 +28,7 @@ export class DynamicByteArray extends RefType {
...
@@ -28,7 +28,7 @@ export class DynamicByteArray extends RefType {
currentSlot
=
await
readFromStorage
(
dataPos
,
storageResolver
)
currentSlot
=
await
readFromStorage
(
dataPos
,
storageResolver
)
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
log
(
e
)
console
.
log
(
e
)
return
{
value
:
'<decoding failed - '
+
e
.
message
+
'>'
,
type
:
this
.
typeName
}
return
{
value
:
'<decoding failed - '
+
e
.
message
+
'>'
,
type
:
this
.
typeName
}
}
}
while
(
length
.
gt
(
new
BN
(
ret
.
length
))
&&
ret
.
length
<
32000
)
{
while
(
length
.
gt
(
new
BN
(
ret
.
length
))
&&
ret
.
length
<
32000
)
{
currentSlot
=
currentSlot
.
replace
(
'0x'
,
''
)
currentSlot
=
currentSlot
.
replace
(
'0x'
,
''
)
...
@@ -38,13 +38,13 @@ export class DynamicByteArray extends RefType {
...
@@ -38,13 +38,13 @@ export class DynamicByteArray extends RefType {
currentSlot
=
await
readFromStorage
(
dataPos
,
storageResolver
)
currentSlot
=
await
readFromStorage
(
dataPos
,
storageResolver
)
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
log
(
e
)
console
.
log
(
e
)
return
{
value
:
'<decoding failed - '
+
e
.
message
+
'>'
,
type
:
this
.
typeName
}
return
{
value
:
'<decoding failed - '
+
e
.
message
+
'>'
,
type
:
this
.
typeName
}
}
}
}
}
return
{
value
:
'0x'
+
ret
.
replace
(
/
(
00
)
+$/
,
''
),
length
:
'0x'
+
length
.
toString
(
16
),
type
:
this
.
typeName
}
return
{
value
:
'0x'
+
ret
.
replace
(
/
(
00
)
+$/
,
''
),
length
:
'0x'
+
length
.
toString
(
16
),
type
:
this
.
typeName
}
}
else
{
}
else
{
var
size
=
parseInt
(
value
.
substr
(
value
.
length
-
2
,
2
),
16
)
/
2
var
size
=
parseInt
(
value
.
substr
(
value
.
length
-
2
,
2
),
16
)
/
2
return
{
value
:
'0x'
+
value
.
substr
(
0
,
size
*
2
),
length
:
'0x'
+
size
.
toString
(
16
),
type
:
this
.
typeName
}
return
{
value
:
'0x'
+
value
.
substr
(
0
,
size
*
2
),
length
:
'0x'
+
size
.
toString
(
16
),
type
:
this
.
typeName
}
}
}
}
}
...
@@ -52,7 +52,6 @@ export class DynamicByteArray extends RefType {
...
@@ -52,7 +52,6 @@ export class DynamicByteArray extends RefType {
offset
=
2
*
offset
offset
=
2
*
offset
let
length
=
memory
.
substr
(
offset
,
64
)
let
length
=
memory
.
substr
(
offset
,
64
)
length
=
2
*
parseInt
(
length
,
16
)
length
=
2
*
parseInt
(
length
,
16
)
return
{
length
:
'0x'
+
length
.
toString
(
16
),
value
:
'0x'
+
memory
.
substr
(
offset
+
64
,
length
),
type
:
this
.
typeName
}
return
{
length
:
'0x'
+
length
.
toString
(
16
),
value
:
'0x'
+
memory
.
substr
(
offset
+
64
,
length
),
type
:
this
.
typeName
}
}
}
}
}
libs/remix-debug/src/solidity-decoder/types/Enum.ts
View file @
399a57d8
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
import
{
ValueType
}
from
'./ValueType'
import
{
ValueType
}
from
'./ValueType'
export
class
Enum
extends
ValueType
{
export
class
Enum
extends
ValueType
{
enumDef
enumDef
constructor
(
enumDef
)
{
constructor
(
enumDef
)
{
...
...
libs/remix-debug/src/solidity-decoder/types/Mapping.ts
View file @
399a57d8
'use strict'
'use strict'
import
{
RefType
}
from
'./RefType'
import
{
RefType
}
from
'./RefType'
import
{
normalizeHex
}
from
'./util'
import
{
normalizeHex
}
from
'./util'
import
{
toBuffer
,
setLengthLeft
,
keccak
,
BN
,
bufferToHex
}
from
'ethereumjs-util'
import
{
toBuffer
,
setLengthLeft
,
keccak
,
BN
,
bufferToHex
}
from
'ethereumjs-util'
import
{
intToBuffer
}
from
'ethjs-util'
import
{
intToBuffer
}
from
'ethjs-util'
export
class
Mapping
extends
RefType
{
export
class
Mapping
extends
RefType
{
keyType
keyType
valueType
valueType
initialDecodedState
initialDecodedState
...
@@ -34,13 +33,13 @@ export class Mapping extends RefType {
...
@@ -34,13 +33,13 @@ export class Mapping extends RefType {
const
mappingPreimages
=
await
storageResolver
.
mappingsLocation
(
corrections
)
const
mappingPreimages
=
await
storageResolver
.
mappingsLocation
(
corrections
)
let
ret
=
await
this
.
decodeMappingsLocation
(
mappingPreimages
,
location
,
storageResolver
)
// fetch mapping storage changes
let
ret
=
await
this
.
decodeMappingsLocation
(
mappingPreimages
,
location
,
storageResolver
)
// fetch mapping storage changes
ret
=
Object
.
assign
({},
this
.
initialDecodedState
,
ret
)
// merge changes
ret
=
Object
.
assign
({},
this
.
initialDecodedState
,
ret
)
// merge changes
return
{
value
:
ret
,
type
:
this
.
typeName
}
return
{
value
:
ret
,
type
:
this
.
typeName
}
}
}
decodeFromMemoryInternal
(
offset
,
memory
)
{
decodeFromMemoryInternal
(
offset
,
memory
)
{
// mappings can only exist in storage and not in memory
// mappings can only exist in storage and not in memory
// so this should never be called
// so this should never be called
return
{
value
:
'<not implemented>'
,
length
:
'0x'
,
type
:
this
.
typeName
}
return
{
value
:
'<not implemented>'
,
length
:
'0x'
,
type
:
this
.
typeName
}
}
}
async
decodeMappingsLocation
(
preimages
,
location
,
storageResolver
)
{
async
decodeMappingsLocation
(
preimages
,
location
,
storageResolver
)
{
...
@@ -49,7 +48,7 @@ export class Mapping extends RefType {
...
@@ -49,7 +48,7 @@ export class Mapping extends RefType {
return
{}
return
{}
}
}
const
ret
=
{}
const
ret
=
{}
for
(
le
t
i
in
preimages
[
mapSlot
])
{
for
(
cons
t
i
in
preimages
[
mapSlot
])
{
const
mapLocation
=
getMappingLocation
(
i
,
location
.
slot
)
const
mapLocation
=
getMappingLocation
(
i
,
location
.
slot
)
const
globalLocation
=
{
const
globalLocation
=
{
offset
:
location
.
offset
,
offset
:
location
.
offset
,
...
@@ -71,13 +70,13 @@ function getMappingLocation (key, position) {
...
@@ -71,13 +70,13 @@ function getMappingLocation (key, position) {
mappingP
=
setLengthLeft
(
mappingP
,
32
)
mappingP
=
setLengthLeft
(
mappingP
,
32
)
const
mappingKeyBuf
=
concatTypedArrays
(
mappingK
,
mappingP
)
const
mappingKeyBuf
=
concatTypedArrays
(
mappingK
,
mappingP
)
const
mappingKeyPreimage
:
string
=
'0x'
+
mappingKeyBuf
.
toString
(
'hex'
)
const
mappingKeyPreimage
:
string
=
'0x'
+
mappingKeyBuf
.
toString
(
'hex'
)
le
t
mappingStorageLocation
:
Buffer
=
keccak
(
mappingKeyPreimage
)
cons
t
mappingStorageLocation
:
Buffer
=
keccak
(
mappingKeyPreimage
)
const
mappingStorageLocationinBn
:
BN
=
new
BN
(
mappingStorageLocation
,
16
)
const
mappingStorageLocationinBn
:
BN
=
new
BN
(
mappingStorageLocation
,
16
)
return
mappingStorageLocationinBn
return
mappingStorageLocationinBn
}
}
function
concatTypedArrays
(
a
,
b
)
{
// a, b TypedArray of same type
function
concatTypedArrays
(
a
,
b
)
{
// a, b TypedArray of same type
le
t
c
=
new
(
a
.
constructor
)(
a
.
length
+
b
.
length
)
cons
t
c
=
new
(
a
.
constructor
)(
a
.
length
+
b
.
length
)
c
.
set
(
a
,
0
)
c
.
set
(
a
,
0
)
c
.
set
(
b
,
a
.
length
)
c
.
set
(
b
,
a
.
length
)
return
c
return
c
...
...
libs/remix-debug/src/solidity-decoder/types/RefType.ts
View file @
399a57d8
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
import
{
toBN
}
from
'./util'
import
{
toBN
}
from
'./util'
export
class
RefType
{
export
class
RefType
{
location
location
storageSlots
storageSlots
storageBytes
storageBytes
...
@@ -28,7 +27,7 @@ export class RefType {
...
@@ -28,7 +27,7 @@ export class RefType {
*/
*/
async
decodeFromStack
(
stackDepth
,
stack
,
memory
,
storageResolver
,
cursor
)
{
async
decodeFromStack
(
stackDepth
,
stack
,
memory
,
storageResolver
,
cursor
)
{
if
(
stack
.
length
-
1
<
stackDepth
)
{
if
(
stack
.
length
-
1
<
stackDepth
)
{
return
{
error
:
'<decoding failed - stack underflow '
+
stackDepth
+
'>'
,
type
:
this
.
typeName
}
return
{
error
:
'<decoding failed - stack underflow '
+
stackDepth
+
'>'
,
type
:
this
.
typeName
}
}
}
let
offset
=
stack
[
stack
.
length
-
1
-
stackDepth
]
let
offset
=
stack
[
stack
.
length
-
1
-
stackDepth
]
if
(
this
.
isInStorage
())
{
if
(
this
.
isInStorage
())
{
...
@@ -37,13 +36,13 @@ export class RefType {
...
@@ -37,13 +36,13 @@ export class RefType {
return
await
this
.
decodeFromStorage
({
offset
:
0
,
slot
:
offset
},
storageResolver
)
return
await
this
.
decodeFromStorage
({
offset
:
0
,
slot
:
offset
},
storageResolver
)
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
log
(
e
)
console
.
log
(
e
)
return
{
error
:
'<decoding failed - '
+
e
.
message
+
'>'
,
type
:
this
.
typeName
}
return
{
error
:
'<decoding failed - '
+
e
.
message
+
'>'
,
type
:
this
.
typeName
}
}
}
}
else
if
(
this
.
isInMemory
())
{
}
else
if
(
this
.
isInMemory
())
{
offset
=
parseInt
(
offset
,
16
)
offset
=
parseInt
(
offset
,
16
)
return
this
.
decodeFromMemoryInternal
(
offset
,
memory
,
cursor
)
return
this
.
decodeFromMemoryInternal
(
offset
,
memory
,
cursor
)
}
else
{
}
else
{
return
{
error
:
'<decoding failed - no decoder for '
+
this
.
location
+
'>'
,
type
:
this
.
typeName
}
return
{
error
:
'<decoding failed - no decoder for '
+
this
.
location
+
'>'
,
type
:
this
.
typeName
}
}
}
}
}
...
...
libs/remix-debug/src/solidity-decoder/types/StringType.ts
View file @
399a57d8
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
import
{
DynamicByteArray
}
from
'./DynamicByteArray'
import
{
DynamicByteArray
}
from
'./DynamicByteArray'
export
class
StringType
extends
DynamicByteArray
{
export
class
StringType
extends
DynamicByteArray
{
typeName
typeName
constructor
(
location
)
{
constructor
(
location
)
{
...
@@ -42,11 +41,11 @@ function format (decoded) {
...
@@ -42,11 +41,11 @@ function format (decoded) {
}
}
let
value
=
decoded
.
value
let
value
=
decoded
.
value
value
=
value
.
replace
(
'0x'
,
''
).
replace
(
/
(
..
)
/g
,
'%$1'
)
value
=
value
.
replace
(
'0x'
,
''
).
replace
(
/
(
..
)
/g
,
'%$1'
)
const
ret
=
{
length
:
decoded
.
length
,
raw
:
decoded
.
value
,
type
:
'string'
}
const
ret
=
{
length
:
decoded
.
length
,
raw
:
decoded
.
value
,
type
:
'string'
}
try
{
try
{
ret
[
'value'
]
=
decodeURIComponent
(
value
)
ret
.
value
=
decodeURIComponent
(
value
)
}
catch
(
e
)
{
}
catch
(
e
)
{
ret
[
'error'
]
=
'Invalid UTF8 encoding'
ret
.
error
=
'Invalid UTF8 encoding'
ret
.
raw
=
decoded
.
value
ret
.
raw
=
decoded
.
value
}
}
return
ret
return
ret
...
...
libs/remix-debug/src/solidity-decoder/types/Struct.ts
View file @
399a57d8
...
@@ -3,7 +3,6 @@ import { add } from './util'
...
@@ -3,7 +3,6 @@ import { add } from './util'
import
{
RefType
}
from
'./RefType'
import
{
RefType
}
from
'./RefType'
export
class
Struct
extends
RefType
{
export
class
Struct
extends
RefType
{
members
members
constructor
(
memberDetails
,
location
,
fullType
)
{
constructor
(
memberDetails
,
location
,
fullType
)
{
...
@@ -25,7 +24,7 @@ export class Struct extends RefType {
...
@@ -25,7 +24,7 @@ export class Struct extends RefType {
ret
[
item
.
name
]
=
'<decoding failed - '
+
e
.
message
+
'>'
ret
[
item
.
name
]
=
'<decoding failed - '
+
e
.
message
+
'>'
}
}
}
}
return
{
value
:
ret
,
type
:
this
.
typeName
}
return
{
value
:
ret
,
type
:
this
.
typeName
}
}
}
decodeFromMemoryInternal
(
offset
,
memory
)
{
decodeFromMemoryInternal
(
offset
,
memory
)
{
...
@@ -36,6 +35,6 @@ export class Struct extends RefType {
...
@@ -36,6 +35,6 @@ export class Struct extends RefType {
ret
[
item
.
name
]
=
member
ret
[
item
.
name
]
=
member
offset
+=
32
offset
+=
32
})
})
return
{
value
:
ret
,
type
:
this
.
typeName
}
return
{
value
:
ret
,
type
:
this
.
typeName
}
}
}
}
}
libs/remix-debug/src/solidity-decoder/types/ValueType.ts
View file @
399a57d8
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
import
{
extractHexValue
}
from
'./util'
import
{
extractHexValue
}
from
'./util'
export
class
ValueType
{
export
class
ValueType
{
storageSlots
storageSlots
storageBytes
storageBytes
typeName
typeName
...
@@ -25,10 +24,10 @@ export class ValueType {
...
@@ -25,10 +24,10 @@ export class ValueType {
async
decodeFromStorage
(
location
,
storageResolver
)
{
async
decodeFromStorage
(
location
,
storageResolver
)
{
try
{
try
{
var
value
=
await
extractHexValue
(
location
,
storageResolver
,
this
.
storageBytes
)
var
value
=
await
extractHexValue
(
location
,
storageResolver
,
this
.
storageBytes
)
return
{
value
:
this
.
decodeValue
(
value
),
type
:
this
.
typeName
}
return
{
value
:
this
.
decodeValue
(
value
),
type
:
this
.
typeName
}
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
log
(
e
)
console
.
log
(
e
)
return
{
value
:
'<decoding failed - '
+
e
.
message
+
'>'
,
type
:
this
.
typeName
}
return
{
value
:
'<decoding failed - '
+
e
.
message
+
'>'
,
type
:
this
.
typeName
}
}
}
}
}
...
@@ -47,7 +46,7 @@ export class ValueType {
...
@@ -47,7 +46,7 @@ export class ValueType {
}
else
{
}
else
{
value
=
this
.
decodeValue
(
stack
[
stack
.
length
-
1
-
stackDepth
].
replace
(
'0x'
,
''
))
value
=
this
.
decodeValue
(
stack
[
stack
.
length
-
1
-
stackDepth
].
replace
(
'0x'
,
''
))
}
}
return
{
value
,
type
:
this
.
typeName
}
return
{
value
,
type
:
this
.
typeName
}
}
}
/**
/**
...
@@ -58,7 +57,7 @@ export class ValueType {
...
@@ -58,7 +57,7 @@ export class ValueType {
* @return {Object} - decoded value
* @return {Object} - decoded value
*/
*/
decodeFromMemory
(
offset
,
memory
)
{
decodeFromMemory
(
offset
,
memory
)
{
le
t
value
=
memory
.
substr
(
2
*
offset
,
64
)
cons
t
value
=
memory
.
substr
(
2
*
offset
,
64
)
return
{
value
:
this
.
decodeValue
(
value
),
type
:
this
.
typeName
}
return
{
value
:
this
.
decodeValue
(
value
),
type
:
this
.
typeName
}
}
}
}
}
libs/remix-debug/src/solidity-decoder/types/util.ts
View file @
399a57d8
...
@@ -9,7 +9,7 @@ export function decodeIntFromHex (value, byteLength, signed) {
...
@@ -9,7 +9,7 @@ export function decodeIntFromHex (value, byteLength, signed) {
return
bigNumber
.
toString
(
10
)
return
bigNumber
.
toString
(
10
)
}
}
export
function
readFromStorage
(
slot
,
storageResolver
):
Promise
<
string
>
{
export
function
readFromStorage
(
slot
,
storageResolver
):
Promise
<
string
>
{
const
hexSlot
=
'0x'
+
normalizeHex
(
bufferToHex
(
slot
))
const
hexSlot
=
'0x'
+
normalizeHex
(
bufferToHex
(
slot
))
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
storageResolver
.
storageSlot
(
hexSlot
,
(
error
,
slot
)
=>
{
storageResolver
.
storageSlot
(
hexSlot
,
(
error
,
slot
)
=>
{
...
@@ -78,7 +78,7 @@ export function removeLocation (type) {
...
@@ -78,7 +78,7 @@ export function removeLocation (type) {
}
}
export
function
extractLocation
(
type
)
{
export
function
extractLocation
(
type
)
{
le
t
match
=
type
.
match
(
/
(
storage ref| storage pointer| memory| calldata
)?
$/
)
cons
t
match
=
type
.
match
(
/
(
storage ref| storage pointer| memory| calldata
)?
$/
)
if
(
match
[
1
]
!==
''
)
{
if
(
match
[
1
]
!==
''
)
{
return
match
[
1
].
trim
()
return
match
[
1
].
trim
()
}
}
...
...
libs/remix-debug/src/source/offsetToLineColumnConverter.ts
View file @
399a57d8
...
@@ -2,11 +2,10 @@
...
@@ -2,11 +2,10 @@
import
{
getLinebreakPositions
,
convertOffsetToLineColumn
}
from
'./sourceMappingDecoder'
import
{
getLinebreakPositions
,
convertOffsetToLineColumn
}
from
'./sourceMappingDecoder'
export
class
OffsetToColumnConverter
{
export
class
OffsetToColumnConverter
{
lineBreakPositionsByContent
lineBreakPositionsByContent
sourceMappingDecoder
sourceMappingDecoder
constructor
(
compilerEvent
)
{
constructor
(
compilerEvent
)
{
this
.
lineBreakPositionsByContent
=
{}
this
.
lineBreakPositionsByContent
=
{}
if
(
compilerEvent
)
{
if
(
compilerEvent
)
{
compilerEvent
.
register
(
'compilationFinished'
,
(
success
,
data
,
source
)
=>
{
compilerEvent
.
register
(
'compilationFinished'
,
(
success
,
data
,
source
)
=>
{
...
@@ -17,7 +16,7 @@ export class OffsetToColumnConverter {
...
@@ -17,7 +16,7 @@ export class OffsetToColumnConverter {
offsetToLineColumn
(
rawLocation
,
file
,
sources
,
asts
)
{
offsetToLineColumn
(
rawLocation
,
file
,
sources
,
asts
)
{
if
(
!
this
.
lineBreakPositionsByContent
[
file
])
{
if
(
!
this
.
lineBreakPositionsByContent
[
file
])
{
for
(
le
t
filename
in
asts
)
{
for
(
cons
t
filename
in
asts
)
{
const
source
=
asts
[
filename
]
const
source
=
asts
[
filename
]
// source id was string before. in newer versions it has been changed to an integer so we need to check the type here
// source id was string before. in newer versions it has been changed to an integer so we need to check the type here
if
(
typeof
source
.
id
===
'string'
)
source
.
id
=
parseInt
(
source
.
id
,
10
)
if
(
typeof
source
.
id
===
'string'
)
source
.
id
=
parseInt
(
source
.
id
,
10
)
...
...
libs/remix-debug/src/source/sourceLocationTracker.ts
View file @
399a57d8
...
@@ -8,7 +8,6 @@ import { util } from '@remix-project/remix-lib'
...
@@ -8,7 +8,6 @@ import { util } from '@remix-project/remix-lib'
* Process the source code location for the current executing bytecode
* Process the source code location for the current executing bytecode
*/
*/
export
class
SourceLocationTracker
{
export
class
SourceLocationTracker
{
opts
opts
codeManager
codeManager
event
event
...
@@ -32,7 +31,7 @@ export class SourceLocationTracker {
...
@@ -32,7 +31,7 @@ export class SourceLocationTracker {
*/
*/
async
getSourceLocationFromInstructionIndex
(
address
,
index
,
contracts
)
{
async
getSourceLocationFromInstructionIndex
(
address
,
index
,
contracts
)
{
const
sourceMap
=
await
this
.
extractSourceMap
(
this
,
this
.
codeManager
,
address
,
contracts
)
const
sourceMap
=
await
this
.
extractSourceMap
(
this
,
this
.
codeManager
,
address
,
contracts
)
return
atIndex
(
index
,
sourceMap
[
'map'
]
)
return
atIndex
(
index
,
sourceMap
.
map
)
}
}
/**
/**
...
@@ -45,7 +44,7 @@ export class SourceLocationTracker {
...
@@ -45,7 +44,7 @@ export class SourceLocationTracker {
async
getSourceLocationFromVMTraceIndex
(
address
,
vmtraceStepIndex
,
contracts
)
{
async
getSourceLocationFromVMTraceIndex
(
address
,
vmtraceStepIndex
,
contracts
)
{
const
sourceMap
=
await
this
.
extractSourceMap
(
this
,
this
.
codeManager
,
address
,
contracts
)
const
sourceMap
=
await
this
.
extractSourceMap
(
this
,
this
.
codeManager
,
address
,
contracts
)
const
index
=
this
.
codeManager
.
getInstructionIndex
(
address
,
vmtraceStepIndex
)
const
index
=
this
.
codeManager
.
getInstructionIndex
(
address
,
vmtraceStepIndex
)
return
atIndex
(
index
,
sourceMap
[
'map'
]
)
return
atIndex
(
index
,
sourceMap
.
map
)
}
}
/**
/**
...
@@ -68,7 +67,7 @@ export class SourceLocationTracker {
...
@@ -68,7 +67,7 @@ export class SourceLocationTracker {
* @param {Object} contractDetails - AST of compiled contracts
* @param {Object} contractDetails - AST of compiled contracts
*/
*/
async
getValidSourceLocationFromVMTraceIndex
(
address
,
vmtraceStepIndex
,
contracts
)
{
async
getValidSourceLocationFromVMTraceIndex
(
address
,
vmtraceStepIndex
,
contracts
)
{
let
map
:
Record
<
string
,
number
>
=
{
file
:
-
1
}
let
map
:
Record
<
string
,
number
>
=
{
file
:
-
1
}
while
(
vmtraceStepIndex
>=
0
&&
map
.
file
===
-
1
)
{
while
(
vmtraceStepIndex
>=
0
&&
map
.
file
===
-
1
)
{
map
=
await
this
.
getSourceLocationFromVMTraceIndex
(
address
,
vmtraceStepIndex
,
contracts
)
map
=
await
this
.
getSourceLocationFromVMTraceIndex
(
address
,
vmtraceStepIndex
,
contracts
)
vmtraceStepIndex
=
vmtraceStepIndex
-
1
vmtraceStepIndex
=
vmtraceStepIndex
-
1
...
@@ -83,8 +82,8 @@ export class SourceLocationTracker {
...
@@ -83,8 +82,8 @@ export class SourceLocationTracker {
private
getSourceMap
(
address
,
code
,
contracts
)
{
private
getSourceMap
(
address
,
code
,
contracts
)
{
const
isCreation
=
isContractCreation
(
address
)
const
isCreation
=
isContractCreation
(
address
)
let
bytes
let
bytes
for
(
le
t
file
in
contracts
)
{
for
(
cons
t
file
in
contracts
)
{
for
(
le
t
contract
in
contracts
[
file
])
{
for
(
cons
t
contract
in
contracts
[
file
])
{
const
bytecode
=
contracts
[
file
][
contract
].
evm
.
bytecode
const
bytecode
=
contracts
[
file
][
contract
].
evm
.
bytecode
const
deployedBytecode
=
contracts
[
file
][
contract
].
evm
.
deployedBytecode
const
deployedBytecode
=
contracts
[
file
][
contract
].
evm
.
deployedBytecode
if
(
!
deployedBytecode
)
continue
if
(
!
deployedBytecode
)
continue
...
@@ -110,7 +109,7 @@ export class SourceLocationTracker {
...
@@ -110,7 +109,7 @@ export class SourceLocationTracker {
if
(
!
isContractCreation
(
address
))
self
.
sourceMapByAddress
[
address
]
=
sourceMap
if
(
!
isContractCreation
(
address
))
self
.
sourceMapByAddress
[
address
]
=
sourceMap
return
resolve
(
sourceMap
)
return
resolve
(
sourceMap
)
}
}
reject
(
'no sourcemap associated with the code '
+
address
)
reject
(
new
Error
(
'no sourcemap associated with the code '
+
address
)
)
}).
catch
(
reject
)
}).
catch
(
reject
)
})
})
}
}
...
...
libs/remix-debug/src/source/sourceMappingDecoder.ts
View file @
399a57d8
...
@@ -33,7 +33,7 @@ export function decode (value) {
...
@@ -33,7 +33,7 @@ export function decode (value) {
export
function
decompressAll
(
mapping
)
{
export
function
decompressAll
(
mapping
)
{
const
map
=
mapping
.
split
(
';'
)
const
map
=
mapping
.
split
(
';'
)
const
ret
=
[]
const
ret
=
[]
for
(
le
t
k
in
map
)
{
for
(
cons
t
k
in
map
)
{
const
compressed
=
map
[
k
].
split
(
':'
)
const
compressed
=
map
[
k
].
split
(
':'
)
const
sourceMap
=
{
const
sourceMap
=
{
start
:
compressed
[
0
]
?
parseInt
(
compressed
[
0
])
:
ret
[
ret
.
length
-
1
].
start
,
start
:
compressed
[
0
]
?
parseInt
(
compressed
[
0
])
:
ret
[
ret
.
length
-
1
].
start
,
...
@@ -74,10 +74,9 @@ export function convertOffsetToLineColumn (sourceLocation, lineBreakPositions) {
...
@@ -74,10 +74,9 @@ export function convertOffsetToLineColumn (sourceLocation, lineBreakPositions) {
end
:
convertFromCharPosition
(
sourceLocation
.
start
+
sourceLocation
.
length
,
lineBreakPositions
)
end
:
convertFromCharPosition
(
sourceLocation
.
start
+
sourceLocation
.
length
,
lineBreakPositions
)
}
}
}
}
return
{
start
:
null
,
end
:
null
}
return
{
start
:
null
,
end
:
null
}
}
}
function
convertFromCharPosition
(
pos
,
lineBreakPositions
)
{
function
convertFromCharPosition
(
pos
,
lineBreakPositions
)
{
let
line
=
util
.
findLowerBound
(
pos
,
lineBreakPositions
)
let
line
=
util
.
findLowerBound
(
pos
,
lineBreakPositions
)
if
(
lineBreakPositions
[
line
]
!==
pos
)
{
if
(
lineBreakPositions
[
line
]
!==
pos
)
{
...
@@ -85,7 +84,7 @@ function convertFromCharPosition (pos, lineBreakPositions) {
...
@@ -85,7 +84,7 @@ function convertFromCharPosition (pos, lineBreakPositions) {
}
}
const
beginColumn
=
line
===
0
?
0
:
(
lineBreakPositions
[
line
-
1
]
+
1
)
const
beginColumn
=
line
===
0
?
0
:
(
lineBreakPositions
[
line
-
1
]
+
1
)
const
column
=
pos
-
beginColumn
const
column
=
pos
-
beginColumn
return
{
line
,
column
}
return
{
line
,
column
}
}
}
function
sourceLocationFromAstNode
(
astNode
)
{
function
sourceLocationFromAstNode
(
astNode
)
{
...
@@ -173,7 +172,7 @@ export function nodesAtPosition (astNodeType, position, ast) {
...
@@ -173,7 +172,7 @@ export function nodesAtPosition (astNodeType, position, ast) {
* @return Object { start, length, file, jump }
* @return Object { start, length, file, jump }
*/
*/
export
function
atIndex
(
index
,
mapping
)
{
export
function
atIndex
(
index
,
mapping
)
{
le
t
ret
=
{}
cons
t
ret
=
{}
const
map
=
mapping
.
split
(
';'
)
const
map
=
mapping
.
split
(
';'
)
if
(
index
>=
map
.
length
)
{
if
(
index
>=
map
.
length
)
{
index
=
map
.
length
-
1
index
=
map
.
length
-
1
...
@@ -184,19 +183,19 @@ export function atIndex (index, mapping) {
...
@@ -184,19 +183,19 @@ export function atIndex (index, mapping) {
continue
continue
}
}
current
=
current
.
split
(
':'
)
current
=
current
.
split
(
':'
)
if
(
ret
[
'start'
]
===
undefined
&&
current
[
0
]
&&
current
[
0
]
!==
'-1'
&&
current
[
0
].
length
)
{
if
(
ret
.
start
===
undefined
&&
current
[
0
]
&&
current
[
0
]
!==
'-1'
&&
current
[
0
].
length
)
{
ret
[
'start'
]
=
parseInt
(
current
[
0
])
ret
.
start
=
parseInt
(
current
[
0
])
}
}
if
(
ret
[
'length'
]
===
undefined
&&
current
[
1
]
&&
current
[
1
]
!==
'-1'
&&
current
[
1
].
length
)
{
if
(
ret
.
length
===
undefined
&&
current
[
1
]
&&
current
[
1
]
!==
'-1'
&&
current
[
1
].
length
)
{
ret
[
'length'
]
=
parseInt
(
current
[
1
])
ret
.
length
=
parseInt
(
current
[
1
])
}
}
if
(
ret
[
'file'
]
===
undefined
&&
current
[
2
]
&&
current
[
2
].
length
)
{
if
(
ret
.
file
===
undefined
&&
current
[
2
]
&&
current
[
2
].
length
)
{
ret
[
'file'
]
=
parseInt
(
current
[
2
])
ret
.
file
=
parseInt
(
current
[
2
])
}
}
if
(
ret
[
'jump'
]
===
undefined
&&
current
[
3
]
&&
current
[
3
].
length
)
{
if
(
ret
.
jump
===
undefined
&&
current
[
3
]
&&
current
[
3
].
length
)
{
ret
[
'jump'
]
=
current
[
3
]
ret
.
jump
=
current
[
3
]
}
}
if
(
ret
[
'start'
]
!==
undefined
&&
ret
[
'length'
]
!==
undefined
&&
ret
[
'file'
]
!==
undefined
&&
ret
[
'jump'
]
!==
undefined
)
{
if
(
ret
.
start
!==
undefined
&&
ret
.
length
!==
undefined
&&
ret
.
file
!==
undefined
&&
ret
.
jump
!==
undefined
)
{
break
break
}
}
}
}
...
...
libs/remix-debug/src/storage/mappingPreimages.ts
View file @
399a57d8
...
@@ -11,12 +11,12 @@ import { sub } from '../solidity-decoder/types/util'
...
@@ -11,12 +11,12 @@ import { sub } from '../solidity-decoder/types/util'
*/
*/
export
async
function
decodeMappingsKeys
(
web3
,
storage
,
corrections
)
{
export
async
function
decodeMappingsKeys
(
web3
,
storage
,
corrections
)
{
const
ret
=
{}
const
ret
=
{}
if
(
!
corrections
.
length
)
corrections
.
push
({
offset
:
0
,
slot
:
0
})
if
(
!
corrections
.
length
)
corrections
.
push
({
offset
:
0
,
slot
:
0
})
for
(
le
t
hashedLoc
in
storage
)
{
for
(
cons
t
hashedLoc
in
storage
)
{
var
preimage
var
preimage
try
{
try
{
const
key
=
storage
[
hashedLoc
].
key
const
key
=
storage
[
hashedLoc
].
key
for
(
le
t
k
in
corrections
)
{
for
(
cons
t
k
in
corrections
)
{
const
corrected
=
sub
(
key
,
corrections
[
k
].
slot
).
toString
(
16
)
const
corrected
=
sub
(
key
,
corrections
[
k
].
slot
).
toString
(
16
)
preimage
=
await
getPreimage
(
web3
,
'0x'
+
corrected
)
preimage
=
await
getPreimage
(
web3
,
'0x'
+
corrected
)
if
(
preimage
)
break
if
(
preimage
)
break
...
...
libs/remix-debug/src/storage/storageResolver.ts
View file @
399a57d8
...
@@ -7,7 +7,6 @@ import { decodeMappingsKeys } from './mappingPreimages'
...
@@ -7,7 +7,6 @@ import { decodeMappingsKeys } from './mappingPreimages'
* (TODO: one instance need to be shared over all the components)
* (TODO: one instance need to be shared over all the components)
*/
*/
export
class
StorageResolver
{
export
class
StorageResolver
{
storageByAddress
storageByAddress
preimagesMappingByAddress
preimagesMappingByAddress
maxSize
maxSize
...
@@ -93,7 +92,7 @@ export class StorageResolver {
...
@@ -93,7 +92,7 @@ export class StorageResolver {
const
result
=
await
this
.
storageRangeWeb3Call
(
tx
,
address
,
slotKey
,
self
.
maxSize
)
const
result
=
await
this
.
storageRangeWeb3Call
(
tx
,
address
,
slotKey
,
self
.
maxSize
)
const
[
storage
,
nextKey
]
=
result
const
[
storage
,
nextKey
]
=
result
if
(
!
storage
[
slotKey
]
&&
slotKey
!==
self
.
zeroSlot
)
{
// we don't cache the zero slot (could lead to inconsistency)
if
(
!
storage
[
slotKey
]
&&
slotKey
!==
self
.
zeroSlot
)
{
// we don't cache the zero slot (could lead to inconsistency)
storage
[
slotKey
]
=
{
key
:
slotKey
,
value
:
self
.
zeroSlot
}
storage
[
slotKey
]
=
{
key
:
slotKey
,
value
:
self
.
zeroSlot
}
}
}
self
.
toCache
(
self
,
address
,
storage
)
self
.
toCache
(
self
,
address
,
storage
)
if
(
slotKey
===
self
.
zeroSlot
&&
!
nextKey
)
{
// only working if keys are sorted !!
if
(
slotKey
===
self
.
zeroSlot
&&
!
nextKey
)
{
// only working if keys are sorted !!
...
@@ -144,7 +143,7 @@ export class StorageResolver {
...
@@ -144,7 +143,7 @@ export class StorageResolver {
}
else
if
(
result
.
storage
)
{
}
else
if
(
result
.
storage
)
{
resolve
([
result
.
storage
,
result
.
nextKey
])
resolve
([
result
.
storage
,
result
.
nextKey
])
}
else
{
}
else
{
reject
(
'the storage has not been provided'
)
reject
(
new
Error
(
'the storage has not been provided'
)
)
}
}
})
})
}
}
...
...
libs/remix-debug/src/storage/storageViewer.ts
View file @
399a57d8
...
@@ -2,13 +2,12 @@
...
@@ -2,13 +2,12 @@
import
{
util
}
from
'@remix-project/remix-lib'
import
{
util
}
from
'@remix-project/remix-lib'
import
{
decodeMappingsKeys
}
from
'./mappingPreimages'
import
{
decodeMappingsKeys
}
from
'./mappingPreimages'
/**
/**
* easier access to the storage resolver
* easier access to the storage resolver
* Basically one instance is created foreach execution step and foreach component that need it.
* Basically one instance is created foreach execution step and foreach component that need it.
* (TODO: one instance need to be shared over all the components)
* (TODO: one instance need to be shared over all the components)
*/
*/
export
class
StorageViewer
{
export
class
StorageViewer
{
context
context
storageResolver
storageResolver
web3
web3
...
...
libs/remix-debug/src/trace/traceAnalyser.ts
View file @
399a57d8
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
import
*
as
traceHelper
from
'./traceHelper'
import
*
as
traceHelper
from
'./traceHelper'
export
class
TraceAnalyser
{
export
class
TraceAnalyser
{
traceCache
traceCache
trace
trace
...
@@ -42,7 +41,7 @@ export class TraceAnalyser {
...
@@ -42,7 +41,7 @@ export class TraceAnalyser {
const
memory
=
this
.
trace
[
this
.
traceCache
.
memoryChanges
[
this
.
traceCache
.
memoryChanges
.
length
-
1
]].
memory
const
memory
=
this
.
trace
[
this
.
traceCache
.
memoryChanges
[
this
.
traceCache
.
memoryChanges
.
length
-
1
]].
memory
const
noOfReturnParams
=
size
/
64
const
noOfReturnParams
=
size
/
64
const
memoryInString
=
memory
.
join
(
''
)
const
memoryInString
=
memory
.
join
(
''
)
le
t
returnParamsObj
=
[]
cons
t
returnParamsObj
=
[]
for
(
let
i
=
0
;
i
<
noOfReturnParams
;
i
++
)
{
for
(
let
i
=
0
;
i
<
noOfReturnParams
;
i
++
)
{
returnParamsObj
.
push
(
'0x'
+
memoryInString
.
substring
(
offset
,
offset
+
64
))
returnParamsObj
.
push
(
'0x'
+
memoryInString
.
substring
(
offset
,
offset
+
64
))
offset
+=
64
offset
+=
64
...
@@ -141,4 +140,3 @@ export class TraceAnalyser {
...
@@ -141,4 +140,3 @@ export class TraceAnalyser {
return
context
return
context
}
}
}
}
libs/remix-debug/src/trace/traceCache.ts
View file @
399a57d8
...
@@ -3,7 +3,6 @@ import { util } from '@remix-project/remix-lib'
...
@@ -3,7 +3,6 @@ import { util } from '@remix-project/remix-lib'
const
{
sha3_256
}
=
util
const
{
sha3_256
}
=
util
export
class
TraceCache
{
export
class
TraceCache
{
returnValues
returnValues
currentCall
currentCall
callsTree
callsTree
...
@@ -16,11 +15,10 @@ export class TraceCache {
...
@@ -16,11 +15,10 @@ export class TraceCache {
storageChanges
storageChanges
sstore
sstore
constructor
()
{
constructor
()
{
this
.
init
()
this
.
init
()
}
}
init
()
{
init
()
{
// ...Changes contains index in the vmtrace of the corresponding changes
// ...Changes contains index in the vmtrace of the corresponding changes
...
@@ -53,7 +51,7 @@ export class TraceCache {
...
@@ -53,7 +51,7 @@ export class TraceCache {
// outOfGas has been removed because gas left logging is apparently made differently
// outOfGas has been removed because gas left logging is apparently made differently
// 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)
pushCall
(
step
,
index
,
address
,
callStack
,
reverted
)
{
pushCall
(
step
,
index
,
address
,
callStack
,
reverted
)
{
le
t
validReturnStep
=
step
.
op
===
'RETURN'
||
step
.
op
===
'STOP'
cons
t
validReturnStep
=
step
.
op
===
'RETURN'
||
step
.
op
===
'STOP'
if
((
validReturnStep
||
reverted
)
&&
(
this
.
currentCall
))
{
if
((
validReturnStep
||
reverted
)
&&
(
this
.
currentCall
))
{
this
.
currentCall
.
call
.
return
=
index
-
1
this
.
currentCall
.
call
.
return
=
index
-
1
if
(
!
validReturnStep
)
{
if
(
!
validReturnStep
)
{
...
@@ -63,7 +61,7 @@ export class TraceCache {
...
@@ -63,7 +61,7 @@ export class TraceCache {
this
.
currentCall
=
parent
?
{
call
:
parent
.
call
,
parent
:
parent
.
parent
}
:
null
this
.
currentCall
=
parent
?
{
call
:
parent
.
call
,
parent
:
parent
.
parent
}
:
null
return
return
}
}
le
t
call
=
{
cons
t
call
=
{
op
:
step
.
op
,
op
:
step
.
op
,
address
:
address
,
address
:
address
,
callStack
:
callStack
,
callStack
:
callStack
,
...
@@ -102,10 +100,10 @@ export class TraceCache {
...
@@ -102,10 +100,10 @@ export class TraceCache {
pushStoreChanges
(
index
,
address
,
key
,
value
)
{
pushStoreChanges
(
index
,
address
,
key
,
value
)
{
this
.
sstore
[
index
]
=
{
this
.
sstore
[
index
]
=
{
'address'
:
address
,
address
:
address
,
'key'
:
key
,
key
:
key
,
'value'
:
value
,
value
:
value
,
'hashedKey'
:
sha3_256
(
key
)
hashedKey
:
sha3_256
(
key
)
}
}
this
.
storageChanges
.
push
(
index
)
this
.
storageChanges
.
push
(
index
)
}
}
...
...
libs/remix-debug/src/trace/traceHelper.ts
View file @
399a57d8
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
import
{
helpers
}
from
'@remix-project/remix-lib'
import
{
helpers
}
from
'@remix-project/remix-lib'
const
{
ui
}
=
helpers
const
{
ui
}
=
helpers
// vmTraceIndex has to point to a CALL, CODECALL, ...
// vmTraceIndex has to point to a CALL, CODECALL, ...
export
function
resolveCalledAddress
(
vmTraceIndex
,
trace
)
{
export
function
resolveCalledAddress
(
vmTraceIndex
,
trace
)
{
const
step
=
trace
[
vmTraceIndex
]
const
step
=
trace
[
vmTraceIndex
]
if
(
isCreateInstruction
(
step
))
{
if
(
isCreateInstruction
(
step
))
{
...
@@ -66,4 +66,3 @@ export function contractCreationToken (index) {
...
@@ -66,4 +66,3 @@ export function contractCreationToken (index) {
export
function
isContractCreation
(
address
)
{
export
function
isContractCreation
(
address
)
{
return
address
.
indexOf
(
'(Contract Creation - Step'
)
!==
-
1
return
address
.
indexOf
(
'(Contract Creation - Step'
)
!==
-
1
}
}
libs/remix-debug/src/trace/traceManager.ts
View file @
399a57d8
...
@@ -6,7 +6,6 @@ import { isCreateInstruction } from './traceHelper'
...
@@ -6,7 +6,6 @@ import { isCreateInstruction } from './traceHelper'
import
{
util
}
from
'@remix-project/remix-lib'
import
{
util
}
from
'@remix-project/remix-lib'
export
class
TraceManager
{
export
class
TraceManager
{
web3
web3
isLoading
:
boolean
isLoading
:
boolean
trace
trace
...
@@ -33,10 +32,10 @@ export class TraceManager {
...
@@ -33,10 +32,10 @@ export class TraceManager {
try
{
try
{
const
result
=
await
this
.
getTrace
(
tx
.
hash
)
const
result
=
await
this
.
getTrace
(
tx
.
hash
)
if
(
result
[
'structLogs'
]
.
length
>
0
)
{
if
(
result
.
structLogs
.
length
>
0
)
{
this
.
trace
=
result
[
'structLogs'
]
this
.
trace
=
result
.
structLogs
this
.
traceAnalyser
.
analyse
(
result
[
'structLogs'
]
,
tx
)
this
.
traceAnalyser
.
analyse
(
result
.
structLogs
,
tx
)
this
.
isLoading
=
false
this
.
isLoading
=
false
return
true
return
true
}
}
...
@@ -82,7 +81,7 @@ export class TraceManager {
...
@@ -82,7 +81,7 @@ export class TraceManager {
getLength
(
callback
)
{
getLength
(
callback
)
{
if
(
!
this
.
trace
)
{
if
(
!
this
.
trace
)
{
callback
(
'no trace available'
,
null
)
callback
(
new
Error
(
'no trace available'
)
,
null
)
}
else
{
}
else
{
callback
(
null
,
this
.
trace
.
length
)
callback
(
null
,
this
.
trace
.
length
)
}
}
...
@@ -136,7 +135,7 @@ export class TraceManager {
...
@@ -136,7 +135,7 @@ export class TraceManager {
getStackAt
(
stepIndex
)
{
getStackAt
(
stepIndex
)
{
this
.
checkRequestedStep
(
stepIndex
)
this
.
checkRequestedStep
(
stepIndex
)
if
(
this
.
trace
[
stepIndex
]
&&
this
.
trace
[
stepIndex
].
stack
)
{
// there's always a stack
if
(
this
.
trace
[
stepIndex
]
&&
this
.
trace
[
stepIndex
].
stack
)
{
// there's always a stack
le
t
stack
=
this
.
trace
[
stepIndex
].
stack
.
slice
(
0
)
cons
t
stack
=
this
.
trace
[
stepIndex
].
stack
.
slice
(
0
)
stack
.
reverse
()
stack
.
reverse
()
return
stack
return
stack
}
else
{
}
else
{
...
@@ -268,7 +267,7 @@ export class TraceManager {
...
@@ -268,7 +267,7 @@ export class TraceManager {
}
}
waterfall
(
calls
,
stepindex
,
cb
)
{
waterfall
(
calls
,
stepindex
,
cb
)
{
le
t
ret
=
[]
cons
t
ret
=
[]
let
retError
=
null
let
retError
=
null
for
(
var
call
in
calls
)
{
for
(
var
call
in
calls
)
{
calls
[
call
].
apply
(
this
,
[
stepindex
,
function
(
error
,
result
)
{
calls
[
call
].
apply
(
this
,
[
stepindex
,
function
(
error
,
result
)
{
...
...
libs/remix-debug/src/trace/traceStepManager.ts
View file @
399a57d8
...
@@ -4,7 +4,6 @@ import { isCallInstruction, isCallToPrecompiledContract, isReturnInstruction } f
...
@@ -4,7 +4,6 @@ import { isCallInstruction, isCallToPrecompiledContract, isReturnInstruction } f
import
{
util
}
from
'@remix-project/remix-lib'
import
{
util
}
from
'@remix-project/remix-lib'
export
class
TraceStepManager
{
export
class
TraceStepManager
{
traceAnalyser
traceAnalyser
constructor
(
_traceAnalyser
)
{
constructor
(
_traceAnalyser
)
{
...
...
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