0
点赞
收藏
分享

微信扫一扫

Unix C调试信息输出, #define debug_error(fmt, ...)


对于daemon守护进程,不能直接printf, 在公共的.h头文件中加入以下内容

#define debug_error(fmt, ...) \
  do {                                 \
	  char path[255];                  \
	  memset(path, 0, 255);              \
	  strcpy(path, getenv("FAPWORKDIR")); \
	  strcat(path, "/log/stderr");   \
	  FILE *fp = fopen(path, "a");  \
	  fprintf(fp, fmt, ##__VA_ARGS__);  \
	  fclose(fp);   \
  } while(0);    \

grep -rn "debug_error" .

检查有没有重名,重名改个宏名称

~/.bash_profile 配置 
export FAPWORKDIR="/home/star30"

更新vim ctags,切换到项目代码所在目录

find . -name "*.[c|h] | xargs ctags

用法:

int xxx = 1;
debug_error("before _shm_chk_to_attach: %d", xxx);

/* 查看调试 */
tail -f ${FAPWORKDIR}/log/stderr

举报

相关推荐

0 条评论