Portable C++ Stack Trace on Exception

后端 未结 7 1348
轮回少年
轮回少年 2020-12-15 08:53

I am writing a library that I would like to be portable. Thus, it should not depend on glibc or Microsoft extensions or anything else that is not in the standard. I have a

7条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-15 09:39

    I don't think there's a "platform independent" way to do this - after all, if there was, there wouldn't be a need for StackWalk or the special gcc stack tracing features you mention.

    It would be a bit messy, but the way I would implement this would be to create a class that offers a consistent interface for accessing the stack trace, then have #ifdefs in the implementation that use the appropriate platform-specific methods to actually put the stack trace together.

    That way your usage of the class is platform independent, and just that class would need to be modified if you wanted to target some other platform.

提交回复
热议问题