diff --git a/_fixtures/testvariables.go b/_fixtures/testvariables.go index 1946f210..d14a38c6 100644 --- a/_fixtures/testvariables.go +++ b/_fixtures/testvariables.go @@ -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() { diff --git a/proctl/variables.go b/proctl/variables.go index 31a37542..8654b639 100644 --- a/proctl/variables.go +++ b/proctl/variables.go @@ -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 - } - - members = append(members, number) + 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 } - - 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) { diff --git a/proctl/variables_test.go b/proctl/variables_test.go index 8dd3c872..5ef1e6d5 100644 --- a/proctl/variables_test.go +++ b/proctl/variables_test.go @@ -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")