forked from mirror/go-ethereum
commit
0dda955f90
@ -0,0 +1,215 @@ |
|||||||
|
import QtQuick 2.0 |
||||||
|
import QtQuick.Controls 1.0; |
||||||
|
import QtQuick.Layouts 1.0; |
||||||
|
import QtQuick.Dialogs 1.0; |
||||||
|
import QtQuick.Window 2.1; |
||||||
|
import QtQuick.Controls.Styles 1.1 |
||||||
|
import Ethereum 1.0 |
||||||
|
|
||||||
|
ApplicationWindow { |
||||||
|
visible: false |
||||||
|
title: "IceCream" |
||||||
|
minimumWidth: 1280 |
||||||
|
minimumHeight: 900 |
||||||
|
width: 1290 |
||||||
|
height: 900 |
||||||
|
|
||||||
|
SplitView { |
||||||
|
anchors.fill: parent |
||||||
|
property var asmModel: ListModel { |
||||||
|
id: asmModel |
||||||
|
} |
||||||
|
TableView { |
||||||
|
id: asmTableView |
||||||
|
width: 200 |
||||||
|
TableViewColumn{ role: "value" ; title: "" ; width: 100 } |
||||||
|
model: asmModel |
||||||
|
} |
||||||
|
|
||||||
|
Rectangle { |
||||||
|
color: "#00000000" |
||||||
|
anchors.left: asmTableView.right |
||||||
|
anchors.right: parent.right |
||||||
|
SplitView { |
||||||
|
orientation: Qt.Vertical |
||||||
|
anchors.fill: parent |
||||||
|
|
||||||
|
Rectangle { |
||||||
|
color: "#00000000" |
||||||
|
height: 500 |
||||||
|
anchors.left: parent.left |
||||||
|
anchors.right: parent.right |
||||||
|
|
||||||
|
TextArea { |
||||||
|
id: codeEditor |
||||||
|
anchors.top: parent.top |
||||||
|
anchors.bottom: parent.bottom |
||||||
|
anchors.left: parent.left |
||||||
|
anchors.right: settings.left |
||||||
|
} |
||||||
|
|
||||||
|
Column { |
||||||
|
id: settings |
||||||
|
spacing: 5 |
||||||
|
width: 300 |
||||||
|
height: parent.height |
||||||
|
anchors.right: parent.right |
||||||
|
anchors.top: parent.top |
||||||
|
anchors.bottom: parent.bottom |
||||||
|
|
||||||
|
Label { |
||||||
|
text: "Arbitrary data" |
||||||
|
} |
||||||
|
TextArea { |
||||||
|
id: rawDataField |
||||||
|
anchors.left: parent.left |
||||||
|
anchors.right: parent.right |
||||||
|
height: 150 |
||||||
|
} |
||||||
|
|
||||||
|
Label { |
||||||
|
text: "Amount" |
||||||
|
} |
||||||
|
TextField { |
||||||
|
id: txValue |
||||||
|
width: 200 |
||||||
|
placeholderText: "Amount" |
||||||
|
validator: RegExpValidator { regExp: /\d*/ } |
||||||
|
} |
||||||
|
Label { |
||||||
|
text: "Amount of gas" |
||||||
|
} |
||||||
|
TextField { |
||||||
|
id: txGas |
||||||
|
width: 200 |
||||||
|
validator: RegExpValidator { regExp: /\d*/ } |
||||||
|
text: "10000" |
||||||
|
placeholderText: "Gas" |
||||||
|
} |
||||||
|
Label { |
||||||
|
text: "Gas price" |
||||||
|
} |
||||||
|
TextField { |
||||||
|
id: txGasPrice |
||||||
|
width: 200 |
||||||
|
placeholderText: "Gas price" |
||||||
|
text: "1000000000000" |
||||||
|
validator: RegExpValidator { regExp: /\d*/ } |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
SplitView { |
||||||
|
orientation: Qt.Vertical |
||||||
|
id: inspectorPane |
||||||
|
height: 500 |
||||||
|
|
||||||
|
SplitView { |
||||||
|
orientation: Qt.Horizontal |
||||||
|
height: 250 |
||||||
|
|
||||||
|
TableView { |
||||||
|
id: stackTableView |
||||||
|
property var stackModel: ListModel { |
||||||
|
id: stackModel |
||||||
|
} |
||||||
|
height: parent.height |
||||||
|
width: 300 |
||||||
|
TableViewColumn{ role: "value" ; title: "Stack" ; width: 200 } |
||||||
|
model: stackModel |
||||||
|
} |
||||||
|
|
||||||
|
TableView { |
||||||
|
id: memoryTableView |
||||||
|
property var memModel: ListModel { |
||||||
|
id: memModel |
||||||
|
} |
||||||
|
height: parent.height |
||||||
|
width: parent.width - stackTableView.width |
||||||
|
TableViewColumn{ id:mnumColmn ; role: "num" ; title: "#" ; width: 50} |
||||||
|
TableViewColumn{ role: "value" ; title: "Memory" ; width: 750} |
||||||
|
model: memModel |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
SplitView { |
||||||
|
height: 300 |
||||||
|
TableView { |
||||||
|
id: storageTableView |
||||||
|
property var memModel: ListModel { |
||||||
|
id: storageModel |
||||||
|
} |
||||||
|
height: parent.height |
||||||
|
width: parent.width - stackTableView.width |
||||||
|
TableViewColumn{ id: key ; role: "key" ; title: "#" ; width: storageTableView.width / 2} |
||||||
|
TableViewColumn{ role: "value" ; title: "value" ; width: storageTableView.width / 2} |
||||||
|
model: storageModel |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
toolBar: ToolBar { |
||||||
|
RowLayout { |
||||||
|
spacing: 5 |
||||||
|
|
||||||
|
Button { |
||||||
|
property var enabled: true |
||||||
|
id: debugStart |
||||||
|
onClicked: { |
||||||
|
dbg.debug(txValue.text, txGas.text, txGasPrice.text, codeEditor.text, rawDataField.text) |
||||||
|
} |
||||||
|
text: "Debug" |
||||||
|
} |
||||||
|
|
||||||
|
Button { |
||||||
|
property var enabled: true |
||||||
|
id: debugNextButton |
||||||
|
onClicked: { |
||||||
|
dbg.next() |
||||||
|
} |
||||||
|
text: "Next" |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
function setAsm(asm) { |
||||||
|
asmModel.append({asm: asm}) |
||||||
|
} |
||||||
|
|
||||||
|
function clearAsm() { |
||||||
|
asmModel.clear() |
||||||
|
} |
||||||
|
|
||||||
|
function setInstruction(num) { |
||||||
|
asmTableView.selection.clear() |
||||||
|
asmTableView.selection.select(num-1) |
||||||
|
} |
||||||
|
|
||||||
|
function setMem(mem) { |
||||||
|
memModel.append({num: mem.num, value: mem.value}) |
||||||
|
} |
||||||
|
function clearMem(){ |
||||||
|
memModel.clear() |
||||||
|
} |
||||||
|
|
||||||
|
function setStack(stack) { |
||||||
|
stackModel.append({value: stack}) |
||||||
|
} |
||||||
|
function addDebugMessage(message){ |
||||||
|
debuggerLog.append({value: message}) |
||||||
|
} |
||||||
|
|
||||||
|
function clearStack() { |
||||||
|
stackModel.clear() |
||||||
|
} |
||||||
|
|
||||||
|
function clearStorage() { |
||||||
|
storageModel.clear() |
||||||
|
} |
||||||
|
|
||||||
|
function setStorage(storage) { |
||||||
|
storageModel.append({key: storage.key, value: storage.value}) |
||||||
|
} |
||||||
|
} |
After Width: | Height: | Size: 4.2 KiB |
@ -0,0 +1,177 @@ |
|||||||
|
package ethui |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
"github.com/ethereum/eth-go/ethchain" |
||||||
|
"github.com/ethereum/eth-go/ethutil" |
||||||
|
"github.com/go-qml/qml" |
||||||
|
"math/big" |
||||||
|
"strings" |
||||||
|
) |
||||||
|
|
||||||
|
type DebuggerWindow struct { |
||||||
|
win *qml.Window |
||||||
|
engine *qml.Engine |
||||||
|
lib *UiLib |
||||||
|
Db *Debugger |
||||||
|
} |
||||||
|
|
||||||
|
func NewDebuggerWindow(lib *UiLib) *DebuggerWindow { |
||||||
|
engine := qml.NewEngine() |
||||||
|
component, err := engine.LoadFile(lib.AssetPath("debugger/debugger.qml")) |
||||||
|
if err != nil { |
||||||
|
fmt.Println(err) |
||||||
|
|
||||||
|
return nil |
||||||
|
} |
||||||
|
|
||||||
|
win := component.CreateWindow(nil) |
||||||
|
db := &Debugger{win, make(chan bool), make(chan bool), true} |
||||||
|
|
||||||
|
return &DebuggerWindow{engine: engine, win: win, lib: lib, Db: db} |
||||||
|
} |
||||||
|
|
||||||
|
func (self *DebuggerWindow) Show() { |
||||||
|
context := self.engine.Context() |
||||||
|
context.SetVar("dbg", self) |
||||||
|
|
||||||
|
go func() { |
||||||
|
self.win.Show() |
||||||
|
self.win.Wait() |
||||||
|
}() |
||||||
|
} |
||||||
|
|
||||||
|
func formatData(data string) []byte { |
||||||
|
if len(data) == 0 { |
||||||
|
return nil |
||||||
|
} |
||||||
|
// Simple stupid
|
||||||
|
d := new(big.Int) |
||||||
|
if data[0:1] == "\"" && data[len(data)-1:] == "\"" { |
||||||
|
d.SetBytes([]byte(data[1 : len(data)-1])) |
||||||
|
} else if data[:2] == "0x" { |
||||||
|
d.SetBytes(ethutil.FromHex(data[2:])) |
||||||
|
} else { |
||||||
|
d.SetString(data, 0) |
||||||
|
} |
||||||
|
|
||||||
|
return ethutil.BigToBytes(d, 256) |
||||||
|
} |
||||||
|
|
||||||
|
func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, dataStr string) { |
||||||
|
if !self.Db.done { |
||||||
|
self.Db.Q <- true |
||||||
|
} |
||||||
|
|
||||||
|
dataSlice := strings.Split(dataStr, "\n") |
||||||
|
var data []byte |
||||||
|
for _, dataItem := range dataSlice { |
||||||
|
d := formatData(dataItem) |
||||||
|
data = append(data, d...) |
||||||
|
} |
||||||
|
|
||||||
|
state := self.lib.eth.BlockChain().CurrentBlock.State() |
||||||
|
|
||||||
|
defer func() { |
||||||
|
if r := recover(); r != nil { |
||||||
|
fmt.Println(r) |
||||||
|
} |
||||||
|
}() |
||||||
|
|
||||||
|
script, err := ethutil.Compile(scriptStr) |
||||||
|
if err != nil { |
||||||
|
ethutil.Config.Log.Debugln(err) |
||||||
|
|
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
dis := ethchain.Disassemble(script) |
||||||
|
self.win.Root().Call("clearAsm") |
||||||
|
|
||||||
|
for _, str := range dis { |
||||||
|
self.win.Root().Call("setAsm", str) |
||||||
|
} |
||||||
|
// Contract addr as test address
|
||||||
|
keyPair := ethutil.GetKeyRing().Get(0) |
||||||
|
callerTx := ethchain.NewContractCreationTx(ethutil.Big(valueStr), ethutil.Big(gasStr), ethutil.Big(gasPriceStr), script) |
||||||
|
callerTx.Sign(keyPair.PrivateKey) |
||||||
|
|
||||||
|
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)) |
||||||
|
|
||||||
|
block := self.lib.eth.BlockChain().CurrentBlock |
||||||
|
vm := ethchain.NewVm(state, self.lib.eth.StateManager(), ethchain.RuntimeVars{ |
||||||
|
Origin: account.Address(), |
||||||
|
BlockNumber: block.BlockInfo().Number, |
||||||
|
PrevHash: block.PrevHash, |
||||||
|
Coinbase: block.Coinbase, |
||||||
|
Time: block.Time, |
||||||
|
Diff: block.Difficulty, |
||||||
|
}) |
||||||
|
|
||||||
|
self.Db.done = false |
||||||
|
go func() { |
||||||
|
callerClosure.Call(vm, data, self.Db.halting) |
||||||
|
|
||||||
|
state.Reset() |
||||||
|
|
||||||
|
self.Db.done = true |
||||||
|
}() |
||||||
|
} |
||||||
|
|
||||||
|
func (self *DebuggerWindow) Next() { |
||||||
|
self.Db.Next() |
||||||
|
} |
||||||
|
|
||||||
|
type Debugger struct { |
||||||
|
win *qml.Window |
||||||
|
N chan bool |
||||||
|
Q chan bool |
||||||
|
done bool |
||||||
|
} |
||||||
|
|
||||||
|
type storeVal struct { |
||||||
|
Key, Value string |
||||||
|
} |
||||||
|
|
||||||
|
func (d *Debugger) halting(pc int, op ethchain.OpCode, mem *ethchain.Memory, stack *ethchain.Stack, stateObject *ethchain.StateObject) bool { |
||||||
|
d.win.Root().Call("setInstruction", pc) |
||||||
|
d.win.Root().Call("clearMem") |
||||||
|
d.win.Root().Call("clearStack") |
||||||
|
d.win.Root().Call("clearStorage") |
||||||
|
|
||||||
|
addr := 0 |
||||||
|
for i := 0; i+32 <= mem.Len(); i += 32 { |
||||||
|
d.win.Root().Call("setMem", memAddr{fmt.Sprintf("%03d", addr), fmt.Sprintf("% x", mem.Data()[i:i+32])}) |
||||||
|
addr++ |
||||||
|
} |
||||||
|
|
||||||
|
for _, val := range stack.Data() { |
||||||
|
d.win.Root().Call("setStack", val.String()) |
||||||
|
} |
||||||
|
|
||||||
|
stateObject.State().EachStorage(func(key string, node *ethutil.Value) { |
||||||
|
d.win.Root().Call("setStorage", storeVal{fmt.Sprintf("% x", key), fmt.Sprintf("% x", node.Str())}) |
||||||
|
}) |
||||||
|
|
||||||
|
out: |
||||||
|
for { |
||||||
|
select { |
||||||
|
case <-d.N: |
||||||
|
break out |
||||||
|
case <-d.Q: |
||||||
|
d.done = true |
||||||
|
|
||||||
|
return false |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return true |
||||||
|
} |
||||||
|
|
||||||
|
func (d *Debugger) Next() { |
||||||
|
if !d.done { |
||||||
|
d.N <- true |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue