Author: Armin Rigo <[email protected]>
Branch:
Changeset: r79046:71f9a7fb1933
Date: 2015-08-18 19:32 +0200
http://bitbucket.org/pypy/pypy/changeset/71f9a7fb1933/
Log: Reimport tweaks done for the CPython version
diff --git a/rpython/rlib/rvmprof/src/vmprof_get_custom_offset.h
b/rpython/rlib/rvmprof/src/vmprof_get_custom_offset.h
--- a/rpython/rlib/rvmprof/src/vmprof_get_custom_offset.h
+++ b/rpython/rlib/rvmprof/src/vmprof_get_custom_offset.h
@@ -7,12 +7,69 @@
#endif
+#ifdef CPYTHON_GET_CUSTOM_OFFSET
+static void *tramp_start, *tramp_end;
+#endif
+
+
static ptrdiff_t vmprof_unw_get_custom_offset(void* ip, void *cp) {
-#ifdef PYPY_JIT_CODEMAP
+
+#if defined(PYPY_JIT_CODEMAP)
+
intptr_t ip_l = (intptr_t)ip;
return pypy_jit_stack_depth_at_loc(ip_l);
+
+#elif defined(CPYTHON_GET_CUSTOM_OFFSET)
+
+ if (ip >= tramp_start && ip <= tramp_end) {
+ // XXX the return value is wrong for all the places before push and
+ // after pop, fix
+ void *bp;
+ void *sp;
+
+ /* This is a stage2 trampoline created by hotpatch:
+
+ push %rbx
+ push %rbp
+ mov %rsp,%rbp
+ and $0xfffffffffffffff0,%rsp // make sure the stack is
aligned
+ movabs $0x7ffff687bb10,%rbx
+ callq *%rbx
+ leaveq
+ pop %rbx
+ retq
+
+ the stack layout is like this:
+
+ +-----------+ high addresses
+ | ret addr |
+ +-----------+
+ | saved rbx | start of the function frame
+ +-----------+
+ | saved rbp |
+ +-----------+
+ | ........ | <-- rbp
+ +-----------+ low addresses
+
+ So, the trampoline frame starts at rbp+16, and the return address,
+ is at rbp+24. The vmprof API requires us to return the offset of
+ the frame relative to sp, hence we have this weird computation.
+
+ XXX (antocuni): I think we could change the API to return directly
+ the frame address instead of the offset; however, this require a
+ change in the PyPy code too
+ */
+
+ unw_get_reg (cp, UNW_REG_SP, (unw_word_t*)&sp);
+ unw_get_reg (cp, UNW_X86_64_RBP, (unw_word_t*)&bp);
+ return bp+16+8-sp;
+ }
+ return -1;
+
#else
+
return -1;
+
#endif
}
diff --git a/rpython/rlib/rvmprof/src/vmprof_main.h
b/rpython/rlib/rvmprof/src/vmprof_main.h
--- a/rpython/rlib/rvmprof/src/vmprof_main.h
+++ b/rpython/rlib/rvmprof/src/vmprof_main.h
@@ -46,6 +46,7 @@
static int profile_file = -1;
static long prepare_interval_usec;
static struct profbuf_s *volatile current_codes;
+static void *(*mainloop_get_virtual_ip)(char *) = 0;
static int opened_profile(char *interp_name);
static void flush_codes(void);
@@ -217,12 +218,10 @@
// found main loop stack frame
void* sp;
unw_get_reg(&cursor, UNW_REG_SP, (unw_word_t *) &sp);
- void *arg_addr = (char*)sp /* + mainloop_sp_offset */;
- void **arg_ptr = (void**)arg_addr;
- /* if (mainloop_get_virtual_ip) {
- ip = mainloop_get_virtual_ip(*arg_ptr);
- } else { */
- ip = *arg_ptr;
+ if (mainloop_get_virtual_ip)
+ ip = mainloop_get_virtual_ip((char *)sp);
+ else
+ ip = *(void **)sp;
}
int first_run = (n == 0);
@@ -278,8 +277,8 @@
st->stack[0] = GetPC((ucontext_t*)ucontext);
depth = get_stack_trace(st->stack+1, MAX_STACK_DEPTH-2, ucontext);
depth++; // To account for pc value in stack[0];
+ st->depth = depth;
st->stack[depth++] = get_current_thread_id();
- st->depth = depth;
p->data_offset = offsetof(struct prof_stacktrace_s, marker);
p->data_size = (depth * sizeof(void *) +
sizeof(struct prof_stacktrace_s) -
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit