3

valgrind --leak-check=full -v offline

结果是:

--6491-- Reading syms from /home/.../offline/offline (0x400000)
--6491-- Reading syms from /lib64/ld-2.11.3.so (0x4000000)
--6491-- Reading syms from /usr/lib64/valgrind/memcheck-amd64-linux (0x38000000)
--6491--    object doesn't have a symbol table
--6491--    object doesn't have a dynamic symbol table
--6491-- Reading suppressions file: /usr/lib64/valgrind/default.supp
--6491-- REDIR: 0x4015fc0 (strlen) redirected to 0x38042017 (???)
--6491-- Reading syms from /usr/lib64/valgrind/vgpreload_core-amd64-linux.so (0x4a20000)
--6491--    object doesn't have a symbol table
--6491-- Reading syms from /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so (0x4c22000)
--6491--    object doesn't have a symbol table
==6491== WARNING: new redirection conflicts with existing -- ignoring it
--6491--     new: 0x04015fc0 (strlen              ) R-> 0x04c26ee0 strlen
--6491-- REDIR: 0x4015f10 (index) redirected to 0x4c26b40 (index)
--6491-- REDIR: 0x4015f90 (strcmp) redirected to 0x4c274e0 (strcmp)
--6491-- Reading syms from /usr/lib64/R/lib/libR.so (0x4e2c000)
--6491-- Reading syms from /usr/lib64/R/lib/libRblas.so (0x543b000)
--6491-- Reading syms from /usr/lib64/R/lib/libRlapack.so (0x5667000)
--6491-- Reading syms from /usr/lib64/R/library/Rcpp/lib/libRcpp.so (0x59e1000)
--6491-- Reading syms from /usr/lib64/R/library/RInside/lib/libRInside.so (0x5c2e000)
--6491-- Reading syms from /home/anisha/qtsdk-2010.05/qt/lib/libQtGui.so.4.7.0 (0x5e43000)
--6491-- Reading syms from /home/anisha/qtsdk-2010.05/qt/lib/libQtCore.so.4.7.0 (0x6bc0000)
--6491-- Reading syms from /lib64/libpthread-2.11.3.so (0x70a3000)
--6491-- Reading syms from /usr/lib64/libstdc++.so.6.0.14 (0x72c0000)
--6491--    object doesn't have a symbol table
--6491-- Reading syms from /lib64/libm-2.11.3.so (0x75c9000)
--6491-- Reading syms from /lib64/libgcc_s.so.1 (0x7820000)
--6491--   Considering /usr/lib/debug/.build-id/e6/eb8011838a065946e5808e036550844548379f.debug ..
--6491--   .. build-id is valid
--6491-- Reading syms from /lib64/libc-2.11.3.so (0x7a36000)
--6491-- Reading syms from /lib64/libreadline.so.6.1 (0x7da3000)
--6491--    object doesn't have a symbol table
--6491-- Reading syms from /lib64/librt-2.11.3.so (0x7fea000)
--6491-- Reading syms from /lib64/libdl-2.11.3.so (0x81f3000)
--6491-- Reading syms from /usr/lib64/libgomp.so.1.0.0 (0x83f7000)



==6491== 5 errors in context 13 of 34:
==6491== Conditional jump or move depends on uninitialised value(s)
==6491==    at 0x611629E: QHash<unsigned int, int>::findNode(unsigned int const&, unsigned int*) const (../include/QtCore/../../src/corelib/tools/qhash.h:884)
==6491==    by 0x62E9AC6: QTextFormatCollection::indexForFormat(QTextFormat const&) (../include/QtCore/../../src/corelib/tools/qhash.h:865)
==6491==    by 0x62E9E51: QTextFormatCollection::createObjectIndex(QTextFormat const&) (/var/tmp/qt-src/src/gui/text/qtextformat.cpp:3142)
==6491==    by 0x62FF56E: QTextDocumentPrivate::createObject(QTextFormat const&, int) (/var/tmp/qt-src/src/gui/text/qtextdocument_p.cpp:1588)
==6491==    by 0x62FFD57: QTextDocumentPrivate::rootFrame() const (/var/tmp/qt-src/src/gui/text/qtextdocument_p.cpp:1407)
==6491==    by 0x63203B0: QTextDocumentLayout::doLayout(int, int, int) (/var/tmp/qt-src/src/gui/text/qtextdocumentlayout.cpp:2908)
==6491==    by 0x632051C: QTextDocumentLayoutPrivate::ensureLayoutedByPosition(int) const (/var/tmp/qt-src/src/gui/text/qtextdocumentlayout.cpp:3076)
==6491==    by 0x6320978: QTextDocumentLayoutPrivate::layoutStep() const (/var/tmp/qt-src/src/gui/text/qtextdocumentlayout.cpp:3082)
==6491==    by 0x632123C: QTextDocumentLayout::documentChanged(int, int, int) (/var/tmp/qt-src/src/gui/text/qtextdocumentlayout.cpp:2874)
==6491==    by 0x62EF7D3: QTextDocument::documentLayout() const (/var/tmp/qt-src/src/gui/text/qtextdocument.cpp:1070)
==6491==    by 0x62C0D36: QTextControlPrivate::_q_documentLayoutChanged() (/var/tmp/qt-src/src/gui/text/qtextcontrol.cpp:624)
==6491==    by 0x62C104E: QTextControlPrivate::setContent(Qt::TextFormat, QString const&, QTextDocument*) (/var/tmp/qt-src/src/gui/text/qtextcontrol.cpp:434)


==6491== 3 errors in context 10 of 34:
==6491== Use of uninitialised value of size 8
==6491==    at 0x6116276: QHash<unsigned int, int>::findNode(unsigned int const&, unsigned int*) const (../include/QtCore/../../src/corelib/tools/qhash.h:884)
==6491==    by 0x62E9AC6: QTextFormatCollection::indexForFormat(QTextFormat const&) (../include/QtCore/../../src/corelib/tools/qhash.h:865)
==6491==    by 0x62E9E51: QTextFormatCollection::createObjectIndex(QTextFormat const&) (/var/tmp/qt-src/src/gui/text/qtextformat.cpp:3142)
==6491==    by 0x62FF56E: QTextDocumentPrivate::createObject(QTextFormat const&, int) (/var/tmp/qt-src/src/gui/text/qtextdocument_p.cpp:1588)
==6491==    by 0x62FFD57: QTextDocumentPrivate::rootFrame() const (/var/tmp/qt-src/src/gui/text/qtextdocument_p.cpp:1407)
==6491==    by 0x63203B0: QTextDocumentLayout::doLayout(int, int, int) (/var/tmp/qt-src/src/gui/text/qtextdocumentlayout.cpp:2908)
==6491==    by 0x632051C: QTextDocumentLayoutPrivate::ensureLayoutedByPosition(int) const (/var/tmp/qt-src/src/gui/text/qtextdocumentlayout.cpp:3076)
==6491==    by 0x6320978: QTextDocumentLayoutPrivate::layoutStep() const (/var/tmp/qt-src/src/gui/text/qtextdocumentlayout.cpp:3082)
==6491==    by 0x632123C: QTextDocumentLayout::documentChanged(int, int, int) (/var/tmp/qt-src/src/gui/text/qtextdocumentlayout.cpp:2874)
==6491==    by 0x62EF7D3: QTextDocument::documentLayout() const (/var/tmp/qt-src/src/gui/text/qtextdocument.cpp:1070)
==6491==    by 0x62C0D36: QTextControlPrivate::_q_documentLayoutChanged() (/var/tmp/qt-src/src/gui/text/qtextcontrol.cpp:624)
==6491==    by 0x62C104E: QTextControlPrivate::setContent(Qt::TextFormat, QString const&, QTextDocument*) (/var/tmp/qt-src/src/gui/text/qtextcontrol.cpp:434)

==6491== ERROR SUMMARY: 52 errors from 34 contexts (suppressed: 18 from 8)

这些错误都没有指向我的源文件。
我需要担心吗?

Makefile 由 qmake 自动生成。
它确实包含 -Wall。

CC = gcc
CXX = g++
DEFINES = -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED
CFLAGS = -m64 -pipe -O2 -Wall -g -pedantic -W -D_REENTRANT $(DEFINES)

Make 不会向我显示任何警告。

4

2 回答 2

3

以下选项帮助我获得了一些提示(来自 Valgrind 手册页的文本):

  • --num-callers

指定堆栈跟踪中显示的标识程序位置的最大条目数。请注意,仅使用前四个函数位置(当前函数中的位置,以及它的三个直接调用者的位置)来共同处理错误。所以这不会影响报告的错误总数。

最大值为 50。请注意,较高的设置将使 Valgrind 运行得更慢并占用更多内存,但在处理具有深度嵌套调用链的程序时可能很有用。

  • --fullpath-after

默认情况下,Valgrind 仅显示堆栈跟踪中的文件名,而不显示源文件的完整路径。在源位于多个不同目录的大型项目中使用 Valgrind 时,这可能会很不方便。--fullpath-after 为这个问题提供了一个灵活的解决方案。存在此选项时,将显示每个源文件的路径,

  • --track-origins=yes

控制 Memcheck 是否跟踪未初始化值的来源。默认情况下,它不会,这意味着尽管它可以告诉您未初始化的值正在以危险的方式使用,但它无法告诉您未初始化的值来自何处。这通常使追查根本问题变得困难。

于 2012-12-05T10:02:54.990 回答
2

我需要担心吗?

是的。您可能错误地使用了 Qt 的函数,向它们传递了不尊重文档中为它们描述的合同的参数。

假设您memcpy()像这样使用标准库:

char t[10];
memcpy(t, ..., 12);

Valgrind 会在 中标记缓冲区溢出memcpy(),但memcpy()在这种情况下不负责:相反,调用者memcpy()使用错误。

在这里,您可能会将指向未初始化内存的指针传递给希望能够从中读取的 Qt 函数。如果 Qt 函数被记录为从指定的内存中读取,则意味着您的程序有问题。

编辑:

同样,错误函数的直接调用者可能不是真正的罪魁祸首:它本身可能因接收到错误的参数而被绊倒。实际上,当 Valgrind 检测到问题时,编程错误位于当前调用堆栈中的某个位置。在“契约式设计”中,鼓励考虑功能需求和保证的编程方法,这被称为“分配责任”。

于 2012-12-05T08:44:36.390 回答