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:
template <typename T>
void sort(vector<T> &data)
vector<T> tempData = data;
unsigned long int currentPower = 1;
unsigned long int i, j, k;
i = 0;
while(currentPower < data.size())
while (i < data.size())
j = 0;
k = 0;
while(j < currentPower || k < currentPower) //here I start my first breakpoint for debugging, where i isn't 0 sometimes.
i += 2*currentPower;
currentPower *= 2;
data = tempData;
Any ideas? I always have to start the program like 10 times to get i to be initialised as 0.
Thanks for any efforts :-)
Am I correct assuming that you are using qt creator and the "build-in" debugger?
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.
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.
I'm using MinGW that comes with the SDK 1.2 under Windows 7 64-bit. Any other information I could prepare if needed!!!
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.
I've done that. The debugger is sometimes skipping some lines... I tried setting a breakpoint at the very first line
@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!!!!
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.
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?
Are you using an optimized build?
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.
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?
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.exe: 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.exe: Leaving directoryC:/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.
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?
Thanks for the help guys. Hopefully they'll solve it soon :-)