php-src/Zend/zend_dtrace.c

122 lines
4.2 KiB
C
Raw Normal View History

2010-04-24 13:32:30 +00:00
/*
+----------------------------------------------------------------------+
| Zend Engine |
+----------------------------------------------------------------------+
| Copyright (c) Zend Technologies Ltd. (http://www.zend.com) |
2010-04-24 13:32:30 +00:00
+----------------------------------------------------------------------+
| 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> |
+----------------------------------------------------------------------+
*/
#include "zend.h"
#include "zend_API.h"
#include "zend_dtrace.h"
#ifdef HAVE_DTRACE
ZEND_API zend_op_array *(*zend_dtrace_compile_file)(zend_file_handle *file_handle, int type);
ZEND_API void (*zend_dtrace_execute)(zend_op_array *op_array);
ZEND_API void (*zend_dtrace_execute_internal)(zend_execute_data *execute_data, zval *return_value);
2010-04-24 13:32:30 +00:00
/* PHP DTrace probes {{{ */
2014-12-13 22:06:14 +00:00
static inline const char *dtrace_get_executed_filename(void)
2010-04-24 13:32:30 +00:00
{
2014-07-22 07:12:49 +00:00
zend_execute_data *ex = EG(current_execute_data);
while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->type))) {
ex = ex->prev_execute_data;
}
if (ex) {
return ZSTR_VAL(ex->func->op_array.filename);
2010-04-24 13:32:30 +00:00
} else {
2014-12-13 22:06:14 +00:00
return zend_get_executed_filename();
2010-04-24 13:32:30 +00:00
}
}
2014-12-13 22:06:14 +00:00
ZEND_API zend_op_array *dtrace_compile_file(zend_file_handle *file_handle, int type)
2010-04-24 13:32:30 +00:00
{
zend_op_array *res;
DTRACE_COMPILE_FILE_ENTRY(ZSTR_VAL(file_handle->opened_path), ZSTR_VAL(file_handle->filename));
2014-12-13 22:06:14 +00:00
res = compile_file(file_handle, type);
DTRACE_COMPILE_FILE_RETURN(ZSTR_VAL(file_handle->opened_path), ZSTR_VAL(file_handle->filename));
2010-04-24 13:32:30 +00:00
return res;
}
/* We wrap the execute function to have fire the execute-entry/return and function-entry/return probes */
2014-12-13 22:06:14 +00:00
ZEND_API void dtrace_execute_ex(zend_execute_data *execute_data)
2010-04-24 13:32:30 +00:00
{
int lineno;
const char *scope, *filename, *funcname, *classname;
2010-04-24 13:32:30 +00: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()) {
2014-12-13 22:06:14 +00:00
filename = dtrace_get_executed_filename();
lineno = zend_get_executed_lineno();
2010-04-24 13:32:30 +00:00
}
if (DTRACE_FUNCTION_ENTRY_ENABLED() || DTRACE_FUNCTION_RETURN_ENABLED()) {
2014-12-13 22:06:14 +00:00
classname = get_active_class_name(&scope);
funcname = get_active_function_name();
2010-04-24 13:32:30 +00:00
}
if (DTRACE_EXECUTE_ENTRY_ENABLED()) {
DTRACE_EXECUTE_ENTRY((char *)filename, lineno);
2010-04-24 13:32:30 +00:00
}
if (DTRACE_FUNCTION_ENTRY_ENABLED() && funcname != NULL) {
DTRACE_FUNCTION_ENTRY((char *)funcname, (char *)filename, lineno, (char *)classname, (char *)scope);
2010-04-24 13:32:30 +00:00
}
2014-12-13 22:06:14 +00:00
execute_ex(execute_data);
2010-04-24 13:32:30 +00:00
if (DTRACE_FUNCTION_RETURN_ENABLED() && funcname != NULL) {
DTRACE_FUNCTION_RETURN((char *)funcname, (char *)filename, lineno, (char *)classname, (char *)scope);
2010-04-24 13:32:30 +00:00
}
if (DTRACE_EXECUTE_RETURN_ENABLED()) {
DTRACE_EXECUTE_RETURN((char *)filename, lineno);
2010-04-24 13:32:30 +00:00
}
}
2014-12-13 22:06:14 +00:00
ZEND_API void dtrace_execute_internal(zend_execute_data *execute_data, zval *return_value)
2010-04-24 13:32:30 +00:00
{
int lineno;
const char *filename;
2010-04-24 13:32:30 +00:00
if (DTRACE_EXECUTE_ENTRY_ENABLED() || DTRACE_EXECUTE_RETURN_ENABLED()) {
2014-12-13 22:06:14 +00:00
filename = dtrace_get_executed_filename();
lineno = zend_get_executed_lineno();
2010-04-24 13:32:30 +00:00
}
if (DTRACE_EXECUTE_ENTRY_ENABLED()) {
DTRACE_EXECUTE_ENTRY((char *)filename, lineno);
2010-04-24 13:32:30 +00:00
}
2014-12-13 22:06:14 +00:00
execute_internal(execute_data, return_value);
2010-04-24 13:32:30 +00:00
if (DTRACE_EXECUTE_RETURN_ENABLED()) {
DTRACE_EXECUTE_RETURN((char *)filename, lineno);
2010-04-24 13:32:30 +00:00
}
}
2021-06-04 13:59:43 +00:00
void dtrace_error_notify_cb(int type, zend_string *error_filename, uint32_t error_lineno, zend_string *message)
{
if (DTRACE_ERROR_ENABLED()) {
2021-06-04 13:59:43 +00:00
DTRACE_ERROR(ZSTR_VAL(message), ZSTR_VAL(error_filename), error_lineno);
}
}
2010-04-24 13:32:30 +00:00
/* }}} */
2015-12-24 02:41:05 +00:00
2010-04-24 13:32:30 +00:00
#endif /* HAVE_DTRACE */