4

automake を使用してプロジェクトをコンパイルしていますが、結果の実行可能ファイルで valgrind を実行しようとすると、期待どおりに動作せず、チェックしたいコードを実際に実行する前に 8 回実行されたように見え、その部分のヒープ サマリーが表示されます。のコードがまったく表示されない:

==4601== Memcheck, a memory error detector
==4601== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.                                                                                            
==4601== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info                                                                                          
==4601== Command: ./launcher -g ../data/params.txt                                                                                                                  
==4601==                                                                                                                                                            
==4605==                                                                                                                                                            
==4605== HEAP SUMMARY:                                                                                                                                              
==4605==     in use at exit: 0 bytes in 0 blocks                                                                                                                    
==4605==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated                                                                                                   
==4605==                                                                                                                                                            
==4605== All heap blocks were freed -- no leaks are possible                                                                                                        
==4605==                                                                                                                                                            
==4605== For counts of detected and suppressed errors, rerun with: -v                                                                                               
==4605== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)                                                                                             
==4604==                                                                                                                                                            
==4604== HEAP SUMMARY:                                                                                                                                              
==4604==     in use at exit: 0 bytes in 0 blocks                                                                                                                    
==4604==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated                                                                                                   
==4604==                                                                                                                                                            
==4604== All heap blocks were freed -- no leaks are possible                                                                                                        
==4604==                                                                                                                                                            
==4604== For counts of detected and suppressed errors, rerun with: -v                                                                                               
==4604== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)                                                                                             
==4606==                                                                                                                                                            
==4606== HEAP SUMMARY:                                                                                                                                              
==4606==     in use at exit: 0 bytes in 0 blocks                                                                                                                    
==4606==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated                                                                                                   
==4606==                                                                                                                                                            
==4606== All heap blocks were freed -- no leaks are possible                                                                                                        
==4606==                                                                                                                                                            
==4606== For counts of detected and suppressed errors, rerun with: -v                                                                                               
==4606== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)                                                                                             
==4608==                                                                                                                                                            
==4608== HEAP SUMMARY:                                                                                                                                              
==4608==     in use at exit: 0 bytes in 0 blocks                                                                                                                    
==4608==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated                                                                                                   
==4608==                                                                                                                                                            
==4608== All heap blocks were freed -- no leaks are possible                                                                                                        
==4608==                                                                                                                                                            
==4608== For counts of detected and suppressed errors, rerun with: -v                                                                                               
==4608== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)                                                                                             
==4607==                                                                                                                                                            
==4607== HEAP SUMMARY:                                                                                                                                              
==4607==     in use at exit: 0 bytes in 0 blocks                                                                                                                    
==4607==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated                                                                                                   
==4607==                                                                                                                                                            
==4607== All heap blocks were freed -- no leaks are possible                                                                                                        
==4607==                                                                                                                                                            
==4607== For counts of detected and suppressed errors, rerun with: -v                                                                                               
==4607== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)                                                                                             
==4610==                                                                                                                                                            
==4610== HEAP SUMMARY:                                                                                                                                              
==4610==     in use at exit: 0 bytes in 0 blocks                                                                                                                    
==4610==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated                                                                                                   
==4610==                                                                                                                                                            
==4610== All heap blocks were freed -- no leaks are possible                                                                                                        
==4610==                                                                                                                                                            
==4610== For counts of detected and suppressed errors, rerun with: -v                                                                                               
==4610== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)                                                                                             
==4613==                                                                                                                                                            
==4613== HEAP SUMMARY:                                                                                                                                              
==4613==     in use at exit: 0 bytes in 0 blocks                                                                                                                    
==4613==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated                                                                                                   
==4613==                                                                                                                                                            
==4613== All heap blocks were freed -- no leaks are possible                                                                                                        
==4613==                                                                                                                                                            
==4613== For counts of detected and suppressed errors, rerun with: -v                                                                                               
==4613== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)                                                                                             
==4614==                                                                                                                                                            
==4614== HEAP SUMMARY:                                                                                                                                              
==4614==     in use at exit: 0 bytes in 0 blocks                                                                                                                    
==4614==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated                                                                                                   
==4614==                                                                                                                                                            
==4614== All heap blocks were freed -- no leaks are possible                                                                                                        
==4614==                                                                                                                                                            
==4614== For counts of detected and suppressed errors, rerun with: -v                                                                                               
==4614== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)                                                                                             
[Program output appears here, nothing appears afterwards]  

以前は、標準のメイクファイルを使用してコンパイルした場合、そのような問題はなく、valgrind は期待どおりに表示されました。ディレクトリのmakefile.amコンパイルに使用しているものは次のようになります。

lib_LTLIBRARIES = libfile_util.la libmath_util.la libgeneral_util.la libparamlist.la
libfile_util_la_SOURCES = file_util.c file_util.h
libmath_util_la_SOURCES = math_util.c math_util.h
libgeneral_util_la_SOURCES = general_util.c general_util.h
libparamlist_la_SOURCES = paramlist.c paramlist.h

bin_PROGRAMS = launcher
generator_CFLAGS = -I/usr/include/muParser
generator_SOURCES = generator.c generator.h
estimator_SOURCES = estimator.c estimator.h
estimator_iwls_SOURCES = estimator_IWLS.c estimator.h
estimator_piecewise_SOURCES = estimator_IWLS.c estimator_piecewise.c estimator.h
estimator_baseline_SOURCES = estimator_IWLS.c estimator_piecewise.c estimator_baseline.c estimator.h
launcher_CFLAGS = -I/usr/include/muParser
launcher_SOURCES = launcher.c generator.c estimator.c estimator.h generator.h
generator_LDADD = libfile_util.la libmath_util.la libgeneral_util.la libparamlist.la
launcher_LDADD = libfile_util.la libmath_util.la libgeneral_util.la libparamlist.la
estimator_iwls_LDADD = libfile_util.la libmath_util.la libgeneral_util.la libparamlist.la
estimator_piecewise_LDADD = libfile_util.la libmath_util.la libgeneral_util.la libparamlist.la
estimator_baseline_LDADD = libfile_util.la libmath_util.la libgeneral_util.la libparamlist.la

この問題は、automake がファイルをコンパイルする方法と関係がありますか? もしそうなら、メイクファイルで何が間違っていますか?

4

1 に答える 1

9

は libtool ライブラリを使用しているためlauncher、ビルド ディレクトリにあるファイルは、実際のバイナリを実行するために必要な環境変数をセットアップする単なるシェル スクリプトです (通常は に隠されてい.libs/ます)。そのスクリプトで valgrind を実行すると、実際のバイナリではなく、スクリプトを実行しているシェルがデバッグされます。

valgrindまたはgdblibtool バイナリで任意のコマンドを実行する適切な方法は、次のlibtoolコマンドを使用することです。

libtool --mode=execute valgrind ./launcher -g ../data/params.txt

次のように短縮することもできます。

libtool e valgrind ./launcher -g ../data/params.txt

これは、launcherコンパイル方法に関係なく機能します。

関連する libtool ドキュメントはhereです。

于 2013-01-06T20:37:16.387 に答える