Author Topic: how I can debug file multiple times without closing cmd?  (Read 600 times)

Offline Dr Wish

  • Single posting newcomer
  • *
  • Posts: 1
how I can debug file multiple times without closing cmd?
« on: May 22, 2018, 12:04:46 am »
The annoying problem is when I do debug and run my cpp file a cmd will open but I can not debug again because I have to close the cmd.
How I can debug multiple times without closing the cmd every time?

Offline headkase

  • Almost regular
  • **
  • Posts: 158
Re: how I can debug file multiple times without closing cmd?
« Reply #1 on: May 22, 2018, 12:42:50 am »
You start debugging with the red right-pointing triangle.  Hover over that for a second.  In the tool-tip that pops up you will see its description as "Debug / Continue".  Start your program using that and when you hit a break-point do what you want to do and then press it again to continue.  First click starts the program with your attached debugger and at a break point(s) subsequent clicks continue execution of your program.

Offline BlueHazzard

  • Lives here!
  • ****
  • Posts: 2022
Re: how I can debug file multiple times without closing cmd?
« Reply #2 on: June 21, 2018, 12:09:55 am »
Now i remember i wanted to answer to this question too.

What do you mean by
Quote
I can not debug again because I have to close the cmd
Do you want to restart the program within the debugger?

To achieve this there are multiple ways:
1) Write your program in a way you can easily restart it by setting a variable (for example use state machines with the first state reseting all variable to a default value). Now you can simply change this variable in the watches window.

2) If you are on linux you can use the checkpoint feature of gdb: https://sourceware.org/gdb/onlinedocs/gdb/Checkpoint_002fRestart.html this is not supported by codeblocks yet, so you have to type the commands by hand in the gdb input field at the bottom. I have planed to add this for a long time, but there are other things to fix for gdb first...

3) Jump back to the beginning of main. This can be dangerous, because variables are not initialized like at the startup of your program. This is also not supported by codeblocks directly but you can type "jump main()" in the gdb command line at the bottom...
NOTE: this method has many pitfalls:
* Memory leaks
* does not work on multi threaded apps
* Open files remain open
* ecc....

sorry for the late reply, i hope this helped...