aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain/vm.go
diff options
context:
space:
mode:
Diffstat (limited to 'ethchain/vm.go')
-rw-r--r--ethchain/vm.go37
1 files changed, 30 insertions, 7 deletions
diff --git a/ethchain/vm.go b/ethchain/vm.go
index 6a64d3ff3..3ad4472ca 100644
--- a/ethchain/vm.go
+++ b/ethchain/vm.go
@@ -31,6 +31,7 @@ type Debugger interface {
BreakHook(step int, op OpCode, mem *Memory, stack *Stack, stateObject *StateObject) bool
StepHook(step int, op OpCode, mem *Memory, stack *Stack, stateObject *StateObject) bool
BreakPoints() []int64
+ SetCode(byteCode []byte)
}
type Vm struct {
@@ -90,7 +91,12 @@ func (self *Vm) Endl() *Vm {
}
func NewVm(state *State, stateManager *StateManager, vars RuntimeVars) *Vm {
- return &Vm{vars: vars, state: state, stateManager: stateManager, logTy: LogTyPretty}
+ lt := LogTyPretty
+ if ethutil.Config.Diff {
+ lt = LogTyDiff
+ }
+
+ return &Vm{vars: vars, state: state, stateManager: stateManager, logTy: lt}
}
var Pow256 = ethutil.BigPow(2, 256)
@@ -107,12 +113,17 @@ func (vm *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
}
}()
+ // Debug hook
+ if vm.Dbg != nil {
+ vm.Dbg.SetCode(closure.Script)
+ }
+
// Don't bother with the execution if there's no code.
if len(closure.Script) == 0 {
return closure.Return(nil), nil
}
- vmlogger.Debugf("(%s) %x gas: %v (d) %x\n", vm.Fn, closure.object.Address(), closure.Gas, closure.Args)
+ vmlogger.Debugf("(%s) %x gas: %v (d) %x\n", vm.Fn, closure.Address(), closure.Gas, closure.Args)
var (
op OpCode
@@ -149,7 +160,7 @@ func (vm *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
b = []byte{0}
}
- fmt.Printf("%x %x %x %x\n", closure.object.Address(), b, []byte{byte(op)}, closure.Gas.Bytes())
+ fmt.Printf("%x %x %x %x\n", closure.Address(), b, []byte{byte(op)}, closure.Gas.Bytes())
}
gas := new(big.Int)
@@ -456,9 +467,9 @@ func (vm *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
vm.Printf(" => %x", data)
// 0x30 range
case ADDRESS:
- stack.Push(ethutil.BigD(closure.Object().Address()))
+ stack.Push(ethutil.BigD(closure.Address()))
- vm.Printf(" => %x", closure.Object().Address())
+ vm.Printf(" => %x", closure.Address())
case BALANCE:
require(1)
@@ -664,9 +675,9 @@ func (vm *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
)
// Generate a new address
- addr := ethcrypto.CreateAddress(closure.object.Address(), closure.object.Nonce)
+ addr := ethcrypto.CreateAddress(closure.Address(), closure.N().Uint64())
for i := uint64(0); vm.state.GetStateObject(addr) != nil; i++ {
- ethcrypto.CreateAddress(closure.object.Address(), closure.object.Nonce+i)
+ ethcrypto.CreateAddress(closure.Address(), closure.N().Uint64()+i)
}
closure.object.Nonce++
@@ -706,6 +717,11 @@ func (vm *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
vm.Printf("CREATE success")
}
vm.Endl()
+
+ // Debug hook
+ if vm.Dbg != nil {
+ vm.Dbg.SetCode(closure.Script)
+ }
case CALL:
require(7)
@@ -749,6 +765,11 @@ func (vm *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
mem.Set(retOffset.Int64(), retSize.Int64(), ret)
}
+
+ // Debug hook
+ if vm.Dbg != nil {
+ vm.Dbg.SetCode(closure.Script)
+ }
}
case RETURN:
require(2)
@@ -786,6 +807,8 @@ func (vm *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
if vm.Dbg != nil {
for _, instrNo := range vm.Dbg.BreakPoints() {
if pc.Cmp(big.NewInt(instrNo)) == 0 {
+ vm.Stepping = true
+
if !vm.Dbg.BreakHook(prevStep, op, mem, stack, closure.Object()) {
return nil, nil
}