PDA

View Full Version : qt creator - breakpoints don't work



pmitas
5th September 2010, 15:14
Hi,

I'm having problems with debugging stuff in qt creator.

I write a simple test app:

int main(int argc, char** argv)
{
QApplication app(argc, argv);
QLabel* lol = new QLabel("test");
lol->show();
return app.exec();
}

Then I set a breakpoint on any of the lines (or even on all lines) and run the debugger. It skips right through all the breakpoints and enters the main loop. If I then pause the execution and look at the stack trace, it shows the main function is at line 0 and is grayed out, like this: http://i.imgur.com/3EZ3g.png . Double clicking it takes me to the assembly view.

What's going on?

wysota
5th September 2010, 17:21
Hard to say without any additional info. You may look at the output from Creator to see if there aren't any warnings related to the debugger.

pmitas
7th September 2010, 18:59
I've kind of tracked down the issue - qtcreator doesn't add -g option to CFLAGS when building in debug mode. In fact it doesn't add any optimization options when building in release mode either...

Here's a build line in debug mode:
g++ -c -pipe -Wall -W -D_REENTRANT -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -o main.o main.cpp

ant this is in release mode:
g++ -c -pipe -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -o main.o main.cpp

The only difference is -DQT_NO_DEBUG.

I clearly remember, that this stuff used to work in the past. What could have happened that broke it?

tbscope
7th September 2010, 19:14
As a side note, and one I did encounter.
Do not use-o optimisation and -g dwarf information at the same time.

Some breakpoints will fail because the code is optimised.
A debugger making use of the dwarf information will not report the correct line numbers. It will report line numbers of the optimised code.

pmitas
7th September 2010, 19:30
Oddly, I rebuilt qt-core (I'm on Gentoo) without optimized-qmake and it started including -g in debug mode, but still is not doing any optimizations in release mode.

I did some snooping around and found the file /usr/share/qt4/mkspecs/common/g++.conf. There I found the lines:

QMAKE_CFLAGS_RELEASE +=
QMAKE_CFLAGS_DEBUG += -g

Should the first line be empty?

tbscope
7th September 2010, 19:32
Did you recently change /etc/make.conf ?
On my system it contains the CXX_FLAGS (or something like that) environment variable.

Edit: note that optimisation isn't always wanted, so you should set the level yourself.

pmitas
7th September 2010, 20:51
No, I didn't change /etc/make.conf C(XX)FLAGS lately. It's set to:

CFLAGS="-O2 -march=core2 -msse3 -mssse3 -msse4.1 -pipe -g"
CXXFLAGS="${CFLAGS}"

I also remember, that in the past the release mode used some or all of these flags.

wysota
7th September 2010, 21:39
I don't think qmake takes /etc/make.conf into consideration when generating the Makefile. It should work solely based upon $QTDIR/mkspecs/*.

pmitas
7th September 2010, 21:54
Well then, should the QMAKE_CFLAGS_RELEASE variable be empty?

wysota
7th September 2010, 22:24
I think you should care more about QMAKE_CXXFLAGS and family.

pmitas
7th September 2010, 22:26
I think you should care more about QMAKE_CXXFLAGS and family.

This one's set to just "-pipe".

wysota
7th September 2010, 22:33
What about QMAKE_CXXFLAGS_DEBUG and others like it?

pmitas
8th September 2010, 09:48
Here are all the defaults:
QMAKE_CC = gcc
QMAKE_CFLAGS += -pipe
QMAKE_CFLAGS_DEPS += -M
QMAKE_CFLAGS_WARN_ON += -Wall -W
QMAKE_CFLAGS_WARN_OFF += -w
QMAKE_CFLAGS_RELEASE +=
QMAKE_CFLAGS_DEBUG += -g
QMAKE_CFLAGS_SHLIB += -fPIC
QMAKE_CFLAGS_STATIC_LIB += -fPIC
QMAKE_CFLAGS_YACC += -Wno-unused -Wno-parentheses
QMAKE_CFLAGS_HIDESYMS += -fvisibility=hidden
QMAKE_CFLAGS_PRECOMPILE += -x c-header -c ${QMAKE_PCH_INPUT} -o ${QMAKE_PCH_OUTPUT}
QMAKE_CFLAGS_USE_PRECOMPILE += -include ${QMAKE_PCH_OUTPUT_BASE}

QMAKE_CXX = g++
QMAKE_CXXFLAGS += $$QMAKE_CFLAGS
QMAKE_CXXFLAGS_DEPS += $$QMAKE_CFLAGS_DEPS
QMAKE_CXXFLAGS_WARN_ON += $$QMAKE_CFLAGS_WARN_ON
QMAKE_CXXFLAGS_WARN_OFF += $$QMAKE_CFLAGS_WARN_OFF
QMAKE_CXXFLAGS_RELEASE += $$QMAKE_CFLAGS_RELEASE
QMAKE_CXXFLAGS_DEBUG += $$QMAKE_CFLAGS_DEBUG
QMAKE_CXXFLAGS_SHLIB += $$QMAKE_CFLAGS_SHLIB
QMAKE_CXXFLAGS_STATIC_LIB += $$QMAKE_CFLAGS_STATIC_LIB
QMAKE_CXXFLAGS_YACC += $$QMAKE_CFLAGS_YACC
QMAKE_CXXFLAGS_HIDESYMS += $$QMAKE_CFLAGS_HIDESYMS -fvisibility-inlines-hidden
QMAKE_CXXFLAGS_PRECOMPILE += -x c++-header -c ${QMAKE_PCH_INPUT} -o ${QMAKE_PCH_OUTPUT}
QMAKE_CXXFLAGS_USE_PRECOMPILE = $$QMAKE_CFLAGS_USE_PRECOMPILE

wysota
8th September 2010, 10:19
Looks fine to me. According to this -g should be in debug mode and not in release mode. My qmake gives me -g in release mode as well (it might be platform dependent, I'm using 'linux-g++' platform) but it's more important that it's there for debug. If -g is missing from your debug makefile, then obviously something had to remove it - maybe you are using some 3rd party addition that introduces such effect.

pmitas
8th September 2010, 10:28
I'm not saying -g should be in the release mode. I'm saying that at least -O2 should be in the release mode. Am I not right?

I just want to know if some optimization flags are SUPPOSED to be there or is it up to the distribution's maintainers. Or maybe it's supposed to be empty after all?

-g was missing from debug, but then I rebuilt qt-core and it popped back. Weird, but it happens, this problem is solved now. I just want to know about the release thing and I'll be gone :)

wysota
8th September 2010, 10:34
I'm saying that at least -O2 should be in the release mode. Am I not right?
I wouldn't say that was relevant to breakpoints working (or not) in debug mode.


I just want to know if some optimization flags are SUPPOSED to be there or is it up to the distribution's maintainers. Or maybe it's supposed to be empty after all?
It depends on where do you have Qt from. If you installed it from the verbatim package downloaded from Nokia then you should have the defaults. But if you installed it through a package manager for your distro, the maintainer of the package might have changed some of the specs (I don't say that is the case). Take a look at the mkspecs directory of your installation and compare it to the Makefile generated by qmake. See if the variable values are consistent.

pmitas
8th September 2010, 10:53
That's all then. Thanks for your time.