📄 dbg.asm
字号:
;// Debug
.686P
.MODEL FLAT, STDCALL
OPTION CASEMAP:NONE
OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE
.MMX
.XMM
INCLUDE jpeg.inc
INCLUDELIB user32.lib
IF DEBUG_SPRINTF
INCLUDELIB msvcrt.lib
ENDIF
OutputDebugStringA PROTO :dword
WriteFile PROTO :dword,:dword,:dword,:dword,:dword
CreateFileA PROTO :dword,:dword,:dword,:dword,:dword,:dword,:dword
CloseHandle PROTO :dword
GENERIC_WRITE equ 40000000h
FILE_SHARE_READ equ 1h
FILE_ATTRIBUTE_NORMAL equ 80h
CREATE_ALWAYS equ 2
;// Jibz's trick to define the start and the end of a segment
ProfSeg$00 SEGMENT byte
ProfStart label byte
ProfSeg$00 ENDS
ProfSeg$02 SEGMENT byte
ProfEnd label byte
ProfSeg$02 ENDS
.DATA
DBG_File dword ?
DBG_Size dword ?
DBG_Nb dword ?
DBG_Buffer byte 4096 DUP (0)
pDBG_Buffer dword DBG_Buffer
filename byte "log.txt", 0
ALIGN 16
DBG_FPUSav byte 512 dup (?)
DBG_MaxDword real4 4294967296.0
DBG_NBTESTOVH = 1000
DBG_NBOVH dword DBG_NBTESTOVH
IF DEBUG_PROFILE
DBG_ProfOvh real4 ?
ENDIF
.CODE
;//=========================================================================
;// Get marker name
;// params : EAX : marker
;// returns : marker name
;//=========================================================================
DBG_PrintMarker PROC
MKSTR MACRO m,s
LOCAL strid
DBGSEG SEGMENT
strid byte s, 0
DBGSEG ENDS
EXITM <dword m, strid>
ENDM
.DATA
ALIGN 4
MarkerName \
MKSTR(0C0h, "Baseline DCT")
MKSTR(0C1h, "Extended sequential DCT")
MKSTR(0C2h, "Progressive DCT")
MKSTR(0C3h, "Lossless (sequential)")
MKSTR(0C5h, "Differential sequential DCT")
MKSTR(0C6h, "Differential progressive DCT")
MKSTR(0C7h, "Differential lossless (sequential)")
MKSTR(0C8h, "Reserved for JPEG extensions")
MKSTR(0C9h, "Extended sequential DCT")
MKSTR(0CAh, "Progressive DCT")
MKSTR(0CBh, "Lossless (sequential)")
MKSTR(0CDh, "Differential sequential DCT")
MKSTR(0CEh, "Differential progressive DCT")
MKSTR(0CFh, "Differential lossless (sequential)")
MKSTR(0C4h, "Define Huffman table(s)")
MKSTR(0CCh, "Define arithmetic coding conditioning(s)")
MKSTR(0D0h, "Restart 0")
MKSTR(0D1h, "Restart 1")
MKSTR(0D2h, "Restart 2")
MKSTR(0D3h, "Restart 3")
MKSTR(0D4h, "Restart 4")
MKSTR(0D5h, "Restart 5")
MKSTR(0D6h, "Restart 6")
MKSTR(0D7h, "Restart 7")
MKSTR(0D8h, "Start of image")
MKSTR(0D9h, "End of image")
MKSTR(0DAh, "Start of scan")
MKSTR(0DBh, "Define quantization table(s)")
MKSTR(0DCh, "Define number of lines")
MKSTR(0DDh, "Define restart interval")
MKSTR(0DEh, "Define hierarchical progression")
MKSTR(0DFh, "Expand reference component(s)")
MKSTR(0E0h, "Reserved for application segments")
MKSTR(0EFh, "Reserved for application segments")
MKSTR(0F0h, "Reserved for JPEG extensions")
MKSTR(0FDh, "Reserved for JPEG extensions")
MKSTR(0FEh, "Comment")
MKSTR(01h, "Reserved")
MKSTR(02h, "Reserved")
MKSTR(00h, "(marker name not found)")
.CODE
pushad
pushfd
lea edx, MarkerName
mov ebx, eax
@@:
mov ecx, [edx]
mov esi, [edx+4]
test ecx, ecx
jz Done
cmp ecx, ebx
je Done
add edx, 8
jmp @B
Done:
DBG "<MRK>"
DBG " 0x%X : %s", ebx, esi
DBG "</MRK>"
popfd
popad
ret
DBG_PrintMarker ENDP
;//=========================================================================
;// output to a logfile
;// params : eax : number of char in the buffer
;//=========================================================================
DBG_Output PROC
mov WPTR DBG_Buffer[eax], 0A0Dh
add eax, 2
mov BPTR DBG_Buffer[eax], 0
mov DBG_Size, eax
IF DEBUG_FILE
INVOKE WriteFile, DBG_File, OFFSET DBG_Buffer, eax, OFFSET DBG_Nb, 0
test eax, eax
jz Err
mov eax, DBG_Size
cmp eax, DBG_Nb
jne Err
ENDIF
IF DEBUG_WND
push OFFSET DBG_Buffer
call OutputDebugStringA
ENDIF
Done:
ret
Err:
int 3
jmp Done
DBG_Output ENDP
;//=========================================================================
;// Init debug
;//=========================================================================
DBG_Start PROC
pushad
pushfd
fxsave DBG_FPUSav
IF DEBUG_PROFILE
lea edi, ProfStart
sub eax, eax
lea ecx, ProfEnd
sub ecx, edi
rep stosb
mov ecx, DBG_NBTESTOVH
ALIGN 16
@@:
PROFILE_IN
PROFILE_OUT "Profile Overhead", p
dec ecx
jnz @B
mov eax, OFFSET p
ASSUME eax:PTR PROFILE
fild DPTR [eax].totaltime[4]
fmul DBG_MaxDword
fiadd DPTR [eax].totaltime[0]
fidiv DBG_NBOVH
fstp DBG_ProfOvh
mov DPTR [eax].numcalls, 0
fxrstor DBG_FPUSav
ENDIF
IF DEBUG_FILE
INVOKE CreateFileA, OFFSET filename, GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0
cmp eax, -1
jne @F
int 3
@@:
mov DBG_File, eax
ENDIF
popfd
popad
ret
DBG_Start ENDP
;//=========================================================================
;// Stop debug
;//=========================================================================
DBG_Stop PROC
.data
avgtime real8 ?
.code
pushad
pushfd
IF DEBUG_PROFILE
lea eax, ProfStart
jmp InLoop
ASSUME eax:PTR PROFILE
@@:
cmp [eax].numcalls, 0
je Next
DBG "<PROFILE>"
DBG " Function name : %s", [eax].funcname
DBG " Number of calls : %d", [eax].numcalls
emms
fild DPTR [eax].totaltime[4]
fmul DBG_MaxDword
fiadd DPTR [eax].totaltime[0]
fidiv DPTR [eax].numcalls
fsub DPTR DBG_ProfOvh
fstp avgtime
DBG " Average time : %.2f", avgtime[0], avgtime[4]
DBG "</PROFILE>"
Next:
add eax, sizeof(PROFILE)
;// the structures may not be continuous in memory
FindProf:
cmp [eax].magic, MAGIC_PROF
je InLoop
inc eax
cmp eax, OFFSET ProfEnd
jb FindProf
InLoop:
cmp eax, OFFSET ProfEnd
jb @B
Done:
ENDIF
IF DEBUG_FILE
cmp DBG_File, 0
je @F
push DBG_File
call CloseHandle
mov DBG_File, 0
@@:
ENDIF
popfd
popad
ret
DBG_Stop ENDP
;//=========================================================================
;// Dump 64 dwords
;// params : edi : pointer to dwords
;//=========================================================================
DBG_Dump8x8DWords PROC
pushad
pushfd
ASSUME edi:ptr dword
mov ecx, 8
@@:
DBG "%d, %d, %d, %d, %d, %d, %d, %d,", [edi][4*0], [edi][4*1], [edi][4*2], [edi][4*3],\
[edi][4*4], [edi][4*5], [edi][4*6], [edi][4*7]
add edi, 8*4
dec ecx
jnz @B
popfd
popad
ret
ASSUME edi:NOTHING
DBG_Dump8x8DWords ENDP
;//=========================================================================
;// Dump 64 words
;// params : edi : pointer to words
;//=========================================================================
DBG_Dump8x8Words PROC
.DATA
tmp dword 8 dup (0)
.CODE
pushad
pushfd
ASSUME edi:ptr word
mov ecx, 8
@@:
movsx eax, [edi][2*0]
mov tmp[4*0], eax
movsx eax, [edi][2*1]
mov tmp[4*1], eax
movsx eax, [edi][2*2]
mov tmp[4*2], eax
movsx eax, [edi][2*3]
mov tmp[4*3], eax
movsx eax, [edi][2*4]
mov tmp[4*4], eax
movsx eax, [edi][2*5]
mov tmp[4*5], eax
movsx eax, [edi][2*6]
mov tmp[4*6], eax
movsx eax, [edi][2*7]
mov tmp[4*7], eax
DBG "%d, %d, %d, %d, %d, %d, %d, %d,", tmp[4*0], tmp[4*1], tmp[4*2], tmp[4*3],\
tmp[4*4], tmp[4*5], tmp[4*6], tmp[4*7]
add edi, 8*2
dec ecx
jnz @B
popfd
popad
ret
ASSUME edi:NOTHING
DBG_Dump8x8Words ENDP
.DATA
f real4 16*2 dup (?)
i dword 16 dup (?)
.CODE
;//=========================================================================
;// Dump NxM floats
;// params : edi : pointer to floats
;// params : ecx : number of lines (N)
;// params : edx : number of columns (M)
;//=========================================================================
DBG_DumpNxMFloats PROC
IF DEBUG_SPRINTF
.DATA
fmt byte "%.4f, ", 0, 0, 0
f8 real8 ?
.CODE
fxsave DBG_FPUSav
pushad
finit
mov esi, edx
mov ebp, edx
imul ecx, edx
mov ebx, ecx
Row:
dec esi
jnz InLine
mov word ptr fmt[6], 00a0dh
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -