Skip to content

Commit

Permalink
Debugging mode for vm
Browse files Browse the repository at this point in the history
  • Loading branch information
obscuren committed Jul 5, 2014
1 parent 329887d commit b232acd
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions ethchain/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,10 @@ var (
GasTx = big.NewInt(500)
)

func CalculateTxGas(initSize *big.Int) *big.Int {
totalGas := new(big.Int)

txTotalBytes := new(big.Int).Set(initSize)
txTotalBytes.Div(txTotalBytes, ethutil.Big32)
totalGas.Add(totalGas, new(big.Int).Mul(txTotalBytes, GasSStore))

return totalGas
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
}

type Vm struct {
Expand All @@ -53,14 +49,13 @@ type Vm struct {
err error

// Debugging
Hook DebugHook
Dbg Debugger

BreakPoints []int64
Stepping bool
Fn string
}

type DebugHook func(step int, op OpCode, mem *Memory, stack *Stack, stateObject *StateObject) bool

type RuntimeVars struct {
Origin []byte
Block *Block
Expand Down Expand Up @@ -754,12 +749,14 @@ func (vm *Vm) RunClosure(closure *Closure) (ret []byte, err error) {

vm.Endl()

if vm.Hook != nil {
for _, instrNo := range vm.BreakPoints {
if pc.Cmp(big.NewInt(instrNo)) == 0 || vm.Stepping {
vm.Stepping = true

if !vm.Hook(prevStep, op, mem, stack, closure.Object()) {
if vm.Dbg != nil {
for _, instrNo := range vm.Dbg.BreakPoints() {
if pc.Cmp(big.NewInt(instrNo)) == 0 {
if !vm.Dbg.BreakHook(prevStep, op, mem, stack, closure.Object()) {
return nil, nil
}
} else if vm.Stepping {
if !vm.Dbg.StepHook(prevStep, op, mem, stack, closure.Object()) {
return nil, nil
}
}
Expand Down

0 comments on commit b232acd

Please sign in to comment.