General > General Programming

Any hints for starting GDB / SE debugger on C++ program run from a script?


I am working on a piece of data processing software that has a perl test harness that starts, stops and restarts the application while supplying various data-sets and monitoring various output files.  All on Linux BTW.

I want to be able to catch exceptions and set breakpoints in the C++ application but these often won't be hit until the application has been run several times by the script.

Any ideas about the best way to configure SE to be configuring breakpoints and waiting for exceptions in this kind of environment?

I suggest that you put an endless loop where you want your breakpoint to be (with a print just before it). Run it outside of SE and when it hits then you can "attach" to it from SE's debugger. If you use a global variable to test to exit your endless loop you can change the global's value to continue stepping.

Hi, I have a question about this solution: How to stop the endless loop, though? It sounds okay theoretically but I can't do it. Maybe I should abort the loop after you get the result outside of the loop? I'm trying every possibility since the morning at my property in Bavaria but nothing works for me so far.

Use a global variable for the loop such as:

--- Code: ---int global_var = 1;

void some_function()
  while(global_var == 1);
--- End code ---

When you attach and are in the debugger, use the debugger to set global_var to 0, then when you step through you will exit the loop.

Your code should only invoke this loop when it detects the "error condition" where you want something like a "breakpoint".


[0] Message Index

Go to full version