github.com/Rookout/GoSDK@v0.1.48/pkg/services/instrumentation/module/module.go (about)

     1  package module
     2  
     3  import "unsafe"
     4  
     5  
     6  
     7  //go:linkname firstModuleData runtime.firstmoduledata
     8  var firstModuleData moduledata
     9  
    10  //go:linkname FuncName runtime.funcname
    11  //goland:noinspection GoUnusedParameter
    12  func FuncName(f FuncInfo) string
    13  
    14  //go:linkname FindFunc runtime.findfunc
    15  func FindFunc(_ uintptr) FuncInfo
    16  
    17  //go:linkname add runtime.add
    18  func add(_ unsafe.Pointer, _ uintptr) unsafe.Pointer
    19  
    20  //go:linkname funcMaxSPDelta runtime.funcMaxSPDelta
    21  func funcMaxSPDelta(_ FuncInfo) int32
    22  
    23  //go:linkname step runtime.step
    24  //goland:noinspection GoUnusedParameter
    25  func step(p []byte, pc *uintptr, val *int32, first bool) (newp []byte, ok bool)
    26  
    27  type FuncID uint8
    28  
    29  
    30  
    31  
    32  
    33  
    34  
    35  
    36  
    37  type findfuncbucket struct {
    38  	idx        uint32
    39  	subbuckets [16]byte
    40  }
    41  
    42  type ptabEntry struct {
    43  	name nameOff
    44  	typ  TypeOff
    45  }
    46  
    47  type nameOff int32
    48  
    49  type TypeOff int32
    50  
    51  type itab struct {
    52  	inter *interfacetype
    53  	_type *_type
    54  	hash  uint32 
    55  	_     [4]byte
    56  	fun   [1]uintptr 
    57  }
    58  
    59  type _type struct {
    60  	size       uintptr
    61  	ptrdata    uintptr 
    62  	hash       uint32
    63  	tflag      tflag
    64  	align      uint8
    65  	fieldAlign uint8
    66  	kind       uint8
    67  	
    68  	
    69  	equal func(unsafe.Pointer, unsafe.Pointer) bool
    70  	
    71  	
    72  	
    73  	gcdata    *byte
    74  	str       nameOff
    75  	ptrToThis TypeOff
    76  }
    77  
    78  type tflag uint8
    79  
    80  type interfacetype struct {
    81  	typ     _type
    82  	pkgpath name
    83  	mhdr    []imethod
    84  }
    85  
    86  type name struct {
    87  	bytes *byte
    88  }
    89  
    90  type imethod struct {
    91  	name nameOff
    92  	ityp TypeOff
    93  }
    94  
    95  type modulehash struct {
    96  	modulename   string
    97  	linktimehash string
    98  	runtimehash  *string
    99  }
   100  
   101  type bitvector struct {
   102  	n        int32 
   103  	bytedata *uint8
   104  }
   105  
   106  type FuncInfo struct {
   107  	*_func
   108  	datap *moduledata
   109  }
   110  
   111  const minfunc = 16 
   112  
   113  const pcbucketsize = 256 * minfunc 
   114  
   115  //go:linkname pcdatastart runtime.pcdatastart
   116  func pcdatastart(_ FuncInfo, _ uint32) uint32
   117  
   118  //go:linkname funcdata runtime.funcdata
   119  func funcdata(f FuncInfo, i uint8) unsafe.Pointer
   120  
   121  //go:linkname pcdatavalue1 runtime.pcdatavalue1
   122  func pcdatavalue1(f FuncInfo, table uint32, targetpc uintptr, cache *PCValueCache, strict bool) int32
   123  
   124  //go:linkname funcspdelta runtime.funcspdelta
   125  func funcspdelta(f FuncInfo, targetpc uintptr, cache *PCValueCache) int32
   126  
   127  //go:linkname funcline1 runtime.funcline1
   128  func funcline1(f FuncInfo, targetpc uintptr, strict bool) (file string, line int32)
   129  
   130  
   131  
   132  type pcvalueCacheEnt struct {
   133  	
   134  	targetpc uintptr
   135  	off      uint32
   136  	
   137  	val int32
   138  }
   139  
   140  type PCValueCache struct {
   141  	entries [2][8]pcvalueCacheEnt
   142  }
   143  
   144  //go:linkname pcvalue runtime.pcvalue
   145  func pcvalue(f FuncInfo, off uint32, targetpc uintptr, cache *PCValueCache, strict bool) (int32, uintptr)
   146  
   147  var moduleDatas []*moduledata
   148  
   149  func loadModuleDatas() {
   150  	if moduleDatas != nil {
   151  		return
   152  	}
   153  
   154  	for moduleData := &firstModuleData; moduleData != nil; moduleData = moduleData.next {
   155  		moduleDatas = append(moduleDatas, moduleData)
   156  	}
   157  }
   158  
   159  func Init() {
   160  	loadModuleDatas()
   161  }
   162  
   163  func FindModuleDataForType(typeAddr uint64) *moduledata {
   164  	for i := range moduleDatas {
   165  		if typeAddr >= uint64(moduleDatas[i].types) && typeAddr < uint64(moduleDatas[i].etypes) {
   166  			return moduleDatas[i]
   167  		}
   168  	}
   169  	return nil
   170  }
   171  
   172  func (md *moduledata) GetFirstPC() uint64 {
   173  	return uint64(md.text)
   174  }
   175  
   176  func (md *moduledata) GetTypesAddr() uint64 {
   177  	return uint64(md.types)
   178  }