1

我在理解 Valgrind 输出时遇到了一些麻烦:

1> 在自动生成的 adb 文件中出现“大小为 4 的无效写入”,

  return (gnat_exit_status); -- this is line 314 of b~main.adb

并且 gnat_exit_status 定义如下:

   gnat_exit_status : Integer;
   pragma Import (C, gnat_exit_status);

2>“进程以信号 11 (SIGSEGV) 的默认操作终止”这是 valgrind 还是我的程序?我从 valgrind 获得了 139 的返回值,但是当自己运行 main 时,我得到 0,这正是我所期望的!

memcheck 的完整输出:

$ valgrind ./main
==2844== Memcheck, a memory error detector
==2844== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==2844== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info
==2844== Command: ./main
==2844== 
==2844== Invalid write of size 4
==2844==    at 0x804BA2F: main (b~main.adb:314)
==2844==  Address 0xbee56294 is not stack'd, malloc'd or (recently) free'd
==2844== 
==2844== 
==2844== Process terminating with default action of signal 11 (SIGSEGV)
==2844==  Access not within mapped region at address 0xBEE56294
==2844==    at 0x804BA2F: main (b~main.adb:314)
==2844==  If you believe this happened as a result of a stack
==2844==  overflow in your program's main thread (unlikely but
==2844==  possible), you can try to increase the size of the
==2844==  main thread stack using the --main-stacksize= flag.
==2844==  The main thread stack size used in this run was 8388608.
==2844== 
==2844== HEAP SUMMARY:
==2844==     in use at exit: 0 bytes in 0 blocks
==2844==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==2844== 
==2844== All heap blocks were freed -- no leaks are possible
==2844== 
==2844== For counts of detected and suppressed errors, rerun with: -v
==2844== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 19 from 8)
Segmentation fault
$ 

任何帮助表示赞赏:)

新创建

4

1 回答 1

2

自大学以来我就没有使用过 Valgrind,但我可以给你一些东西来为你指明正确的方向。

首先,我知道 prog 的编译方式会有所不同。您应该使用 -g 标志而不是使用 -O#(优化)。此外,我总是使用 -v 运行 Valgrind,因此它输出最多的信息(大量信息)。

查看此页面: http ://www.redhat.com/magazine/015jan06/features/valgrind/

大约一半是标题为“运行 valgrind 之前”和“如何阅读 valgrind 错误报告”的部分将帮助您。

于 2011-06-08T18:49:29.860 回答