forked from gphilippot/purebasic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WindowsDebugging.pb
68 lines (56 loc) · 2.28 KB
/
WindowsDebugging.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
;--------------------------------------------------------------------------------------------
; 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.
;--------------------------------------------------------------------------------------------
CompilerIf #CompileWindows
CompilerIf #DEBUG
; It's used in debugging.pb as well, so declare them in the global scope
CompilerIf #CompileX86
!extrn _PB_StringHeap
!extrn _PB_Memory_Heap
CompilerElse
!extrn PB_StringHeap
!extrn PB_Memory_Heap
CompilerEndIf
; For easier bug hunting (use with GetLastError_() for example
;
Procedure WindowsError(Code.l)
Buffer$ = Space(1000)
FormatMessage_(#FORMAT_MESSAGE_IGNORE_INSERTS|#FORMAT_MESSAGE_FROM_SYSTEM, 0, Code, 0, @Buffer$, 1000, 0)
MessageRequester("Error", "Code: " + Str(Code) + #NewLine + "Message: " + Buffer$)
EndProcedure
; Declare a macro which can helps a lot to localize weird bugs
;
Procedure _TestHeaps(File$, Line)
Protected StringHeap, MemoryBase, MemoryHeap
CompilerIf #CompileX86
!mov eax, dword [_PB_StringHeap]
!mov [p.v_StringHeap], eax
!mov eax, dword [_PB_MemoryBase]
!mov [p.v_MemoryBase], eax
!mov eax, dword [_PB_Memory_Heap]
!mov [p.v_MemoryHeap], eax
CompilerElse
!mov rax, qword [PB_StringHeap]
!mov [p.v_StringHeap], rax
!mov rax, qword [_PB_MemoryBase]
!mov [p.v_MemoryBase], rax
!mov rax, qword [PB_Memory_Heap]
!mov [p.v_MemoryHeap], rax
CompilerEndIf
If HeapValidate_(StringHeap, 0, 0) = 0
MessageRequester("StringHeap corrupted !", File$+" : "+Str(Line))
EndIf
If HeapValidate_(MemoryBase, 0, 0) = 0
MessageRequester("MemoryBase heap corrupted !", File$+" : "+Str(Line))
EndIf
If HeapValidate_(MemoryHeap, 0, 0) = 0
MessageRequester("AllocateMemory heap corrupted !", File$+" : "+Str(Line))
EndIf
EndProcedure
Macro TestHeaps
_TestHeaps(#PB_Compiler_File, #PB_Compiler_Line)
EndMacro
CompilerEndIf
CompilerEndIf