Skip to content

Commit 81049cd

Browse files
committed
Implemented fpm_trace for PHP7
1 parent 0be3714 commit 81049cd

File tree

2 files changed

+85
-34
lines changed

2 files changed

+85
-34
lines changed

sapi/fpm/fpm/fpm_php_trace.c

Lines changed: 84 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,13 @@
4242

4343
static int fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{ */
4444
{
45-
// TODO: fpm_php_trace_dump() has to be reimplemented ???
46-
#if 0
4745
int callers_limit = 20;
4846
pid_t pid = child->pid;
4947
struct timeval tv;
5048
static const int buf_size = 1024;
5149
char buf[buf_size];
5250
long execute_data;
51+
long path_translated;
5352
long l;
5453

5554
gettimeofday(&tv, 0);
@@ -58,7 +57,13 @@ static int fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{ *
5857

5958
fprintf(slowlog, "\n%s [pool %s] pid %d\n", buf, child->wp->config->name, (int) pid);
6059

61-
if (0 > fpm_trace_get_strz(buf, buf_size, (long) &SG(request_info).path_translated)) {
60+
if (0 > fpm_trace_get_long((long) &SG(request_info).path_translated, &l)) {
61+
return -1;
62+
}
63+
64+
path_translated = l;
65+
66+
if (0 > fpm_trace_get_strz(buf, buf_size, path_translated)) {
6267
return -1;
6368
}
6469

@@ -72,68 +77,118 @@ static int fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{ *
7277

7378
while (execute_data) {
7479
long function;
80+
long function_name;
81+
long file_name;
82+
long prev;
7583
uint lineno = 0;
7684

77-
fprintf(slowlog, "[0x%" PTR_FMT "lx] ", execute_data);
78-
79-
if (0 > fpm_trace_get_long(execute_data + offsetof(zend_execute_data, function_state.function), &l)) {
85+
if (0 > fpm_trace_get_long(execute_data + offsetof(zend_execute_data, func), &l)) {
8086
return -1;
8187
}
8288

8389
function = l;
8490

8591
if (valid_ptr(function)) {
86-
if (0 > fpm_trace_get_strz(buf, buf_size, function + offsetof(zend_function, common.function_name))) {
92+
if (0 > fpm_trace_get_long(function + offsetof(zend_function, common.function_name), &l)) {
8793
return -1;
8894
}
8995

90-
fprintf(slowlog, "%s()", buf);
96+
function_name = l;
97+
98+
if (function_name == 0) {
99+
uint32_t *call_info = (uint32_t *)&l;
100+
if (0 > fpm_trace_get_long(execute_data + offsetof(zend_execute_data, This.u1.type_info), &l)) {
101+
return -1;
102+
}
103+
104+
if (ZEND_CALL_KIND_EX((*call_info) >> 24) == ZEND_CALL_TOP_CODE) {
105+
return 0;
106+
} else if (ZEND_CALL_KIND_EX(*(call_info) >> 24) == ZEND_CALL_NESTED_CODE) {
107+
memcpy(buf, "[INCLUDE_OR_EVAL]", sizeof("[INCLUDE_OR_EVAL]"));
108+
} else {
109+
ZEND_ASSERT(0);
110+
}
111+
} else {
112+
if (0 > fpm_trace_get_strz(buf, buf_size, function_name + offsetof(zend_string, val))) {
113+
return -1;
114+
}
115+
116+
}
91117
} else {
92-
fprintf(slowlog, "???");
118+
memcpy(buf, "???", sizeof("???"));
93119
}
120+
121+
fprintf(slowlog, "[0x%" PTR_FMT "lx] ", execute_data);
94122

95-
if (0 > fpm_trace_get_long(execute_data + offsetof(zend_execute_data, op_array), &l)) {
123+
fprintf(slowlog, "%s()", buf);
124+
125+
*buf = '\0';
126+
127+
if (0 > fpm_trace_get_long(execute_data + offsetof(zend_execute_data, prev_execute_data), &l)) {
96128
return -1;
97129
}
98130

99-
*buf = '\0';
131+
execute_data = prev = l;
100132

101-
if (valid_ptr(l)) {
102-
long op_array = l;
133+
while (prev) {
103134

104-
if (0 > fpm_trace_get_strz(buf, buf_size, op_array + offsetof(zend_op_array, filename))) {
135+
if (0 > fpm_trace_get_long(prev + offsetof(zend_execute_data, func), &l)) {
105136
return -1;
106137
}
107-
}
108138

109-
if (0 > fpm_trace_get_long(execute_data + offsetof(zend_execute_data, opline), &l)) {
110-
return -1;
111-
}
139+
function = l;
112140

113-
if (valid_ptr(l)) {
114-
long opline = l;
115-
uint *lu = (uint *) &l;
141+
if (!valid_ptr(function)) {
142+
break;
143+
}
116144

117-
if (0 > fpm_trace_get_long(opline + offsetof(struct _zend_op, lineno), &l)) {
145+
if (0 > fpm_trace_get_long(function + offsetof(zend_function, type), &l)) {
118146
return -1;
119147
}
120148

121-
lineno = *lu;
122-
}
149+
/* zend_uchar? */
150+
if (ZEND_USER_CODE(l)) {
151+
if (0 > fpm_trace_get_long(function + offsetof(zend_op_array, filename), &l)) {
152+
return -1;
153+
}
123154

124-
fprintf(slowlog, " %s:%u\n", *buf ? buf : "unknown", lineno);
155+
file_name = l;
125156

126-
if (0 > fpm_trace_get_long(execute_data + offsetof(zend_execute_data, prev_execute_data), &l)) {
127-
return -1;
157+
if (0 > fpm_trace_get_strz(buf, buf_size, file_name + offsetof(zend_string, val))) {
158+
return -1;
159+
}
160+
161+
if (0 > fpm_trace_get_long(prev + offsetof(zend_execute_data, opline), &l)) {
162+
return -1;
163+
}
164+
165+
if (valid_ptr(l)) {
166+
long opline = l;
167+
uint32_t *lu = (uint32_t *) &l;
168+
169+
if (0 > fpm_trace_get_long(opline + offsetof(struct _zend_op, lineno), &l)) {
170+
return -1;
171+
}
172+
173+
lineno = *lu;
174+
}
175+
break;
176+
}
177+
178+
if (0 > fpm_trace_get_long(prev + offsetof(zend_execute_data, prev_execute_data), &l)) {
179+
return -1;
180+
}
181+
182+
prev = l;
128183
}
129184

130-
execute_data = l;
185+
fprintf(slowlog, " %s:%u\n", *buf ? buf : "unknown", lineno);
131186

132187
if (0 == --callers_limit) {
133188
break;
134189
}
135190
}
136-
#endif
191+
137192
return 0;
138193
}
139194
/* }}} */

sapi/fpm/fpm/fpm_trace.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,9 @@
1111
int fpm_trace_get_strz(char *buf, size_t sz, long addr) /* {{{ */
1212
{
1313
int i;
14-
long l;
14+
long l = addr;
1515
char *lc = (char *) &l;
1616

17-
if (0 > fpm_trace_get_long(addr, &l)) {
18-
return -1;
19-
}
20-
2117
i = l % SIZEOF_LONG;
2218
l -= i;
2319
for (addr = l; ; addr += SIZEOF_LONG) {

0 commit comments

Comments
 (0)