提交 2b83a1f3 编写于 作者: D Derek Parker

Implement reading of float64 value

上级 3993cfe1
......@@ -9,12 +9,14 @@ type FooBar struct {
func main() {
var (
bar = "foo"
foo = 6
sl = []int{1, 2, 3, 4, 5}
arr = [1]int{1}
baz = &FooBar{Baz: 5, Bur: "strum"}
a1 = "foo"
a2 = 6
a3 = 7.23
a4 = []int{1, 2, 3, 4, 5}
a5 = [1]int{1}
a6 = FooBar{Baz: 8, Bur: "word"}
a7 = &FooBar{Baz: 5, Bur: "strum"}
)
fmt.Println(bar, foo, arr, sl, baz)
fmt.Println(a1, a2, a3, a4, a5, a6, a7)
}
......@@ -384,6 +384,17 @@ func (dbp *DebuggedProcess) extractValue(instructions []byte, typ interface{}) (
n := binary.LittleEndian.Uint64(val)
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)
return strconv.FormatFloat(n, 'f', -1, 64), nil
}
return "", fmt.Errorf("could not find value for type %s", typ)
......
......@@ -231,17 +231,18 @@ func TestVariableEvaluation(t *testing.T) {
value string
varType string
}{
{"foo", "6", "int"},
{"a2", "6", "int"},
{"a3", "7.23", "float64"},
}
helper.WithTestProcess(executablePath, t, func(p *proctl.DebuggedProcess) {
pc, _, _ := p.GoSymTable.LineToPC(fp, 19)
pc, _, _ := p.GoSymTable.LineToPC(fp, 21)
_, err := p.Break(uintptr(pc))
assertNoError(err, t, "Break() returned an error")
err = p.Continue()
assertNoError(err, t, "Break() returned an error")
assertNoError(err, t, "Continue() returned an error")
for _, tc := range testcases {
variable, err := p.EvalSymbol(tc.name)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册