/**************************************************************************** * This file is part of the v2lin Library. * VxWorks is a registered trademark of Wind River Systems, Inc. * * Copyright (C) 2006 Constantine Shulyupin, conan.sh@gmail.com * * The v2lin library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * The v2lin Library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * ****************************************************************************/ #ifndef __V2LIN_DEBUG__ #define __V2LIN_DEBUG__ #include #include #include #include #include #include #ifdef USE_CYGWIN #include #else #include #endif pid_t gettid(void); #include "internal.h" extern int trace; extern int trace_cnt; extern int tid; extern char trace_fn[100]; extern struct timeval prev_tv; extern struct timeval start_tv; //#define DEBUG void trace_time(); #ifdef DEBUG // TRACEV is for printing variable name and value #define TRACEV(F,V) do { if (trace) { \ if ( tid != gettid() ) { \ tid = gettid();\ fprintf(stderr,"thread=%i\n",tid);}; \ fprintf(stderr,#V"="F"\n",V); \ } } while (0) #define TRACEF(args ... ) do { if (trace) { \ trace_time(); \ fprintf(stderr,"%s:%i", __FILE__, __LINE__); \ if ( strcmp(trace_fn,__FUNCTION__) ) \ strcpy(trace_fn,__FUNCTION__) && fprintf(stderr," %s()",trace_fn); \ fprintf(stderr," "args); \ fprintf(stderr,"\n"); \ } } while (0) // if ( tid != gettid() ) { // tid = gettid(); // fprintf(stderr,"\nthread=%i task=%x %s\n",(int)tid,(int)my_task(),my_task()?my_task()->taskname:NULL);}; // #else #define TRACEV(F,V) #define TRACEF(args ... ) #endif #define FNSTART int status = OK; #define FNFINISH exit: return status; #ifdef TRACE_IN_OUT #define FN_IN(s) TRACEF("%s {",s) #define FN_OUT(s) TRACEF("%s }",s) #else #define FN_IN(s) #define FN_OUT(s) #endif // ON_ERR defines common error processing behaveur: // a) ignore error and continue code exection // b) goto to finalization sections of a functions #define ON_ERR // ignore //#define ON_ERR goto exit // CHK and CHK0 - common macros for error processing // and optional code tracing. This marcos prints error messages and // optionally processes errors in case of subfunction failures. #define TRACE_errno() fprintf(stderr,"\t|%s:%d| errno=%i(%x) %s \n",__FUNCTION__, __LINE__, errno, errno, VxWorksError(errno)) // CHK supposes !0 is success, suitable for checking pointers // and functions in form: CHK(0