Portable C++ Stack Trace on Exception

后端 未结 7 1344
轮回少年
轮回少年 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:31

    I think this is a really bad idea.

    Portability is a very worthy goal, but not when it results in a solution that is intrusive, performance-sapping, and an inferior implementation.

    Every platform (Windows/Linux/PS2/iPhone/etc) I've worked on has offered a way to walk the stack when an exception occurs and match addresses to function names. Yes, none of these are portable but the reporting framework can be and it usually takes less than a day or two to write a platform-specific version of stack walking code.

    Not only is this less time than it'd take creating/maintaining a cross-platform solution, but the results are far better;

    • No need to modify functions
    • Traps crashes in standard or third party libraries
    • No need for a try/catch in every function (slow and memory intensive)

提交回复
热议问题