@@ -443,16 +443,54 @@ static PHP_FUNCTION(phpdbg_start_oplog)
443
443
PHPDBG_G (oplog_list )-> start = PHPDBG_G (oplog_cur );
444
444
}
445
445
446
+ static void phpdbg_oplog_fill_executable (zend_op_array * op_array , HashTable * insert_ht , zend_bool by_opcode ) {
447
+ /* ignore RECV_* opcodes */
448
+ zend_op * cur = op_array -> opcodes + op_array -> num_args + !!(op_array -> fn_flags & ZEND_ACC_VARIADIC );
449
+ zend_op * end = op_array -> opcodes + op_array -> last ;
450
+
451
+ zend_long insert_idx ;
452
+ zval zero ;
453
+ ZVAL_LONG (& zero , 0 );
454
+
455
+ /* ignore autogenerated return (well, not too precise with finally branches, but that's okay) */
456
+ if (op_array -> last > 1 && (end - 1 )-> opcode == ZEND_RETURN && ((end - 2 )-> opcode == ZEND_RETURN || (end - 2 )-> opcode == ZEND_GENERATOR_RETURN || (end - 2 )-> opcode == ZEND_THROW )) {
457
+ end -- ;
458
+ }
459
+
460
+ for (; cur < end ; cur ++ ) {
461
+ if (cur -> opcode == ZEND_NOP || cur -> opcode == ZEND_OP_DATA || cur -> opcode == ZEND_FE_FREE || cur -> opcode == ZEND_FREE || cur -> opcode == ZEND_ASSERT_CHECK
462
+ || cur -> opcode == ZEND_DECLARE_CONST || cur -> opcode == ZEND_DECLARE_CLASS || cur -> opcode == ZEND_DECLARE_INHERITED_CLASS || cur -> opcode == ZEND_DECLARE_FUNCTION
463
+ || cur -> opcode == ZEND_DECLARE_INHERITED_CLASS_DELAYED || cur -> opcode == ZEND_VERIFY_ABSTRACT_CLASS || cur -> opcode == ZEND_ADD_TRAIT || cur -> opcode == ZEND_BIND_TRAITS
464
+ || cur -> opcode == ZEND_DECLARE_ANON_CLASS || cur -> opcode == ZEND_DECLARE_ANON_INHERITED_CLASS || cur -> opcode == ZEND_FAST_RET || cur -> opcode == ZEND_TICKS
465
+ || cur -> opcode == ZEND_EXT_STMT || cur -> opcode == ZEND_EXT_FCALL_BEGIN || cur -> opcode == ZEND_EXT_FCALL_END || cur -> opcode == ZEND_EXT_NOP || cur -> opcode == ZEND_BIND_GLOBAL ) {
466
+ continue ;
467
+ }
468
+
469
+ if (by_opcode ) {
470
+ insert_idx = cur - op_array -> opcodes ;
471
+ } else {
472
+ insert_idx = cur -> lineno ;
473
+ }
474
+
475
+ if (cur -> opcode == ZEND_NEW && (cur + 1 )-> opcode == ZEND_DO_FCALL ) {
476
+ cur ++ ;
477
+ }
478
+
479
+ zend_hash_index_update (insert_ht , insert_idx , & zero );
480
+ }
481
+ }
482
+
446
483
/* {{{ proto void phpdbg_end_oplog() */
447
484
static PHP_FUNCTION (phpdbg_end_oplog )
448
485
{
449
- phpdbg_oplog_entry * cur = PHPDBG_G ( oplog_list ) -> start ;
450
- phpdbg_oplog_list * prev = PHPDBG_G ( oplog_list ) -> prev ;
486
+ phpdbg_oplog_entry * cur ;
487
+ phpdbg_oplog_list * prev ;
451
488
452
489
HashTable * options = NULL ;
453
490
zval * option_buffer ;
454
491
zend_bool by_function = 0 ;
455
492
zend_bool by_opcode = 0 ;
493
+ zend_bool show_unexecuted = 0 ;
456
494
457
495
if (zend_parse_parameters (ZEND_NUM_ARGS (), "|H" , & options ) == FAILURE ) {
458
496
return ;
@@ -463,6 +501,9 @@ static PHP_FUNCTION(phpdbg_end_oplog)
463
501
return ;
464
502
}
465
503
504
+ cur = PHPDBG_G (oplog_list )-> start ;
505
+ prev = PHPDBG_G (oplog_list )-> prev ;
506
+
466
507
efree (PHPDBG_G (oplog_list ));
467
508
PHPDBG_G (oplog_list ) = prev ;
468
509
@@ -476,6 +517,10 @@ static PHP_FUNCTION(phpdbg_end_oplog)
476
517
}
477
518
}
478
519
520
+ if (options && (option_buffer = zend_hash_str_find (options , ZEND_STRL ("show_unexecuted" )))) {
521
+ show_unexecuted = zend_is_true (option_buffer );
522
+ }
523
+
479
524
array_init (return_value );
480
525
481
526
{
@@ -490,35 +535,51 @@ static PHP_FUNCTION(phpdbg_end_oplog)
490
535
491
536
do {
492
537
zend_op_array * op_array = cur -> op_array ;
538
+ zval zero ;
539
+ ZVAL_LONG (& zero , 0 );
540
+
493
541
if (op_array -> filename != last_file ) {
494
542
last_file = op_array -> filename ;
495
543
file_buf = zend_hash_find (Z_ARR_P (return_value ), last_file );
496
544
if (!file_buf ) {
497
545
zval ht ;
498
546
array_init (& ht );
499
547
file_buf = zend_hash_add_new (Z_ARR_P (return_value ), last_file , & ht );
548
+
549
+ if (show_unexecuted ) {
550
+ phpdbg_oplog_fill_executable (op_array , Z_ARR_P (file_buf ), by_opcode );
551
+ }
500
552
}
553
+ insert_ht = Z_ARR_P (file_buf );
501
554
}
502
- insert_ht = Z_ARR_P (file_buf );
503
555
504
556
if (by_function ) {
505
- if (op_array -> function_name != last_function || op_array -> scope != last_scope ) {
557
+ if (op_array -> function_name == NULL ) {
558
+ if (last_function != NULL ) {
559
+ insert_ht = Z_ARR_P (file_buf );
560
+ }
561
+ last_function = NULL ;
562
+ } else if (op_array -> function_name != last_function || op_array -> scope != last_scope ) {
506
563
zend_string * fn_name ;
507
564
last_function = op_array -> function_name ;
508
565
last_scope = op_array -> scope ;
509
566
if (last_scope == NULL ) {
510
- fn_name = zend_string_copy (last_function );
567
+ fn_name = zend_string_copy (last_function ? last_function : last_file );
511
568
} else {
512
- fn_name = strpprintf (ZSTR_LEN (last_function ) + ZSTR_LEN (last_scope -> name ) + 2 , "%.*s::%.*s" , ZSTR_LEN (last_function ), ZSTR_VAL (last_function ), ZSTR_LEN (last_scope -> name ), ZSTR_VAL (last_scope -> name ));
569
+ fn_name = strpprintf (ZSTR_LEN (last_function ) + ZSTR_LEN (last_scope -> name ) + 2 , "%.*s::%.*s" , ZSTR_LEN (last_scope -> name ), ZSTR_VAL (last_scope -> name ), ZSTR_LEN (last_function ), ZSTR_VAL (last_function ));
513
570
}
514
571
fn_buf = zend_hash_find (Z_ARR_P (return_value ), fn_name );
515
572
if (!fn_buf ) {
516
573
zval ht ;
517
574
array_init (& ht );
518
575
fn_buf = zend_hash_add_new (Z_ARR_P (return_value ), fn_name , & ht );
576
+
577
+ if (show_unexecuted ) {
578
+ phpdbg_oplog_fill_executable (op_array , Z_ARR_P (fn_buf ), by_opcode );
579
+ }
519
580
}
581
+ insert_ht = Z_ARR_P (fn_buf );
520
582
}
521
- insert_ht = Z_ARR_P (fn_buf );
522
583
}
523
584
524
585
if (by_opcode ) {
@@ -530,9 +591,7 @@ static PHP_FUNCTION(phpdbg_end_oplog)
530
591
{
531
592
zval * num = zend_hash_index_find (insert_ht , insert_idx );
532
593
if (!num ) {
533
- zval zv ;
534
- ZVAL_LONG (& zv , 0 );
535
- num = zend_hash_index_add_new (insert_ht , insert_idx , & zv );
594
+ num = zend_hash_index_add_new (insert_ht , insert_idx , & zero );
536
595
}
537
596
Z_LVAL_P (num )++ ;
538
597
}
@@ -1675,6 +1734,8 @@ int main(int argc, char **argv) /* {{{ */
1675
1734
goto phpdbg_out ;
1676
1735
}
1677
1736
1737
+ PG (during_request_startup ) = 0 ;
1738
+
1678
1739
phpdbg_fully_started = 1 ;
1679
1740
1680
1741
/* #ifndef for making compiler shutting up */
0 commit comments