这篇教程C++ unw_init_local函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中unw_init_local函数的典型用法代码示例。如果您正苦于以下问题:C++ unw_init_local函数的具体用法?C++ unw_init_local怎么用?C++ unw_init_local使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了unw_init_local函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: dwarf_backtraceint dwarf_backtrace(CallStack **returnStack) { *returnStack = calloc(1, sizeof(CallStack)); CallStack *callStack = *returnStack; callStack->stack = calloc(INITIAL_LIVE_FUNCTION_SIZE, sizeof(LiveFunction)); callStack->count = 0; callStack->capacity = INITIAL_LIVE_FUNCTION_SIZE; unw_cursor_t cursor; unw_context_t uc; unw_word_t ip, sp; unw_getcontext(&uc); unw_init_local(&cursor, &uc); while (unw_step(&cursor) > 0) { unw_get_reg(&cursor, UNW_REG_IP, &ip); unw_get_reg(&cursor, UNW_REG_SP, &sp); if (callStack->count >= callStack->capacity) { callStack->capacity *= 2; callStack->stack = realloc(callStack->stack, callStack->capacity * sizeof(LiveFunction *)); } callStack->stack[callStack->count].cursor = cursor; callStack->stack[callStack->count].pc = (void *)ip; callStack->stack[callStack->count].sp = (void *)sp; printf("%p => %p/n", (void *)ip, (void *)sp); callStack->count++; } return callStack->count;}
开发者ID:alexanderkyte,项目名称:Bug-Collector,代码行数:33,
示例2: fakegcvoid fakegc(){ std::cout << "GC/n"; unw_cursor_t cursor; unw_word_t ip, sp; unw_context_t uc; root_info_t root_info_ptr; unw_getcontext(&uc); unw_init_local(&cursor, &uc); do { unw_get_reg(&cursor, UNW_REG_IP, &ip); unw_get_reg(&cursor, UNW_REG_SP, &sp); // printf("ip=%p sp=%p/n", ip, sp); if (stk_map.find_root_info((void*)ip, root_info_ptr)) { for(auto it : root_info_ptr) { int *cptr = *((int**)sp - it); printf("x=%p/n", cptr); printf("i=%d/n", *cptr); *cptr = *cptr + 1; } } } while (unw_step(&cursor) > 0);}
开发者ID:scottgw,项目名称:quicksilver,代码行数:29,
示例3: getCurrentStackTraceint getCurrentStackTrace(size_t skip, StackTrace* trace) { trace->frameIPs = NULL; trace->frameCount = 0; struct Context ctx; ctx.trace = trace; ctx.skip = skip; ctx.capacity = 0; unw_context_t uctx; int r = unw_getcontext(&uctx); int err = checkError("unw_get_context", r); if (err) return err; unw_cursor_t cursor; r = unw_init_local(&cursor, &uctx); err = checkError("unw_init_local", r); if (err) return err; while ((r = unw_step(&cursor)) > 0) { if ((err = addIP(&ctx, &cursor)) != 0) { destroyStackTrace(trace); return err; } } err = checkError("unw_step", r); if (err) return err; return 0;}
开发者ID:Andymic,项目名称:folly,代码行数:30,
示例4: _adjust_stack_pre_safepointstatic void _adjust_stack_pre_safepoint(hlt_execution_context* ctx){ // Climb up the stack and adjust the reference counts for live objects // referenced there so that it reflects reality. unw_cursor_t cursor; unw_context_t uc; unw_word_t ip, sp; unw_getcontext(&uc); unw_init_local(&cursor, &uc); int level = 0; while ( unw_step(&cursor) > 0 ) { unw_get_reg(&cursor, UNW_REG_IP, &ip); unw_get_reg(&cursor, UNW_REG_SP, &sp); printf("level = %d ip = %lx, sp = %lx/n", level, (long)ip, (long)sp); level++; }#ifdef DEBUG// DBG_LOG("hilti-mem", "%10s stack-adjust-ctor %p %d %s::%s = %s", obj, level, func, id, render);#endif}
开发者ID:rsmmr,项目名称:hilti,代码行数:25,
示例5: slow_backtracestatic ALWAYS_INLINE intslow_backtrace (void **buffer, int size, unw_context_t *uc, int skip){ unw_cursor_t cursor; unw_word_t ip; int n = 0; if (unlikely (unw_init_local (&cursor, uc) < 0)) return 0; while (unw_step (&cursor) > 0) { if (n >= size) return n; if (unw_get_reg (&cursor, UNW_REG_IP, &ip) < 0) return n; if (skip > 0) skip--; else buffer[n++] = (void *) (uintptr_t) ip; } return n;}
开发者ID:Daft-Freak,项目名称:vogl,代码行数:25,
示例6: handler static void handler(int sig) { unw_context_t context; unw_getcontext(&context); unw_cursor_t cursor; unw_init_local(&cursor, &context); SkDebugf("/nSignal %d:/n", sig); while (unw_step(&cursor) > 0) { static const size_t kMax = 256; char mangled[kMax], demangled[kMax]; unw_word_t offset; unw_get_proc_name(&cursor, mangled, kMax, &offset); int ok; size_t len = kMax; abi::__cxa_demangle(mangled, demangled, &len, &ok); SkDebugf("%s (+0x%zx)/n", ok == 0 ? demangled : mangled, (size_t)offset); } SkDebugf("/n"); // Exit NOW. Don't notify other threads, don't call anything registered with atexit(). _Exit(sig); }
开发者ID:BertiKarsunke,项目名称:skia,代码行数:25,
示例7: Extrae_get_callerUINT64 Extrae_get_caller (int offset){ int current_deep = 0; unw_cursor_t cursor; unw_context_t uc; unw_word_t ip; if (unw_getcontext(&uc) < 0) return 0; if (unw_init_local(&cursor, &uc)) return 0; offset --; /* Don't compute call to unw_getcontext */ while (current_deep <= offset) { if (unw_get_reg(&cursor, UNW_REG_IP, &ip) < 0) break;#if defined(DEBUG) fprintf (stderr, "DEBUG: offset %d depth %d address %08llx %c/n", offset, current_deep, ip, (offset == current_deep)?'*':' ');#endif if (unw_step (&cursor) <= 0) return 0; current_deep ++; } return (UINT64) ip;}
开发者ID:gllort,项目名称:extrae,代码行数:28,
示例8: findRealErrorOnStackstatic void findRealErrorOnStack (ShockerScriptableControlObject* obj) { unw_context_t uc; unw_cursor_t cursor, prev; unw_word_t bp; unw_getcontext(&uc); unw_init_local(&cursor, &uc); char framename [1024]; int count = 0; while (unw_step(&cursor) > 0 && count < 18) { count++; unw_get_proc_name (&cursor, framename, sizeof(framename), 0); if (!*framename) continue; if (strstr (framename, "js_ReportErrorAgain")) {#if (__i386__) unw_get_reg(&prev, UNW_X86_EBP, &bp);#elif (__amd64__) unw_get_reg(&prev, UNW_X86_64_RBP, &bp);#endif bp += 12; char ** n = (char**)bp; obj->GetLogProvider ()->LogError (*n); break; } prev = cursor; }}
开发者ID:499940913,项目名称:moon,代码行数:30,
示例9: xbt_libunwind_backtraceint xbt_libunwind_backtrace(void** bt, int size){ int i = 0; for(i=0; i < size; i++) bt[i] = nullptr; i=0; unw_cursor_t c; unw_context_t uc; unw_getcontext (&uc); unw_init_local (&c, &uc); unw_word_t ip; unw_step(&c); while(unw_step(&c) >= 0 && i < size){ unw_get_reg(&c, UNW_REG_IP, &ip); bt[i] = (void*)(long)ip; i++; } return i;}
开发者ID:fabienchaix,项目名称:simgrid,代码行数:25,
示例10: backtracevoid backtrace() { unw_cursor_t cursor; unw_context_t context; // Initialize cursor to current frame for local unwinding. unw_getcontext(&context); unw_init_local(&cursor, &context); // Unwind frames one by one, going up the frame stack. while (unw_step(&cursor) > 0) { unw_word_t offset, pc; unw_get_reg(&cursor, UNW_REG_IP, &pc); if (pc == 0) { break; } printf("0x%lx:", pc); char sym[256]; if (unw_get_proc_name(&cursor, sym, sizeof(sym), &offset) == 0) { char* nameptr = sym; int status; char* demangled = abi::__cxa_demangle(sym, nullptr, nullptr, &status); if (status == 0) { nameptr = demangled; } char file[256]; int line = 0; getFileAndLine((long)pc, file, 256, &line); printf(" (%s+0x%lx) in %s:%d/n", nameptr, offset, file, line); free(demangled); } else { printf(" -- error: unable to obtain symbol name for this frame/n"); } }}
开发者ID:stelonix,项目名称:tmpgl,代码行数:35,
示例11: getStackTraceSafessize_t getStackTraceSafe(uintptr_t* addresses, size_t maxAddresses) { if (maxAddresses == 0) { return 0; } unw_context_t context; if (unw_getcontext(&context) < 0) { return -1; } unw_cursor_t cursor; if (unw_init_local(&cursor, &context) < 0) { return -1; } if (!getFrameInfo(&cursor, *addresses)) { return -1; } ++addresses; size_t count = 1; for (; count != maxAddresses; ++count, ++addresses) { int r = unw_step(&cursor); if (r < 0) { return -1; } if (r == 0) { break; } if (!getFrameInfo(&cursor, *addresses)) { return -1; } } return count;}
开发者ID:191919,项目名称:folly,代码行数:31,
示例12: InitializeUnwindContextAndCursor// Initialize unw_cursor_t and unw_context_t from REGDISPLAYbool InitializeUnwindContextAndCursor(REGDISPLAY* regDisplay, unw_cursor_t* cursor, unw_context_t* unwContext){#ifndef CAN_LINK_SHARED_LIBUNWIND return false;#else // CAN_LINK_SHARED_LIBUNWIND int st;#if !UNWIND_CONTEXT_IS_UCONTEXT_T st = unw_getcontext(unwContext); if (st < 0) { return false; }#endif RegDisplayToUnwindContext(regDisplay, unwContext); st = unw_init_local(cursor, unwContext); if (st < 0) { return false; }#if !UNWIND_CONTEXT_IS_UCONTEXT_T // Set the unwind context to the specified windows context RegDisplayToUnwindCursor(regDisplay, cursor);#endif return true;#endif // CAN_LINK_SHARED_LIBUNWIND}
开发者ID:OceanYan,项目名称:corert,代码行数:32,
示例13: print_tracestatic voidprint_trace (void){#ifdef HAVE_LIBUNWIND unw_context_t uc; unw_cursor_t cursor; guint stack_num = 0; if (!display_filter (DISPLAY_FLAG_BACKTRACE)) return; unw_getcontext (&uc); unw_init_local (&cursor, &uc); while (unw_step (&cursor) > 0) { gchar name[129]; unw_word_t off; int result; result = unw_get_proc_name (&cursor, name, sizeof (name) - 1, &off); if (result < 0 && result != UNW_ENOMEM) { g_print ("Error getting proc name/n"); break; } g_print ("#%d %s + [0x%08x]/n", stack_num++, name, (unsigned int)off); }}
开发者ID:matze,项目名称:gobject-list,代码行数:30,
示例14: ut_dump_backtrace/* * ut_dump_backtrace -- dump stacktrace to error log using libunwind */voidut_dump_backtrace(void){ unw_context_t context; unw_proc_info_t pip; pip.unwind_info = NULL; int ret = unw_getcontext(&context); if (ret) { ERR("unw_getcontext: %s [%d]", unw_strerror(ret), ret); return; } unw_cursor_t cursor; ret = unw_init_local(&cursor, &context); if (ret) { ERR("unw_init_local: %s [%d]", unw_strerror(ret), ret); return; } ret = unw_step(&cursor); char procname[PROCNAMELEN]; unsigned i = 0; while (ret > 0) { ret = unw_get_proc_info(&cursor, &pip); if (ret) { ERR("unw_get_proc_info: %s [%d]", unw_strerror(ret), ret); break; } unw_word_t off; ret = unw_get_proc_name(&cursor, procname, PROCNAMELEN, &off); if (ret && ret != -UNW_ENOMEM) { if (ret != -UNW_EUNSPEC) { ERR("unw_get_proc_name: %s [%d]", unw_strerror(ret), ret); } strcpy(procname, "?"); } void *ptr = (void *)(pip.start_ip + off); Dl_info dlinfo; const char *fname = "?"; if (dladdr(ptr, &dlinfo) && dlinfo.dli_fname && *dlinfo.dli_fname) fname = dlinfo.dli_fname; ERR("%u: %s (%s%s+0x%lx) [%p]", i++, fname, procname, ret == -UNW_ENOMEM ? "..." : "", off, ptr); ret = unw_step(&cursor); if (ret < 0) ERR("unw_step: %s [%d]", unw_strerror(ret), ret); }}
开发者ID:Skyprophet,项目名称:peloton,代码行数:63,
示例15: unw_getcontextvoid VSDebugLib::printStack() { unw_cursor_t cursor; unw_context_t uc; unw_word_t ip, sp, off; unw_proc_info_t pi; char file[256], name[256]; int line; int status; unw_getcontext(&uc); unw_init_local(&cursor, &uc); while (unw_step(&cursor) > 0) { unw_get_reg(&cursor, UNW_REG_IP, &ip); unw_get_reg(&cursor, UNW_REG_SP, &sp); unw_get_proc_name (&cursor, name, sizeof (name), &off); getFileAndLine((long)ip, file, 256, &line); if (line >= 0) { char *realname; realname = abi::__cxa_demangle(name, 0, 0, &status); if (realname) { printf("%s: %s, %d/n", realname, file, line); free(realname); } else { printf("%s: %s, %d/n", name, file, line); } } }}
开发者ID:ArturSoczek,项目名称:OpenGLInsightsCode,代码行数:32,
示例16: throw_exceptionstatic voidthrow_exception (MonoObject *exc, guint64 rethrow){ unw_context_t unw_ctx; MonoContext ctx; MonoJitInfo *ji; unw_word_t ip, sp; int res; if (mono_object_isinst (exc, mono_defaults.exception_class)) { MonoException *mono_ex = (MonoException*)exc; if (!rethrow) { mono_ex->stack_trace = NULL; mono_ex->trace_ips = NULL; } } res = unw_getcontext (&unw_ctx); g_assert (res == 0); res = unw_init_local (&ctx.cursor, &unw_ctx); g_assert (res == 0); /* * Unwind until the first managed frame. This is needed since * mono_handle_exception expects the variables in the original context to * correspond to the method returned by mono_find_jit_info. */ while (TRUE) { res = unw_get_reg (&ctx.cursor, UNW_IA64_IP, &ip); g_assert (res == 0); res = unw_get_reg (&ctx.cursor, UNW_IA64_SP, &sp); g_assert (res == 0); ji = mini_jit_info_table_find (mono_domain_get (), (gpointer)ip, NULL); //printf ("UN: %s %lx %lx/n", ji ? jinfo_get_method (ji)->name : "", ip, sp); if (ji) break; res = unw_step (&ctx.cursor); if (res == 0) { /* * This means an unhandled exception during the compilation of a * topmost method like Main */ break; } g_assert (res >= 0); } ctx.precise_ip = FALSE; mono_handle_exception (&ctx, exc); restore_context (&ctx); g_assert_not_reached ();}
开发者ID:red-gate,项目名称:mono,代码行数:59,
示例17: collectStackRootsvoid collectStackRoots(TraceStack *stack) { unw_cursor_t cursor; unw_context_t uc; unw_word_t ip, sp, bp; // force callee-save registers onto the stack: // Actually, I feel like this is pretty brittle: // collectStackRoots itself is allowed to save the callee-save registers // on its own stack. jmp_buf registers __attribute__((aligned(sizeof(void*))));#ifdef VALGRIND memset(®isters, 0, sizeof(registers)); memset(&cursor, 0, sizeof(cursor)); memset(&uc, 0, sizeof(uc)); memset(&ip, 0, sizeof(ip)); memset(&sp, 0, sizeof(sp)); memset(&bp, 0, sizeof(bp));#endif setjmp(registers); assert(sizeof(registers) % 8 == 0); //void* stack_bottom = __builtin_frame_address(0); collectRoots(®isters, ®isters + 1, stack); unw_getcontext(&uc); unw_init_local(&cursor, &uc); TraceStackGCVisitor visitor(stack); int code; while (true) { int code = unw_step(&cursor); assert(code > 0 && "something broke unwinding!"); unw_get_reg(&cursor, UNW_REG_IP, &ip); unw_get_reg(&cursor, UNW_REG_SP, &sp); unw_get_reg(&cursor, UNW_TDEP_BP, &bp); void* cur_sp = (void*)sp; void* cur_bp = (void*)bp; //std::string name = g.func_addr_registry.getFuncNameAtAddress((void*)ip, true); //if (VERBOSITY()) printf("ip = %lx (%s), stack = [%p, %p)/n", (long) ip, name.c_str(), cur_sp, cur_bp); unw_proc_info_t pip; unw_get_proc_info(&cursor, &pip); if (pip.start_ip == (uintptr_t)&__libc_start_main) { break; } if (pip.start_ip == (intptr_t)interpretFunction) { // TODO Do we still need to crawl the interpreter itself? gatherInterpreterRootsForFrame(&visitor, cur_bp); } collectRoots(cur_sp, (char*)cur_bp, stack); }}
开发者ID:Bassem450,项目名称:pyston,代码行数:59,
示例18: luw_backtracestatic void luw_backtrace(){ unw_cursor_t cursor; unw_context_t context; unw_getcontext(&context); unw_init_local(&cursor, &context); std::stringstream output; output << "Traceback (most recent call first):" << std::endl; while (unw_step(&cursor) > 0) { unw_word_t pc; unw_get_reg(&cursor, UNW_REG_IP, &pc); if (pc == 0) break; const char *file = NULL; const char *func = NULL; unsigned line = 0; resolve(pc, &file, &line, &func); if (file != NULL) { if (strcmp("__cxa_throw", func) == 0) continue; if (strncmp(func, "_Z", 2) == 0) { // This is a C++ mangled name (as per the IA-64 spec) output << " 0x" << std::hex << pc << std::dec << " " << demangle(func) << " (" << file << ":" << line << ")" << std::endl; } else { output << " 0x" << std::hex << pc << std::dec << " " << func << " (" << file << ":" << line << ")" << std::endl; } // Try to load the file and print the offending line std::ifstream f; f.open(file); if (!f.is_open()) { output << " <unable to find file>" << std::endl; } else { seek_to_line(f, line); std::string line; std::getline(f, line); output << " " << line << std::endl; } } else { output << " <unknown> (<unknown file>:<unknown line>)" << std::endl; } } output << std::endl; __latest_backtrace = output.str();}
开发者ID:svkampen,项目名称:netamphetamine,代码行数:58,
示例19: unw_init_localbool UnwindCurrent::UnwindFromContext(size_t num_ignore_frames, bool resolve) { // The cursor structure is pretty large, do not put it on the stack. unw_cursor_t* cursor = new unw_cursor_t; int ret = unw_init_local(cursor, &context_); if (ret < 0) { BACK_LOGW("unw_init_local failed %d", ret); delete cursor; return false; } std::vector<backtrace_frame_data_t>* frames = GetFrames(); frames->reserve(MAX_BACKTRACE_FRAMES); size_t num_frames = 0; do { unw_word_t pc; ret = unw_get_reg(cursor, UNW_REG_IP, &pc); if (ret < 0) { BACK_LOGW("Failed to read IP %d", ret); break; } unw_word_t sp; ret = unw_get_reg(cursor, UNW_REG_SP, &sp); if (ret < 0) { BACK_LOGW("Failed to read SP %d", ret); break; } if (num_ignore_frames == 0) { frames->resize(num_frames+1); backtrace_frame_data_t* frame = &frames->at(num_frames); frame->num = num_frames; frame->pc = static_cast<uintptr_t>(pc); frame->sp = static_cast<uintptr_t>(sp); frame->stack_size = 0; if (num_frames > 0) { // Set the stack size for the previous frame. backtrace_frame_data_t* prev = &frames->at(num_frames-1); prev->stack_size = frame->sp - prev->sp; } if (resolve) { frame->func_name = GetFunctionName(frame->pc, &frame->func_offset); frame->map = FindMap(frame->pc); } else { frame->map = NULL; frame->func_offset = 0; } num_frames++; } else { num_ignore_frames--; } ret = unw_step (cursor); } while (ret > 0 && num_frames < MAX_BACKTRACE_FRAMES); delete cursor; return true;}
开发者ID:Caxuyc,项目名称:platform_system_core,代码行数:58,
示例20: backtraceintbacktrace(void **trace, int size){ unw_cursor_t cursor; unw_context_t uc; unw_word_t ip; int n = 0; unw_getcontext(&uc); unw_init_local(&cursor, &uc); while (unw_step(&cursor) > 0) { unw_get_reg(&cursor, UNW_REG_IP, &ip); trace[n++] = (void *)ip; { char buf[256]; unw_get_proc_name(&cursor, buf, 256, &ip); if (strncmp("_sigtramp", buf, sizeof("_sigtramp")) == 0) { goto darwin_sigtramp; } } } return n;darwin_sigtramp: /* darwin's bundled libunwind doesn't support signal trampoline */ { ucontext_t *uctx; /* get _sigtramp's ucontext_t and set values to cursor * http://www.opensource.apple.com/source/Libc/Libc-825.25/i386/sys/_sigtramp.s * http://www.opensource.apple.com/source/libunwind/libunwind-35.1/src/unw_getcontext.s */ unw_get_reg(&cursor, UNW_X86_64_RBX, &ip); uctx = (ucontext_t *)ip; unw_set_reg(&cursor, UNW_X86_64_RAX, uctx->uc_mcontext->__ss.__rax); unw_set_reg(&cursor, UNW_X86_64_RBX, uctx->uc_mcontext->__ss.__rbx); unw_set_reg(&cursor, UNW_X86_64_RCX, uctx->uc_mcontext->__ss.__rcx); unw_set_reg(&cursor, UNW_X86_64_RDX, uctx->uc_mcontext->__ss.__rdx); unw_set_reg(&cursor, UNW_X86_64_RDI, uctx->uc_mcontext->__ss.__rdi); unw_set_reg(&cursor, UNW_X86_64_RSI, uctx->uc_mcontext->__ss.__rsi); unw_set_reg(&cursor, UNW_X86_64_RBP, uctx->uc_mcontext->__ss.__rbp); unw_set_reg(&cursor, UNW_X86_64_RSP, 8+(uctx->uc_mcontext->__ss.__rsp)); unw_set_reg(&cursor, UNW_X86_64_R8, uctx->uc_mcontext->__ss.__r8); unw_set_reg(&cursor, UNW_X86_64_R9, uctx->uc_mcontext->__ss.__r9); unw_set_reg(&cursor, UNW_X86_64_R10, uctx->uc_mcontext->__ss.__r10); unw_set_reg(&cursor, UNW_X86_64_R11, uctx->uc_mcontext->__ss.__r11); unw_set_reg(&cursor, UNW_X86_64_R12, uctx->uc_mcontext->__ss.__r12); unw_set_reg(&cursor, UNW_X86_64_R13, uctx->uc_mcontext->__ss.__r13); unw_set_reg(&cursor, UNW_X86_64_R14, uctx->uc_mcontext->__ss.__r14); unw_set_reg(&cursor, UNW_X86_64_R15, uctx->uc_mcontext->__ss.__r15); ip = *(unw_word_t*)uctx->uc_mcontext->__ss.__rsp; unw_set_reg(&cursor, UNW_REG_IP, ip); trace[n++] = (void *)uctx->uc_mcontext->__ss.__rip; trace[n++] = (void *)ip; } while (unw_step(&cursor) > 0) { unw_get_reg(&cursor, UNW_REG_IP, &ip); trace[n++] = (void *)ip; } return n;}
开发者ID:sho-h,项目名称:ruby,代码行数:58,
示例21: jffi_longjmpvoidjffi_longjmp (jmp_buf env, int val){ extern int _jffi_longjmp_cont; unw_context_t uc; unw_cursor_t c; unw_word_t sp, ip, bp = 0; uintptr_t *wp = (uintptr_t *) env; int i, setjmp_frame; if (unw_getcontext (&uc) < 0 || unw_init_local (&c, &uc) < 0) { debug("failed to get context"); abort (); }#ifdef __x86_86__# define UNW_REG_BP UNW_X86_64_RBP#else# define UNW_REG_BP UNW_X86_EBP#endif setjmp_frame = 0; do { char name[256]; unw_proc_info_t pi; unw_word_t off; if (unw_get_reg (&c, UNW_REG_BP, &bp) < 0) { abort(); } if (unw_get_reg (&c, UNW_REG_SP, &sp) < 0) { abort(); } if (unw_get_reg (&c, UNW_REG_IP, &ip) < 0) { abort(); } unw_get_proc_name(&c, name, sizeof(name), &off); unw_get_proc_info(&c, &pi);// debug("frame %s ip=%llx sp=%llx bp=%llx wp[RP]=%p wp[SP]=%p, pi.start_ip=%llx, pi.end_ip=%llx",// name, (long long) ip, (long long) sp, (long long) bp, (void *) wp[JB_RP], (void *) wp[JB_SP],// pi.start_ip, pi.end_ip); if (wp[JB_SP] > sp || wp[JB_RP] < pi.start_ip || wp[JB_RP] > pi.end_ip) continue; /* found the right frame: */// debug("found frame to jump back to"); assert (UNW_NUM_EH_REGS >= 2); if (unw_set_reg (&c, UNW_REG_EH + 0, wp[JB_RP]) < 0 || unw_set_reg (&c, UNW_REG_EH + 1, val) < 0 || unw_set_reg (&c, UNW_REG_IP, (unw_word_t) (uintptr_t) &_jffi_longjmp_cont)) abort (); unw_resume (&c); // should not reach here abort (); } while (unw_step (&c) > 0);// debug("failed to find correct frame to jmp to");}
开发者ID:aaronbartell,项目名称:jffi,代码行数:56,
示例22: log_stack_tracevoid log_stack_trace(const char *msg){#ifdef USE_UNWIND unw_context_t ctx; unw_cursor_t cur; unw_word_t ip, off; unsigned level; char sym[512], *dsym; int status; const char *log = stack_trace_log.empty() ? NULL : stack_trace_log.c_str();#endif if (msg) ST_LOG(msg); ST_LOG("Unwound call stack:");#ifdef USE_UNWIND if (unw_getcontext(&ctx) < 0) { ST_LOG("Failed to create unwind context"); return; } if (unw_init_local(&cur, &ctx) < 0) { ST_LOG("Failed to find the first unwind frame"); return; } for (level = 1; level < 999; ++level) { // 999 for safety int ret = unw_step(&cur); if (ret < 0) { ST_LOG("Failed to find the next frame"); return; } if (ret == 0) break; if (unw_get_reg(&cur, UNW_REG_IP, &ip) < 0) { ST_LOG(" " << std::setw(4) << level); continue; } if (unw_get_proc_name(&cur, sym, sizeof(sym), &off) < 0) { ST_LOG(" " << std::setw(4) << level << std::setbase(16) << std::setw(20) << "0x" << ip); continue; } dsym = abi::__cxa_demangle(sym, NULL, NULL, &status); ST_LOG(" " << std::setw(4) << level << std::setbase(16) << std::setw(20) << "0x" << ip << " " << (!status && dsym ? dsym : sym) << " + " << "0x" << off); free(dsym); }#else std::stringstream ss; ss << el::base::debug::StackTrace(); std::vector<std::string> lines; std::string s = ss.str(); boost::split(lines, s, boost::is_any_of("/n")); for (const auto &line: lines) ST_LOG(line);#endif}
开发者ID:monero-project,项目名称:bitmonero,代码行数:55,
示例23: AS_UTL_catchCrashvoidAS_UTL_catchCrash(int sig_num, siginfo_t *info, void *ctx) { WRITE_STRING("/nFailed with '"); WRITE_STRING(strsignal(sig_num)); WRITE_STRING("'/n"); WRITE_STRING("/nBacktrace (mangled):/n/n"); unw_cursor_t cursor; unw_context_t uc; unw_word_t ip, sp; int depth = 0; unw_getcontext(&uc); // Get state unw_init_local(&cursor, &uc); // Initialize state cursor while (unw_step(&cursor) > 0) { unw_get_reg(&cursor, UNW_REG_IP, &ip); unw_get_reg(&cursor, UNW_REG_SP, &sp); unw_word_t off; char name[256]; if (unw_get_proc_name (&cursor, name, sizeof (name), &off) == 0) { if (off) fprintf(stderr, "%02d <%s + 0x%lx> ip=%lx sp=%lx/n", depth, name, (long)off, ip, sp); else fprintf(stderr, "%02d <%s> ip=%lx sp=%lx/n", depth, name, ip, sp); } else { fprintf(stderr, "%02d <?> ip=%lx sp=%lx/n", depth, ip, sp); } depth++; } //WRITE_STRING("/nBacktrace (demangled):/n/n"); //WRITE_STRING("/nGDB:/n/n"); //AS_UTL_envokeGDB(); // Pass the signal through, only so a core file can get generated. struct sigaction sa; sa.sa_handler = SIG_DFL; sigemptyset (&sa.sa_mask); sa.sa_flags = 0; sigaction(sig_num, &sa, NULL); raise(sig_num);}
开发者ID:cdunn2001,项目名称:DConvert,代码行数:53,
示例24: mainint main(int argc, char** argv){ SIMIX_global_init(&argc, argv); simgrid::mc::Variable* var; simgrid::mc::Type* type; simgrid::mc::Process process(getpid(), -1); process.init(); test_global_variable(process, process.binary_info.get(), "some_local_variable", &some_local_variable, sizeof(int)); var = test_global_variable(process, process.binary_info.get(), "test_some_array", &test_some_array, sizeof(test_some_array)); auto i = process.binary_info->types.find(var->type_id); xbt_assert(i != process.binary_info->types.end(), "Missing type"); type = &i->second; xbt_assert(type->element_count == 6*5*4, "element_count mismatch in test_some_array : %i / %i", type->element_count, 6*5*4); var = test_global_variable(process, process.binary_info.get(), "test_some_struct", &test_some_struct, sizeof(test_some_struct)); i = process.binary_info->types.find(var->type_id); xbt_assert(i != process.binary_info->types.end(), "Missing type"); type = &i->second; assert(type); assert(find_member(*type, "first")->offset() == 0); assert(find_member(*type, "second")->offset() == ((const char*)&test_some_struct.second) - (const char*)&test_some_struct); unw_context_t context; unw_cursor_t cursor; unw_getcontext(&context); unw_init_local(&cursor, &context); test_local_variable(process.binary_info.get(), "main", "argc", &argc, &cursor); { int lexical_block_variable = 50; test_local_variable(process.binary_info.get(), "main", "lexical_block_variable", &lexical_block_variable, &cursor); } s_foo my_foo; test_type_by_name(process, my_foo); _exit(0);}
开发者ID:RockyMeadow,项目名称:simgrid,代码行数:51,
示例25: Extrae_trace_callersvoid Extrae_trace_callers (iotimer_t time, int offset, int type){ int current_deep = 1; unw_cursor_t cursor; unw_context_t uc; unw_word_t ip; /* Leave if they aren't initialized (asked by user!) */ if (Trace_Caller[type] == NULL) return; if (unw_getcontext(&uc) < 0) return; if (unw_init_local(&cursor, &uc) < 0) return; offset --; /* Don't compute call to unw_getcontext */ while ((unw_step(&cursor) > 0) && (current_deep < Caller_Deepness[type]+offset)) { if (unw_get_reg(&cursor, UNW_REG_IP, &ip) < 0) break;#if defined(MPICALLER_DEBUG) if (current_deep >= offset) fprintf (stderr, "emitted (deep = %d, offset = %d) ip = %lx/n", current_deep, offset, (long) ip); else fprintf (stderr, "ignored (deep = %d, offset = %d) ip = %lx/n", current_deep, offset, (long) ip);#endif if (current_deep >= offset) { if (type == CALLER_MPI || type == CALLER_DYNAMIC_MEMORY) { if (Trace_Caller[type][current_deep-offset]) { TRACE_EVENT(time, CALLER_EVENT_TYPE(type, current_deep-offset+1), (UINT64)ip); } }#if defined(SAMPLING_SUPPORT) else if (type == CALLER_SAMPLING) { if (Trace_Caller[type][current_deep-offset]) SAMPLE_EVENT_NOHWC(time, SAMPLING_EV+current_deep-offset+1, (UINT64) ip); } #endif } current_deep ++; }}
开发者ID:gllort,项目名称:extrae,代码行数:50,
示例26: _LIBUNWIND_TRACE_API/// Scans unwind information to find the function that contains the/// specified code address "pc"._LIBUNWIND_EXPORT void *_Unwind_FindEnclosingFunction(void *pc) { _LIBUNWIND_TRACE_API("_Unwind_FindEnclosingFunction(pc=%p)/n", pc); // This is slow, but works. // We create an unwind cursor then alter the IP to be pc unw_cursor_t cursor; unw_context_t uc; unw_proc_info_t info; unw_getcontext(&uc); unw_init_local(&cursor, &uc); unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)(long) pc); if (unw_get_proc_info(&cursor, &info) == UNW_ESUCCESS) return (void *)(long) info.start_ip; else return NULL;}
开发者ID:Bluerise,项目名称:bitrig,代码行数:17,
示例27: fill_in_backtracevoidfill_in_backtrace(FaultData* fdp){ unw_context_t uc; unw_cursor_t c; int i, boff; memset(&uc, 0, sizeof(uc)); memset(&c, 0, sizeof(c)); if (unw_getcontext(&uc) < 0) { abort(); } if (unw_init_local(&c, &uc) < 0) { abort(); } // Skip the signal handler, and the signal trampoline for (i = 0; i < SKIP_FRAME_COUNT; i++) { if (unw_step(&c) <= 0) { break; } } memset(fdp->frame, 0, sizeof(fdp->frame)); fdp->frame_count = 0; boff = 0; do { char fn[256]; unw_word_t off, ip; Dl_info dli; unw_proc_info_t pi; unw_get_reg (&c, UNW_REG_IP, &ip); fdp->frame[fdp->frame_count].addr = (uintptr_t) ip; fdp->frame[fdp->frame_count].procname = (uintptr_t) &fdp->backtrace_buf[boff]; unw_get_proc_name(&c, (char *) fdp->frame[fdp->frame_count].procname, sizeof(fdp->backtrace_buf) - boff, &off); unw_get_proc_info(&c, &pi); boff += strlen((char *) fdp->frame[fdp->frame_count].procname) + 1; fdp->frame[fdp->frame_count].libname = (uintptr_t) &fdp->backtrace_buf[boff]; dladdr((void *)(uintptr_t) ip, &dli); strcpy((char *) (uintptr_t) fdp->frame[fdp->frame_count].libname, dli.dli_fname); boff += strlen((char *) fdp->frame[fdp->frame_count].libname) + 1; fdp->frame_count++; } while (unw_step(&c) > 0);}
开发者ID:aaronbartell,项目名称:jffi,代码行数:48,
示例28: unwindExcvoid unwindExc(Box* exc_obj) { unw_cursor_t cursor; unw_context_t uc; unw_word_t ip, sp; unw_getcontext(&uc); unw_init_local(&cursor, &uc); int code; unw_proc_info_t pip; while (unw_step(&cursor) > 0) { unw_get_reg(&cursor, UNW_REG_IP, &ip); unw_get_reg(&cursor, UNW_REG_SP, &sp); printf("ip = %lx, sp = %lx/n", (long)ip, (long)sp); code = unw_get_proc_info(&cursor, &pip); RELEASE_ASSERT(code == 0, ""); // printf("%lx %lx %lx %lx %lx %lx %d %d %p/n", pip.start_ip, pip.end_ip, pip.lsda, pip.handler, pip.gp, // pip.flags, pip.format, pip.unwind_info_size, pip.unwind_info); assert((pip.lsda == 0) == (pip.handler == 0)); assert(pip.flags == 0); if (pip.handler == 0) { if (VERBOSITY()) printf("Skipping frame without handler/n"); continue; } printf("%lx %lx %lx/n", pip.lsda, pip.handler, pip.flags); // assert(pip.handler == (uintptr_t)__gxx_personality_v0 || pip.handler == (uintptr_t)__py_personality_v0); // auto handler_fn = (int (*)(int, int, uint64_t, void*, void*))pip.handler; ////handler_fn(1, 1 /* _UA_SEARCH_PHASE */, 0 /* exc_class */, NULL, NULL); // handler_fn(2, 2 /* _UA_SEARCH_PHASE */, 0 /* exc_class */, NULL, NULL); unw_set_reg(&cursor, UNW_REG_IP, 1); // TODO testing: // unw_resume(&cursor); } abort();}
开发者ID:DarrelHsu,项目名称:pyston,代码行数:46,
示例29: unw_getcontextvoid zmq::print_backtrace (void){ static zmq::mutex_t mtx; mtx.lock (); Dl_info dl_info; unw_cursor_t cursor; unw_context_t ctx; unsigned frame_n = 0; unw_getcontext (&ctx); unw_init_local (&cursor, &ctx); while (unw_step (&cursor) > 0) { unw_word_t offset; unw_proc_info_t p_info; const char *file_name; char *demangled_name; char func_name[256] = ""; void *addr; int rc; if (unw_get_proc_info (&cursor, &p_info)) break; addr = (void *)(p_info.start_ip + offset); if (dladdr (addr, &dl_info) && dl_info.dli_fname) file_name = dl_info.dli_fname; else file_name = "?"; rc = unw_get_proc_name (&cursor, func_name, 256, &offset); if (rc == -UNW_ENOINFO) strcpy(func_name, "?"); demangled_name = abi::__cxa_demangle (func_name, NULL, NULL, &rc); printf ("#%u %p in %s (%s+0x%lx)/n", frame_n++, addr, file_name, rc ? func_name : demangled_name, (unsigned long) offset); free (demangled_name); } puts (""); fflush (stdout); mtx.unlock ();}
开发者ID:mattconnolly,项目名称:libzmq,代码行数:46,
注:本文中的unw_init_local函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ unw_step函数代码示例 C++ unw_getcontext函数代码示例 |