Page 1 of 1

DEBUGFG macro (log groups)

Posted: Wed Dec 28, 2016 5:07 am
by dunkaist
Hi,

I wrote a macro I wanted for a long time. It took 10 lines and a few hours:

Code: Select all

macro DEBUGFG _level, _group, _format, [_arg] {
 common
  if _group eqtype
   DEBUGF _level, _format,_arg
  else
   if _level >= _group
    DEBUGF 999, _format,_arg
   end if
  end if
}
This macro introduces so called log groups, a method to combine debug messages into logical groups to set their log level on per group basis.

Here is a simple example:
Spoiler:

Code: Select all

use32
    org 0x0
    db  'MENUET01'
    dd  0x01,start,i_end,e_end,e_end,0,0

__DEBUG__ = 1
__DEBUG_LEVEL__ = 2

LOG_FLOW equ 1
LOG_CALC equ 3
LOG_SEND equ 

include '../../../macros.inc'
include '../../../debug-fdo.inc'

start:
        DEBUGFG 1, LOG_FLOW, '1 flow\n'
        DEBUGFG 2, LOG_FLOW, '2 flow\n'
        DEBUGFG 3, LOG_FLOW, '3 flow\n'

        DEBUGFG 1, LOG_CALC, '1 calc\n'
        DEBUGFG 2, LOG_CALC, '2 calc\n'
        DEBUGFG 3, LOG_CALC, '3 calc\n'

        DEBUGFG 1, LOG_SEND, '1 send\n'
        DEBUGFG 2, LOG_SEND, '2 send\n'
        DEBUGFG 3, LOG_SEND, '3 send\n'

        DEBUGF 1, '1 blah\n'
        DEBUGF 2, '2 blah\n'
        DEBUGF 3, '3 blah\n'

        mov     eax, -1
        int     0x40


include_debug_strings 

i_end:
rb 0x100        ;stack
e_end:
On debug board:

Code: Select all

1 flow
2 flow
3 flow
3 calc
2 send
3 send
2 blah
3 blah
The macro works as follows:
  • If you specify log level for a group, it overrides __DEBUG_LEVEL__ for this particular group;
  • If you don't specify group log level, __DEBUG_LEVEL__ is used (calls DEBUGF);
  • If you misspelled group name, fasm will report an error.

Code: Select all

$ fasm loggroups.asm loggroups
flat assembler  version 1.71.58  (16384 kilobytes memory)
loggroups.asm [23]:
        DEBUGFG 3, LOG_CLAC, '3 calc\n'
../../../debug-fdo.inc [380] DEBUGFG [5]:
   if _level >= _group
processed: if 3>=LOG_CLAC
error: undefined symbol 'LOG_CLAC'.
I hope this new macro will be useful for you.

Re: DEBUGFG macro (log groups)

Posted: Wed Dec 28, 2016 12:55 pm
by Pathoswithin
It certainly could be useful... if you write a commentary about its arguments (or a one-string example). Same for the other macros. Cause each time I look into the fdo.inc I see a shit, so it's totally useless for me.