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:
Derek Parker
2014-12-28 22:37:18 -06:00
parent 9e8ac82104
commit 623ec5e53d
3 changed files with 16 additions and 17 deletions

View File

@ -24,10 +24,11 @@ func foobar(baz string) {
neg = -1 neg = -1
i8 = int8(1) i8 = int8(1)
f32 = float32(1.2) f32 = float32(1.2)
i32 = [2]int32{1, 2}
) )
barfoo() 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() { func main() {

View File

@ -559,27 +559,24 @@ func (thread *ThreadContext) readIntSlice(addr uintptr) (string, error) {
} }
func (thread *ThreadContext) readIntArray(addr uintptr, t *dwarf.ArrayType) (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)) val, err := thread.readMemory(addr, uintptr(t.ByteSize))
if err != nil { if err != nil {
return "", err return "", err
} }
buf := bytes.NewBuffer(val) switch t.Type.Size() {
for { case 4:
err := binary.Read(buf, binary.LittleEndian, &number) members := *(*[]uint32)(unsafe.Pointer(&val))
if err != nil { lptr := (*int)(unsafe.Pointer(uintptr(unsafe.Pointer(&members)) + ptrsize))
break *lptr = int(t.Count)
} return fmt.Sprintf("[%d]int32 %d", t.Count, members), nil
case 8:
members = append(members, number) 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.Errorf("Could not read array")
return fmt.Sprintf("[%d]int %d", t.ByteSize/int64(ptrsize), members), nil
} }
func (thread *ThreadContext) readInt(addr uintptr, size int64) (string, error) { func (thread *ThreadContext) readInt(addr uintptr, size int64) (string, error) {

View File

@ -30,10 +30,11 @@ func TestVariableEvaluation(t *testing.T) {
{"i8", "1", "int8"}, {"i8", "1", "int8"},
{"f32", "1.2", "float32"}, {"f32", "1.2", "float32"},
{"a6.Baz", "8", "int"}, {"a6.Baz", "8", "int"},
{"i32", "[2]int32 [1 2]", "[2]int32"},
} }
withTestProcess(executablePath, t, func(p *DebuggedProcess) { withTestProcess(executablePath, t, func(p *DebuggedProcess) {
pc, _, _ := p.GoSymTable.LineToPC(fp, 29) pc, _, _ := p.GoSymTable.LineToPC(fp, 30)
_, err := p.Break(uintptr(pc)) _, err := p.Break(uintptr(pc))
assertNoError(err, t, "Break() returned an error") assertNoError(err, t, "Break() returned an error")