开发者

how to write my own function that prints back trace

开发者 https://www.devze.com 2023-03-28 06:53 出处:网络
How to write a C function to print back trace till that function is called. I don\'t want to use any library.I wouldlike to write my ow开发者_JS百科n code to do that job.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号