⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 trace.h

📁 TRACE的源代码,在LINUX调试程序要使用的.
💻 H
📖 第 1 页 / 共 2 页
字号:
    /* now accomplish the prepending of the time and the appending of the newline */    sprintf( newbuf, "%s%s\n", timbuf, msg );    va_start( ap, msg );    vprintf( newbuf, ap );    va_end( ap );    return;}# endif# ifndef  TRACE_USER_FUNCTIONtypedef void (*func_ptr_t)(struct timeval*,int,int,char*,...);static func_ptr_t trace_user_functions[]=TRACE_FUNCTIONS;#  define TRACE_USER_FUNCTION( tv_adr, tid, lvl, msg, params... ) \    /* NOTE THE FUNCTION ARRAY IDX 0 LINES UP WITH MODE/LEVEL IDX 1 */\    do \    {       int	_ii_, lidx;\        lidx = TRACE_TID * traceControl_sp->numberOfFunctions;\        for (_ii_=1; _ii_<traceControl_sp->numberOfFunctions; _ii_++)\        {   if ((traceControl_sp->mode&(1<<_ii_)) && (traceLevel_ip[lidx+_ii_]&(1<<lvl)))\	    { if (trace_user_functions[_ii_-1])\              {   if ((tv_adr)->tv_sec == 0) gettimeofday( tv_adr, 0 );\		  trace_user_functions[_ii_-1](tv_adr,tid,lvl, msg , ## params );\              }\	    }\        }\    } while (0)# endifstatic int			traceControl_fd=0;static int			disabled_level[4]={0};static struct s_traceControl	disabled_control={{0}};/*  This can be a function with no fear of producing "warning: defined, but    not used" because it is referenced from the TRACE macro.*/static inttraceControl_Init( char *name ){	int			fd_map;	int			levelArraySize;	int			levelOffset;	int			sts;	union u_traceIoctl	ioctl_data;    /*  This should assure we do init processing once. Use ReInit to	change name.        Note: first call may return -1 while successive calls will	return 0. */    if (traceControl_sp) return (0);    /* incase anything bad happens... */    traceTID = 0;    traceControl_sp = &disabled_control;    traceLevel_ip   = disabled_level;    traceControl_sp->numberOfFunctions = ( sizeof(disabled_level)					  /sizeof(disabled_level[0]));    traceControl_fd = open( "/proc/trace/control", O_RDONLY );    if (traceControl_fd == -1)    {   perror( "open /proc/trace/control" );	fprintf( stderr, "continueing with disabled tracing\n" );	return (-1);    }    /* get a traceTID via ioctl */    if (name[0] == '\0')    {   /* try TRACE_NAME (which may actually be the same thing [""] */	name = TRACE_NAME;    }    ioctl_data.generic.ptr = name;    sts = ioctl( traceControl_fd, traceIoctl_e_init, &ioctl_data );    traceTID = ioctl_data.generic.num;    fd_map = open( "/proc/trace/map", O_RDONLY );    if (fd_map == -1)    {   perror( "open /proc/trace/map" );	fprintf( stderr, "continueing with disabled tracing\n" );	traceTID = 0;	traceControl_fd = -1;	traceControl_sp = &disabled_control;	traceLevel_ip   = disabled_level;	traceControl_sp->numberOfFunctions = ( sizeof(disabled_level)					      /sizeof(disabled_level[0]));	return (-1);    }    traceControl_sp = (struct s_traceControl *)mmap(  0 /* hint address */						    , sizeof(struct s_traceControl)						    , PROT_READ						    , MAP_SHARED						    , fd_map						    , 0 /* offset */ );    if (traceControl_sp == (void *)-1/*MAP_FAILED*/)    {   perror( "mmap /proc/trace/map" );	fprintf( stderr, "continueing with disabled tracing\n" );	traceTID = 0;	traceControl_fd = -1;	traceControl_sp = &disabled_control;	traceLevel_ip   = disabled_level;	traceControl_sp->numberOfFunctions = ( sizeof(disabled_level)					      /sizeof(disabled_level[0]));	return (-1);    }#   if 0    else    {   void	(*trace_functions[])(struct timeval*,int,int,char*,...)=TRACE_FUNCTIONS;	/*  init up to the lesser of the two:	        traceControl_sp->numberOfFunctions		or the number of initializer in TRACE_FUNCTIONS		NOTE THE FUNCTION ARRAY IDX 0 LINES UP WITH MODE/LEVEL IDX 1	*/	for (sts=1;	     (  (sts<traceControl_sp->numberOfFunctions)	      &&((sts-1)<(int)(sizeof(trace_functions)/sizeof(void*))));	     sts++)	{   (trace_user_functions)[sts-1] = trace_functions[sts-1];	}	/* if traceControl_sp->numberOfFunctions has more, init the rest to NULL	 */	for (;	     (  (sts<traceControl_sp->numberOfFunctions));	     sts++)	{   (trace_user_functions)[sts-1] = NULL;	}    }#   endif    levelArraySize = ( traceControl_sp->numberOfTID		      *traceControl_sp->numberOfFunctions);    /*  NEED TO REORGANIZE STRUCTURE TO REMOVE HARD CODED NUMBER	ref. trace_proc.c:trace_proc_map_mmap() */    levelOffset = 4096;    traceLevel_ip = (int *)mmap(  0 /* hint address */				, levelArraySize * sizeof(int)				, PROT_READ				, MAP_SHARED				, fd_map				, levelOffset );    if (traceLevel_ip == (void *)-1/*MAP_FAILED*/)    {   perror( "mmap level" );	fprintf( stderr, "continueing with disabled tracing\n" );	traceTID = 0;	traceControl_fd = -1;	traceControl_sp = &disabled_control;	traceLevel_ip   = disabled_level;	traceControl_sp->numberOfFunctions = ( sizeof(disabled_level)					      /sizeof(disabled_level[0]));	return (-1);    }    /*  skip past initial	NOTE: it does not work to add this to the offset as mmap page	aligns the returned pointer */    traceLevel_ip += traceControl_sp->numberOfFunctions;    close( fd_map );    return (0);}   /* traceControl_Init *//* to allow a forked process to get a new TID via a new name i.e.   parentName = "This"   forkedName = "This_" */#define traceControl_ReInit( name )	\			({  int	__sts__=0;\			    if (!traceControl_sp)\			    {   traceControl_Init("");\			    }\			    else if (traceControl_fd > 0)\			    {   /* get a traceTID via ioctl */\				union u_traceIoctl	ioctl_data;\				ioctl_data.generic.ptr = name;\				__sts__ = ioctl( traceControl_fd, traceIoctl_e_init, &ioctl_data );\				traceTID = ioctl_data.generic.num;\			    }\			    __sts__;\			})#define traceControl_Mode( new_mode )	\			({  int	old_mode;\			    if (!traceControl_sp) traceControl_Init("");\			    old_mode = traceControl_sp->mode;\			    if (traceControl_fd > 0)\			    {   ioctl( traceControl_fd, traceIoctl_e_modeSet, new_mode );\			    }\			    old_mode;\			})#define traceControl_ModeGet()	\			({  if (!traceControl_sp) traceControl_Init("");\			    traceControl_sp->mode;\			})/* Set bits (i.e. bitwise OR mode with value specified) */#define traceControl_ModeSet( mask )	\			({  int	old_mode, new_mode;\			    if (!traceControl_sp) traceControl_Init("");\			    old_mode = traceControl_sp->mode;\			    new_mode = old_mode | mask;\			    if (traceControl_fd > 0)\			    {   ioctl( traceControl_fd, traceIoctl_e_modeSet, new_mode );\			    }\			    else\			    {   traceControl_sp->mode = new_mode;\			    }\			    old_mode;\			})/* Clr bits (i.e. bitwise AND mode with ones-complement of value specified) */#define traceControl_ModeClr( mask )	\			({  int	old_mode, new_mode;\			    if (!traceControl_sp) traceControl_Init("");\			    old_mode = traceControl_sp->mode;\			    new_mode = old_mode & ~mask;\			    if (traceControl_fd > 0)\			    {   ioctl( traceControl_fd, traceIoctl_e_modeSet, new_mode );\			    }\			    else\			    {   traceControl_sp->mode = new_mode;\			    }\			    old_mode;\			})#define traceControl_Reset()	\			({  if (!traceControl_sp) traceControl_Init("");\			    if (traceControl_fd > 0)\			    {   ioctl( traceControl_fd, traceIoctl_e_reset, 0 );\			    }\			})#define traceControl_PMCGet( which )	\			({   union u_traceIoctl	ioctl_data;\			     if (!traceControl_sp) traceControl_Init("");\			     if (traceControl_fd > 0)\			     {   ioctl_data.pmc.whichIn_cpuidOut = which;\				 ioctl( traceControl_fd, traceIoctl_e_PMCGet, &ioctl_data );\			     }\			     ioctl_data.pmc.pmc_data_val;\			})#define traceControl_PMCRead( which, cpuidOut_ptr )	\			({   union u_traceIoctl	ioctl_data;\			     if (!traceControl_sp) traceControl_Init("");\			     if (traceControl_fd > 0)\			     {   ioctl_data.pmc.whichIn_cpuidOut = which;\				 ioctl( traceControl_fd, traceIoctl_e_PMCGet, &ioctl_data );\			     }\                             *(cpuidOut_ptr) = ioctl_data.pmc.whichIn_cpuidOut;\			     ioctl_data.pmc.pmc_data_val;\			})#define traceControl_LevelSet( func, __mask__ )	\			({  union u_traceIoctl	ioctl_data;\			    if (!traceControl_sp) traceControl_Init("");\			    if (traceControl_fd > 0)\			    {   ioctl_data.generic.num = traceTID;\				ioctl_data.generic.ptr = (void*)func;\				ioctl_data.generic.mask = __mask__;\				ioctl( traceControl_fd, traceIoctl_e_levelSet, &ioctl_data );\			    }\			    else if (func < (sizeof(disabled_level)/sizeof(int)))\			    {   traceLevel_ip[func] = __mask__;\			    }\			})#define traceControl_LevelGet( func )	\			({  int lidx;\			    if (!traceControl_sp) traceControl_Init("");\			    lidx = TRACE_TID * traceControl_sp->numberOfFunctions;\			    traceLevel_ip[lidx+func];\			})#endif	/* of #else for ifdef __KERNEL__ *//*----------------------------------------------------------------------------*/#endif	/* __TRACE_H */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -