forked from cerc-io/plugeth
Debugging mode for vm
This commit is contained in:
parent
329887df99
commit
b232acd04e
@ -24,14 +24,10 @@ var (
|
|||||||
GasTx = big.NewInt(500)
|
GasTx = big.NewInt(500)
|
||||||
)
|
)
|
||||||
|
|
||||||
func CalculateTxGas(initSize *big.Int) *big.Int {
|
type Debugger interface {
|
||||||
totalGas := new(big.Int)
|
BreakHook(step int, op OpCode, mem *Memory, stack *Stack, stateObject *StateObject) bool
|
||||||
|
StepHook(step int, op OpCode, mem *Memory, stack *Stack, stateObject *StateObject) bool
|
||||||
txTotalBytes := new(big.Int).Set(initSize)
|
BreakPoints() []int64
|
||||||
txTotalBytes.Div(txTotalBytes, ethutil.Big32)
|
|
||||||
totalGas.Add(totalGas, new(big.Int).Mul(txTotalBytes, GasSStore))
|
|
||||||
|
|
||||||
return totalGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Vm struct {
|
type Vm struct {
|
||||||
@ -53,14 +49,13 @@ type Vm struct {
|
|||||||
err error
|
err error
|
||||||
|
|
||||||
// Debugging
|
// Debugging
|
||||||
Hook DebugHook
|
Dbg Debugger
|
||||||
|
|
||||||
BreakPoints []int64
|
BreakPoints []int64
|
||||||
Stepping bool
|
Stepping bool
|
||||||
Fn string
|
Fn string
|
||||||
}
|
}
|
||||||
|
|
||||||
type DebugHook func(step int, op OpCode, mem *Memory, stack *Stack, stateObject *StateObject) bool
|
|
||||||
|
|
||||||
type RuntimeVars struct {
|
type RuntimeVars struct {
|
||||||
Origin []byte
|
Origin []byte
|
||||||
Block *Block
|
Block *Block
|
||||||
@ -754,12 +749,14 @@ func (vm *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
|
|||||||
|
|
||||||
vm.Endl()
|
vm.Endl()
|
||||||
|
|
||||||
if vm.Hook != nil {
|
if vm.Dbg != nil {
|
||||||
for _, instrNo := range vm.BreakPoints {
|
for _, instrNo := range vm.Dbg.BreakPoints() {
|
||||||
if pc.Cmp(big.NewInt(instrNo)) == 0 || vm.Stepping {
|
if pc.Cmp(big.NewInt(instrNo)) == 0 {
|
||||||
vm.Stepping = true
|
if !vm.Dbg.BreakHook(prevStep, op, mem, stack, closure.Object()) {
|
||||||
|
return nil, nil
|
||||||
if !vm.Hook(prevStep, op, mem, stack, closure.Object()) {
|
}
|
||||||
|
} else if vm.Stepping {
|
||||||
|
if !vm.Dbg.StepHook(prevStep, op, mem, stack, closure.Object()) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user