-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathvariable.go
131 lines (102 loc) · 3.04 KB
/
variable.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Copyright 2013 Chris McGee <[email protected]>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gdblib
import ()
type VarCreateParms struct {
// Name for the new variable or empty for gdb to assign a new unique variable name.
Name string
// Frame address can be a valid frame id, "*" (current frame), or "@" (floating variable)
// An empty frame address defaults to the current frame.
FrameAddr string
// Expression to assign this variable
Expression string
}
type VarCreateResult struct {
Name string `json:"name"`
NumChild string `json:"numchild"`
Value string `json:"value"`
Type string `json:"type"`
ThreadId string `json:"thread-id"`
HasMore string `json:"has_more"`
}
func (gdb *GDB) VarCreate(parms VarCreateParms) (*VarCreateResult, error) {
descriptor := cmdDescr{}
descriptor.cmd = "-var-create"
if parms.Name != "" {
descriptor.cmd = descriptor.cmd + " " + parms.Name
} else {
descriptor.cmd = descriptor.cmd + " -"
}
if parms.FrameAddr == "" {
descriptor.cmd = descriptor.cmd + " *"
} else {
descriptor.cmd = descriptor.cmd + " " + parms.FrameAddr
}
descriptor.cmd = descriptor.cmd + " " + parms.Expression
descriptor.response = make(chan cmdResultRecord)
gdb.input <- descriptor
result := <-descriptor.response
resultObj := VarCreateResult{}
err := parseResult(result, &resultObj)
if err != nil {
return nil, err
}
return &resultObj, nil
}
type VarDeleteParms struct {
Name string
ChildrenOnly bool
}
func (gdb *GDB) VarDelete(parms VarDeleteParms) error {
descriptor := cmdDescr{}
descriptor.cmd = "-var-delete"
if parms.ChildrenOnly {
descriptor.cmd = descriptor.cmd + " -c"
}
descriptor.cmd = descriptor.cmd + " " + parms.Name
descriptor.response = make(chan cmdResultRecord)
gdb.input <- descriptor
result := <-descriptor.response
err := parseResult(result, nil)
return err
}
type VarListChildrenParms struct {
Name string
AllValues bool
From string
To string
}
type VarListChildrenResult struct {
NumChild string `json:"num-child"`
Children []ChildVar `json:"children"`
}
type ChildVar struct {
Name string `json:"name"`
Exp string `json:"exp"`
NumChild string `json:"numchild"`
Type string `json:"type"`
Value string `json:"value"`
ThreadId string `json:"thread-id"`
Frozen string `json:"frozen"`
}
func (gdb *GDB) VarListChildren(parms VarListChildrenParms) (*VarListChildrenResult, error) {
descriptor := cmdDescr{}
descriptor.cmd = "-var-list-children"
if parms.AllValues {
descriptor.cmd = descriptor.cmd + " --all-values"
}
descriptor.cmd = descriptor.cmd + " " + parms.Name
if parms.From != "" && parms.To != "" {
descriptor.cmd = descriptor.cmd + " " + parms.From + " " + parms.To
}
descriptor.response = make(chan cmdResultRecord)
gdb.input <- descriptor
result := <-descriptor.response
resultObj := VarListChildrenResult{}
err := parseResult(result, &resultObj)
if err != nil {
return nil, err
}
return &resultObj, nil
}