Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exceptions stacktrace

Tags:

c++

What's the best way to implement an exception stack trace?

I found some kind of a solution using uncaught_exception() but it requires to add some code to every function.

I need something working on gcc under linux and windows

like image 381
f4. Avatar asked Dec 29 '22 05:12

f4.


2 Answers

I don't think there's a cross-platform way to do it. On windows, look at the StackWalk method; on linux, man backtrace. This will get the information; it's up to you to format it.

like image 126
Anne Avatar answered Dec 31 '22 18:12

Anne


I'm not sure that a reliable cross-platform method for unwinding the stack exists.

All the platforms/architectures that I've worked on have offered a way to walk the stack when an exception occurs and match addresses to function names. None of these are portable, but the reporting framework can written to be portable with the actual stack walking code remaining platform-specific (StackWalk on Windows or backtrace on Linux).

You might take a look at the libunwind project. I've never used or looked into this myself, so it may not be what you are looking for.

like image 42
jschmier Avatar answered Dec 31 '22 19:12

jschmier