Manual Pages for UNIX Darwin command on man TCL_MEM_DEBUG
MyWebUniversity

Manual Pages for UNIX Darwin command on man TCL_MEM_DEBUG

TCLMEMDEBUG(3) Tcl Library Procedures TCLMEMDEBUG(3)

NAME

TCLMEMDEBUG - Compile-time flag to enable Tcl memory debugging.

DESCRIPTION

When Tcl is compiled with TTCCLLMMEEMMDDEEBBUUGG defined, a powerful set of mem-

ory 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. EENNAABBLLIINNGG MMEEMMOORRYY DDEEBBUUGGGGIINNGG To enable memory debugging, Tcl should be recompiled from scratch with

TTCCLLMMEEMMDDEEBBUUGG defined. This will also compile in a non-stub version of

TTccllIInniittMMeemmoorryy to add the mmeemmoorryy command to Tcl. TTCCLLMMEEMMDDEEBBUUGG 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 TTccllDDbbCCkkffrreeee and TTccllDDbbCCkkaalllloocc or TTccllCCkkaalllloocc and TTccllCCkkffrreeee being undefined.

Once memory debugging support has been compiled into Tcl, the C func-

tions TTccllVVaalliiddaatteeAAllllMMeemmoorryy, and TTccllDDuummppAAccttiivveeMMeemmoorryy, and the Tcl mmeemm-

oorryy command can be used to validate and examine memory usage. GGUUAARRDD ZZOONNEESS When memory debugging is enabled, whenever a call to cckkaalllloocc is made,

slightly more memory than requested is allocated so the memory debug-

ging 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 LLOOWWGGUUAARRDDSSIIZZEE and #define HHIIGGHHGGUUAARRDDSSIIZZEE in the file

generic/tclCkalloc.c - it can be extended if you suspect large over-

write problems, at some cost in performance.) A known pattern is writ-

ten into the guard zones and, on a call to cckkffrreeee, the guard zones of

the space being freed are checked to see if either zone has been modi-

fied in any way. If one has been, the guard bytes and their new con-

tents 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 cckkffrreeee. 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. DDEEBBUUGGGGIINNGG DDIIFFFFIICCUULLTT MMEEMMOORRYY CCOORRRRUUPPTTIIOONN PPRROOBBLLEEMMSS 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 MMEEMMVVAALLIIDDAATTEE define,

recompile tclCkalloc.c and rebuild Tcl. This will enable memory vali-

dation from the first call to cckkaalllloocc, again, at a large performance impact. If you are desperate and validating memory on every call to cckkaalllloocc and cckkffrreeee isn't enough, you can explicitly call TTccllVVaalliiddaatteeAAllllMMeemmoorryy directly at any point. It takes a char * and an int 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.

SEE ALSO

ckalloc, memory, TclValidateAllMemory, TclDumpActiveMemory KKEEYYWWOORRDDSS memory, debug Tcl 8.1 TCLMEMDEBUG(3)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™