Changed api.Variable to have a machine readable value

The new contents of api.Variable are documented in
proc/variables.go.

Implements #243
This commit is contained in:
aarzilli
2015-10-18 19:37:13 +02:00
committed by Derek Parker
parent 91939bc9e7
commit 50b5fc92e2
15 changed files with 1192 additions and 745 deletions

View File

@ -1,7 +1,9 @@
package api
import (
"debug/dwarf"
"debug/gosym"
"fmt"
"strconv"
"github.com/derekparker/delve/proc"
@ -57,12 +59,43 @@ func ConvertThread(th *proc.Thread) *Thread {
}
// convertVar converts an internal variable to an API Variable.
func ConvertVar(v *proc.Variable) Variable {
return Variable{
Name: v.Name,
Value: v.Value,
Type: v.Type,
func ConvertVar(v *proc.Variable) *Variable {
r := Variable{
Addr: v.Addr,
Name: v.Name,
Kind: v.Kind,
Len: v.Len,
Cap: v.Cap,
}
if v.DwarfType != nil {
r.Type = v.DwarfType.String()
}
if v.RealType != nil {
r.RealType = v.RealType.String()
}
if v.Unreadable != nil {
r.Unreadable = v.Unreadable.Error()
}
switch typ := v.RealType.(type) {
case *dwarf.FloatType:
r.Value = strconv.FormatFloat(v.Value.(float64), 'f', -1, int(typ.Size()*8))
default:
if v.Value != nil {
r.Value = fmt.Sprintf("%v", v.Value)
}
}
r.Children = make([]Variable, len(v.Children))
for i := range v.Children {
r.Children[i] = *ConvertVar(&v.Children[i])
}
return &r
}
func ConvertFunction(fn *gosym.Func) *Function {