TCL_MEM_DEBUG.3
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:4k
- '"
- '" Copyright (c) 1992-1999 Karl Lehenbauer and Mark Diekhans.
- '" Copyright (c) 2000 by Scriptics Corporation.
- '" All rights reserved.
- '"
- '" RCS: @(#) $Id: TCL_MEM_DEBUG.3,v 1.6 2002/11/15 15:34:17 dkf Exp $
- '"
- .so man.macros
- .TH TCL_MEM_DEBUG 3 8.1 Tcl "Tcl Library Procedures"
- .BS
- .SH NAME
- TCL_MEM_DEBUG - Compile-time flag to enable Tcl memory debugging.
- .BE
- .SH DESCRIPTION
- When Tcl is compiled with fBTCL_MEM_DEBUGfR defined, a powerful set
- of memory debugging aids are included in the compiled binary. This
- includes C and Tcl functions which can aid with debugging
- memory leaks, memory allocation overruns, and other memory related
- errors.
- .SH "ENABLING MEMORY DEBUGGING"
- .PP
- To enable memory debugging, Tcl should be recompiled from scratch with
- fBTCL_MEM_DEBUGfR defined. This will also compile in a non-stub
- version of fBTcl_InitMemoryfR to add the fBmemoryfR command to Tcl.
- .PP
- fBTCL_MEM_DEBUGfR must be either left defined for all modules or undefined
- for all modules that are going to be linked together. If they are not, link
- errors will occur, with either fBTclDbCkfreefR and fBTcl_DbCkallocfR or
- fBTcl_CkallocfR and fBTcl_CkfreefR being undefined.
- .PP
- Once memory debugging support has been compiled into Tcl, the C
- functions fBTcl_ValidateAllMemoryfR, and fBTcl_DumpActiveMemoryfR,
- and the Tcl fBmemoryfR command can be used to validate and examine
- memory usage.
- .SH "GUARD ZONES"
- .PP
- When memory debugging is enabled, whenever a call to fBckallocfR is
- made, slightly more memory than requested is allocated so the memory debugging
- code can keep track of the allocated memory, and eight-byte ``guard
- zones'' are placed in front of and behind the space that will be
- returned to the caller. (The sizes of the guard zones are defined by the
- C #define fBLOW_GUARD_SIZEfR and #define fBHIGH_GUARD_SIZEfR
- in the file fIgeneric/tclCkalloc.cfR -- it can
- be extended if you suspect large overwrite problems, at some cost in
- performance.) A known pattern is written into the guard zones and, on
- a call to fBckfreefR, the guard zones of the space being freed are
- checked to see if either zone has been modified in any way. If one
- has been, the guard bytes and their new contents are identified, and a
- ``low guard failed'' or ``high guard failed'' message is issued. The
- ``guard failed'' message includes the address of the memory packet and
- the file name and line number of the code that called fBckfreefR.
- This allows you to detect the common sorts of one-off problems, where
- not enough space was allocated to contain the data written, for
- example.
- .SH "DEBUGGING DIFFICULT MEMORY CORRUPTION PROBLEMS"
- .PP
- Normally, Tcl compiled with memory debugging enabled will make it easy
- to isolate a corruption problem. Turning on memory validation with
- the memory command can help isolate difficult problems. If you
- suspect (or know) that corruption is occurring before the Tcl
- interpreter comes up far enough for you to issue commands, you can set
- fBMEM_VALIDATEfR define, recompile tclCkalloc.c and rebuild Tcl.
- This will enable memory validation from the first call to
- fBckallocfR, again, at a large performance impact.
- .PP
- If you are desperate and validating memory on every call to
- fBckallocfR and fBckfreefR isn't enough, you can explicitly call
- fBTcl_ValidateAllMemoryfR directly at any point. It takes a fIchar
- *fR and an fIintfR which are normally the filename and line number
- of the caller, but they can actually be anything you want. Remember
- to remove the calls after you find the problem.
- .SH "SEE ALSO"
- ckalloc, memory, Tcl_ValidateAllMemory, Tcl_DumpActiveMemory
- .SH KEYWORDS
- memory, debug