php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
zend_dtrace.c
Go to the documentation of this file.
1/*
2 +----------------------------------------------------------------------+
3 | Zend Engine |
4 +----------------------------------------------------------------------+
5 | Copyright (c) Zend Technologies Ltd. (http://www.zend.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 2.00 of the Zend license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.zend.com/license/2_00.txt. |
11 | If you did not receive a copy of the Zend license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@zend.com so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
15 | Authors: David Soria Parra <david.soriaparra@sun.com> |
16 +----------------------------------------------------------------------+
17*/
18
19#include "zend.h"
20#include "zend_API.h"
21#include "zend_dtrace.h"
22
23#ifdef HAVE_DTRACE
24
25ZEND_API zend_op_array *(*zend_dtrace_compile_file)(zend_file_handle *file_handle, int type);
26ZEND_API void (*zend_dtrace_execute)(zend_op_array *op_array);
27ZEND_API void (*zend_dtrace_execute_internal)(zend_execute_data *execute_data, zval *return_value);
28
29/* PHP DTrace probes {{{ */
30static inline const char *dtrace_get_executed_filename(void)
31{
32 zend_execute_data *ex = EG(current_execute_data);
33
34 while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->type))) {
35 ex = ex->prev_execute_data;
36 }
37 if (ex) {
38 return ZSTR_VAL(ex->func->op_array.filename);
39 } else {
41 }
42}
43
44ZEND_API zend_op_array *dtrace_compile_file(zend_file_handle *file_handle, int type)
45{
47 DTRACE_COMPILE_FILE_ENTRY(ZSTR_VAL(file_handle->opened_path), ZSTR_VAL(file_handle->filename));
48 res = compile_file(file_handle, type);
49 DTRACE_COMPILE_FILE_RETURN(ZSTR_VAL(file_handle->opened_path), ZSTR_VAL(file_handle->filename));
50
51 return res;
52}
53
54/* We wrap the execute function to have fire the execute-entry/return and function-entry/return probes */
55ZEND_API void dtrace_execute_ex(zend_execute_data *execute_data)
56{
57 int lineno;
58 const char *scope, *filename, *funcname, *classname;
59 scope = filename = funcname = classname = NULL;
60
61 /* we need filename and lineno for both execute and function probes */
62 if (DTRACE_EXECUTE_ENTRY_ENABLED() || DTRACE_EXECUTE_RETURN_ENABLED()
63 || DTRACE_FUNCTION_ENTRY_ENABLED() || DTRACE_FUNCTION_RETURN_ENABLED()) {
64 filename = dtrace_get_executed_filename();
65 lineno = zend_get_executed_lineno();
66 }
67
68 if (DTRACE_FUNCTION_ENTRY_ENABLED() || DTRACE_FUNCTION_RETURN_ENABLED()) {
69 classname = get_active_class_name(&scope);
70 funcname = get_active_function_name();
71 }
72
73 if (DTRACE_EXECUTE_ENTRY_ENABLED()) {
74 DTRACE_EXECUTE_ENTRY((char *)filename, lineno);
75 }
76
77 if (DTRACE_FUNCTION_ENTRY_ENABLED() && funcname != NULL) {
78 DTRACE_FUNCTION_ENTRY((char *)funcname, (char *)filename, lineno, (char *)classname, (char *)scope);
79 }
80
82
83 if (DTRACE_FUNCTION_RETURN_ENABLED() && funcname != NULL) {
84 DTRACE_FUNCTION_RETURN((char *)funcname, (char *)filename, lineno, (char *)classname, (char *)scope);
85 }
86
87 if (DTRACE_EXECUTE_RETURN_ENABLED()) {
88 DTRACE_EXECUTE_RETURN((char *)filename, lineno);
89 }
90}
91
92ZEND_API void dtrace_execute_internal(zend_execute_data *execute_data, zval *return_value)
93{
94 int lineno;
95 const char *filename;
96 if (DTRACE_EXECUTE_ENTRY_ENABLED() || DTRACE_EXECUTE_RETURN_ENABLED()) {
97 filename = dtrace_get_executed_filename();
98 lineno = zend_get_executed_lineno();
99 }
100
101 if (DTRACE_EXECUTE_ENTRY_ENABLED()) {
102 DTRACE_EXECUTE_ENTRY((char *)filename, lineno);
103 }
104
106
107 if (DTRACE_EXECUTE_RETURN_ENABLED()) {
108 DTRACE_EXECUTE_RETURN((char *)filename, lineno);
109 }
110}
111
112void dtrace_error_notify_cb(int type, zend_string *error_filename, uint32_t error_lineno, zend_string *message)
113{
114 if (DTRACE_ERROR_ENABLED()) {
115 DTRACE_ERROR(ZSTR_VAL(message), ZSTR_VAL(error_filename), error_lineno);
116 }
117}
118
119/* }}} */
120
121#endif /* HAVE_DTRACE */
zend_ffi_type * type
Definition ffi.c:3812
zend_string * res
Definition ffi.c:4692
#define NULL
Definition gdcache.h:45
zend_op_array *(* compile_file)(zend_file_handle *file_handle, int type)
Definition phpdbg.h:272
zend_object * ex
zend_string * filename
Definition zend_stream.h:58
zend_string * opened_path
Definition zend_stream.h:59
struct _zval_struct zval
#define ZEND_USER_CODE(type)
struct _zend_op_array zend_op_array
#define ZEND_API
ZEND_API void execute_internal(zend_execute_data *execute_data, zval *return_value)
ZEND_API void(ZEND_FASTCALL *zend_touch_vm_stack_data)(void *vm_stack_data)
ZEND_API const char * get_active_function_name(void)
ZEND_API uint32_t zend_get_executed_lineno(void)
ZEND_API const char * zend_get_executed_filename(void)
ZEND_API void execute_ex(zend_execute_data *execute_data)
ZEND_API const char * get_active_class_name(const char **space)
#define EG(v)
struct _zend_file_handle zend_file_handle
struct _zend_string zend_string
#define ZSTR_VAL(zstr)
Definition zend_string.h:68
struct _zend_execute_data zend_execute_data
Definition zend_types.h:91
zval * return_value
execute_data
new_op_array scope