How to write a C function to print back trace till that function is called. I don't want to use any library.I would like to write my ow开发者_JS百科n code to do that job.
Can anyone please inputs to achieve this task?You can't write such a function in portable C, and you can't write it without knowing specific platform and calling conventions used by your compiler. Therefore your question (currently) lacks all the details one would need to answer it.
If you want to know how backtrace() works in general, you can study any number of implementations available.
If you want to implement one from scratch (homework?), study the calling convention for your platform.
There's no portable way to do this, but gcc provides a halfway-clean way to do it with __builtin_return_address
and friends.
精彩评论