问题
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
回答1:
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.
回答2:
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]"
来源:https://stackoverflow.com/questions/8041614/how-to-debug-in-codeblocks