📄 debug.inc
字号:
popad
endif
endm
;---------------------------------------------------------------------------
PrintLine macro
local szLine
if DBGWIN_DEBUG_ON eq 1
.data
szLine byte "----------------------------------------", 0
.code
pushad
invoke DebugPrint, addr szLine
popad
endif
endm
;---------------------------------------------------------------------------
PrintHex macro Var: REQ, Text
local szDebugNum
local info
local txt
local sz
local wNum
local bNum
local dwNum
if DBGWIN_DEBUG_ON eq 1
.data
szDebugNum byte 9 dup(0)
wNum label word
bNum label byte
dwNum dword 0
.code
pushad
sz = GetSize(Var)
if sz eq 1
if (OPATTR(Var)) and 00010000y
mov bNum, Var
else
mov al, Var
mov bNum, al
endif
shl dwNum, 24
elseif sz eq 2
m2m wNum, Var
shl dwNum, 16
elseif sz eq 4
m2m dwNum, Var
endif
invoke dw2hex, dwNum, addr szDebugNum
if sz eq 1
mov byte ptr szDebugNum[2], 0
elseif sz eq 2
mov byte ptr szDebugNum[4], 0
endif
invoke lstrlen, addr szDebugNum
if DBGWIN_EXT_INFO eq 1
info textequ @CatStr(< !(>, SFileName(), <!, >, %@Line, <!)>)
push eax
ifnb <&Text>
add eax, @SizeStr(&Var)+3+@SizeStr(%info)+@SizeStr(&Text)+1
else
add eax, @SizeStr(&Var)+3+@SizeStr(%info)+1
endif
else
ifnb <&Text>
add eax, @SizeStr(&Var)+3+@SizeStr(&Text)+1
else
add eax, @SizeStr(&Var)+3+1
endif
endif
invoke GlobalAlloc, GPTR, eax
mov ebx, eax
FillMem ebx, &Var
mov dword ptr [eax+@SizeStr(&Var)], 203D20h
invoke lstrcat, ebx, addr szDebugNum
ifnb <&Text>
invoke lstrlen, eax
mov byte ptr [ebx+eax], ","
mov byte ptr [ebx+eax+1], " "
mov byte ptr [ebx+eax+2], 0
.data
txt byte &Text, 0
.code
invoke lstrcat, ebx, addr txt
endif
if DBGWIN_EXT_INFO eq 1
pop edx
push ebx
ifnb <&Text>
add ebx, @SizeStr(&Var)+@SizeStr(&Text)+3
else
add ebx, @SizeStr(&Var)+3
endif
add ebx, edx
FillMem ebx, %info
pop ebx
endif
invoke DebugPrint, ebx
invoke GlobalFree, ebx
popad
endif
endm
;---------------------------------------------------------------------------
PrintError macro
local pDesc
local info
if DBGWIN_DEBUG_ON eq 1
pushad
.data
pDesc dword 0
.code
invoke GetLastError
invoke FormatMessage, FORMAT_MESSAGE_ALLOCATE_BUFFER or FORMAT_MESSAGE_FROM_SYSTEM, 0, eax, 0, addr pDesc, 0, 0
;FormatMessage returns length of err description in eax
if DBGWIN_EXT_INFO eq 1
info textequ @CatStr(< !(>, SFileName(), <!, >, %@Line, <!)>)
push eax
add eax, @SizeStr(%info)+1
invoke GlobalAlloc, GPTR, eax
push eax
invoke lstrcpy, eax, pDesc
pop eax
pop edx
push eax
add eax, edx
sub eax, 2
FillMem eax, %info
pop eax
invoke DebugPrint, eax
else
invoke DebugPrint, pDesc
endif
invoke LocalFree, pDesc
popad
endif
endm
;------------------------------------------------------------------------------
PrintException macro pExcept: REQ
local InfoText
local info
if DBGWIN_DEBUG_ON eq 1
info textequ @CatStr(< !(>, SFileName(), <!, >, %@Line, <!)>)
.data
InfoText byte 35+@SizeStr(%info) dup(0)
.code
pushad
mov eax, pExcept
mov eax, (EXCEPTION_RECORD ptr [eax]).ExceptionCode
invoke GetExName, eax
invoke lstrcpy, addr InfoText, eax
if DBGWIN_EXT_INFO eq 1
invoke lstrlen, addr InfoText
add eax, offset InfoText
FillMem eax, %info
endif
invoke DebugPrint, addr InfoText
popad
endif
endm
;-----------------------------------------------------------------------------
ASSERT macro Val: REQ, Message
local Msg, Text, Mwq
if DBGWIN_DEBUG_ON eq 1
if DBGWIN_EXT_INFO eq 1
ifnb <&Message>
if @InStr(1, Message, <!">)
Mwq equ @SubStr(Message, 2, @SizeStr(Message)-2)
endif
if @InStr(1, Message, <!'>)
Mwq equ @SubStr(Message, 2, @SizeStr(Message)-2)
endif
Text equ @CatStr(<ASSERT >, Val, <, >, Mwq, < !(>, SFileName(), <!, >, %@Line, <!)>)
else
Text equ @CatStr(<ASSERT >, Val, < !(>, SFileName(), <!, >, %@Line, <!)>)
endif
else
ifnb <&Message>
Text equ @CatStr(<ASSERT >, Val, <, >, Mwq)
else
Text equ @CatStr(<ASSERT >, Val)
endif
endif
.data
Msg byte @SizeStr(%Text)+1 dup(0)
.code
pushad
FillString &Msg, %Text
.if !Val
invoke DebugPrint, addr Msg
.endif
popad
endif
endm
assert equ <ASSERT>
;----------------------------------------------------------------------------
Spy macro Var: REQ
if DBGWIN_DEBUG_ON eq 1
.if __fTrap == 0
push eax
assume fs: nothing
mov __pVar, offset Var
push offset debug_except_handler
push fs:[0]
mov fs:[0], esp
mov __fTrap, 1
pushf
pop ax
or ax, 100h
push ax
popf
nop
.endif
endif
endm
StopSpy macro
if DBGWIN_DEBUG_ON eq 1
mov __fTrap, 0
mov eax, [esp] ;restore previous SEH
mov fs:[0], eax
add esp, 8
pop eax ;restore eax
endif
endm
;---------------------------------------------------------------------------
TrapException macro eh: REQ
if DBGWIN_DEBUG_ON eq 1
pushad
invoke LoadLibrary, CTEXT("dbghelp.dll")
mov __hLib, eax
invoke GetCurrentProcess
mov __hInst, eax
invoke GetProcAddress, __hLib, CTEXT("SymInitialize")
mov __pSymInit, eax
invoke GetProcAddress, __hLib, CTEXT("SymSetOptions")
mov __pSymOpt, eax
invoke GetProcAddress, __hLib, CTEXT("SymGetLineFromAddr")
mov __pGetLine, eax
.if __hLib
push SYMOPT_LOAD_LINES
call __pSymOpt
push TRUE
push NULL
push __hInst
call __pSymInit
popad
mov __esp, esp
assume fs: nothing
push offset TrapEx_seh
push fs:[0]
push esp
pop fs:[0]
push eh
pop __eh
pushf
pop ax
or ax, 100h ;set TF
push ax
popf
.else
popad
PrintText "Can't load dbghelp.dll. Please copy it to the system directory."
.endif
endif
endm
;---------------------------------------------------------------------------
Fix macro txt:=<Fix this later!!!!>
local pos, spos
pos = 0
spos = 0
% forc chr, @FileCur ;; Don't display full path. Easier to read.
pos = pos + 1
if "&chr" eq 5Ch ;; "\"
spos = pos
endif
endm
% echo @CatStr(<Fix: >, @SubStr(%@FileCur, spos+1,), <(%@Line) - txt>)
endm
;---------------------------------------------------------------------------
DbgDump macro lpStart: REQ, lnData: REQ
local @pmem
if DBGWIN_DEBUG_ON eq 1
.data?
@pmem dd ?
.code
pushad
push lpStart
push lnData
invoke GlobalAlloc, GMEM_FIXED, 80
mov @pmem, eax
pop ebx ;lnData
pop esi ;lpStart
.while ebx
mov edi, @pmem
invoke dw2hex, esi, edi
mov word ptr [edi+8], " :"
mov byte ptr [edi+10], " "
add edi, 11
push esi
push ebx
; dump hex values:
xor ecx, ecx
.while ecx < 16
.if !ebx
mov dword ptr [edi], " "
add edi, 3
.else
dec ebx
xor eax, eax
mov al, [esi]
inc esi
ror ax, 4
shr ah, 4
add ax, 3030h
cmp ah, 39h
jbe @F
add ah, "A"-3Ah
@@:
cmp al, 39h
jbe @F
add al, "A"-3Ah
@@:
mov word ptr [edi], ax
mov byte ptr [edi+2], " "
add edi, 3
.endif
inc ecx
.endw
pop ebx
pop esi
mov word ptr [edi], " "
add edi, 2
; dump text output:
xor ecx, ecx
.while ecx < 16
mov al, [esi]
.if !ebx
mov al, "."
.else
dec ebx
inc esi
cmp al, 20h
jae @F
mov al, "."
@@:
.endif
mov [edi], al
inc edi
inc ecx
.endw
mov byte ptr [edi],0
mov edi, @pmem
; write dashes:
mov byte ptr [edi+22], "-"
mov byte ptr [edi+34], "-"
mov byte ptr [edi+46], "-"
invoke DebugPrint, edi
.endw
invoke GlobalFree, @pmem
popad
endif
endm
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -