Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Stack Trace [modified]

Stack Trace [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
csharpvisual-studiodata-structuresdebugginghelp
7 Posts 5 Posters 0 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.
  • B Offline
    B Offline
    baerten
    wrote on last edited by
    #1

    Hello everybody, is it possible to determine at realtime the function which has called the current function? Example

    void A(void)
    {
    DoWork();
    }

    void B(void)
    {
    DoWork();
    }

    void DoWork(void)
    {
    char *trace = GetTraceOf5LastFunction();
    OutputDebugString("DoWork called from function : ");
    OutputDebugString(trace);
    }

    Is it possible? Big thanks for any help :) Edit: I have found a fonction called "backtrace" which is placed into execinfo.h But i don't have a such header-file on my system (Visual Studio)

    modified on Tuesday, January 27, 2009 6:26 AM

    H L S 3 Replies Last reply
    0
    • B baerten

      Hello everybody, is it possible to determine at realtime the function which has called the current function? Example

      void A(void)
      {
      DoWork();
      }

      void B(void)
      {
      DoWork();
      }

      void DoWork(void)
      {
      char *trace = GetTraceOf5LastFunction();
      OutputDebugString("DoWork called from function : ");
      OutputDebugString(trace);
      }

      Is it possible? Big thanks for any help :) Edit: I have found a fonction called "backtrace" which is placed into execinfo.h But i don't have a such header-file on my system (Visual Studio)

      modified on Tuesday, January 27, 2009 6:26 AM

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

      Can you use of dll's you can load your functions of dll on the current function.

      Of one Essence is the human race thus has Creation put the base One Limb impacted is sufficient For all Others to feel the Mace (Saadi )

      B 1 Reply Last reply
      0
      • H Hamid Taebi

        Can you use of dll's you can load your functions of dll on the current function.

        Of one Essence is the human race thus has Creation put the base One Limb impacted is sufficient For all Others to feel the Mace (Saadi )

        B Offline
        B Offline
        baerten
        wrote on last edited by
        #3

        Is there a DLL which executes the work of backtracing?

        1 Reply Last reply
        0
        • B baerten

          Hello everybody, is it possible to determine at realtime the function which has called the current function? Example

          void A(void)
          {
          DoWork();
          }

          void B(void)
          {
          DoWork();
          }

          void DoWork(void)
          {
          char *trace = GetTraceOf5LastFunction();
          OutputDebugString("DoWork called from function : ");
          OutputDebugString(trace);
          }

          Is it possible? Big thanks for any help :) Edit: I have found a fonction called "backtrace" which is placed into execinfo.h But i don't have a such header-file on my system (Visual Studio)

          modified on Tuesday, January 27, 2009 6:26 AM

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Hi, the easiest way may well be the low-tech one: add a string parameter to the function, and pass the caller's name. That works no matter what. DoWork("A"); :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


          modified on Tuesday, January 27, 2009 8:10 AM

          B 1 Reply Last reply
          0
          • L Luc Pattyn

            Hi, the easiest way may well be the low-tech one: add a string parameter to the function, and pass the caller's name. That works no matter what. DoWork("A"); :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


            modified on Tuesday, January 27, 2009 8:10 AM

            B Offline
            B Offline
            baerten
            wrote on last edited by
            #5

            This method is the simplest, but i can't write over 100 Debug-Lines into the code :-) But thanks anyway ;)

            L 1 Reply Last reply
            0
            • B baerten

              Hello everybody, is it possible to determine at realtime the function which has called the current function? Example

              void A(void)
              {
              DoWork();
              }

              void B(void)
              {
              DoWork();
              }

              void DoWork(void)
              {
              char *trace = GetTraceOf5LastFunction();
              OutputDebugString("DoWork called from function : ");
              OutputDebugString(trace);
              }

              Is it possible? Big thanks for any help :) Edit: I have found a fonction called "backtrace" which is placed into execinfo.h But i don't have a such header-file on my system (Visual Studio)

              modified on Tuesday, January 27, 2009 6:26 AM

              S Offline
              S Offline
              Stuart Dootson
              wrote on last edited by
              #6

              You need a stack walking function. Here are some[^] links[^] that may be useful. The second is probably best - John Robbins is a well regarded expert on debugging and things like that. His SUPERASSERT code includes stack tracing code - see the dialog screenshot about half way through the article for an example of what you can get. Obviously you only need the last item in the trace. One last thing - IIRC, without debug symbols, all you're going to get is the address that called you, not a function name.

              1 Reply Last reply
              0
              • B baerten

                This method is the simplest, but i can't write over 100 Debug-Lines into the code :-) But thanks anyway ;)

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Hi baerten, I agree with Luc. However you may be able to use a pre-defined macro[^] something like below:VOID FunctionB(int iVal,char *caller,int line) { char szBuf[MAX_PATH]; sprintf(szBuf,"I was called by %s on line %d",caller,line); MessageBoxA(NULL,szBuf,0,0); } VOID FunctionA() { FunctionB(1,__FUNCTION__,__LINE__); }

                baerten wrote:

                i can't write over 100 Debug-Lines into the code

                A stack trace is several times more expensive at runtime. Best Wishes, -David Delaune

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups