Skip to content

Commit a15d215

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: [Observer] Save opline before calling begin/end handlers
2 parents e169ad3 + 855d8fa commit a15d215

File tree

5 files changed

+111
-13
lines changed

5 files changed

+111
-13
lines changed

Zend/zend_vm_def.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3956,8 +3956,9 @@ ZEND_VM_HOT_HANDLER(130, ZEND_DO_UCALL, ANY, ANY, SPEC(RETVAL,OBSERVER))
39563956
call->prev_execute_data = execute_data;
39573957
execute_data = call;
39583958
i_init_func_execute_data(&fbc->op_array, ret, 0 EXECUTE_DATA_CC);
3959-
ZEND_OBSERVER_FCALL_BEGIN(execute_data);
39603959
LOAD_OPLINE_EX();
3960+
ZEND_OBSERVER_SAVE_OPLINE();
3961+
ZEND_OBSERVER_FCALL_BEGIN(execute_data);
39613962

39623963
ZEND_VM_ENTER_EX();
39633964
}
@@ -3981,8 +3982,9 @@ ZEND_VM_HOT_HANDLER(131, ZEND_DO_FCALL_BY_NAME, ANY, ANY, SPEC(RETVAL,OBSERVER))
39813982
call->prev_execute_data = execute_data;
39823983
execute_data = call;
39833984
i_init_func_execute_data(&fbc->op_array, ret, 0 EXECUTE_DATA_CC);
3984-
ZEND_OBSERVER_FCALL_BEGIN(execute_data);
39853985
LOAD_OPLINE_EX();
3986+
ZEND_OBSERVER_SAVE_OPLINE();
3987+
ZEND_OBSERVER_FCALL_BEGIN(execute_data);
39863988

39873989
ZEND_VM_ENTER_EX();
39883990
} else {
@@ -4075,13 +4077,15 @@ ZEND_VM_HOT_HANDLER(60, ZEND_DO_FCALL, ANY, ANY, SPEC(RETVAL,OBSERVER))
40754077
call->prev_execute_data = execute_data;
40764078
execute_data = call;
40774079
i_init_func_execute_data(&fbc->op_array, ret, 1 EXECUTE_DATA_CC);
4078-
ZEND_OBSERVER_FCALL_BEGIN(execute_data);
40794080

40804081
if (EXPECTED(zend_execute_ex == execute_ex)) {
40814082
LOAD_OPLINE_EX();
4083+
ZEND_OBSERVER_SAVE_OPLINE();
4084+
ZEND_OBSERVER_FCALL_BEGIN(execute_data);
40824085
ZEND_VM_ENTER_EX();
40834086
} else {
40844087
SAVE_OPLINE_EX();
4088+
ZEND_OBSERVER_FCALL_BEGIN(execute_data);
40854089
execute_data = EX(prev_execute_data);
40864090
LOAD_OPLINE();
40874091
ZEND_ADD_CALL_FLAG(call, ZEND_CALL_TOP);
@@ -4299,6 +4303,7 @@ ZEND_VM_INLINE_HANDLER(62, ZEND_RETURN, CONST|TMP|VAR|CV, ANY, SPEC(OBSERVER))
42994303
}
43004304
}
43014305
}
4306+
ZEND_OBSERVER_SAVE_OPLINE();
43024307
ZEND_OBSERVER_FCALL_END(execute_data, return_value);
43034308
ZEND_VM_DISPATCH_TO_HELPER(zend_leave_helper);
43044309
}
@@ -8511,12 +8516,14 @@ ZEND_VM_HANDLER(158, ZEND_CALL_TRAMPOLINE, ANY, ANY, SPEC(OBSERVER))
85118516
}
85128517
execute_data = call;
85138518
i_init_func_execute_data(&fbc->op_array, ret, 0 EXECUTE_DATA_CC);
8514-
ZEND_OBSERVER_FCALL_BEGIN(execute_data);
85158519
if (EXPECTED(zend_execute_ex == execute_ex)) {
85168520
LOAD_OPLINE_EX();
8521+
ZEND_OBSERVER_SAVE_OPLINE();
8522+
ZEND_OBSERVER_FCALL_BEGIN(execute_data);
85178523
ZEND_VM_ENTER_EX();
85188524
} else {
85198525
SAVE_OPLINE_EX();
8526+
ZEND_OBSERVER_FCALL_BEGIN(execute_data);
85208527
execute_data = EX(prev_execute_data);
85218528
LOAD_OPLINE();
85228529
ZEND_ADD_CALL_FLAG(call, ZEND_CALL_TOP);

Zend/zend_vm_execute.h

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,9 +1350,9 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_UCALL_SPEC_RETV
13501350
call->prev_execute_data = execute_data;
13511351
execute_data = call;
13521352
i_init_func_execute_data(&fbc->op_array, ret, 0 EXECUTE_DATA_CC);
1353-
13541353
LOAD_OPLINE_EX();
13551354

1355+
13561356
ZEND_VM_ENTER_EX();
13571357
}
13581358

@@ -1374,9 +1374,9 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_UCALL_SPEC_RETV
13741374
call->prev_execute_data = execute_data;
13751375
execute_data = call;
13761376
i_init_func_execute_data(&fbc->op_array, ret, 0 EXECUTE_DATA_CC);
1377-
13781377
LOAD_OPLINE_EX();
13791378

1379+
13801380
ZEND_VM_ENTER_EX();
13811381
}
13821382

@@ -1398,8 +1398,9 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_UCALL_SPEC_OBS
13981398
call->prev_execute_data = execute_data;
13991399
execute_data = call;
14001400
i_init_func_execute_data(&fbc->op_array, ret, 0 EXECUTE_DATA_CC);
1401-
zend_observer_fcall_begin(execute_data);
14021401
LOAD_OPLINE_EX();
1402+
SAVE_OPLINE();
1403+
zend_observer_fcall_begin(execute_data);
14031404

14041405
ZEND_VM_ENTER_EX();
14051406
}
@@ -1423,9 +1424,9 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_BY_NAME_S
14231424
call->prev_execute_data = execute_data;
14241425
execute_data = call;
14251426
i_init_func_execute_data(&fbc->op_array, ret, 0 EXECUTE_DATA_CC);
1426-
14271427
LOAD_OPLINE_EX();
14281428

1429+
14291430
ZEND_VM_ENTER_EX();
14301431
} else {
14311432
zval retval;
@@ -1517,9 +1518,9 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_BY_NAME_S
15171518
call->prev_execute_data = execute_data;
15181519
execute_data = call;
15191520
i_init_func_execute_data(&fbc->op_array, ret, 0 EXECUTE_DATA_CC);
1520-
15211521
LOAD_OPLINE_EX();
15221522

1523+
15231524
ZEND_VM_ENTER_EX();
15241525
} else {
15251526
zval retval;
@@ -1611,8 +1612,9 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_BY_NAME_
16111612
call->prev_execute_data = execute_data;
16121613
execute_data = call;
16131614
i_init_func_execute_data(&fbc->op_array, ret, 0 EXECUTE_DATA_CC);
1614-
zend_observer_fcall_begin(execute_data);
16151615
LOAD_OPLINE_EX();
1616+
SAVE_OPLINE();
1617+
zend_observer_fcall_begin(execute_data);
16161618

16171619
ZEND_VM_ENTER_EX();
16181620
} else {
@@ -1708,9 +1710,12 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_SPEC_RETV
17081710

17091711
if (EXPECTED(zend_execute_ex == execute_ex)) {
17101712
LOAD_OPLINE_EX();
1713+
1714+
17111715
ZEND_VM_ENTER_EX();
17121716
} else {
17131717
SAVE_OPLINE_EX();
1718+
17141719
execute_data = EX(prev_execute_data);
17151720
LOAD_OPLINE();
17161721
ZEND_ADD_CALL_FLAG(call, ZEND_CALL_TOP);
@@ -1813,9 +1818,12 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_SPEC_RETV
18131818

18141819
if (EXPECTED(zend_execute_ex == execute_ex)) {
18151820
LOAD_OPLINE_EX();
1821+
1822+
18161823
ZEND_VM_ENTER_EX();
18171824
} else {
18181825
SAVE_OPLINE_EX();
1826+
18191827
execute_data = EX(prev_execute_data);
18201828
LOAD_OPLINE();
18211829
ZEND_ADD_CALL_FLAG(call, ZEND_CALL_TOP);
@@ -1915,13 +1923,15 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_SPEC_OBS
19151923
call->prev_execute_data = execute_data;
19161924
execute_data = call;
19171925
i_init_func_execute_data(&fbc->op_array, ret, 1 EXECUTE_DATA_CC);
1918-
zend_observer_fcall_begin(execute_data);
19191926

19201927
if (EXPECTED(zend_execute_ex == execute_ex)) {
19211928
LOAD_OPLINE_EX();
1929+
SAVE_OPLINE();
1930+
zend_observer_fcall_begin(execute_data);
19221931
ZEND_VM_ENTER_EX();
19231932
} else {
19241933
SAVE_OPLINE_EX();
1934+
zend_observer_fcall_begin(execute_data);
19251935
execute_data = EX(prev_execute_data);
19261936
LOAD_OPLINE();
19271937
ZEND_ADD_CALL_FLAG(call, ZEND_CALL_TOP);
@@ -3136,12 +3146,14 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_CALL_TRAMPOLINE_SPEC_HANDLER(Z
31363146
}
31373147
execute_data = call;
31383148
i_init_func_execute_data(&fbc->op_array, ret, 0 EXECUTE_DATA_CC);
3139-
31403149
if (EXPECTED(zend_execute_ex == execute_ex)) {
31413150
LOAD_OPLINE_EX();
3151+
3152+
31423153
ZEND_VM_ENTER_EX();
31433154
} else {
31443155
SAVE_OPLINE_EX();
3156+
31453157
execute_data = EX(prev_execute_data);
31463158
LOAD_OPLINE();
31473159
ZEND_ADD_CALL_FLAG(call, ZEND_CALL_TOP);
@@ -3270,12 +3282,14 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_CALL_TRAMPOLINE_SPEC_OBSERVER_
32703282
}
32713283
execute_data = call;
32723284
i_init_func_execute_data(&fbc->op_array, ret, 0 EXECUTE_DATA_CC);
3273-
zend_observer_fcall_begin(execute_data);
32743285
if (EXPECTED(zend_execute_ex == execute_ex)) {
32753286
LOAD_OPLINE_EX();
3287+
SAVE_OPLINE();
3288+
zend_observer_fcall_begin(execute_data);
32763289
ZEND_VM_ENTER_EX();
32773290
} else {
32783291
SAVE_OPLINE_EX();
3292+
zend_observer_fcall_begin(execute_data);
32793293
execute_data = EX(prev_execute_data);
32803294
LOAD_OPLINE();
32813295
ZEND_ADD_CALL_FLAG(call, ZEND_CALL_TOP);
@@ -4069,6 +4083,7 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_RETURN_SPEC_CONST_
40694083
}
40704084
}
40714085

4086+
40724087
ZEND_VM_TAIL_CALL(zend_leave_helper_SPEC(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU));
40734088
}
40744089

@@ -4141,6 +4156,7 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_RETURN_SPEC_OBSER
41414156
}
41424157
}
41434158
}
4159+
SAVE_OPLINE();
41444160
zend_observer_fcall_end(execute_data, return_value);
41454161
ZEND_VM_TAIL_CALL(zend_leave_helper_SPEC(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU));
41464162
}
@@ -18574,6 +18590,7 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_RETURN_SPEC_TMP_HA
1857418590
}
1857518591
}
1857618592

18593+
1857718594
ZEND_VM_TAIL_CALL(zend_leave_helper_SPEC(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU));
1857818595
}
1857918596

@@ -21139,6 +21156,7 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_RETURN_SPEC_VAR_HA
2113921156
}
2114021157
}
2114121158

21159+
2114221160
ZEND_VM_TAIL_CALL(zend_leave_helper_SPEC(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU));
2114321161
}
2114421162

@@ -37670,6 +37688,7 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_RETURN_SPEC_CV_HAN
3767037688
}
3767137689
}
3767237690

37691+
3767337692
ZEND_VM_TAIL_CALL(zend_leave_helper_SPEC(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU));
3767437693
}
3767537694

@@ -54736,6 +54755,7 @@ ZEND_API void execute_ex(zend_execute_data *ex)
5473654755
}
5473754756
}
5473854757

54758+
5473954759
goto zend_leave_helper_SPEC_LABEL;
5474054760
}
5474154761

@@ -54809,6 +54829,7 @@ ZEND_API void execute_ex(zend_execute_data *ex)
5480954829
}
5481054830
}
5481154831
}
54832+
SAVE_OPLINE();
5481254833
zend_observer_fcall_end(execute_data, return_value);
5481354834
goto zend_leave_helper_SPEC_LABEL;
5481454835
}
@@ -56344,6 +56365,7 @@ ZEND_API void execute_ex(zend_execute_data *ex)
5634456365
}
5634556366
}
5634656367

56368+
5634756369
goto zend_leave_helper_SPEC_LABEL;
5634856370
}
5634956371

@@ -56642,6 +56664,7 @@ ZEND_API void execute_ex(zend_execute_data *ex)
5664256664
}
5664356665
}
5664456666

56667+
5664556668
goto zend_leave_helper_SPEC_LABEL;
5664656669
}
5664756670

@@ -57756,6 +57779,7 @@ ZEND_API void execute_ex(zend_execute_data *ex)
5775657779
}
5775757780
}
5775857781

57782+
5775957783
goto zend_leave_helper_SPEC_LABEL;
5776057784
}
5776157785

Zend/zend_vm_gen.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,7 @@ function gen_code($f, $spec, $kind, $code, $op1, $op2, $name, $extra_spec=null)
794794
($extra_spec['ISSET'] == 0 ? "\\0" : "opline->extended_value")
795795
: "\\0",
796796
"/ZEND_OBSERVER_ENABLED/" => isset($extra_spec['OBSERVER']) && $extra_spec['OBSERVER'] == 1 ? "1" : "0",
797+
"/ZEND_OBSERVER_SAVE_OPLINE\(\)/" => isset($extra_spec['OBSERVER']) && $extra_spec['OBSERVER'] == 1 ? "SAVE_OPLINE()" : "",
797798
"/ZEND_OBSERVER_FCALL_BEGIN\(\s*(.*)\s*\)/" => isset($extra_spec['OBSERVER']) ?
798799
($extra_spec['OBSERVER'] == 0 ? "" : "zend_observer_fcall_begin(\\1)")
799800
: "",

ext/zend_test/test.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ ZEND_BEGIN_MODULE_GLOBALS(zend_test)
3737
int observer_show_return_type;
3838
int observer_show_return_value;
3939
int observer_show_init_backtrace;
40+
int observer_show_opcode;
4041
int observer_nesting_depth;
4142
ZEND_END_MODULE_GLOBALS(zend_test)
4243

@@ -330,6 +331,7 @@ PHP_INI_BEGIN()
330331
STD_PHP_INI_BOOLEAN("zend_test.observer.show_return_type", "0", PHP_INI_SYSTEM, OnUpdateBool, observer_show_return_type, zend_zend_test_globals, zend_test_globals)
331332
STD_PHP_INI_BOOLEAN("zend_test.observer.show_return_value", "0", PHP_INI_SYSTEM, OnUpdateBool, observer_show_return_value, zend_zend_test_globals, zend_test_globals)
332333
STD_PHP_INI_BOOLEAN("zend_test.observer.show_init_backtrace", "0", PHP_INI_SYSTEM, OnUpdateBool, observer_show_init_backtrace, zend_zend_test_globals, zend_test_globals)
334+
STD_PHP_INI_BOOLEAN("zend_test.observer.show_opcode", "0", PHP_INI_SYSTEM, OnUpdateBool, observer_show_opcode, zend_zend_test_globals, zend_test_globals)
333335
PHP_INI_END()
334336

335337
static zend_observer_fcall_handlers observer_fcall_init(zend_execute_data *execute_data);
@@ -441,6 +443,14 @@ PHP_MSHUTDOWN_FUNCTION(zend_test)
441443
return SUCCESS;
442444
}
443445

446+
static void observer_show_opcode(zend_execute_data *execute_data)
447+
{
448+
if (!ZT_G(observer_show_opcode)) {
449+
return;
450+
}
451+
php_printf("%*s<!-- opcode: '%s' -->\n", 2 * ZT_G(observer_nesting_depth), "", zend_get_opcode_name(EX(opline)->opcode));
452+
}
453+
444454
static void observer_begin(zend_execute_data *execute_data)
445455
{
446456
if (!ZT_G(observer_show_output)) {
@@ -457,6 +467,7 @@ static void observer_begin(zend_execute_data *execute_data)
457467
php_printf("%*s<file '%s'>\n", 2 * ZT_G(observer_nesting_depth), "", ZSTR_VAL(execute_data->func->op_array.filename));
458468
}
459469
ZT_G(observer_nesting_depth)++;
470+
observer_show_opcode(execute_data);
460471
}
461472

462473
static void get_retval_info(zval *retval, smart_str *buf)
@@ -485,6 +496,7 @@ static void observer_end(zend_execute_data *execute_data, zval *retval)
485496
if (EG(exception)) {
486497
php_printf("%*s<!-- Exception: %s -->\n", 2 * ZT_G(observer_nesting_depth), "", ZSTR_VAL(EG(exception)->ce->name));
487498
}
499+
observer_show_opcode(execute_data);
488500
ZT_G(observer_nesting_depth)--;
489501
if (execute_data->func && execute_data->func->common.function_name) {
490502
smart_str retval_info = {0};
@@ -541,6 +553,7 @@ static zend_observer_fcall_handlers observer_fcall_init(zend_execute_data *execu
541553
if (ZT_G(observer_show_init_backtrace)) {
542554
observer_show_init_backtrace(execute_data);
543555
}
556+
observer_show_opcode(execute_data);
544557
}
545558

546559
if (ZT_G(observer_observe_all)) {

0 commit comments

Comments
 (0)