valgrind
向我展示了以下内容:
==13880== Warning: invalid file descriptor -1 in syscall close()
有没有简单的方法来调查此错误?我的意思是 - 例如显示堆栈跟踪?
这是一个庞大的项目,我无法手动检查每个close
。另外,我猜这对于坏域描述符的每个sys调用都是一样的。
我按照以下方式运行:
valgrind --trace-children=yes --track-fds=yes --log-fd=2 --error-limit=no \
--leak-check=full --show-possibly-lost=yes --track-origins=yes \
--show-reachable=yes ./exe
exe
带有调试信息。
valgrind
输出的更大部分是:
==13880== Conditional jump or move depends on uninitialised value(s)
==13880== at 0x5A4022F: ??? (in /lib/i686/cmov/libc-2.11.3.so)
==13880== by 0x5A57323: ??? (in /lib/i686/cmov/libc-2.11.3.so)
==13880== by 0x5A56EC2: ??? (in /lib/i686/cmov/libc-2.11.3.so)
==13880== by 0x5A5555B: localtime_r (in /lib/i686/cmov/libc-2.11.3.so)
==13880== by 0x754E983: ??? (in /usr/lib/libapr-1.so.0.4.2)
==13880== by 0x754EAC9: apr_time_exp_lt (in /usr/lib/libapr-1.so.0.4.2)
==13880== by 0x6056B56: log4cxx::helpers::TimeZoneImpl::LocalTimeZone::explode(apr_time_exp_t*, long long) const (in /usr/lib/liblog4cxx.so.10.0.0)
==13880== by 0x6037940: log4cxx::helpers::SimpleDateFormat::format(std::string&, long long, log4cxx::helpers::Pool&) const (in /usr/lib/liblog4cxx.so.10.0.0)
==13880== by 0x5FBE539: log4cxx::pattern::CachedDateFormat::format(std::string&, long long, log4cxx::helpers::Pool&) const (in /usr/lib/liblog4cxx.so.10.0.0)
==13880== by 0x5FCEA2B: log4cxx::pattern::DatePatternConverter::format(log4cxx::helpers::ObjectPtrT<log4cxx::spi::LoggingEvent> const&, std::string&, log4cxx::helpers::Pool&) const (in /usr/lib/liblog4cxx.so.10.0.0)
==13880== by 0x601EE10: log4cxx::PatternLayout::format(std::string&, log4cxx::helpers::ObjectPtrT<log4cxx::spi::LoggingEvent> const&, log4cxx::helpers::Pool&) const (in /usr/lib/liblog4cxx.so.10.0.0)
==13880== by 0x605BCAB: log4cxx::WriterAppender::subAppend(log4cxx::helpers::ObjectPtrT<log4cxx::spi::LoggingEvent> const&, log4cxx::helpers::Pool&) (in /usr/lib/liblog4cxx.so.10.0.0)
==13880== Uninitialised value was created by a heap allocation
==13880== at 0x40255BC: malloc (vg_replace_malloc.c:270)
==13880== by 0x5A57A03: ??? (in /lib/i686/cmov/libc-2.11.3.so)
==13880== by 0x5A56D17: ??? (in /lib/i686/cmov/libc-2.11.3.so)
==13880== by 0x5A56E20: ??? (in /lib/i686/cmov/libc-2.11.3.so)
==13880== by 0x5A5555B: localtime_r (in /lib/i686/cmov/libc-2.11.3.so)
==13880== by 0x754E983: ??? (in /usr/lib/libapr-1.so.0.4.2)
==13880== by 0x754EAC9: apr_time_exp_lt (in /usr/lib/libapr-1.so.0.4.2)
==13880== by 0x605701D: log4cxx::helpers::TimeZoneImpl::LocalTimeZone::getTimeZoneName() (in /usr/lib/liblog4cxx.so.10.0.0)
==13880== by 0x6055D53: log4cxx::helpers::TimeZone::getDefault() (in /usr/lib/liblog4cxx.so.10.0.0)
==13880== by 0x6038606: log4cxx::helpers::SimpleDateFormat::SimpleDateFormat(std::string const&) (in /usr/lib/liblog4cxx.so.10.0.0)
==13880== by 0x5FCF09D: log4cxx::pattern::DatePatternConverter::getDateFormat(std::vector<std::string, std::allocator<std::string> > const&) (in /usr/lib/liblog4cxx.so.10.0.0)
==13880== by 0x5FCF587: log4cxx::pattern::DatePatternConverter::DatePatternConverter(std::vector<std::string, std::allocator<std::string> > const&) (in /usr/lib/liblog4cxx.so.10.0.0)
==13880==
==13880== Warning: invalid file descriptor -1 in syscall close()
Warning
之前的空行让我觉得上面的堆栈跟踪与警告无关。此外,在Warning
到达Summary
后,没有别的。
答案 0 :(得分:9)
使用-v运行valgrind(ver.3)也会生成无效的文件描述符 警告堆栈跟踪。
答案 1 :(得分:2)
显而易见的方法是:在close()
中放置一个断点。这当然假设您可以在调试器中运行程序,但是如果您可以在Valgrind中运行它并不是很牵强。