logger.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2015 The go-ethereum Authors
  2. // This file is part of go-ethereum.
  3. //
  4. // go-ethereum 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. // go-ethereum 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 go-ethereum. 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. func StdErrFormat(logs []StructLog) {
  24. fmt.Fprintf(os.Stderr, "VM STAT %d OPs\n", len(logs))
  25. for _, log := range logs {
  26. fmt.Fprintf(os.Stderr, "PC %08d: %s GAS: %v COST: %v", log.Pc, log.Op, log.Gas, log.GasCost)
  27. if log.Err != nil {
  28. fmt.Fprintf(os.Stderr, " ERROR: %v", log.Err)
  29. }
  30. fmt.Fprintf(os.Stderr, "\n")
  31. fmt.Fprintln(os.Stderr, "STACK =", len(log.Stack))
  32. for i := len(log.Stack) - 1; i >= 0; i-- {
  33. fmt.Fprintf(os.Stderr, "%04d: %x\n", len(log.Stack)-i-1, common.LeftPadBytes(log.Stack[i].Bytes(), 32))
  34. }
  35. const maxMem = 10
  36. addr := 0
  37. fmt.Fprintln(os.Stderr, "MEM =", len(log.Memory))
  38. for i := 0; i+16 <= len(log.Memory) && addr < maxMem; i += 16 {
  39. data := log.Memory[i : i+16]
  40. str := fmt.Sprintf("%04d: % x ", addr*16, data)
  41. for _, r := range data {
  42. if r == 0 {
  43. str += "."
  44. } else if unicode.IsPrint(rune(r)) {
  45. str += fmt.Sprintf("%s", string(r))
  46. } else {
  47. str += "?"
  48. }
  49. }
  50. addr++
  51. fmt.Fprintln(os.Stderr, str)
  52. }
  53. fmt.Fprintln(os.Stderr, "STORAGE =", len(log.Storage))
  54. for h, item := range log.Storage {
  55. fmt.Fprintf(os.Stderr, "%x: %x\n", h, common.LeftPadBytes(item, 32))
  56. }
  57. fmt.Fprintln(os.Stderr)
  58. }
  59. }