【发布时间】:2016-12-01 08:57:24
【问题描述】:
我正在关注“Learn C the Hard Way”,特别是 the chapter on Valgrind。本章提供了一个故意错误的程序来展示 Valgrind 的工作原理。
当我在 Valgrind 下运行练习时,我的堆栈跟踪中没有行号,只有 '(below main)' 用于错误。
我肯定使用 -g 标志进行编译。
我的 Valgrind 输出如下:
djb@twin:~/projects/Learning/C$ valgrind ./ex4
==5190== Memcheck, a memory error detector
==5190== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==5190== Using Valgrind-3.6.1-Debian and LibVEX; rerun with -h for copyright info
==5190== Command: ./ex4
==5190==
==5190== Use of uninitialised value of size 4
==5190== at 0x4078B2B: _itoa_word (_itoa.c:195)
==5190== by 0x407CE55: vfprintf (vfprintf.c:1619)
==5190== by 0x40831DE: printf (printf.c:35)
==5190== by 0x4052112: (below main) (libc-start.c:226)
==5190==
==5190== Conditional jump or move depends on uninitialised value(s)
==5190== at 0x4078B33: _itoa_word (_itoa.c:195)
==5190== by 0x407CE55: vfprintf (vfprintf.c:1619)
==5190== by 0x40831DE: printf (printf.c:35)
==5190== by 0x4052112: (below main) (libc-start.c:226)
==5190==
==5190== Conditional jump or move depends on uninitialised value(s)
==5190== at 0x407CC10: vfprintf (vfprintf.c:1619)
==5190== by 0x40831DE: printf (printf.c:35)
==5190== by 0x4052112: (below main) (libc-start.c:226)
==5190==
==5190== Conditional jump or move depends on uninitialised value(s)
==5190== at 0x407C742: vfprintf (vfprintf.c:1619)
==5190== by 0x40831DE: printf (printf.c:35)
==5190== by 0x4052112: (below main) (libc-start.c:226)
==5190==
I am 0 years old.
I am 68882420 inches tall.
==5190==
==5190== HEAP SUMMARY:
==5190== in use at exit: 0 bytes in 0 blocks
==5190== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==5190==
==5190== All heap blocks were freed -- no leaks are possible
==5190==
==5190== For counts of detected and suppressed errors, rerun with: -v
==5190== Use --track-origins=yes to see where uninitialised values come from
==5190== ERROR SUMMARY: 22 errors from 4 contexts (suppressed: 11 from 6)
我在 VirtualBox 虚拟机中使用 Ubuntu 11.10。
感谢您的帮助。
更新
似乎如果我从main() 调用一个函数并且该函数包含一个错误(例如一个未初始化的变量),那么我确实会跟踪到该函数在@ 中被调用的位置987654329@。但是,main() 中的错误仍未指定。示例见this paste。
【问题讨论】:
-
请创建一个新的空目录,并将您在pastebin.com/A6bK2hdw 找到的内容放入该目录;这是一个尝试重现问题的 bash 脚本。当我运行它时,我得到的输出就像你在 pastebin.com/JncWz2GF 看到的那样,这就是你的教程说你应该得到的。自己运行。如果你得到正确的输出,然后确定你做它的方式与这个 shell 脚本有什么不同。如果你运行这个 shell 脚本并得到不正确的输出,如上所示,回来讨论吧。
-
嗨@Bill,感谢您的帮助。在运行您的脚本时,我得到相同的输出以及有关时钟偏差的警告。 http://pastebin.com/fjfPrLts
-
我遇到了同样的问题,同样的操作系统,同样的 VirtualBox 虚拟机。我试过 valgrind 3.6.1 和 3.7.0 都没有使用 -g 选项显示行号。
-
我猜这个问题与 VirtualBox 本身有关。我不熟悉VirtualBox。我建议您将 VirtualBox 标签添加到您的问题中,看看是否有什么东西浮出水面。如果这没有帮助,请查看forums.virtualbox.org 的人员是否可以提供帮助。希望我能提供更多帮助。对不起。
-
刚刚在 Mac OSX 上测试了与我的 Ubuntu/VBox 设置相同的版本,它在 Mac 上完美运行。我认为 Bill 可能是对的,它要么是 VBox 的东西,要么是 Ubuntu 的东西。