title: Printing the contents of the program stack (C Language)
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/105659/how-can-one-grab-a-stack-trace-in-c">How can one grab a stack trace in C?</a>  </p>
  </blockquote>
  
  
  
  <p>Hi,</p>
  
  <p>I would like to know how to print the contents of the current program stack (using C language). </p>
  
  <p>say for eg.</p>
  
  <pre><code>    call_some_function() 
  {
      ...
      ...
             print_stack_till_now();
      return something;
      }
  
      call_some_other_function() 
  {
      ...
      ...
             print_stack_till_now();
      return something;
      }
  
      main()
      {
         print_stack_till_now();
         call_some_function();
         print_stack_till_now();
         call_some_other_function();
         print_stack_till_now();
  
         return 0;
      }
  </code></pre>
  
  <p>In the prev example (may be not an example exactly :)) when I call the print_stack_till_now() function I should be able to print the current stack built till that point (including the newer function call entries, return location, their arguments etc.) </p>
  
  <p>Is such a function possible in C language (even inlined assembly). Please point me to the theory (or existing code would be even better) needed to write such a function. </p>
  
  <p>In gdb we can use backtrace to look at the current stack, I'm looking for something similar. Why do I need this ?... just wanted to learn.</p>
  
  <p>Thank you.</p>