February 20, 2012

TheDestroyer TheDestroyer
Lab Rat
145 posts

Qt debugger is taking its own initial values

 

Hello guys, :-)

I’m writing a simple function for merge sorting. Of course everyone will tell me “use std algorithm sorters”, but I can’t do that because the container, in which is that data I wanna sort, is somehow a very complicated linked list and I can’t do it with std containers. I’m gonna finish this sorter and do my minor changes to fit in my container.

The problem is the following: I’m debugging the function of sorting step by step. The program starts with initial conditions for the variables i, j and k. But Qt debugger sometimes give random values for i, although it’s initialised. It’s driving me crazy, and I can’t understand why that’s happenening. Any clue? please find the code below:

  1. template <typename T>
  2. void sort(vector<T> &data)
  3. {
  4.     vector<T> tempData = data;
  5.     unsigned long int currentPower = 1;
  6.     unsigned long int i, j, k;
  7.     i = 0;
  8.     while(currentPower < data.size())
  9.     {
  10.         while (i < data.size())
  11.         {
  12.             j = 0;
  13.             k = 0;
  14.             while(j < currentPower || k < currentPower) //here I start my first breakpoint for debugging, where i isn't 0 sometimes.
  15.             {
  16.                 ...
  17.             }
  18.             i += 2*currentPower;
  19.         }
  20.         currentPower *= 2;
  21.     }
  22.     data = tempData;
  23. }

Any ideas? I always have to start the program like 10 times to get i to be initialised as 0.

Thanks for any efforts :-)

14 replies

February 20, 2012

koahnig koahnig
Mad Scientist
2193 posts

Am I correct assuming that you are using qt creator and the “build-in” debugger?

February 20, 2012

TheDestroyer TheDestroyer
Lab Rat
145 posts

Yes. And the same code every time I start, but I get different i values (and even recently j values) every time I start the debugger.

February 20, 2012

koahnig koahnig
Mad Scientist
2193 posts

I have moved your thread to tools. That will probably attract the right people for helping you.

You should give probably also some details on the operation system, compiler and the actual debugger.

February 20, 2012

TheDestroyer TheDestroyer
Lab Rat
145 posts

I’m using MinGW that comes with the SDK 1.2 under Windows 7 64-bit. Any other information I could prepare if needed!!!

February 20, 2012

Volker Volker
Robot Herder
5428 posts

To make sure it actually is the debugger I would put some qDebug() output into the method and print out the values of i, j and k.

February 20, 2012

TheDestroyer TheDestroyer
Lab Rat
145 posts

I’ve done that. The debugger is sometimes skipping some lines… I tried setting a breakpoint at the very first line

  1. vector<T> tempData = data;

and it some times skips it!!!!! I don’t understand what’s going on!!! it’s acting crazy!

Is there someway (that I don’t know of) to start debugging from the middle? perhaps I’m doing that without knowing it!!!!

February 20, 2012

Lukas Geyer Lukas Geyer
Dinosaur Breeder
2074 posts

Are you sure that the code matches the binary? If the debugger skips lines, halts on strange locations and shows odd values you most probably looking at a different version of the source than the one which was used to compile the current binary.

Try to recompile your project with the sources you are actually using to debug the binary.

February 20, 2012

TheDestroyer TheDestroyer
Lab Rat
145 posts

Yes, I’m pretty sure.

I think I know what the problem is. The debugger is “resuming” the last debug. Apparently, if you stop the debugger and run it again, it resumes, and doesn’t start from the beginning…!! I never knew that!!!

How could I reset the debugger manually? is there an option for that?

February 20, 2012

Tobias Hunger Tobias Hunger
Mad Scientist
3224 posts

Are you using an optimized build?

February 20, 2012

TheDestroyer TheDestroyer
Lab Rat
145 posts

If you mean with optimised build using -O2 or -O3 for compiling, then no. The option for the compiler is set to Debug; i.e., to -g.

If that’s not what you mean, please explain what an optimised build is.

February 20, 2012

apoenitz apoenitz
Lab Rat
10 posts

Can you please double check this is a clean build, without any -Ox option, and if the problem persists, paste the debugger log somewhere? Are there any jumps/returns in the “…” part of your code?

February 20, 2012

TheDestroyer TheDestroyer
Lab Rat
145 posts

Here’s the build log for a debug version:

——————————————————————————————————-

17:54:15: Running build steps for project MergeSort…
17:54:15: Configuration unchanged, skipping qmake step.
17:54:16: Starting: “D:\QtSDK\mingw\bin\mingw32-make.exe”
D:/QtSDK/mingw/bin/mingw32-make.exe -f Makefile.Debug
mingw32-make.exe1: Entering directory `C:/Users/Sam/Dropbox/common_src/MergeSort/MergeSort-build-desktop-Qt_4_8_0_for_Desktop_-_MinGW__Qt_SDK__Debug’
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -I“d:\QtSDK\Desktop\Qt\4.8.0\mingw\include\QtCore” -I“d:\QtSDK\Desktop\Qt\4.8.0\mingw\include” -I“d:\QtSDK\Desktop\Qt\4.8.0\mingw\include\ActiveQt” -I“debug” -I”..\MergeSort” -I”.” -I“d:\QtSDK\Desktop\Qt\4.8.0\mingw\mkspecs\win32-g++” -o debug\main.o ..\MergeSort\main.cpp
..\MergeSort\main.cpp: In function ‘int main(int, char**)’:
..\MergeSort\main.cpp:143: warning: comparison between signed and unsigned integer expressions
..\MergeSort\main.cpp: In function ‘void sort(std::vector<T, std::allocator<_CharT> >&) [with T = double]’:
..\MergeSort\main.cpp:147: instantiated from here
..\MergeSort\main.cpp:28: warning: comparison between signed and unsigned integer expressions
..\MergeSort\main.cpp:32: warning: comparison between signed and unsigned integer expressions
..\MergeSort\main.cpp:147: instantiated from here
..\MergeSort\main.cpp:103: warning: unused variable ‘xxx’
g++ -Wl,-subsystem,console -mthreads -o debug\MergeSort.exe debug/main.o -L“d:\QtSDK\Desktop\Qt\4.8.0\mingw\lib” -lQtCored4
mingw32-make.exe1: Leaving directory `C:/Users/Sam/Dropbox/common_src/MergeSort/MergeSort-build-desktop-Qt_4_8_0_for_Desktop_-_MinGW__Qt_SDK__Debug’
17:54:19: The process “D:\QtSDK\mingw\bin\mingw32-make.exe” exited normally.

——————————————————————————————————

The part “…” has only some other while loops and break commands. No goto or return commands.

I don’t have a problem now, since I finished writing the sort function I wanted to write. But the problem persists and still there, and in the future it will happen again.

The problem is that the debugger “resumes” debugging after stopping it, and not starting from the beginning. I don’t know how to disable this stupid feature. If anyone knows, please say, because this summarises the problem.

Please start a console program with your Qt and try to debug stuff similar to my code, and you’ll see how it “resumes” debugging. I’m using Qt SDK 1.2.

February 20, 2012

apoenitz apoenitz
Lab Rat
10 posts

I don’t see it here. Can you please open a bugreport at bugreports.qt-project.org and add a minimal example showing that behaviour? Preferably with the debugger log (the contents of the right pane of Windows->Views->Debugger Log) attached?

February 20, 2012

TheDestroyer TheDestroyer
Lab Rat
145 posts

Bug reported:

https://bugreports.qt-project.org/browse/QTBUG-24388

Thanks for the help guys. Hopefully they’ll solve it soon :-)

 
  ‹‹ Qt Creator Compile Output window produces invalid path      [Solved] "qmake " Console window problem in the release build ››

You must log in to post a reply. Not a member yet? Register here!