MCPcopy
hub / github.com/google/mtail / DumpByteCode

Method DumpByteCode

internal/runtime/vm/vm.go:1012–1040  ·  view source on GitHub ↗

DumpByteCode emits the program disassembly and program objects to a string.

()

Source from the content-addressed store, hash-verified

1010
1011// DumpByteCode emits the program disassembly and program objects to a string.
1012func (v *VM) DumpByteCode() string {
1013 b := new(bytes.Buffer)
1014 fmt.Fprintf(b, "Prog: %s\n", v.name)
1015 fmt.Fprintln(b, "Metrics")
1016 for i, m := range v.Metrics {
1017 if m.Program == v.name {
1018 fmt.Fprintf(b, " %8d %s\n", i, m)
1019 }
1020 }
1021 fmt.Fprintln(b, "Regexps")
1022 for i, re := range v.re {
1023 fmt.Fprintf(b, " %8d /%s/\n", i, re)
1024 }
1025 fmt.Fprintln(b, "Strings")
1026 for i, str := range v.str {
1027 fmt.Fprintf(b, " %8d \"%s\"\n", i, str)
1028 }
1029 w := new(tabwriter.Writer)
1030 w.Init(b, 0, 0, 1, ' ', tabwriter.AlignRight)
1031
1032 fmt.Fprintln(w, "disasm\tl\top\topnd\tline\t")
1033 for n, i := range v.prog {
1034 fmt.Fprintf(w, "\t%d\t%s\t%v\t%d\t\n", n, i.Opcode, i.Operand, i.SourceLine+1)
1035 }
1036 if err := w.Flush(); err != nil {
1037 glog.Infof("flush error: %s", err)
1038 }
1039 return b.String()
1040}
1041
1042// RuntimeErrorString returns the last runtime erro rthat the program enountered.
1043func (v *VM) RuntimeErrorString() string {

Callers 4

errorfMethod · 0.95
FuzzFunction · 0.80
ProgzHandlerMethod · 0.80
CompileAndRunMethod · 0.80

Calls 1

StringMethod · 0.65

Tested by

no test coverage detected