mirror of
https://github.com/go-delve/delve.git
synced 2025-10-28 04:35:19 +08:00
Support 32 bit floats
This commit is contained in:
@ -18,9 +18,10 @@ func foobar(baz string) {
|
||||
a7 = &FooBar{Baz: 5, Bur: "strum"}
|
||||
neg = -1
|
||||
i8 = int8(1)
|
||||
f32 = float32(1.2)
|
||||
)
|
||||
|
||||
fmt.Println(a1, a2, a3, a4, a5, a6, a7, baz, neg, i8)
|
||||
fmt.Println(a1, a2, a3, a4, a5, a6, a7, baz, neg, i8, f32)
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
@ -141,7 +141,7 @@ func (thread *ThreadContext) extractValue(instructions []byte, off int64, typ in
|
||||
case *dwarf.IntType:
|
||||
return thread.readInt(offaddr, t.ByteSize)
|
||||
case *dwarf.FloatType:
|
||||
return thread.readFloat64(offaddr)
|
||||
return thread.readFloat(offaddr, t.ByteSize)
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("could not find value for type %s", typ)
|
||||
@ -242,16 +242,25 @@ func (thread *ThreadContext) readInt(addr uintptr, size int64) (string, error) {
|
||||
return strconv.Itoa(n), nil
|
||||
}
|
||||
|
||||
func (thread *ThreadContext) readFloat64(addr uintptr) (string, error) {
|
||||
var n float64
|
||||
val, err := thread.readMemory(addr, 8)
|
||||
func (thread *ThreadContext) readFloat(addr uintptr, size int64) (string, error) {
|
||||
val, err := thread.readMemory(addr, uintptr(size))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
buf := bytes.NewBuffer(val)
|
||||
binary.Read(buf, binary.LittleEndian, &n)
|
||||
|
||||
return strconv.FormatFloat(n, 'f', -1, 64), nil
|
||||
switch size {
|
||||
case 4:
|
||||
n := float32(0)
|
||||
binary.Read(buf, binary.LittleEndian, &n)
|
||||
return strconv.FormatFloat(float64(n), 'f', -1, int(size)*8), nil
|
||||
case 8:
|
||||
n := float64(0)
|
||||
binary.Read(buf, binary.LittleEndian, &n)
|
||||
return strconv.FormatFloat(n, 'f', -1, int(size)*8), nil
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("could not read float")
|
||||
}
|
||||
|
||||
func (thread *ThreadContext) readMemory(addr uintptr, size uintptr) ([]byte, error) {
|
||||
|
||||
@ -31,10 +31,11 @@ func TestVariableEvaluation(t *testing.T) {
|
||||
{"baz", "bazburzum", "struct string"},
|
||||
{"neg", "-1", "int"},
|
||||
{"i8", "1", "int8"},
|
||||
{"f32", "1.2", "float32"},
|
||||
}
|
||||
|
||||
helper.WithTestProcess(executablePath, t, func(p *proctl.DebuggedProcess) {
|
||||
pc, _, _ := p.GoSymTable.LineToPC(fp, 23)
|
||||
pc, _, _ := p.GoSymTable.LineToPC(fp, 24)
|
||||
|
||||
_, err := p.Break(uintptr(pc))
|
||||
assertNoError(err, t, "Break() returned an error")
|
||||
|
||||
Reference in New Issue
Block a user