Implement basic array evaling
This commit is contained in:
parent
f8abe30aa7
commit
21025b2fc6
Binary file not shown.
@ -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"}
|
||||
)
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user