I am developing a simple application in C ++ / Qt and I have the following declaration:
QGridLayout *layout = new QGridLayout;
I am debugging an application using gdb . I set a breakpoint, it works fine, and the debugger gets in line. But if I try to verify the object declared above, I get this output:
-data-evaluate-expression --thread 1 --frame 0 layout
^done,value="<value> optimized out>"
I read that this message "<value> optimized out>"is because the compiler optimized the code and put the data in a register. I am using the g ++ compiler with the checkbox selected -O0(no optimization).
Is there something that I am missing, or is there a way to declare a variable that should not be optimized, say, unlike the storage specifier register? I'm on Ubuntu 10.10 Maverick, kernel 2.6.35-24.
EDIT1
Another code:
WorkspaceChooserDialog::WorkspaceChooserDialog(QWidget *parent) : QDialog(parent)
{
setWindowTitle(tr("Select a workspace location"));
QLabel *wpLabel = new QLabel(tr("Workspace:"), this);
QLineEdit *wpLineEdit = new QLineEdit(QDir().homePath(), this);
QPushButton *okButton = new QPushButton(tr("OK"), this);
QPushButton *cancelButton = new QPushButton(tr("Cancel"), this);
QGridLayout *layout = new QGridLayout;
connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
qDebug() << "begin: " << layout << " :end";
layout->addWidget(wpLabel, 0, 0);
layout->addWidget(wpLineEdit, 0, 1, 1, 2);
layout->addWidget(okButton, 1, 1);
layout->addWidget(cancelButton, 1, 2);
setLayout(layout);
}
EDIT2
For reasons unknown to me, after I compiled with the flag set -v, the error no longer appears, even after it was canceled. Now gdb creates a variable, and I can check its value.
For those interested, compiler flags are set:
g++ -O0 -g3 -Wall -c -fmessage-length=0