views:

249

answers:

4

Is the trickery way that we can show the entire stack trace (function+line) for an exception, much like in Java and C#, in C++?

Can we do something with macros to accomplish that for windows and linux-like platforms?

thanks

+2  A: 

Not without either platform specific knowledge or addition of code in each function.

AProgrammer
edited.........
vehomzzz
+2  A: 

On Windows it can be done using the Windows DbgHelp API, but to get it exactly right requires lots of experimenting and twiddling. See http://msdn.microsoft.com/en-us/library/ms679267(VS.85).aspx for a start. I have no idea how to implement it for other platforms.

Hope this helps a bit.

Regards,

Sebastiaan

Sebastiaan Megens
This article (http://www.codeproject.com/KB/debug/XCrashReportPt1.aspx) will help with using DbgHelp API.
Kirill V. Lyadvinsky
+1  A: 

If you are running on a platform which uses glibc, you can use the backtrace() functions. This are C functions, but they do work for c++ back traces too. This is of course not portable, but I doubt you will find a portable solution without additional code in every function ;-)

http://www.gnu.org/software/libc/manual/html_node/Backtraces.html

drhirsch