-
Notifications
You must be signed in to change notification settings - Fork 35
/
php_yasd.h
149 lines (131 loc) · 5.39 KB
/
php_yasd.h
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
+----------------------------------------------------------------------+
| Yasd |
+----------------------------------------------------------------------+
| This source file is subject to version 2.0 of the Apache 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.apache.org/licenses/LICENSE-2.0.html |
| If you did not receive a copy of the Apache2.0 license and are unable|
| to obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: codinghuang <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_YASD_H_
#define PHP_YASD_H_
#include "main/php.h"
#include "Zend/zend_types.h"
#include "zend_closures.h"
#include "zend_exceptions.h"
#include "include/common.h"
extern zend_module_entry yasd_module_entry;
#define phpext_yasd_ptr &yasd_module_entry
#define PHP_YASD_VERSION (char*)"0.3.9-alpha"
ZEND_BEGIN_MODULE_GLOBALS(yasd)
char *breakpoints_file;
char *init_file;
char *debug_mode;
char *remote_host;
uint16_t remote_port;
uint16_t depth;
int log_level;
int open_extended_info;
ssize_t max_executed_opline_num;
ssize_t max_executed_milliseconds;
// compatible with phpstorm
int coverage_enable;
int profiler_enable;
int remote_autostart;
int remote_connect_back;
char *remote_mode;
char *ide_key;
ZEND_END_MODULE_GLOBALS(yasd)
extern ZEND_DECLARE_MODULE_GLOBALS(yasd);
#define YASD_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(yasd, v)
#define php_yasd_fatal_error(level, fmt_str, ...) \
php_error_docref(NULL, level, (const char *) (fmt_str), ##__VA_ARGS__)
static inline zend_bool yasd_zend_is_callable_at_frame(zval *zcallable,
zval *zobject,
zend_execute_data *frame,
uint check_flags,
char **callable_name,
size_t *callable_name_len,
zend_fcall_info_cache *fci_cache,
char **error) {
zend_string *name;
zend_bool ret;
#if PHP_VERSION_ID < 80000
ret = zend_is_callable_ex(zcallable, zobject ? Z_OBJ_P(zobject) : NULL, check_flags, &name, fci_cache, error);
#else
ret = zend_is_callable_at_frame(zcallable, zobject ? Z_OBJ_P(zobject) : NULL, frame, check_flags, fci_cache, error);
name = zend_get_callable_name_ex(zcallable, zobject ? Z_OBJ_P(zobject) : NULL);
#endif
if (callable_name) {
*callable_name = estrndup(ZSTR_VAL(name), ZSTR_LEN(name));
}
if (callable_name_len) {
*callable_name_len = ZSTR_LEN(name);
}
zend_string_release(name);
return ret;
}
static inline zend_bool yasd_zend_is_callable_ex(zval *zcallable,
zval *zobject,
uint check_flags,
char **callable_name,
size_t *callable_name_len,
zend_fcall_info_cache *fci_cache,
char **error) {
return yasd_zend_is_callable_at_frame(
zcallable, zobject, NULL, check_flags, callable_name, callable_name_len, fci_cache, error);
}
static inline void yasd_zend_fci_cache_discard(zend_fcall_info_cache *fci_cache) {
if (fci_cache->object) {
OBJ_RELEASE(fci_cache->object);
}
if (fci_cache->function_handler->op_array.fn_flags & ZEND_ACC_CLOSURE) {
OBJ_RELEASE(ZEND_CLOSURE_OBJECT(fci_cache->function_handler));
}
}
static inline void yasd_zend_fci_cache_persist(zend_fcall_info_cache *fci_cache) {
if (fci_cache->object) {
GC_ADDREF(fci_cache->object);
}
if (fci_cache->function_handler->op_array.fn_flags & ZEND_ACC_CLOSURE) {
GC_ADDREF(ZEND_CLOSURE_OBJECT(fci_cache->function_handler));
}
}
/* this API can work well when retval is NULL */
static inline int yasd_zend_call_function_ex(
zval *function_name, zend_fcall_info_cache *fci_cache, uint32_t param_count, zval *params, zval *retval) {
zend_fcall_info fci;
zval _retval;
int ret;
fci.size = sizeof(fci);
fci.object = NULL;
if (!fci_cache || !fci_cache->function_handler) {
if (!function_name) {
php_yasd_fatal_error(E_WARNING, "Bad function");
return FAILURE;
}
ZVAL_COPY_VALUE(&fci.function_name, function_name);
} else {
ZVAL_UNDEF(&fci.function_name);
}
fci.retval = retval ? retval : &_retval;
fci.param_count = param_count;
fci.params = params;
#if PHP_VERSION_ID >= 80000
fci.named_params = NULL;
#else
fci.no_separation = 0;
#endif
ret = zend_call_function(&fci, fci_cache);
if (!retval) {
zval_ptr_dtor(&_retval);
}
return ret;
}
#endif /* PHP_YASD_H_ */