forked from fantaisie-software/purebasic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHistory.pb
394 lines (304 loc) · 18.4 KB
/
History.pb
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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
; --------------------------------------------------------------------------------------------
; Copyright (c) Fantaisie Software. All rights reserved.
; Dual licensed under the GPL and Fantaisie Software licenses.
; See LICENSE and LICENSE-FANTAISIE in the project root for license information.
; --------------------------------------------------------------------------------------------
Procedure HistoryWindowEvents(*Debugger.DebuggerData, EventID)
If EventID = #PB_Event_Gadget
EventGadgetID = EventGadget()
If EventGadgetID = *Debugger\Gadgets[#DEBUGGER_GADGET_History_Update]
Command.CommandInfo\Command = #COMMAND_GetHistory
SendDebuggerCommand(*Debugger, @Command)
ElseIf EventGadgetID = *Debugger\Gadgets[#DEBUGGER_GADGET_History_Reset]
For i = 0 To *Debugger\NbProcedures - 1
If GetGadgetItemState(*Debugger\Gadgets[#DEBUGGER_GADGET_History_Stats], i) & #PB_ListIcon_Selected
Command.CommandInfo\Command = #COMMAND_ResetProcedureStats
Command\Value1 = i
SendDebuggerCommand(*Debugger, @Command)
EndIf
Next i
Command.CommandInfo\Command = #COMMAND_GetProcedureStats
SendDebuggerCommand(*Debugger, @Command)
ElseIf EventGadgetID = *Debugger\Gadgets[#DEBUGGER_GADGET_History_ResetAll]
Command.CommandInfo\Command = #COMMAND_ResetProcedureStats
Command\Value1 = -1
SendDebuggerCommand(*Debugger, @Command)
Command.CommandInfo\Command = #COMMAND_GetProcedureStats
SendDebuggerCommand(*Debugger, @Command)
ElseIf EventGadgetID = *Debugger\Gadgets[#DEBUGGER_GADGET_History_UpdateStats]
Command.CommandInfo\Command = #COMMAND_GetProcedureStats
SendDebuggerCommand(*Debugger, @Command)
ElseIf *Debugger\History
*history.Debugger_History = *Debugger\History
For i = 0 To *Debugger\HistorySize-1
If EventGadgetID = *history\item[i]\Show
HistoryWindowEvents(*Debugger, #PB_Event_SizeWindow) ; resize the gadgets accordingly
Break
ElseIf EventGadgetID = *history\item[i]\Variables
VariableGadget_Event(*history\item[i]\Variables)
EndIf
Next i
EndIf
ElseIf EventID = #PB_Event_SizeWindow
ResizeGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_History_Panel], 10, 10, WindowWidth(*Debugger\Windows[#DEBUGGER_WINDOW_History])-20, WindowHeight(*Debugger\Windows[#DEBUGGER_WINDOW_History])-20)
Width = GetPanelWidth(*Debugger\Gadgets[#DEBUGGER_GADGET_History_Panel])
Height = GetPanelHeight(*Debugger\Gadgets[#DEBUGGER_GADGET_History_Panel])
GetRequiredSize(*Debugger\Gadgets[#DEBUGGER_GADGET_History_Update], @ButtonWidth, @ButtonHeight)
ButtonWidth = Max(ButtonWidth, 120)
ResizeGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_History_ScrollArea], 10, 10, Width-20, Height-30-ButtonHeight)
ResizeGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_History_Update], Width-10-ButtonWidth, Height-10-ButtonHeight, ButtonWidth, ButtonHeight)
ResizeGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_History_Updating], 10, 10, Width-20, Height-30-ButtonHeight)
Top = 10
InnerWidth = Width - 70
ContainerWidth = Width - 55
ContainerHeight = ButtonHeight * 3 + 25
If *Debugger\History
*history.Debugger_History = *Debugger\History
If *Debugger\HistorySize > 0
ButtonWidth = Max(110, GetRequiredWidth(*history\item[0]\Show))
EndIf
For i = 0 To *Debugger\HistorySize-1
ResizeGadget(*history\item[i]\Line, 5, 5, InnerWidth-15-ButtonWidth, ButtonHeight)
ResizeGadget(*history\item[i]\File, 5, 5+ButtonHeight, InnerWidth, ButtonHeight)
ResizeGadget(*history\item[i]\Show, 5+InnerWidth-ButtonWidth, 5, ButtonWidth, ButtonHeight)
ResizeGadget(*history\item[i]\Call, 5, 15+ButtonHeight*2, InnerWidth, ButtonHeight)
ResizeGadget(*history\item[i]\Variables, 5, 5+ContainerHeight, InnerWidth, 195)
If GetGadgetState(*history\item[i]\Show) = 0
ResizeGadget(*history\item[i]\Container, 5, Top, ContainerWidth, ContainerHeight)
Top + ContainerHeight + 10
Else
ResizeGadget(*history\item[i]\Container, 5, Top, ContainerWidth, ContainerHeight+210)
Top + ContainerHeight + 220
EndIf
Next i
EndIf
ResizeGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_History_CurrentText], 5, 5, InnerWidth, ButtonHeight)
ResizeGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_History_CurrentFile], 5, 10+ButtonHeight, InnerWidth, ButtonHeight)
ResizeGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_History_CurrentLine], 5, 15+ButtonHeight*2, InnerWidth, ButtonHeight)
ResizeGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_History_CurrentContainer], 5, Top, ContainerWidth, ContainerHeight)
Top + ContainerHeight + 10
SetGadgetAttribute(*Debugger\Gadgets[#DEBUGGER_GADGET_History_ScrollArea], #PB_ScrollArea_InnerWidth, Width - 50)
SetGadgetAttribute(*Debugger\Gadgets[#DEBUGGER_GADGET_History_ScrollArea], #PB_ScrollArea_InnerHeight, Top + 10)
ResetAllWidth = Max(120, GetRequiredWidth(*Debugger\Gadgets[#DEBUGGER_GADGET_History_ResetAll]))
ResetWidth = Max(120, GetRequiredWidth(*Debugger\Gadgets[#DEBUGGER_GADGET_History_Reset]))
ResizeGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_History_Stats], 10, 10, Width-20, Height-30-ButtonHeight)
ResizeGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_History_ResetAll], 10, Height-10-ButtonHeight, ResetAllWidth, ButtonHeight)
ResizeGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_History_Reset], 20+ResetAllWidth, Height-10-ButtonHeight, ResetWidth, ButtonHeight)
ResizeGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_History_UpdateStats], Width-10-ButtonWidth, Height-10-ButtonHeight, ButtonWidth, ButtonHeight)
ElseIf EventID = #PB_Event_CloseWindow
If DebuggerMemorizeWindows And IsWindowMinimized(*Debugger\Windows[#DEBUGGER_WINDOW_History]) = 0
HistoryMaximize = IsWindowMaximized(*Debugger\Windows[#DEBUGGER_WINDOW_History])
If HistoryMaximize = 0
HistoryWindowX = WindowX(*Debugger\Windows[#DEBUGGER_WINDOW_History])
HistoryWindowY = WindowY(*Debugger\Windows[#DEBUGGER_WINDOW_History])
HistoryWindowWidth = WindowWidth (*Debugger\Windows[#DEBUGGER_WINDOW_History])
HistoryWindowHeight = WindowHeight(*Debugger\Windows[#DEBUGGER_WINDOW_History])
EndIf
EndIf
If *Debugger\History
*history.Debugger_History = *Debugger\History
For i = 0 To *Debugger\HistorySize - 1
VariableGadget_Free(*history\item[i]\Variables)
Next i
FreeMemory(*Debugger\History)
*Debugger\History = 0
*Debugger\HistorySize = 0
EndIf
CloseWindow(*Debugger\Windows[#DEBUGGER_WINDOW_History])
*Debugger\Windows[#DEBUGGER_WINDOW_History] = 0
Debugger_CheckDestroy(*Debugger)
EndIf
EndProcedure
Procedure UpdateHistoryWindowState(*Debugger.DebuggerData)
If *Debugger\ProgramState = -1
DisableGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_History_Update], 1)
DisableGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_History_Reset], 1)
DisableGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_History_ResetAll], 1)
Else
DisableGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_History_Update], 0)
DisableGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_History_Reset], 0)
DisableGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_History_ResetAll], 0)
If *Debugger\ProgramState <> 0 And *Debugger\ProgramState <> -2
Command.CommandInfo\Command = #COMMAND_GetHistory
SendDebuggerCommand(*Debugger, @Command)
Command.CommandInfo\Command = #COMMAND_GetProcedureStats
SendDebuggerCommand(*Debugger, @Command)
EndIf
EndIf
EndProcedure
Procedure OpenHistoryWindow(*Debugger.DebuggerData)
If *Debugger\Windows[#DEBUGGER_WINDOW_History]
SetWindowForeground(*Debugger\Windows[#DEBUGGER_WINDOW_History])
Else
Window = OpenWindow(#PB_Any, HistoryWindowX, HistoryWindowY, HistoryWindowWidth, HistoryWindowHeight, Language("Debugger","HistoryWindowTitle") + " - " + DebuggerTitle(*Debugger\FileName$), #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_SizeGadget|#PB_Window_Invisible|#PB_Window_MaximizeGadget)
If Window
*Debugger\Windows[#DEBUGGER_WINDOW_History] = Window
*Debugger\Gadgets[#DEBUGGER_GADGET_History_Panel] = PanelGadget(#PB_Any, 0, 0, 0, 0)
AddGadgetItem(*Debugger\Gadgets[#DEBUGGER_GADGET_History_Panel], -1, Language("Debugger","History"))
*Debugger\Gadgets[#DEBUGGER_GADGET_History_ScrollArea] = ScrollAreaGadget(#PB_Any, 0, 0, 0, 0, 1000, 1000, 10, #PB_ScrollArea_Single)
*Debugger\Gadgets[#DEBUGGER_GADGET_History_CurrentContainer] = ContainerGadget(#PB_Any, 0, 0, 0, 0, #PB_Container_Single)
*Debugger\Gadgets[#DEBUGGER_GADGET_History_CurrentText] = TextGadget(#PB_Any, 5, 5, 0, 25, Language("Debugger","CurrentPosition"))
*Debugger\Gadgets[#DEBUGGER_GADGET_History_CurrentLine] = TextGadget(#PB_Any, 5, 35, 0, 25, "")
*Debugger\Gadgets[#DEBUGGER_GADGET_History_CurrentFile] = TextGadget(#PB_Any, 5, 65, 0, 25, "")
CloseGadgetList()
CloseGadgetList()
*Debugger\Gadgets[#DEBUGGER_GADGET_History_Update] = ButtonGadget(#PB_Any, 0, 0, 0, 0, Language("Debugger","Update"))
*Debugger\Gadgets[#DEBUGGER_GADGET_History_Updating] = TextGadget(#PB_Any, 0, 0, 0, 0, Language("Debugger","Updating"), #PB_Text_Center)
HideGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_History_Updating], 1)
AddGadgetItem(*Debugger\Gadgets[#DEBUGGER_GADGET_History_Panel], -1, Language("Debugger","Statistics"))
*Debugger\Gadgets[#DEBUGGER_GADGET_History_Stats] = ListIconGadget(#PB_Any, 0, 0, 0, 0, Language("Debugger","Name"), 300, #PB_ListIcon_MultiSelect|#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
AddGadgetColumn(*Debugger\Gadgets[#DEBUGGER_GADGET_History_Stats], 1, Language("Debugger","CallCount"), 100)
If *Debugger\Procedures
*Pointer = *Debugger\Procedures
For i = 1 To *Debugger\NbPRocedures
Name$ = PeekAscii(*Pointer) + "()"
*Pointer + MemoryAsciiLength(*Pointer) + 1
ModName$ = PeekAscii(*Pointer)
*Pointer + MemoryAsciiLength(*Pointer) + 1
AddGadgetItem(*Debugger\Gadgets[#DEBUGGER_GADGET_History_Stats], -1, ModuleName(Name$, ModName$))
Next i
Command.CommandInfo\Command = #COMMAND_GetProcedureStats
SendDebuggerCommand(*Debugger, @Command)
EndIf
*Debugger\Gadgets[#DEBUGGER_GADGET_History_Reset] = ButtonGadget(#PB_Any, 0, 0, 0, 0, Language("Debugger","Reset"))
*Debugger\Gadgets[#DEBUGGER_GADGET_History_ResetAll] = ButtonGadget(#PB_Any, 0, 0, 0, 0, Language("Debugger","ResetAll"))
*Debugger\Gadgets[#DEBUGGER_GADGET_History_UpdateStats] = ButtonGadget(#PB_Any, 0, 0, 0, 0, Language("Debugger","Update"))
CloseGadgetList()
EnsureWindowOnDesktop(Window)
If HistoryMaximize
ShowWindowMaximized(Window)
Else
HideWindow(Window, 0)
EndIf
HistoryWindowEvents(*Debugger, #PB_Event_SizeWindow)
CompilerIf #DEFAULT_CanWindowStayOnTop
SetWindowStayOnTop(Window, DebuggerOnTop)
CompilerEndIf
Debugger_AddShortcuts(Window)
Command.CommandInfo\Command = #COMMAND_GetHistory
SendDebuggerCommand(*Debugger, @Command)
Debugger_ProcessEvents(Window, #PB_Event_ActivateWindow) ; makes all debugger windows go to the top
EndIf
EndIf
EndProcedure
Procedure UpdateHistoryWindow(*Debugger.DebuggerData)
SetWindowTitle(*Debugger\Windows[#DEBUGGER_WINDOW_History], Language("Debugger","HistoryWindowTitle") + " - " + GetFilePart(*Debugger\FileName$))
SetGadgetItemText(*Debugger\Gadgets[#DEBUGGER_GADGET_History_Panel], 0, Language("Debugger","History"), 0)
SetGadgetItemText(*Debugger\Gadgets[#DEBUGGER_GADGET_History_Panel], 1, Language("Debugger","Statistics"), 0)
SetGadgetText(*Debugger\Gadgets[#DEBUGGER_GADGET_History_Update], Language("Debugger","Update"))
SetGadgetText(*Debugger\Gadgets[#DEBUGGER_GADGET_History_Updating], Language("Debugger","Updating"))
SetGadgetText(*Debugger\Gadgets[#DEBUGGER_GADGET_History_Reset], Language("Debugger","Reset"))
SetGadgetText(*Debugger\Gadgets[#DEBUGGER_GADGET_History_ResetAll], Language("Debugger","ResetAll"))
SetGadgetText(*Debugger\Gadgets[#DEBUGGER_GADGET_History_UpdateStats], Language("Debugger","Update"))
HistoryWindowEvents(*Debugger, #PB_Window_SizeGadget) ; update button sizes
EndProcedure
Procedure History_DebuggerEvent(*Debugger.DebuggerData)
If *Debugger\Command\Command = #COMMAND_ControlCallstack
OpenHistoryWindow(*Debugger)
ProcedureReturn ; do not run the rest of this code
EndIf
; ignore these messages when the window is closed
;
If *Debugger\Windows[#DEBUGGER_WINDOW_History] = 0
ProcedureReturn
EndIf
Select *Debugger\Command\Command
Case #COMMAND_History
HideGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_History_Updating], 0)
HideGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_History_ScrollArea], 1)
DisableGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_History_Update], 1)
; delete the old gadgets & data
;
If *Debugger\History
*history.Debugger_History = *Debugger\History
For i = 0 To *Debugger\HistorySize - 1
VariableGadget_Free(*history\item[i]\Variables)
FreeGadget(*history\item[i]\Container)
Next i
FreeMemory(*Debugger\History)
*Debugger\History = 0
*Debugger\HistorySize = 0
EndIf
If *Debugger\Command\Value1 > 0
*Debugger\HistorySize = *Debugger\Command\Value1
*Debugger\History = AllocateMemory(*Debugger\HistorySize * SizeOf(Debugger_HistoryData))
If *Debugger\History
*history.Debugger_History = *Debugger\History
*pointer = *Debugger\CommandData
OpenGadgetList(*Debugger\Gadgets[#DEBUGGER_GADGET_History_ScrollArea])
For i = 0 To *Debugger\HistorySize-1
Line = PeekL(*Pointer): *Pointer + 4
Call$ = PeekS(*Pointer): *Pointer + MemoryStringLengthBytes(*Pointer) + #CharSize ; not ascii!
*history\item[i]\Container = ContainerGadget(#PB_Any, 0, 0, 0, 0, #PB_Container_Single)
*history\item[i]\Line = TextGadget(#PB_Any, 5, 5, 0, 25, Language("Debugger","Line")+": "+Str(DebuggerLineGetLine(Line)+1))
*history\item[i]\File = TextGadget(#PB_Any, 5, 35, 0, 25, Language("Debugger","File")+": "+GetDebuggerRelativeFile(*Debugger, Line))
*history\item[i]\Show = ButtonGadget(#PB_Any, 0, 5, 110, 25, Language("Debugger","ShowVariables"), #PB_Button_Toggle)
*history\item[i]\Call = StringGadget(#PB_Any, 5, 65, 0, 25, Call$, #PB_String_ReadOnly)
*history\item[i]\Variables = VariableGadget_Create(#PB_Any, 5, 100, 0, 195, Language("Debugger","Scope"), #True, #False)
CloseGadgetList()
Command.CommandInfo\Command = #COMMAND_GetHistoryLocals
Command\Value1 = i
SendDebuggerCommand(*Debugger, @Command)
Next i
CloseGadgetList()
EndIf
EndIf
SetGadgetText(*Debugger\Gadgets[#DEBUGGER_GADGET_History_CurrentLine], Language("Debugger","Line")+": "+Str(DebuggerLineGetLine(*Debugger\Command\Value2) + 1))
SetGadgetText(*Debugger\Gadgets[#DEBUGGER_GADGET_History_CurrentFile], Language("Debugger","File")+": "+GetDebuggerRelativeFile(*Debugger, *Debugger\Command\Value2))
HideGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_History_Updating], 1)
HideGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_History_ScrollArea], 0)
DisableGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_History_Update], 0)
HistoryWindowEvents(*Debugger, #PB_Event_SizeWindow)
Case #COMMAND_HistoryLocals
If *Debugger\History
*history.Debugger_History = *Debugger\History
If *Debugger\Command\Value1 < *Debugger\HistorySize
VariableGadget_Lock(*history\item[*Debugger\Command\Value1]\Variables)
VariableGadget_Allocate(*history\item[*Debugger\Command\Value1]\Variables, *Debugger\Command\Value2)
VariableGadget_Use(*history\item[*Debugger\Command\Value1]\Variables)
*Pointer = *Debugger\CommandData
For i = 1 To *Debugger\Command\Value2
type = PeekB(*Pointer) & ~(1<<6) ; remove the direct param flag right at the start
*Pointer + 1
dynamictype = PeekB(*Pointer)
*Pointer + 1
scope = PeekB(*Pointer)
*Pointer + 1
sublevel = PeekL(*Pointer)
*Pointer + 4
name$ = PeekAscii(*Pointer)
*Pointer + MemoryAsciiLength(*Pointer) + 1
Select scope
Case #SCOPE_GLOBAL: ScopeName$ = ""
Case #SCOPE_LOCAL: ScopeName$ = "Local"
Case #SCOPE_STATIC: ScopeName$ = "Static"
Case #SCOPE_SHARED: ScopeName$ = "Shared"
EndSelect
VariableGadget_Add(type, dynamictype, sublevel, ScopeName$, name$, "", *Pointer, *Debugger\Is64bit)
*Pointer + GetValueSize(type, *Pointer, *Debugger\Is64bit)
Next i
VariableGadget_Unlock(*history\item[*Debugger\Command\Value1]\Variables)
VariableGadget_Sort(*history\item[*Debugger\Command\Value1]\Variables)
EndIf
EndIf
Case #COMMAND_Procedures
If *Debugger\Procedures
ClearGadgetItems(*Debugger\Gadgets[#DEBUGGER_GADGET_History_Stats])
*Pointer = *Debugger\Procedures
For i = 1 To *Debugger\NbPRocedures
Name$ = PeekAscii(*Pointer) + "()"
*Pointer + MemoryAsciiLength(*Pointer) + 1
ModName$ = PeekAscii(*Pointer)
*Pointer + MemoryAsciiLength(*Pointer) + 1
AddGadgetItem(*Debugger\Gadgets[#DEBUGGER_GADGET_History_Stats], -1, ModuleName(Name$, ModName$))
Next i
Command.CommandInfo\Command = #COMMAND_GetPRocedureStats
SendDebuggerCommand(*Debugger, @Command)
EndIf
Case #COMMAND_ProcedureStats
*stats.ProcedureStats_List = *Debugger\CommandData
For i = 0 To *Debugger\Command\Value1 - 1
SetGadgetItemText(*Debugger\Gadgets[#DEBUGGER_GADGET_History_Stats], i, Str(*stats\callcount[i]), 1)
Next i
EndSelect
EndProcedure