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. Get stack trace

Get stack trace

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 14.3k Views
  • 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.
  • K Offline
    K Offline
    kalay
    wrote on last edited by
    #1

    Hi.

    I have an error on my application, it doesn't crash, it just calls a function when it shouldn't, but this function is called from many places and I want to kwnow where is this function called, so I want to save the stack trace in a file.

    Is there any way to get the stack trace?

    Thanks.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      Hi and welcome to devnet.

      As often, that depends :-)
      If you are debugguing the application, you can just set a breakpoint.
      Otherwise it depends on the system you are on.

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kalay
        wrote on last edited by
        #3

        Hi Gerolf.

        I saw debuging tools in Qt creator are great!, but in this case I can't debug, it's an occasional error we can't reproduce any time we want, and it's a remote device and debuging does application go very slow and it needs to send frames in high frequency. I can execute my application compiled in debug mode.
        I would like to print stack trace like debuging does it.
        I'm using Linux (Debian 7.6).

        Thanks.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          AFAIK, that is not possible without instrumenting your application. A debugger would do that, but you could also create your own. It is a PITA though.

          We've build some code that we can use for similar cases. The idea is that you keep around a thread-global stack of function names. In every function that you wish to include in your stack, you make sure that at the start of that function (or scope, if you wish) you push the name of the function on to the stack, and you pop it off again on exit of the function. A RAII approach for making sure the pop actually happens is recommended.

          You'll need to put such a statement everywhere where you suspect code may pass that eventually leads to your wrong function call. At the location of the wrong function call, you can then dump the contents of the stack to a log file.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            giesbert
            wrote on last edited by
            #5

            It is possible go backtrace the stack but it's not trivial. I have an open issue here to do that, and IIRC googleing for linux backtrace stackwalk gave good results on that. But it's not a trivial thing....

            Nokia Certified Qt Specialist.
            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              Interesting. But it sounds like something that is really dependent on the compiler and its settings. It might work for some very specific cases, but AFAIK, there are no provisions for this kind of introspection anywhere in the C++ standard...

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Hi and welcome to devnet,

                What about inspecting it with "GammaRay":http://www.kdab.com/kdab-products/gammaray/ ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  kalay
                  wrote on last edited by
                  #8

                  Ok.

                  I'll create my own, using QVector/QList will be easy.

                  Thank you

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andre
                    wrote on last edited by
                    #9

                    Better use QStack as your basis, I'd say.

                    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