[LCP]Printing a Variables Value..!!!
robert at ncdesigns.net
robert at ncdesigns.net
Tue Jun 24 04:41:02 UTC 2003
On Mon, 23 Jun 2003, Mike and/or Penny Novack wrote:
> ARE there "stock" C debuggers with "batch mode" capabilities?
>
"stock" is dependent on the OS/platform that your using. Since this board
has a Linux slant, then yes, you can use the GNU debugger if your using
the stock GNU C/C++ compiler. Do a search for "gdb", and of course anyone
knows that you need debugging symbols for this to work, i.e. "-g" compiler
flag. Now for anyone interested in profiling, there is another program
called "gprof" which profiles your code if you enable some extra profile
information. Compile with the "-pg" flags. Do not do this on production,
since every execution of your binary will drop a "gmon.out" file in your
current working directory. This datafile is then fed into the profiler.
There is even a way that if you code execute in 1.23 seconds, that you can
run it 1-n times and collate the results over a larger set.
Now that we're talking about using "stock" Linux compilers, gcc has some
other nice features built-in.
#ifdef DEBUG
FILE *debug_fp; // Or could be a lowlevel FD or whatever...I don't care
#define DEBUG_MSG(message) print_debug_info(__FILE__, __LINE__, MESSAGE)
void *print_debug_info( int line, char *filename, char *message )
{
fprintf(debug_fp, "(%s:%d) %s", filename, line, message);
}
#endif
so you can sprinkle DEBUG_MSG all around your code and compile with the
-DDEBUG flag.
DEBUG_MSG("achar = %c, astring = %s, etc...",achar,astring...);
Then in production, compile without that flag, and all your message
disappear.
Do things like this, and who needs a debugger. And who needs a profiler?
just add timing code around critical sections...basically build yourself a
simple timer for your functions. Hmmm....maybe even output your data in
gplot format to provide upper managers with pretty pictures of your
execution time...and time savings with a little proper optimization
learned from this board maybe? :)
BTW: Upper managers love these pretty graphs, it gives them warm fuzzies.
Robert
More information about the linuxCprogramming
mailing list