Page 1 of 2 12 LastLast
Results 1 to 20 of 26

Thread: How to debug with dbg in this case?

  1. #1
    Join Date
    Jun 2006
    Location
    Vietnam
    Posts
    59
    Thanks
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default How to debug with dbg in this case?

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to debug with dbg in this case?

    Quote Originally Posted by vql View Post
    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.

  3. #3
    Join Date
    Jun 2006
    Location
    Vietnam
    Posts
    59
    Thanks
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to debug with dbg in this case?

    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:
    Qt Code:
    1. D:\Compiler\MinGW\ld.exe: cannot find -lQtGuid4
    2. collect2: ld returned 1 exit status
    3. mingw32-make[1]: *** [debug\mythread.exe] Error 1
    4. mingw32-make[1]: Leaving directory `D:/Projects/Qt/mythread'
    5. mingw32-make: *** [debug] Error 2
    To copy to clipboard, switch view to plain text mode 
    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?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to debug with dbg in this case?

    Quote Originally Posted by vql View Post
    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).

  5. #5
    Join Date
    Jun 2006
    Location
    Vietnam
    Posts
    59
    Thanks
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to debug with dbg in this case?

    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.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to debug with dbg in this case?

    Quote Originally Posted by vql View Post
    How do I use mingw to compile it with debug mode because I have errors when compiling?
    What errors? What did you install exactly?

  7. #7
    Join Date
    Jun 2006
    Location
    Vietnam
    Posts
    59
    Thanks
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to debug with dbg in this case?

    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.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to debug with dbg in this case?

    Quote Originally Posted by vql View Post
    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).

  9. #9
    Join Date
    Jun 2006
    Location
    Vietnam
    Posts
    59
    Thanks
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to debug with dbg in this case?

    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.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to debug with dbg in this case?

    Quote Originally Posted by vql View Post
    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.

  11. The following user says thank you to jacek for this useful post:

    vql (4th February 2007)

  12. #11
    Join Date
    Jun 2006
    Location
    Vietnam
    Posts
    59
    Thanks
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to debug with dbg in this case?

    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?

  13. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to debug with dbg in this case?

    Quote Originally Posted by vql View Post
    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>

  14. #13
    Join Date
    Jun 2006
    Location
    Vietnam
    Posts
    59
    Thanks
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to debug with dbg in this case?

    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?

  15. #14
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to debug with dbg in this case?

    Quote Originally Posted by vql View Post
    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 for more info.
    J-P Nurmi

  16. #15
    Join Date
    Jun 2006
    Location
    Vietnam
    Posts
    59
    Thanks
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to debug with dbg in this case?

    Sorry, the warning output from file Coin library in Linux (.o), not in source .cpp. Please help me.

  17. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to debug with dbg in this case?

    Quote Originally Posted by vql View Post
    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?

  18. #17
    Join Date
    Jun 2006
    Location
    Vietnam
    Posts
    59
    Thanks
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to debug with dbg in this case?

    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.

  19. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to debug with dbg in this case?

    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.

  20. #19
    Join Date
    Jun 2006
    Location
    Vietnam
    Posts
    59
    Thanks
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to debug with dbg in this case?

    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.

  21. #20
    Join Date
    Jun 2006
    Location
    Vietnam
    Posts
    59
    Thanks
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to debug with dbg in this case?

    I tried to break on QString ( const QString & other ).
    Qt Code:
    1. gdb ./myapp
    2. break QString::QString (const QString &)
    3. run
    To copy to clipboard, switch view to plain text mode 
    It can't break on this function (specially on functions have parameter contain keyword const).

    Please help me. Thanks.

Similar Threads

  1. qmake and debug output
    By mattie in forum Qt Programming
    Replies: 7
    Last Post: 18th September 2006, 22:33
  2. Unable to execute in Debug Mode
    By Kapil in forum Installation and Deployment
    Replies: 38
    Last Post: 5th April 2006, 07:27
  3. Replies: 11
    Last Post: 22nd March 2006, 19:06
  4. QTextCursor - setTextColor()
    By Dalamar in forum Newbie
    Replies: 0
    Last Post: 20th February 2006, 18:34
  5. TIP: If Qt4.1 debug compile doesn't work...
    By pthomas in forum Newbie
    Replies: 3
    Last Post: 13th January 2006, 14:36

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.