刚刚解决了一个自认为十分诡异的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)进行第二步处理,在日志信息中增加写入日志的时间;
InternalDispatch(const char *format, va_list vars)进行日志的最终拼接及写入。
对比上面的core dump,可以发现其中少了对于Debug(const

本文探讨了一起因GCC在32位和64位平台中va_list类型不同导致的编译问题。在32位系统中,va_list被定义为char *,而在64位系统中则是一个特定的结构体__va_list_tag。这个问题在32位平台上引发了程序崩溃,通过分析核心转储文件和源代码,发现函数重载错误是由于类型匹配导致的。解决方案在于理解和适配不同平台的va_list实现。
最低0.47元/天 解锁文章
906

被折叠的 条评论
为什么被折叠?



