2 ; Formatted Debug Output (FDO)
\r
3 ; Copyright (c) 2005-2006, mike.dld
\r
4 ; Created: 2005-01-29, Changed: 2006-11-10
\r
6 ; For questions and bug reports, mail to mike.dld@gmail.com
\r
8 ; Available format specifiers are: %s, %d, %u, %x (with partial width support)
\r
13 ; __DEBUG_LEVEL__ equ 5
\r
21 macro debug_func name {
\r
23 name@of@func equ name
\r
26 macro debug_beginf {
\r
31 debug_endf fix end if
\r
33 macro DEBUGS _sign,[_str] {
\r
37 match _arg:_num,_str \{
\r
38 DEBUGS_N _sign,_num,_arg
\r
41 match =0 _arg,tp _str \{
\r
42 DEBUGS_N _sign,,_arg
\r
46 macro DEBUGS_N _sign,_num,[_str] {
\r
50 local ..str,..label,is_str
\r
69 if _num in <eax,ebx,ecx,edx,edi,ebp,esp>
\r
71 else if ~_num eq esi
\r
74 else if _num eqtype 0
\r
79 match [_arg],_num \{
\r
80 mov esi, dword[_arg]
\r
83 match =0 =dword[_arg],tp _num \{
\r
84 mov esi, dword[_arg]
\r
87 match =0 =word[_arg],tp _num \{
\r
88 movzx esi, word[_arg]
\r
91 match =0 =byte[_arg],tp _num \{
\r
92 movzx esi, byte[_arg]
\r
96 'Error: specified string width is incorrect'
\r
100 mov esi, 0x7FFFFFFF
\r
102 call fdo_debug_outstr
\r
107 macro DEBUGD _sign,_dec {
\r
110 match _arg:_num,_dec \{
\r
111 DEBUGD_N _sign,_num,_arg
\r
114 match =0 _arg,tp _dec \{
\r
115 DEBUGD_N _sign,,_arg
\r
119 macro DEBUGD_N _sign,_num,_dec {
\r
123 if (_dec eqtype eax | _dec eqtype 0)
\r
124 'Error: precision allowed only for in-memory variables'
\r
126 if (~_num in <1,2,4>)
\r
128 'Error: 1, 2 and 4 are only allowed for precision in %d'
\r
130 'Error: 1, 2 and 4 are only allowed for precision in %u'
\r
135 if _dec in <ebx,ecx,edx,esi,edi,ebp,esp>
\r
137 else if ~_dec eq eax
\r
144 else if _dec eqtype 0
\r
150 mov eax, dword _dec
\r
153 movsx eax, byte _dec
\r
155 movzx eax, byte _dec
\r
159 movsx eax, word _dec
\r
161 movzx eax, word _dec
\r
164 mov eax, dword _dec
\r
170 call fdo_debug_outdec
\r
175 macro DEBUGH _sign,_hex {
\r
178 match _arg:_num,_hex \{
\r
179 DEBUGH_N _sign,_num,_arg
\r
182 match =0 _arg,tp _hex \{
\r
183 DEBUGH_N _sign,,_arg
\r
187 macro DEBUGH_N _sign,_num,_hex {
\r
190 if (~_num eq) & (~_num in <1,2,3,4,5,6,7,8>)
\r
191 'Error: 1..8 are only allowed for precision in %x'
\r
194 if _hex in <eax,ebx,ecx,edx,esi,edi,ebp,esp>
\r
199 else if _hex in <ax,bx,cx,dx,si,di,bp,sp>
\r
206 else if _hex in <al,ah,bl,bh,cl,ch,dl,dh>
\r
214 else if _hex eqtype 0
\r
219 mov eax, dword _hex
\r
226 if ~_hex eqtype eax
\r
230 call fdo_debug_outhex
\r
235 ;-----------------------------------------------------------------------------
\r
237 debug_func fdo_debug_outchar
\r
247 debug_func fdo_debug_outstr
\r
253 movzx ecx, byte[edx]
\r
263 debug_func fdo_debug_outdec
\r
272 call fdo_debug_outchar
\r
287 call fdo_debug_outchar
\r
293 debug_func fdo_debug_outhex
\r
294 __fdo_hexdigits db '0123456789ABCDEF'
\r
304 and eax, 0x0000000F
\r
305 mov al, [__fdo_hexdigits+eax]
\r
306 call fdo_debug_outchar
\r
313 ;-----------------------------------------------------------------------------
\r
315 macro DEBUGF _level,_format,[_arg] {
\r
317 if __DEBUG__ = 1 & _level >= __DEBUG_LEVEL__
\r
318 local ..f1,f2,a1,a2,c1,c2,c3,..lbl
\r
319 _debug_str_ equ __debug_str_ # a1
\r
327 load c1 word from %-1
\r
332 store word 0 at %-1
\r
336 DEBUGS 0,_debug_str_+f2-c2
\r
340 DEBUGF_HELPER S,a1,0,_arg
\r
344 store word 0 at %-1
\r
348 DEBUGS 0,_debug_str_+f2-c2
\r
352 DEBUGF_HELPER H,a1,0,_arg
\r
353 else if c1 = '%d' | c1 = '%u'
\r
362 store word 0 at %-1
\r
366 DEBUGS 0,_debug_str_+f2-c2
\r
370 DEBUGF_HELPER D,a1,c4,_arg
\r
379 if (c1<>0)&(f2<>..lbl-..f1-1)
\r
380 DEBUGS 0,_debug_str_+f2-c2
\r
385 __debug_strings equ __debug_strings,_debug_str_,<_format>,..lbl-..f1-1-c2-c3
\r
390 macro DEBUGFG _level, _group, _format, [_arg] {
\r
393 DEBUGF _level, _format,_arg
\r
395 if _level >= _group
\r
396 DEBUGF 999, _format,_arg
\r
401 macro __include_debug_strings dummy,[_id,_fmt,_len] {
\r
405 if defined _len & ~_len eq
\r
412 load c1 word from %+a2-1
\r
414 if (c1='%s')|(c1='%x')|(c1='%d')|(c1='%u')
\r
429 macro DEBUGF_HELPER _letter,_num,_sign,[_arg] {
\r
435 DEBUG#_letter _sign,_arg
\r
442 macro include_debug_strings {
\r
444 match dbg_str,__debug_strings \{
\r
445 __include_debug_strings dbg_str
\r