⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 memory leak detection in embedded systems linux journal.htm

📁 嵌入式系统下内存泄漏检查库函数mTrace以及测试代码,有详细使用文档.这个是将malloc和free 函数控制起来,检查内存.
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<li><p>check-funcs (cfu): check functions (0x4000)</p></li><li><p>force-linear (fli): force heap-space to be linear (0x10000)</p></li><li><p>catch-signals (csi): shut down program on SIGHUP, SIGINT, SIGTERM (0x20000)</p></li><li><p>realloc-copy (rco): copy all re-allocations (0x100000)</p></li><li><p>free-blank (fbl): overwrite freed memory space with BLANK_CHAR (0x200000)</p></li><li><p>error-abort (eab): abort immediately on error (0x400000)</p></li><li><p>alloc-blank (abl): overwrite newly alloced memory with BLANK_CHAR (0x800000)</p></li><li><p>heap-check-map (hcm): log heap-map on heap-check (0x1000000)</p></li><li><p>print-messages (pme): write messages to stderr (0x2000000)</p></li><li><p>catch-null (cnu): abort if no memory available (0x4000000)</p></li><li><p>never-reuse (nre): never reuse freed memory (0x8000000)</p></li><li><p>allow-free-null (afn): allow the frees of NULL pointers (0x20000000)</p></li><li><p>error-dump (edu): dump core on error and then continue (0x40000000)</p></li></ul></div><br><br><p>If the library needs to check C++ programs, a source file named dmalloc.cc is needed with the application.This module provides wrapper functions for new to malloc and delete to free. The GNU debugger GDB can be usedwith dmalloc. A file is included with the product that can be used as part of a .gdbinit file so that GDB isset up automatically to know about dmalloc.</p><p>Along with the library is a utility named dmalloc that will programmatically set up the DMALLOC_OPTIONSvariable. I've made a setup script that is sourced prior to running the program to be debugged. This way thesetup is repeatable without errors.</p><p>This article only covers the general use of the tool, but the documentation for it is extensive anddetails more available features. The test program used with the earlier tools was run using DMALLOC. Theresults can be lengthy and optionally include the bytes present at critical areas of memory such as the``fence-top'', where a pointer overruns a malloc'd area. The end of the log file includes statistics,addresses, block sizes and line numbers for occurrences of malloc without free.</p><p>The three tools provide varying support for memory leak detection and reporting. Each of these tools hasbeen used on a Linux workstation as well as cross-compiled and executed on several different targetarchitectures. In one application, developers used all three tools. <span class="bold"><b>mtrace</b></span>was used to find a memory leak in a third-party C++ library where an exception throw/catch block caused amajor leak. The dmalloc tool was used to find memory leaks in the execution of Linux pthreaded applications.The memwatch tool was used to catch a buffer pool mechanism that was not properly defragmenting itself. Thesetools are small and easy to implement and remove when debugging is completed.</p><p>The example program consists of one source file, my_test.c. There are three separate directories thatcontain a README, Makefile and a script to run the test [available at <a href="ftp://ftp.ssc.com/pub/lj/listings/issue101/6059.tgz" target="_top">ftp.ssc.com/pub/lj/listings/issue101/6059.tgz</a>]. In the dmalloc test, the environment setup scriptis also available. Each of the tests has been built on Red Hat and SuSE Linux releases, as well as theMontaVista Linux cross-development environments.</p><p><a href="/articles/lj/0101/6059/6059s1.html" target="_top">Resources</a></p><div class="mediaobject"><img src="/articles/lj/0101/6059/6059aa.png"></div><br><br><div class="blockquote"><blockquote class="blockquote"><p><span class="bold"><b>Cal Erickson</b></span> (<a href="mailto:cal_erickson@mvista.com" target="_top">cal_erickson@mvista.com</a>) currently works for MontaVista Software as a senior Linux consultant.Prior to joining MontaVista, he was a senior support engineer at Mentor Graphics Embedded Software Division.Cal has been in the computing industry for over 30 years with experience at computer manufacturers andend-user development environments.</p></blockquote></div></div></div><p>email: <a href="mailto:cal_erickson@mvista.com">cal_erickson@mvista.com</a></p></div>      <div class="links">&raquo; <a href="comment/reply/6059#comment" title="Share your thoughts and opinions related to this posting.">add new comment</a> | <a href="emailpage&amp;nid=6059" title="Email this page to a friend">email this page</a> | <a href="node/6059/print" title="Display a printer friendly version of this page.">printer friendly version</a></div>  </div><a id="comment"></a><form method="post" action="comment"><div>  <div class="box">    <h2 class="title">Comment viewing options</h2>    <div class="content"><div class="form-item"> <select name="mode"> <option value="1">Flat list - collapsed</option> <option value="2">Flat list - expanded</option> <option value="3">Threaded list - collapsed</option> <option value="4" selected="selected">Threaded list - expanded</option></select><select name="order"> <option value="1" selected="selected">Date - newest first</option> <option value="2">Date - oldest first</option></select><select name="comments_per_page"> <option value="10">10 comments per page</option> <option value="30">30 comments per page</option> <option value="50" selected="selected">50 comments per page</option> <option value="70">70 comments per page</option> <option value="90">90 comments per page</option></select><input type="hidden" name="threshold" value="0" /> <input type="submit" class="form-submit" name="op" value="Save settings"  /> <div class="description">Select your preferred way to display the comments and click "Save settings" to activate your changes.</div></div>    </div> </div><input type="hidden" name="edit[nid]" value="6059" /></div></form><form method="post" action="comment"><div><input type="hidden" name="edit[nid]" value="6059" /><a id="comment-13419"></a>  <div class="comment">         <h3 class="title"><a href="article/6059#comment-13419" class="active">why advertise the article in</a></h3>    <div class="submitted">Submitted by Anonymous (not verified) on Wed, 2004-11-03 12:03. </div>    <div class="content"><p>why advertise the article in an expensive book to only find that lj is nickeling and diming</p></div>    <div class="links">&raquo; <a href="comment/reply/6059/13419">reply</a> | <a href="emailpage&amp;nid=6059" title="Email this page to a friend">email this page</a></div>  </div></div></form><!-- end content -->      </div><!-- main -->    </td>    <td id="sidebar-right">        <div class="block block-search" id="block-search-0">    <div class="title"><h3>Search</h3></div>    <div class="content"><form action="search/" method="post"> <div class="search-form"><div class="form-item"> <div class="container-inline"><div class="form-item"> <input type="text" maxlength="150" class="form-text" name="edit[keys]" id="edit-keys" size="20" value="" /></div><input type="submit" class="form-submit" name="op" value="Search"  /></div></div></div></form></div> </div>  <div class="block block-block" id="block-block-29">    <div class="title"><h3>Skyscraper Ad</h3></div>    <div class="content"><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td align="center"><script language="JavaScript" type="text/javascript" src="http://ads.linuxjournal.com/adx.js"></script><script type="text/javascript"><!--phpads_show_ad('http://ads.linuxjournal.com', '9');//--></script><noscript><p><a href='http://ads.linuxjournal.com/adclick.php?n=acff6c1e'><img src='http://ads.linuxjournal.com/adview.php?what=zone:9&amp;n=acff6c1e' alt='' /></a></p></noscript></td></tr></table></div> </div>  <div class="block block-block" id="block-block-7">    <div class="title"><h3>Button 1 zone 6</h3></div>    <div class="content"><div class="adimage"><script language="JavaScript" type="text/javascript" src="http://ads.linuxjournal.com/adx.js"></script><script type="text/javascript"><!--phpads_show_ad('http://ads.linuxjournal.com', '6');//--></script><noscript><p><a href='http://ads.linuxjournal.com/adclick.php?n=acff6c1e'><img src='http://ads.linuxjournal.com/adview.php?what=zone:6&amp;n=acff6c1e' alt='' /></a></p></noscript></div></div> </div>  <div class="block block-block" id="block-block-17">    <div class="title"><h3>Text ad 4 - zone 12</h3></div>    <div class="content"><div class="adimage"><script language="JavaScript" type="text/javascript" src="http://ads.linuxjournal.com/adx.js"></script><script type="text/javascript"><!--phpads_show_ad('http://ads.linuxjournal.com', '12');//--></script><noscript><p><a href='http://ads.linuxjournal.com/adclick.php?n=acff6c1e'><img src='http://ads.linuxjournal.com/adview.php?what=zone:12&amp;n=acff6c1e' alt='' /></a></p></noscript></div></div> </div>  <div class="block block-block" id="block-block-22">    <div class="title"><h3>Text Ad Eight - zone 17</h3></div>    <div class="content"><div class="adimage"><script language="JavaScript" type="text/javascript" src="http://ads.linuxjournal.com/adx.js"></script><script type="text/javascript"><!--phpads_show_ad('http://ads.linuxjournal.com', '17');//--></script><noscript><p><a href='http://ads.linuxjournal.com/adclick.php?n=acff6c1e'><img src='http://ads.linuxjournal.com/adview.php?what=zone:17&amp;n=acff6c1e' alt='' /></a></p></noscript></div></div> </div>  <div class="block block-block" id="block-block-28">    <div class="title"><h3>Text ad twelve - zone 22</h3></div>    <div class="content"><div class="adimage"><script language="JavaScript" type="text/javascript" src="http://ads.linuxjournal.com/adx.js"></script><script type="text/javascript"><!--phpads_show_ad('http://ads.linuxjournal.com', '22');//--></script><noscript><p><a href='http://ads.linuxjournal.com/adclick.php?n=acff6c1e'><img src='http://ads.linuxjournal.com/adview.php?what=zone:22&amp;n=acff6c1e' alt='' /></a></p></noscript></div></div> </div>  <div class="block block-block" id="block-block-20">    <div class="title"><h3>Text ad Six - zone 15</h3></div>    <div class="content"><div class="adimage"><script language="JavaScript" type="text/javascript" src="http://ads.linuxjournal.com/adx.js"></script><script type="text/javascript"><!--phpads_show_ad('http://ads.linuxjournal.com', '15');//--></script><noscript><p><a href='http://ads.linuxjournal.com/adclick.php?n=acff6c1e'><img src='http://ads.linuxjournal.com/adview.php?what=zone:15&amp;n=acff6c1e' alt='' /></a></p></noscript></div></div> </div>    </td>  </tr></table><!--<table id="footer-menu" summary="Navigation elements." border="0" cellpadding="0" cellspacing="0" width="100%">  <tr>    <td align="center" valign="middle">      <div class="primary-links"><table id="primary-links-table" summary="Primary navigation elements." border="0" cellpadding="0" cellspacing="0" width="100%">
 <tr>
  <td id="home" rowspan="2"><a href="./" title="Home">
   <img src="/sites/default/themes/linuxjournal/ljlogo.png" alt="Home"
        border="0" /></a></td>
  <td></td>
  <td id="primary-links-hdr">Subscribe <strong>Now</strong></td>
 </tr>
 <tr>

  <td id="tagline" valign="bottom" align="left">Since 1994:
    The Original Monthly Magazine of the Linux Community</td>
  <td id="primary-links" valign="middle">
   <ul class="subscribeBar">
    <li><a href="/xstatic/subs/">Subscribe</a></li>
	<li><a href="https://www.ssc.com/dlissc/index">Renew</a></li>
    <li><a href="/xstatic/subs/customer_service.html">Customer Service</a></li>
   </ul>
  </td>
 </tr>
</table></div>      <div class="secondary-links"><table id="secondary-links-table" summary="Navigation elements." border="0" cellpadding="0" cellspacing="0" width="100%">
 <tr>
   <td id="secondary-links">

<table align="center"><tr>
<td width="18%">&#160;</td>
<td align="center" width="16%"><a class="first" href="/xstatic/magazine">Magazine</a></td>
<td align="center" width="16%"><a class="second" href="/xstatic/advertising">Advertise</a></td>
<td align="center" width="16%"><a class="second" href="/xstatic/community">Community</a></td>
<td align="center" width="16%"><a class="second" href="/xstatic/aboutus">About&#160;Us</a></td>

<td width="18%">&#160;</td>
</tr></table>

   </td>
 </tr>
</table></div>    </td>  </tr></table>--><hr id="footer-sep" /><div id="footer-message">  <table width="100%"><tr>
<td width="10%" align="left"><img src="/xsfiles/i/drupal07.png" alt="Drupal"/></td>
<td width="80%" id="first-foot-links">
<a class="first" href="/xstatic/magazine" title="Magazine">Magazine</a>

<a href="/xstatic/advertising/" title="Advertise">Advertise</a>
<a href="/xstatic/community" title="Community" >Community</a>
<a href="/xstatic/aboutus" title="Contact Us">Contact&#160;Us</a>
<a href="https://www.ssc.com/lj/subs/privacy.html" title="Privacy Statement">Privacy&#160;Statement</a></td>
<td width="10%">&#160;</td>
</tr></table>



<table align="center"><tr>
<td id="sec-foot-links">
Copyright &copy; 1994 - 2006 <a href="http://www.ssc.com/">SSC&#160;Media&#160;Corporation</a>. All rights reserved.
</td></tr></table>

<table align="center"><tr>
<td>Visit SSC's other sites:</td>
<td>&#160;</td>
<td id="third-foot-links">
<a class="first" href="http://www.tuxmagazine.com" title="TUX Magazine">TUX&#160;Magazine</a>
<a href="http://www.docsearls.com/" title="Doc's IT Garage">Doc's&#160;IT&#160;Garage
</a><a href="/xstatic/aboutus/rss_page" title="Click here for more RSS feeds">RSS&#160;Links</a>
</td></tr></table>

<table align="center">
<tr>
<td>Read "News Feeds" from SSC's other sites:</td>
<td>&#160;</td><td id="fourth-foot-links"><a class="first" href="/aggregator" title="Click here for News Feeds">News&#160;Feeds</a>
 <a href="MAILTO:webmaster@ssc.com">Report&nbsp;&nbsp;Problems</a></td></tr></table></div></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -