esrf

Beamline Instrument Software Support
SPEC Macro documentation: [ Macro Index | BCU Home ]

#%TITLE% debugfile.mac
#%NAME%
#   Macros to store debug information on a file.
#
#%CATEGORY% Tools
#
#%DESCRIPTION%
#   This macro set allows to store debug information
#   in a file in a transparent mode to the user.
#   The file is deleted each time the SPEC prompt is
#   reached.
#   Typical application is SPEC blocking during some
#   device server access when one does not know  the
#   device being accessed and the error being hard to
#   reproduce.
#%SETUP%
#%PRE%
#   The line debugfileon HAS TO BE in the setup.
#   If it is called from the prompt the debug file
#   will be deleted after each SPEC start not being
#   able to recover the information of last crash.
#%PRE%
#%END%

global DEBUG_FILE_ON
global DEBUG_FILE
global DEBUG_NON_STANDARD_END

#%UU% [keep_file_on_exit_flag]
#%MDESC%
#%PRE%
#   This macro sets SPEC into debug 192 mode and
#   adds hooks in prompt_mac and end_mac to store
#   the debug information.
#   If last time SPEC did not quit properly  the
#   macro will refuse to be activated in order to
#   keep the old debug file. Nevertheless, if one
#   does not need the old debug file, one can first
#   execute debugfileoff.
#   If it desired to keep the debug file on normal
#   SPEC exit it has to be executed with 1 as first
#   argument.
#%PRE%
def debugfileon '{
    local unix_cmd
    if ($#){
        DEBUG_KEEP_ON_EXIT = $1
    }
    if(DEBUG_NON_STANDARD_END == 0){
    	if(DEBUG_FILE_ON == 0){
    		DEBUG_FILE_ON=1
    	}else{
    		close(DEBUG_FILE)
    	}
    	DEBUG_FILE=sprintf("%s/%s.dlog",CWD,SPEC)
    	debug_fileon
    	open(DEBUG_FILE)
    	on(DEBUG_FILE)
    	debug 192
    	cdef("end_mac","debugfile_end\n","dbgfile",0x10)
    }else{
        debug 0
    	printf("You may have IMPORTANT information in %s\n",DEBUG_FILE)
    	cdef("","","dbgfile","delete")
        if (DEBUG_FILE_ON){
            off(DEBUG_FILE)
            close(DEBUG_FILE)
            DEBUG_FILE_ON = 0
        }
    }
}'

#%IU%
#%MDESC%
#%PRE%
#   Implements a hook into prompt_mac
#%PRE%
def debug_fileon '
cdef("prompt_mac","\ndebug_info;\n","dbgfile",0x10)
'

#%UU%
#%MDESC%
#%PRE%
#   It deactivates the macros restoring debug 0 and
#   removing the hooks.
#%PRE%
def debugfileoff '
    cdef("prompt_mac","","dbgfile","delete")
    printf("DEBUG_FILE %s deactivated\n",DEBUG_FILE)
    debug 0
    if (DEBUG_FILE_ON){
        off(DEBUG_FILE)
        close(DEBUG_FILE)
        DEBUG_FILE_ON=0
    }
    DEBUG_NON_STANDARD_END=0
'

#%IU%
#%MDESC%
#%PRE%
#   This macro is called in prompt_mac.
#   It deletes the debug file and opens it again.
#   It calls savstate in order to store a variable
#   (DEBUG_NON_STANDARD_END) that is used the next
#   time SPEC starts.
#%PRE%
def debug_info '{
    local unix_cmd
    if (DEBUG_FILE_ON){
        off(DEBUG_FILE)
        close(DEBUG_FILE)
    }
    unix_cmd=sprintf("/bin/rm %s 2>/dev/null",DEBUG_FILE)
    unix(unix_cmd)
    printf("DEBUG redirected to %s\n",DEBUG_FILE)
    open(DEBUG_FILE)
    on(DEBUG_FILE)
    DEBUG_NON_STANDARD_END=1
    savstate
}
'

#%IU%
#%MDESC%
def debug_inforesetup_end '
    if (DEBUG_FILE_ON){
    	cdef("prompt_mac","","dbgfile","delete")
    	off(DEBUG_FILE)
    	close(DEBUG_FILE)
    }
    DEBUG_FILE_ON = 0
'

#%IU%
#%MDESC%
#%PRE%
#   This macro is called by end_mac.
#   It sets debug mode to 0 and deletes the debug file
#   unless debugfileinfo was called with 1 as argument.
#%PRE%
def debugfile_end ' 
    DEBUG_NON_STANDARD_END = 0
    debug 0
    if (DEBUG_KEEP_ON_EXIT != 1){
        off(DEBUG_FILE)
        close(DEBUG_FILE)
        unix_cmd=sprintf("/bin/rm %s 2>/dev/null",DEBUG_FILE)
        unix(unix_cmd)
        printf("DEBUG file %s deleted\n",DEBUG_FILE)
    }
'
#%MACROS%
#%IMACROS%
#%AUTHOR% V.A.Sole - BLISS - ESRF - Copyright 2002
#%TOC%
#