Support for uint and boolean types

This commit is contained in:
epipho
2015-01-19 22:18:17 -05:00
parent 67ad85feec
commit 056df44318
3 changed files with 73 additions and 13 deletions

View File

@ -616,8 +616,12 @@ func (thread *ThreadContext) extractValue(instructions []byte, addr int64, typ i
return thread.readIntArray(ptraddress, t)
case *dwarf.IntType:
return thread.readInt(ptraddress, t.ByteSize)
case *dwarf.UintType:
return thread.readUint(ptraddress, t.ByteSize)
case *dwarf.FloatType:
return thread.readFloat(ptraddress, t.ByteSize)
case *dwarf.BoolType:
return thread.readBool(ptraddress)
}
return "", fmt.Errorf("could not find value for type %s", typ)
@ -693,7 +697,7 @@ func (thread *ThreadContext) readIntArray(addr uintptr, t *dwarf.ArrayType) (str
}
func (thread *ThreadContext) readInt(addr uintptr, size int64) (string, error) {
var n int
var n int64
val, err := thread.readMemory(addr, uintptr(size))
if err != nil {
@ -702,16 +706,38 @@ func (thread *ThreadContext) readInt(addr uintptr, size int64) (string, error) {
switch size {
case 1:
n = int(val[0])
n = int64(val[0])
case 2:
n = int(binary.LittleEndian.Uint16(val))
n = int64(binary.LittleEndian.Uint16(val))
case 4:
n = int(binary.LittleEndian.Uint32(val))
n = int64(binary.LittleEndian.Uint32(val))
case 8:
n = int(binary.LittleEndian.Uint64(val))
n = int64(binary.LittleEndian.Uint64(val))
}
return strconv.Itoa(n), nil
return strconv.FormatInt(n, 10), nil
}
func (thread *ThreadContext) readUint(addr uintptr, size int64) (string, error) {
var n uint64
val, err := thread.readMemory(addr, uintptr(size))
if err != nil {
return "", err
}
switch size {
case 1:
n = uint64(val[0])
case 2:
n = uint64(binary.LittleEndian.Uint16(val))
case 4:
n = uint64(binary.LittleEndian.Uint32(val))
case 8:
n = uint64(binary.LittleEndian.Uint64(val))
}
return strconv.FormatUint(n, 10), nil
}
func (thread *ThreadContext) readFloat(addr uintptr, size int64) (string, error) {
@ -735,6 +761,19 @@ func (thread *ThreadContext) readFloat(addr uintptr, size int64) (string, error)
return "", fmt.Errorf("could not read float")
}
func (thread *ThreadContext) readBool(addr uintptr) (string, error) {
val, err := thread.readMemory(addr, uintptr(1))
if err != nil {
return "", err
}
if val[0] == 0 {
return "false", nil
}
return "true", nil
}
func (thread *ThreadContext) readMemory(addr uintptr, size uintptr) ([]byte, error) {
buf := make([]byte, size)
@ -770,7 +809,8 @@ func (thread *ThreadContext) variablesByTag(tag dwarf.Tag) ([]*Variable, error)
if entry.Tag == tag {
val, err := thread.extractVariableFromEntry(entry)
if err != nil {
return nil, err
// skip variables that we can't parse yet
continue
}
vars = append(vars, val)