tags:

views:

59

answers:

1

I have some debugging code that if executed while running with GBD attached should break the execution of the application, but if GDB is not running it should continue.

The code I'm working with looks something like this in structure:

try
{
  if( some_complex_expression )
  {
     gdb_should_break_here();
     do_some_stuff();
     throw MyException();
  }
}
catch( const MyException & e )
{
  handle_exception_and_continue();
}

What should gdb_should_break_here be?

+2  A: 

Actually it looks like just making sure there is an empty gdb_should_break_here() function everywhere I need to break will work. (So long as I'm not optimising the code).

Then all I need to do is a

break gdb_should_break_here

and gdb will stop in all the right places.

Guess I overlooked it as my code wasn't really that nicely organised, and contained in a few debugging macros.

Michael Anderson
Yes, that's probably the easiest way. You might at some point also find it useful to put logging code in there. Also, even if you're optimizing the code, so long as the implementation of gdb_should_break_here is in a separate file and you link it into the final application separately, it will still be called (despite being empty) and so GDB can break on it.
Brooks Moses
Yeah unfortunately those functions are part of a header only library.The code I'm looking at is essentially part of the error logging and handling code so more logging is probably not appropriate.. its really only for debugging rare edge cases - in particular for cases where I need a stack trace.
Michael Anderson