-
Notifications
You must be signed in to change notification settings - Fork 15
/
DebugVarsGui.ahk
374 lines (330 loc) · 10.3 KB
/
DebugVarsGui.ahk
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
#Include VarTreeGui.ahk
#Include VarEditGui.ahk
DvInspectProperty(dbg, fullname, extra_args:="", show_opt:="") {
dbg.feature_set("-n max_depth -v 1")
; 1MB seems reasonably permissive. Note that -m 0 (unlimited
; according to the spec) doesn't work with v1.1.24.02 and earlier.
response := dbg.property_get("-m 1048576 -n " fullname (extra_args="" ? "" : " " extra_args))
dbg.feature_set("-n max_depth -v 0")
prop := DvLoadXml(response).selectSingleNode("/response/property")
if (prop.getAttribute("name") = "(invalid)") {
MsgBox "Invalid variable name: " fullname,, "Icon!"
return false
}
type := prop.getAttribute("type")
if (type != "object") {
isReadOnly := prop.getAttribute("facet") = "Builtin"
value := DBGp_Base64UTF8Decode(prop.text)
dv := DebugVarGui(dbg, {name: fullname, value: value, type: type, readonly: isReadOnly})
}
else {
dv := DebugVarsGui(DvPropertyNode(dbg, prop))
}
dv.Show(show_opt)
}
class DebugVarGui extends VarEditGui
{
__New(dbg, var) {
super.__New(var)
this.dbg := dbg
}
OnSave(value, type) {
DvSetProperty(this.dbg, this.var.name, value, type)
this.var.value := value
this.var.type := type
DvRefreshAll()
}
}
DvSetProperty(dbg, fullname, value, type) {
if (type = "integer")
value := format("{:i}", value) ; Force decimal format.
if (type = "integer" || type = "float") && dbg.no_base64_numbers
data := value
else
data := DBGp_Base64UTF8Encode(value)
return dbg.property_set("-n " fullname " -t " type " -- " data)
}
class DvNodeBase
{
static prototype.expandable := false
static prototype.children := ""
expanded {
set {
if value {
; Expanded for the first time: populate.
this.children := this.GetChildren()
this.DefineProp 'expanded', {value: true}
}
return value
}
get {
return false
}
}
SetValue(value) {
return false
}
Clone() {
node := super.Clone()
node.children := this.GetChildren()
return node
}
Update(tlv) {
if !this.HasProp('children')
return
for child in this.children
child.Update(tlv)
}
}
class DvPropertyParentNode extends DvNodeBase
{
UpdateChildren(tlv, props) {
children := this.children
if !children {
if !props.length
return
this.children := children := []
}
np := 0, nc := 1
loop {
if (np < props.length) {
prop := props.item(np)
if (nc > children.Length() || prop.getAttribute("name") < children[nc].name) {
tlv.InsertChild(this, nc, DvPropertyNode(this.dbg, prop))
++nc, ++np
continue
}
if (prop.getAttribute("name") = children[nc].name) {
children[nc].Update(tlv, prop)
++nc, ++np
continue
}
}
if (nc > children.Length())
break
tlv.RemoveChild(this, nc)
}
}
}
class DvPropertyNode extends DvPropertyParentNode
{
__new(dbg, prop) {
this.dbg := dbg
this.fullname := prop.getAttribute("fullname")
this.name := prop.getAttribute("name")
this.xml := prop
props := prop.selectNodes("property")
if props.length {
this.children := DvPropertyNode.FromXmlNodes(props, dbg)
this.DefineProp 'expanded', {value: false}
}
else {
this._value := DBGp_Base64UTF8Decode(prop.text)
}
this.values := [this.name, this.GetValueString()]
}
value {
set {
this._value := value
this.values[2] := this.GetValueString()
return value
}
get {
return this._value
}
}
static FromXmlNodes(props, dbg) {
nodes := []
for prop in props
nodes.Push(DvPropertyNode(dbg, prop))
return nodes
}
expandable {
get {
return this.xml.getAttribute("children")
}
}
GetProperty() {
this.dbg.feature_set("-n max_depth -v 1")
response := this.dbg.property_get("-n " this.fullname)
this.dbg.feature_set("-n max_depth -v 0")
xml := DvLoadXml(response)
return this.xml := xml.selectSingleNode("/response/property")
}
GetChildren() {
prop := this.GetProperty()
props := prop.selectNodes("property")
return DvPropertyNode.FromXmlNodes(props, this.dbg)
}
GetValueString() {
if (cn := this.xml.getAttribute("classname"))
return cn
utf8_len := StrPut(this.value, "UTF-8") - 1
return this.value (this.xml.getAttribute("size") > utf8_len ? "..." : "")
}
GetWindowTitle() {
title := "Inspector - " this.fullname
if prop := this.xml {
if !(type := prop.getAttribute("classname"))
type := prop.getAttribute("type")
title .= " (" type ")"
}
return title
}
SetValue(value) {
type := this.xml.getAttribute("type") ; Try to match type of previous value.
if (type = "float" || type = "integer") && value+0 != ""
type := InStr(value, ".") ? "float" : "integer"
else
type := "string"
try
response := DvSetProperty(this.dbg, this.xml.getAttribute("fullname"), value, type)
catch DbgpError
return false
else if InStr(response, 'success="0"')
return false
; Update .xml for @classname and @children, and in case the value
; differs from what we set (e.g. for setting A_KeyDelay in v2).
this.GetProperty()
this.value := value := DBGp_Base64UTF8Decode(this.xml.text)
}
Update(tlv, prop:="") {
had_children := this.xml.getAttribute("children")
if !prop || prop.getAttribute("children") && !prop.selectSingleNode("property")
prop := this.GetProperty()
else
this.xml := prop
props := prop.selectNodes("property")
value2 := this.values[2]
this.value := props.length ? "" : DBGp_Base64UTF8Decode(prop.text)
if !(this.values[2] "" == "" value2) ; Prevent unnecessary redraw and flicker.
|| (had_children != prop.getAttribute("children"))
tlv.RefreshValues(this)
this.UpdateChildren(tlv, props)
}
}
class DvContextNode extends DvPropertyParentNode
{
static prototype.expandable := true
__new(dbg, context) {
this.dbg := dbg
this.context := context
}
values {
get {
return [this.GetWindowTitle(), ""]
}
}
GetProperties() {
response := this.dbg.context_get("-c " this.context)
xml := DvLoadXml(response)
return xml.selectNodes("/response/property")
}
GetChildren() {
props := this.GetProperties()
return DvPropertyNode.FromXmlNodes(props, this.dbg)
}
GetWindowTitle() {
return this.context=0 ? "Local vars" : "Global vars"
}
Update(tlv) {
props := this.GetProperties()
this.UpdateChildren(tlv, props)
}
}
class Dv2ContextsNode extends DvNodeBase
{
static prototype.expandable := true
__new(dbg) {
this.dbg := dbg
}
GetChildren() {
children := []
Loop 2 {
children.Push(node := DvContextNode(this.dbg, A_Index-1))
node.expanded := true
}
return children
}
GetWindowTitle() {
return "Variables"
}
}
class DebugVarsGui extends VarTreeGui
{
AddVarTree(p*) => DebugVarsGui.Control(this, p*)
class Control extends VarTreeGui.Control
{
LV_Key_F5() {
this.Gui.Refresh()
}
LV_Key_Enter(r, node) {
DvInspectProperty(node.dbg, node.xml.getAttribute("fullname"))
}
}
OnContextMenu(node, isRightClick, x, y) {
m := Menu()
if !(node is DvPropertyNode)
m.Add "New window", (*) => this.NewWindow(node)
else
m.Add "Inspect", (*) => this.InspectNode(node)
m.Add "Refresh", (*) => this.Refresh()
mr := Menu()
static refresh_intervals := Map("Off", 0, "0.5 s", 500, "1.0 s", 1000, "5.0 s", 5000)
for text, interval in refresh_intervals {
mr.Add text, ((n, *) => this.SetAutoRefresh(n)).Bind(interval)
if interval = this.refresh_interval
mr.Check text
}
m.Add "Auto refresh", mr
m.Show x, y
}
OnDoubleClick(node) {
if !(node is DvPropertyNode)
this.NewWindow(node)
else
this.InspectNode(node)
}
InspectNode(node) {
DvInspectProperty(node.dbg, node.xml.getAttribute("fullname"))
}
NewWindow(node) {
dv := DebugVarsGui(node.Clone())
dv.Show()
}
refresh_interval := 0
SetAutoRefresh(interval) {
this.refresh_interval := interval
timer := this.HasProp('timer') ? this.timer : ""
if !interval {
if timer {
SetTimer timer, 0
this.timer := ""
}
return
}
if !timer
this.timer := timer := ObjBindMethod(this, "Refresh", true)
SetTimer timer, interval
}
Refresh(auto:=false) {
if auto && !DllCall("IsWindowVisible", "ptr", this.hwnd)
; @Debug-Output => DebugVarsGui refreshed when not visible; turning off now.
return this.SetAutoRefresh(0)
this.TLV.root.Update(this.TLV)
this.Title := this.TLV.root.GetWindowTitle()
}
}
DvRefreshAll() {
for hwnd in WinGetList("ahk_class AutoHotkeyGui ahk_pid " ProcessExist())
if (g := GuiFromHwnd(hwnd)) && g is DebugVarsGui
g.Refresh()
}
DvLoadXml(data) {
o := ComObject("MSXML2.DOMDocument")
o.async := false
o.setProperty("SelectionLanguage", "XPath")
o.loadXml(data)
return o
}