ºìÁªLinuxÃÅ»§
Linux°ïÖú

linuxÏÂÄÚ´æ¼ì²é¹¤¾ßvalgrindʹÓ÷½·¨£¬ÏÂÔØ

·¢²¼Ê±¼ä:2007-12-22 12:55:50À´Ô´:ºìÁª×÷Õß:kbopoeco
valgrindÊÇlinuxÏ·dz£ÓÅÐãµÄÒ»¿îÄÚ´æ¼ì²éµÄ¹¤¾ß¡£ËüµÄ¹Ù·½ÍøÕ¾ÊÇhttp://www.valgrind.org£¬´Ó¹ÙÍø¿ÉÒÔϵ½×îеÄÔ´Âë°ü¡£

1.°²×°

±ê×¼gnuÈí¼þ°²×°·½Ê½£¬./configure -- make --- makeinstall

Èç¹û°²×°Ë³Àû£¬valgrind¿ÉÖ´ÐгÌÐòÒѾ­±»°²×°µ½/usr/binÏ¿ÉÒÔÖ±½ÓʹÓÃÁË

2.ʹÓÃ

valgrindÌṩÁ˺ü¸¸ötool¿É¹©Ê¹Óã¬ÕâÀï½ö½éÉÜ×î³£ÓÃtool-memcheckµÄʹÓÃ

±ê×¼µ÷Ó÷½·¨ÊÇ:

valgrind -tool=memcheck -leak-check=yes [command] [para]

ÆäÖÐcommand¾ÍÊÇÄãµÄ¼ì²âÄ¿±ê³ÌÐò£¬paraÊǸóÌÐòµÄ²ÎÊý

·½±ãÆð¼û£¬¿ÉÒÔ×Ô¼º×ö¸öalias£¬ÀýÈç

alias memcheck=¡¯valgrind -tool=memcheck -leak-check=yes¡¯

·ÅÈë~/.bashrcÖУ¬±ÜÃâÁËÿ´Î¶¼ÇÃÄÇô³¤µÄ×Ö·û´®

3.°´2ÖеIJ½Öèµ÷ÓÃÁËÖ®ºó£¬ÄãµÄ³ÌÐò¾Í»á±»vargrind½Ó¹Ü¡£

ËùÓÐÉæ¼°ÄÚ´æ·ÖÅäÊͷŵŤ×÷£¬vargrind¶¼»á¿´µ½¡£Òò´ËËü¿ÉÒÔ°ïÄã¼ì²âÊÇ·ñÓÐй©·¢Éú¡£

4.ÐèҪעÒâµÄÊÇ£¬ÎªÁ˸üºÃµÄµ÷ÊÔ£¬ÔÚ´úÂëµ÷ÊԽ׶Σ¬±àÒëʱӦ¸Ã¼ÓÉÏ-g²ÎÊýÉú³Éµ÷ÊÔÐÅÏ¢¡£

ÕâÑùvalgrindÔÚ¼ì²âʱÄܹ»Ã÷È·Ö¸³öÊdzÌÐòµÄÄÄÒ»ÐзÖÅäµÄÄÚ´æ¡£

·ñÔòËüÖ»ÄܸæËßÄãÄÚ´æµØÖ·£¬¿´µÃÄãһͷÎíË®¡£

Ïȼòµ¥ËµÕâô¶à£¬¸ù¾Ý20/80Ô­Ôò£¬valgrindÕâ20%µÄ¹¦ÄÜ×ã¹»½â¾öÄã³ÌÐòÖÐ80%µÄÎÊÌâ¡£
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 0 ÌõÆÀÂÛ