<!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>&gt; For debugging purposes, I wished to provide a standard means of</FONT>
<BR><FONT SIZE=2>&gt; logging the entry into, and exit from, each of my routines.&nbsp; This</FONT>
<BR><FONT SIZE=2>&gt; log should give the name of the routine, and calling signature.</FONT>
<BR><FONT SIZE=2>&gt; On entry it should print the input parameters, and on exit, the</FONT>
<BR><FONT SIZE=2>&gt; output parameters.</FONT>
</P>

<P><FONT SIZE=2>class EntryExitLogger {</FONT>
<BR><FONT SIZE=2>private:</FONT>
<BR><FONT SIZE=2>&nbsp; string name;</FONT>
<BR><FONT SIZE=2>public:</FONT>
<BR><FONT SIZE=2>&nbsp; EntryExitLogger(const char *name): name(name)</FONT>
<BR><FONT SIZE=2>&nbsp; {</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; fprintf(stderr,&quot;Entering %s\n&quot;,name);</FONT>
<BR><FONT SIZE=2>&nbsp; }</FONT>
<BR><FONT SIZE=2>&nbsp; ~EntryExitLogger()</FONT>
<BR><FONT SIZE=2>&nbsp; {</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; fprintf(stderr,&quot;Exiting %s\n&quot;,name);</FONT>
<BR><FONT SIZE=2>&nbsp; }</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>&nbsp; EELOG</FONT>
<BR><FONT SIZE=2>&nbsp; // 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>