Source File
debuglog.go
Belonging Package
runtime
package runtime
import (
)
const debugLogBytes = 16 << 10
const debugLogStringLimit = debugLogBytes / 8
func () *dlogger {
if !dlogEnabled {
return nil
}
:= getCachedDlogger()
:= (*uintptr)(unsafe.Pointer(&allDloggers))
for {
:= atomic.Loaduintptr()
.allLink = (*dlogger)(unsafe.Pointer())
if atomic.Casuintptr(, , uintptr(unsafe.Pointer())) {
break
}
}
}
type dlogger struct {
w debugLogWriter
var allDloggers *dlogger
func ( *dlogger) () {
if !dlogEnabled {
return
}
if putCachedDlogger() {
return
}
func ( *dlogger) ( bool) *dlogger {
if !dlogEnabled {
return
}
if {
.w.byte(debugLogBoolTrue)
} else {
.w.byte(debugLogBoolFalse)
}
return
}
func ( *dlogger) ( int64) *dlogger {
if !dlogEnabled {
return
}
.w.byte(debugLogInt)
.w.varint()
return
}
func ( *dlogger) ( uint64) *dlogger {
if !dlogEnabled {
return
}
.w.byte(debugLogUint)
.w.uvarint()
return
}
func ( *dlogger) ( uint64) *dlogger {
if !dlogEnabled {
return
}
.w.byte(debugLogHex)
.w.uvarint()
return
}
func ( *dlogger) ( interface{}) *dlogger {
if !dlogEnabled {
return
}
.w.byte(debugLogPtr)
if == nil {
.w.uvarint(0)
} else {
:= efaceOf(&)
switch ._type.kind & kindMask {
case kindChan, kindFunc, kindMap, kindPtr, kindUnsafePointer:
.w.uvarint(uint64(uintptr(.data)))
default:
throw("not a pointer type")
}
}
return
}
func ( *dlogger) ( string) *dlogger {
if !dlogEnabled {
return
}
:= stringStructOf(&)
:= &firstmoduledata
.w.byte(debugLogConstString)
.w.uvarint(uint64(.len))
.w.uvarint(uint64(uintptr(.str) - .etext))
} else {
.w.byte(debugLogString)
var []byte
:= (*slice)(unsafe.Pointer(&))
.array = .str
.len, .cap = .len, .len
if len() > debugLogStringLimit {
= [:debugLogStringLimit]
}
.w.uvarint(uint64(len()))
.w.bytes()
if len() != len() {
.w.byte(debugLogStringOverflow)
.w.uvarint(uint64(len() - len()))
}
}
return
}
func ( *dlogger) ( uintptr) *dlogger {
if !dlogEnabled {
return
}
.w.byte(debugLogPC)
.w.uvarint(uint64())
return
}
type debugLogWriter struct {
write uint64
data debugLogBuf
type debugLogBuf [debugLogBytes]byte
debugLogSyncSize = debugLogHeaderSize + 2*8
)
func ( *debugLogWriter) ( uint64) {
throw("record wrapped around")
}
}
}
func ( *debugLogWriter) (, uint64) {
.tick, .nano = ,
.ensure(debugLogHeaderSize)
.writeFrameAt(.write, 0)
.write += debugLogHeaderSize
.writeUint64LE()
.writeUint64LE()
.r.end = .write
}
func ( *debugLogWriter) ( uint64) {
:= 0
for >= 0x80 {
.buf[] = byte() | 0x80
>>= 7
++
}
.buf[] = byte()
++
.bytes(.buf[:])
}
type debugLogReader struct {
data *debugLogBuf
if .begin+debugLogHeaderSize > .end {
return ^uint64(0)
}
:= uint64(.readUint16LEAt(.begin))
.tick = .readUint64LEAt(.begin + debugLogHeaderSize)
.nano = .readUint64LEAt(.begin + debugLogHeaderSize + 8)
= debugLogSyncSize
}
if .begin+ > .end {
return ^uint64(0)
}
.begin +=
return
}
:= uint64(0)
for == 0 {
if .begin+debugLogHeaderSize > .end {
return ^uint64(0)
}
= uint64(.readUint16LEAt(.begin))
if != 0 {
break
}
if .begin+debugLogSyncSize > .end {
return ^uint64(0)
.tick = .readUint64LEAt(.begin + debugLogHeaderSize)
.nano = .readUint64LEAt(.begin + debugLogHeaderSize + 8)
.begin += debugLogSyncSize
}
:= uint64(.readUint16LEAt(.begin))
= .begin +
.begin += debugLogHeaderSize
= .uvarint() + .tick
= .uvarint() + .nano
= int(.varint())
return
}
func ( *debugLogReader) () uint64 {
var uint64
for := uint(0); ; += 7 {
:= .data[.begin%uint64(len(.data))]
.begin++
|= uint64(&^0x80) <<
if &0x80 == 0 {
break
}
}
return
}
func ( *debugLogReader) () int64 {
:= .uvarint()
var int64
if &1 == 0 {
= int64( >> 1)
} else {
= ^int64( >> 1)
}
return
}
func ( *debugLogReader) () bool {
:= .data[.begin%uint64(len(.data))]
.begin++
switch {
default:
print("<unknown field type ", hex(), " pos ", .begin-1, " end ", .end, ">\n")
return false
case debugLogUnknown:
print("<unknown kind>")
case debugLogBoolTrue:
print(true)
case debugLogBoolFalse:
print(false)
case debugLogInt:
print(.varint())
case debugLogUint:
print(.uvarint())
case debugLogHex, debugLogPtr:
print(hex(.uvarint()))
case debugLogString:
:= .uvarint()
if .begin+ > .end {
.begin = .end
print("<string length corrupted>")
break
}
for > 0 {
:= .data[.begin%uint64(len(.data)):]
if uint64(len()) > {
= [:]
}
.begin += uint64(len())
-= uint64(len())
gwrite()
}
case debugLogConstString:
, := int(.uvarint()), uintptr(.uvarint())
+= firstmoduledata.etext
:= stringStruct{
str: unsafe.Pointer(),
len: ,
}
:= *(*string)(unsafe.Pointer(&))
print()
case debugLogStringOverflow:
print("..(", .uvarint(), " more bytes)..")
case debugLogPC:
printDebugLogPC(uintptr(.uvarint()), false)
case debugLogTraceback:
:= int(.uvarint())
for := 0; < ; ++ {
printDebugLogPC(uintptr(.uvarint()), true)
}
}
return true
}
func () {
if !dlogEnabled {
return
}
:= (*uintptr)(unsafe.Pointer(&allDloggers))
:= (*dlogger)(unsafe.Pointer(atomic.Loaduintptr()))
:= 0
for := ; != nil; = .allLink {
++
}
if == 0 {
printunlock()
return
}
.begin =
.end =
. = .peek()
}
printunlock()
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |