aboutsummaryrefslogtreecommitdiffstats
path: root/ethereal/ui/debugger.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-06-10 04:24:24 +0800
committerobscuren <geffobscura@gmail.com>2014-06-10 04:24:24 +0800
commitaa8a86f0a61286b3d0709316215ce6e9d3833f25 (patch)
tree97aa0aae649463bf8bc0701555ab8d42f9d5a77c /ethereal/ui/debugger.go
parent98811f11e5d7ccf6e053b46b9ca2ed897140ce47 (diff)
parentd929c634749c3c2db9f3290e635a763eba211656 (diff)
downloaddexon-aa8a86f0a61286b3d0709316215ce6e9d3833f25.tar
dexon-aa8a86f0a61286b3d0709316215ce6e9d3833f25.tar.gz
dexon-aa8a86f0a61286b3d0709316215ce6e9d3833f25.tar.bz2
dexon-aa8a86f0a61286b3d0709316215ce6e9d3833f25.tar.lz
dexon-aa8a86f0a61286b3d0709316215ce6e9d3833f25.tar.xz
dexon-aa8a86f0a61286b3d0709316215ce6e9d3833f25.tar.zst
dexon-aa8a86f0a61286b3d0709316215ce6e9d3833f25.zip
Merge branch 'release/poc5-rc12'
Diffstat (limited to 'ethereal/ui/debugger.go')
-rw-r--r--ethereal/ui/debugger.go56
1 files changed, 45 insertions, 11 deletions
diff --git a/ethereal/ui/debugger.go b/ethereal/ui/debugger.go
index a6b8e16d0..919407b34 100644
--- a/ethereal/ui/debugger.go
+++ b/ethereal/ui/debugger.go
@@ -5,6 +5,7 @@ import (
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethutil"
"github.com/go-qml/qml"
+ "math/big"
"strings"
)
@@ -25,7 +26,7 @@ func NewDebuggerWindow(lib *UiLib) *DebuggerWindow {
}
win := component.CreateWindow(nil)
- db := &Debugger{win, make(chan bool), make(chan bool), true}
+ db := &Debugger{win, make(chan bool), make(chan bool), true, false}
return &DebuggerWindow{engine: engine, win: win, lib: lib, Db: db}
}
@@ -59,6 +60,12 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, data
self.Db.Q <- true
}
+ defer func() {
+ if r := recover(); r != nil {
+ self.Logf("compile FAULT: %v", r)
+ }
+ }()
+
data := ethutil.StringToByteFunc(dataStr, func(s string) (ret []byte) {
slice := strings.Split(dataStr, "\n")
for _, dataItem := range slice {
@@ -89,15 +96,17 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, data
self.win.Root().Call("setAsm", str)
}
+ gas := ethutil.Big(gasStr)
+ gasPrice := ethutil.Big(gasPriceStr)
// Contract addr as test address
keyPair := ethutil.GetKeyRing().Get(0)
- callerTx := ethchain.NewContractCreationTx(ethutil.Big(valueStr), ethutil.Big(gasStr), ethutil.Big(gasPriceStr), script)
+ callerTx := ethchain.NewContractCreationTx(ethutil.Big(valueStr), gas, gasPrice, script)
callerTx.Sign(keyPair.PrivateKey)
state := self.lib.eth.BlockChain().CurrentBlock.State()
account := self.lib.eth.StateManager().TransState().GetAccount(keyPair.Address())
contract := ethchain.MakeContract(callerTx, state)
- callerClosure := ethchain.NewClosure(account, contract, script, state, ethutil.Big(gasStr), ethutil.Big(gasPriceStr))
+ callerClosure := ethchain.NewClosure(account, contract, script, state, gas, gasPrice)
block := self.lib.eth.BlockChain().CurrentBlock
vm := ethchain.NewVm(state, self.lib.eth.StateManager(), ethchain.RuntimeVars{
@@ -111,17 +120,28 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, data
})
self.Db.done = false
+ self.Logf("callsize %d", len(script))
go func() {
- ret, _, err := callerClosure.Call(vm, data, self.Db.halting)
+ ret, g, err := callerClosure.Call(vm, data, self.Db.halting)
+ tot := new(big.Int).Mul(g, gasPrice)
+ self.Logf("gas usage %v total price = %v (%v)", g, tot, ethutil.CurrencyToString(tot))
if err != nil {
self.Logln("exited with errors:", err)
} else {
- self.Logf("exited: %v", ret)
+ if len(ret) > 0 {
+ self.Logf("exited: % x", ret)
+ } else {
+ self.Logf("exited: nil")
+ }
}
state.Reset()
- self.Db.done = true
+ if !self.Db.interrupt {
+ self.Db.done = true
+ } else {
+ self.Db.interrupt = false
+ }
}()
}
@@ -139,10 +159,10 @@ func (self *DebuggerWindow) Next() {
}
type Debugger struct {
- win *qml.Window
- N chan bool
- Q chan bool
- done bool
+ win *qml.Window
+ N chan bool
+ Q chan bool
+ done, interrupt bool
}
type storeVal struct {
@@ -175,7 +195,8 @@ out:
case <-d.N:
break out
case <-d.Q:
- d.done = true
+ d.interrupt = true
+ d.clearBuffers()
return false
}
@@ -184,6 +205,19 @@ out:
return true
}
+func (d *Debugger) clearBuffers() {
+out:
+ // drain
+ for {
+ select {
+ case <-d.N:
+ case <-d.Q:
+ default:
+ break out
+ }
+ }
+}
+
func (d *Debugger) Next() {
if !d.done {
d.N <- true