tracing_example.cppThis code exemplifies how to insert trace statements to follow the flow of program execution. When compiler under gcc 3.3 and run, the following program will output the following trace: 00001 trace[1]: Entering int main()
00002 trace[2]: Entering int foo(int)
00003 trace[3]: Entering int Foo::bar(int)
00004 trace[3]: i = 21
00005 trace[3]: At line 16 in tracing_example.cpp
00006 trace[3]: Wrong answer
00007 trace[3]: i = 42
00008 trace[3]: Exiting int Foo::bar(int)
00009 trace[3]: Entering int Foo::bar(int)
00010 trace[3]: i = 42
00011 trace[3]: At line 13 in tracing_example.cpp
00012 trace[3]: Right answer, but no question
00013 trace[3]: i = 42
00014 trace[3]: Exiting int Foo::bar(int)
00015 trace[2]: Exiting int foo(int)
00016 trace[1]: Exiting int main()
Of course, a word of warning must be added: adding so much tracing to your code might degrade its readability, at least until we devise an Emacs macro to hide trace statements with a couple of keystrokes.
|