Blame SOURCES/00055-systemtap.patch

b54164
diff --git a/Include/pydtrace.d b/Include/pydtrace.d
b54164
new file mode 100644
b54164
index 0000000..3aedc4c
b54164
--- /dev/null
b54164
+++ b/Include/pydtrace.d
23b3e9
@@ -0,0 +1,10 @@
23b3e9
+provider python {
23b3e9
+	probe function__entry(const char *, const char *, int);
23b3e9
+	probe function__return(const char *, const char *, int);
23b3e9
+};
23b3e9
+
23b3e9
+#pragma D attributes Evolving/Evolving/Common provider python provider
23b3e9
+#pragma D attributes Private/Private/Common provider python module
23b3e9
+#pragma D attributes Private/Private/Common provider python function
23b3e9
+#pragma D attributes Evolving/Evolving/Common provider python name
23b3e9
+#pragma D attributes Evolving/Evolving/Common provider python args
b54164
diff --git a/Makefile.pre.in b/Makefile.pre.in
b54164
index 314c89b..6d8ebbf 100644
b54164
--- a/Makefile.pre.in
b54164
+++ b/Makefile.pre.in
b54164
@@ -337,6 +337,7 @@ PYTHON_OBJS=	\
23b3e9
 		Python/formatter_unicode.o \
23b3e9
 		Python/formatter_string.o \
23b3e9
 		Python/$(DYNLOADFILE) \
23b3e9
+		@DTRACEOBJS@ \
23b3e9
 		$(LIBOBJS) \
23b3e9
 		$(MACHDEP_OBJS) \
23b3e9
 		$(THREADOBJ)
b54164
@@ -748,6 +749,18 @@ Python/formatter_unicode.o: $(srcdir)/Python/formatter_unicode.c \
23b3e9
 Python/formatter_string.o: $(srcdir)/Python/formatter_string.c \
23b3e9
 				$(STRINGLIB_HEADERS)
23b3e9
 
23b3e9
+# Only needed with --with-dtrace
23b3e9
+buildinclude:
23b3e9
+	mkdir -p Include
23b3e9
+
23b3e9
+Include/pydtrace.h: buildinclude $(srcdir)/Include/pydtrace.d
23b3e9
+	dtrace -o $@ $(DFLAGS) -C -h -s $(srcdir)/Include/pydtrace.d
23b3e9
+
23b3e9
+Python/ceval.o: Include/pydtrace.h
23b3e9
+
23b3e9
+Python/dtrace.o: buildinclude $(srcdir)/Include/pydtrace.d Python/ceval.o
23b3e9
+	dtrace -o $@ $(DFLAGS) -C -G -s $(srcdir)/Include/pydtrace.d Python/ceval.o
23b3e9
+
23b3e9
 ############################################################################
23b3e9
 # Header files
23b3e9
 
b54164
@@ -1486,7 +1499,7 @@ Python/thread.o: @THREADHEADERS@
23b3e9
 .PHONY: frameworkinstall frameworkinstallframework frameworkinstallstructure
23b3e9
 .PHONY: frameworkinstallmaclib frameworkinstallapps frameworkinstallunixtools
b54164
 .PHONY: frameworkaltinstallunixtools recheck clean clobber distclean
b54164
-.PHONY: smelly funny patchcheck altmaninstall commoninstall
b54164
+.PHONY: smelly funny patchcheck altmaninstall commoninstall buildinclude
23b3e9
 .PHONY: gdbhooks
23b3e9
 
23b3e9
 # IF YOU PUT ANYTHING HERE IT WILL GO AWAY
b54164
diff --git a/Python/ceval.c b/Python/ceval.c
b54164
index 9a8301a..8049333 100644
b54164
--- a/Python/ceval.c
b54164
+++ b/Python/ceval.c
23b3e9
@@ -19,6 +19,10 @@
23b3e9
 
23b3e9
 #include <ctype.h>
23b3e9
 
23b3e9
+#ifdef WITH_DTRACE
23b3e9
+#include "pydtrace.h"
23b3e9
+#endif
23b3e9
+
23b3e9
 #ifndef WITH_TSC
23b3e9
 
23b3e9
 #define READ_TIMESTAMP(var)
b54164
@@ -692,6 +696,55 @@ PyEval_EvalCode(PyCodeObject *co, PyObject *globals, PyObject *locals)
23b3e9
                       NULL);
23b3e9
 }
23b3e9
 
23b3e9
+#ifdef WITH_DTRACE
23b3e9
+static void
23b3e9
+dtrace_entry(PyFrameObject *f)
23b3e9
+{
23b3e9
+    const char *filename;
23b3e9
+    const char *fname;
23b3e9
+    int lineno;
23b3e9
+
23b3e9
+    filename = PyString_AsString(f->f_code->co_filename);
23b3e9
+    fname = PyString_AsString(f->f_code->co_name);
23b3e9
+    lineno = PyCode_Addr2Line(f->f_code, f->f_lasti);
23b3e9
+
23b3e9
+    PYTHON_FUNCTION_ENTRY((char *)filename, (char *)fname, lineno);
23b3e9
+
23b3e9
+    /*
23b3e9
+     * Currently a USDT tail-call will not receive the correct arguments.
23b3e9
+     * Disable the tail call here.
23b3e9
+     */
23b3e9
+#if defined(__sparc)
23b3e9
+    asm("nop");
23b3e9
+#endif
23b3e9
+}
23b3e9
+
23b3e9
+static void
23b3e9
+dtrace_return(PyFrameObject *f)
23b3e9
+{
23b3e9
+    const char *filename;
23b3e9
+    const char *fname;
23b3e9
+    int lineno;
23b3e9
+
23b3e9
+    filename = PyString_AsString(f->f_code->co_filename);
23b3e9
+    fname = PyString_AsString(f->f_code->co_name);
23b3e9
+    lineno = PyCode_Addr2Line(f->f_code, f->f_lasti);
23b3e9
+    PYTHON_FUNCTION_RETURN((char *)filename, (char *)fname, lineno);
23b3e9
+
23b3e9
+    /*
23b3e9
+     * Currently a USDT tail-call will not receive the correct arguments.
23b3e9
+     * Disable the tail call here.
23b3e9
+     */
23b3e9
+#if defined(__sparc)
23b3e9
+    asm("nop");
23b3e9
+#endif
23b3e9
+}
23b3e9
+#else
23b3e9
+#define	PYTHON_FUNCTION_ENTRY_ENABLED() 0
23b3e9
+#define	PYTHON_FUNCTION_RETURN_ENABLED() 0
23b3e9
+#define	dtrace_entry(f)
23b3e9
+#define	dtrace_return(f)
23b3e9
+#endif
23b3e9
 
23b3e9
 /* Interpreter main loop */
23b3e9
 
b54164
@@ -1039,6 +1092,9 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
23b3e9
         }
23b3e9
     }
23b3e9
 
23b3e9
+    if (PYTHON_FUNCTION_ENTRY_ENABLED())
23b3e9
+        dtrace_entry(f);
23b3e9
+
23b3e9
     co = f->f_code;
23b3e9
     names = co->co_names;
23b3e9
     consts = co->co_consts;
b54164
@@ -3375,6 +3431,9 @@ fast_yield:
23b3e9
 
23b3e9
     /* pop frame */
23b3e9
 exit_eval_frame:
23b3e9
+    if (PYTHON_FUNCTION_RETURN_ENABLED())
23b3e9
+        dtrace_return(f);
23b3e9
+
23b3e9
     Py_LeaveRecursiveCall();
23b3e9
     tstate->frame = f->f_back;
23b3e9
 
b54164
diff --git a/configure.ac b/configure.ac
b54164
index 4ca84e3..579dfd3 100644
b54164
--- a/configure.ac
b54164
+++ b/configure.ac
b54164
@@ -3070,6 +3070,38 @@ if test "$with_valgrind" != no; then
b54164
     )
b54164
 fi
b54164
 
b54164
+# Check for dtrace support
b54164
+AC_MSG_CHECKING(for --with-dtrace)
b54164
+AC_ARG_WITH(dtrace,
b54164
+            AC_HELP_STRING(--with(out)-dtrace, disable/enable dtrace support))
b54164
+
b54164
+if test ! -z "$with_dtrace"
b54164
+then
b54164
+    if dtrace -G -o /dev/null -s $srcdir/Include/pydtrace.d 2>/dev/null
b54164
+    then
b54164
+	AC_DEFINE(WITH_DTRACE, 1, 
b54164
+	 [Define if you want to compile in Dtrace support])
b54164
+	with_dtrace="Sun"
b54164
+	DTRACEOBJS="Python/dtrace.o"
b54164
+	DTRADEHDRS=""
b54164
+    elif dtrace -h -o /dev/null -s $srcdir/Include/pydtrace.d
b54164
+    then
b54164
+	AC_DEFINE(WITH_DTRACE, 1, 
b54164
+	 [Define if you want to compile in Dtrace support])
b54164
+	with_dtrace="Apple"
b54164
+	DTRACEOBJS=""
b54164
+	DTRADEHDRS="pydtrace.h"
b54164
+    else
b54164
+	with_dtrace="no"
b54164
+    fi
b54164
+else
b54164
+    with_dtrace="no"
b54164
+fi
b54164
+
b54164
+AC_MSG_RESULT($with_dtrace)
b54164
+AC_SUBST(DTRACEOBJS)
b54164
+AC_SUBST(DTRACEHDRS)
b54164
+
b54164
 # Check for --with-wctype-functions
b54164
 AC_MSG_CHECKING(for --with-wctype-functions)
b54164
 AC_ARG_WITH(wctype-functions, 
b54164
diff --git a/pyconfig.h.in b/pyconfig.h.in
b54164
index 75d70e2..ea28a6a 100644
b54164
--- a/pyconfig.h.in
b54164
+++ b/pyconfig.h.in
b54164
@@ -1148,6 +1148,9 @@
b54164
 /* Define if you want documentation strings in extension modules */
b54164
 #undef WITH_DOC_STRINGS
b54164
 
b54164
+/* Define if you want to compile in Dtrace support */
b54164
+#undef WITH_DTRACE
b54164
+
b54164
 /* Define if you want to use the new-style (Openstep, Rhapsody, MacOS) dynamic
b54164
    linker (dyld) instead of the old-style (NextStep) dynamic linker (rld).
b54164
    Dyld is necessary to support frameworks. */