提交 a22d5632 编写于 作者: D Derek Parker

Refactor: split read* into seperate functions

上级 2b83a1f3
......@@ -373,31 +373,38 @@ func (dbp *DebuggedProcess) extractValue(instructions []byte, typ interface{}) (
return "", err
}
offset := uintptr(int64(regs.Rsp) + off)
switch typ.(type) {
case *dwarf.IntType:
addr := uintptr(int64(regs.Rsp) + off)
val, err := dbp.readMemory(addr, 8)
if err != nil {
return "", err
}
return dbp.readInt(offset)
case *dwarf.FloatType:
return dbp.readFloat64(offset)
}
n := binary.LittleEndian.Uint64(val)
return "", fmt.Errorf("could not find value for type %s", typ)
}
return strconv.Itoa(int(n)), nil
case *dwarf.FloatType:
var n float64
addr := uintptr(int64(regs.Rsp) + off)
val, err := dbp.readMemory(addr, 8)
if err != nil {
return "", err
}
buf := bytes.NewBuffer(val)
binary.Read(buf, binary.LittleEndian, &n)
func (dbp *DebuggedProcess) readInt(addr uintptr) (string, error) {
val, err := dbp.readMemory(addr, 8)
if err != nil {
return "", err
}
n := binary.LittleEndian.Uint64(val)
return strconv.FormatFloat(n, 'f', -1, 64), nil
return strconv.Itoa(int(n)), nil
}
func (dbp *DebuggedProcess) readFloat64(addr uintptr) (string, error) {
var n float64
val, err := dbp.readMemory(addr, 8)
if err != nil {
return "", err
}
buf := bytes.NewBuffer(val)
binary.Read(buf, binary.LittleEndian, &n)
return "", fmt.Errorf("could not find value for type %s", typ)
return strconv.FormatFloat(n, 'f', -1, 64), nil
}
func (dbp *DebuggedProcess) readMemory(addr uintptr, size uintptr) ([]byte, error) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册