Hoping, the image describes the issue much better than I can do.

Generally, I'm debugging a multithreaded application in KDevelop with gdb.

I'm debugging the app step by step (F11 shortcut) and have already passed, say, the initialization of the variable resp.

To the left of the screen is the list of all variables I'm able to see.

I'm using -g option for g++, but I suspect I'm missing some other options for it.

From my makefile:

g++ -std=c++11 -g -ggdb -O example.cpp -I../libs -I$(BOOST_INCLUDES) -L$(BOOST_LIBS) -pthread -lboost_thread -lboost_system  -o example 

So, basically, there are no problems with building the app. It is also running okay. Does anybody know why not all variables are displayed in the debugger?

enter image description here

closed as unclear what you're asking by Gilles, roaima, Networker, Anthon, Michael Homer May 24 '15 at 21:57

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


The GCC documentation explains this:

GCC allows you to use -g with -O. The shortcuts taken by optimized code may occasionally produce surprising results: some variables you declared may not exist at all; flow of control may briefly move where you did not expect it; some statements may not be executed because they compute constant results or their values are already at hand; some statements may execute in different places because they have been moved out of loops.

In your case the variables you can't see while debugging were probably optimised away.

To debug your program, you should use -Og instead of -O in your g++ command line. This enables optimisations that don't have any effect on debugging.

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