diff --git a/_fixtures/testvariables b/_fixtures/testvariables index 354ec676..0381f403 100755 Binary files a/_fixtures/testvariables and b/_fixtures/testvariables differ diff --git a/_fixtures/testvariables.go b/_fixtures/testvariables.go index 07d8530a..54533217 100644 --- a/_fixtures/testvariables.go +++ b/_fixtures/testvariables.go @@ -12,8 +12,8 @@ func main() { a1 = "foo" a2 = 6 a3 = 7.23 - a4 = []int{1, 2, 3, 4, 5} - a5 = [1]int{1} + a4 = [2]int{1, 2} + a5 = []int{1, 2, 3, 4, 5} a6 = FooBar{Baz: 8, Bur: "word"} a7 = &FooBar{Baz: 5, Bur: "strum"} ) diff --git a/proctl/proctl_linux_amd64.go b/proctl/proctl_linux_amd64.go index c036a603..a3df5431 100644 --- a/proctl/proctl_linux_amd64.go +++ b/proctl/proctl_linux_amd64.go @@ -11,6 +11,7 @@ import ( "fmt" "os" "strconv" + "strings" "syscall" "unsafe" @@ -376,9 +377,15 @@ func (dbp *DebuggedProcess) extractValue(instructions []byte, typ interface{}) ( offset := uintptr(int64(regs.Rsp) + off) - switch typ.(type) { + switch t := typ.(type) { case *dwarf.StructType: - return dbp.readString(offset) + ty := strings.Split(t.String(), " ") + switch ty[1] { + case "string": + return dbp.readString(offset) + } + case *dwarf.ArrayType: + return dbp.readIntArray(offset, t) case *dwarf.IntType: return dbp.readInt(offset) case *dwarf.FloatType: @@ -407,6 +414,32 @@ func (dbp *DebuggedProcess) readString(addr uintptr) (string, error) { return str, nil } +func (dbp *DebuggedProcess) readIntArray(addr uintptr, t *dwarf.ArrayType) (string, error) { + var ( + number uint64 + members = make([]uint64, 0, t.Size()/8) + ) + + val, err := dbp.readMemory(addr, uintptr(t.Size())) + 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) + } + + str := fmt.Sprintf("%s %d", t.String(), members) + + return str, err +} + func (dbp *DebuggedProcess) readInt(addr uintptr) (string, error) { val, err := dbp.readMemory(addr, 8) if err != nil { diff --git a/proctl/proctl_test.go b/proctl/proctl_test.go index 523bb350..91838803 100644 --- a/proctl/proctl_test.go +++ b/proctl/proctl_test.go @@ -234,6 +234,7 @@ func TestVariableEvaluation(t *testing.T) { {"a1", "foo", "struct string"}, {"a2", "6", "int"}, {"a3", "7.23", "float64"}, + {"a4", "[2]int [1 2]", "[2]int"}, } helper.WithTestProcess(executablePath, t, func(p *proctl.DebuggedProcess) {