Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
ca79360f
Commit
ca79360f
authored
Jun 17, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Verbose logging for VM
parent
34c8045d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
5 deletions
+41
-5
state_transition.go
ethchain/state_transition.go
+1
-0
vm.go
ethchain/vm.go
+40
-5
No files found.
ethchain/state_transition.go
View file @
ca79360f
...
...
@@ -236,6 +236,7 @@ func (self *StateTransition) Eval(script []byte, context *StateObject) (ret []by
Diff
:
block
.
Difficulty
,
Value
:
tx
.
Value
,
})
vm
.
Verbose
=
true
ret
,
_
,
err
=
closure
.
Call
(
vm
,
tx
.
Data
,
nil
)
return
...
...
ethchain/vm.go
View file @
ca79360f
...
...
@@ -45,6 +45,10 @@ type Vm struct {
state
*
State
stateManager
*
StateManager
Verbose
bool
logStr
string
}
type
RuntimeVars
struct
{
...
...
@@ -58,6 +62,23 @@ type RuntimeVars struct {
Value
*
big
.
Int
}
func
(
self
*
Vm
)
Printf
(
format
string
,
v
...
interface
{})
*
Vm
{
if
self
.
Verbose
{
self
.
logStr
+=
fmt
.
Sprintf
(
format
,
v
...
)
}
return
self
}
func
(
self
*
Vm
)
Endl
()
*
Vm
{
if
self
.
Verbose
{
ethutil
.
Config
.
Log
.
Infoln
(
self
.
logStr
)
self
.
logStr
=
""
}
return
self
}
func
NewVm
(
state
*
State
,
stateManager
*
StateManager
,
vars
RuntimeVars
)
*
Vm
{
return
&
Vm
{
vars
:
vars
,
state
:
state
,
stateManager
:
stateManager
}
}
...
...
@@ -95,8 +116,6 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
step
:=
0
prevStep
:=
0
ethutil
.
Config
.
Log
.
Debugf
(
"# op
\n
"
)
for
{
prevStep
=
step
// The base for all big integer arithmetic
...
...
@@ -108,7 +127,8 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
// Get the opcode (it must be an opcode!)
op
:=
OpCode
(
val
.
Uint
())
ethutil
.
Config
.
Log
.
Debugf
(
"%-3d %-4s"
,
pc
,
op
.
String
())
vm
.
Printf
(
"(pc) %-3d -o- %-14s"
,
pc
,
op
.
String
())
//ethutil.Config.Log.Debugf("%-3d %-4s", pc, op.String())
gas
:=
new
(
big
.
Int
)
addStepGasUsage
:=
func
(
amount
*
big
.
Int
)
{
...
...
@@ -193,6 +213,8 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
return
closure
.
Return
(
nil
),
fmt
.
Errorf
(
"insufficient gas %v %v"
,
closure
.
Gas
,
gas
)
}
vm
.
Printf
(
" (g) %-3v (%v)"
,
gas
,
closure
.
Gas
)
mem
.
Resize
(
newMemSize
)
switch
op
{
...
...
@@ -428,6 +450,8 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
pc
.
Add
(
pc
,
a
.
Sub
(
a
,
big
.
NewInt
(
1
)))
step
+=
int
(
op
)
-
int
(
PUSH1
)
+
1
vm
.
Printf
(
" => %#x"
,
data
.
Bytes
())
case
POP
:
require
(
1
)
stack
.
Pop
()
...
...
@@ -448,11 +472,15 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
// Pop value of the stack
val
,
mStart
:=
stack
.
Popn
()
mem
.
Set
(
mStart
.
Int64
(),
32
,
ethutil
.
BigToBytes
(
val
,
256
))
vm
.
Printf
(
" => %#x"
,
val
)
case
MSTORE8
:
require
(
2
)
val
,
mStart
:=
stack
.
Popn
()
base
.
And
(
val
,
new
(
big
.
Int
)
.
SetInt64
(
0xff
))
mem
.
Set
(
mStart
.
Int64
(),
32
,
ethutil
.
BigToBytes
(
base
,
256
))
vm
.
Printf
(
" => %#x"
,
val
)
case
SLOAD
:
require
(
1
)
loc
:=
stack
.
Pop
()
...
...
@@ -466,18 +494,23 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
// Add the change to manifest
vm
.
state
.
manifest
.
AddStorageChange
(
closure
.
Object
(),
loc
.
Bytes
(),
val
)
vm
.
Printf
(
" => %#x"
,
val
)
case
JUMP
:
require
(
1
)
pc
=
stack
.
Pop
()
// Reduce pc by one because of the increment that's at the end of this for loop
//pc.Sub(pc, ethutil.Big1)
vm
.
Printf
(
" ~> %v"
,
pc
)
.
Endl
()
continue
case
JUMPI
:
require
(
2
)
cond
,
pos
:=
stack
.
Popn
()
if
cond
.
Cmp
(
ethutil
.
BigTrue
)
>=
0
{
pc
=
pos
//pc.Sub(pc, ethutil.Big1)
vm
.
Printf
(
" ~> %v"
,
pc
)
.
Endl
()
continue
}
case
PC
:
...
...
@@ -603,6 +636,8 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
pc
.
Add
(
pc
,
ethutil
.
Big1
)
vm
.
Endl
()
if
hook
!=
nil
{
if
!
hook
(
prevStep
,
op
,
mem
,
stack
,
closure
.
Object
())
{
return
nil
,
nil
...
...
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