刚刚解决了一个自认为十分诡异的BUG,其根本原因是自己的技术深度不够,没有考虑不同平台下gcc中内置变量的定义不同所造成的。
现象为Koala LINUX客户端在64位平台工作正常,在32位平台会出现core dump,对core文件进行分析,调用堆栈如下所示:
#0 0x00322701 in vfprintf () from /lib/libc.so.6
#1 0x003475f0 in vsnprintf () from /lib/libc.so.6
#2 0x0805c23b in inspsys::InspLog::InternalDispatch (this=0x838e050,
format=0xbfef57a0 "[AGFSMONITOR][DEBUG]begin handle message %s",
vars=0x8062c73 "why") at insplog.cpp:100
#3 0x0805bfdf in inspsys::InspLog::Debug (this=0x838e050,
fmt=0x8062c77 "begin handle message %s", vars=0x8062c73 "why")
at insplog.cpp:26
#4 0x08053658 in FSMonitorService::HandleMessage (this=0x806f660)
at fsmonitorservice.cpp:191
#5 0x0804b789 in main () at agfsmonitor.cpp:50
可见,在HandleMessage中调用了InspLog进行日志打印,进而调用vsnprintf进行不定参的解析时出现core dump。其中,InspLog的定义简要如下所示:
class InspLog
{
public:
//不定参日志接口
void Debug(const char *format, ...);
void Debug(const char *format, va_list vars);
private:
void InternalDispatch(const char *format, va_list vars);
};
写入日志时,其调用过程应为Debug(const char *format,...)->Debug(const char *format, va_list vars)->InternalDispatch(oncst char *format, va_list vars).
其中,Debug(const char *format, ...)对可变参数进行第一步处理,在日志信息中增加写入日志的模块名;
Debug(const char *format, va_list vars)进行第二步处理,在日志信息中增加写入日