ulak blade
ulak blade

Reputation: 2665

Qt debugging in release mode - all methods not working

I am trying to build my Qt app with MinGW in QtCreator in order to try and debug a release-only crash.

Here is what I put in my .pro file (also tried putting it directly into qmake.conf):

QMAKE_CFLAGS_RELEASE += -g
QMAKE_CXXFLAGS_RELEASE += -g
QMAKE_CXXFLAGS += -g

as well as tried with

QMAKE_CFLAGS_RELEASE += -ggdb
QMAKE_CXXFLAGS_RELEASE += -ggdb
QMAKE_CXXFLAGS += -ggdb

I tried them separately or together like this:

QMAKE_CFLAGS_RELEASE += -g
QMAKE_CXXFLAGS_RELEASE += -g
QMAKE_CXXFLAGS += -g
QMAKE_CFLAGS_RELEASE += -ggdb
QMAKE_CXXFLAGS_RELEASE += -ggdb
QMAKE_CXXFLAGS += -ggdb

I have also manually edited the generated Makefile(Makefile.Release to be exact and checked Makefile.Debug just in case) to remove the NO_DEBUG flag (I don't know why it was being put there) and to make sure the -g and -ggdb flags are there.

The result of all of this is that the app took almost twice as long to build, however it was exactly the same size as before and didn't have any debugging symbols and trying to debug it didn't succeed.

What else can I do? I know it's possible, but looking for other answers only directed me to using those flags and that didn't help at all(only made build slower)

Upvotes: 2

Views: 2062

Answers (2)

code_fodder
code_fodder

Reputation: 16341

In qmake.conf (can't recall where this is now) the default behaviour is set as:

QMAKE_LFLAGS_RELEASE = -Wl,-s

Where the -s means the linker does away with the symbolic info. So in addition to the flags you have set you need to clear the flags (or overwrite) in QMAKE_LFLAGS_RELEASE. In your case just setting it to empty should do it, so in your .pro file add:

QMAKE_LFLAGS_RELEASE =

FURTHER NOTES

If you add the line message(QMAKESPEC: $$QMAKESPEC) to your .pro file, when you run qmake you will see the path for your make spec. Look in the qmake.conf file (it will have includes) and work your way through them.

Assuming you are using windows (because I did not see the -Wl,-s option set in the linux make specs for Qt 5.5.1) then the file in question is: <path-to-qt>/5.5/gcc_64/mkspecs/win32-g++/qmake.conf

Anyway, I did not see any other useful flags set (I am using linux so this was only checked by eye. However if you are worried, then add the following to your .pro file:

message(QMAKE_LFLAGS_RELEASE: $$QMAKE_LFLAGS_RELEASE)

To check it before you make changes and then you will have the complete picture of what is going on :)

Upvotes: 3

Sergei Tachenov
Sergei Tachenov

Reputation: 24879

I've just figured it out, and only saw @code_fodder's answer after it. It looks like @code_fodder is essentially right, but I'm adding more details to reflect the precise steps that helped me.

I've specified qmake arguments in the Qt Creator project settings like this:

QMAKE_CXXFLAGS+=-g QMAKE_LFLAGS_RELEASE-=-Wl,-s

This essentially adds -g to the compiler flags and removes -Wl,-s from the linker flags (which strips all symbols). Then I ran qmake and did full rebuild. After that, debugging sort of worked—as you'd expect for a release build: jumping from line to line in a somewhat random fashion because of the optimizations, but at least it worked.

I'm using 32-bit Qt 5.5.1 with bundled MinGW on a 64-bit Windows 7 system, if that is of any help.

Upvotes: 1

Related Questions