-3

I need to print a call stack in log file in a running program (in C) as I need to check the flow, I have to send traces to other environment and I can't debug, Is there any way to do it in C.

user1773207
  • 61
  • 3
  • 9
  • 2
    You've provided no information here that can be used to help, and asked nothing specific. Without knowing what OS and compiler you're using, there's no information. As you've phrased it, an answer of "Yes, there's a way to do it in C" or "No, there's no way to do it in C" would be acceptable answers, which obviously would not be useful. If you want help here, you need to be much more specific about what you're asking, and provide more information about what environment you're using. The [FAQ](http://stackoverflow.com/faq) has some tips on how to ask better questions. – Ken White Mar 01 '13 at 03:36
  • [Possible duplicate](http://stackoverflow.com/q/2281739/968261). – Alexey Frunze Mar 01 '13 at 03:39

1 Answers1

1

If the platform is linux (and I believe in OSX too), you could use backtrace and backtrace_symbols to achieve what you want.

As per the notes section of backtrace

The symbol names may be unavailable without the use of special linker options. For systems using the GNU linker, it is necessary to use the -rdynamic linker option. Note that names of "static" functions are not exposed, and won't be available in the backtrace.

Tuxdude
  • 47,485
  • 15
  • 109
  • 110