aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2017-03-01 17:19:15 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2017-03-01 18:20:25 +0800
commitbf4155846cf1adaf03e6395a93ce911f315acdbf (patch)
treeeec6000ddf86fda4b71c7da1ecd078043884b379 /core
parent230cf2ec9142b6a8f421cb8873deb5df1566e89c (diff)
downloadgo-tangerine-bf4155846cf1adaf03e6395a93ce911f315acdbf.tar
go-tangerine-bf4155846cf1adaf03e6395a93ce911f315acdbf.tar.gz
go-tangerine-bf4155846cf1adaf03e6395a93ce911f315acdbf.tar.bz2
go-tangerine-bf4155846cf1adaf03e6395a93ce911f315acdbf.tar.lz
go-tangerine-bf4155846cf1adaf03e6395a93ce911f315acdbf.tar.xz
go-tangerine-bf4155846cf1adaf03e6395a93ce911f315acdbf.tar.zst
go-tangerine-bf4155846cf1adaf03e6395a93ce911f315acdbf.zip
core/evm, core/vm: improved evm trace output
* Improved the standard evm tracer output and renamed it to WriteTrace which now takes an io.Writer to write the logs to. * Added WriteLogs which writes logs to the given writer in a readable format. * evm utility now also prints logs generated during the execution.
Diffstat (limited to 'core')
-rw-r--r--core/vm/logger.go40
1 files changed, 25 insertions, 15 deletions
diff --git a/core/vm/logger.go b/core/vm/logger.go
index ccdf21a4b..3d7e1c95f 100644
--- a/core/vm/logger.go
+++ b/core/vm/logger.go
@@ -19,11 +19,12 @@ package vm
import (
"encoding/hex"
"fmt"
+ "io"
"math/big"
- "os"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
+ "github.com/ethereum/go-ethereum/core/types"
)
type Storage map[common.Hash]common.Hash
@@ -168,29 +169,38 @@ func (l *StructLogger) StructLogs() []StructLog {
return l.logs
}
-// StdErrFormat formats a slice of StructLogs to human readable format
-func StdErrFormat(logs []StructLog) {
- fmt.Fprintf(os.Stderr, "VM STAT %d OPs\n", len(logs))
+// WriteTrace writes a formatted trace to the given writer
+func WriteTrace(writer io.Writer, logs []StructLog) {
for _, log := range logs {
- fmt.Fprintf(os.Stderr, "PC %08d: %s GAS: %v COST: %v", log.Pc, log.Op, log.Gas, log.GasCost)
+ fmt.Fprintf(writer, "%-10spc=%08d gas=%v cost=%v", log.Op, log.Pc, log.Gas, log.GasCost)
if log.Err != nil {
- fmt.Fprintf(os.Stderr, " ERROR: %v", log.Err)
+ fmt.Fprintf(writer, " ERROR: %v", log.Err)
}
- fmt.Fprintf(os.Stderr, "\n")
-
- fmt.Fprintln(os.Stderr, "STACK =", len(log.Stack))
+ fmt.Fprintf(writer, "\n")
for i := len(log.Stack) - 1; i >= 0; i-- {
- fmt.Fprintf(os.Stderr, "%04d: %x\n", len(log.Stack)-i-1, math.PaddedBigBytes(log.Stack[i], 32))
+ fmt.Fprintf(writer, "%08d %x\n", len(log.Stack)-i-1, math.PaddedBigBytes(log.Stack[i], 32))
}
- fmt.Fprintln(os.Stderr, "MEM =", len(log.Memory))
- fmt.Fprintln(os.Stderr, hex.Dump(log.Memory))
+ fmt.Fprint(writer, hex.Dump(log.Memory))
- fmt.Fprintln(os.Stderr, "STORAGE =", len(log.Storage))
for h, item := range log.Storage {
- fmt.Fprintf(os.Stderr, "%x: %x\n", h, item)
+ fmt.Fprintf(writer, "%x: %x\n", h, item)
+ }
+ fmt.Fprintln(writer)
+ }
+}
+
+// WriteLogs writes vm logs in a readable format to the given writer
+func WriteLogs(writer io.Writer, logs []*types.Log) {
+ for _, log := range logs {
+ fmt.Fprintf(writer, "LOG%d: %x bn=%d txi=%x\n", len(log.Topics), log.Address, log.BlockNumber, log.TxIndex)
+
+ for i, topic := range log.Topics {
+ fmt.Fprintf(writer, "%08d %x\n", i, topic)
}
- fmt.Fprintln(os.Stderr)
+
+ fmt.Fprint(writer, hex.Dump(log.Data))
+ fmt.Fprintln(writer)
}
}