logger.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. package vm
  17. import (
  18. "fmt"
  19. "os"
  20. "unicode"
  21. "github.com/ethereum/go-ethereum/common"
  22. )
  23. // StdErrFormat formats a slice of StructLogs to human readable format
  24. func StdErrFormat(logs []StructLog) {
  25. fmt.Fprintf(os.Stderr, "VM STAT %d OPs\n", len(logs))
  26. for _, log := range logs {
  27. fmt.Fprintf(os.Stderr, "PC %08d: %s GAS: %v COST: %v", log.Pc, log.Op, log.Gas, log.GasCost)
  28. if log.Err != nil {
  29. fmt.Fprintf(os.Stderr, " ERROR: %v", log.Err)
  30. }
  31. fmt.Fprintf(os.Stderr, "\n")
  32. fmt.Fprintln(os.Stderr, "STACK =", len(log.Stack))
  33. for i := len(log.Stack) - 1; i >= 0; i-- {
  34. fmt.Fprintf(os.Stderr, "%04d: %x\n", len(log.Stack)-i-1, common.LeftPadBytes(log.Stack[i].Bytes(), 32))
  35. }
  36. const maxMem = 10
  37. addr := 0
  38. fmt.Fprintln(os.Stderr, "MEM =", len(log.Memory))
  39. for i := 0; i+16 <= len(log.Memory) && addr < maxMem; i += 16 {
  40. data := log.Memory[i : i+16]
  41. str := fmt.Sprintf("%04d: % x ", addr*16, data)
  42. for _, r := range data {
  43. if r == 0 {
  44. str += "."
  45. } else if unicode.IsPrint(rune(r)) {
  46. str += fmt.Sprintf("%s", string(r))
  47. } else {
  48. str += "?"
  49. }
  50. }
  51. addr++
  52. fmt.Fprintln(os.Stderr, str)
  53. }
  54. fmt.Fprintln(os.Stderr, "STORAGE =", len(log.Storage))
  55. for h, item := range log.Storage {
  56. fmt.Fprintf(os.Stderr, "%x: %x\n", h, common.LeftPadBytes(item, 32))
  57. }
  58. fmt.Fprintln(os.Stderr)
  59. }
  60. }