<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2448.0">
<TITLE>RE: [LC++]Producing a log of routine entry and exit</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=2>> For debugging purposes, I wished to provide a standard means of</FONT>
<BR><FONT SIZE=2>> logging the entry into, and exit from, each of my routines. This</FONT>
<BR><FONT SIZE=2>> log should give the name of the routine, and calling signature.</FONT>
<BR><FONT SIZE=2>> On entry it should print the input parameters, and on exit, the</FONT>
<BR><FONT SIZE=2>> output parameters.</FONT>
</P>
<P><FONT SIZE=2>class EntryExitLogger {</FONT>
<BR><FONT SIZE=2>private:</FONT>
<BR><FONT SIZE=2> string name;</FONT>
<BR><FONT SIZE=2>public:</FONT>
<BR><FONT SIZE=2> EntryExitLogger(const char *name): name(name)</FONT>
<BR><FONT SIZE=2> {</FONT>
<BR><FONT SIZE=2> fprintf(stderr,"Entering %s\n",name);</FONT>
<BR><FONT SIZE=2> }</FONT>
<BR><FONT SIZE=2> ~EntryExitLogger()</FONT>
<BR><FONT SIZE=2> {</FONT>
<BR><FONT SIZE=2> fprintf(stderr,"Exiting %s\n",name);</FONT>
<BR><FONT SIZE=2> }</FONT>
<BR><FONT SIZE=2>};</FONT>
</P>
<P><FONT SIZE=2>#define EELOG EntryExitLogger entry_exit_logger(__PRETTY_FUNCTION__);</FONT>
</P>
<P><FONT SIZE=2>void foo()</FONT>
<BR><FONT SIZE=2>{</FONT>
<BR><FONT SIZE=2> EELOG</FONT>
<BR><FONT SIZE=2> // Do stuff</FONT>
<BR><FONT SIZE=2>}</FONT>
</P>
<P><FONT SIZE=2>__PRETTY_FUNCTION__ may not be the right spelling, check the docs.</FONT>
</P>
<BR>
<P><FONT SIZE=2>If you want the parameters, then it becomes way more complicated.</FONT>
<BR><FONT SIZE=2>If you want an automated thing, your best bet is to either modify</FONT>
<BR><FONT SIZE=2>the code to GCC to insert such code (yuck) or have some code to</FONT>
<BR><FONT SIZE=2>interpret the function signature and peek on the stack what it says</FONT>
<BR><FONT SIZE=2>is there (probably rather flaky).</FONT>
</P>
<P><FONT SIZE=2>-- </FONT>
<BR><FONT SIZE=2>Vincent Penquerc'h </FONT>
</P>
</BODY>
</HTML>