repo
stringlengths 5
67
| path
stringlengths 4
218
| func_name
stringlengths 0
151
| original_string
stringlengths 52
373k
| language
stringclasses 6
values | code
stringlengths 52
373k
| code_tokens
listlengths 10
512
| docstring
stringlengths 3
47.2k
| docstring_tokens
listlengths 3
234
| sha
stringlengths 40
40
| url
stringlengths 85
339
| partition
stringclasses 3
values |
|---|---|---|---|---|---|---|---|---|---|---|---|
segmentio/objconv
|
struct.go
|
newStructType
|
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
|
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
}
|
[
"func",
"newStructType",
"(",
"t",
"reflect",
".",
"Type",
",",
"c",
"map",
"[",
"reflect",
".",
"Type",
"]",
"*",
"structType",
")",
"*",
"structType",
"{",
"if",
"s",
":=",
"c",
"[",
"t",
"]",
";",
"s",
"!=",
"nil",
"{",
"return",
"s",
"\n",
"}",
"\n",
"n",
":=",
"t",
".",
"NumField",
"(",
")",
"\n",
"s",
":=",
"&",
"structType",
"{",
"fields",
":",
"make",
"(",
"[",
"]",
"structField",
",",
"0",
",",
"n",
")",
",",
"fieldsByName",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"structField",
")",
",",
"}",
"\n",
"c",
"[",
"t",
"]",
"=",
"s",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"!=",
"n",
";",
"i",
"++",
"{",
"ft",
":=",
"t",
".",
"Field",
"(",
"i",
")",
"\n",
"if",
"ft",
".",
"Anonymous",
"||",
"len",
"(",
"ft",
".",
"PkgPath",
")",
"!=",
"0",
"{",
"continue",
"\n",
"}",
"\n",
"sf",
":=",
"makeStructField",
"(",
"ft",
",",
"c",
")",
"\n",
"if",
"sf",
".",
"name",
"==",
"\"-\"",
"{",
"continue",
"\n",
"}",
"\n",
"s",
".",
"fields",
"=",
"append",
"(",
"s",
".",
"fields",
",",
"sf",
")",
"\n",
"s",
".",
"fieldsByName",
"[",
"sf",
".",
"name",
"]",
"=",
"&",
"s",
".",
"fields",
"[",
"len",
"(",
"s",
".",
"fields",
")",
"-",
"1",
"]",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] |
// newStructType takes a Go type as argument and extract information to make a
// new structType value.
// The type has to be a struct type or a panic will be raised.
|
[
"newStructType",
"takes",
"a",
"Go",
"type",
"as",
"argument",
"and",
"extract",
"information",
"to",
"make",
"a",
"new",
"structType",
"value",
".",
"The",
"type",
"has",
"to",
"be",
"a",
"struct",
"type",
"or",
"a",
"panic",
"will",
"be",
"raised",
"."
] |
7a1d7b8e6f3551b30751e6b2ea6bae500883870e
|
https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/struct.go#L87-L117
|
test
|
segmentio/objconv
|
struct.go
|
lookup
|
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
|
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
}
|
[
"func",
"(",
"cache",
"*",
"structTypeCache",
")",
"lookup",
"(",
"t",
"reflect",
".",
"Type",
")",
"(",
"s",
"*",
"structType",
")",
"{",
"cache",
".",
"mutex",
".",
"RLock",
"(",
")",
"\n",
"s",
"=",
"cache",
".",
"store",
"[",
"t",
"]",
"\n",
"cache",
".",
"mutex",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"s",
"==",
"nil",
"{",
"s",
"=",
"newStructType",
"(",
"t",
",",
"map",
"[",
"reflect",
".",
"Type",
"]",
"*",
"structType",
"{",
"}",
")",
"\n",
"cache",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"cache",
".",
"store",
"[",
"t",
"]",
"=",
"s",
"\n",
"cache",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// lookup takes a Go type as argument and returns the matching structType value,
// potentially creating it if it didn't already exist.
// This method is safe to call from multiple goroutines.
|
[
"lookup",
"takes",
"a",
"Go",
"type",
"as",
"argument",
"and",
"returns",
"the",
"matching",
"structType",
"value",
"potentially",
"creating",
"it",
"if",
"it",
"didn",
"t",
"already",
"exist",
".",
"This",
"method",
"is",
"safe",
"to",
"call",
"from",
"multiple",
"goroutines",
"."
] |
7a1d7b8e6f3551b30751e6b2ea6bae500883870e
|
https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/struct.go#L128-L147
|
test
|
segmentio/objconv
|
struct.go
|
clear
|
func (cache *structTypeCache) clear() {
cache.mutex.Lock()
for typ := range cache.store {
delete(cache.store, typ)
}
cache.mutex.Unlock()
}
|
go
|
func (cache *structTypeCache) clear() {
cache.mutex.Lock()
for typ := range cache.store {
delete(cache.store, typ)
}
cache.mutex.Unlock()
}
|
[
"func",
"(",
"cache",
"*",
"structTypeCache",
")",
"clear",
"(",
")",
"{",
"cache",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"for",
"typ",
":=",
"range",
"cache",
".",
"store",
"{",
"delete",
"(",
"cache",
".",
"store",
",",
"typ",
")",
"\n",
"}",
"\n",
"cache",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"}"
] |
// clear empties the cache.
|
[
"clear",
"empties",
"the",
"cache",
"."
] |
7a1d7b8e6f3551b30751e6b2ea6bae500883870e
|
https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/struct.go#L150-L156
|
test
|
segmentio/objconv
|
objutil/limits.go
|
CheckUint64Bounds
|
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
|
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
}
|
[
"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",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// CheckUint64Bounds verifies that v is smaller than max, t represents the
// original type of v.
|
[
"CheckUint64Bounds",
"verifies",
"that",
"v",
"is",
"smaller",
"than",
"max",
"t",
"represents",
"the",
"original",
"type",
"of",
"v",
"."
] |
7a1d7b8e6f3551b30751e6b2ea6bae500883870e
|
https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/objutil/limits.go#L90-L95
|
test
|
segmentio/objconv
|
objutil/limits.go
|
CheckInt64Bounds
|
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
|
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
}
|
[
"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",
")",
"\n",
"}",
"\n",
"if",
"v",
">",
"0",
"&&",
"uint64",
"(",
"v",
")",
">",
"max",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"objconv: %d overflows the maximum value of %d for %s\"",
",",
"v",
",",
"max",
",",
"t",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// CheckInt64Bounds verifies that v is within min and max, t represents the
// original type of v.
|
[
"CheckInt64Bounds",
"verifies",
"that",
"v",
"is",
"within",
"min",
"and",
"max",
"t",
"represents",
"the",
"original",
"type",
"of",
"v",
"."
] |
7a1d7b8e6f3551b30751e6b2ea6bae500883870e
|
https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/objutil/limits.go#L99-L107
|
test
|
segmentio/objconv
|
decode.go
|
NewDecoder
|
func NewDecoder(p Parser) *Decoder {
if p == nil {
panic("objconv: the parser is nil")
}
return &Decoder{Parser: p}
}
|
go
|
func NewDecoder(p Parser) *Decoder {
if p == nil {
panic("objconv: the parser is nil")
}
return &Decoder{Parser: p}
}
|
[
"func",
"NewDecoder",
"(",
"p",
"Parser",
")",
"*",
"Decoder",
"{",
"if",
"p",
"==",
"nil",
"{",
"panic",
"(",
"\"objconv: the parser is nil\"",
")",
"\n",
"}",
"\n",
"return",
"&",
"Decoder",
"{",
"Parser",
":",
"p",
"}",
"\n",
"}"
] |
// NewDecoder returns a decoder object that uses p, will panic if p is nil.
|
[
"NewDecoder",
"returns",
"a",
"decoder",
"object",
"that",
"uses",
"p",
"will",
"panic",
"if",
"p",
"is",
"nil",
"."
] |
7a1d7b8e6f3551b30751e6b2ea6bae500883870e
|
https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/decode.go#L31-L36
|
test
|
segmentio/objconv
|
decode.go
|
Decode
|
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
|
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
}
|
[
"func",
"(",
"d",
"Decoder",
")",
"Decode",
"(",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"to",
":=",
"reflect",
".",
"ValueOf",
"(",
"v",
")",
"\n",
"if",
"d",
".",
"off",
"!=",
"0",
"{",
"var",
"err",
"error",
"\n",
"if",
"d",
".",
"off",
",",
"err",
"=",
"0",
",",
"d",
".",
"Parser",
".",
"ParseMapValue",
"(",
"d",
".",
"off",
"-",
"1",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"to",
".",
"IsValid",
"(",
")",
"{",
"_",
",",
"err",
":=",
"d",
".",
"decodeInterface",
"(",
"to",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"switch",
"x",
":=",
"v",
".",
"(",
"type",
")",
"{",
"case",
"ValueDecoder",
":",
"return",
"x",
".",
"DecodeValue",
"(",
"d",
")",
"\n",
"}",
"\n",
"if",
"to",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Ptr",
"{",
"to",
"=",
"to",
".",
"Elem",
"(",
")",
"\n",
"}",
"\n",
"_",
",",
"err",
":=",
"d",
".",
"decode",
"(",
"to",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// Decode expects v to be a pointer to a value in which the decoder will load
// the next parsed data.
//
// The method panics if v is neither a pointer type nor implements the
// ValueDecoder interface, or if v is a nil pointer.
|
[
"Decode",
"expects",
"v",
"to",
"be",
"a",
"pointer",
"to",
"a",
"value",
"in",
"which",
"the",
"decoder",
"will",
"load",
"the",
"next",
"parsed",
"data",
".",
"The",
"method",
"panics",
"if",
"v",
"is",
"neither",
"a",
"pointer",
"type",
"nor",
"implements",
"the",
"ValueDecoder",
"interface",
"or",
"if",
"v",
"is",
"a",
"nil",
"pointer",
"."
] |
7a1d7b8e6f3551b30751e6b2ea6bae500883870e
|
https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/decode.go#L43-L78
|
test
|
segmentio/objconv
|
decode.go
|
DecodeArray
|
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
|
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
}
|
[
"func",
"(",
"d",
"Decoder",
")",
"DecodeArray",
"(",
"f",
"func",
"(",
"Decoder",
")",
"error",
")",
"(",
"err",
"error",
")",
"{",
"var",
"typ",
"Type",
"\n",
"if",
"d",
".",
"off",
"!=",
"0",
"{",
"if",
"d",
".",
"off",
",",
"err",
"=",
"0",
",",
"d",
".",
"Parser",
".",
"ParseMapValue",
"(",
"d",
".",
"off",
"-",
"1",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"typ",
",",
"err",
"=",
"d",
".",
"Parser",
".",
"ParseType",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"err",
"=",
"d",
".",
"decodeArrayImpl",
"(",
"typ",
",",
"f",
")",
"\n",
"return",
"\n",
"}"
] |
// DecodeArray provides the implementation of the algorithm for decoding arrays,
// where f is called to decode each element of the array.
|
[
"DecodeArray",
"provides",
"the",
"implementation",
"of",
"the",
"algorithm",
"for",
"decoding",
"arrays",
"where",
"f",
"is",
"called",
"to",
"decode",
"each",
"element",
"of",
"the",
"array",
"."
] |
7a1d7b8e6f3551b30751e6b2ea6bae500883870e
|
https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/decode.go#L1133-L1148
|
test
|
segmentio/objconv
|
decode.go
|
DecodeMap
|
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
|
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
}
|
[
"func",
"(",
"d",
"Decoder",
")",
"DecodeMap",
"(",
"f",
"func",
"(",
"Decoder",
",",
"Decoder",
")",
"error",
")",
"(",
"err",
"error",
")",
"{",
"var",
"typ",
"Type",
"\n",
"if",
"d",
".",
"off",
"!=",
"0",
"{",
"if",
"d",
".",
"off",
",",
"err",
"=",
"0",
",",
"d",
".",
"Parser",
".",
"ParseMapValue",
"(",
"d",
".",
"off",
"-",
"1",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"typ",
",",
"err",
"=",
"d",
".",
"Parser",
".",
"ParseType",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"err",
"=",
"d",
".",
"decodeMapImpl",
"(",
"typ",
",",
"f",
")",
"\n",
"return",
"\n",
"}"
] |
// DecodeMap provides the implementation of the algorithm for decoding maps,
// where f is called to decode each pair of key and value.
//
// The function f is expected to decode two values from the map, the first one
// being the key and the second the associated value. The first decoder must be
// used to decode the key, the second one for the value.
|
[
"DecodeMap",
"provides",
"the",
"implementation",
"of",
"the",
"algorithm",
"for",
"decoding",
"maps",
"where",
"f",
"is",
"called",
"to",
"decode",
"each",
"pair",
"of",
"key",
"and",
"value",
".",
"The",
"function",
"f",
"is",
"expected",
"to",
"decode",
"two",
"values",
"from",
"the",
"map",
"the",
"first",
"one",
"being",
"the",
"key",
"and",
"the",
"second",
"the",
"associated",
"value",
".",
"The",
"first",
"decoder",
"must",
"be",
"used",
"to",
"decode",
"the",
"key",
"the",
"second",
"one",
"for",
"the",
"value",
"."
] |
7a1d7b8e6f3551b30751e6b2ea6bae500883870e
|
https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/decode.go#L1197-L1212
|
test
|
segmentio/objconv
|
decode.go
|
NewStreamDecoder
|
func NewStreamDecoder(p Parser) *StreamDecoder {
if p == nil {
panic("objconv: the parser is nil")
}
return &StreamDecoder{Parser: p}
}
|
go
|
func NewStreamDecoder(p Parser) *StreamDecoder {
if p == nil {
panic("objconv: the parser is nil")
}
return &StreamDecoder{Parser: p}
}
|
[
"func",
"NewStreamDecoder",
"(",
"p",
"Parser",
")",
"*",
"StreamDecoder",
"{",
"if",
"p",
"==",
"nil",
"{",
"panic",
"(",
"\"objconv: the parser is nil\"",
")",
"\n",
"}",
"\n",
"return",
"&",
"StreamDecoder",
"{",
"Parser",
":",
"p",
"}",
"\n",
"}"
] |
// NewStreamDecoder returns a new stream decoder that takes input from p.
//
// The function panics if p is nil.
|
[
"NewStreamDecoder",
"returns",
"a",
"new",
"stream",
"decoder",
"that",
"takes",
"input",
"from",
"p",
".",
"The",
"function",
"panics",
"if",
"p",
"is",
"nil",
"."
] |
7a1d7b8e6f3551b30751e6b2ea6bae500883870e
|
https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/decode.go#L1282-L1287
|
test
|
segmentio/objconv
|
decode.go
|
Len
|
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
|
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
}
|
[
"func",
"(",
"d",
"*",
"StreamDecoder",
")",
"Len",
"(",
")",
"int",
"{",
"if",
"d",
".",
"err",
"!=",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n",
"if",
"d",
".",
"typ",
"==",
"Unknown",
"{",
"if",
"d",
".",
"init",
"(",
")",
"!=",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"d",
".",
"max",
"-",
"d",
".",
"cnt",
"\n",
"}"
] |
// Len returns the number of values remaining to be read from the stream, which
// may be -1 if the underlying format doesn't provide this information. If an
// error occurred while decoding the stream the method returns zero because no
// more values can be read.
|
[
"Len",
"returns",
"the",
"number",
"of",
"values",
"remaining",
"to",
"be",
"read",
"from",
"the",
"stream",
"which",
"may",
"be",
"-",
"1",
"if",
"the",
"underlying",
"format",
"doesn",
"t",
"provide",
"this",
"information",
".",
"If",
"an",
"error",
"occurred",
"while",
"decoding",
"the",
"stream",
"the",
"method",
"returns",
"zero",
"because",
"no",
"more",
"values",
"can",
"be",
"read",
"."
] |
7a1d7b8e6f3551b30751e6b2ea6bae500883870e
|
https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/decode.go#L1293-L1305
|
test
|
segmentio/objconv
|
decode.go
|
Err
|
func (d *StreamDecoder) Err() error {
if d.err == End {
return nil
}
return d.err
}
|
go
|
func (d *StreamDecoder) Err() error {
if d.err == End {
return nil
}
return d.err
}
|
[
"func",
"(",
"d",
"*",
"StreamDecoder",
")",
"Err",
"(",
")",
"error",
"{",
"if",
"d",
".",
"err",
"==",
"End",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"d",
".",
"err",
"\n",
"}"
] |
// Err returns the last error returned by the Decode method.
//
// The method returns nil if the stream reached its natural end.
|
[
"Err",
"returns",
"the",
"last",
"error",
"returned",
"by",
"the",
"Decode",
"method",
".",
"The",
"method",
"returns",
"nil",
"if",
"the",
"stream",
"reached",
"its",
"natural",
"end",
"."
] |
7a1d7b8e6f3551b30751e6b2ea6bae500883870e
|
https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/decode.go#L1310-L1315
|
test
|
segmentio/objconv
|
decode.go
|
Decode
|
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
|
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
}
|
[
"func",
"(",
"d",
"*",
"StreamDecoder",
")",
"Decode",
"(",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"d",
".",
"err",
"!=",
"nil",
"{",
"return",
"d",
".",
"err",
"\n",
"}",
"\n",
"err",
":=",
"error",
"(",
"nil",
")",
"\n",
"cnt",
":=",
"d",
".",
"cnt",
"\n",
"max",
":=",
"d",
".",
"max",
"\n",
"dec",
":=",
"Decoder",
"{",
"Parser",
":",
"d",
".",
"Parser",
",",
"MapType",
":",
"d",
".",
"MapType",
",",
"}",
"\n",
"switch",
"d",
".",
"typ",
"{",
"case",
"Unknown",
":",
"err",
"=",
"d",
".",
"init",
"(",
")",
"\n",
"max",
"=",
"d",
".",
"max",
"\n",
"case",
"Array",
":",
"if",
"cnt",
"==",
"max",
"{",
"err",
"=",
"dec",
".",
"Parser",
".",
"ParseArrayEnd",
"(",
"cnt",
")",
"\n",
"}",
"else",
"if",
"cnt",
"!=",
"0",
"{",
"err",
"=",
"dec",
".",
"Parser",
".",
"ParseArrayNext",
"(",
"cnt",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"err",
"==",
"nil",
"{",
"if",
"cnt",
"==",
"max",
"{",
"err",
"=",
"End",
"\n",
"}",
"else",
"{",
"switch",
"err",
"=",
"dec",
".",
"Decode",
"(",
"v",
")",
";",
"err",
"{",
"case",
"nil",
":",
"cnt",
"++",
"\n",
"case",
"End",
":",
"cnt",
"++",
"\n",
"max",
"=",
"cnt",
"\n",
"default",
":",
"if",
"max",
"<",
"0",
"&&",
"dec",
".",
"Parser",
".",
"ParseArrayEnd",
"(",
"cnt",
")",
"==",
"nil",
"{",
"err",
"=",
"End",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"d",
".",
"err",
"=",
"err",
"\n",
"d",
".",
"cnt",
"=",
"cnt",
"\n",
"d",
".",
"max",
"=",
"max",
"\n",
"return",
"err",
"\n",
"}"
] |
// Decodes the next value from the stream into v.
|
[
"Decodes",
"the",
"next",
"value",
"from",
"the",
"stream",
"into",
"v",
"."
] |
7a1d7b8e6f3551b30751e6b2ea6bae500883870e
|
https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/decode.go#L1318-L1365
|
test
|
segmentio/objconv
|
decode.go
|
Encoder
|
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
|
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
}
|
[
"func",
"(",
"d",
"*",
"StreamDecoder",
")",
"Encoder",
"(",
"e",
"Emitter",
")",
"(",
"enc",
"*",
"StreamEncoder",
",",
"err",
"error",
")",
"{",
"var",
"typ",
"Type",
"\n",
"if",
"typ",
",",
"err",
"=",
"d",
".",
"Parser",
".",
"ParseType",
"(",
")",
";",
"err",
"==",
"nil",
"{",
"enc",
"=",
"NewStreamEncoder",
"(",
"e",
")",
"\n",
"enc",
".",
"oneshot",
"=",
"typ",
"!=",
"Array",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// Encoder returns a new StreamEncoder which can be used to re-encode the stream
// decoded by d into e.
//
// The method panics if e is nil.
|
[
"Encoder",
"returns",
"a",
"new",
"StreamEncoder",
"which",
"can",
"be",
"used",
"to",
"re",
"-",
"encode",
"the",
"stream",
"decoded",
"by",
"d",
"into",
"e",
".",
"The",
"method",
"panics",
"if",
"e",
"is",
"nil",
"."
] |
7a1d7b8e6f3551b30751e6b2ea6bae500883870e
|
https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/decode.go#L1371-L1380
|
test
|
btcsuite/btclog
|
log.go
|
init
|
func init() {
for _, f := range strings.Split(os.Getenv("LOGFLAGS"), ",") {
switch f {
case "longfile":
defaultFlags |= Llongfile
case "shortfile":
defaultFlags |= Lshortfile
}
}
}
|
go
|
func init() {
for _, f := range strings.Split(os.Getenv("LOGFLAGS"), ",") {
switch f {
case "longfile":
defaultFlags |= Llongfile
case "shortfile":
defaultFlags |= Lshortfile
}
}
}
|
[
"func",
"init",
"(",
")",
"{",
"for",
"_",
",",
"f",
":=",
"range",
"strings",
".",
"Split",
"(",
"os",
".",
"Getenv",
"(",
"\"LOGFLAGS\"",
")",
",",
"\",\"",
")",
"{",
"switch",
"f",
"{",
"case",
"\"longfile\"",
":",
"defaultFlags",
"|=",
"Llongfile",
"\n",
"case",
"\"shortfile\"",
":",
"defaultFlags",
"|=",
"Lshortfile",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// Read logger flags from the LOGFLAGS environment variable. Multiple flags can
// be set at once, separated by commas.
|
[
"Read",
"logger",
"flags",
"from",
"the",
"LOGFLAGS",
"environment",
"variable",
".",
"Multiple",
"flags",
"can",
"be",
"set",
"at",
"once",
"separated",
"by",
"commas",
"."
] |
84c8d2346e9fc8c7b947e243b9c24e6df9fd206a
|
https://github.com/btcsuite/btclog/blob/84c8d2346e9fc8c7b947e243b9c24e6df9fd206a/log.go#L66-L75
|
test
|
btcsuite/btclog
|
log.go
|
LevelFromString
|
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
|
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
}
}
|
[
"func",
"LevelFromString",
"(",
"s",
"string",
")",
"(",
"l",
"Level",
",",
"ok",
"bool",
")",
"{",
"switch",
"strings",
".",
"ToLower",
"(",
"s",
")",
"{",
"case",
"\"trace\"",
",",
"\"trc\"",
":",
"return",
"LevelTrace",
",",
"true",
"\n",
"case",
"\"debug\"",
",",
"\"dbg\"",
":",
"return",
"LevelDebug",
",",
"true",
"\n",
"case",
"\"info\"",
",",
"\"inf\"",
":",
"return",
"LevelInfo",
",",
"true",
"\n",
"case",
"\"warn\"",
",",
"\"wrn\"",
":",
"return",
"LevelWarn",
",",
"true",
"\n",
"case",
"\"error\"",
",",
"\"err\"",
":",
"return",
"LevelError",
",",
"true",
"\n",
"case",
"\"critical\"",
",",
"\"crt\"",
":",
"return",
"LevelCritical",
",",
"true",
"\n",
"case",
"\"off\"",
":",
"return",
"LevelOff",
",",
"true",
"\n",
"default",
":",
"return",
"LevelInfo",
",",
"false",
"\n",
"}",
"\n",
"}"
] |
// LevelFromString returns a level based on the input string s. If the input
// can't be interpreted as a valid log level, the info level and false is
// returned.
|
[
"LevelFromString",
"returns",
"a",
"level",
"based",
"on",
"the",
"input",
"string",
"s",
".",
"If",
"the",
"input",
"can",
"t",
"be",
"interpreted",
"as",
"a",
"valid",
"log",
"level",
"the",
"info",
"level",
"and",
"false",
"is",
"returned",
"."
] |
84c8d2346e9fc8c7b947e243b9c24e6df9fd206a
|
https://github.com/btcsuite/btclog/blob/84c8d2346e9fc8c7b947e243b9c24e6df9fd206a/log.go#L98-L117
|
test
|
btcsuite/btclog
|
log.go
|
NewBackend
|
func NewBackend(w io.Writer, opts ...BackendOption) *Backend {
b := &Backend{w: w, flag: defaultFlags}
for _, o := range opts {
o(b)
}
return b
}
|
go
|
func NewBackend(w io.Writer, opts ...BackendOption) *Backend {
b := &Backend{w: w, flag: defaultFlags}
for _, o := range opts {
o(b)
}
return b
}
|
[
"func",
"NewBackend",
"(",
"w",
"io",
".",
"Writer",
",",
"opts",
"...",
"BackendOption",
")",
"*",
"Backend",
"{",
"b",
":=",
"&",
"Backend",
"{",
"w",
":",
"w",
",",
"flag",
":",
"defaultFlags",
"}",
"\n",
"for",
"_",
",",
"o",
":=",
"range",
"opts",
"{",
"o",
"(",
"b",
")",
"\n",
"}",
"\n",
"return",
"b",
"\n",
"}"
] |
// NewBackend creates a logger backend from a Writer.
|
[
"NewBackend",
"creates",
"a",
"logger",
"backend",
"from",
"a",
"Writer",
"."
] |
84c8d2346e9fc8c7b947e243b9c24e6df9fd206a
|
https://github.com/btcsuite/btclog/blob/84c8d2346e9fc8c7b947e243b9c24e6df9fd206a/log.go#L129-L135
|
test
|
btcsuite/btclog
|
log.go
|
callsite
|
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
|
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
}
|
[
"func",
"callsite",
"(",
"flag",
"uint32",
")",
"(",
"string",
",",
"int",
")",
"{",
"_",
",",
"file",
",",
"line",
",",
"ok",
":=",
"runtime",
".",
"Caller",
"(",
"calldepth",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\"???\"",
",",
"0",
"\n",
"}",
"\n",
"if",
"flag",
"&",
"Lshortfile",
"!=",
"0",
"{",
"short",
":=",
"file",
"\n",
"for",
"i",
":=",
"len",
"(",
"file",
")",
"-",
"1",
";",
"i",
">",
"0",
";",
"i",
"--",
"{",
"if",
"os",
".",
"IsPathSeparator",
"(",
"file",
"[",
"i",
"]",
")",
"{",
"short",
"=",
"file",
"[",
"i",
"+",
"1",
":",
"]",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"file",
"=",
"short",
"\n",
"}",
"\n",
"return",
"file",
",",
"line",
"\n",
"}"
] |
// callsite returns the file name and line number of the callsite to the
// subsystem logger.
|
[
"callsite",
"returns",
"the",
"file",
"name",
"and",
"line",
"number",
"of",
"the",
"callsite",
"to",
"the",
"subsystem",
"logger",
"."
] |
84c8d2346e9fc8c7b947e243b9c24e6df9fd206a
|
https://github.com/btcsuite/btclog/blob/84c8d2346e9fc8c7b947e243b9c24e6df9fd206a/log.go#L243-L259
|
test
|
btcsuite/btclog
|
log.go
|
print
|
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
|
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)
}
|
[
"func",
"(",
"b",
"*",
"Backend",
")",
"print",
"(",
"lvl",
",",
"tag",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"t",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"bytebuf",
":=",
"buffer",
"(",
")",
"\n",
"var",
"file",
"string",
"\n",
"var",
"line",
"int",
"\n",
"if",
"b",
".",
"flag",
"&",
"(",
"Lshortfile",
"|",
"Llongfile",
")",
"!=",
"0",
"{",
"file",
",",
"line",
"=",
"callsite",
"(",
"b",
".",
"flag",
")",
"\n",
"}",
"\n",
"formatHeader",
"(",
"bytebuf",
",",
"t",
",",
"lvl",
",",
"tag",
",",
"file",
",",
"line",
")",
"\n",
"buf",
":=",
"bytes",
".",
"NewBuffer",
"(",
"*",
"bytebuf",
")",
"\n",
"fmt",
".",
"Fprintln",
"(",
"buf",
",",
"args",
"...",
")",
"\n",
"*",
"bytebuf",
"=",
"buf",
".",
"Bytes",
"(",
")",
"\n",
"b",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"b",
".",
"w",
".",
"Write",
"(",
"*",
"bytebuf",
")",
"\n",
"b",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"recycleBuffer",
"(",
"bytebuf",
")",
"\n",
"}"
] |
// print outputs a log message to the writer associated with the backend after
// creating a prefix for the given level and tag according to the formatHeader
// function and formatting the provided arguments using the default formatting
// rules.
|
[
"print",
"outputs",
"a",
"log",
"message",
"to",
"the",
"writer",
"associated",
"with",
"the",
"backend",
"after",
"creating",
"a",
"prefix",
"for",
"the",
"given",
"level",
"and",
"tag",
"according",
"to",
"the",
"formatHeader",
"function",
"and",
"formatting",
"the",
"provided",
"arguments",
"using",
"the",
"default",
"formatting",
"rules",
"."
] |
84c8d2346e9fc8c7b947e243b9c24e6df9fd206a
|
https://github.com/btcsuite/btclog/blob/84c8d2346e9fc8c7b947e243b9c24e6df9fd206a/log.go#L265-L286
|
test
|
btcsuite/btclog
|
log.go
|
Logger
|
func (b *Backend) Logger(subsystemTag string) Logger {
return &slog{LevelInfo, subsystemTag, b}
}
|
go
|
func (b *Backend) Logger(subsystemTag string) Logger {
return &slog{LevelInfo, subsystemTag, b}
}
|
[
"func",
"(",
"b",
"*",
"Backend",
")",
"Logger",
"(",
"subsystemTag",
"string",
")",
"Logger",
"{",
"return",
"&",
"slog",
"{",
"LevelInfo",
",",
"subsystemTag",
",",
"b",
"}",
"\n",
"}"
] |
// Logger returns a new logger for a particular subsystem that writes to the
// Backend b. A tag describes the subsystem and is included in all log
// messages. The logger uses the info verbosity level by default.
|
[
"Logger",
"returns",
"a",
"new",
"logger",
"for",
"a",
"particular",
"subsystem",
"that",
"writes",
"to",
"the",
"Backend",
"b",
".",
"A",
"tag",
"describes",
"the",
"subsystem",
"and",
"is",
"included",
"in",
"all",
"log",
"messages",
".",
"The",
"logger",
"uses",
"the",
"info",
"verbosity",
"level",
"by",
"default",
"."
] |
84c8d2346e9fc8c7b947e243b9c24e6df9fd206a
|
https://github.com/btcsuite/btclog/blob/84c8d2346e9fc8c7b947e243b9c24e6df9fd206a/log.go#L318-L320
|
test
|
btcsuite/btclog
|
log.go
|
Trace
|
func (l *slog) Trace(args ...interface{}) {
lvl := l.Level()
if lvl <= LevelTrace {
l.b.print("TRC", l.tag, args...)
}
}
|
go
|
func (l *slog) Trace(args ...interface{}) {
lvl := l.Level()
if lvl <= LevelTrace {
l.b.print("TRC", l.tag, args...)
}
}
|
[
"func",
"(",
"l",
"*",
"slog",
")",
"Trace",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"lvl",
":=",
"l",
".",
"Level",
"(",
")",
"\n",
"if",
"lvl",
"<=",
"LevelTrace",
"{",
"l",
".",
"b",
".",
"print",
"(",
"\"TRC\"",
",",
"l",
".",
"tag",
",",
"args",
"...",
")",
"\n",
"}",
"\n",
"}"
] |
// Trace formats message using the default formats for its operands, prepends
// the prefix as necessary, and writes to log with LevelTrace.
//
// This is part of the Logger interface implementation.
|
[
"Trace",
"formats",
"message",
"using",
"the",
"default",
"formats",
"for",
"its",
"operands",
"prepends",
"the",
"prefix",
"as",
"necessary",
"and",
"writes",
"to",
"log",
"with",
"LevelTrace",
".",
"This",
"is",
"part",
"of",
"the",
"Logger",
"interface",
"implementation",
"."
] |
84c8d2346e9fc8c7b947e243b9c24e6df9fd206a
|
https://github.com/btcsuite/btclog/blob/84c8d2346e9fc8c7b947e243b9c24e6df9fd206a/log.go#L333-L338
|
test
|
btcsuite/btclog
|
log.go
|
Tracef
|
func (l *slog) Tracef(format string, args ...interface{}) {
lvl := l.Level()
if lvl <= LevelTrace {
l.b.printf("TRC", l.tag, format, args...)
}
}
|
go
|
func (l *slog) Tracef(format string, args ...interface{}) {
lvl := l.Level()
if lvl <= LevelTrace {
l.b.printf("TRC", l.tag, format, args...)
}
}
|
[
"func",
"(",
"l",
"*",
"slog",
")",
"Tracef",
"(",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"lvl",
":=",
"l",
".",
"Level",
"(",
")",
"\n",
"if",
"lvl",
"<=",
"LevelTrace",
"{",
"l",
".",
"b",
".",
"printf",
"(",
"\"TRC\"",
",",
"l",
".",
"tag",
",",
"format",
",",
"args",
"...",
")",
"\n",
"}",
"\n",
"}"
] |
// Tracef formats message according to format specifier, prepends the prefix as
// necessary, and writes to log with LevelTrace.
//
// This is part of the Logger interface implementation.
|
[
"Tracef",
"formats",
"message",
"according",
"to",
"format",
"specifier",
"prepends",
"the",
"prefix",
"as",
"necessary",
"and",
"writes",
"to",
"log",
"with",
"LevelTrace",
".",
"This",
"is",
"part",
"of",
"the",
"Logger",
"interface",
"implementation",
"."
] |
84c8d2346e9fc8c7b947e243b9c24e6df9fd206a
|
https://github.com/btcsuite/btclog/blob/84c8d2346e9fc8c7b947e243b9c24e6df9fd206a/log.go#L344-L349
|
test
|
btcsuite/btclog
|
log.go
|
Debug
|
func (l *slog) Debug(args ...interface{}) {
lvl := l.Level()
if lvl <= LevelDebug {
l.b.print("DBG", l.tag, args...)
}
}
|
go
|
func (l *slog) Debug(args ...interface{}) {
lvl := l.Level()
if lvl <= LevelDebug {
l.b.print("DBG", l.tag, args...)
}
}
|
[
"func",
"(",
"l",
"*",
"slog",
")",
"Debug",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"lvl",
":=",
"l",
".",
"Level",
"(",
")",
"\n",
"if",
"lvl",
"<=",
"LevelDebug",
"{",
"l",
".",
"b",
".",
"print",
"(",
"\"DBG\"",
",",
"l",
".",
"tag",
",",
"args",
"...",
")",
"\n",
"}",
"\n",
"}"
] |
// Debug formats message using the default formats for its operands, prepends
// the prefix as necessary, and writes to log with LevelDebug.
//
// This is part of the Logger interface implementation.
|
[
"Debug",
"formats",
"message",
"using",
"the",
"default",
"formats",
"for",
"its",
"operands",
"prepends",
"the",
"prefix",
"as",
"necessary",
"and",
"writes",
"to",
"log",
"with",
"LevelDebug",
".",
"This",
"is",
"part",
"of",
"the",
"Logger",
"interface",
"implementation",
"."
] |
84c8d2346e9fc8c7b947e243b9c24e6df9fd206a
|
https://github.com/btcsuite/btclog/blob/84c8d2346e9fc8c7b947e243b9c24e6df9fd206a/log.go#L355-L360
|
test
|
btcsuite/btclog
|
log.go
|
Debugf
|
func (l *slog) Debugf(format string, args ...interface{}) {
lvl := l.Level()
if lvl <= LevelDebug {
l.b.printf("DBG", l.tag, format, args...)
}
}
|
go
|
func (l *slog) Debugf(format string, args ...interface{}) {
lvl := l.Level()
if lvl <= LevelDebug {
l.b.printf("DBG", l.tag, format, args...)
}
}
|
[
"func",
"(",
"l",
"*",
"slog",
")",
"Debugf",
"(",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"lvl",
":=",
"l",
".",
"Level",
"(",
")",
"\n",
"if",
"lvl",
"<=",
"LevelDebug",
"{",
"l",
".",
"b",
".",
"printf",
"(",
"\"DBG\"",
",",
"l",
".",
"tag",
",",
"format",
",",
"args",
"...",
")",
"\n",
"}",
"\n",
"}"
] |
// Debugf formats message according to format specifier, prepends the prefix as
// necessary, and writes to log with LevelDebug.
//
// This is part of the Logger interface implementation.
|
[
"Debugf",
"formats",
"message",
"according",
"to",
"format",
"specifier",
"prepends",
"the",
"prefix",
"as",
"necessary",
"and",
"writes",
"to",
"log",
"with",
"LevelDebug",
".",
"This",
"is",
"part",
"of",
"the",
"Logger",
"interface",
"implementation",
"."
] |
84c8d2346e9fc8c7b947e243b9c24e6df9fd206a
|
https://github.com/btcsuite/btclog/blob/84c8d2346e9fc8c7b947e243b9c24e6df9fd206a/log.go#L366-L371
|
test
|
btcsuite/btclog
|
log.go
|
Info
|
func (l *slog) Info(args ...interface{}) {
lvl := l.Level()
if lvl <= LevelInfo {
l.b.print("INF", l.tag, args...)
}
}
|
go
|
func (l *slog) Info(args ...interface{}) {
lvl := l.Level()
if lvl <= LevelInfo {
l.b.print("INF", l.tag, args...)
}
}
|
[
"func",
"(",
"l",
"*",
"slog",
")",
"Info",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"lvl",
":=",
"l",
".",
"Level",
"(",
")",
"\n",
"if",
"lvl",
"<=",
"LevelInfo",
"{",
"l",
".",
"b",
".",
"print",
"(",
"\"INF\"",
",",
"l",
".",
"tag",
",",
"args",
"...",
")",
"\n",
"}",
"\n",
"}"
] |
// Info formats message using the default formats for its operands, prepends
// the prefix as necessary, and writes to log with LevelInfo.
//
// This is part of the Logger interface implementation.
|
[
"Info",
"formats",
"message",
"using",
"the",
"default",
"formats",
"for",
"its",
"operands",
"prepends",
"the",
"prefix",
"as",
"necessary",
"and",
"writes",
"to",
"log",
"with",
"LevelInfo",
".",
"This",
"is",
"part",
"of",
"the",
"Logger",
"interface",
"implementation",
"."
] |
84c8d2346e9fc8c7b947e243b9c24e6df9fd206a
|
https://github.com/btcsuite/btclog/blob/84c8d2346e9fc8c7b947e243b9c24e6df9fd206a/log.go#L377-L382
|
test
|
btcsuite/btclog
|
log.go
|
Infof
|
func (l *slog) Infof(format string, args ...interface{}) {
lvl := l.Level()
if lvl <= LevelInfo {
l.b.printf("INF", l.tag, format, args...)
}
}
|
go
|
func (l *slog) Infof(format string, args ...interface{}) {
lvl := l.Level()
if lvl <= LevelInfo {
l.b.printf("INF", l.tag, format, args...)
}
}
|
[
"func",
"(",
"l",
"*",
"slog",
")",
"Infof",
"(",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"lvl",
":=",
"l",
".",
"Level",
"(",
")",
"\n",
"if",
"lvl",
"<=",
"LevelInfo",
"{",
"l",
".",
"b",
".",
"printf",
"(",
"\"INF\"",
",",
"l",
".",
"tag",
",",
"format",
",",
"args",
"...",
")",
"\n",
"}",
"\n",
"}"
] |
// Infof formats message according to format specifier, prepends the prefix as
// necessary, and writes to log with LevelInfo.
//
// This is part of the Logger interface implementation.
|
[
"Infof",
"formats",
"message",
"according",
"to",
"format",
"specifier",
"prepends",
"the",
"prefix",
"as",
"necessary",
"and",
"writes",
"to",
"log",
"with",
"LevelInfo",
".",
"This",
"is",
"part",
"of",
"the",
"Logger",
"interface",
"implementation",
"."
] |
84c8d2346e9fc8c7b947e243b9c24e6df9fd206a
|
https://github.com/btcsuite/btclog/blob/84c8d2346e9fc8c7b947e243b9c24e6df9fd206a/log.go#L388-L393
|
test
|
btcsuite/btclog
|
log.go
|
Warn
|
func (l *slog) Warn(args ...interface{}) {
lvl := l.Level()
if lvl <= LevelWarn {
l.b.print("WRN", l.tag, args...)
}
}
|
go
|
func (l *slog) Warn(args ...interface{}) {
lvl := l.Level()
if lvl <= LevelWarn {
l.b.print("WRN", l.tag, args...)
}
}
|
[
"func",
"(",
"l",
"*",
"slog",
")",
"Warn",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"lvl",
":=",
"l",
".",
"Level",
"(",
")",
"\n",
"if",
"lvl",
"<=",
"LevelWarn",
"{",
"l",
".",
"b",
".",
"print",
"(",
"\"WRN\"",
",",
"l",
".",
"tag",
",",
"args",
"...",
")",
"\n",
"}",
"\n",
"}"
] |
// Warn formats message using the default formats for its operands, prepends
// the prefix as necessary, and writes to log with LevelWarn.
//
// This is part of the Logger interface implementation.
|
[
"Warn",
"formats",
"message",
"using",
"the",
"default",
"formats",
"for",
"its",
"operands",
"prepends",
"the",
"prefix",
"as",
"necessary",
"and",
"writes",
"to",
"log",
"with",
"LevelWarn",
".",
"This",
"is",
"part",
"of",
"the",
"Logger",
"interface",
"implementation",
"."
] |
84c8d2346e9fc8c7b947e243b9c24e6df9fd206a
|
https://github.com/btcsuite/btclog/blob/84c8d2346e9fc8c7b947e243b9c24e6df9fd206a/log.go#L399-L404
|
test
|
btcsuite/btclog
|
log.go
|
Warnf
|
func (l *slog) Warnf(format string, args ...interface{}) {
lvl := l.Level()
if lvl <= LevelWarn {
l.b.printf("WRN", l.tag, format, args...)
}
}
|
go
|
func (l *slog) Warnf(format string, args ...interface{}) {
lvl := l.Level()
if lvl <= LevelWarn {
l.b.printf("WRN", l.tag, format, args...)
}
}
|
[
"func",
"(",
"l",
"*",
"slog",
")",
"Warnf",
"(",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"lvl",
":=",
"l",
".",
"Level",
"(",
")",
"\n",
"if",
"lvl",
"<=",
"LevelWarn",
"{",
"l",
".",
"b",
".",
"printf",
"(",
"\"WRN\"",
",",
"l",
".",
"tag",
",",
"format",
",",
"args",
"...",
")",
"\n",
"}",
"\n",
"}"
] |
// Warnf formats message according to format specifier, prepends the prefix as
// necessary, and writes to log with LevelWarn.
//
// This is part of the Logger interface implementation.
|
[
"Warnf",
"formats",
"message",
"according",
"to",
"format",
"specifier",
"prepends",
"the",
"prefix",
"as",
"necessary",
"and",
"writes",
"to",
"log",
"with",
"LevelWarn",
".",
"This",
"is",
"part",
"of",
"the",
"Logger",
"interface",
"implementation",
"."
] |
84c8d2346e9fc8c7b947e243b9c24e6df9fd206a
|
https://github.com/btcsuite/btclog/blob/84c8d2346e9fc8c7b947e243b9c24e6df9fd206a/log.go#L410-L415
|
test
|
btcsuite/btclog
|
log.go
|
Error
|
func (l *slog) Error(args ...interface{}) {
lvl := l.Level()
if lvl <= LevelError {
l.b.print("ERR", l.tag, args...)
}
}
|
go
|
func (l *slog) Error(args ...interface{}) {
lvl := l.Level()
if lvl <= LevelError {
l.b.print("ERR", l.tag, args...)
}
}
|
[
"func",
"(",
"l",
"*",
"slog",
")",
"Error",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"lvl",
":=",
"l",
".",
"Level",
"(",
")",
"\n",
"if",
"lvl",
"<=",
"LevelError",
"{",
"l",
".",
"b",
".",
"print",
"(",
"\"ERR\"",
",",
"l",
".",
"tag",
",",
"args",
"...",
")",
"\n",
"}",
"\n",
"}"
] |
// Error formats message using the default formats for its operands, prepends
// the prefix as necessary, and writes to log with LevelError.
//
// This is part of the Logger interface implementation.
|
[
"Error",
"formats",
"message",
"using",
"the",
"default",
"formats",
"for",
"its",
"operands",
"prepends",
"the",
"prefix",
"as",
"necessary",
"and",
"writes",
"to",
"log",
"with",
"LevelError",
".",
"This",
"is",
"part",
"of",
"the",
"Logger",
"interface",
"implementation",
"."
] |
84c8d2346e9fc8c7b947e243b9c24e6df9fd206a
|
https://github.com/btcsuite/btclog/blob/84c8d2346e9fc8c7b947e243b9c24e6df9fd206a/log.go#L421-L426
|
test
|
btcsuite/btclog
|
log.go
|
Errorf
|
func (l *slog) Errorf(format string, args ...interface{}) {
lvl := l.Level()
if lvl <= LevelError {
l.b.printf("ERR", l.tag, format, args...)
}
}
|
go
|
func (l *slog) Errorf(format string, args ...interface{}) {
lvl := l.Level()
if lvl <= LevelError {
l.b.printf("ERR", l.tag, format, args...)
}
}
|
[
"func",
"(",
"l",
"*",
"slog",
")",
"Errorf",
"(",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"lvl",
":=",
"l",
".",
"Level",
"(",
")",
"\n",
"if",
"lvl",
"<=",
"LevelError",
"{",
"l",
".",
"b",
".",
"printf",
"(",
"\"ERR\"",
",",
"l",
".",
"tag",
",",
"format",
",",
"args",
"...",
")",
"\n",
"}",
"\n",
"}"
] |
// Errorf formats message according to format specifier, prepends the prefix as
// necessary, and writes to log with LevelError.
//
// This is part of the Logger interface implementation.
|
[
"Errorf",
"formats",
"message",
"according",
"to",
"format",
"specifier",
"prepends",
"the",
"prefix",
"as",
"necessary",
"and",
"writes",
"to",
"log",
"with",
"LevelError",
".",
"This",
"is",
"part",
"of",
"the",
"Logger",
"interface",
"implementation",
"."
] |
84c8d2346e9fc8c7b947e243b9c24e6df9fd206a
|
https://github.com/btcsuite/btclog/blob/84c8d2346e9fc8c7b947e243b9c24e6df9fd206a/log.go#L432-L437
|
test
|
btcsuite/btclog
|
log.go
|
Critical
|
func (l *slog) Critical(args ...interface{}) {
lvl := l.Level()
if lvl <= LevelCritical {
l.b.print("CRT", l.tag, args...)
}
}
|
go
|
func (l *slog) Critical(args ...interface{}) {
lvl := l.Level()
if lvl <= LevelCritical {
l.b.print("CRT", l.tag, args...)
}
}
|
[
"func",
"(",
"l",
"*",
"slog",
")",
"Critical",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"lvl",
":=",
"l",
".",
"Level",
"(",
")",
"\n",
"if",
"lvl",
"<=",
"LevelCritical",
"{",
"l",
".",
"b",
".",
"print",
"(",
"\"CRT\"",
",",
"l",
".",
"tag",
",",
"args",
"...",
")",
"\n",
"}",
"\n",
"}"
] |
// Critical formats message using the default formats for its operands, prepends
// the prefix as necessary, and writes to log with LevelCritical.
//
// This is part of the Logger interface implementation.
|
[
"Critical",
"formats",
"message",
"using",
"the",
"default",
"formats",
"for",
"its",
"operands",
"prepends",
"the",
"prefix",
"as",
"necessary",
"and",
"writes",
"to",
"log",
"with",
"LevelCritical",
".",
"This",
"is",
"part",
"of",
"the",
"Logger",
"interface",
"implementation",
"."
] |
84c8d2346e9fc8c7b947e243b9c24e6df9fd206a
|
https://github.com/btcsuite/btclog/blob/84c8d2346e9fc8c7b947e243b9c24e6df9fd206a/log.go#L443-L448
|
test
|
btcsuite/btclog
|
log.go
|
Criticalf
|
func (l *slog) Criticalf(format string, args ...interface{}) {
lvl := l.Level()
if lvl <= LevelCritical {
l.b.printf("CRT", l.tag, format, args...)
}
}
|
go
|
func (l *slog) Criticalf(format string, args ...interface{}) {
lvl := l.Level()
if lvl <= LevelCritical {
l.b.printf("CRT", l.tag, format, args...)
}
}
|
[
"func",
"(",
"l",
"*",
"slog",
")",
"Criticalf",
"(",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"lvl",
":=",
"l",
".",
"Level",
"(",
")",
"\n",
"if",
"lvl",
"<=",
"LevelCritical",
"{",
"l",
".",
"b",
".",
"printf",
"(",
"\"CRT\"",
",",
"l",
".",
"tag",
",",
"format",
",",
"args",
"...",
")",
"\n",
"}",
"\n",
"}"
] |
// Criticalf formats message according to format specifier, prepends the prefix
// as necessary, and writes to log with LevelCritical.
//
// This is part of the Logger interface implementation.
|
[
"Criticalf",
"formats",
"message",
"according",
"to",
"format",
"specifier",
"prepends",
"the",
"prefix",
"as",
"necessary",
"and",
"writes",
"to",
"log",
"with",
"LevelCritical",
".",
"This",
"is",
"part",
"of",
"the",
"Logger",
"interface",
"implementation",
"."
] |
84c8d2346e9fc8c7b947e243b9c24e6df9fd206a
|
https://github.com/btcsuite/btclog/blob/84c8d2346e9fc8c7b947e243b9c24e6df9fd206a/log.go#L454-L459
|
test
|
btcsuite/btclog
|
log.go
|
Level
|
func (l *slog) Level() Level {
return Level(atomic.LoadUint32((*uint32)(&l.lvl)))
}
|
go
|
func (l *slog) Level() Level {
return Level(atomic.LoadUint32((*uint32)(&l.lvl)))
}
|
[
"func",
"(",
"l",
"*",
"slog",
")",
"Level",
"(",
")",
"Level",
"{",
"return",
"Level",
"(",
"atomic",
".",
"LoadUint32",
"(",
"(",
"*",
"uint32",
")",
"(",
"&",
"l",
".",
"lvl",
")",
")",
")",
"\n",
"}"
] |
// Level returns the current logging level
//
// This is part of the Logger interface implementation.
|
[
"Level",
"returns",
"the",
"current",
"logging",
"level",
"This",
"is",
"part",
"of",
"the",
"Logger",
"interface",
"implementation",
"."
] |
84c8d2346e9fc8c7b947e243b9c24e6df9fd206a
|
https://github.com/btcsuite/btclog/blob/84c8d2346e9fc8c7b947e243b9c24e6df9fd206a/log.go#L464-L466
|
test
|
btcsuite/btclog
|
log.go
|
SetLevel
|
func (l *slog) SetLevel(level Level) {
atomic.StoreUint32((*uint32)(&l.lvl), uint32(level))
}
|
go
|
func (l *slog) SetLevel(level Level) {
atomic.StoreUint32((*uint32)(&l.lvl), uint32(level))
}
|
[
"func",
"(",
"l",
"*",
"slog",
")",
"SetLevel",
"(",
"level",
"Level",
")",
"{",
"atomic",
".",
"StoreUint32",
"(",
"(",
"*",
"uint32",
")",
"(",
"&",
"l",
".",
"lvl",
")",
",",
"uint32",
"(",
"level",
")",
")",
"\n",
"}"
] |
// SetLevel changes the logging level to the passed level.
//
// This is part of the Logger interface implementation.
|
[
"SetLevel",
"changes",
"the",
"logging",
"level",
"to",
"the",
"passed",
"level",
".",
"This",
"is",
"part",
"of",
"the",
"Logger",
"interface",
"implementation",
"."
] |
84c8d2346e9fc8c7b947e243b9c24e6df9fd206a
|
https://github.com/btcsuite/btclog/blob/84c8d2346e9fc8c7b947e243b9c24e6df9fd206a/log.go#L471-L473
|
test
|
qor/roles
|
permission.go
|
Concat
|
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
|
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
}
|
[
"func",
"(",
"permission",
"*",
"Permission",
")",
"Concat",
"(",
"newPermission",
"*",
"Permission",
")",
"*",
"Permission",
"{",
"var",
"result",
"=",
"Permission",
"{",
"Role",
":",
"Global",
",",
"AllowedRoles",
":",
"map",
"[",
"PermissionMode",
"]",
"[",
"]",
"string",
"{",
"}",
",",
"DeniedRoles",
":",
"map",
"[",
"PermissionMode",
"]",
"[",
"]",
"string",
"{",
"}",
",",
"}",
"\n",
"var",
"appendRoles",
"=",
"func",
"(",
"p",
"*",
"Permission",
")",
"{",
"if",
"p",
"!=",
"nil",
"{",
"result",
".",
"Role",
"=",
"p",
".",
"Role",
"\n",
"for",
"mode",
",",
"roles",
":=",
"range",
"p",
".",
"DeniedRoles",
"{",
"result",
".",
"DeniedRoles",
"[",
"mode",
"]",
"=",
"append",
"(",
"result",
".",
"DeniedRoles",
"[",
"mode",
"]",
",",
"roles",
"...",
")",
"\n",
"}",
"\n",
"for",
"mode",
",",
"roles",
":=",
"range",
"p",
".",
"AllowedRoles",
"{",
"result",
".",
"AllowedRoles",
"[",
"mode",
"]",
"=",
"append",
"(",
"result",
".",
"AllowedRoles",
"[",
"mode",
"]",
",",
"roles",
"...",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"appendRoles",
"(",
"newPermission",
")",
"\n",
"appendRoles",
"(",
"permission",
")",
"\n",
"return",
"&",
"result",
"\n",
"}"
] |
// Concat concat two permissions into a new one
|
[
"Concat",
"concat",
"two",
"permissions",
"into",
"a",
"new",
"one"
] |
d6375609fe3e5da46ad3a574fae244fb633e79c1
|
https://github.com/qor/roles/blob/d6375609fe3e5da46ad3a574fae244fb633e79c1/permission.go#L50-L74
|
test
|
qor/roles
|
permission.go
|
HasPermission
|
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
|
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
}
|
[
"func",
"(",
"permission",
"Permission",
")",
"HasPermission",
"(",
"mode",
"PermissionMode",
",",
"roles",
"...",
"interface",
"{",
"}",
")",
"bool",
"{",
"var",
"roleNames",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"role",
":=",
"range",
"roles",
"{",
"if",
"r",
",",
"ok",
":=",
"role",
".",
"(",
"string",
")",
";",
"ok",
"{",
"roleNames",
"=",
"append",
"(",
"roleNames",
",",
"r",
")",
"\n",
"}",
"else",
"if",
"roler",
",",
"ok",
":=",
"role",
".",
"(",
"Roler",
")",
";",
"ok",
"{",
"roleNames",
"=",
"append",
"(",
"roleNames",
",",
"roler",
".",
"GetRoles",
"(",
")",
"...",
")",
"\n",
"}",
"else",
"{",
"fmt",
".",
"Printf",
"(",
"\"invalid role %#v\\n\"",
",",
"\\n",
")",
"\n",
"role",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"if",
"len",
"(",
"permission",
".",
"DeniedRoles",
")",
"!=",
"0",
"{",
"if",
"DeniedRoles",
":=",
"permission",
".",
"DeniedRoles",
"[",
"mode",
"]",
";",
"DeniedRoles",
"!=",
"nil",
"{",
"if",
"includeRoles",
"(",
"DeniedRoles",
",",
"roleNames",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"permission",
".",
"AllowedRoles",
")",
"==",
"0",
"{",
"return",
"true",
"\n",
"}",
"\n",
"if",
"AllowedRoles",
":=",
"permission",
".",
"AllowedRoles",
"[",
"mode",
"]",
";",
"AllowedRoles",
"!=",
"nil",
"{",
"if",
"includeRoles",
"(",
"AllowedRoles",
",",
"roleNames",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// HasPermission check roles has permission for mode or not
|
[
"HasPermission",
"check",
"roles",
"has",
"permission",
"for",
"mode",
"or",
"not"
] |
d6375609fe3e5da46ad3a574fae244fb633e79c1
|
https://github.com/qor/roles/blob/d6375609fe3e5da46ad3a574fae244fb633e79c1/permission.go#L103-L136
|
test
|
qor/roles
|
permissioner.go
|
ConcatPermissioner
|
func ConcatPermissioner(ps ...Permissioner) Permissioner {
var newPS []Permissioner
for _, p := range ps {
if p != nil {
newPS = append(newPS, p)
}
}
return permissioners(newPS)
}
|
go
|
func ConcatPermissioner(ps ...Permissioner) Permissioner {
var newPS []Permissioner
for _, p := range ps {
if p != nil {
newPS = append(newPS, p)
}
}
return permissioners(newPS)
}
|
[
"func",
"ConcatPermissioner",
"(",
"ps",
"...",
"Permissioner",
")",
"Permissioner",
"{",
"var",
"newPS",
"[",
"]",
"Permissioner",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"ps",
"{",
"if",
"p",
"!=",
"nil",
"{",
"newPS",
"=",
"append",
"(",
"newPS",
",",
"p",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"permissioners",
"(",
"newPS",
")",
"\n",
"}"
] |
// ConcatPermissioner concat permissioner
|
[
"ConcatPermissioner",
"concat",
"permissioner"
] |
d6375609fe3e5da46ad3a574fae244fb633e79c1
|
https://github.com/qor/roles/blob/d6375609fe3e5da46ad3a574fae244fb633e79c1/permissioner.go#L9-L17
|
test
|
qor/roles
|
permissioner.go
|
HasPermission
|
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
|
func (ps permissioners) HasPermission(mode PermissionMode, roles ...interface{}) bool {
for _, p := range ps {
if p != nil && !p.HasPermission(mode, roles) {
return false
}
}
return true
}
|
[
"func",
"(",
"ps",
"permissioners",
")",
"HasPermission",
"(",
"mode",
"PermissionMode",
",",
"roles",
"...",
"interface",
"{",
"}",
")",
"bool",
"{",
"for",
"_",
",",
"p",
":=",
"range",
"ps",
"{",
"if",
"p",
"!=",
"nil",
"&&",
"!",
"p",
".",
"HasPermission",
"(",
"mode",
",",
"roles",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] |
// HasPermission check has permission for permissioners or not
|
[
"HasPermission",
"check",
"has",
"permission",
"for",
"permissioners",
"or",
"not"
] |
d6375609fe3e5da46ad3a574fae244fb633e79c1
|
https://github.com/qor/roles/blob/d6375609fe3e5da46ad3a574fae244fb633e79c1/permissioner.go#L22-L30
|
test
|
qor/roles
|
role.go
|
Register
|
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
|
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
}
|
[
"func",
"(",
"role",
"*",
"Role",
")",
"Register",
"(",
"name",
"string",
",",
"fc",
"Checker",
")",
"{",
"if",
"role",
".",
"definitions",
"==",
"nil",
"{",
"role",
".",
"definitions",
"=",
"map",
"[",
"string",
"]",
"Checker",
"{",
"}",
"\n",
"}",
"\n",
"definition",
":=",
"role",
".",
"definitions",
"[",
"name",
"]",
"\n",
"if",
"definition",
"!=",
"nil",
"{",
"fmt",
".",
"Printf",
"(",
"\"Role `%v` already defined, overwrited it!\\n\"",
",",
"\\n",
")",
"\n",
"}",
"\n",
"name",
"\n",
"}"
] |
// Register register role with conditions
|
[
"Register",
"register",
"role",
"with",
"conditions"
] |
d6375609fe3e5da46ad3a574fae244fb633e79c1
|
https://github.com/qor/roles/blob/d6375609fe3e5da46ad3a574fae244fb633e79c1/role.go#L27-L37
|
test
|
qor/roles
|
role.go
|
NewPermission
|
func (role *Role) NewPermission() *Permission {
return &Permission{
Role: role,
AllowedRoles: map[PermissionMode][]string{},
DeniedRoles: map[PermissionMode][]string{},
}
}
|
go
|
func (role *Role) NewPermission() *Permission {
return &Permission{
Role: role,
AllowedRoles: map[PermissionMode][]string{},
DeniedRoles: map[PermissionMode][]string{},
}
}
|
[
"func",
"(",
"role",
"*",
"Role",
")",
"NewPermission",
"(",
")",
"*",
"Permission",
"{",
"return",
"&",
"Permission",
"{",
"Role",
":",
"role",
",",
"AllowedRoles",
":",
"map",
"[",
"PermissionMode",
"]",
"[",
"]",
"string",
"{",
"}",
",",
"DeniedRoles",
":",
"map",
"[",
"PermissionMode",
"]",
"[",
"]",
"string",
"{",
"}",
",",
"}",
"\n",
"}"
] |
// NewPermission initialize permission
|
[
"NewPermission",
"initialize",
"permission"
] |
d6375609fe3e5da46ad3a574fae244fb633e79c1
|
https://github.com/qor/roles/blob/d6375609fe3e5da46ad3a574fae244fb633e79c1/role.go#L40-L46
|
test
|
qor/roles
|
role.go
|
Get
|
func (role *Role) Get(name string) (Checker, bool) {
fc, ok := role.definitions[name]
return fc, ok
}
|
go
|
func (role *Role) Get(name string) (Checker, bool) {
fc, ok := role.definitions[name]
return fc, ok
}
|
[
"func",
"(",
"role",
"*",
"Role",
")",
"Get",
"(",
"name",
"string",
")",
"(",
"Checker",
",",
"bool",
")",
"{",
"fc",
",",
"ok",
":=",
"role",
".",
"definitions",
"[",
"name",
"]",
"\n",
"return",
"fc",
",",
"ok",
"\n",
"}"
] |
// Get role defination
|
[
"Get",
"role",
"defination"
] |
d6375609fe3e5da46ad3a574fae244fb633e79c1
|
https://github.com/qor/roles/blob/d6375609fe3e5da46ad3a574fae244fb633e79c1/role.go#L59-L62
|
test
|
golang/debug
|
internal/gocore/object.go
|
isPtrFromHeap
|
func (p *Process) isPtrFromHeap(a core.Address) bool {
return p.findHeapInfo(a).IsPtr(a, p.proc.PtrSize())
}
|
go
|
func (p *Process) isPtrFromHeap(a core.Address) bool {
return p.findHeapInfo(a).IsPtr(a, p.proc.PtrSize())
}
|
[
"func",
"(",
"p",
"*",
"Process",
")",
"isPtrFromHeap",
"(",
"a",
"core",
".",
"Address",
")",
"bool",
"{",
"return",
"p",
".",
"findHeapInfo",
"(",
"a",
")",
".",
"IsPtr",
"(",
"a",
",",
"p",
".",
"proc",
".",
"PtrSize",
"(",
")",
")",
"\n",
"}"
] |
// isPtrFromHeap reports whether the inferior at address a contains a pointer.
// a must be somewhere in the heap.
|
[
"isPtrFromHeap",
"reports",
"whether",
"the",
"inferior",
"at",
"address",
"a",
"contains",
"a",
"pointer",
".",
"a",
"must",
"be",
"somewhere",
"in",
"the",
"heap",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/object.go#L133-L135
|
test
|
golang/debug
|
internal/gocore/object.go
|
IsPtr
|
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
|
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
}
|
[
"func",
"(",
"p",
"*",
"Process",
")",
"IsPtr",
"(",
"a",
"core",
".",
"Address",
")",
"bool",
"{",
"h",
":=",
"p",
".",
"findHeapInfo",
"(",
"a",
")",
"\n",
"if",
"h",
"!=",
"nil",
"{",
"return",
"h",
".",
"IsPtr",
"(",
"a",
",",
"p",
".",
"proc",
".",
"PtrSize",
"(",
")",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"m",
":=",
"range",
"p",
".",
"modules",
"{",
"for",
"_",
",",
"s",
":=",
"range",
"[",
"2",
"]",
"string",
"{",
"\"data\"",
",",
"\"bss\"",
"}",
"{",
"min",
":=",
"core",
".",
"Address",
"(",
"m",
".",
"r",
".",
"Field",
"(",
"s",
")",
".",
"Uintptr",
"(",
")",
")",
"\n",
"max",
":=",
"core",
".",
"Address",
"(",
"m",
".",
"r",
".",
"Field",
"(",
"\"e\"",
"+",
"s",
")",
".",
"Uintptr",
"(",
")",
")",
"\n",
"if",
"a",
"<",
"min",
"||",
"a",
">=",
"max",
"{",
"continue",
"\n",
"}",
"\n",
"gc",
":=",
"m",
".",
"r",
".",
"Field",
"(",
"\"gc\"",
"+",
"s",
"+",
"\"mask\"",
")",
".",
"Field",
"(",
"\"bytedata\"",
")",
".",
"Address",
"(",
")",
"\n",
"i",
":=",
"a",
".",
"Sub",
"(",
"min",
")",
"\n",
"return",
"p",
".",
"proc",
".",
"ReadUint8",
"(",
"gc",
".",
"Add",
"(",
"i",
"/",
"8",
")",
")",
">>",
"uint",
"(",
"i",
"%",
"8",
")",
"!=",
"0",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// IsPtr reports whether the inferior at address a contains a pointer.
|
[
"IsPtr",
"reports",
"whether",
"the",
"inferior",
"at",
"address",
"a",
"contains",
"a",
"pointer",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/object.go#L138-L159
|
test
|
golang/debug
|
internal/gocore/object.go
|
FindObject
|
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
|
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)
}
|
[
"func",
"(",
"p",
"*",
"Process",
")",
"FindObject",
"(",
"a",
"core",
".",
"Address",
")",
"(",
"Object",
",",
"int64",
")",
"{",
"h",
":=",
"p",
".",
"findHeapInfo",
"(",
"a",
")",
"\n",
"if",
"h",
"==",
"nil",
"{",
"return",
"0",
",",
"0",
"\n",
"}",
"\n",
"x",
":=",
"h",
".",
"base",
".",
"Add",
"(",
"a",
".",
"Sub",
"(",
"h",
".",
"base",
")",
"/",
"h",
".",
"size",
"*",
"h",
".",
"size",
")",
"\n",
"h",
"=",
"p",
".",
"findHeapInfo",
"(",
"x",
")",
"\n",
"if",
"h",
".",
"mark",
">>",
"(",
"uint64",
"(",
"x",
")",
"%",
"heapInfoSize",
"/",
"8",
")",
"&",
"1",
"==",
"0",
"{",
"return",
"0",
",",
"0",
"\n",
"}",
"\n",
"return",
"Object",
"(",
"x",
")",
",",
"a",
".",
"Sub",
"(",
"x",
")",
"\n",
"}"
] |
// FindObject finds the object containing a. Returns that object and the offset within
// that object to which a points.
// Returns 0,0 if a doesn't point to a live heap object.
|
[
"FindObject",
"finds",
"the",
"object",
"containing",
"a",
".",
"Returns",
"that",
"object",
"and",
"the",
"offset",
"within",
"that",
"object",
"to",
"which",
"a",
"points",
".",
"Returns",
"0",
"0",
"if",
"a",
"doesn",
"t",
"point",
"to",
"a",
"live",
"heap",
"object",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/object.go#L164-L179
|
test
|
golang/debug
|
internal/gocore/object.go
|
ForEachObject
|
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
|
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
}
}
}
}
}
|
[
"func",
"(",
"p",
"*",
"Process",
")",
"ForEachObject",
"(",
"fn",
"func",
"(",
"x",
"Object",
")",
"bool",
")",
"{",
"for",
"_",
",",
"k",
":=",
"range",
"p",
".",
"pages",
"{",
"pt",
":=",
"p",
".",
"pageTable",
"[",
"k",
"]",
"\n",
"for",
"i",
":=",
"range",
"pt",
"{",
"h",
":=",
"&",
"pt",
"[",
"i",
"]",
"\n",
"m",
":=",
"h",
".",
"mark",
"\n",
"for",
"m",
"!=",
"0",
"{",
"j",
":=",
"bits",
".",
"TrailingZeros64",
"(",
"m",
")",
"\n",
"m",
"&=",
"m",
"-",
"1",
"\n",
"x",
":=",
"Object",
"(",
"k",
")",
"*",
"pageTableSize",
"*",
"heapInfoSize",
"+",
"Object",
"(",
"i",
")",
"*",
"heapInfoSize",
"+",
"Object",
"(",
"j",
")",
"*",
"8",
"\n",
"if",
"!",
"fn",
"(",
"x",
")",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// ForEachObject calls fn with each object in the Go heap.
// If fn returns false, ForEachObject returns immediately.
|
[
"ForEachObject",
"calls",
"fn",
"with",
"each",
"object",
"in",
"the",
"Go",
"heap",
".",
"If",
"fn",
"returns",
"false",
"ForEachObject",
"returns",
"immediately",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/object.go#L192-L208
|
test
|
golang/debug
|
internal/gocore/object.go
|
ForEachRoot
|
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
|
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
}
}
}
}
}
|
[
"func",
"(",
"p",
"*",
"Process",
")",
"ForEachRoot",
"(",
"fn",
"func",
"(",
"r",
"*",
"Root",
")",
"bool",
")",
"{",
"for",
"_",
",",
"r",
":=",
"range",
"p",
".",
"globals",
"{",
"if",
"!",
"fn",
"(",
"r",
")",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"g",
":=",
"range",
"p",
".",
"goroutines",
"{",
"for",
"_",
",",
"f",
":=",
"range",
"g",
".",
"frames",
"{",
"for",
"_",
",",
"r",
":=",
"range",
"f",
".",
"roots",
"{",
"if",
"!",
"fn",
"(",
"r",
")",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// ForEachRoot calls fn with each garbage collection root.
// If fn returns false, ForEachRoot returns immediately.
|
[
"ForEachRoot",
"calls",
"fn",
"with",
"each",
"garbage",
"collection",
"root",
".",
"If",
"fn",
"returns",
"false",
"ForEachRoot",
"returns",
"immediately",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/object.go#L212-L227
|
test
|
golang/debug
|
internal/gocore/object.go
|
Addr
|
func (p *Process) Addr(x Object) core.Address {
return core.Address(x)
}
|
go
|
func (p *Process) Addr(x Object) core.Address {
return core.Address(x)
}
|
[
"func",
"(",
"p",
"*",
"Process",
")",
"Addr",
"(",
"x",
"Object",
")",
"core",
".",
"Address",
"{",
"return",
"core",
".",
"Address",
"(",
"x",
")",
"\n",
"}"
] |
// Addr returns the starting address of x.
|
[
"Addr",
"returns",
"the",
"starting",
"address",
"of",
"x",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/object.go#L230-L232
|
test
|
golang/debug
|
internal/gocore/object.go
|
Size
|
func (p *Process) Size(x Object) int64 {
return p.findHeapInfo(core.Address(x)).size
}
|
go
|
func (p *Process) Size(x Object) int64 {
return p.findHeapInfo(core.Address(x)).size
}
|
[
"func",
"(",
"p",
"*",
"Process",
")",
"Size",
"(",
"x",
"Object",
")",
"int64",
"{",
"return",
"p",
".",
"findHeapInfo",
"(",
"core",
".",
"Address",
"(",
"x",
")",
")",
".",
"size",
"\n",
"}"
] |
// Size returns the size of x in bytes.
|
[
"Size",
"returns",
"the",
"size",
"of",
"x",
"in",
"bytes",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/object.go#L235-L237
|
test
|
golang/debug
|
internal/gocore/object.go
|
Type
|
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
|
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
}
|
[
"func",
"(",
"p",
"*",
"Process",
")",
"Type",
"(",
"x",
"Object",
")",
"(",
"*",
"Type",
",",
"int64",
")",
"{",
"p",
".",
"typeHeap",
"(",
")",
"\n",
"i",
",",
"_",
":=",
"p",
".",
"findObjectIndex",
"(",
"core",
".",
"Address",
"(",
"x",
")",
")",
"\n",
"return",
"p",
".",
"types",
"[",
"i",
"]",
".",
"t",
",",
"p",
".",
"types",
"[",
"i",
"]",
".",
"r",
"\n",
"}"
] |
// Type returns the type and repeat count for the object x.
// x contains at least repeat copies of the returned type.
|
[
"Type",
"returns",
"the",
"type",
"and",
"repeat",
"count",
"for",
"the",
"object",
"x",
".",
"x",
"contains",
"at",
"least",
"repeat",
"copies",
"of",
"the",
"returned",
"type",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/object.go#L241-L246
|
test
|
golang/debug
|
internal/gocore/object.go
|
ForEachRootPtr
|
func (p *Process) ForEachRootPtr(r *Root, fn func(int64, Object, int64) bool) {
edges1(p, r, 0, r.Type, fn)
}
|
go
|
func (p *Process) ForEachRootPtr(r *Root, fn func(int64, Object, int64) bool) {
edges1(p, r, 0, r.Type, fn)
}
|
[
"func",
"(",
"p",
"*",
"Process",
")",
"ForEachRootPtr",
"(",
"r",
"*",
"Root",
",",
"fn",
"func",
"(",
"int64",
",",
"Object",
",",
"int64",
")",
"bool",
")",
"{",
"edges1",
"(",
"p",
",",
"r",
",",
"0",
",",
"r",
".",
"Type",
",",
"fn",
")",
"\n",
"}"
] |
// ForEachRootPtr behaves like ForEachPtr but it starts with a Root instead of an Object.
|
[
"ForEachRootPtr",
"behaves",
"like",
"ForEachPtr",
"but",
"it",
"starts",
"with",
"a",
"Root",
"instead",
"of",
"an",
"Object",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/object.go#L274-L276
|
test
|
golang/debug
|
internal/gocore/object.go
|
edges1
|
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
|
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
}
|
[
"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",
":",
"case",
"KindIface",
",",
"KindEface",
":",
"a",
":=",
"r",
".",
"Addr",
".",
"Add",
"(",
"off",
")",
"\n",
"if",
"r",
".",
"Frame",
"==",
"nil",
"||",
"r",
".",
"Frame",
".",
"Live",
"[",
"a",
"]",
"{",
"dst",
",",
"off2",
":=",
"p",
".",
"FindObject",
"(",
"p",
".",
"proc",
".",
"ReadPtr",
"(",
"a",
")",
")",
"\n",
"if",
"dst",
"!=",
"0",
"{",
"if",
"!",
"fn",
"(",
"off",
",",
"dst",
",",
"off2",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"off",
"+=",
"p",
".",
"proc",
".",
"PtrSize",
"(",
")",
"\n",
"fallthrough",
"\n",
"case",
"KindPtr",
",",
"KindString",
",",
"KindSlice",
",",
"KindFunc",
":",
"a",
":=",
"r",
".",
"Addr",
".",
"Add",
"(",
"off",
")",
"\n",
"if",
"r",
".",
"Frame",
"==",
"nil",
"||",
"r",
".",
"Frame",
".",
"Live",
"[",
"a",
"]",
"{",
"dst",
",",
"off2",
":=",
"p",
".",
"FindObject",
"(",
"p",
".",
"proc",
".",
"ReadPtr",
"(",
"a",
")",
")",
"\n",
"if",
"dst",
"!=",
"0",
"{",
"if",
"!",
"fn",
"(",
"off",
",",
"dst",
",",
"off2",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"case",
"KindArray",
":",
"s",
":=",
"t",
".",
"Elem",
".",
"Size",
"\n",
"for",
"i",
":=",
"int64",
"(",
"0",
")",
";",
"i",
"<",
"t",
".",
"Count",
";",
"i",
"++",
"{",
"if",
"!",
"edges1",
"(",
"p",
",",
"r",
",",
"off",
"+",
"i",
"*",
"s",
",",
"t",
".",
"Elem",
",",
"fn",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"case",
"KindStruct",
":",
"for",
"_",
",",
"f",
":=",
"range",
"t",
".",
"Fields",
"{",
"if",
"!",
"edges1",
"(",
"p",
",",
"r",
",",
"off",
"+",
"f",
".",
"Off",
",",
"f",
".",
"Type",
",",
"fn",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] |
// edges1 calls fn for the edges found in an object of type t living at offset off in the root r.
// If fn returns false, return immediately with false.
|
[
"edges1",
"calls",
"fn",
"for",
"the",
"edges",
"found",
"in",
"an",
"object",
"of",
"type",
"t",
"living",
"at",
"offset",
"off",
"in",
"the",
"root",
"r",
".",
"If",
"fn",
"returns",
"false",
"return",
"immediately",
"with",
"false",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/object.go#L280-L325
|
test
|
golang/debug
|
internal/gocore/object.go
|
setHeapPtr
|
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
|
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)
}
|
[
"func",
"(",
"p",
"*",
"Process",
")",
"setHeapPtr",
"(",
"a",
"core",
".",
"Address",
")",
"{",
"h",
":=",
"p",
".",
"allocHeapInfo",
"(",
"a",
")",
"\n",
"if",
"p",
".",
"proc",
".",
"PtrSize",
"(",
")",
"==",
"8",
"{",
"i",
":=",
"uint",
"(",
"a",
"%",
"heapInfoSize",
")",
"/",
"8",
"\n",
"h",
".",
"ptr",
"[",
"0",
"]",
"|=",
"uint64",
"(",
"1",
")",
"<<",
"i",
"\n",
"return",
"\n",
"}",
"\n",
"i",
":=",
"a",
"%",
"heapInfoSize",
"/",
"4",
"\n",
"h",
".",
"ptr",
"[",
"i",
"/",
"64",
"]",
"|=",
"uint64",
"(",
"1",
")",
"<<",
"(",
"i",
"%",
"64",
")",
"\n",
"}"
] |
// setHeapPtr records that the memory at heap address a contains a pointer.
|
[
"setHeapPtr",
"records",
"that",
"the",
"memory",
"at",
"heap",
"address",
"a",
"contains",
"a",
"pointer",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/object.go#L351-L360
|
test
|
golang/debug
|
internal/gocore/object.go
|
findHeapInfo
|
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
|
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
}
|
[
"func",
"(",
"p",
"*",
"Process",
")",
"findHeapInfo",
"(",
"a",
"core",
".",
"Address",
")",
"*",
"heapInfo",
"{",
"k",
":=",
"a",
"/",
"heapInfoSize",
"/",
"pageTableSize",
"\n",
"i",
":=",
"a",
"/",
"heapInfoSize",
"%",
"pageTableSize",
"\n",
"t",
":=",
"p",
".",
"pageTable",
"[",
"k",
"]",
"\n",
"if",
"t",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"h",
":=",
"&",
"t",
"[",
"i",
"]",
"\n",
"if",
"h",
".",
"base",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"h",
"\n",
"}"
] |
// findHeapInfo finds the heapInfo structure for a.
// Returns nil if a is not a heap address.
|
[
"findHeapInfo",
"finds",
"the",
"heapInfo",
"structure",
"for",
"a",
".",
"Returns",
"nil",
"if",
"a",
"is",
"not",
"a",
"heap",
"address",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/object.go#L370-L382
|
test
|
golang/debug
|
internal/gocore/object.go
|
allocHeapInfo
|
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
|
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]
}
|
[
"func",
"(",
"p",
"*",
"Process",
")",
"allocHeapInfo",
"(",
"a",
"core",
".",
"Address",
")",
"*",
"heapInfo",
"{",
"k",
":=",
"a",
"/",
"heapInfoSize",
"/",
"pageTableSize",
"\n",
"i",
":=",
"a",
"/",
"heapInfoSize",
"%",
"pageTableSize",
"\n",
"t",
":=",
"p",
".",
"pageTable",
"[",
"k",
"]",
"\n",
"if",
"t",
"==",
"nil",
"{",
"t",
"=",
"new",
"(",
"pageTableEntry",
")",
"\n",
"for",
"j",
":=",
"0",
";",
"j",
"<",
"pageTableSize",
";",
"j",
"++",
"{",
"t",
"[",
"j",
"]",
".",
"firstIdx",
"=",
"-",
"1",
"\n",
"}",
"\n",
"p",
".",
"pageTable",
"[",
"k",
"]",
"=",
"t",
"\n",
"p",
".",
"pages",
"=",
"append",
"(",
"p",
".",
"pages",
",",
"k",
")",
"\n",
"}",
"\n",
"return",
"&",
"t",
"[",
"i",
"]",
"\n",
"}"
] |
// Same as findHeapInfo, but allocates the heapInfo if it
// hasn't been allocated yet.
|
[
"Same",
"as",
"findHeapInfo",
"but",
"allocates",
"the",
"heapInfo",
"if",
"it",
"hasn",
"t",
"been",
"allocated",
"yet",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/object.go#L386-L399
|
test
|
golang/debug
|
internal/gocore/dwarf.go
|
runtimeName
|
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
|
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())
}
}
|
[
"func",
"runtimeName",
"(",
"dt",
"dwarf",
".",
"Type",
")",
"string",
"{",
"switch",
"x",
":=",
"dt",
".",
"(",
"type",
")",
"{",
"case",
"*",
"dwarf",
".",
"PtrType",
":",
"if",
"_",
",",
"ok",
":=",
"x",
".",
"Type",
".",
"(",
"*",
"dwarf",
".",
"VoidType",
")",
";",
"ok",
"{",
"return",
"\"unsafe.Pointer\"",
"\n",
"}",
"\n",
"return",
"\"*\"",
"+",
"runtimeName",
"(",
"x",
".",
"Type",
")",
"\n",
"case",
"*",
"dwarf",
".",
"ArrayType",
":",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"[%d]%s\"",
",",
"x",
".",
"Count",
",",
"runtimeName",
"(",
"x",
".",
"Type",
")",
")",
"\n",
"case",
"*",
"dwarf",
".",
"StructType",
":",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"x",
".",
"StructName",
",",
"\"struct {\"",
")",
"{",
"return",
"stripPackagePath",
"(",
"x",
".",
"StructName",
")",
"\n",
"}",
"\n",
"var",
"anon",
"[",
"]",
"bool",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"strings",
".",
"Split",
"(",
"x",
".",
"StructName",
"[",
"8",
":",
"len",
"(",
"x",
".",
"StructName",
")",
"-",
"1",
"]",
",",
"\";\"",
")",
"{",
"f",
"=",
"strings",
".",
"TrimSpace",
"(",
"f",
")",
"\n",
"anon",
"=",
"append",
"(",
"anon",
",",
"!",
"strings",
".",
"Contains",
"(",
"f",
",",
"\" \"",
")",
")",
"\n",
"}",
"\n",
"for",
"len",
"(",
"anon",
")",
"<",
"len",
"(",
"x",
".",
"Field",
")",
"{",
"anon",
"=",
"append",
"(",
"anon",
",",
"false",
")",
"\n",
"}",
"\n",
"s",
":=",
"\"struct {\"",
"\n",
"first",
":=",
"true",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"x",
".",
"Field",
"{",
"if",
"!",
"first",
"{",
"s",
"+=",
"\";\"",
"\n",
"}",
"\n",
"name",
":=",
"f",
".",
"Name",
"\n",
"if",
"i",
":=",
"strings",
".",
"Index",
"(",
"name",
",",
"\".\"",
")",
";",
"i",
">=",
"0",
"{",
"name",
"=",
"name",
"[",
"i",
"+",
"1",
":",
"]",
"\n",
"}",
"\n",
"if",
"anon",
"[",
"0",
"]",
"{",
"s",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\" %s\"",
",",
"runtimeName",
"(",
"f",
".",
"Type",
")",
")",
"\n",
"}",
"else",
"{",
"s",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\" %s %s\"",
",",
"name",
",",
"runtimeName",
"(",
"f",
".",
"Type",
")",
")",
"\n",
"}",
"\n",
"first",
"=",
"false",
"\n",
"anon",
"=",
"anon",
"[",
"1",
":",
"]",
"\n",
"}",
"\n",
"s",
"+=",
"\" }\"",
"\n",
"return",
"s",
"\n",
"default",
":",
"return",
"stripPackagePath",
"(",
"dt",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"}"
] |
// Generate the name the runtime uses for a dwarf type. The DWARF generator
// and the runtime use slightly different names for the same underlying type.
|
[
"Generate",
"the",
"name",
"the",
"runtime",
"uses",
"for",
"a",
"dwarf",
"type",
".",
"The",
"DWARF",
"generator",
"and",
"the",
"runtime",
"use",
"slightly",
"different",
"names",
"for",
"the",
"same",
"underlying",
"type",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/dwarf.go#L278-L330
|
test
|
golang/debug
|
internal/gocore/dwarf.go
|
readRuntimeConstants
|
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
|
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)
}
}
|
[
"func",
"(",
"p",
"*",
"Process",
")",
"readRuntimeConstants",
"(",
")",
"{",
"p",
".",
"rtConstants",
"=",
"map",
"[",
"string",
"]",
"int64",
"{",
"}",
"\n",
"m",
":=",
"p",
".",
"rtConstants",
"\n",
"m",
"[",
"\"_MSpanDead\"",
"]",
"=",
"0",
"\n",
"m",
"[",
"\"_MSpanInUse\"",
"]",
"=",
"1",
"\n",
"m",
"[",
"\"_MSpanManual\"",
"]",
"=",
"2",
"\n",
"m",
"[",
"\"_MSpanFree\"",
"]",
"=",
"3",
"\n",
"m",
"[",
"\"_Gidle\"",
"]",
"=",
"0",
"\n",
"m",
"[",
"\"_Grunnable\"",
"]",
"=",
"1",
"\n",
"m",
"[",
"\"_Grunning\"",
"]",
"=",
"2",
"\n",
"m",
"[",
"\"_Gsyscall\"",
"]",
"=",
"3",
"\n",
"m",
"[",
"\"_Gwaiting\"",
"]",
"=",
"4",
"\n",
"m",
"[",
"\"_Gdead\"",
"]",
"=",
"6",
"\n",
"m",
"[",
"\"_Gscan\"",
"]",
"=",
"0x1000",
"\n",
"m",
"[",
"\"_PCDATA_StackMapIndex\"",
"]",
"=",
"0",
"\n",
"m",
"[",
"\"_FUNCDATA_LocalsPointerMaps\"",
"]",
"=",
"1",
"\n",
"m",
"[",
"\"_FUNCDATA_ArgsPointerMaps\"",
"]",
"=",
"0",
"\n",
"m",
"[",
"\"tflagExtraStar\"",
"]",
"=",
"1",
"<<",
"1",
"\n",
"m",
"[",
"\"kindGCProg\"",
"]",
"=",
"1",
"<<",
"6",
"\n",
"m",
"[",
"\"kindDirectIface\"",
"]",
"=",
"1",
"<<",
"5",
"\n",
"m",
"[",
"\"_PageSize\"",
"]",
"=",
"1",
"<<",
"13",
"\n",
"m",
"[",
"\"_KindSpecialFinalizer\"",
"]",
"=",
"1",
"\n",
"d",
",",
"_",
":=",
"p",
".",
"proc",
".",
"DWARF",
"(",
")",
"\n",
"r",
":=",
"d",
".",
"Reader",
"(",
")",
"\n",
"for",
"e",
",",
"err",
":=",
"r",
".",
"Next",
"(",
")",
";",
"e",
"!=",
"nil",
"&&",
"err",
"==",
"nil",
";",
"e",
",",
"err",
"=",
"r",
".",
"Next",
"(",
")",
"{",
"if",
"e",
".",
"Tag",
"!=",
"dwarf",
".",
"TagConstant",
"{",
"continue",
"\n",
"}",
"\n",
"f",
":=",
"e",
".",
"AttrField",
"(",
"dwarf",
".",
"AttrName",
")",
"\n",
"if",
"f",
"==",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"name",
":=",
"f",
".",
"Val",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"name",
",",
"\"runtime.\"",
")",
"{",
"continue",
"\n",
"}",
"\n",
"name",
"=",
"name",
"[",
"8",
":",
"]",
"\n",
"c",
":=",
"e",
".",
"AttrField",
"(",
"dwarf",
".",
"AttrConstValue",
")",
"\n",
"if",
"c",
"==",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"p",
".",
"rtConstants",
"[",
"name",
"]",
"=",
"c",
".",
"Val",
".",
"(",
"int64",
")",
"\n",
"}",
"\n",
"}"
] |
// readRuntimeConstants populates the p.rtConstants map.
|
[
"readRuntimeConstants",
"populates",
"the",
"p",
".",
"rtConstants",
"map",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/dwarf.go#L346-L394
|
test
|
golang/debug
|
internal/gocore/module.go
|
add
|
func (t *funcTab) add(min, max core.Address, f *Func) {
t.entries = append(t.entries, funcTabEntry{min: min, max: max, f: f})
}
|
go
|
func (t *funcTab) add(min, max core.Address, f *Func) {
t.entries = append(t.entries, funcTabEntry{min: min, max: max, f: f})
}
|
[
"func",
"(",
"t",
"*",
"funcTab",
")",
"add",
"(",
"min",
",",
"max",
"core",
".",
"Address",
",",
"f",
"*",
"Func",
")",
"{",
"t",
".",
"entries",
"=",
"append",
"(",
"t",
".",
"entries",
",",
"funcTabEntry",
"{",
"min",
":",
"min",
",",
"max",
":",
"max",
",",
"f",
":",
"f",
"}",
")",
"\n",
"}"
] |
// add records that PCs in the range [min,max) map to function f.
|
[
"add",
"records",
"that",
"PCs",
"in",
"the",
"range",
"[",
"min",
"max",
")",
"map",
"to",
"function",
"f",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/module.go#L98-L100
|
test
|
golang/debug
|
internal/gocore/module.go
|
sort
|
func (t *funcTab) sort() {
sort.Slice(t.entries, func(i, j int) bool {
return t.entries[i].min < t.entries[j].min
})
}
|
go
|
func (t *funcTab) sort() {
sort.Slice(t.entries, func(i, j int) bool {
return t.entries[i].min < t.entries[j].min
})
}
|
[
"func",
"(",
"t",
"*",
"funcTab",
")",
"sort",
"(",
")",
"{",
"sort",
".",
"Slice",
"(",
"t",
".",
"entries",
",",
"func",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"t",
".",
"entries",
"[",
"i",
"]",
".",
"min",
"<",
"t",
".",
"entries",
"[",
"j",
"]",
".",
"min",
"\n",
"}",
")",
"\n",
"}"
] |
// sort must be called after all the adds, but before any find.
|
[
"sort",
"must",
"be",
"called",
"after",
"all",
"the",
"adds",
"but",
"before",
"any",
"find",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/module.go#L103-L107
|
test
|
golang/debug
|
internal/gocore/module.go
|
find
|
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
|
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
}
|
[
"func",
"(",
"t",
"*",
"funcTab",
")",
"find",
"(",
"pc",
"core",
".",
"Address",
")",
"*",
"Func",
"{",
"n",
":=",
"sort",
".",
"Search",
"(",
"len",
"(",
"t",
".",
"entries",
")",
",",
"func",
"(",
"i",
"int",
")",
"bool",
"{",
"return",
"t",
".",
"entries",
"[",
"i",
"]",
".",
"max",
">",
"pc",
"\n",
"}",
")",
"\n",
"if",
"n",
"==",
"len",
"(",
"t",
".",
"entries",
")",
"||",
"pc",
"<",
"t",
".",
"entries",
"[",
"n",
"]",
".",
"min",
"||",
"pc",
">=",
"t",
".",
"entries",
"[",
"n",
"]",
".",
"max",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"t",
".",
"entries",
"[",
"n",
"]",
".",
"f",
"\n",
"}"
] |
// Finds a Func for the given address. Sort must have been called already.
|
[
"Finds",
"a",
"Func",
"for",
"the",
"given",
"address",
".",
"Sort",
"must",
"have",
"been",
"called",
"already",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/module.go#L110-L118
|
test
|
golang/debug
|
internal/gocore/module.go
|
read
|
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
|
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
}
}
|
[
"func",
"(",
"t",
"*",
"pcTab",
")",
"read",
"(",
"core",
"*",
"core",
".",
"Process",
",",
"data",
"core",
".",
"Address",
")",
"{",
"var",
"pcQuantum",
"int64",
"\n",
"switch",
"core",
".",
"Arch",
"(",
")",
"{",
"case",
"\"386\"",
",",
"\"amd64\"",
",",
"\"amd64p32\"",
":",
"pcQuantum",
"=",
"1",
"\n",
"case",
"\"s390x\"",
":",
"pcQuantum",
"=",
"2",
"\n",
"case",
"\"arm\"",
",",
"\"arm64\"",
",",
"\"mips\"",
",",
"\"mipsle\"",
",",
"\"mips64\"",
",",
"\"mips64le\"",
",",
"\"ppc64\"",
",",
"\"ppc64le\"",
":",
"pcQuantum",
"=",
"4",
"\n",
"default",
":",
"panic",
"(",
"\"unknown architecture \"",
"+",
"core",
".",
"Arch",
"(",
")",
")",
"\n",
"}",
"\n",
"val",
":=",
"int64",
"(",
"-",
"1",
")",
"\n",
"first",
":=",
"true",
"\n",
"for",
"{",
"v",
",",
"n",
":=",
"readVarint",
"(",
"core",
",",
"data",
")",
"\n",
"if",
"v",
"==",
"0",
"&&",
"!",
"first",
"{",
"return",
"\n",
"}",
"\n",
"data",
"=",
"data",
".",
"Add",
"(",
"n",
")",
"\n",
"if",
"v",
"&",
"1",
"!=",
"0",
"{",
"val",
"+=",
"^",
"(",
"v",
">>",
"1",
")",
"\n",
"}",
"else",
"{",
"val",
"+=",
"v",
">>",
"1",
"\n",
"}",
"\n",
"v",
",",
"n",
"=",
"readVarint",
"(",
"core",
",",
"data",
")",
"\n",
"data",
"=",
"data",
".",
"Add",
"(",
"n",
")",
"\n",
"t",
".",
"entries",
"=",
"append",
"(",
"t",
".",
"entries",
",",
"pcTabEntry",
"{",
"bytes",
":",
"v",
"*",
"pcQuantum",
",",
"val",
":",
"val",
"}",
")",
"\n",
"first",
"=",
"false",
"\n",
"}",
"\n",
"}"
] |
// read parses a pctab from the core file at address data.
|
[
"read",
"parses",
"a",
"pctab",
"from",
"the",
"core",
"file",
"at",
"address",
"data",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/module.go#L131-L164
|
test
|
golang/debug
|
internal/gocore/module.go
|
readVarint
|
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
|
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
}
}
}
|
[
"func",
"readVarint",
"(",
"core",
"*",
"core",
".",
"Process",
",",
"a",
"core",
".",
"Address",
")",
"(",
"val",
",",
"n",
"int64",
")",
"{",
"for",
"{",
"b",
":=",
"core",
".",
"ReadUint8",
"(",
"a",
")",
"\n",
"val",
"|=",
"int64",
"(",
"b",
"&",
"0x7f",
")",
"<<",
"uint",
"(",
"n",
"*",
"7",
")",
"\n",
"n",
"++",
"\n",
"a",
"++",
"\n",
"if",
"b",
"&",
"0x80",
"==",
"0",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// readVarint reads a varint from the core file.
// val is the value, n is the number of bytes consumed.
|
[
"readVarint",
"reads",
"a",
"varint",
"from",
"the",
"core",
"file",
".",
"val",
"is",
"the",
"value",
"n",
"is",
"the",
"number",
"of",
"bytes",
"consumed",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/module.go#L182-L192
|
test
|
golang/debug
|
cmd/viewcore/main.go
|
useLine
|
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
|
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
}
|
[
"func",
"useLine",
"(",
"c",
"*",
"cobra",
".",
"Command",
")",
"string",
"{",
"var",
"useline",
"string",
"\n",
"if",
"c",
".",
"HasParent",
"(",
")",
"{",
"useline",
"=",
"commandPath",
"(",
"c",
".",
"Parent",
"(",
")",
")",
"+",
"\" \"",
"+",
"c",
".",
"Use",
"\n",
"}",
"else",
"{",
"useline",
"=",
"c",
".",
"Use",
"\n",
"}",
"\n",
"if",
"c",
".",
"DisableFlagsInUseLine",
"{",
"return",
"useline",
"\n",
"}",
"\n",
"if",
"c",
".",
"HasAvailableFlags",
"(",
")",
"&&",
"!",
"strings",
".",
"Contains",
"(",
"useline",
",",
"\"[flags]\"",
")",
"{",
"useline",
"+=",
"\" [flags]\"",
"\n",
"}",
"\n",
"return",
"useline",
"\n",
"}"
] |
// useLine is like cobra.Command.UseLine but tweaked to use commandPath.
|
[
"useLine",
"is",
"like",
"cobra",
".",
"Command",
".",
"UseLine",
"but",
"tweaked",
"to",
"use",
"commandPath",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/cmd/viewcore/main.go#L180-L194
|
test
|
golang/debug
|
cmd/viewcore/main.go
|
commandPath
|
func commandPath(c *cobra.Command) string {
if c.HasParent() {
return commandPath(c) + " " + c.Name()
}
return c.Use
}
|
go
|
func commandPath(c *cobra.Command) string {
if c.HasParent() {
return commandPath(c) + " " + c.Name()
}
return c.Use
}
|
[
"func",
"commandPath",
"(",
"c",
"*",
"cobra",
".",
"Command",
")",
"string",
"{",
"if",
"c",
".",
"HasParent",
"(",
")",
"{",
"return",
"commandPath",
"(",
"c",
")",
"+",
"\" \"",
"+",
"c",
".",
"Name",
"(",
")",
"\n",
"}",
"\n",
"return",
"c",
".",
"Use",
"\n",
"}"
] |
// commandPath is like cobra.Command.CommandPath but tweaked to
// use c.Use instead of c.Name for the root command so it works
// with viewcore's unusual command structure.
|
[
"commandPath",
"is",
"like",
"cobra",
".",
"Command",
".",
"CommandPath",
"but",
"tweaked",
"to",
"use",
"c",
".",
"Use",
"instead",
"of",
"c",
".",
"Name",
"for",
"the",
"root",
"command",
"so",
"it",
"works",
"with",
"viewcore",
"s",
"unusual",
"command",
"structure",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/cmd/viewcore/main.go#L199-L204
|
test
|
golang/debug
|
cmd/viewcore/main.go
|
readCore
|
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
|
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
}
|
[
"func",
"readCore",
"(",
")",
"(",
"*",
"core",
".",
"Process",
",",
"*",
"gocore",
".",
"Process",
",",
"error",
")",
"{",
"cc",
":=",
"coreCache",
"\n",
"if",
"cc",
".",
"cfg",
"==",
"cfg",
"{",
"return",
"cc",
".",
"coreP",
",",
"cc",
".",
"gocoreP",
",",
"cc",
".",
"err",
"\n",
"}",
"\n",
"c",
",",
"err",
":=",
"core",
".",
"Core",
"(",
"cfg",
".",
"corefile",
",",
"cfg",
".",
"base",
",",
"cfg",
".",
"exePath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"p",
",",
"err",
":=",
"gocore",
".",
"Core",
"(",
"c",
")",
"\n",
"if",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"&&",
"cfg",
".",
"exePath",
"==",
"\"\"",
"{",
"return",
"nil",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"%v; consider specifying the --exe flag\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"w",
":=",
"range",
"c",
".",
"Warnings",
"(",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"WARNING: %s\\n\"",
",",
"\\n",
")",
"\n",
"}",
"\n",
"w",
"\n",
"cc",
".",
"cfg",
"=",
"cfg",
"\n",
"cc",
".",
"coreP",
"=",
"c",
"\n",
"cc",
".",
"gocoreP",
"=",
"p",
"\n",
"cc",
".",
"err",
"=",
"nil",
"\n",
"}"
] |
// readCore reads corefile and returns core and gocore process states.
|
[
"readCore",
"reads",
"corefile",
"and",
"returns",
"core",
"and",
"gocore",
"process",
"states",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/cmd/viewcore/main.go#L251-L275
|
test
|
golang/debug
|
cmd/viewcore/main.go
|
typeName
|
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
|
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
}
|
[
"func",
"typeName",
"(",
"c",
"*",
"gocore",
".",
"Process",
",",
"x",
"gocore",
".",
"Object",
")",
"string",
"{",
"size",
":=",
"c",
".",
"Size",
"(",
"x",
")",
"\n",
"typ",
",",
"repeat",
":=",
"c",
".",
"Type",
"(",
"x",
")",
"\n",
"if",
"typ",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"unk%d\"",
",",
"size",
")",
"\n",
"}",
"\n",
"name",
":=",
"typ",
".",
"String",
"(",
")",
"\n",
"n",
":=",
"size",
"/",
"typ",
".",
"Size",
"\n",
"if",
"n",
">",
"1",
"{",
"if",
"repeat",
"<",
"n",
"{",
"name",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"[%d+%d?]%s\"",
",",
"repeat",
",",
"n",
"-",
"repeat",
",",
"name",
")",
"\n",
"}",
"else",
"{",
"name",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"[%d]%s\"",
",",
"repeat",
",",
"name",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"name",
"\n",
"}"
] |
// typeName returns a string representing the type of this object.
|
[
"typeName",
"returns",
"a",
"string",
"representing",
"the",
"type",
"of",
"this",
"object",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/cmd/viewcore/main.go#L749-L765
|
test
|
golang/debug
|
cmd/viewcore/main.go
|
fieldName
|
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
|
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)
}
|
[
"func",
"fieldName",
"(",
"c",
"*",
"gocore",
".",
"Process",
",",
"x",
"gocore",
".",
"Object",
",",
"off",
"int64",
")",
"string",
"{",
"size",
":=",
"c",
".",
"Size",
"(",
"x",
")",
"\n",
"typ",
",",
"repeat",
":=",
"c",
".",
"Type",
"(",
"x",
")",
"\n",
"if",
"typ",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"f%d\"",
",",
"off",
")",
"\n",
"}",
"\n",
"n",
":=",
"size",
"/",
"typ",
".",
"Size",
"\n",
"i",
":=",
"off",
"/",
"typ",
".",
"Size",
"\n",
"if",
"i",
"==",
"0",
"&&",
"repeat",
"==",
"1",
"{",
"return",
"typeFieldName",
"(",
"typ",
",",
"off",
")",
"\n",
"}",
"\n",
"if",
"i",
">=",
"n",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"f%d\"",
",",
"off",
")",
"\n",
"}",
"\n",
"q",
":=",
"\"\"",
"\n",
"if",
"i",
">=",
"repeat",
"{",
"q",
"=",
"\"?\"",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"[%d]%s%s\"",
",",
"i",
",",
"typeFieldName",
"(",
"typ",
",",
"off",
"-",
"i",
"*",
"typ",
".",
"Size",
")",
",",
"q",
")",
"\n",
"}"
] |
// fieldName returns the name of the field at offset off in x.
|
[
"fieldName",
"returns",
"the",
"name",
"of",
"the",
"field",
"at",
"offset",
"off",
"in",
"x",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/cmd/viewcore/main.go#L768-L790
|
test
|
golang/debug
|
cmd/viewcore/main.go
|
typeFieldName
|
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
|
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 ".???"
}
|
[
"func",
"typeFieldName",
"(",
"t",
"*",
"gocore",
".",
"Type",
",",
"off",
"int64",
")",
"string",
"{",
"switch",
"t",
".",
"Kind",
"{",
"case",
"gocore",
".",
"KindBool",
",",
"gocore",
".",
"KindInt",
",",
"gocore",
".",
"KindUint",
",",
"gocore",
".",
"KindFloat",
":",
"return",
"\"\"",
"\n",
"case",
"gocore",
".",
"KindComplex",
":",
"if",
"off",
"==",
"0",
"{",
"return",
"\".real\"",
"\n",
"}",
"\n",
"return",
"\".imag\"",
"\n",
"case",
"gocore",
".",
"KindIface",
",",
"gocore",
".",
"KindEface",
":",
"if",
"off",
"==",
"0",
"{",
"return",
"\".type\"",
"\n",
"}",
"\n",
"return",
"\".data\"",
"\n",
"case",
"gocore",
".",
"KindPtr",
",",
"gocore",
".",
"KindFunc",
":",
"return",
"\"\"",
"\n",
"case",
"gocore",
".",
"KindString",
":",
"if",
"off",
"==",
"0",
"{",
"return",
"\".ptr\"",
"\n",
"}",
"\n",
"return",
"\".len\"",
"\n",
"case",
"gocore",
".",
"KindSlice",
":",
"if",
"off",
"==",
"0",
"{",
"return",
"\".ptr\"",
"\n",
"}",
"\n",
"if",
"off",
"<=",
"t",
".",
"Size",
"/",
"2",
"{",
"return",
"\".len\"",
"\n",
"}",
"\n",
"return",
"\".cap\"",
"\n",
"case",
"gocore",
".",
"KindArray",
":",
"s",
":=",
"t",
".",
"Elem",
".",
"Size",
"\n",
"i",
":=",
"off",
"/",
"s",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"[%d]%s\"",
",",
"i",
",",
"typeFieldName",
"(",
"t",
".",
"Elem",
",",
"off",
"-",
"i",
"*",
"s",
")",
")",
"\n",
"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",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\".???\"",
"\n",
"}"
] |
// typeFieldName returns the name of the field at offset off in t.
|
[
"typeFieldName",
"returns",
"the",
"name",
"of",
"the",
"field",
"at",
"offset",
"off",
"in",
"t",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/cmd/viewcore/main.go#L793-L834
|
test
|
golang/debug
|
internal/gocore/process.go
|
FindFunc
|
func (p *Process) FindFunc(pc core.Address) *Func {
return p.funcTab.find(pc)
}
|
go
|
func (p *Process) FindFunc(pc core.Address) *Func {
return p.funcTab.find(pc)
}
|
[
"func",
"(",
"p",
"*",
"Process",
")",
"FindFunc",
"(",
"pc",
"core",
".",
"Address",
")",
"*",
"Func",
"{",
"return",
"p",
".",
"funcTab",
".",
"find",
"(",
"pc",
")",
"\n",
"}"
] |
// FindFunc returns the function which contains the code at address pc, if any.
|
[
"FindFunc",
"returns",
"the",
"function",
"which",
"contains",
"the",
"code",
"at",
"address",
"pc",
"if",
"any",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/process.go#L99-L101
|
test
|
golang/debug
|
internal/gocore/process.go
|
Core
|
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
|
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
}
|
[
"func",
"Core",
"(",
"proc",
"*",
"core",
".",
"Process",
")",
"(",
"p",
"*",
"Process",
",",
"err",
"error",
")",
"{",
"if",
"_",
",",
"err",
":=",
"proc",
".",
"DWARF",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"p",
"=",
"&",
"Process",
"{",
"proc",
":",
"proc",
",",
"runtimeMap",
":",
"map",
"[",
"core",
".",
"Address",
"]",
"*",
"Type",
"{",
"}",
",",
"dwarfMap",
":",
"map",
"[",
"dwarf",
".",
"Type",
"]",
"*",
"Type",
"{",
"}",
",",
"}",
"\n",
"p",
".",
"readDWARFTypes",
"(",
")",
"\n",
"p",
".",
"readRuntimeConstants",
"(",
")",
"\n",
"p",
".",
"readGlobals",
"(",
")",
"\n",
"p",
".",
"rtGlobals",
"=",
"map",
"[",
"string",
"]",
"region",
"{",
"}",
"\n",
"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",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"p",
".",
"buildVersion",
"=",
"p",
".",
"rtGlobals",
"[",
"\"buildVersion\"",
"]",
".",
"String",
"(",
")",
"\n",
"p",
".",
"readModules",
"(",
")",
"\n",
"p",
".",
"readHeap",
"(",
")",
"\n",
"p",
".",
"readGs",
"(",
")",
"\n",
"p",
".",
"readStackVars",
"(",
")",
"\n",
"p",
".",
"markObjects",
"(",
")",
"\n",
"return",
"p",
",",
"nil",
"\n",
"}"
] |
// Core takes a loaded core file and extracts Go information from it.
|
[
"Core",
"takes",
"a",
"loaded",
"core",
"file",
"and",
"extracts",
"Go",
"information",
"from",
"it",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/process.go#L112-L162
|
test
|
golang/debug
|
internal/gocore/region.go
|
Address
|
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
|
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)
}
|
[
"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",
")",
"\n",
"}",
"\n",
"return",
"r",
".",
"p",
".",
"proc",
".",
"ReadPtr",
"(",
"r",
".",
"a",
")",
"\n",
"}"
] |
// Address returns the address that a region of pointer type points to.
|
[
"Address",
"returns",
"the",
"address",
"that",
"a",
"region",
"of",
"pointer",
"type",
"points",
"to",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/region.go#L20-L25
|
test
|
golang/debug
|
internal/gocore/region.go
|
Int
|
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
|
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)
}
|
[
"func",
"(",
"r",
"region",
")",
"Int",
"(",
")",
"int64",
"{",
"if",
"r",
".",
"typ",
".",
"Kind",
"!=",
"KindInt",
"||",
"r",
".",
"typ",
".",
"Size",
"!=",
"r",
".",
"p",
".",
"proc",
".",
"PtrSize",
"(",
")",
"{",
"panic",
"(",
"\"not an int: \"",
"+",
"r",
".",
"typ",
".",
"Name",
")",
"\n",
"}",
"\n",
"return",
"r",
".",
"p",
".",
"proc",
".",
"ReadInt",
"(",
"r",
".",
"a",
")",
"\n",
"}"
] |
// Int returns the int value stored in r.
|
[
"Int",
"returns",
"the",
"int",
"value",
"stored",
"in",
"r",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/region.go#L28-L33
|
test
|
golang/debug
|
internal/gocore/region.go
|
Uintptr
|
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
|
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)
}
|
[
"func",
"(",
"r",
"region",
")",
"Uintptr",
"(",
")",
"uint64",
"{",
"if",
"r",
".",
"typ",
".",
"Kind",
"!=",
"KindUint",
"||",
"r",
".",
"typ",
".",
"Size",
"!=",
"r",
".",
"p",
".",
"proc",
".",
"PtrSize",
"(",
")",
"{",
"panic",
"(",
"\"not a uintptr: \"",
"+",
"r",
".",
"typ",
".",
"Name",
")",
"\n",
"}",
"\n",
"return",
"r",
".",
"p",
".",
"proc",
".",
"ReadUintptr",
"(",
"r",
".",
"a",
")",
"\n",
"}"
] |
// Uintptr returns the uintptr value stored in r.
|
[
"Uintptr",
"returns",
"the",
"uintptr",
"value",
"stored",
"in",
"r",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/region.go#L36-L41
|
test
|
golang/debug
|
internal/gocore/region.go
|
Cast
|
func (r region) Cast(typ string) region {
return region{p: r.p, a: r.a, typ: r.p.findType(typ)}
}
|
go
|
func (r region) Cast(typ string) region {
return region{p: r.p, a: r.a, typ: r.p.findType(typ)}
}
|
[
"func",
"(",
"r",
"region",
")",
"Cast",
"(",
"typ",
"string",
")",
"region",
"{",
"return",
"region",
"{",
"p",
":",
"r",
".",
"p",
",",
"a",
":",
"r",
".",
"a",
",",
"typ",
":",
"r",
".",
"p",
".",
"findType",
"(",
"typ",
")",
"}",
"\n",
"}"
] |
// Cast the region to the given type.
|
[
"Cast",
"the",
"region",
"to",
"the",
"given",
"type",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/region.go#L44-L46
|
test
|
golang/debug
|
internal/gocore/region.go
|
Deref
|
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
|
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}
}
|
[
"func",
"(",
"r",
"region",
")",
"Deref",
"(",
")",
"region",
"{",
"if",
"r",
".",
"typ",
".",
"Kind",
"!=",
"KindPtr",
"{",
"panic",
"(",
"\"can't deref on non-pointer: \"",
"+",
"r",
".",
"typ",
".",
"Name",
")",
"\n",
"}",
"\n",
"if",
"r",
".",
"typ",
".",
"Elem",
"==",
"nil",
"{",
"panic",
"(",
"\"can't deref unsafe.Pointer\"",
")",
"\n",
"}",
"\n",
"p",
":=",
"r",
".",
"p",
".",
"proc",
".",
"ReadPtr",
"(",
"r",
".",
"a",
")",
"\n",
"return",
"region",
"{",
"p",
":",
"r",
".",
"p",
",",
"a",
":",
"p",
",",
"typ",
":",
"r",
".",
"typ",
".",
"Elem",
"}",
"\n",
"}"
] |
// Deref loads from a pointer. r must contain a pointer.
|
[
"Deref",
"loads",
"from",
"a",
"pointer",
".",
"r",
"must",
"contain",
"a",
"pointer",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/region.go#L49-L58
|
test
|
golang/debug
|
internal/gocore/region.go
|
Uint64
|
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
|
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)
}
|
[
"func",
"(",
"r",
"region",
")",
"Uint64",
"(",
")",
"uint64",
"{",
"if",
"r",
".",
"typ",
".",
"Kind",
"!=",
"KindUint",
"||",
"r",
".",
"typ",
".",
"Size",
"!=",
"8",
"{",
"panic",
"(",
"\"bad uint64 type \"",
"+",
"r",
".",
"typ",
".",
"Name",
")",
"\n",
"}",
"\n",
"return",
"r",
".",
"p",
".",
"proc",
".",
"ReadUint64",
"(",
"r",
".",
"a",
")",
"\n",
"}"
] |
// Uint64 returns the uint64 value stored in r.
// r must have type uint64.
|
[
"Uint64",
"returns",
"the",
"uint64",
"value",
"stored",
"in",
"r",
".",
"r",
"must",
"have",
"type",
"uint64",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/region.go#L62-L67
|
test
|
golang/debug
|
internal/gocore/region.go
|
Uint32
|
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
|
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)
}
|
[
"func",
"(",
"r",
"region",
")",
"Uint32",
"(",
")",
"uint32",
"{",
"if",
"r",
".",
"typ",
".",
"Kind",
"!=",
"KindUint",
"||",
"r",
".",
"typ",
".",
"Size",
"!=",
"4",
"{",
"panic",
"(",
"\"bad uint32 type \"",
"+",
"r",
".",
"typ",
".",
"Name",
")",
"\n",
"}",
"\n",
"return",
"r",
".",
"p",
".",
"proc",
".",
"ReadUint32",
"(",
"r",
".",
"a",
")",
"\n",
"}"
] |
// Uint32 returns the uint32 value stored in r.
// r must have type uint32.
|
[
"Uint32",
"returns",
"the",
"uint32",
"value",
"stored",
"in",
"r",
".",
"r",
"must",
"have",
"type",
"uint32",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/region.go#L71-L76
|
test
|
golang/debug
|
internal/gocore/region.go
|
Int32
|
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
|
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)
}
|
[
"func",
"(",
"r",
"region",
")",
"Int32",
"(",
")",
"int32",
"{",
"if",
"r",
".",
"typ",
".",
"Kind",
"!=",
"KindInt",
"||",
"r",
".",
"typ",
".",
"Size",
"!=",
"4",
"{",
"panic",
"(",
"\"bad int32 type \"",
"+",
"r",
".",
"typ",
".",
"Name",
")",
"\n",
"}",
"\n",
"return",
"r",
".",
"p",
".",
"proc",
".",
"ReadInt32",
"(",
"r",
".",
"a",
")",
"\n",
"}"
] |
// Int32 returns the int32 value stored in r.
// r must have type int32.
|
[
"Int32",
"returns",
"the",
"int32",
"value",
"stored",
"in",
"r",
".",
"r",
"must",
"have",
"type",
"int32",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/region.go#L80-L85
|
test
|
golang/debug
|
internal/gocore/region.go
|
Uint16
|
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
|
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)
}
|
[
"func",
"(",
"r",
"region",
")",
"Uint16",
"(",
")",
"uint16",
"{",
"if",
"r",
".",
"typ",
".",
"Kind",
"!=",
"KindUint",
"||",
"r",
".",
"typ",
".",
"Size",
"!=",
"2",
"{",
"panic",
"(",
"\"bad uint16 type \"",
"+",
"r",
".",
"typ",
".",
"Name",
")",
"\n",
"}",
"\n",
"return",
"r",
".",
"p",
".",
"proc",
".",
"ReadUint16",
"(",
"r",
".",
"a",
")",
"\n",
"}"
] |
// Uint16 returns the uint16 value stored in r.
// r must have type uint16.
|
[
"Uint16",
"returns",
"the",
"uint16",
"value",
"stored",
"in",
"r",
".",
"r",
"must",
"have",
"type",
"uint16",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/region.go#L89-L94
|
test
|
golang/debug
|
internal/gocore/region.go
|
Uint8
|
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
|
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)
}
|
[
"func",
"(",
"r",
"region",
")",
"Uint8",
"(",
")",
"uint8",
"{",
"if",
"r",
".",
"typ",
".",
"Kind",
"!=",
"KindUint",
"||",
"r",
".",
"typ",
".",
"Size",
"!=",
"1",
"{",
"panic",
"(",
"\"bad uint8 type \"",
"+",
"r",
".",
"typ",
".",
"Name",
")",
"\n",
"}",
"\n",
"return",
"r",
".",
"p",
".",
"proc",
".",
"ReadUint8",
"(",
"r",
".",
"a",
")",
"\n",
"}"
] |
// Uint8 returns the uint8 value stored in r.
// r must have type uint8.
|
[
"Uint8",
"returns",
"the",
"uint8",
"value",
"stored",
"in",
"r",
".",
"r",
"must",
"have",
"type",
"uint8",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/region.go#L98-L103
|
test
|
golang/debug
|
internal/gocore/region.go
|
String
|
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
|
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)
}
|
[
"func",
"(",
"r",
"region",
")",
"String",
"(",
")",
"string",
"{",
"if",
"r",
".",
"typ",
".",
"Kind",
"!=",
"KindString",
"{",
"panic",
"(",
"\"bad string type \"",
"+",
"r",
".",
"typ",
".",
"Name",
")",
"\n",
"}",
"\n",
"p",
":=",
"r",
".",
"p",
".",
"proc",
".",
"ReadPtr",
"(",
"r",
".",
"a",
")",
"\n",
"n",
":=",
"r",
".",
"p",
".",
"proc",
".",
"ReadUintptr",
"(",
"r",
".",
"a",
".",
"Add",
"(",
"r",
".",
"p",
".",
"proc",
".",
"PtrSize",
"(",
")",
")",
")",
"\n",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"n",
")",
"\n",
"r",
".",
"p",
".",
"proc",
".",
"ReadAt",
"(",
"b",
",",
"p",
")",
"\n",
"return",
"string",
"(",
"b",
")",
"\n",
"}"
] |
// String returns the value of the string stored in r.
|
[
"String",
"returns",
"the",
"value",
"of",
"the",
"string",
"stored",
"in",
"r",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/region.go#L106-L115
|
test
|
golang/debug
|
internal/gocore/region.go
|
SlicePtr
|
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
|
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}}
}
|
[
"func",
"(",
"r",
"region",
")",
"SlicePtr",
"(",
")",
"region",
"{",
"if",
"r",
".",
"typ",
".",
"Kind",
"!=",
"KindSlice",
"{",
"panic",
"(",
"\"can't Ptr a non-slice\"",
")",
"\n",
"}",
"\n",
"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",
"}",
"}",
"\n",
"}"
] |
// SlicePtr returns the pointer inside a slice. r must contain a slice.
|
[
"SlicePtr",
"returns",
"the",
"pointer",
"inside",
"a",
"slice",
".",
"r",
"must",
"contain",
"a",
"slice",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/region.go#L128-L133
|
test
|
golang/debug
|
internal/gocore/region.go
|
SliceLen
|
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
|
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()))
}
|
[
"func",
"(",
"r",
"region",
")",
"SliceLen",
"(",
")",
"int64",
"{",
"if",
"r",
".",
"typ",
".",
"Kind",
"!=",
"KindSlice",
"{",
"panic",
"(",
"\"can't len a non-slice\"",
")",
"\n",
"}",
"\n",
"return",
"r",
".",
"p",
".",
"proc",
".",
"ReadInt",
"(",
"r",
".",
"a",
".",
"Add",
"(",
"r",
".",
"p",
".",
"proc",
".",
"PtrSize",
"(",
")",
")",
")",
"\n",
"}"
] |
// SliceLen returns the length of a slice. r must contain a slice.
|
[
"SliceLen",
"returns",
"the",
"length",
"of",
"a",
"slice",
".",
"r",
"must",
"contain",
"a",
"slice",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/region.go#L136-L141
|
test
|
golang/debug
|
internal/gocore/region.go
|
Field
|
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
|
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}
}
|
[
"func",
"(",
"r",
"region",
")",
"Field",
"(",
"f",
"string",
")",
"region",
"{",
"finfo",
":=",
"r",
".",
"typ",
".",
"field",
"(",
"f",
")",
"\n",
"if",
"finfo",
"==",
"nil",
"{",
"panic",
"(",
"\"can't find field \"",
"+",
"r",
".",
"typ",
".",
"Name",
"+",
"\".\"",
"+",
"f",
")",
"\n",
"}",
"\n",
"return",
"region",
"{",
"p",
":",
"r",
".",
"p",
",",
"a",
":",
"r",
".",
"a",
".",
"Add",
"(",
"finfo",
".",
"Off",
")",
",",
"typ",
":",
"finfo",
".",
"Type",
"}",
"\n",
"}"
] |
// Field returns the part of r which contains the field f.
// r must contain a struct, and f must be one of its fields.
|
[
"Field",
"returns",
"the",
"part",
"of",
"r",
"which",
"contains",
"the",
"field",
"f",
".",
"r",
"must",
"contain",
"a",
"struct",
"and",
"f",
"must",
"be",
"one",
"of",
"its",
"fields",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/region.go#L153-L159
|
test
|
golang/debug
|
internal/core/read.go
|
ReadUint8
|
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
|
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)]
}
|
[
"func",
"(",
"p",
"*",
"Process",
")",
"ReadUint8",
"(",
"a",
"Address",
")",
"uint8",
"{",
"m",
":=",
"p",
".",
"findMapping",
"(",
"a",
")",
"\n",
"if",
"m",
"==",
"nil",
"{",
"panic",
"(",
"fmt",
".",
"Errorf",
"(",
"\"address %x is not mapped in the core file\"",
",",
"a",
")",
")",
"\n",
"}",
"\n",
"return",
"m",
".",
"contents",
"[",
"a",
".",
"Sub",
"(",
"m",
".",
"min",
")",
"]",
"\n",
"}"
] |
// ReadUint8 returns a uint8 read from address a of the inferior.
|
[
"ReadUint8",
"returns",
"a",
"uint8",
"read",
"from",
"address",
"a",
"of",
"the",
"inferior",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/core/read.go#L33-L39
|
test
|
golang/debug
|
internal/core/read.go
|
ReadUint16
|
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
|
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)
}
|
[
"func",
"(",
"p",
"*",
"Process",
")",
"ReadUint16",
"(",
"a",
"Address",
")",
"uint16",
"{",
"m",
":=",
"p",
".",
"findMapping",
"(",
"a",
")",
"\n",
"if",
"m",
"==",
"nil",
"{",
"panic",
"(",
"fmt",
".",
"Errorf",
"(",
"\"address %x is not mapped in the core file\"",
",",
"a",
")",
")",
"\n",
"}",
"\n",
"b",
":=",
"m",
".",
"contents",
"[",
"a",
".",
"Sub",
"(",
"m",
".",
"min",
")",
":",
"]",
"\n",
"if",
"len",
"(",
"b",
")",
"<",
"2",
"{",
"var",
"buf",
"[",
"2",
"]",
"byte",
"\n",
"b",
"=",
"buf",
"[",
":",
"]",
"\n",
"p",
".",
"ReadAt",
"(",
"b",
",",
"a",
")",
"\n",
"}",
"\n",
"if",
"p",
".",
"littleEndian",
"{",
"return",
"binary",
".",
"LittleEndian",
".",
"Uint16",
"(",
"b",
")",
"\n",
"}",
"\n",
"return",
"binary",
".",
"BigEndian",
".",
"Uint16",
"(",
"b",
")",
"\n",
"}"
] |
// ReadUint16 returns a uint16 read from address a of the inferior.
|
[
"ReadUint16",
"returns",
"a",
"uint16",
"read",
"from",
"address",
"a",
"of",
"the",
"inferior",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/core/read.go#L42-L57
|
test
|
golang/debug
|
internal/core/read.go
|
ReadUint32
|
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
|
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)
}
|
[
"func",
"(",
"p",
"*",
"Process",
")",
"ReadUint32",
"(",
"a",
"Address",
")",
"uint32",
"{",
"m",
":=",
"p",
".",
"findMapping",
"(",
"a",
")",
"\n",
"if",
"m",
"==",
"nil",
"{",
"panic",
"(",
"fmt",
".",
"Errorf",
"(",
"\"address %x is not mapped in the core file\"",
",",
"a",
")",
")",
"\n",
"}",
"\n",
"b",
":=",
"m",
".",
"contents",
"[",
"a",
".",
"Sub",
"(",
"m",
".",
"min",
")",
":",
"]",
"\n",
"if",
"len",
"(",
"b",
")",
"<",
"4",
"{",
"var",
"buf",
"[",
"4",
"]",
"byte",
"\n",
"b",
"=",
"buf",
"[",
":",
"]",
"\n",
"p",
".",
"ReadAt",
"(",
"b",
",",
"a",
")",
"\n",
"}",
"\n",
"if",
"p",
".",
"littleEndian",
"{",
"return",
"binary",
".",
"LittleEndian",
".",
"Uint32",
"(",
"b",
")",
"\n",
"}",
"\n",
"return",
"binary",
".",
"BigEndian",
".",
"Uint32",
"(",
"b",
")",
"\n",
"}"
] |
// ReadUint32 returns a uint32 read from address a of the inferior.
|
[
"ReadUint32",
"returns",
"a",
"uint32",
"read",
"from",
"address",
"a",
"of",
"the",
"inferior",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/core/read.go#L60-L75
|
test
|
golang/debug
|
internal/core/read.go
|
ReadUint64
|
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
|
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)
}
|
[
"func",
"(",
"p",
"*",
"Process",
")",
"ReadUint64",
"(",
"a",
"Address",
")",
"uint64",
"{",
"m",
":=",
"p",
".",
"findMapping",
"(",
"a",
")",
"\n",
"if",
"m",
"==",
"nil",
"{",
"panic",
"(",
"fmt",
".",
"Errorf",
"(",
"\"address %x is not mapped in the core file\"",
",",
"a",
")",
")",
"\n",
"}",
"\n",
"b",
":=",
"m",
".",
"contents",
"[",
"a",
".",
"Sub",
"(",
"m",
".",
"min",
")",
":",
"]",
"\n",
"if",
"len",
"(",
"b",
")",
"<",
"8",
"{",
"var",
"buf",
"[",
"8",
"]",
"byte",
"\n",
"b",
"=",
"buf",
"[",
":",
"]",
"\n",
"p",
".",
"ReadAt",
"(",
"b",
",",
"a",
")",
"\n",
"}",
"\n",
"if",
"p",
".",
"littleEndian",
"{",
"return",
"binary",
".",
"LittleEndian",
".",
"Uint64",
"(",
"b",
")",
"\n",
"}",
"\n",
"return",
"binary",
".",
"BigEndian",
".",
"Uint64",
"(",
"b",
")",
"\n",
"}"
] |
// ReadUint64 returns a uint64 read from address a of the inferior.
|
[
"ReadUint64",
"returns",
"a",
"uint64",
"read",
"from",
"address",
"a",
"of",
"the",
"inferior",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/core/read.go#L78-L93
|
test
|
golang/debug
|
internal/core/read.go
|
ReadInt8
|
func (p *Process) ReadInt8(a Address) int8 {
return int8(p.ReadUint8(a))
}
|
go
|
func (p *Process) ReadInt8(a Address) int8 {
return int8(p.ReadUint8(a))
}
|
[
"func",
"(",
"p",
"*",
"Process",
")",
"ReadInt8",
"(",
"a",
"Address",
")",
"int8",
"{",
"return",
"int8",
"(",
"p",
".",
"ReadUint8",
"(",
"a",
")",
")",
"\n",
"}"
] |
// ReadInt8 returns an int8 read from address a of the inferior.
|
[
"ReadInt8",
"returns",
"an",
"int8",
"read",
"from",
"address",
"a",
"of",
"the",
"inferior",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/core/read.go#L96-L98
|
test
|
golang/debug
|
internal/core/read.go
|
ReadInt16
|
func (p *Process) ReadInt16(a Address) int16 {
return int16(p.ReadUint16(a))
}
|
go
|
func (p *Process) ReadInt16(a Address) int16 {
return int16(p.ReadUint16(a))
}
|
[
"func",
"(",
"p",
"*",
"Process",
")",
"ReadInt16",
"(",
"a",
"Address",
")",
"int16",
"{",
"return",
"int16",
"(",
"p",
".",
"ReadUint16",
"(",
"a",
")",
")",
"\n",
"}"
] |
// ReadInt16 returns an int16 read from address a of the inferior.
|
[
"ReadInt16",
"returns",
"an",
"int16",
"read",
"from",
"address",
"a",
"of",
"the",
"inferior",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/core/read.go#L101-L103
|
test
|
golang/debug
|
internal/core/read.go
|
ReadInt32
|
func (p *Process) ReadInt32(a Address) int32 {
return int32(p.ReadUint32(a))
}
|
go
|
func (p *Process) ReadInt32(a Address) int32 {
return int32(p.ReadUint32(a))
}
|
[
"func",
"(",
"p",
"*",
"Process",
")",
"ReadInt32",
"(",
"a",
"Address",
")",
"int32",
"{",
"return",
"int32",
"(",
"p",
".",
"ReadUint32",
"(",
"a",
")",
")",
"\n",
"}"
] |
// ReadInt32 returns an int32 read from address a of the inferior.
|
[
"ReadInt32",
"returns",
"an",
"int32",
"read",
"from",
"address",
"a",
"of",
"the",
"inferior",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/core/read.go#L106-L108
|
test
|
golang/debug
|
internal/core/read.go
|
ReadInt64
|
func (p *Process) ReadInt64(a Address) int64 {
return int64(p.ReadUint64(a))
}
|
go
|
func (p *Process) ReadInt64(a Address) int64 {
return int64(p.ReadUint64(a))
}
|
[
"func",
"(",
"p",
"*",
"Process",
")",
"ReadInt64",
"(",
"a",
"Address",
")",
"int64",
"{",
"return",
"int64",
"(",
"p",
".",
"ReadUint64",
"(",
"a",
")",
")",
"\n",
"}"
] |
// ReadInt64 returns an int64 read from address a of the inferior.
|
[
"ReadInt64",
"returns",
"an",
"int64",
"read",
"from",
"address",
"a",
"of",
"the",
"inferior",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/core/read.go#L111-L113
|
test
|
golang/debug
|
internal/core/read.go
|
ReadUintptr
|
func (p *Process) ReadUintptr(a Address) uint64 {
if p.ptrSize == 4 {
return uint64(p.ReadUint32(a))
}
return p.ReadUint64(a)
}
|
go
|
func (p *Process) ReadUintptr(a Address) uint64 {
if p.ptrSize == 4 {
return uint64(p.ReadUint32(a))
}
return p.ReadUint64(a)
}
|
[
"func",
"(",
"p",
"*",
"Process",
")",
"ReadUintptr",
"(",
"a",
"Address",
")",
"uint64",
"{",
"if",
"p",
".",
"ptrSize",
"==",
"4",
"{",
"return",
"uint64",
"(",
"p",
".",
"ReadUint32",
"(",
"a",
")",
")",
"\n",
"}",
"\n",
"return",
"p",
".",
"ReadUint64",
"(",
"a",
")",
"\n",
"}"
] |
// ReadUintptr returns a uint of pointer size read from address a of the inferior.
|
[
"ReadUintptr",
"returns",
"a",
"uint",
"of",
"pointer",
"size",
"read",
"from",
"address",
"a",
"of",
"the",
"inferior",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/core/read.go#L116-L121
|
test
|
golang/debug
|
internal/core/read.go
|
ReadPtr
|
func (p *Process) ReadPtr(a Address) Address {
return Address(p.ReadUintptr(a))
}
|
go
|
func (p *Process) ReadPtr(a Address) Address {
return Address(p.ReadUintptr(a))
}
|
[
"func",
"(",
"p",
"*",
"Process",
")",
"ReadPtr",
"(",
"a",
"Address",
")",
"Address",
"{",
"return",
"Address",
"(",
"p",
".",
"ReadUintptr",
"(",
"a",
")",
")",
"\n",
"}"
] |
// ReadPtr returns a pointer loaded from address a of the inferior.
|
[
"ReadPtr",
"returns",
"a",
"pointer",
"loaded",
"from",
"address",
"a",
"of",
"the",
"inferior",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/core/read.go#L132-L134
|
test
|
golang/debug
|
internal/core/read.go
|
ReadCString
|
func (p *Process) ReadCString(a Address) string {
for n := int64(0); ; n++ {
if p.ReadUint8(a.Add(n)) == 0 {
b := make([]byte, n)
p.ReadAt(b, a)
return string(b)
}
}
}
|
go
|
func (p *Process) ReadCString(a Address) string {
for n := int64(0); ; n++ {
if p.ReadUint8(a.Add(n)) == 0 {
b := make([]byte, n)
p.ReadAt(b, a)
return string(b)
}
}
}
|
[
"func",
"(",
"p",
"*",
"Process",
")",
"ReadCString",
"(",
"a",
"Address",
")",
"string",
"{",
"for",
"n",
":=",
"int64",
"(",
"0",
")",
";",
";",
"n",
"++",
"{",
"if",
"p",
".",
"ReadUint8",
"(",
"a",
".",
"Add",
"(",
"n",
")",
")",
"==",
"0",
"{",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"n",
")",
"\n",
"p",
".",
"ReadAt",
"(",
"b",
",",
"a",
")",
"\n",
"return",
"string",
"(",
"b",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// ReadCString reads a null-terminated string starting at address a.
|
[
"ReadCString",
"reads",
"a",
"null",
"-",
"terminated",
"string",
"starting",
"at",
"address",
"a",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/core/read.go#L137-L145
|
test
|
golang/debug
|
internal/core/mapping.go
|
Source
|
func (m *Mapping) Source() (string, int64) {
if m.f == nil {
return "", 0
}
return m.f.Name(), m.off
}
|
go
|
func (m *Mapping) Source() (string, int64) {
if m.f == nil {
return "", 0
}
return m.f.Name(), m.off
}
|
[
"func",
"(",
"m",
"*",
"Mapping",
")",
"Source",
"(",
")",
"(",
"string",
",",
"int64",
")",
"{",
"if",
"m",
".",
"f",
"==",
"nil",
"{",
"return",
"\"\"",
",",
"0",
"\n",
"}",
"\n",
"return",
"m",
".",
"f",
".",
"Name",
"(",
")",
",",
"m",
".",
"off",
"\n",
"}"
] |
// Source returns the backing file and offset for the mapping, or "", 0 if none.
|
[
"Source",
"returns",
"the",
"backing",
"file",
"and",
"offset",
"for",
"the",
"mapping",
"or",
"0",
"if",
"none",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/core/mapping.go#L53-L58
|
test
|
golang/debug
|
internal/core/mapping.go
|
findMapping
|
func (p *Process) findMapping(a Address) *Mapping {
t3 := p.pageTable[a>>52]
if t3 == nil {
return nil
}
t2 := t3[a>>42%(1<<10)]
if t2 == nil {
return nil
}
t1 := t2[a>>32%(1<<10)]
if t1 == nil {
return nil
}
t0 := t1[a>>22%(1<<10)]
if t0 == nil {
return nil
}
return t0[a>>12%(1<<10)]
}
|
go
|
func (p *Process) findMapping(a Address) *Mapping {
t3 := p.pageTable[a>>52]
if t3 == nil {
return nil
}
t2 := t3[a>>42%(1<<10)]
if t2 == nil {
return nil
}
t1 := t2[a>>32%(1<<10)]
if t1 == nil {
return nil
}
t0 := t1[a>>22%(1<<10)]
if t0 == nil {
return nil
}
return t0[a>>12%(1<<10)]
}
|
[
"func",
"(",
"p",
"*",
"Process",
")",
"findMapping",
"(",
"a",
"Address",
")",
"*",
"Mapping",
"{",
"t3",
":=",
"p",
".",
"pageTable",
"[",
"a",
">>",
"52",
"]",
"\n",
"if",
"t3",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"t2",
":=",
"t3",
"[",
"a",
">>",
"42",
"%",
"(",
"1",
"<<",
"10",
")",
"]",
"\n",
"if",
"t2",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"t1",
":=",
"t2",
"[",
"a",
">>",
"32",
"%",
"(",
"1",
"<<",
"10",
")",
"]",
"\n",
"if",
"t1",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"t0",
":=",
"t1",
"[",
"a",
">>",
"22",
"%",
"(",
"1",
"<<",
"10",
")",
"]",
"\n",
"if",
"t0",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"t0",
"[",
"a",
">>",
"12",
"%",
"(",
"1",
"<<",
"10",
")",
"]",
"\n",
"}"
] |
// findMapping is simple enough that it inlines.
|
[
"findMapping",
"is",
"simple",
"enough",
"that",
"it",
"inlines",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/core/mapping.go#L115-L133
|
test
|
golang/debug
|
internal/core/address.go
|
Max
|
func (a Address) Max(b Address) Address {
if a > b {
return a
}
return b
}
|
go
|
func (a Address) Max(b Address) Address {
if a > b {
return a
}
return b
}
|
[
"func",
"(",
"a",
"Address",
")",
"Max",
"(",
"b",
"Address",
")",
"Address",
"{",
"if",
"a",
">",
"b",
"{",
"return",
"a",
"\n",
"}",
"\n",
"return",
"b",
"\n",
"}"
] |
// Max returns the larger of a and b.
|
[
"Max",
"returns",
"the",
"larger",
"of",
"a",
"and",
"b",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/core/address.go#L21-L26
|
test
|
golang/debug
|
internal/core/address.go
|
Min
|
func (a Address) Min(b Address) Address {
if a < b {
return a
}
return b
}
|
go
|
func (a Address) Min(b Address) Address {
if a < b {
return a
}
return b
}
|
[
"func",
"(",
"a",
"Address",
")",
"Min",
"(",
"b",
"Address",
")",
"Address",
"{",
"if",
"a",
"<",
"b",
"{",
"return",
"a",
"\n",
"}",
"\n",
"return",
"b",
"\n",
"}"
] |
// Min returns the smaller of a and b.
|
[
"Min",
"returns",
"the",
"smaller",
"of",
"a",
"and",
"b",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/core/address.go#L29-L34
|
test
|
golang/debug
|
internal/core/address.go
|
Align
|
func (a Address) Align(x int64) Address {
return (a + Address(x) - 1) & ^(Address(x) - 1)
}
|
go
|
func (a Address) Align(x int64) Address {
return (a + Address(x) - 1) & ^(Address(x) - 1)
}
|
[
"func",
"(",
"a",
"Address",
")",
"Align",
"(",
"x",
"int64",
")",
"Address",
"{",
"return",
"(",
"a",
"+",
"Address",
"(",
"x",
")",
"-",
"1",
")",
"&",
"^",
"(",
"Address",
"(",
"x",
")",
"-",
"1",
")",
"\n",
"}"
] |
// Align rounds a up to a multiple of x.
// x must be a power of 2.
|
[
"Align",
"rounds",
"a",
"up",
"to",
"a",
"multiple",
"of",
"x",
".",
"x",
"must",
"be",
"a",
"power",
"of",
"2",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/core/address.go#L38-L40
|
test
|
golang/debug
|
internal/gocore/dominator.go
|
initialize
|
func (d *ltDom) initialize() {
type workItem struct {
name vName
parentName vName
}
// Initialize objs for mapping from object index back to Object.
i := 0
d.p.ForEachObject(func(x Object) bool {
d.objs[i] = x
i++
return true
})
// Add roots to the work stack, essentially pretending to visit
// the pseudo-root, numbering it 0.
d.semis[pseudoRoot] = 0
d.parents[pseudoRoot] = -1
d.vertices[0] = pseudoRoot
var work []workItem
for i := 1; i < 1+d.nRoots; i++ {
work = append(work, workItem{name: vName(i), parentName: 0})
}
n := vNumber(1) // 0 was the pseudo-root.
// Build the spanning tree, assigning vertex numbers to each object
// and initializing semi and parent.
for len(work) != 0 {
item := work[len(work)-1]
work = work[:len(work)-1]
if d.semis[item.name] != -1 {
continue
}
d.semis[item.name] = n
d.parents[item.name] = item.parentName
d.vertices[n] = item.name
n++
visitChild := func(_ int64, child Object, _ int64) bool {
childIdx, _ := d.p.findObjectIndex(d.p.Addr(child))
work = append(work, workItem{name: vName(childIdx + d.nRoots + 1), parentName: item.name})
return true
}
root, object := d.findVertexByName(item.name)
if root != nil {
d.p.ForEachRootPtr(root, visitChild)
} else {
d.p.ForEachPtr(object, visitChild)
}
}
}
|
go
|
func (d *ltDom) initialize() {
type workItem struct {
name vName
parentName vName
}
// Initialize objs for mapping from object index back to Object.
i := 0
d.p.ForEachObject(func(x Object) bool {
d.objs[i] = x
i++
return true
})
// Add roots to the work stack, essentially pretending to visit
// the pseudo-root, numbering it 0.
d.semis[pseudoRoot] = 0
d.parents[pseudoRoot] = -1
d.vertices[0] = pseudoRoot
var work []workItem
for i := 1; i < 1+d.nRoots; i++ {
work = append(work, workItem{name: vName(i), parentName: 0})
}
n := vNumber(1) // 0 was the pseudo-root.
// Build the spanning tree, assigning vertex numbers to each object
// and initializing semi and parent.
for len(work) != 0 {
item := work[len(work)-1]
work = work[:len(work)-1]
if d.semis[item.name] != -1 {
continue
}
d.semis[item.name] = n
d.parents[item.name] = item.parentName
d.vertices[n] = item.name
n++
visitChild := func(_ int64, child Object, _ int64) bool {
childIdx, _ := d.p.findObjectIndex(d.p.Addr(child))
work = append(work, workItem{name: vName(childIdx + d.nRoots + 1), parentName: item.name})
return true
}
root, object := d.findVertexByName(item.name)
if root != nil {
d.p.ForEachRootPtr(root, visitChild)
} else {
d.p.ForEachPtr(object, visitChild)
}
}
}
|
[
"func",
"(",
"d",
"*",
"ltDom",
")",
"initialize",
"(",
")",
"{",
"type",
"workItem",
"struct",
"{",
"name",
"vName",
"\n",
"parentName",
"vName",
"\n",
"}",
"\n",
"i",
":=",
"0",
"\n",
"d",
".",
"p",
".",
"ForEachObject",
"(",
"func",
"(",
"x",
"Object",
")",
"bool",
"{",
"d",
".",
"objs",
"[",
"i",
"]",
"=",
"x",
"\n",
"i",
"++",
"\n",
"return",
"true",
"\n",
"}",
")",
"\n",
"d",
".",
"semis",
"[",
"pseudoRoot",
"]",
"=",
"0",
"\n",
"d",
".",
"parents",
"[",
"pseudoRoot",
"]",
"=",
"-",
"1",
"\n",
"d",
".",
"vertices",
"[",
"0",
"]",
"=",
"pseudoRoot",
"\n",
"var",
"work",
"[",
"]",
"workItem",
"\n",
"for",
"i",
":=",
"1",
";",
"i",
"<",
"1",
"+",
"d",
".",
"nRoots",
";",
"i",
"++",
"{",
"work",
"=",
"append",
"(",
"work",
",",
"workItem",
"{",
"name",
":",
"vName",
"(",
"i",
")",
",",
"parentName",
":",
"0",
"}",
")",
"\n",
"}",
"\n",
"n",
":=",
"vNumber",
"(",
"1",
")",
"\n",
"for",
"len",
"(",
"work",
")",
"!=",
"0",
"{",
"item",
":=",
"work",
"[",
"len",
"(",
"work",
")",
"-",
"1",
"]",
"\n",
"work",
"=",
"work",
"[",
":",
"len",
"(",
"work",
")",
"-",
"1",
"]",
"\n",
"if",
"d",
".",
"semis",
"[",
"item",
".",
"name",
"]",
"!=",
"-",
"1",
"{",
"continue",
"\n",
"}",
"\n",
"d",
".",
"semis",
"[",
"item",
".",
"name",
"]",
"=",
"n",
"\n",
"d",
".",
"parents",
"[",
"item",
".",
"name",
"]",
"=",
"item",
".",
"parentName",
"\n",
"d",
".",
"vertices",
"[",
"n",
"]",
"=",
"item",
".",
"name",
"\n",
"n",
"++",
"\n",
"visitChild",
":=",
"func",
"(",
"_",
"int64",
",",
"child",
"Object",
",",
"_",
"int64",
")",
"bool",
"{",
"childIdx",
",",
"_",
":=",
"d",
".",
"p",
".",
"findObjectIndex",
"(",
"d",
".",
"p",
".",
"Addr",
"(",
"child",
")",
")",
"\n",
"work",
"=",
"append",
"(",
"work",
",",
"workItem",
"{",
"name",
":",
"vName",
"(",
"childIdx",
"+",
"d",
".",
"nRoots",
"+",
"1",
")",
",",
"parentName",
":",
"item",
".",
"name",
"}",
")",
"\n",
"return",
"true",
"\n",
"}",
"\n",
"root",
",",
"object",
":=",
"d",
".",
"findVertexByName",
"(",
"item",
".",
"name",
")",
"\n",
"if",
"root",
"!=",
"nil",
"{",
"d",
".",
"p",
".",
"ForEachRootPtr",
"(",
"root",
",",
"visitChild",
")",
"\n",
"}",
"else",
"{",
"d",
".",
"p",
".",
"ForEachPtr",
"(",
"object",
",",
"visitChild",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// initialize implements step 1 of LT.
|
[
"initialize",
"implements",
"step",
"1",
"of",
"LT",
"."
] |
19561fee47cf8cd0400d1b094c5898002f97cf90
|
https://github.com/golang/debug/blob/19561fee47cf8cd0400d1b094c5898002f97cf90/internal/gocore/dominator.go#L121-L176
|
test
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.