github.com/jeffallen/go-ethereum@v1.1.4-0.20150910155051-571d3236c49c/core/vm/logger.go (about) 1 // Copyright 2015 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 package vm 18 19 import ( 20 "fmt" 21 "os" 22 "unicode" 23 24 "github.com/ethereum/go-ethereum/common" 25 ) 26 27 func StdErrFormat(logs []StructLog) { 28 fmt.Fprintf(os.Stderr, "VM STAT %d OPs\n", len(logs)) 29 for _, log := range logs { 30 fmt.Fprintf(os.Stderr, "PC %08d: %s GAS: %v COST: %v", log.Pc, log.Op, log.Gas, log.GasCost) 31 if log.Err != nil { 32 fmt.Fprintf(os.Stderr, " ERROR: %v", log.Err) 33 } 34 fmt.Fprintf(os.Stderr, "\n") 35 36 fmt.Fprintln(os.Stderr, "STACK =", len(log.Stack)) 37 38 for i := len(log.Stack) - 1; i >= 0; i-- { 39 fmt.Fprintf(os.Stderr, "%04d: %x\n", len(log.Stack)-i-1, common.LeftPadBytes(log.Stack[i].Bytes(), 32)) 40 } 41 42 const maxMem = 10 43 addr := 0 44 fmt.Fprintln(os.Stderr, "MEM =", len(log.Memory)) 45 for i := 0; i+16 <= len(log.Memory) && addr < maxMem; i += 16 { 46 data := log.Memory[i : i+16] 47 str := fmt.Sprintf("%04d: % x ", addr*16, data) 48 for _, r := range data { 49 if r == 0 { 50 str += "." 51 } else if unicode.IsPrint(rune(r)) { 52 str += fmt.Sprintf("%s", string(r)) 53 } else { 54 str += "?" 55 } 56 } 57 addr++ 58 fmt.Fprintln(os.Stderr, str) 59 } 60 61 fmt.Fprintln(os.Stderr, "STORAGE =", len(log.Storage)) 62 for h, item := range log.Storage { 63 fmt.Fprintf(os.Stderr, "%x: %x\n", h, common.LeftPadBytes(item, 32)) 64 } 65 fmt.Fprintln(os.Stderr) 66 } 67 }