📄 debug.inc
字号:
;-----------------------------------------------------------------------------
;
; Include file for VKDEBUG v1.1, September 2002.
;
;-----------------------------------------------------------------------------
;PrintString, PrintStringByAddr, PrintDec, PrintHex, PrintDouble, PrintText,
;PrintLine, Spy, StopSpy, PrintError, ASSERT, PrintException, TrapException,
;FillString, FillMem, GetSize macros are written by vkim.
;-----------------------------------------------------------------------------
;SFileName is written by vkim and based on Four-F's idea.
;-----------------------------------------------------------------------------
;DbgDump is written by Thomas.
;-----------------------------------------------------------------------------
;DumpMem, DumpFPU are written by NaN.
;-----------------------------------------------------------------------------
;CTEXT is written by huh.
;-----------------------------------------------------------------------------
;m2m is written by hutch.
;-----------------------------------------------------------------------------
;Fix is written by Four-F.
;-----------------------------------------------------------------------------
;FillStirng and FillMem are optimized by bitRAKE.
;-----------------------------------------------------------------------------
;Some bugs of PrintDec and PrintHex are fixed by NaN and Four-F.
;-----------------------------------------------------------------------------
externdef stdcall DebugPrint :proto stdcall :dword
externdef stdcall HexDump2 :proto stdcall :dword, :dword
externdef stdcall FPUDump :proto stdcall
externdef C TrapEx_seh :proto C :dword, :dword, :dword, :dword
externdef stdcall GetExName :proto stdcall :dword
externdef stdcall FormatFlags :proto stdcall :dword, :dword, :dword
externdef C debug_except_handler :proto C :dword, :dword, :dword, :dword
externdef __fTrap: dword
externdef __pVar: dword
externdef __esp: dword
externdef __hLib: dword
externdef __hInst: dword
externdef __pSymOpt: dword
externdef __pSymInit: dword
externdef __pGetLine: dword
externdef __eh: dword
DBGWIN_DEBUG_ON = 1
DBGWIN_EXT_INFO = 1
;===================================HELPER MACROS=============================
CTEXT macro Text
local szText
.data
szText byte Text, 0
.code
exitm <offset szText>
endm
m2m macro M1, M2
push M2
pop M1
endm
FillString macro Arr, Text
local i,j
i = 0
j = 0
forc var, <&Text>
j = ('&var' shl ((i and 3)*8)) + j
if (i and 3) eq 3
mov dword ptr Arr[(i and -4)], j
j=0
endif
i = i + 1
endm
if (i and 3) eq 0
mov byte ptr Arr[i], 0
elseif (i and 3) eq 1
mov word ptr Arr[i-1], j
elseif (i and 3) eq 2
mov word ptr Arr[i-2], j
mov byte ptr Arr[i], 0
elseif (i and 3) eq 3
mov dword ptr Arr[(i-3)], j
endif
endm
FillMem macro pString, Text
ifdifi <&pString>, <eax>
push eax
mov eax, pString
FillString [eax], <&Text>
pop eax
else
FillString [eax], <&Text>
endif
endm
GetSize macro var: REQ
local char
if (OPATTR(var)) and 00010000y ;var is register
if @SizeStr(var) eq 3 ;eax, ebx, ecx, edx, esi, esi, esp, esp
exitm <4>
elseif @SizeStr(var) eq 2
char textequ @SubStr(var, 2, 1)
ifidni char, <l> ;al, bl, cl, dl
exitm <1>
else
ifidni char, <h> ;ah, bh, ch, dh
exitm <1>
else
exitm <2> ;ax, bx, cx, dx, si, di, sp, bp
endif
endif
endif
elseif (OPATTR(var)) and 00000100y
exitm <4> ;return size of dword if var is constant
else
exitm <sizeof &var>
endif
endm
SFileName macro
local i, pos
i = 0
pos = 0
% forc chr, @FileCur
i = i + 1
if "&chr" eq 5Ch
pos = i
endif
endm
exitm @SubStr(%@FileCur, pos+1,)
endm
;============================================================================
PrintString macro Var: REQ
local info
if DBGWIN_DEBUG_ON eq 1
pushad
invoke lstrlen, addr Var
if DBGWIN_EXT_INFO eq 1
info textequ @CatStr(< !(>, SFileName(), <!, >, %@Line, <!)>)
push eax
add eax, @SizeStr(&Var)+4+@SizeStr(%info)
else
add eax, @SizeStr(&Var)+4
endif
invoke GlobalAlloc, GPTR, eax
mov ebx, eax
FillMem ebx, &Var
mov dword ptr [eax+@SizeStr(&Var)], 203D20h
invoke lstrcat, ebx, addr Var
if DBGWIN_EXT_INFO eq 1
pop edx
push ebx
add ebx, @SizeStr(&Var)+3
add ebx, edx
FillMem ebx, %info
pop ebx
endif
invoke DebugPrint, ebx
invoke GlobalFree, ebx
popad
endif
endm
;----------------------------------------------------------------------------
PrintStringByAddr macro Var: REQ
local info
if DBGWIN_DEBUG_ON eq 1
info textequ @CatStr(< !(>, SFileName(), <!, >, %@Line, <!)>)
pushad
push Var
invoke lstrlen, Var
push eax
if DBGWIN_EXT_INFO eq 1
add eax, @SizeStr(&Var)+4+@SizeStr(%info)
else
add eax, @SizeStr(&Var)+4
endif
invoke GlobalAlloc, GPTR, eax
mov ebx, eax
FillMem ebx, &Var
mov dword ptr [eax+@SizeStr(&Var)], 203D20h
pop edx
pop eax
invoke lstrcat, ebx, eax
if DBGWIN_EXT_INFO eq 1
push ebx
add ebx, @SizeStr(&Var)+3
add ebx, edx
FillMem ebx, %info
pop ebx
endif
invoke DebugPrint, ebx
invoke GlobalFree, ebx
popad
endif
endm
;---------------------------------------------------------------------------
PrintText macro Var: REQ
local info
local szText
local szBuff
if DBGWIN_DEBUG_ON eq 1
info textequ @CatStr(< !(>, SFileName(), <!, >, %@Line, <!)>)
.data
szText byte Var, 0
if DBGWIN_EXT_INFO eq 1
szBuff byte @SizeStr(%info)+@SizeStr(&Var)+1 dup(0)
endif
.code
pushad
if DBGWIN_EXT_INFO eq 1
invoke lstrcpy, addr szBuff, addr szText ;returns address of a buffer in eax
add eax, @SizeStr(&Var)-2
FillMem eax, <%info>
invoke DebugPrint, addr szBuff
else
invoke DebugPrint, addr szText
endif
popad
endif
endm
;--------------------------------------------------------------------------
DumpMem macro lpData:REQ, lnLen:REQ, txt:VARARG
if DBGWIN_DEBUG_ON eq 1 ; If Debug is on
ifnb <txt> ; If text is given
PrintText txt ; Print Text
endif
pushad
invoke HexDump2, lpData, lnLen ; Call the Dump proc
popad
endif
endm
;--------------------------------------------------------------------------
DumpFPU macro txt:VARARG
if DBGWIN_DEBUG_ON eq 1 ; If Debug is on
ifnb <txt> ; If text is given
PrintText txt ; Print Text
PrintLine ; Print Line
endif
pushad
invoke FPUDump ; Call the Dump proc
popad
endif
endm
;--------------------------------------------------------------------------
PrintDec macro Var: REQ, Text
local szDebugNum
local info
local txt
local sz
local dwNum
local wNum
local bNum
if DBGWIN_DEBUG_ON eq 1
.data
szDebugNum byte 20 dup(0)
dwNum dword 0
.code
pushad
sz = GetSize(Var)
if sz eq 1
mov al, Var
cbw
cwde
mov dwNum, eax
elseif sz eq 2
mov ax, Var
cwde
mov dwNum, eax
elseif sz eq 4
m2m dwNum, Var
endif
invoke wsprintf, addr szDebugNum, CTEXT("%li"), dwNum
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 eax, &Var
mov dword ptr [eax+@SizeStr(&Var)], 203D20h
invoke lstrcat, eax, 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)+3+@SizeStr(&Text)
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
PrintDword equ <PrintDec>
;---------------------------------------------------------------------------
PrintDouble macro Var: REQ, Text
local szDebugNum
local info
local txt
if DBGWIN_DEBUG_ON eq 1
.data
szDebugNum byte 20 dup(0)
.code
pushad
invoke FloatToStr, Var, addr szDebugNum
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 eax, &Var
mov dword ptr [eax+@SizeStr(&Var)], 203D20h
invoke lstrcat, eax, 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)+3+@SizeStr(&Text)
else
add ebx, @SizeStr(&Var)+3
endif
add ebx, edx
FillMem ebx, %info
pop ebx
endif
invoke DebugPrint, ebx
invoke GlobalFree, ebx
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -