-
Notifications
You must be signed in to change notification settings - Fork 2
/
CPython-2.7.diff
70 lines (64 loc) · 2.32 KB
/
CPython-2.7.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
diff -r a8e6ea473db2 Makefile.pre.in
--- a/Makefile.pre.in Fri Dec 05 22:02:33 2014 -0500
+++ b/Makefile.pre.in Tue Dec 09 15:13:00 2014 +0200
@@ -84,6 +84,11 @@
# C flags used for building the interpreter object files
PY_CFLAGS= $(CFLAGS) $(CPPFLAGS) $(CFLAGSFORSHARED) -DPy_BUILD_CORE
+# vmprof hack
+VMPROFDIR = /home/antocuni/pypy/misc/vmprof/vmprof
+CFLAGS += -I$(VMPROFDIR)
+LDLAST += -Wl,-rpath,$(VMPROFDIR) -L$(VMPROFDIR) -lvmprof
+
# Machine-dependent subdirectories
MACHDEP= @MACHDEP@
diff -r a8e6ea473db2 Python/ceval.c
--- a/Python/ceval.c Fri Dec 05 22:02:33 2014 -0500
+++ b/Python/ceval.c Tue Dec 09 15:13:00 2014 +0200
@@ -19,6 +19,8 @@
#include <ctype.h>
+#include <vmprof.h>
+
#ifndef WITH_TSC
#define READ_TIMESTAMP(var)
@@ -684,7 +686,41 @@
}
PyObject *
-PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
+Do_PyEval_EvalFrameEx(PyFrameObject *f, int throwflag);
+
+/* this is called by vmprof */
+static void* PyEval_GetVirtualIp(PyFrameObject* f) {
+ char buf[4096];
+ char* co_name = PyString_AsString(f->f_code->co_name);
+ char* co_filename = PyString_AsString(f->f_code->co_filename);
+ int co_lineno = f->f_code->co_firstlineno;
+ // set the first bit to 1; on my system, such address space is unused, so
+ // we don't risk spurious conflicts with loaded libraries. The proper
+ // solution would be to tell the linker to reserve us some address space
+ // and use that.
+ unsigned long res = (unsigned long)f->f_code | 0x8000000000000000;
+ sprintf(buf, "py:%s:%s:%d", co_filename, co_name, co_lineno); // XXX, I know, possible buffer overflow
+ vmprof_register_virtual_function(buf, (void*)res, NULL);
+ return (void*)res;
+}
+
+/* we need to force -O2 to make sure that gcc saves f2 on the stack, and that
+ it is preserved after the call to Do_PyEval_EvalFrameEx */
+PyObject *
+__attribute__((optimize("O2")))
+PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) {
+ register void* _rsp asm("rsp");
+ ptrdiff_t offset;
+ volatile PyFrameObject *f2 = f;
+ offset = (char*)&f2 - (char*)_rsp;
+ if (!vmprof_mainloop_func)
+ vmprof_set_mainloop(&PyEval_EvalFrameEx, offset, (void*)PyEval_GetVirtualIp);
+ return Do_PyEval_EvalFrameEx(f, throwflag);
+}
+
+
+PyObject *
+Do_PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
{
#ifdef DXPAIRS
int lastopcode = 0;