📄 tcl_mem_debug.3
字号:
'\" '\" 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 NAMETCL_MEM_DEBUG \- Compile-time flag to enable Tcl memory debugging..BE.SH DESCRIPTIONWhen Tcl is compiled with \fBTCL_MEM_DEBUG\fR defined, a powerful setof memory debugging aids are included in the compiled binary. Thisincludes C and Tcl functions which can aid with debuggingmemory leaks, memory allocation overruns, and other memory relatederrors..SH "ENABLING MEMORY DEBUGGING".PPTo enable memory debugging, Tcl should be recompiled from scratch with\fBTCL_MEM_DEBUG\fR defined. This will also compile in a non-stubversion of \fBTcl_InitMemory\fR to add the \fBmemory\fR command to Tcl..PP\fBTCL_MEM_DEBUG\fR must be either left defined for all modules or undefinedfor all modules that are going to be linked together. If they are not, linkerrors will occur, with either \fBTclDbCkfree\fR and \fBTcl_DbCkalloc\fR or\fBTcl_Ckalloc\fR and \fBTcl_Ckfree\fR being undefined..PPOnce memory debugging support has been compiled into Tcl, the Cfunctions \fBTcl_ValidateAllMemory\fR, and \fBTcl_DumpActiveMemory\fR,and the Tcl \fBmemory\fR command can be used to validate and examinememory usage..SH "GUARD ZONES".PPWhen memory debugging is enabled, whenever a call to \fBckalloc\fR ismade, slightly more memory than requested is allocated so the memory debuggingcode can keep track of the allocated memory, and eight-byte ``guardzones'' are placed in front of and behind the space that will bereturned to the caller. (The sizes of the guard zones are defined by theC #define \fBLOW_GUARD_SIZE\fR and #define \fBHIGH_GUARD_SIZE\fRin the file \fIgeneric/tclCkalloc.c\fR -- it canbe extended if you suspect large overwrite problems, at some cost inperformance.) A known pattern is written into the guard zones and, ona call to \fBckfree\fR, the guard zones of the space being freed arechecked to see if either zone has been modified in any way. If onehas 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 andthe file name and line number of the code that called \fBckfree\fR.This allows you to detect the common sorts of one-off problems, wherenot enough space was allocated to contain the data written, forexample..SH "DEBUGGING DIFFICULT MEMORY CORRUPTION PROBLEMS".PPNormally, Tcl compiled with memory debugging enabled will make it easyto isolate a corruption problem. Turning on memory validation withthe memory command can help isolate difficult problems. If yoususpect (or know) that corruption is occurring before the Tclinterpreter comes up far enough for you to issue commands, you can set\fBMEM_VALIDATE\fR define, recompile tclCkalloc.c and rebuild Tcl.This will enable memory validation from the first call to\fBckalloc\fR, again, at a large performance impact..PPIf you are desperate and validating memory on every call to\fBckalloc\fR and \fBckfree\fR isn't enough, you can explicitly call\fBTcl_ValidateAllMemory\fR directly at any point. It takes a \fIchar*\fR and an \fIint\fR which are normally the filename and line numberof the caller, but they can actually be anything you want. Rememberto remove the calls after you find the problem..SH "SEE ALSO"ckalloc, memory, Tcl_ValidateAllMemory, Tcl_DumpActiveMemory.SH KEYWORDSmemory, debug
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -