c++ stack trace from unhandled exception? -
have been asked before the question and given specific answers to windows but no satisfactory GCC has been no reply. I called a set of set_terminate ()
is I can use (the Close instead of
) when thrown an unused exception. How do I use the backtrace library to generate a stack trace from a point in the program? However, when my termination-replacement is called from that point, it will not help if the stack is useless.
However, if I allow the program to be abort ()
, then it will produce a core dump which contains the complete stack information from that point on which the exception is thrown I went. So the information is there - but is there a programmatic way to get it, for example, it can be logged instead of checking the original file?
Edit Answer:
You
#include & lt; Cstdlib & gt; You can use. # Include & lt; Iostream & gt; # Include & lt; Stdexcept & gt; # Include & lt; Execinfo.h & gt; Zero handler () {Zero * trace_elems [20]; Int trace_elem_count (backtrace (trace_elems, 20)); Char ** stack_syms (backtrace_smoles (trace_elems, trace_elem_count)); (Int i = 0; i
is giving this output:
samm @ macmini ~> K/akaut K/akaut [0x10000d20] /usr/lib/libsdk++ksok6 [0xf9bb8c8] /usr/lib/libsdk++ksok6 [0xf9bb90c] /usr/lib/libsdk++ksok6 [ 0xf9bbaa0] K/akaut [0x10000c18] K/akaut [0x10000c70] K/akaut [0x10000ca0] K/akaut [0x10000cdc] /lib/libsksok6 [0xfe4dd80] / lib / libc 6 [0xfe4dfc0] samjmill @ bgqfen4 ~ & gt;
Assume that embodies debug your binary, you can use addr2line to build a beautiful stack trace Postmartem
samm @ Macmini ~ & gt; ADR2 Line 0x10000C18 / Home / Smm / FUCCSISSM @ McMinni ~ & gt;
The basic answer is below
I got it backtrace
and backtrace
stack trace injection using An exception to which is thrown in execinfo.h
in the past.
typedef boost: error_info & lt; Struct tag_stack_st, std :: string & gt; Stack_info;
Then, while holding the exception, you can hold } (const std :: exception & amp; e) {if (std :: string Const * stack promotion :: get_error_info & lt; stack_error_info & gt; (e)) {std :: cout & lt; & Lt; Stack & lt; & Lt; Std :: endl; }}
Comments
Post a Comment