mirror of
				https://github.com/go-delve/delve.git
				synced 2025-10-31 18:57:18 +08:00 
			
		
		
		
	 12009e9833
			
		
	
	12009e9833
	
	
	
		
			
			Since proc is supposed to work independently from the target architecture it shouldn't use architecture-dependent types, like uintptr. For example when reading a 64bit core file on a 32bit architecture, uintptr will be 32bit but the addresses proc needs to represent will be 64bit.
		
			
				
	
	
		
			54 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			54 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package proc
 | |
| 
 | |
| type goroutineCache struct {
 | |
| 	partialGCache map[int]*G
 | |
| 	allGCache     []*G
 | |
| 
 | |
| 	allgentryAddr, allglenAddr uint64
 | |
| }
 | |
| 
 | |
| func (gcache *goroutineCache) init(bi *BinaryInfo) {
 | |
| 	var err error
 | |
| 
 | |
| 	exeimage := bi.Images[0]
 | |
| 	rdr := exeimage.DwarfReader()
 | |
| 
 | |
| 	gcache.allglenAddr, _ = rdr.AddrFor("runtime.allglen", exeimage.StaticBase, bi.Arch.PtrSize())
 | |
| 
 | |
| 	rdr.Seek(0)
 | |
| 	gcache.allgentryAddr, err = rdr.AddrFor("runtime.allgs", exeimage.StaticBase, bi.Arch.PtrSize())
 | |
| 	if err != nil {
 | |
| 		// try old name (pre Go 1.6)
 | |
| 		gcache.allgentryAddr, _ = rdr.AddrFor("runtime.allg", exeimage.StaticBase, bi.Arch.PtrSize())
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func (gcache *goroutineCache) getRuntimeAllg(bi *BinaryInfo, mem MemoryReadWriter) (uint64, uint64, error) {
 | |
| 	if gcache.allglenAddr == 0 || gcache.allgentryAddr == 0 {
 | |
| 		return 0, 0, ErrNoRuntimeAllG
 | |
| 	}
 | |
| 	allglen, err := readUintRaw(mem, gcache.allglenAddr, int64(bi.Arch.PtrSize()))
 | |
| 	if err != nil {
 | |
| 		return 0, 0, err
 | |
| 	}
 | |
| 
 | |
| 	allgptr, err := readUintRaw(mem, gcache.allgentryAddr, int64(bi.Arch.PtrSize()))
 | |
| 	if err != nil {
 | |
| 		return 0, 0, err
 | |
| 	}
 | |
| 	return allgptr, allglen, nil
 | |
| }
 | |
| 
 | |
| func (gcache *goroutineCache) addGoroutine(g *G) {
 | |
| 	if gcache.partialGCache == nil {
 | |
| 		gcache.partialGCache = make(map[int]*G)
 | |
| 	}
 | |
| 	gcache.partialGCache[g.ID] = g
 | |
| }
 | |
| 
 | |
| // Clear clears the cached contents of the cache for runtime.allgs.
 | |
| func (gcache *goroutineCache) Clear() {
 | |
| 	gcache.partialGCache = nil
 | |
| 	gcache.allGCache = nil
 | |
| }
 |