github.com/Rookout/GoSDK@v0.1.48/pkg/processor/namespaces/traceback_namespace.go (about) 1 package namespaces 2 3 import ( 4 "github.com/Rookout/GoSDK/pkg/rookoutErrors" 5 "github.com/Rookout/GoSDK/pkg/services/collection" 6 "github.com/Rookout/GoSDK/pkg/services/collection/registers" 7 ) 8 9 type TracebackNamespace struct { 10 traceback []collection.Stackframe 11 depth int 12 } 13 14 func NewTracebackNamespace(traceback []collection.Stackframe, depth int) *TracebackNamespace { 15 return &TracebackNamespace{ 16 traceback: traceback, 17 depth: depth, 18 } 19 } 20 21 func (t *TracebackNamespace) ReadKey(key interface{}) (Namespace, rookoutErrors.RookoutError) { 22 collectionService, err := collection.NewCollectionService(registers.OnStackRegisters{}, 0, []collection.Stackframe{t.traceback[key.(int)]}, nil, 0) 23 if err != nil { 24 return nil, err 25 } 26 return NewFrameNamespace(collectionService), nil 27 } 28 29 func (t *TracebackNamespace) CallMethod(name string, _ string) (Namespace, rookoutErrors.RookoutError) { 30 if name == "size" { 31 return NewGoObjectNamespace(t.depth), nil 32 } 33 34 return nil, rookoutErrors.NewRookMethodNotFound(name) 35 } 36 37 func (t *TracebackNamespace) ReadAttribute(_ string) (Namespace, rookoutErrors.RookoutError) { 38 return nil, rookoutErrors.NewNotImplemented() 39 } 40 41 func (t *TracebackNamespace) WriteAttribute(_ string, _ Namespace) rookoutErrors.RookoutError { 42 return rookoutErrors.NewNotImplemented() 43 } 44 45 func (t *TracebackNamespace) GetObject() interface{} { 46 return nil 47 } 48 49 func (t *TracebackNamespace) Serialize(serializer Serializer) { 50 getFrame := func(i int) (int, string, string) { 51 return t.traceback[i].Line, t.traceback[i].File, t.traceback[i].Function 52 } 53 tracebackLen := t.depth 54 if tracebackLen > len(t.traceback) { 55 tracebackLen = len(t.traceback) 56 } 57 serializer.dumpTraceback(getFrame, tracebackLen) 58 } 59 60 func (t *TracebackNamespace) GetTraceback() []collection.Stackframe { 61 return t.traceback 62 }