私はvalgrindソースコードでいくつかの実験をしようとしています。私はテストコードとして以下のコードを使用しています:Valgrindソースコードからユーザ変数にアクセス
#include <stdio.h>
int g_int = 12;
int main()
{
int y = 10;
int x;
printf("%d\n",x);
return x;
}
"test.out"という名前の実行可能ファイルをビルドします。私は初期化されていないバグがあり、valgrindのは次のように私にいくつかのメッセージを与えることで、「mc_errors.c」からそのバグを報告する私のテストコードで
$./valgrind --tool=memcheck ./test.out
:今
../build/bin$ ./valgrind --tool=memcheck --track-origins=yes --read-var-info=yes ./test >> outpur.txt
==24255== Memcheck, a memory error detector
==24255== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==24255== Using Valgrind-3.14.0.GIT and LibVEX; rerun with -h for copyright info
==24255== Command: ./test
==24255==
==24255== Conditional jump or move depends on uninitialised value(s)
==24255== I want to print my local variable here!
==24255== at 0x4E87B83: vfprintf (vfprintf.c:1631)
==24255== by 0x4E8F898: printf (printf.c:33)
==24255== by 0x400548: main (test.c:10)
==24255== Uninitialised value was created by a stack allocation
==24255== at 0x400526: main (test.c:6)
==24255==
==24255== Use of uninitialised value of size 8
==24255== I want to print my local variable here!
==24255== at 0x4E8476B: _itoa_word (_itoa.c:179)
==24255== by 0x4E8812C: vfprintf (vfprintf.c:1631)
==24255== by 0x4E8F898: printf (printf.c:33)
==24255== by 0x400548: main (test.c:10)
==24255== Uninitialised value was created by a stack allocation
==24255== at 0x400526: main (test.c:6)
==24255==
==24255== Conditional jump or move depends on uninitialised value(s)
==24255== I want to print my local variable here!
==24255== at 0x4E84775: _itoa_word (_itoa.c:179)
==24255== by 0x4E8812C: vfprintf (vfprintf.c:1631)
==24255== by 0x4E8F898: printf (printf.c:33)
==24255== by 0x400548: main (test.c:10)
==24255== Uninitialised value was created by a stack allocation
==24255== at 0x400526: main (test.c:6)
==24255==
==24255== Conditional jump or move depends on uninitialised value(s)
==24255== I want to print my local variable here!
==24255== at 0x4E881AF: vfprintf (vfprintf.c:1631)
==24255== by 0x4E8F898: printf (printf.c:33)
==24255== by 0x400548: main (test.c:10)
==24255== Uninitialised value was created by a stack allocation
==24255== at 0x400526: main (test.c:6)
==24255==
==24255== Conditional jump or move depends on uninitialised value(s)
==24255== I want to print my local variable here!
==24255== at 0x4E87C59: vfprintf (vfprintf.c:1631)
==24255== by 0x4E8F898: printf (printf.c:33)
==24255== by 0x400548: main (test.c:10)
==24255== Uninitialised value was created by a stack allocation
==24255== at 0x400526: main (test.c:6)
==24255==
==24255== Conditional jump or move depends on uninitialised value(s)
==24255== I want to print my local variable here!
==24255== at 0x4E8841A: vfprintf (vfprintf.c:1631)
==24255== by 0x4E8F898: printf (printf.c:33)
==24255== by 0x400548: main (test.c:10)
==24255== Uninitialised value was created by a stack allocation
==24255== at 0x400526: main (test.c:6)
==24255==
==24255== Conditional jump or move depends on uninitialised value(s)
==24255== I want to print my local variable here!
==24255== at 0x4E87CAB: vfprintf (vfprintf.c:1631)
==24255== by 0x4E8F898: printf (printf.c:33)
==24255== by 0x400548: main (test.c:10)
==24255== Uninitialised value was created by a stack allocation
==24255== at 0x400526: main (test.c:6)
==24255==
==24255== Conditional jump or move depends on uninitialised value(s)
==24255== I want to print my local variable here!
==24255== at 0x4E87CE2: vfprintf (vfprintf.c:1631)
==24255== by 0x4E8F898: printf (printf.c:33)
==24255== by 0x400548: main (test.c:10)
==24255== Uninitialised value was created by a stack allocation
==24255== at 0x400526: main (test.c:6)
==24255==
==24255==
==24255== HEAP SUMMARY:
==24255== in use at exit: 0 bytes in 0 blocks
==24255== total heap usage: 1 allocs, 1 frees, 4,096 bytes allocated
==24255==
==24255== All heap blocks were freed -- no leaks are possible
==24255==
==24255== For counts of detected and suppressed errors, rerun with: -v
==24255== ERROR SUMMARY: 8 errors from 8 contexts (suppressed: 0 from 0)
それから私は、コマンドの下に実行しました私は "g_int"と "y"の値をvalgrindからのメッセージ(バグレポート)と共に表示したいと思います。私はvalgrindソース印刷ですでに印刷を追加しています: "私はローカル変数をここに印刷したい!" 内部APIを使用してvalgrindソースからユーザーソースコードから変数の値を読み取る方法はありますか? ユーザーコードからすべての変数名を取得できる場合はプラスになります。
はあなたをしました-g、-ggdb、または-ggdb3フラグを指定してコードをコンパイルしますか? –
あなたの質問はあまり意味がありません。あなたは質問を言い換えて、おそらく完全なvalgrind出力を投稿できますか? – ks1322
コンパイル時に-gを使用しました。 -ggdb3を使うべきですか? – kayas