2021-05-18 08:48:13 +03:00
|
|
|
package vm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-03-19 22:53:43 +03:00
|
|
|
"io"
|
2021-05-18 08:48:13 +03:00
|
|
|
|
|
|
|
"github.com/goccy/go-json/internal/encoder"
|
|
|
|
)
|
|
|
|
|
2021-05-31 16:25:33 +03:00
|
|
|
func DebugRun(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]byte, error) {
|
2021-05-18 08:48:13 +03:00
|
|
|
defer func() {
|
2021-05-31 19:25:05 +03:00
|
|
|
var code *encoder.Opcode
|
2021-06-01 07:40:15 +03:00
|
|
|
if (ctx.Option.Flag & encoder.HTMLEscapeOption) != 0 {
|
2021-05-31 19:25:05 +03:00
|
|
|
code = codeSet.EscapeKeyCode
|
|
|
|
} else {
|
|
|
|
code = codeSet.NoescapeKeyCode
|
|
|
|
}
|
2023-03-19 22:53:43 +03:00
|
|
|
if wc := ctx.Option.DebugDOTOut; wc != nil {
|
|
|
|
_, _ = io.WriteString(wc, code.DumpDOT())
|
|
|
|
wc.Close()
|
|
|
|
ctx.Option.DebugDOTOut = nil
|
|
|
|
}
|
2021-05-31 19:25:05 +03:00
|
|
|
|
2021-05-18 08:48:13 +03:00
|
|
|
if err := recover(); err != nil {
|
2022-03-24 23:09:22 +03:00
|
|
|
w := ctx.Option.DebugOut
|
|
|
|
fmt.Fprintln(w, "=============[DEBUG]===============")
|
|
|
|
fmt.Fprintln(w, "* [TYPE]")
|
|
|
|
fmt.Fprintln(w, codeSet.Type)
|
|
|
|
fmt.Fprintf(w, "\n")
|
|
|
|
fmt.Fprintln(w, "* [ALL OPCODE]")
|
|
|
|
fmt.Fprintln(w, code.Dump())
|
|
|
|
fmt.Fprintf(w, "\n")
|
|
|
|
fmt.Fprintln(w, "* [CONTEXT]")
|
|
|
|
fmt.Fprintf(w, "%+v\n", ctx)
|
|
|
|
fmt.Fprintln(w, "===================================")
|
2021-05-18 08:48:13 +03:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2021-05-31 16:25:33 +03:00
|
|
|
return Run(ctx, b, codeSet)
|
2021-05-18 08:48:13 +03:00
|
|
|
}
|