Page 1 of 3 123 LastLast
Results 1 to 20 of 48

Thread: Program crashes (SIGSEGV)

  1. #1
    Join Date
    May 2007
    Posts
    37
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Program crashes (SIGSEGV)

    Hello,

    My program crashes sometimes (SIGSEGV - Segmentation fault). This is (a part of) the code:

    This shows the error message when the connection with the server was broken or stopped.
    Qt Code:
    1. void Window_Login_Busy::show_errors(int sort_error)
    2. {
    3. close();
    4. window_login->show();
    5. progressbar->setValue(0);
    6.  
    7. QString text = "Aanmelden mislukt";
    8. if(sort_error == 1)
    9. text += ": Disconnected from server.";
    10. else if (sort_error == 2)
    11. text += ": Gebruikersnaam of wachtwoord is fout.";
    12.  
    13. err.setIcon(QMessageBox::Warning);
    14. err.setWindowTitle("QQMsn: Error");
    15. err.setText(text);
    16. err.exec();
    17.  
    18. //debug->setData("bla");
    19. }
    To copy to clipboard, switch view to plain text mode 
    and

    Here someone entered the wrong password, I break the connection with the server.
    Qt Code:
    1. while(ssl_sck_dalogin->canReadLine())
    2. {
    3. [...]
    4. else if(line.contains("HTTP/1.1 302 FOUND"))
    5. {
    6. debug->setData("Redirect");
    7.  
    8. break;
    9. }
    10. [...]
    11. }
    To copy to clipboard, switch view to plain text mode 
    and

    This is the emited slot when I close the connection, it uses the standard Qt signal:

    connect(socket, SIGNAL(disconnected()), SLOT(isDisconnected()));

    login_busy->show_errors(1); is the function in the first code I posted.

    Qt Code:
    1. void cmsn::isDisconnected()
    2. {
    3. debug->setData("\nDisconnected from host (Notification server).");
    4.  
    5. if(login_busy->change_lbl)
    6. login_busy->show_errors(1);
    7. }
    To copy to clipboard, switch view to plain text mode 
    When someone enters the wrong password, I get an error dialog with an Ok button, the login screen is showed and the login_busy is closed. But when you close that screen or press the Ok button, the program receives the SIGSEGV signal and crashes.

    gdb says:

    `/home/quinten/QQMsn_build/QQMsn' has changed; re-reading symbols.
    Starting program: /home/quinten/QQMsn_build/QQMsn
    Failed to read a valid object file image from memory.
    [Thread debugging using libthread_db enabled]
    [New Thread -1223088432 (LWP 4881)]
    [New Thread -1225602160 (LWP 4882)]

    Program received signal SIGSEGV, Segmentation fault.
    [Switching to Thread -1223088432 (LWP 4881)]
    When I don't show an MessageBox, the program does not crash and gdb says:

    Starting program: /home/quinten/QQMsn_build/QQMsn
    Failed to read a valid object file image from memory.
    [Thread debugging using libthread_db enabled]
    [New Thread -1222646064 (LWP 4927)]
    [New Thread -1225159792 (LWP 4928)]
    [Thread -1225159792 (LWP 4928) exited]

    Program exited normally.
    There are some cases where the server closes the connection (e.g. entering a wrong username). In that case, the same slot is emited, the
    MessageBox shows, and when pressing OK, the MessageBox closes and the program doesn't crash.


    Why does my program crash? How can I solve it? I don't understand where the error is, in my ssl class, in my window_login class, in Qt, in OpenSSL or somewhere else? When you need the whole source code, I'll post it.
    Last edited by Voldemort; 9th May 2007 at 21:16.
    Using Qt version 4.3.0

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Program crashes (SIGSEGV)

    My assumption is that calling close() in show_errors causes a lot of problems.
    It will post a close event in the event loop. But then you show a modal warning message box. This will block all activity in your window, and show_errors will not exit until you close the dialog.

    Try using hide() instead if you can, or show the warning message box and the login window after the main window is closed. You could do something about this in close event.

    Or, in isDisconnected, call showErrors and then call login_busy->close() right after it, but remove close() from show_errors().

    Perhaps it would be more helpful if you posted the entire code, so somebody can testy it.

    Regards

  3. #3
    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: Program crashes (SIGSEGV)

    Could we see the backtrace? Do you use threads in your application?

  4. #4
    Join Date
    May 2007
    Posts
    37
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Program crashes (SIGSEGV)

    When I remove the close(); (just for testing), it still crashes, so I think the problem is not the close(); but something else.

    Where can I find backtraces?

    What are threads?

    Source
    The source is in the attachment.

    Licence
    GPLv2

    Info
    When you enter your MSN and correct password, it will stay to 100%, that's because I have to program the other things. The crash happens only when you enter a valid mailadres and a wrong password.

    Requirements
    Qt 4.3
    CMake (don't know which version, I use CMake 2.4.6)

    Compiling
    Qt Code:
    1. mkdir QQMsn_build
    2. cd QQMsn_build
    3. cmake ../<source_dir>
    4. make
    To copy to clipboard, switch view to plain text mode 
    Attached Files Attached Files
    Last edited by Voldemort; 12th May 2007 at 12:07.
    Using Qt version 4.3.0

  5. #5
    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: Program crashes (SIGSEGV)

    Quote Originally Posted by Voldemort View Post
    Where can I find backtraces?
    Enter "bt" in gdb after the application crashes.

    What are threads?
    http://en.wikipedia.org/wiki/Thread_(computer_science)

  6. #6
    Join Date
    May 2007
    Posts
    37
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Program crashes (SIGSEGV)

    Backtrace:

    Qt Code:
    1. #0 0xb668ad83 in SSL_read () from /usr/lib/libssl.so
    2. #1 0x00000004 in ?? ()
    3. #2 0x00000004 in ?? ()
    4. #3 0x00000000 in ?? ()
    To copy to clipboard, switch view to plain text mode 

    But I don't understand a backtrace, how do you have to read it? Where can you find the crucial information in the backtrace?

    I don't think I use threads.
    Using Qt version 4.3.0

  7. #7
    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: Program crashes (SIGSEGV)

    First you have to compile your application with debug information (CONFIG+=debug in .pro file). Adding QMAKE_CXXFLAGS+=-ggdb will give you even more info.

  8. #8
    Join Date
    May 2007
    Posts
    37
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Program crashes (SIGSEGV)

    But I use CMake, not QMake, how can I do the same in CMake?
    Using Qt version 4.3.0

  9. #9
    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: Program crashes (SIGSEGV)

    Consult the manual on how to set CXXFLAGS for your project.

  10. #10
    Join Date
    May 2007
    Posts
    37
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Program crashes (SIGSEGV)

    I can't find the answer in the documentation

    http://www.cmake.org/HTML/Documentation.html
    Using Qt version 4.3.0

  11. #11
    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: Program crashes (SIGSEGV)

    set(CMAKE_CXX_FLAGS "-ggdb")

  12. #12
    Join Date
    May 2007
    Posts
    37
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Program crashes (SIGSEGV)

    I added the line, but there is no difference, I think I have to this:

    First you have to compile your application with debug information (CONFIG+=debug in .pro file).
    But how do I have to set this option?
    Using Qt version 4.3.0

  13. #13
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Program crashes (SIGSEGV)

    In the .pro file you have to add that line.

  14. #14
    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: Program crashes (SIGSEGV)

    @marcel: He doesn't use qmake.

    It's enough if you add the -ggdb flag.

  15. #15
    Join Date
    May 2007
    Posts
    37
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Program crashes (SIGSEGV)

    There changes nothing:

    # gdb ./QQMsn 2> ../QQMsn_debug.txt
    GNU gdb 6.5
    Copyright (C) 2006 Free Software Foundation, Inc.
    GDB is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.
    Type "show copying" to see the conditions.
    There is absolutely no warranty for GDB. Type "show warranty" for details.
    This GDB was configured as "i586-suse-linux"...Using host libthread_db library "/lib/libthread_db.so.1".

    (gdb) run
    Starting program: /home/quinten/QQMsn_build/QQMsn
    [Thread debugging using libthread_db enabled]
    [New Thread -1222338864 (LWP 4290)]
    [New Thread -1224852592 (LWP 4297)]

    Program received signal SIGSEGV, Segmentation fault.
    [Switching to Thread -1222338864 (LWP 4290)]
    0xb66f7d83 in SSL_read () from /usr/lib/libssl.so
    (gdb) bt
    #0 0xb66f7d83 in SSL_read () from /usr/lib/libssl.so
    #1 0x00000004 in ?? ()
    #2 0x00000004 in ?? ()
    #3 0x00000000 in ?? ()
    (gdb) kill
    Kill the program being debugged? (y or n) y
    But I don't understand a backtrace, how do you have to read it? Where can you find the crucial information in the backtrace?
    Using Qt version 4.3.0

  16. #16
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Program crashes (SIGSEGV)

    From what I see in the call stack, it crashes in libssl.
    Qt supports SSL from 4.3. Did you link with the correct( required ) ssl library ?
    Maybe you didn't have the correct version when you compiled Qt. Anyway, It does not make a lot of sense crashing at that point ( perhaps a bug in Qt related to SSL ? ).

    Try disabling SSL from QHttp, if you can...

    To Wysota: It doesn't matter if he enables debugging information in his app, because it crashes in another lib.

    Regards

  17. #17
    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: Program crashes (SIGSEGV)

    Quote Originally Posted by marcel View Post
    To Wysota: It doesn't matter if he enables debugging information in his app, because it crashes in another lib.
    Of course it matters - something calls this "another lib", right?. As you can see three symbols are not identified correctly. And it looks like a corrupted stack (look at symbol addresses, it looks like the frame stack is incorrect), by the way, so I suggest doing "make distclean && qmake && make" first to make sure the app is compiled properly. Blaiming OpenSSL is certainly not the way to go.

  18. #18
    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: Program crashes (SIGSEGV)

    Quote Originally Posted by Voldemort View Post
    #3 0x00000000 in ?? ()
    It looks like you try to dereference a null pointer somewhere. Make sure you create all Qt objects after QApplication instance was created.

    Quote Originally Posted by Voldemort View Post
    But I use CMake, not QMake, how can I do the same in CMake?
    Run ccmake and set CMAKE_BUILD_TYPE to Debug.

  19. #19
    Join Date
    May 2007
    Posts
    37
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Program crashes (SIGSEGV)

    1) I create QOBjects before I use QApplication, but that's because otherwise extern won't work (main.cpp). Is that the cause of the crash? How can I solve this problem?

    2) How do I disable SSL from QHttp? I need a QSslSocket, so disabling SSL will cause my application won't work.

    3) CMAKE_BUILD_TYPE is set to "Debug", no change in the bactrace?
    Using Qt version 4.3.0

  20. #20
    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: Program crashes (SIGSEGV)

    Why not use a pointer to QObject?

Similar Threads

  1. Porting my program to another windows machine !
    By probine in forum Qt Programming
    Replies: 1
    Last Post: 14th March 2007, 07:46
  2. QT Program debug,GDB on Linux
    By darpan in forum General Programming
    Replies: 1
    Last Post: 26th January 2007, 23:02
  3. QT MySQL
    By sabeeshcs in forum Newbie
    Replies: 6
    Last Post: 12th January 2007, 05:19
  4. Enter key causing program to exit
    By welby in forum Qt Programming
    Replies: 2
    Last Post: 9th March 2006, 17:11
  5. Reading from TCP Socket crashes program
    By OnionRingOfDoom in forum Qt Programming
    Replies: 26
    Last Post: 27th January 2006, 20:32

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.