Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!lll-winken!gandalf!jac From: jac@gandalf..llnl.gov (James Crotinger) Newsgroups: comp.lang.c++ Subject: Re: automatic tracing of function entry/exit Message-ID: <69413@lll-winken.LLNL.GOV> Date: 7 Oct 90 23:04:20 GMT References: <52352@brunix.UUCP> Sender: usenet@lll-winken.LLNL.GOV Distribution: na Organization: Lawrence Livermore National Laboratory Lines: 85 In the October '89 issue of Computer Language there was an article "A Debugging Class for C++" by Marco Hyman which presented a Trace class that I find quite useful. At the entry of every function you declare an instance of the Trace class, passing the name of the function as an argument: main() { Trace trace = "::main()"; ... } The trace class has a static member which keeps track of the number of instances currently alive and indents its output accordingly. It also overloads operator() to print out diagnostic messages. Through an environment variable you can select whether you want "trace", "info", "assert", or "error" information printed out (or any combo, of course). Here is some output from ::main() AbsoluteFile::AbsoluteFile(...) info: name = stats info: mode = 2 info: length = 131072 info: bufflen = 2048 info: size_inc = 0 info: FREEUS returned unit = 1 Opening file for read only. info: unit = 1 info: filename = stats info: type = 4 info: filelength = 131072 info: OPEN returned filelength = 9081 OldStatFile::OldStatFile(...) info: name = stats info: mode = 2 info: length = 131072 info: bufflen = 2048 info: size_inc = 0 AbsoluteFile::Read( void * const, const long ) info: Reading 2 words from address 0... info: ...read. info: ID = TYPE: STATS AbsoluteFile::Read( void * const, const long ) info: Reading 1 words from address 2... info: ...read. AbsoluteFile::Read( void * const, const long ) info: Reading 1 words from address 3... info: ...read. AbsoluteFile::Read( void * const, const long ) info: Reading 1 words from address 4... info: ...read. AbsoluteFile::Read( void * const, const long ) info: Reading 1 words from address 5... info: ...read. info: STATS_Version = 0 info: dataStartLocation = 16 info: recordSize = 45 info: recordCount = 201 info: Checking for correct record size. info: recordSize = 45 info: 8 * sizeof(StatRecord) = 48 AbsoluteFile::Read( void * const, const long ) info: Reading 45 words from address 16... info: ...read. OldStatFile::NextRecord(...) info: Getting record 1; size = 48 AbsoluteFile::Read( void * const, const long ) info: Reading 48 words from address 61... info: ...read. ... etc. We recently got CFRONT running on the CRAYS here which have no source-level debuggers (not even for Fortran, let alone C++). This Trace class is proving immensely useful! Jim P.S. If Marco Hyman reads this, thanks! -- ----------------------------------------------------------------------------- James A. Crotinger Lawrence Livermore Nat'l Lab // The above views jac@gandalf.llnl.gov P.O. Box 808; L-630 \\ // are mine and are not (415) 422-0259 Livermore CA 94550 \\/ necessarily those of LLNL.