6

I just finished coding my program but am facing a few logic errors. I want to debug the program.

I am using Codeblocks, so what do I need to do to view the status and value of every variable as the program goes on, and go through the program line by line?

I basically want to do the thing you do in Visual Studio - where the value and address of EVERY variable is displayed as you go through line by line.

I also want the CodeBlocks to show what line is currently being executed.

Does anyone know how I can do this?

Thanks for your help

user1017485
  • 679
  • 1
  • 8
  • 16

2 Answers2

2

First set a breakpoint at the beginning of your code or codeblocks won't go line by line.

When you run your program with debug mode (check the menus) you should get some toolbars with controls to advance lines and view variables. You can you the value of a variable by hovering over it in your code.

xthexder
  • 1,555
  • 10
  • 22
  • thanks i put a breakpoint on the first line and i got it to do the line by line thing however by like the 20th line it says in __cxa_throw () () and doesn't do anything from then on – user1017485 Nov 07 '11 at 20:02
  • do you have any idea what __cxa_throw () () is and why its doing thing? – user1017485 Nov 07 '11 at 20:02
  • It means that your program threw an exception. You have a bug and you just found out where :) – jrok Nov 07 '11 at 20:09
1

See the answer by xthexder, but just in case that you are as freshly beginning the whole debugging thing as I am, here is an additional hint:

You need to activate debugging symbols in the build options for your project.
Otherwise debugging does not work (no breakpoints stop the program, etc.) in slightly special situations like more than one thread and the interesting part not being in the first one. For me that was for example the case when trying to debug my OpenGL/SDL2 program, which means that you can get into those situations without doing the multiple threads consciously yourself.

Of course that is obvious to all those who are experienced in debugging.
But you and me, being beginners...

How to activate the debugging symbols, especially in Code::Blocks:

  • menu "project"
  • menu entry "Build options ..."
  • tab "Compiler settings"
  • category "Debugging"
  • check box "Produce debugging symbols [-g]"
Yunnosch
  • 26,130
  • 9
  • 42
  • 54