简体   繁体   中英

how to write my own function that prints back trace

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 own 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM