mirror of
				https://github.com/go-delve/delve.git
				synced 2025-11-04 14:36:47 +08:00 
			
		
		
		
	Refactor: split read* into seperate functions
This commit is contained in:
		@ -373,9 +373,19 @@ func (dbp *DebuggedProcess) extractValue(instructions []byte, typ interface{}) (
 | 
				
			|||||||
		return "", err
 | 
							return "", err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						offset := uintptr(int64(regs.Rsp) + off)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	switch typ.(type) {
 | 
						switch typ.(type) {
 | 
				
			||||||
	case *dwarf.IntType:
 | 
						case *dwarf.IntType:
 | 
				
			||||||
		addr := uintptr(int64(regs.Rsp) + off)
 | 
							return dbp.readInt(offset)
 | 
				
			||||||
 | 
						case *dwarf.FloatType:
 | 
				
			||||||
 | 
							return dbp.readFloat64(offset)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return "", fmt.Errorf("could not find value for type %s", typ)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (dbp *DebuggedProcess) readInt(addr uintptr) (string, error) {
 | 
				
			||||||
	val, err := dbp.readMemory(addr, 8)
 | 
						val, err := dbp.readMemory(addr, 8)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return "", err
 | 
							return "", err
 | 
				
			||||||
@ -384,9 +394,9 @@ func (dbp *DebuggedProcess) extractValue(instructions []byte, typ interface{}) (
 | 
				
			|||||||
	n := binary.LittleEndian.Uint64(val)
 | 
						n := binary.LittleEndian.Uint64(val)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return strconv.Itoa(int(n)), nil
 | 
						return strconv.Itoa(int(n)), nil
 | 
				
			||||||
	case *dwarf.FloatType:
 | 
					}
 | 
				
			||||||
 | 
					func (dbp *DebuggedProcess) readFloat64(addr uintptr) (string, error) {
 | 
				
			||||||
	var n float64
 | 
						var n float64
 | 
				
			||||||
		addr := uintptr(int64(regs.Rsp) + off)
 | 
					 | 
				
			||||||
	val, err := dbp.readMemory(addr, 8)
 | 
						val, err := dbp.readMemory(addr, 8)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return "", err
 | 
							return "", err
 | 
				
			||||||
@ -395,9 +405,6 @@ func (dbp *DebuggedProcess) extractValue(instructions []byte, typ interface{}) (
 | 
				
			|||||||
	binary.Read(buf, binary.LittleEndian, &n)
 | 
						binary.Read(buf, binary.LittleEndian, &n)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return strconv.FormatFloat(n, 'f', -1, 64), nil
 | 
						return strconv.FormatFloat(n, 'f', -1, 64), nil
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return "", fmt.Errorf("could not find value for type %s", typ)
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (dbp *DebuggedProcess) readMemory(addr uintptr, size uintptr) ([]byte, error) {
 | 
					func (dbp *DebuggedProcess) readMemory(addr uintptr, size uintptr) ([]byte, error) {
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user