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. Something about qt creator debug
Forum Updated to NodeBB v4.3 + New Features

Something about qt creator debug

Scheduled Pinned Locked Moved General and Desktop
12 Posts 4 Posters 6.7k 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.
  • H Offline
    H Offline
    henryxuv
    wrote on last edited by
    #1

    If I have a code like this
    @void testFun()
    {
    int result = add(a, b);
    }@
    The value of 'result' cannot be watched when debugging. the qt creator hint me , that the variable 'result' is out of scopt when the program run to the end of this function. Consider this situation, I have to add a meaningless sentence to keep the 'result' still in scope and watch the 'result' value. Is this gdb problem or qt creator. How can I resolve it? The same code in msvc, I can see the 'result' value no doubt. This is not convinient for debugg.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tobias.hunger
      wrote on last edited by
      #2

      It is most likely neither the fault of creator nor gdb: The compiler will be optimizing out the variable. I am surprised that MSVC is supposedly not doing this.

      Try disabling optimizations in your compiler. You can also add a Q_UNUSED(result); after line 3 to discourage the compiler from using this optimization.

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hardcodes.de
        wrote on last edited by
        #3

        Have you set a breakpoint in line 3? After leaving the function result is destroyed, there is nothing that can be watched afterwards.
        Or I do not get, what you really asked for ;-) And what is a and b?

        while(!sleep){++sheep;}

        1 Reply Last reply
        0
        • H Offline
          H Offline
          henryxuv
          wrote on last edited by
          #4

          Yes, you didn't get me . what is a and b is not the problem. the code I wrote is just a sample. The problem is , if a temporary variable declared at the end of a function. you will not able to watch the value of it when you debug the function in qt creator.

          [quote author="hardcodes.de" date="1368782030"]Have you set a breakpoint in line 3? After leaving the function result is destroyed, there is nothing that can be watched afterwards. Or I do not get, what you really asked for ;-) And what is a and b?[/quote]

          1 Reply Last reply
          0
          • H Offline
            H Offline
            henryxuv
            wrote on last edited by
            #5

            if my programe is released, the variable may be optimized out. But what I said is in debug mode, In my opinion , there is no optimization in debug mode. the macro Q_UNUSED doesn't work as I expected. I still can't watch the value of te variable at the end of function.

            [quote author="Tobias Hunger" date="1368782018"]It is most likely neither the fault of creator nor gdb: The compiler will be optimizing out the variable. I am surprised that MSVC is supposedly not doing this. Try disabling optimizations in your compiler. You can also add a Q_UNUSED(result); after line 3 to discourage the compiler from using this optimization.[/quote]

            1 Reply Last reply
            0
            • JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by
              #6

              I'm not sure what's going on with your GDB/Creator, but here's a different method you can try:
              @
              #include <QDebug>

              void testFun()
              {
              int result = add(a, b);
              qDebug() << result;
              }
              @

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply
              0
              • H Offline
                H Offline
                henryxuv
                wrote on last edited by
                #7

                Yes , qDebug is a good way. I want is not only a solution, I am interested in why this happen?

                [quote author="JKSH" date="1368789354"]I'm not sure what's going on with your GDB/Creator, but here's a different method you can try: @ #include <QDebug> void testFun() { int result = add(a, b); qDebug() << result; } @[/quote]

                1 Reply Last reply
                0
                • JKSHJ Offline
                  JKSHJ Offline
                  JKSH
                  Moderators
                  wrote on last edited by
                  #8

                  [quote author="henryxuv" date="1368789831"]Yes , qDebug is a good way. I want is not only a solution, I am interested in why this happen?[/quote]I don't know the answer; you'll have to ask someone else :) "Stack Overflow":http://stackoverflow.com/ is a good place to ask general software development questions. I think yours is a GDB issue, not a Qt Creator issue.

                  Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                  1 Reply Last reply
                  0
                  • H Offline
                    H Offline
                    hardcodes.de
                    wrote on last edited by
                    #9

                    Maybe if you dump the generated object file, you can reproduce if the lines are actually there or optimized away.

                    while(!sleep){++sheep;}

                    1 Reply Last reply
                    0
                    • H Offline
                      H Offline
                      henryxuv
                      wrote on last edited by
                      #10

                      You are right, the variable has been optimizated out. I try to disable the optimization, but failed. Could you tell me a way to do that, I check my qmake.conf file under qt\mkspecs\win32-g++ directory. (because my platform is winxp). the QMAKE_CFLAGS is empty. without any flags for optimization.

                      [quote author="Tobias Hunger" date="1368782018"]It is most likely neither the fault of creator nor gdb: The compiler will be optimizing out the variable. I am surprised that MSVC is supposedly not doing this. Try disabling optimizations in your compiler. You can also add a Q_UNUSED(result); after line 3 to discourage the compiler from using this optimization.[/quote]

                      1 Reply Last reply
                      0
                      • H Offline
                        H Offline
                        hardcodes.de
                        wrote on last edited by
                        #11

                        Maybe the volatile keyword can help here although I'm not sure that the creators of C++ had that in mind.

                        Just out of curiosity: what is the goal of the whole thing?

                        while(!sleep){++sheep;}

                        1 Reply Last reply
                        0
                        • H Offline
                          H Offline
                          henryxuv
                          wrote on last edited by
                          #12

                          When I wrote program with Qt Creator, I find the situation which never happened in MSVC. So I wonder why? For me, this is a opportunity to know Qt and it's tools in detail. So I try to figure out the reason. Thank for all of you to help me .Now I have got the reason.
                          [quote author="hardcodes.de" date="1369330298"]Maybe the volatile keyword can help here although I'm not sure that the creators of C++ had that in mind.

                          Just out of curiosity: what is the goal of the whole thing?[/quote]

                          1 Reply Last reply
                          0

                          • Login

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