_id
stringlengths
2
7
title
stringlengths
1
118
partition
stringclasses
3 values
text
stringlengths
52
85.5k
language
stringclasses
1 value
meta_information
dict
q180300
ParseTag
test
func ParseTag(s string) Tag { var name string var omitzero bool var omitempty bool name, s = parseNextTagToken(s) for len(s) != 0 { var token string switch token, s = parseNextTagToken(s); token { case "omitempty": omitempty = true case "omitzero": omitzero = true } } return Tag{ Name: name, Omitempty: omitempty, Omitzero: omitzero, } }
go
{ "resource": "" }
q180301
NewEncoder
test
func NewEncoder(w io.Writer) *objconv.Encoder { return objconv.NewEncoder(NewEmitter(w)) }
go
{ "resource": "" }
q180302
NewStreamEncoder
test
func NewStreamEncoder(w io.Writer) *objconv.StreamEncoder { return objconv.NewStreamEncoder(NewEmitter(w)) }
go
{ "resource": "" }
q180303
NewPrettyEncoder
test
func NewPrettyEncoder(w io.Writer) *objconv.Encoder { return objconv.NewEncoder(NewPrettyEmitter(w)) }
go
{ "resource": "" }
q180304
NewPrettyStreamEncoder
test
func NewPrettyStreamEncoder(w io.Writer) *objconv.StreamEncoder { return objconv.NewStreamEncoder(NewPrettyEmitter(w)) }
go
{ "resource": "" }
q180305
Marshal
test
func Marshal(v interface{}) (b []byte, err error) { m := marshalerPool.Get().(*marshaler) m.b.Truncate(0) if err = (objconv.Encoder{Emitter: m}).Encode(v); err == nil { b = make([]byte, m.b.Len()) copy(b, m.b.Bytes()) } marshalerPool.Put(m) return }
go
{ "resource": "" }
q180306
NewEncoder
test
func NewEncoder(e Emitter) *Encoder { if e == nil { panic("objconv: the emitter is nil") } return &Encoder{Emitter: e} }
go
{ "resource": "" }
q180307
EncodeArray
test
func (e Encoder) EncodeArray(n int, f func(Encoder) error) (err error) { if e.key { if e.key, err = false, e.Emitter.EmitMapValue(); err != nil { return } } if err = e.Emitter.EmitArrayBegin(n); err != nil { return } encodeArray: for i := 0; n < 0 || i < n; i++ { if i != 0 { if e.Emitter.EmitArrayNext(); err != nil { return } } switch err = f(e); err { case nil: case End: break encodeArray default: return } } return e.Emitter.EmitArrayEnd() }
go
{ "resource": "" }
q180308
EncodeMap
test
func (e Encoder) EncodeMap(n int, f func(Encoder, Encoder) error) (err error) { if e.key { if e.key, err = false, e.Emitter.EmitMapValue(); err != nil { return } } if err = e.Emitter.EmitMapBegin(n); err != nil { return } encodeMap: for i := 0; n < 0 || i < n; i++ { if i != 0 { if err = e.Emitter.EmitMapNext(); err != nil { return } } e.key = true err = f( Encoder{Emitter: e.Emitter, SortMapKeys: e.SortMapKeys}, Encoder{Emitter: e.Emitter, SortMapKeys: e.SortMapKeys, key: true}, ) // Because internal calls don't use the exported methods they may not // reset this flag to false when expected, forcing the value here. e.key = false switch err { case nil: case End: break encodeMap default: return } } return e.Emitter.EmitMapEnd() }
go
{ "resource": "" }
q180309
NewStreamEncoder
test
func NewStreamEncoder(e Emitter) *StreamEncoder { if e == nil { panic("objconv.NewStreamEncoder: the emitter is nil") } return &StreamEncoder{Emitter: e} }
go
{ "resource": "" }
q180310
Open
test
func (e *StreamEncoder) Open(n int) error { if err := e.err; err != nil { return err } if e.closed { return io.ErrClosedPipe } if !e.opened { e.max = n e.opened = true if !e.oneshot { e.err = e.Emitter.EmitArrayBegin(n) } } return e.err }
go
{ "resource": "" }
q180311
Close
test
func (e *StreamEncoder) Close() error { if !e.closed { if err := e.Open(-1); err != nil { return err } e.closed = true if !e.oneshot { e.err = e.Emitter.EmitArrayEnd() } } return e.err }
go
{ "resource": "" }
q180312
Encode
test
func (e *StreamEncoder) Encode(v interface{}) error { if err := e.Open(-1); err != nil { return err } if e.max >= 0 && e.cnt >= e.max { return fmt.Errorf("objconv: too many values sent to a stream encoder exceed the configured limit of %d", e.max) } if !e.oneshot && e.cnt != 0 { e.err = e.Emitter.EmitArrayNext() } if e.err == nil { e.err = (Encoder{ Emitter: e.Emitter, SortMapKeys: e.SortMapKeys, }).Encode(v) if e.cnt++; e.max >= 0 && e.cnt >= e.max { e.Close() } } return e.err }
go
{ "resource": "" }
q180313
newStructType
test
func newStructType(t reflect.Type, c map[reflect.Type]*structType) *structType { if s := c[t]; s != nil { return s } n := t.NumField() s := &structType{ fields: make([]structField, 0, n), fieldsByName: make(map[string]*structField), } c[t] = s for i := 0; i != n; i++ { ft := t.Field(i) if ft.Anonymous || len(ft.PkgPath) != 0 { // anonymous or non-exported continue } sf := makeStructField(ft, c) if sf.name == "-" { // skip continue } s.fields = append(s.fields, sf) s.fieldsByName[sf.name] = &s.fields[len(s.fields)-1] } return s }
go
{ "resource": "" }
q180314
lookup
test
func (cache *structTypeCache) lookup(t reflect.Type) (s *structType) { cache.mutex.RLock() s = cache.store[t] cache.mutex.RUnlock() if s == nil { // There's a race confition here where this value may be generated // multiple times. // The impact in practice is really small as it's unlikely to happen // often, we take the approach of keeping the logic simple and avoid // a more complex synchronization logic required to solve this edge // case. s = newStructType(t, map[reflect.Type]*structType{}) cache.mutex.Lock() cache.store[t] = s cache.mutex.Unlock() } return }
go
{ "resource": "" }
q180315
clear
test
func (cache *structTypeCache) clear() { cache.mutex.Lock() for typ := range cache.store { delete(cache.store, typ) } cache.mutex.Unlock() }
go
{ "resource": "" }
q180316
CheckUint64Bounds
test
func CheckUint64Bounds(v uint64, max uint64, t reflect.Type) (err error) { if v > max { err = fmt.Errorf("objconv: %d overflows the maximum value of %d for %s", v, max, t) } return }
go
{ "resource": "" }
q180317
CheckInt64Bounds
test
func CheckInt64Bounds(v int64, min int64, max uint64, t reflect.Type) (err error) { if v < min { err = fmt.Errorf("objconv: %d overflows the minimum value of %d for %s", v, min, t) } if v > 0 && uint64(v) > max { err = fmt.Errorf("objconv: %d overflows the maximum value of %d for %s", v, max, t) } return }
go
{ "resource": "" }
q180318
NewDecoder
test
func NewDecoder(p Parser) *Decoder { if p == nil { panic("objconv: the parser is nil") } return &Decoder{Parser: p} }
go
{ "resource": "" }
q180319
Decode
test
func (d Decoder) Decode(v interface{}) error { to := reflect.ValueOf(v) if d.off != 0 { var err error if d.off, err = 0, d.Parser.ParseMapValue(d.off-1); err != nil { return err } } if !to.IsValid() { // This special case for a nil value is used to make it possible to // discard decoded values. _, err := d.decodeInterface(to) return err } // Optimization for ValueDecoder, in practice tho it's also handled in the // methods that are based on reflection. switch x := v.(type) { case ValueDecoder: return x.DecodeValue(d) } if to.Kind() == reflect.Ptr { // In most cases the method receives a pointer, but we may also have to // support types that aren't pointers but implement ValueDecoder, or // types that have got adapters set. // If we're not in either of those cases the code will likely panic when // the value is set because it won't be addressable. to = to.Elem() } _, err := d.decode(to) return err }
go
{ "resource": "" }
q180320
DecodeArray
test
func (d Decoder) DecodeArray(f func(Decoder) error) (err error) { var typ Type if d.off != 0 { if d.off, err = 0, d.Parser.ParseMapValue(d.off-1); err != nil { return } } if typ, err = d.Parser.ParseType(); err != nil { return } err = d.decodeArrayImpl(typ, f) return }
go
{ "resource": "" }
q180321
DecodeMap
test
func (d Decoder) DecodeMap(f func(Decoder, Decoder) error) (err error) { var typ Type if d.off != 0 { if d.off, err = 0, d.Parser.ParseMapValue(d.off-1); err != nil { return } } if typ, err = d.Parser.ParseType(); err != nil { return } err = d.decodeMapImpl(typ, f) return }
go
{ "resource": "" }
q180322
NewStreamDecoder
test
func NewStreamDecoder(p Parser) *StreamDecoder { if p == nil { panic("objconv: the parser is nil") } return &StreamDecoder{Parser: p} }
go
{ "resource": "" }
q180323
Len
test
func (d *StreamDecoder) Len() int { if d.err != nil { return 0 } if d.typ == Unknown { if d.init() != nil { return 0 } } return d.max - d.cnt }
go
{ "resource": "" }
q180324
Err
test
func (d *StreamDecoder) Err() error { if d.err == End { return nil } return d.err }
go
{ "resource": "" }
q180325
Decode
test
func (d *StreamDecoder) Decode(v interface{}) error { if d.err != nil { return d.err } err := error(nil) cnt := d.cnt max := d.max dec := Decoder{ Parser: d.Parser, MapType: d.MapType, } switch d.typ { case Unknown: err = d.init() max = d.max case Array: if cnt == max { err = dec.Parser.ParseArrayEnd(cnt) } else if cnt != 0 { err = dec.Parser.ParseArrayNext(cnt) } } if err == nil { if cnt == max { err = End } else { switch err = dec.Decode(v); err { case nil: cnt++ case End: cnt++ max = cnt default: if max < 0 && dec.Parser.ParseArrayEnd(cnt) == nil { err = End } } } } d.err = err d.cnt = cnt d.max = max return err }
go
{ "resource": "" }
q180326
Encoder
test
func (d *StreamDecoder) Encoder(e Emitter) (enc *StreamEncoder, err error) { var typ Type if typ, err = d.Parser.ParseType(); err == nil { enc = NewStreamEncoder(e) enc.oneshot = typ != Array } return }
go
{ "resource": "" }
q180327
init
test
func init() { for _, f := range strings.Split(os.Getenv("LOGFLAGS"), ",") { switch f { case "longfile": defaultFlags |= Llongfile case "shortfile": defaultFlags |= Lshortfile } } }
go
{ "resource": "" }
q180328
LevelFromString
test
func LevelFromString(s string) (l Level, ok bool) { switch strings.ToLower(s) { case "trace", "trc": return LevelTrace, true case "debug", "dbg": return LevelDebug, true case "info", "inf": return LevelInfo, true case "warn", "wrn": return LevelWarn, true case "error", "err": return LevelError, true case "critical", "crt": return LevelCritical, true case "off": return LevelOff, true default: return LevelInfo, false } }
go
{ "resource": "" }
q180329
NewBackend
test
func NewBackend(w io.Writer, opts ...BackendOption) *Backend { b := &Backend{w: w, flag: defaultFlags} for _, o := range opts { o(b) } return b }
go
{ "resource": "" }
q180330
callsite
test
func callsite(flag uint32) (string, int) { _, file, line, ok := runtime.Caller(calldepth) if !ok { return "???", 0 } if flag&Lshortfile != 0 { short := file for i := len(file) - 1; i > 0; i-- { if os.IsPathSeparator(file[i]) { short = file[i+1:] break } } file = short } return file, line }
go
{ "resource": "" }
q180331
print
test
func (b *Backend) print(lvl, tag string, args ...interface{}) { t := time.Now() // get as early as possible bytebuf := buffer() var file string var line int if b.flag&(Lshortfile|Llongfile) != 0 { file, line = callsite(b.flag) } formatHeader(bytebuf, t, lvl, tag, file, line) buf := bytes.NewBuffer(*bytebuf) fmt.Fprintln(buf, args...) *bytebuf = buf.Bytes() b.mu.Lock() b.w.Write(*bytebuf) b.mu.Unlock() recycleBuffer(bytebuf) }
go
{ "resource": "" }
q180332
Logger
test
func (b *Backend) Logger(subsystemTag string) Logger { return &slog{LevelInfo, subsystemTag, b} }
go
{ "resource": "" }
q180333
Trace
test
func (l *slog) Trace(args ...interface{}) { lvl := l.Level() if lvl <= LevelTrace { l.b.print("TRC", l.tag, args...) } }
go
{ "resource": "" }
q180334
Tracef
test
func (l *slog) Tracef(format string, args ...interface{}) { lvl := l.Level() if lvl <= LevelTrace { l.b.printf("TRC", l.tag, format, args...) } }
go
{ "resource": "" }
q180335
Debug
test
func (l *slog) Debug(args ...interface{}) { lvl := l.Level() if lvl <= LevelDebug { l.b.print("DBG", l.tag, args...) } }
go
{ "resource": "" }
q180336
Debugf
test
func (l *slog) Debugf(format string, args ...interface{}) { lvl := l.Level() if lvl <= LevelDebug { l.b.printf("DBG", l.tag, format, args...) } }
go
{ "resource": "" }
q180337
Info
test
func (l *slog) Info(args ...interface{}) { lvl := l.Level() if lvl <= LevelInfo { l.b.print("INF", l.tag, args...) } }
go
{ "resource": "" }
q180338
Infof
test
func (l *slog) Infof(format string, args ...interface{}) { lvl := l.Level() if lvl <= LevelInfo { l.b.printf("INF", l.tag, format, args...) } }
go
{ "resource": "" }
q180339
Warn
test
func (l *slog) Warn(args ...interface{}) { lvl := l.Level() if lvl <= LevelWarn { l.b.print("WRN", l.tag, args...) } }
go
{ "resource": "" }
q180340
Warnf
test
func (l *slog) Warnf(format string, args ...interface{}) { lvl := l.Level() if lvl <= LevelWarn { l.b.printf("WRN", l.tag, format, args...) } }
go
{ "resource": "" }
q180341
Error
test
func (l *slog) Error(args ...interface{}) { lvl := l.Level() if lvl <= LevelError { l.b.print("ERR", l.tag, args...) } }
go
{ "resource": "" }
q180342
Errorf
test
func (l *slog) Errorf(format string, args ...interface{}) { lvl := l.Level() if lvl <= LevelError { l.b.printf("ERR", l.tag, format, args...) } }
go
{ "resource": "" }
q180343
Critical
test
func (l *slog) Critical(args ...interface{}) { lvl := l.Level() if lvl <= LevelCritical { l.b.print("CRT", l.tag, args...) } }
go
{ "resource": "" }
q180344
Criticalf
test
func (l *slog) Criticalf(format string, args ...interface{}) { lvl := l.Level() if lvl <= LevelCritical { l.b.printf("CRT", l.tag, format, args...) } }
go
{ "resource": "" }
q180345
Level
test
func (l *slog) Level() Level { return Level(atomic.LoadUint32((*uint32)(&l.lvl))) }
go
{ "resource": "" }
q180346
SetLevel
test
func (l *slog) SetLevel(level Level) { atomic.StoreUint32((*uint32)(&l.lvl), uint32(level)) }
go
{ "resource": "" }
q180347
Concat
test
func (permission *Permission) Concat(newPermission *Permission) *Permission { var result = Permission{ Role: Global, AllowedRoles: map[PermissionMode][]string{}, DeniedRoles: map[PermissionMode][]string{}, } var appendRoles = func(p *Permission) { if p != nil { result.Role = p.Role for mode, roles := range p.DeniedRoles { result.DeniedRoles[mode] = append(result.DeniedRoles[mode], roles...) } for mode, roles := range p.AllowedRoles { result.AllowedRoles[mode] = append(result.AllowedRoles[mode], roles...) } } } appendRoles(newPermission) appendRoles(permission) return &result }
go
{ "resource": "" }
q180348
HasPermission
test
func (permission Permission) HasPermission(mode PermissionMode, roles ...interface{}) bool { var roleNames []string for _, role := range roles { if r, ok := role.(string); ok { roleNames = append(roleNames, r) } else if roler, ok := role.(Roler); ok { roleNames = append(roleNames, roler.GetRoles()...) } else { fmt.Printf("invalid role %#v\n", role) return false } } if len(permission.DeniedRoles) != 0 { if DeniedRoles := permission.DeniedRoles[mode]; DeniedRoles != nil { if includeRoles(DeniedRoles, roleNames) { return false } } } // return true if haven't define allowed roles if len(permission.AllowedRoles) == 0 { return true } if AllowedRoles := permission.AllowedRoles[mode]; AllowedRoles != nil { if includeRoles(AllowedRoles, roleNames) { return true } } return false }
go
{ "resource": "" }
q180349
ConcatPermissioner
test
func ConcatPermissioner(ps ...Permissioner) Permissioner { var newPS []Permissioner for _, p := range ps { if p != nil { newPS = append(newPS, p) } } return permissioners(newPS) }
go
{ "resource": "" }
q180350
HasPermission
test
func (ps permissioners) HasPermission(mode PermissionMode, roles ...interface{}) bool { for _, p := range ps { if p != nil && !p.HasPermission(mode, roles) { return false } } return true }
go
{ "resource": "" }
q180351
Register
test
func (role *Role) Register(name string, fc Checker) { if role.definitions == nil { role.definitions = map[string]Checker{} } definition := role.definitions[name] if definition != nil { fmt.Printf("Role `%v` already defined, overwrited it!\n", name) } role.definitions[name] = fc }
go
{ "resource": "" }
q180352
NewPermission
test
func (role *Role) NewPermission() *Permission { return &Permission{ Role: role, AllowedRoles: map[PermissionMode][]string{}, DeniedRoles: map[PermissionMode][]string{}, } }
go
{ "resource": "" }
q180353
Get
test
func (role *Role) Get(name string) (Checker, bool) { fc, ok := role.definitions[name] return fc, ok }
go
{ "resource": "" }
q180354
isPtrFromHeap
test
func (p *Process) isPtrFromHeap(a core.Address) bool { return p.findHeapInfo(a).IsPtr(a, p.proc.PtrSize()) }
go
{ "resource": "" }
q180355
IsPtr
test
func (p *Process) IsPtr(a core.Address) bool { h := p.findHeapInfo(a) if h != nil { return h.IsPtr(a, p.proc.PtrSize()) } for _, m := range p.modules { for _, s := range [2]string{"data", "bss"} { min := core.Address(m.r.Field(s).Uintptr()) max := core.Address(m.r.Field("e" + s).Uintptr()) if a < min || a >= max { continue } gc := m.r.Field("gc" + s + "mask").Field("bytedata").Address() i := a.Sub(min) return p.proc.ReadUint8(gc.Add(i/8))>>uint(i%8) != 0 } } // Everywhere else can't be a pointer. At least, not a pointer into the Go heap. // TODO: stacks? // TODO: finalizers? return false }
go
{ "resource": "" }
q180356
FindObject
test
func (p *Process) FindObject(a core.Address) (Object, int64) { // Round down to the start of an object. h := p.findHeapInfo(a) if h == nil { // Not in Go heap, or in a span // that doesn't hold Go objects (freed, stacks, ...) return 0, 0 } x := h.base.Add(a.Sub(h.base) / h.size * h.size) // Check if object is marked. h = p.findHeapInfo(x) if h.mark>>(uint64(x)%heapInfoSize/8)&1 == 0 { // free or garbage return 0, 0 } return Object(x), a.Sub(x) }
go
{ "resource": "" }
q180357
ForEachObject
test
func (p *Process) ForEachObject(fn func(x Object) bool) { for _, k := range p.pages { pt := p.pageTable[k] for i := range pt { h := &pt[i] m := h.mark for m != 0 { j := bits.TrailingZeros64(m) m &= m - 1 x := Object(k)*pageTableSize*heapInfoSize + Object(i)*heapInfoSize + Object(j)*8 if !fn(x) { return } } } } }
go
{ "resource": "" }
q180358
ForEachRoot
test
func (p *Process) ForEachRoot(fn func(r *Root) bool) { for _, r := range p.globals { if !fn(r) { return } } for _, g := range p.goroutines { for _, f := range g.frames { for _, r := range f.roots { if !fn(r) { return } } } } }
go
{ "resource": "" }
q180359
Addr
test
func (p *Process) Addr(x Object) core.Address { return core.Address(x) }
go
{ "resource": "" }
q180360
Size
test
func (p *Process) Size(x Object) int64 { return p.findHeapInfo(core.Address(x)).size }
go
{ "resource": "" }
q180361
Type
test
func (p *Process) Type(x Object) (*Type, int64) { p.typeHeap() i, _ := p.findObjectIndex(core.Address(x)) return p.types[i].t, p.types[i].r }
go
{ "resource": "" }
q180362
ForEachRootPtr
test
func (p *Process) ForEachRootPtr(r *Root, fn func(int64, Object, int64) bool) { edges1(p, r, 0, r.Type, fn) }
go
{ "resource": "" }
q180363
edges1
test
func edges1(p *Process, r *Root, off int64, t *Type, fn func(int64, Object, int64) bool) bool { switch t.Kind { case KindBool, KindInt, KindUint, KindFloat, KindComplex: // no edges here case KindIface, KindEface: // The first word is a type or itab. // Itabs are never in the heap. // Types might be, though. a := r.Addr.Add(off) if r.Frame == nil || r.Frame.Live[a] { dst, off2 := p.FindObject(p.proc.ReadPtr(a)) if dst != 0 { if !fn(off, dst, off2) { return false } } } // Treat second word like a pointer. off += p.proc.PtrSize() fallthrough case KindPtr, KindString, KindSlice, KindFunc: a := r.Addr.Add(off) if r.Frame == nil || r.Frame.Live[a] { dst, off2 := p.FindObject(p.proc.ReadPtr(a)) if dst != 0 { if !fn(off, dst, off2) { return false } } } case KindArray: s := t.Elem.Size for i := int64(0); i < t.Count; i++ { if !edges1(p, r, off+i*s, t.Elem, fn) { return false } } case KindStruct: for _, f := range t.Fields { if !edges1(p, r, off+f.Off, f.Type, fn) { return false } } } return true }
go
{ "resource": "" }
q180364
setHeapPtr
test
func (p *Process) setHeapPtr(a core.Address) { h := p.allocHeapInfo(a) if p.proc.PtrSize() == 8 { i := uint(a%heapInfoSize) / 8 h.ptr[0] |= uint64(1) << i return } i := a % heapInfoSize / 4 h.ptr[i/64] |= uint64(1) << (i % 64) }
go
{ "resource": "" }
q180365
findHeapInfo
test
func (p *Process) findHeapInfo(a core.Address) *heapInfo { k := a / heapInfoSize / pageTableSize i := a / heapInfoSize % pageTableSize t := p.pageTable[k] if t == nil { return nil } h := &t[i] if h.base == 0 { return nil } return h }
go
{ "resource": "" }
q180366
allocHeapInfo
test
func (p *Process) allocHeapInfo(a core.Address) *heapInfo { k := a / heapInfoSize / pageTableSize i := a / heapInfoSize % pageTableSize t := p.pageTable[k] if t == nil { t = new(pageTableEntry) for j := 0; j < pageTableSize; j++ { t[j].firstIdx = -1 } p.pageTable[k] = t p.pages = append(p.pages, k) } return &t[i] }
go
{ "resource": "" }
q180367
runtimeName
test
func runtimeName(dt dwarf.Type) string { switch x := dt.(type) { case *dwarf.PtrType: if _, ok := x.Type.(*dwarf.VoidType); ok { return "unsafe.Pointer" } return "*" + runtimeName(x.Type) case *dwarf.ArrayType: return fmt.Sprintf("[%d]%s", x.Count, runtimeName(x.Type)) case *dwarf.StructType: if !strings.HasPrefix(x.StructName, "struct {") { // This is a named type, return that name. return stripPackagePath(x.StructName) } // Figure out which fields have anonymous names. var anon []bool for _, f := range strings.Split(x.StructName[8:len(x.StructName)-1], ";") { f = strings.TrimSpace(f) anon = append(anon, !strings.Contains(f, " ")) // TODO: this isn't perfect. If the field type has a space in it, // then this logic doesn't work. Need to search for keyword for // field type, like "interface", "struct", ... } // Make sure anon is long enough. This probably never triggers. for len(anon) < len(x.Field) { anon = append(anon, false) } // Build runtime name from the DWARF fields. s := "struct {" first := true for _, f := range x.Field { if !first { s += ";" } name := f.Name if i := strings.Index(name, "."); i >= 0 { name = name[i+1:] } if anon[0] { s += fmt.Sprintf(" %s", runtimeName(f.Type)) } else { s += fmt.Sprintf(" %s %s", name, runtimeName(f.Type)) } first = false anon = anon[1:] } s += " }" return s default: return stripPackagePath(dt.String()) } }
go
{ "resource": "" }
q180368
readRuntimeConstants
test
func (p *Process) readRuntimeConstants() { p.rtConstants = map[string]int64{} // Hardcoded values for Go 1.9. // (Go did not have constants in DWARF before 1.10.) m := p.rtConstants m["_MSpanDead"] = 0 m["_MSpanInUse"] = 1 m["_MSpanManual"] = 2 m["_MSpanFree"] = 3 m["_Gidle"] = 0 m["_Grunnable"] = 1 m["_Grunning"] = 2 m["_Gsyscall"] = 3 m["_Gwaiting"] = 4 m["_Gdead"] = 6 m["_Gscan"] = 0x1000 m["_PCDATA_StackMapIndex"] = 0 m["_FUNCDATA_LocalsPointerMaps"] = 1 m["_FUNCDATA_ArgsPointerMaps"] = 0 m["tflagExtraStar"] = 1 << 1 m["kindGCProg"] = 1 << 6 m["kindDirectIface"] = 1 << 5 m["_PageSize"] = 1 << 13 m["_KindSpecialFinalizer"] = 1 // From 1.10, these constants are recorded in DWARF records. d, _ := p.proc.DWARF() r := d.Reader() for e, err := r.Next(); e != nil && err == nil; e, err = r.Next() { if e.Tag != dwarf.TagConstant { continue } f := e.AttrField(dwarf.AttrName) if f == nil { continue } name := f.Val.(string) if !strings.HasPrefix(name, "runtime.") { continue } name = name[8:] c := e.AttrField(dwarf.AttrConstValue) if c == nil { continue } p.rtConstants[name] = c.Val.(int64) } }
go
{ "resource": "" }
q180369
add
test
func (t *funcTab) add(min, max core.Address, f *Func) { t.entries = append(t.entries, funcTabEntry{min: min, max: max, f: f}) }
go
{ "resource": "" }
q180370
sort
test
func (t *funcTab) sort() { sort.Slice(t.entries, func(i, j int) bool { return t.entries[i].min < t.entries[j].min }) }
go
{ "resource": "" }
q180371
find
test
func (t *funcTab) find(pc core.Address) *Func { n := sort.Search(len(t.entries), func(i int) bool { return t.entries[i].max > pc }) if n == len(t.entries) || pc < t.entries[n].min || pc >= t.entries[n].max { return nil } return t.entries[n].f }
go
{ "resource": "" }
q180372
read
test
func (t *pcTab) read(core *core.Process, data core.Address) { var pcQuantum int64 switch core.Arch() { case "386", "amd64", "amd64p32": pcQuantum = 1 case "s390x": pcQuantum = 2 case "arm", "arm64", "mips", "mipsle", "mips64", "mips64le", "ppc64", "ppc64le": pcQuantum = 4 default: panic("unknown architecture " + core.Arch()) } val := int64(-1) first := true for { // Advance value. v, n := readVarint(core, data) if v == 0 && !first { return } data = data.Add(n) if v&1 != 0 { val += ^(v >> 1) } else { val += v >> 1 } // Advance pc. v, n = readVarint(core, data) data = data.Add(n) t.entries = append(t.entries, pcTabEntry{bytes: v * pcQuantum, val: val}) first = false } }
go
{ "resource": "" }
q180373
readVarint
test
func readVarint(core *core.Process, a core.Address) (val, n int64) { for { b := core.ReadUint8(a) val |= int64(b&0x7f) << uint(n*7) n++ a++ if b&0x80 == 0 { return } } }
go
{ "resource": "" }
q180374
useLine
test
func useLine(c *cobra.Command) string { var useline string if c.HasParent() { useline = commandPath(c.Parent()) + " " + c.Use } else { useline = c.Use } if c.DisableFlagsInUseLine { return useline } if c.HasAvailableFlags() && !strings.Contains(useline, "[flags]") { useline += " [flags]" } return useline }
go
{ "resource": "" }
q180375
commandPath
test
func commandPath(c *cobra.Command) string { if c.HasParent() { return commandPath(c) + " " + c.Name() } return c.Use }
go
{ "resource": "" }
q180376
readCore
test
func readCore() (*core.Process, *gocore.Process, error) { cc := coreCache if cc.cfg == cfg { return cc.coreP, cc.gocoreP, cc.err } c, err := core.Core(cfg.corefile, cfg.base, cfg.exePath) if err != nil { return nil, nil, err } p, err := gocore.Core(c) if os.IsNotExist(err) && cfg.exePath == "" { return nil, nil, fmt.Errorf("%v; consider specifying the --exe flag", err) } if err != nil { return nil, nil, err } for _, w := range c.Warnings() { fmt.Fprintf(os.Stderr, "WARNING: %s\n", w) } cc.cfg = cfg cc.coreP = c cc.gocoreP = p cc.err = nil return c, p, nil }
go
{ "resource": "" }
q180377
typeName
test
func typeName(c *gocore.Process, x gocore.Object) string { size := c.Size(x) typ, repeat := c.Type(x) if typ == nil { return fmt.Sprintf("unk%d", size) } name := typ.String() n := size / typ.Size if n > 1 { if repeat < n { name = fmt.Sprintf("[%d+%d?]%s", repeat, n-repeat, name) } else { name = fmt.Sprintf("[%d]%s", repeat, name) } } return name }
go
{ "resource": "" }
q180378
fieldName
test
func fieldName(c *gocore.Process, x gocore.Object, off int64) string { size := c.Size(x) typ, repeat := c.Type(x) if typ == nil { return fmt.Sprintf("f%d", off) } n := size / typ.Size i := off / typ.Size if i == 0 && repeat == 1 { // Probably a singleton object, no need for array notation. return typeFieldName(typ, off) } if i >= n { // Partial space at the end of the object - the type can't be complete. return fmt.Sprintf("f%d", off) } q := "" if i >= repeat { // Past the known repeat section, add a ? because we're not sure about the type. q = "?" } return fmt.Sprintf("[%d]%s%s", i, typeFieldName(typ, off-i*typ.Size), q) }
go
{ "resource": "" }
q180379
typeFieldName
test
func typeFieldName(t *gocore.Type, off int64) string { switch t.Kind { case gocore.KindBool, gocore.KindInt, gocore.KindUint, gocore.KindFloat: return "" case gocore.KindComplex: if off == 0 { return ".real" } return ".imag" case gocore.KindIface, gocore.KindEface: if off == 0 { return ".type" } return ".data" case gocore.KindPtr, gocore.KindFunc: return "" case gocore.KindString: if off == 0 { return ".ptr" } return ".len" case gocore.KindSlice: if off == 0 { return ".ptr" } if off <= t.Size/2 { return ".len" } return ".cap" case gocore.KindArray: s := t.Elem.Size i := off / s return fmt.Sprintf("[%d]%s", i, typeFieldName(t.Elem, off-i*s)) case gocore.KindStruct: for _, f := range t.Fields { if f.Off <= off && off < f.Off+f.Type.Size { return "." + f.Name + typeFieldName(f.Type, off-f.Off) } } } return ".???" }
go
{ "resource": "" }
q180380
FindFunc
test
func (p *Process) FindFunc(pc core.Address) *Func { return p.funcTab.find(pc) }
go
{ "resource": "" }
q180381
Core
test
func Core(proc *core.Process) (p *Process, err error) { // Make sure we have DWARF info. if _, err := proc.DWARF(); err != nil { return nil, err } // Guard against failures of proc.Read* routines. /* defer func() { e := recover() if e == nil { return } p = nil if x, ok := e.(error); ok { err = x return } panic(e) // Not an error, re-panic it. }() */ p = &Process{ proc: proc, runtimeMap: map[core.Address]*Type{}, dwarfMap: map[dwarf.Type]*Type{}, } // Initialize everything that just depends on DWARF. p.readDWARFTypes() p.readRuntimeConstants() p.readGlobals() // Find runtime globals we care about. Initialize regions for them. p.rtGlobals = map[string]region{} for _, g := range p.globals { if strings.HasPrefix(g.Name, "runtime.") { p.rtGlobals[g.Name[8:]] = region{p: p, a: g.Addr, typ: g.Type} } } // Read all the data that depend on runtime globals. p.buildVersion = p.rtGlobals["buildVersion"].String() p.readModules() p.readHeap() p.readGs() p.readStackVars() // needs to be after readGs. p.markObjects() // needs to be after readGlobals, readStackVars. return p, nil }
go
{ "resource": "" }
q180382
Address
test
func (r region) Address() core.Address { if r.typ.Kind != KindPtr { panic("can't ask for the Address of a non-pointer " + r.typ.Name) } return r.p.proc.ReadPtr(r.a) }
go
{ "resource": "" }
q180383
Int
test
func (r region) Int() int64 { if r.typ.Kind != KindInt || r.typ.Size != r.p.proc.PtrSize() { panic("not an int: " + r.typ.Name) } return r.p.proc.ReadInt(r.a) }
go
{ "resource": "" }
q180384
Uintptr
test
func (r region) Uintptr() uint64 { if r.typ.Kind != KindUint || r.typ.Size != r.p.proc.PtrSize() { panic("not a uintptr: " + r.typ.Name) } return r.p.proc.ReadUintptr(r.a) }
go
{ "resource": "" }
q180385
Cast
test
func (r region) Cast(typ string) region { return region{p: r.p, a: r.a, typ: r.p.findType(typ)} }
go
{ "resource": "" }
q180386
Deref
test
func (r region) Deref() region { if r.typ.Kind != KindPtr { panic("can't deref on non-pointer: " + r.typ.Name) } if r.typ.Elem == nil { panic("can't deref unsafe.Pointer") } p := r.p.proc.ReadPtr(r.a) return region{p: r.p, a: p, typ: r.typ.Elem} }
go
{ "resource": "" }
q180387
Uint64
test
func (r region) Uint64() uint64 { if r.typ.Kind != KindUint || r.typ.Size != 8 { panic("bad uint64 type " + r.typ.Name) } return r.p.proc.ReadUint64(r.a) }
go
{ "resource": "" }
q180388
Uint32
test
func (r region) Uint32() uint32 { if r.typ.Kind != KindUint || r.typ.Size != 4 { panic("bad uint32 type " + r.typ.Name) } return r.p.proc.ReadUint32(r.a) }
go
{ "resource": "" }
q180389
Int32
test
func (r region) Int32() int32 { if r.typ.Kind != KindInt || r.typ.Size != 4 { panic("bad int32 type " + r.typ.Name) } return r.p.proc.ReadInt32(r.a) }
go
{ "resource": "" }
q180390
Uint16
test
func (r region) Uint16() uint16 { if r.typ.Kind != KindUint || r.typ.Size != 2 { panic("bad uint16 type " + r.typ.Name) } return r.p.proc.ReadUint16(r.a) }
go
{ "resource": "" }
q180391
Uint8
test
func (r region) Uint8() uint8 { if r.typ.Kind != KindUint || r.typ.Size != 1 { panic("bad uint8 type " + r.typ.Name) } return r.p.proc.ReadUint8(r.a) }
go
{ "resource": "" }
q180392
String
test
func (r region) String() string { if r.typ.Kind != KindString { panic("bad string type " + r.typ.Name) } p := r.p.proc.ReadPtr(r.a) n := r.p.proc.ReadUintptr(r.a.Add(r.p.proc.PtrSize())) b := make([]byte, n) r.p.proc.ReadAt(b, p) return string(b) }
go
{ "resource": "" }
q180393
SlicePtr
test
func (r region) SlicePtr() region { if r.typ.Kind != KindSlice { panic("can't Ptr a non-slice") } return region{p: r.p, a: r.a, typ: &Type{Name: "*" + r.typ.Name[2:], Size: r.p.proc.PtrSize(), Kind: KindPtr, Elem: r.typ.Elem}} }
go
{ "resource": "" }
q180394
SliceLen
test
func (r region) SliceLen() int64 { if r.typ.Kind != KindSlice { panic("can't len a non-slice") } return r.p.proc.ReadInt(r.a.Add(r.p.proc.PtrSize())) }
go
{ "resource": "" }
q180395
Field
test
func (r region) Field(f string) region { finfo := r.typ.field(f) if finfo == nil { panic("can't find field " + r.typ.Name + "." + f) } return region{p: r.p, a: r.a.Add(finfo.Off), typ: finfo.Type} }
go
{ "resource": "" }
q180396
ReadUint8
test
func (p *Process) ReadUint8(a Address) uint8 { m := p.findMapping(a) if m == nil { panic(fmt.Errorf("address %x is not mapped in the core file", a)) } return m.contents[a.Sub(m.min)] }
go
{ "resource": "" }
q180397
ReadUint16
test
func (p *Process) ReadUint16(a Address) uint16 { m := p.findMapping(a) if m == nil { panic(fmt.Errorf("address %x is not mapped in the core file", a)) } b := m.contents[a.Sub(m.min):] if len(b) < 2 { var buf [2]byte b = buf[:] p.ReadAt(b, a) } if p.littleEndian { return binary.LittleEndian.Uint16(b) } return binary.BigEndian.Uint16(b) }
go
{ "resource": "" }
q180398
ReadUint32
test
func (p *Process) ReadUint32(a Address) uint32 { m := p.findMapping(a) if m == nil { panic(fmt.Errorf("address %x is not mapped in the core file", a)) } b := m.contents[a.Sub(m.min):] if len(b) < 4 { var buf [4]byte b = buf[:] p.ReadAt(b, a) } if p.littleEndian { return binary.LittleEndian.Uint32(b) } return binary.BigEndian.Uint32(b) }
go
{ "resource": "" }
q180399
ReadUint64
test
func (p *Process) ReadUint64(a Address) uint64 { m := p.findMapping(a) if m == nil { panic(fmt.Errorf("address %x is not mapped in the core file", a)) } b := m.contents[a.Sub(m.min):] if len(b) < 8 { var buf [8]byte b = buf[:] p.ReadAt(b, a) } if p.littleEndian { return binary.LittleEndian.Uint64(b) } return binary.BigEndian.Uint64(b) }
go
{ "resource": "" }