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

Refactor: split read* into seperate functions

上级 2b83a1f3
...@@ -373,31 +373,38 @@ func (dbp *DebuggedProcess) extractValue(instructions []byte, typ interface{}) ( ...@@ -373,31 +373,38 @@ 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)
val, err := dbp.readMemory(addr, 8) case *dwarf.FloatType:
if err != nil { return dbp.readFloat64(offset)
return "", err }
}
n := binary.LittleEndian.Uint64(val) return "", fmt.Errorf("could not find value for type %s", typ)
}
return strconv.Itoa(int(n)), nil func (dbp *DebuggedProcess) readInt(addr uintptr) (string, error) {
case *dwarf.FloatType: val, err := dbp.readMemory(addr, 8)
var n float64 if err != nil {
addr := uintptr(int64(regs.Rsp) + off) return "", err
val, err := dbp.readMemory(addr, 8) }
if err != nil {
return "", err n := binary.LittleEndian.Uint64(val)
}
buf := bytes.NewBuffer(val)
binary.Read(buf, binary.LittleEndian, &n)
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) { 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.
先完成此消息的编辑!
想要评论请 注册