mirror of
https://github.com/go-delve/delve.git
synced 2025-10-29 01:27:16 +08:00
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:
@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user