mirror of
https://github.com/go-delve/delve.git
synced 2025-10-29 17:56:45 +08:00
Improve array evaluation support
* First of a few commits to allow for evaluating arrays of arbitrary types * Adds support for 32 bit integer arrays
This commit is contained in:
@ -24,10 +24,11 @@ func foobar(baz string) {
|
||||
neg = -1
|
||||
i8 = int8(1)
|
||||
f32 = float32(1.2)
|
||||
i32 = [2]int32{1, 2}
|
||||
)
|
||||
|
||||
barfoo()
|
||||
fmt.Println(a1, a2, a3, a4, a5, a6, a7, baz, neg, i8, f32)
|
||||
fmt.Println(a1, a2, a3, a4, a5, a6, a7, baz, neg, i8, f32, i32)
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
@ -559,27 +559,24 @@ func (thread *ThreadContext) readIntSlice(addr uintptr) (string, error) {
|
||||
}
|
||||
|
||||
func (thread *ThreadContext) readIntArray(addr uintptr, t *dwarf.ArrayType) (string, error) {
|
||||
var (
|
||||
number uint64
|
||||
members = make([]uint64, 0, t.ByteSize)
|
||||
)
|
||||
|
||||
val, err := thread.readMemory(addr, uintptr(t.ByteSize))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
buf := bytes.NewBuffer(val)
|
||||
for {
|
||||
err := binary.Read(buf, binary.LittleEndian, &number)
|
||||
if err != nil {
|
||||
break
|
||||
switch t.Type.Size() {
|
||||
case 4:
|
||||
members := *(*[]uint32)(unsafe.Pointer(&val))
|
||||
lptr := (*int)(unsafe.Pointer(uintptr(unsafe.Pointer(&members)) + ptrsize))
|
||||
*lptr = int(t.Count)
|
||||
return fmt.Sprintf("[%d]int32 %d", t.Count, members), nil
|
||||
case 8:
|
||||
members := *(*[]uint64)(unsafe.Pointer(&val))
|
||||
lptr := (*int)(unsafe.Pointer(uintptr(unsafe.Pointer(&members)) + ptrsize))
|
||||
*lptr = int(t.Count)
|
||||
return fmt.Sprintf("[%d]int %d", t.Count, members), nil
|
||||
}
|
||||
|
||||
members = append(members, number)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("[%d]int %d", t.ByteSize/int64(ptrsize), members), nil
|
||||
return "", fmt.Errorf("Could not read array")
|
||||
}
|
||||
|
||||
func (thread *ThreadContext) readInt(addr uintptr, size int64) (string, error) {
|
||||
|
||||
@ -30,10 +30,11 @@ func TestVariableEvaluation(t *testing.T) {
|
||||
{"i8", "1", "int8"},
|
||||
{"f32", "1.2", "float32"},
|
||||
{"a6.Baz", "8", "int"},
|
||||
{"i32", "[2]int32 [1 2]", "[2]int32"},
|
||||
}
|
||||
|
||||
withTestProcess(executablePath, t, func(p *DebuggedProcess) {
|
||||
pc, _, _ := p.GoSymTable.LineToPC(fp, 29)
|
||||
pc, _, _ := p.GoSymTable.LineToPC(fp, 30)
|
||||
|
||||
_, err := p.Break(uintptr(pc))
|
||||
assertNoError(err, t, "Break() returned an error")
|
||||
|
||||
Reference in New Issue
Block a user