diff options
author | zelig <viktor.tron@gmail.com> | 2014-07-05 19:53:00 +0800 |
---|---|---|
committer | zelig <viktor.tron@gmail.com> | 2014-07-05 19:53:00 +0800 |
commit | 4fb2905b1ef764fd5e26d0eda5f4b7bf4adda195 (patch) | |
tree | f230131da69f816d7f33207268cc5b72692f17f0 | |
parent | 44d0d6abd26bcaca0e1caecf798183b45fb2365a (diff) | |
parent | b232acd04ef957fb65e1c49b330165535da7e871 (diff) | |
download | go-tangerine-4fb2905b1ef764fd5e26d0eda5f4b7bf4adda195.tar.gz go-tangerine-4fb2905b1ef764fd5e26d0eda5f4b7bf4adda195.tar.zst go-tangerine-4fb2905b1ef764fd5e26d0eda5f4b7bf4adda195.zip |
Merge branch 'develop' of github.com:ethereum/eth-go into feature/ethutil-refactor
-rw-r--r-- | ethchain/vm.go | 31 | ||||
-rw-r--r-- | ethlog/loggers.go | 20 |
2 files changed, 28 insertions, 23 deletions
diff --git a/ethchain/vm.go b/ethchain/vm.go index cfedadb08..769333649 100644 --- a/ethchain/vm.go +++ b/ethchain/vm.go @@ -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 { @@ -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 @@ -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 } } diff --git a/ethlog/loggers.go b/ethlog/loggers.go index 9ebe59096..219c78240 100644 --- a/ethlog/loggers.go +++ b/ethlog/loggers.go @@ -39,7 +39,7 @@ func (msg *logMessage) send(logger LogSystem) { var logMessages chan (*logMessage) var logSystems []LogSystem -var drained = true +var quit chan bool type LogLevel uint8 @@ -54,6 +54,7 @@ const ( // log messages are dispatched to log writers func start() { +out: for { select { case msg := <-logMessages: @@ -62,15 +63,23 @@ func start() { msg.send(logSystem) } } - default: - drained = true + case <-quit: + break out } } } // waits until log messages are drained (dispatched to log writers) func Flush() { - for !drained { + quit <- true + +done: + for { + select { + case <-logMessages: + default: + break done + } } } @@ -88,6 +97,7 @@ func AddLogSystem(logSystem LogSystem) { defer mutex.Unlock() if logSystems == nil { logMessages = make(chan *logMessage) + quit = make(chan bool) go start() } logSystems = append(logSystems, logSystem) @@ -96,7 +106,6 @@ func AddLogSystem(logSystem LogSystem) { func (logger *Logger) sendln(level LogLevel, v ...interface{}) { if logMessages != nil { msg := newPrintlnLogMessage(level, logger.tag, v...) - drained = false logMessages <- msg } } @@ -104,7 +113,6 @@ func (logger *Logger) sendln(level LogLevel, v ...interface{}) { func (logger *Logger) sendf(level LogLevel, format string, v ...interface{}) { if logMessages != nil { msg := newPrintfLogMessage(level, logger.tag, format, v...) - drained = false logMessages <- msg } } |