2010-04-24 21:32:30 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Zend Engine |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Copyright (c) 1998-2009 Zend Technologies Ltd. (http://www.zend.com) |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| This source file is subject to version 2.00 of the Zend license, |
|
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available through the world-wide-web at the following url: |
|
|
|
|
| http://www.zend.com/license/2_00.txt. |
|
|
|
|
| If you did not receive a copy of the Zend license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@zend.com so we can mail you a copy immediately. |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Authors: David Soria Parra <david.soriaparra@sun.com> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* $Id: $ */
|
|
|
|
|
|
|
|
#include "zend.h"
|
|
|
|
#include "zend_API.h"
|
|
|
|
#include "zend_dtrace.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_DTRACE
|
|
|
|
/* PHP DTrace probes {{{ */
|
2013-08-14 11:42:39 +08:00
|
|
|
static inline const char *dtrace_get_executed_filename(TSRMLS_D)
|
2010-04-24 21:32:30 +08:00
|
|
|
{
|
|
|
|
if (EG(current_execute_data) && EG(current_execute_data)->op_array) {
|
|
|
|
return EG(current_execute_data)->op_array->filename;
|
|
|
|
} else {
|
|
|
|
return zend_get_executed_filename(TSRMLS_C);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ZEND_API zend_op_array *dtrace_compile_file(zend_file_handle *file_handle, int type TSRMLS_DC)
|
|
|
|
{
|
|
|
|
zend_op_array *res;
|
2013-08-14 11:42:39 +08:00
|
|
|
DTRACE_COMPILE_FILE_ENTRY(file_handle->opened_path, (char *)file_handle->filename);
|
2010-04-24 21:32:30 +08:00
|
|
|
res = compile_file(file_handle, type TSRMLS_CC);
|
2013-08-14 11:42:39 +08:00
|
|
|
DTRACE_COMPILE_FILE_RETURN(file_handle->opened_path, (char *)file_handle->filename);
|
2010-04-24 21:32:30 +08:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We wrap the execute function to have fire the execute-entry/return and function-entry/return probes */
|
2012-12-05 07:45:23 +08:00
|
|
|
ZEND_API void dtrace_execute_ex(zend_execute_data *execute_data TSRMLS_DC)
|
2010-04-24 21:32:30 +08:00
|
|
|
{
|
|
|
|
int lineno;
|
2013-08-14 11:42:39 +08:00
|
|
|
const char *scope, *filename, *funcname, *classname;
|
2010-04-24 21:32:30 +08:00
|
|
|
scope = filename = funcname = classname = NULL;
|
|
|
|
|
|
|
|
/* we need filename and lineno for both execute and function probes */
|
|
|
|
if (DTRACE_EXECUTE_ENTRY_ENABLED() || DTRACE_EXECUTE_RETURN_ENABLED()
|
|
|
|
|| DTRACE_FUNCTION_ENTRY_ENABLED() || DTRACE_FUNCTION_RETURN_ENABLED()) {
|
|
|
|
filename = dtrace_get_executed_filename(TSRMLS_C);
|
|
|
|
lineno = zend_get_executed_lineno(TSRMLS_C);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DTRACE_FUNCTION_ENTRY_ENABLED() || DTRACE_FUNCTION_RETURN_ENABLED()) {
|
|
|
|
classname = get_active_class_name(&scope TSRMLS_CC);
|
|
|
|
funcname = get_active_function_name(TSRMLS_C);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DTRACE_EXECUTE_ENTRY_ENABLED()) {
|
2013-08-14 11:42:39 +08:00
|
|
|
DTRACE_EXECUTE_ENTRY((char *)filename, lineno);
|
2010-04-24 21:32:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (DTRACE_FUNCTION_ENTRY_ENABLED() && funcname != NULL) {
|
2013-08-14 11:42:39 +08:00
|
|
|
DTRACE_FUNCTION_ENTRY((char *)funcname, (char *)filename, lineno, (char *)classname, (char *)scope);
|
2010-04-24 21:32:30 +08:00
|
|
|
}
|
|
|
|
|
2012-12-05 07:45:23 +08:00
|
|
|
execute_ex(execute_data TSRMLS_CC);
|
2010-04-24 21:32:30 +08:00
|
|
|
|
|
|
|
if (DTRACE_FUNCTION_RETURN_ENABLED() && funcname != NULL) {
|
2013-08-14 11:42:39 +08:00
|
|
|
DTRACE_FUNCTION_RETURN((char *)funcname, (char *)filename, lineno, (char *)classname, (char *)scope);
|
2010-04-24 21:32:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (DTRACE_EXECUTE_RETURN_ENABLED()) {
|
2013-08-14 11:42:39 +08:00
|
|
|
DTRACE_EXECUTE_RETURN((char *)filename, lineno);
|
2010-04-24 21:32:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-07 19:50:44 +08:00
|
|
|
ZEND_API void dtrace_execute_internal(zend_execute_data *execute_data, zval *return_value TSRMLS_DC)
|
2010-04-24 21:32:30 +08:00
|
|
|
{
|
|
|
|
int lineno;
|
2013-08-14 11:42:39 +08:00
|
|
|
const char *filename;
|
2010-04-24 21:32:30 +08:00
|
|
|
if (DTRACE_EXECUTE_ENTRY_ENABLED() || DTRACE_EXECUTE_RETURN_ENABLED()) {
|
|
|
|
filename = dtrace_get_executed_filename(TSRMLS_C);
|
|
|
|
lineno = zend_get_executed_lineno(TSRMLS_C);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DTRACE_EXECUTE_ENTRY_ENABLED()) {
|
2013-08-14 11:42:39 +08:00
|
|
|
DTRACE_EXECUTE_ENTRY((char *)filename, lineno);
|
2010-04-24 21:32:30 +08:00
|
|
|
}
|
|
|
|
|
2014-07-07 19:50:44 +08:00
|
|
|
execute_internal(execute_data, return_value TSRMLS_CC);
|
2010-04-24 21:32:30 +08:00
|
|
|
|
|
|
|
if (DTRACE_EXECUTE_RETURN_ENABLED()) {
|
2013-08-14 11:42:39 +08:00
|
|
|
DTRACE_EXECUTE_RETURN((char *)filename, lineno);
|
2010-04-24 21:32:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
#endif /* HAVE_DTRACE */
|
|
|
|
|