debug_vm.go 840 B

1234567891011121314151617181920212223242526272829303132333435
  1. package vm
  2. import (
  3. "fmt"
  4. "github.com/goccy/go-json/internal/encoder"
  5. )
  6. func DebugRun(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]byte, error) {
  7. defer func() {
  8. var code *encoder.Opcode
  9. if (ctx.Option.Flag & encoder.HTMLEscapeOption) != 0 {
  10. code = codeSet.EscapeKeyCode
  11. } else {
  12. code = codeSet.NoescapeKeyCode
  13. }
  14. if err := recover(); err != nil {
  15. w := ctx.Option.DebugOut
  16. fmt.Fprintln(w, "=============[DEBUG]===============")
  17. fmt.Fprintln(w, "* [TYPE]")
  18. fmt.Fprintln(w, codeSet.Type)
  19. fmt.Fprintf(w, "\n")
  20. fmt.Fprintln(w, "* [ALL OPCODE]")
  21. fmt.Fprintln(w, code.Dump())
  22. fmt.Fprintf(w, "\n")
  23. fmt.Fprintln(w, "* [CONTEXT]")
  24. fmt.Fprintf(w, "%+v\n", ctx)
  25. fmt.Fprintln(w, "===================================")
  26. panic(err)
  27. }
  28. }()
  29. return Run(ctx, b, codeSet)
  30. }