Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unw_cursor_t cursor; unw_context_t uc;
- unw_word_t ip, sp;
- unw_getcontext(&uc);
- unw_init_local(&cursor, &uc);
- unsigned long a[100];
- int ctr = 0;
- while (unw_step(&cursor) > 0) {
- unw_get_reg(&cursor, UNW_REG_IP, &ip);
- unw_get_reg(&cursor, UNW_REG_SP, &sp);
- if (ctr >= 10) break;
- a[ctr++] = ip;
- }
- #include <execinfo.h>
- #include <stdio.h>
- ...
- void* callstack[128];
- int i, frames = backtrace(callstack, 128);
- char** strs = backtrace_symbols(callstack, frames);
- for (i = 0; i < frames; ++i) {
- printf("%sn", strs[i]);
- }
- free(strs);
- ...
- class MyException : public std::exception {
- char ** strs;
- MyException( const std::string & message ) {
- int i, frames = backtrace(callstack, 128);
- strs = backtrace_symbols(callstack, frames);
- }
- void printStackTrace() {
- for (i = 0; i
- ...
- try {
- throw MyException("Oops!");
- } catch ( MyException e ) {
- e.printStackTrace();
- }
- -rdynamic
Add Comment
Please, Sign In to add comment