Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to configure Visual Studio to stop on qfatal?
Forum Updated to NodeBB v4.3 + New Features

How to configure Visual Studio to stop on qfatal?

Scheduled Pinned Locked Moved Unsolved General and Desktop
visual studioqt 5.5qfataldebug
11 Posts 2 Posters 2.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alain38 0
    wrote on last edited by
    #1

    Hi,
    I have a lot of tests (using QTest). Sometimes some of them generate calls to qfatal. Unfortunately, in this case, even whether my test suite is compiled in debug mode, it does not stop to give me the capability to debug. It just kills the application. So, for the moment, the only way I found to debug in this situation is to set breakpoints inside q_assert functions.

    Does it exist a way to configure Visual Studio 2017 so that a call to qfatal just block the application for debugging instead of killing it?

    JonBJ 1 Reply Last reply
    0
    • A Alain38 0

      Hi,
      I have a lot of tests (using QTest). Sometimes some of them generate calls to qfatal. Unfortunately, in this case, even whether my test suite is compiled in debug mode, it does not stop to give me the capability to debug. It just kills the application. So, for the moment, the only way I found to debug in this situation is to set breakpoints inside q_assert functions.

      Does it exist a way to configure Visual Studio 2017 so that a call to qfatal just block the application for debugging instead of killing it?

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by JonB
      #2

      @Alain38-0
      You can write your own "qtMessageHandler" and install it via http://doc.qt.io/qt-5/qtglobal.html#qInstallMessageHandler.

      See also http://doc.qt.io/qt-5/qtglobal.html#qFatal.

      If you are using the default message handler this function will abort to create a core dump. On Windows, for debug builds, this function will report a _CRT_ERROR enabling you to connect a debugger to the application.

      So it may be that in Debug build you can already trap just that.

      A 1 Reply Last reply
      0
      • JonBJ JonB

        @Alain38-0
        You can write your own "qtMessageHandler" and install it via http://doc.qt.io/qt-5/qtglobal.html#qInstallMessageHandler.

        See also http://doc.qt.io/qt-5/qtglobal.html#qFatal.

        If you are using the default message handler this function will abort to create a core dump. On Windows, for debug builds, this function will report a _CRT_ERROR enabling you to connect a debugger to the application.

        So it may be that in Debug build you can already trap just that.

        A Offline
        A Offline
        Alain38 0
        wrote on last edited by
        #3

        Hi @JonB,
        My purpose is just to be in a mode to be able to debug, so to have the call stack and so on, to be able to understand why I have a problem. Writing my own handler for this seems a little bit to heavy compared to the current solution (setting breackpoints in Qt source files).

        JonBJ 1 Reply Last reply
        0
        • A Alain38 0

          Hi @JonB,
          My purpose is just to be in a mode to be able to debug, so to have the call stack and so on, to be able to understand why I have a problem. Writing my own handler for this seems a little bit to heavy compared to the current solution (setting breackpoints in Qt source files).

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by JonB
          #4

          @Alain38-0
          You don't write your own code to handle it. You write the function like I said and put a breakpoint in when QtMessageType::QtFatalMsg. Or for that case there is a Windows call to auto-enter a debugger if attached, ::DebugBreak https://msdn.microsoft.com/en-us/library/ms679297(v=VS.85).aspx, to save you even bothering with a breakpoint. In all cases you let your message handler then call the default message handler. Total about 2 lines of code. Or copy the exact example code on the referenced page. As you please.

          Having said that the doc I quoted

          On Windows, for debug builds, this function will report a _CRT_ERROR enabling you to connect a debugger to the application

          implies you should already be able to catch this in the VS debugger without any further work from you, but I leave you to investigate that.

          A 1 Reply Last reply
          0
          • JonBJ JonB

            @Alain38-0
            You don't write your own code to handle it. You write the function like I said and put a breakpoint in when QtMessageType::QtFatalMsg. Or for that case there is a Windows call to auto-enter a debugger if attached, ::DebugBreak https://msdn.microsoft.com/en-us/library/ms679297(v=VS.85).aspx, to save you even bothering with a breakpoint. In all cases you let your message handler then call the default message handler. Total about 2 lines of code. Or copy the exact example code on the referenced page. As you please.

            Having said that the doc I quoted

            On Windows, for debug builds, this function will report a _CRT_ERROR enabling you to connect a debugger to the application

            implies you should already be able to catch this in the VS debugger without any further work from you, but I leave you to investigate that.

            A Offline
            A Offline
            Alain38 0
            wrote on last edited by
            #5

            @JonB The problem is that I am in debug mode. So a debugger is supposed to ba automatically connected to the application. But qFatal is not trapped by the debugger.

            JonBJ 1 Reply Last reply
            0
            • A Alain38 0

              @JonB The problem is that I am in debug mode. So a debugger is supposed to ba automatically connected to the application. But qFatal is not trapped by the debugger.

              JonBJ Online
              JonBJ Online
              JonB
              wrote on last edited by
              #6

              @Alain38-0
              This really should not be complicated. You are confusing me now.

              1. Do you compile for Debug? I assume yes.
              2. Do you run your app/tests from inside VS or from outside VS?
              3. If you run from inside VS, do you set it running via "Start Debugging" or "Start without Debugging"?
              A 1 Reply Last reply
              0
              • JonBJ JonB

                @Alain38-0
                This really should not be complicated. You are confusing me now.

                1. Do you compile for Debug? I assume yes.
                2. Do you run your app/tests from inside VS or from outside VS?
                3. If you run from inside VS, do you set it running via "Start Debugging" or "Start without Debugging"?
                A Offline
                A Offline
                Alain38 0
                wrote on last edited by
                #7

                @JonB
                Everything si compiled in debug mode. I'm running inside VS by using "Start Debugging". This is why I am so surprised that qFatal kill my application instead of just be trapped by the debugger. To add (I have seen something about on Internet), I'm using _DEBUG (and not NDEBUG). So CRT debugging is supposed to be active.

                JonBJ 1 Reply Last reply
                0
                • A Alain38 0

                  @JonB
                  Everything si compiled in debug mode. I'm running inside VS by using "Start Debugging". This is why I am so surprised that qFatal kill my application instead of just be trapped by the debugger. To add (I have seen something about on Internet), I'm using _DEBUG (and not NDEBUG). So CRT debugging is supposed to be active.

                  JonBJ Online
                  JonBJ Online
                  JonB
                  wrote on last edited by JonB
                  #8

                  @Alain38-0
                  Then you are saying you do not agree with the documentation statement:

                  On Windows, for debug builds, this function will report a _CRT_ERROR enabling you to connect a debugger to the application

                  I cannot comment on that. But let's assume you're right. So I'm saying, to workaround for what you want please do the following:

                  1. From http://doc.qt.io/qt-5/qtglobal.html#qInstallMessageHandler copy & paste their myMessageOutput() function sample code into your application.

                  2. Install that as event handler somewhere via qInstallMessageHandler(myMessageOutput);, as they show in their main().

                  3. Place a VS debug breakpoint on case QtFatalMsg: (you may need to place it on the line after the case).

                  4. Run your app via "Start Debugging".

                  5. Optionally test that, say, an explicit qDebug() of your own does hit the installed handler (breakpoint on entry to function), to make sure all is correctly in place.

                  6. Cause a qFatal(), which may be either in your own code or in a Qt library, to get hit.

                  7. You should find you stop at the breakpoint, and can see the stacktrace?

                  8. Assuming that is working, you can now prune that function's code so that it has little other than a place you can breakpoint for type == QtFatalMsg, and in all cases calls the original handler at the end of the function.

                  A 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @Alain38-0
                    Then you are saying you do not agree with the documentation statement:

                    On Windows, for debug builds, this function will report a _CRT_ERROR enabling you to connect a debugger to the application

                    I cannot comment on that. But let's assume you're right. So I'm saying, to workaround for what you want please do the following:

                    1. From http://doc.qt.io/qt-5/qtglobal.html#qInstallMessageHandler copy & paste their myMessageOutput() function sample code into your application.

                    2. Install that as event handler somewhere via qInstallMessageHandler(myMessageOutput);, as they show in their main().

                    3. Place a VS debug breakpoint on case QtFatalMsg: (you may need to place it on the line after the case).

                    4. Run your app via "Start Debugging".

                    5. Optionally test that, say, an explicit qDebug() of your own does hit the installed handler (breakpoint on entry to function), to make sure all is correctly in place.

                    6. Cause a qFatal(), which may be either in your own code or in a Qt library, to get hit.

                    7. You should find you stop at the breakpoint, and can see the stacktrace?

                    8. Assuming that is working, you can now prune that function's code so that it has little other than a place you can breakpoint for type == QtFatalMsg, and in all cases calls the original handler at the end of the function.

                    A Offline
                    A Offline
                    Alain38 0
                    wrote on last edited by
                    #9

                    @JonB IN fact It is not that I do not agree with the documentation. It is just that I have an unexpected behavior. It can come from a lot of reasons. I can have somewhere a strange configuration (quite common with Windows). It might come from the fact I'm under QTest, so not in a normal situation (no running qApp), and so on.

                    For the moment I'm debugging by setting breakpoints in qGlobal (qt_assert and qt_assert_x). But as I'm managing several VS solutions I have to think to set them on each solution. It is why I hoped that someone already had the same problem.

                    JonBJ 1 Reply Last reply
                    0
                    • A Alain38 0

                      @JonB IN fact It is not that I do not agree with the documentation. It is just that I have an unexpected behavior. It can come from a lot of reasons. I can have somewhere a strange configuration (quite common with Windows). It might come from the fact I'm under QTest, so not in a normal situation (no running qApp), and so on.

                      For the moment I'm debugging by setting breakpoints in qGlobal (qt_assert and qt_assert_x). But as I'm managing several VS solutions I have to think to set them on each solution. It is why I hoped that someone already had the same problem.

                      JonBJ Online
                      JonBJ Online
                      JonB
                      wrote on last edited by
                      #10

                      @Alain38-0
                      I have no idea why you choose not to try what I have suggested. Up to you.

                      A 1 Reply Last reply
                      0
                      • JonBJ JonB

                        @Alain38-0
                        I have no idea why you choose not to try what I have suggested. Up to you.

                        A Offline
                        A Offline
                        Alain38 0
                        wrote on last edited by
                        #11

                        @JonB Do not misunderstand. I have not said that I will not try your solution. I have just explained my temporary approach that I'm currently using to find the origin of my crashes. For the future I will take time to investigate more with the hope to have a generic solution to apply on all my VS solutions.

                        1 Reply Last reply
                        1

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved