Results 1 to 8 of 8

Thread: a strange crash

  1. #1
    Join Date
    Mar 2016
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default a strange crash

    Basic information:
    Qt4.8.6 + mingw + win8 + gdb + qtcreator
    problem description:
    The application program compiles ok in both debug and release modes, but crashes randomly when I run it. I tried all my best to find if there is a bug in my code, but the code looks ok. The strange thing is that when I run the same program in the step-by-step debugger, it never crash. I noticed that when the debugger runs it reports "load ...*dll successful", so I guess if some library *dll can be loaded by the debugger but can not be loaded when I actually run it by click the green button "run"?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: a strange crash

    You need to do a post-mortem analysis, i.e. look at the stack trace when it crashed.

    Maybe you are accessing an uninitialized pointer or a pointer to a deleted object, etc.

    Cheers,
    _

  3. #3
    Join Date
    Mar 2016
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: a strange crash

    Thanks for reply, anda_skoa. In fact what you said is a good way to solve the problem, however, the program runs well in the debugger mode. Or in other words, when I use the debugger mode(GDB) to figure out the location where it crashes, the crash never happens. Or, maybe do you know another way to find the stack trace except by using GDB?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: a strange crash

    You don't need to run it in the debugger, when it crashed it should still be debuggable.
    I think on Windows you get a dialog asking if you want to Retry and that starts the debugger or maybe that is compiler specific and a MinGW built program also creates a core dump like on other operating systems.

    Cheers,
    _

  5. #5
    Join Date
    Mar 2016
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default [solved]Re: a strange crash

    [solved] Cheers, my problem has been solved, at least, it looks so currently
    What I would like to share including:
    (1). the reason caused program crash was that I used an uninitialized variable (int max_value) as the bound in a loop:
    Qt Code:
    1. for(int i=0; i<max_value; i++){a[i]=***;} //int a[10] is a arrary
    To copy to clipboard, switch view to plain text mode 
    so the above loop statement might lead to an illegal usage of memory especially when the value of "max_value" initialized by windows 8 system is very big!
    I found the value of max_value initialized by windows 8 is 14339584, and lead to the crash as a result.

    (2). On how to debug. I tried to figure out the problem in the Qt debugger mode (GDB) but the program never crash as I said at the beginning. Maybe in the environment set by the debugger gave a reasonable value to "max_value", I didn't check. My method which helped me figure out the problem successfully here was the oldest one: print everywhere. Of course, it is unnecessary to print everywhere if you know you code very well, just print at some key points in the flow chart of your code. Find the possible codes where the bug is then continue to print in that area. Honestly, it took me only 2 minutes to find out and fix the bug which confused me at least for 2 whole working days. Programmers should calm down and think.

    (3). Another interesting thing is that when the program crash Qt reported: "quit with code -1073741819", and I found many people were asking and discussing on the "-1073741819 code". Maybe what I posted here helps.

    (4). [ask]. I still want to know on how to generate a core dump like file in windows and how to use it to debug? should gdb still work? Anyway, powerful debug tools are still desired to find the location quickly!

    Quote Originally Posted by anda_skoa View Post
    You don't need to run it in the debugger, when it crashed it should still be debuggable.
    I think on Windows you get a dialog asking if you want to Retry and that starts the debugger or maybe that is compiler specific and a MinGW built program also creates a core dump like on other operating systems.

    Cheers,
    _
    Last edited by hxf@dlut.edu.cn; 8th March 2016 at 13:07.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: [solved]Re: a strange crash

    Quote Originally Posted by hxf@dlut.edu.cn View Post
    I found the value of max_value initialized by windows 8 is 14339584, and lead to the crash as a result.
    An uninitialized variable is, by definition, uninitialized
    It can have any value, basically whatever the content of the memory at its location is at the time of access.

    Modern compilers and static code analyzers and memory checkers can detect and warn these things.

    Better of course is to always initialize variables.

    Quote Originally Posted by hxf@dlut.edu.cn View Post
    (4). [ask]. I still want to know on how to generate a core dump like file in windows and how to use it to debug? should gdb still work?
    Someone developing on Windows will have to answer that but this is how it work on all other platforms.

    Cheers,
    _

  7. #7
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: [solved]Re: a strange crash

    Quote Originally Posted by hxf@dlut.edu.cn View Post
    I still want to know on how to generate a core dump like file in windows and how to use it to debug? should gdb still work? Anyway, powerful debug tools are still desired to find the location quickly!
    Many years since I have done any debugging on windows, but I suspect it hasn't changed much. Google windbg and symbols. Basically MS provides symbols for all of the windows run-time dll's and you can generate symbols for your own app executables using MS tool chain.

    Hope that gets you started in the right direction. Good luck!

    P.S. Sorry, I just noticed that you are using mingw tool chain, not sure if it and/or GDB are windows symbols aware, etc. You'll have to google around to find out whether or not that's the case or whether windbg/symbols approach will be usable if not using the MS tool chain.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  8. #8
    Join Date
    Mar 2016
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: [solved]Re: a strange crash

    Thank you for your guides, Jeff, if you don't mind I call you Jeff. Actually my first Qt program and maybe my first c++ program as well were coded on Linux red hat. At that time I have good colleagues to set all the debug things and all the environment things as well. Then I quit that place where I worked for nearly two years, and moved to a new country, and I have to do things all by myself. Got myself crazy on some difficult/strange issues. Your name/ID Jeff makes me so said because at that time Jeff and I shared an office. He was always staring on the computer screen, and I think he is still there, maybe still working on that computer this afternoon. Next time I just send my problem to Jeff directly, maybe that would help.

    Quote Originally Posted by jefftee View Post
    Many years since I have done any debugging on windows, but I suspect it hasn't changed much. Google windbg and symbols. Basically MS provides symbols for all of the windows run-time dll's and you can generate symbols for your own app executables using MS tool chain.

    Hope that gets you started in the right direction. Good luck!

    P.S. Sorry, I just noticed that you are using mingw tool chain, not sure if it and/or GDB are windows symbols aware, etc. You'll have to google around to find out whether or not that's the case or whether windbg/symbols approach will be usable if not using the MS tool chain.

Similar Threads

  1. Replies: 0
    Last Post: 3rd November 2015, 17:58
  2. Strange QHash crash
    By t_3 in forum Qt Programming
    Replies: 2
    Last Post: 16th December 2013, 19:28
  3. Replies: 3
    Last Post: 12th May 2011, 17:45
  4. Crash gracefully? No crash!
    By lni in forum Qt Programming
    Replies: 0
    Last Post: 7th July 2010, 03:59
  5. !!!A Strange Crash
    By hhf in forum Qt Programming
    Replies: 12
    Last Post: 10th March 2010, 12:45

Tags for this Thread

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.