📄 autobook_190.html
字号:
<HTML><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><!-- Created on September, 12 2004 by texi2html 1.64 --><!-- Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author) Karl Berry <karl@freefriends.org> Olaf Bachmann <obachman@mathematik.uni-kl.de> and many others.Maintained by: Olaf Bachmann <obachman@mathematik.uni-kl.de>Send bugs and suggestions to <texi2html@mathematik.uni-kl.de> --><HEAD><TITLE>Autoconf, Automake, and Libtool: Integrating Dmalloc</TITLE><META NAME="description" CONTENT="Autoconf, Automake, and Libtool: Integrating Dmalloc"><META NAME="keywords" CONTENT="Autoconf, Automake, and Libtool: Integrating Dmalloc"><META NAME="resource-type" CONTENT="document"><META NAME="distribution" CONTENT="global"><META NAME="Generator" CONTENT="texi2html 1.64"><script language="Javascript"><!-- // Check the browser version. function checkVersion() { if (navigator.appVersion.charAt(0)>=3) return true; if (navigator.appVersion.charAt(0)>=4) return true; else return false; } if (checkVersion()) { homeon = new Image(); homeon.src = "homeon.png"; homeoff = new Image(); homeoff.src = "home.png"; tocon = new Image(); tocon.src = "tocon.png"; tocoff = new Image(); tocoff.src = "toc.png"; indexon = new Image(); indexon.src = "indexon.png"; indexoff = new Image(); indexoff.src = "index.png"; helpon = new Image(); helpon.src = "helpon.png"; helpoff = new Image(); helpoff.src = "help.png"; backon = new Image(); backon.src = "backon.png"; backoff = new Image(); backoff.src = "back.png"; forwardon = new Image(); forwardon.src = "forwardon.png"; forwardoff = new Image(); forwardoff.src = "forward.png"; prevon = new Image(); prevon.src = "prevon.png"; prevoff = new Image(); prevoff.src = "prev.png"; nexton = new Image(); nexton.src = "nexton.png"; nextoff = new Image(); nextoff.src = "next.png"; upon = new Image(); upon.src = "upon.png"; upoff = new Image(); upoff.src = "up.png"; } function img_act(imgName) { if (checkVersion()) { imgOn = eval(imgName + "on.src"); document [imgName].src = imgOn; } } function img_inact(imgName) { if (checkVersion()) { imgOff = eval(imgName + "off.src"); document [imgName].src = imgOff; } }// --></SCRIPT></HEAD><BODY LANG="EN" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#6688AA" VLINK="#336688" ALINK="#808080"><A NAME="SEC190"></A><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=10><TR VALIGN="TOP"><TD ALIGN="MIDDLE" WIDTH=50 BGCOLOR="#e6e6e6"><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_189.html#SEC189" onMouseover="img_act('prev')" onMouseout="img_inact('prev')"><IMG SRC="prev.png" BORDER="0" ALT="Back: Interpreting Commands from a File" ALIGN="MIDDLE" NAME="prev"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_191.html#SEC191" onMouseover="img_act('next')" onMouseout="img_inact('next')"><IMG SRC="next.png" BORDER="0" ALT="Forward: M4" ALIGN="MIDDLE" NAME="next"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"> <TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_182.html#SEC182" onMouseover="img_act('back')" onMouseout="img_inact('back')"><IMG SRC="back.png" BORDER="0" ALT="FastBack: A Complex GNU Autotools Project" ALIGN="MIDDLE" NAME="back"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_182.html#SEC182" onMouseover="img_act('up')" onMouseout="img_inact('up')"><IMG SRC="up.png" BORDER="0" ALT="Up: A Complex GNU Autotools Project" ALIGN="MIDDLE" NAME="up"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_191.html#SEC191" onMouseover="img_act('forward')" onMouseout="img_inact('forward')"><IMG SRC="forward.png" BORDER="0" ALT="FastForward: M4" ALIGN="MIDDLE" NAME="forward"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook.html#SEC_Top" onMouseover="img_act('home')" onMouseout="img_inact('home')"><IMG SRC="home.png" BORDER="0" ALT="Top: Autoconf, Automake, and Libtool" ALIGN="MIDDLE" NAME="home"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_toc.html#SEC_Contents" onMouseover="img_act('toc')" onMouseout="img_inact('toc')"><IMG SRC="toc.png" BORDER="0" ALT="Contents: Table of Contents" ALIGN="MIDDLE" NAME="toc"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_285.html#SEC285" onMouseover="img_act('index')" onMouseout="img_inact('index')"><IMG SRC="index.png" BORDER="0" ALT="Index: Index" ALIGN="MIDDLE" NAME="index"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_abt.html#SEC_About" onMouseover="img_act('help')" onMouseout="img_inact('help')"><IMG SRC="help.png" BORDER="0" ALT="About: About this document" ALIGN="MIDDLE" NAME="help"></A></TD></TR></TABLE></TD><TD ALIGN="LEFT"><H2> 20.4 Integrating Dmalloc </H2><!--docid::SEC190::--><P>A huge number of bugs in C and C++ code are caused by mismanagement ofmemory. Using the wrapper functions described earlier (see section <A HREF="autobook_55.html#SEC55">9.2.1.2 Memory Management</A>), or their equivalent, can help immensely in reducing theoccurrence of such bugs. Ultimately, you will introduce adifficult-to-diagnose memory bug in spite of these measures.</P><P>That is where Dmalloc<A NAME="DOCF48" HREF="autobook_fot.html#FOOT48">(48)</A> comes in. I recommend using itroutinely in all of your projects -- you will find all sorts of leaksand bugs that might otherwise have lain dormant for some time. Automakehas explicit support for Dmalloc to make using it in your own projectsas painless as possible. The first step is to add the macro<SAMP>`AM_WITH_DMALLOC'</SAMP> to <TT>`configure.in'</TT>. Citing this macro addsa <SAMP>`--with-dmalloc'</SAMP> option to <CODE>configure</CODE>, which, whenspecified by the user, adds <SAMP>`-ldmalloc'</SAMP> to <SAMP>`LIBS'</SAMP> anddefines <SAMP>`WITH_DMALLOC'</SAMP>.</P><P>The usefulness of Dmalloc is much increased by compiling an entireproject with the header, <TT>`dmalloc.h'</TT> -- easily achieved in Sic byconditionally adding it to <TT>`common-h.in'</TT>:</P><P><TABLE width=100%><tr><td> </td><td class=example bgcolor=#6688aa><br><pre></pre></td></tr></table></P><P>I have been careful to include the <TT>`dmalloc.h'</TT> header from the endof this file so that it overrides my own <EM>definitions</EM> withoutrenaming the function <EM>prototypes</EM>. Similarly I must be careful toaccommodate Dmalloc's redefinition of the mallocation routines in<TT>`sic/xmalloc.c'</TT> and <TT>`sic/xstrdup.c'</TT>, by putting each fileinside an <SAMP>`#ifndef WITH_DMALLOC'</SAMP>. That way, when compiling theproject, if <SAMP>`--with-dmalloc'</SAMP> is specified and the<SAMP>`WITH_DMALLOC'</SAMP> preprocessor symbol is defined, then Dmalloc'sdebugging definitions of <CODE>xstrdup</CODE> et. al. will be used in place ofthe versions I wrote.</P><P>Enabling Dmalloc is now simply a matter of reconfiguring the wholepackage using the <SAMP>`--with-dmalloc'</SAMP> option, and disabling it againis a matter of reconfiguring without that option.</P><P>The use of Dmalloc is beyond the scope of this book, and is in any casedescribed very well in the documentation that comes with the package. Istrongly recommend you become familiar with it -- the time you investhere will pay dividends many times over in the time you save debugging.</P><P>This chapter completes the description of the Sic library project, andindeed this part of the book. All of the infrastructure for building anadvanced command line shell is in place now -- you need only add thebuiltin and syntax function definitions to create a complete shell ofyour own.</P><P>Each of the chapters in the next part of the book explores a morespecialised application of the GNU Autotools, starting with a discussion ofM4, a major part of the implementation of Autoconf.</P><P><A NAME="M4"></A></TR></TABLE><BR> <FONT SIZE="-1">This document was generatedby <I>Gary V. Vaughan</I> on <I>September, 12 2004</I>using <A HREF="http://www.mathematik.uni-kl.de/~obachman/Texi2html"><I>texi2html</I></A></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -