2

I have a really large code and when I try to run it in codelite, the codelite interface becomes non-responsive and I have to kill it. This usually happens in case of infinite loops.

I tried to put breakpoints in multiple places of the code to find the problem, but no luck so far. The execution halts after a while from the time that I start running the program. What is the best way of detecting such infinite loops? Codelite doesn't have a "stop" button AFAIK.

EDIT: I ended up adding a lot of cout statements and ran the executable in a terminal rather than gdb. This helped finding what the program is doing after a really long time.

1 Answer 1

2

The simplest approach is to run the code for a while and then use the debugger to suspend execution without using breakpoints. If you are lucky, the call stack should indicate the bit of code that you are getting stuck in.

Failing that you will need to pepper your code with logging statements.

5
  • What do you mean by "suspend execution without using breakpoints" ?
    – Ari
    Jun 1, 2012 at 21:12
  • 2
    On gdb you can press Ctrl C to suspend or halt execution. IDE normally have a stop button.
    – doron
    Jun 1, 2012 at 21:19
  • Thanks. At least for me, Codelite IDE is completely non-responsive, and no menu or button is enabled.
    – Ari
    Jun 1, 2012 at 21:35
  • 1
    +1 for 'pepper your code with logging statements' :) that's what I'll be forced to do for the next N hours.
    – tmaric
    Feb 11, 2014 at 13:39
  • 'pepper your code with logging statements' is what I do all the time: works equally well in C++, Perl, Tcl... Just make sure you can turn easily turn them on/off. :)
    – Michael
    Feb 11, 2014 at 19:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.