2012-01-05 11 views
2

これは愚かな質問のように思えるかもしれませんが、valgrindはデフォルトで十分な情報を提供していません。 Valgrindは次のように報告しています。valgrindでどの値の値が初期化されていないのかを特定するにはどうすればよいですか?

==2541== Conditional jump or move depends on uninitialised value(s) 
==2541== at 0x401777: process_read.clone.3 (in /home/matt/dev/ocs/client3/a.out) 
==2541== by 0x4026B8: obbs_main (in /home/matt/dev/ocs/client3/client) 
==2541== by 0x53D1D8B: start_thread (pthread_create.c:304) 
==2541== by 0x511D04C: clone (clone.S:112) 

明らかなことはありません。 Valgrind -vも役に立ちません。

valgrindに初期化されていない値を教えてもらう方法はありますか?

+1

は、あなたのコンパイラは、あなたがあなたもvalgrindの中でそれを実行するために取得する前にいることを知らせることではないでしょうか? –

+0

コンパイラは-Wallでもサイレントです。多分、mallocの構造体の中の変数であることとは関係があります。 – Matt

答えて

4

valgrindで--track-origins=yesフラグを使用すると、ユニット化されたメモリが最初に割り当てられた行番号(-gでコンパイルしたと仮定します)が表示されます。これは、通常、関数の先頭のどこかでスタックの割り当てにあります。

-Wallでもコンパイルしてみてください。 -Wallは、コンパイル時に「使用された初期化されていない」エラーのほとんどをキャッチする必要があります。

+0

ありがとう、それを得た。以前はcallocで初期化されたフィールドを含む構造体がありました。しかし、私はmallocに変更し、手動でそのフィールドを初期化することを忘れました。 – Matt

1

Valgrindのは、初期化されていない値の使用についてユーザーに通知 - だけでなく、初期化されていない値例えば:

==1029== Memcheck, a memory error detector 
==1029== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al. 
==1029== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info 
==1029== Command: a.out 
==1029== 
==1029== Conditional jump or move depends on uninitialised value(s) 
==1029== at 0x4004D7: main (uninit.c:6) 
==1029== 
==1029== 
==1029== HEAP SUMMARY: 
==1029==  in use at exit: 0 bytes in 0 blocks 
==1029== total heap usage: 0 allocs, 0 frees, 0 bytes allocated 
==1029== 
==1029== All heap blocks were freed -- no leaks are possible 
==1029== 
==1029== For counts of detected and suppressed errors, rerun with: -v 
==1029== Use --track-origins=yes to see where uninitialised values come from 
==1029== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 6 from 6) 
[[email protected] ~]$ cat uninit.c 
#include <stdio.h> 
int main(int argc, char *argv[]) 
{ 
    int i; 

    if(i) 
    { 
     printf("Hello\n"); 
    } 
    return 0; 
} 
関連する問題