PDA

View Full Version : How to debug with dbg in this case?



vql
4th February 2007, 11:27
I use gdb on Linux to debug error about "segmentation failt". It work good.
But how to debug in this case:
I declare QList myList;
I call myList[1]; Qt will output warning "... Out of index List" (i don't remember).
gdb can't catch this error, it only know program exit normally. I think why Qt don't throw error "Segmentation failt" for user to catch it easier. Thanks.

The question 2: I use Qt on Windows (version Desktop). How to debug program written by Qt on Windows? Thanks.

wysota
4th February 2007, 14:33
I call myList[1]; Qt will output warning "... Out of index List" (i don't remember).
gdb can't catch this error, it only know program exit normally. I think why Qt don't throw error "Segmentation failt" for user to catch it easier. Thanks.
Qt can't "throw" a segmentation fault error, because it is the system that aborts the process, so Qt could only call abort() here. Instead Qt calls its handler which outputs a warning and then aborts the process. You can easily debug such situation in gdb - simply display the backtrace and look where is the error handler called - it'll be called from within QList::index or something simmilar. Then look further in the call list, the first entry not related to QtCore will be a position in your code which triggered the warning.


The question 2: I use Qt on Windows (version Desktop). How to debug program written by Qt on Windows? Thanks.

You can use gdb under Windows as well.

vql
4th February 2007, 15:08
I am using Qt 4.2 Free Version (version setup). When I add "CONFIG += debug" in .pro file. When I qmake, make, it have errors:


D:\Compiler\MinGW\ld.exe: cannot find -lQtGuid4
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\mythread.exe] Error 1
mingw32-make[1]: Leaving directory `D:/Projects/Qt/mythread'
mingw32-make: *** [debug] Error 2

I think only Qt Commercial force using debug option. That's right?



Qt can't "throw" a segmentation fault error, because it is the system that aborts the process, so Qt could only call abort() here. Instead Qt calls its handler which outputs a warning and then aborts the process. You can easily debug such situation in gdb - simply display the backtrace and look where is the error handler called - it'll be called from within QList::index or something simmilar. Then look further in the call list, the first entry not related to QtCore will be a position in your code which triggered the warning.

Suppose my program have error & output error: "index out of range". Can you guide me clearly how to use backtrace?

jacek
4th February 2007, 15:09
I think only Qt Commercial force using debug option. That's right?
No, it's not. You have to compile Qt in debug mode yourself (there's even a link to a script that does this in Start menu).

vql
4th February 2007, 15:15
I know that on Qt's server contain source file and I tried download it. How do I use mingw to compile it with debug mode because I have errors when compiling? Thanks.

jacek
4th February 2007, 15:21
How do I use mingw to compile it with debug mode because I have errors when compiling?
What errors? What did you install exactly?

vql
4th February 2007, 15:36
I remember exactly when the last version of Qt is 3.3.6, I downloaded opensource form Qt's website to compile with MingW but failed (i don't remember errors). Then I search on internet, and found website: http://sourceforge.net/projects/qtwin/. I tried download it and compile successfully. Right now, I don't find version 4.2 on http://sourceforge.net/projects/qtwin/. If I download version 4.2 from Qt'website, I think I also have errors when compiling same as 3.3.6.

jacek
4th February 2007, 15:44
Right now, I don't find version 4.2 on http://sourceforge.net/projects/qtwin/. If I download version 4.2 from Qt'website, I think I also have errors when compiling same as 3.3.6.
The 3.3.6 version you have found is an unofficial port of Qt/X11 to windows and has nothing to do with official Qt versions available from Trolltech.

You can download the real Open Source version of Qt for windows from here: http://www.trolltech.com/developer/downloads/qt/windows (the .exe file is an installer that will set up Qt for you).

vql
4th February 2007, 15:56
If download file .exe to install, This version will not be debug mode (I am using it). If I downlad file .zip to compile, I will have debug mode? Thanks.

jacek
4th February 2007, 16:19
If download file .exe to install, This version will not be debug mode (I am using it).
Then you already have all you need to produce the debug version. There should be a link in menu "Start" called "Build debug libraries" or similar.

vql
4th February 2007, 16:26
Please answer this question:


Qt can't "throw" a segmentation fault error, because it is the system that aborts the process, so Qt could only call abort() here. Instead Qt calls its handler which outputs a warning and then aborts the process. You can easily debug such situation in gdb - simply display the backtrace and look where is the error handler called - it'll be called from within QList::index or something simmilar. Then look further in the call list, the first entry not related to QtCore will be a position in your code which triggered the warning.

Suppose my program have error & output message: "index out of range". Can you guide me clearly how to use backtrace?

jacek
4th February 2007, 16:32
Suppose my program have error & output message: "index out of range". Can you guide me clearly how to use backtrace?
If your executable is called "app", this should be enough:
$ gdb ./app
GNU gdb 6.6
Copyright (C) 2006 Free Software Foundation, Inc.
...
(gdb) run
<application crashes>
(gdb) bt
<backtrace is here>

vql
5th February 2007, 15:03
If QList throw warning "index out of range", and exit program, I can use backtrace. But in this case, how to solve it?
I'm programing with Coin library. But in my program have a problem. This library only throw warning "Error ..." but it ignore this error and continue (don't exit program). How to break at the line which output this warning?

jpn
5th February 2007, 15:13
How to break at the line which output this warning?
Search where the warning comes from and set a breakpoint there. break <filename:linenum> or break <filename:function>... Refer to the manual of gdb (http://sourceware.org/gdb/current/onlinedocs/gdb_6.html#SEC33) for more info.

vql
5th February 2007, 16:33
Sorry, the warning output from file Coin library in Linux (.o), not in source .cpp. Please help me.

jacek
5th February 2007, 17:38
Sorry, the warning output from file Coin library in Linux (.o), not in source .cpp. Please help me.
Could you post the exact error message?

vql
6th February 2007, 14:12
Ok. Because my program is very big, I can't manage errors from my program.
I'm programming with Coin.
I declare a SbBox2f (a, b). Because there are problems about computing, so a & b can negative. If I use this SbBox2f, class SbBox2f (of Coin library) output warning : "Coin warning in SbBox2f::setBounds(): The bound will give the box negative area."

This warning is very dangerous, it cause my program will not run exactly.
Do you know in my program, there are alot places where I declare SbBox2f as above?

How to I know, I have the problem at which line?
Thanks.

wysota
6th February 2007, 16:07
Set a breakpoint on SbBox2f::setBounds in the debugger and check each call for negative values. When you encounter them, simply display the backtrace and you'll know where it happens.

vql
7th February 2007, 15:18
I have problem about command break (set breakpoint) of gdb.

If I have functions:
void MyClass::test1(QString){ //... }
void MyClass::test2(const QString&){ //... }

When I set breakpoint on test1: break MyClass::test1(QString), it effect.
But when I set breakpoint on test2: break MyClass::test2(const QString&), it doesn't effect.

Thanks.

vql
8th February 2007, 11:17
I tried to break on QString ( const QString & other ).


gdb ./myapp
break QString::QString (const QString &)
run

It can't break on this function (specially on functions have parameter contain keyword const).

Please help me. Thanks.

wysota
8th February 2007, 11:59
How about just "break QString::QString"? Or "break QString::QString(const QString&)" (without the space) ?

You can enter "break QString::" and press the tab key to get a list of all methods defined for QString. You can then find the one you seek.

vql
8th February 2007, 12:39
How to gdb know functions of QString because QString in Qt's library? So I think in this case, if press Tab, it can't list of all methods defined for QString.

Why do you try to break on QString::QString(const QString&) in examples?

Try it & help me.

wysota
8th February 2007, 12:43
How to gdb know functions of QString because QString in Qt's library?
GDB knows how to resolve symbols from the binary it controls and its dependencies.


So I think in this case, if press Tab, it can't list of all methods defined for QString.
You can list methods which are actually seen (used) by your application.


Why do you try to break on QString::QString(const QString&) in examples?

I think the question is why do you try to do it...

vql
8th February 2007, 13:40
You answered:


Set a breakpoint on SbBox2f::setBounds in the debugger and check each call for negative values. When you encounter them, simply display the backtrace and you'll know where it happens.

I tried break on SbBox2f::setBound(const SbVec2f&, const SbVec2f&) but it not effect.

Because I think Coin or Qt, they're the same. So I tried on Qt' library with QString.
I tried on QString::QString(QChar), it have effect.
But I tried on QString::QString(const QString&), it don't have effect.

Can you answer this question, wysota??? Please try on your computer before anwer. Thanks.

wysota
8th February 2007, 15:09
I tried break on SbBox2f::setBound(const SbVec2f&, const SbVec2f&) but it not effect.
Do you use that method in your app? If not (which means that it is used internally), do you have a debug version of libraries you use compiled? You have to compile in debug mode and link with debug libraries to have access to all symbols from within the debugger.


I tried on QString::QString(QChar), it have effect.
But I tried on QString::QString(const QString&), it don't have effect.

Can you answer this question, wysota??? Please try on your computer before anwer. Thanks.

As I already said, you don't have access to QString::QString(const QString&) because you don't use it in your application.

Try debugging this one:

#include <QString>
int main(){
QString x ="xxx";
QString y(x); // here the copy constructor is used
return 0;
}

You'll notice that QString::QString(const QString &) will be among symbols available (remember to compile your app in debug mode). If you don't have a debug version of Qt compiled (and linked to the application), you'll only receive symbols defined for your executable and used by it.

(gdb) break QString<tab>
QString QString::QString(char const*)
QString::QString(QString const&) QString::~QString()

vql
2nd April 2007, 16:52
Qt can't "throw" a segmentation fault error, because it is the system that aborts the process, so Qt could only call abort() here. Instead Qt calls its handler which outputs a warning and then aborts the process. You can easily debug such situation in gdb - simply display the backtrace and look where is the error handler called - it'll be called from within QList::index or something simmilar. Then look further in the call list, the first entry not related to QtCore will be a position in your code which triggered the warning.



You can use gdb under Windows as well.

I tried but not successful. I get message from gdb when type backtrace: "No stack" (not remember)

Please explain me clearly. Thanks.