diff options
author | Martin Holst Swende <martin@swende.se> | 2017-06-21 20:52:31 +0800 |
---|---|---|
committer | Felix Lange <fjl@users.noreply.github.com> | 2017-06-21 20:52:31 +0800 |
commit | 9a44e1035ed72eec121cf6fbe38761eea20e09c6 (patch) | |
tree | 17f5dbc5267d47bc88126bf23776c4a0b42fc348 /cmd | |
parent | 9012863ad78bca17f768b83324be8a26ddb34657 (diff) | |
download | dexon-9a44e1035ed72eec121cf6fbe38761eea20e09c6.tar dexon-9a44e1035ed72eec121cf6fbe38761eea20e09c6.tar.gz dexon-9a44e1035ed72eec121cf6fbe38761eea20e09c6.tar.bz2 dexon-9a44e1035ed72eec121cf6fbe38761eea20e09c6.tar.lz dexon-9a44e1035ed72eec121cf6fbe38761eea20e09c6.tar.xz dexon-9a44e1035ed72eec121cf6fbe38761eea20e09c6.tar.zst dexon-9a44e1035ed72eec121cf6fbe38761eea20e09c6.zip |
cmd/evm, core/vm: add --nomemory, --nostack to evm (#14617)
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/evm/json_logger.go | 33 | ||||
-rw-r--r-- | cmd/evm/main.go | 10 | ||||
-rw-r--r-- | cmd/evm/runner.go | 10 |
3 files changed, 37 insertions, 16 deletions
diff --git a/cmd/evm/json_logger.go b/cmd/evm/json_logger.go index a84d5daeb..d61981062 100644 --- a/cmd/evm/json_logger.go +++ b/cmd/evm/json_logger.go @@ -28,25 +28,32 @@ import ( type JSONLogger struct { encoder *json.Encoder + cfg *vm.LogConfig } -func NewJSONLogger(writer io.Writer) *JSONLogger { - return &JSONLogger{json.NewEncoder(writer)} +func NewJSONLogger(cfg *vm.LogConfig, writer io.Writer) *JSONLogger { + return &JSONLogger{json.NewEncoder(writer), cfg} } // CaptureState outputs state information on the logger. func (l *JSONLogger) CaptureState(env *vm.EVM, pc uint64, op vm.OpCode, gas, cost uint64, memory *vm.Memory, stack *vm.Stack, contract *vm.Contract, depth int, err error) error { - return l.encoder.Encode(vm.StructLog{ - Pc: pc, - Op: op, - Gas: gas + cost, - GasCost: cost, - Memory: memory.Data(), - Stack: stack.Data(), - Storage: nil, - Depth: depth, - Err: err, - }) + log := vm.StructLog{ + Pc: pc, + Op: op, + Gas: gas + cost, + GasCost: cost, + MemorySize: memory.Len(), + Storage: nil, + Depth: depth, + Err: err, + } + if !l.cfg.DisableMemory { + log.Memory = memory.Data() + } + if !l.cfg.DisableStack { + log.Stack = stack.Data() + } + return l.encoder.Encode(log) } // CaptureEnd is triggered at end of execution. diff --git a/cmd/evm/main.go b/cmd/evm/main.go index 48a1b92cb..1892ae3d3 100644 --- a/cmd/evm/main.go +++ b/cmd/evm/main.go @@ -102,6 +102,14 @@ var ( Name: "sender", Usage: "The transaction origin", } + DisableMemoryFlag = cli.BoolFlag{ + Name: "nomemory", + Usage: "disable memory output", + } + DisableStackFlag = cli.BoolFlag{ + Name: "nostack", + Usage: "disable stack output", + } ) func init() { @@ -123,6 +131,8 @@ func init() { GenesisFlag, MachineFlag, SenderFlag, + DisableMemoryFlag, + DisableStackFlag, } app.Commands = []cli.Command{ compileCommand, diff --git a/cmd/evm/runner.go b/cmd/evm/runner.go index b1fb8998f..2ce0920f6 100644 --- a/cmd/evm/runner.go +++ b/cmd/evm/runner.go @@ -73,6 +73,10 @@ func runCmd(ctx *cli.Context) error { glogger := log.NewGlogHandler(log.StreamHandler(os.Stderr, log.TerminalFormat(false))) glogger.Verbosity(log.Lvl(ctx.GlobalInt(VerbosityFlag.Name))) log.Root().SetHandler(glogger) + logconfig := &vm.LogConfig{ + DisableMemory: ctx.GlobalBool(DisableMemoryFlag.Name), + DisableStack: ctx.GlobalBool(DisableStackFlag.Name), + } var ( tracer vm.Tracer @@ -82,12 +86,12 @@ func runCmd(ctx *cli.Context) error { sender = common.StringToAddress("sender") ) if ctx.GlobalBool(MachineFlag.Name) { - tracer = NewJSONLogger(os.Stdout) + tracer = NewJSONLogger(logconfig, os.Stdout) } else if ctx.GlobalBool(DebugFlag.Name) { - debugLogger = vm.NewStructLogger(nil) + debugLogger = vm.NewStructLogger(logconfig) tracer = debugLogger } else { - debugLogger = vm.NewStructLogger(nil) + debugLogger = vm.NewStructLogger(logconfig) } if ctx.GlobalString(GenesisFlag.Name) != "" { gen := readGenesis(ctx.GlobalString(GenesisFlag.Name)) |