]> granicus.if.org Git - php/commitdiff
Fix phpdbg_break_next() and add test
authorBob Weinand <bobwei9@hotmail.com>
Sun, 23 Aug 2015 10:58:32 +0000 (11:58 +0100)
committerBob Weinand <bobwei9@hotmail.com>
Sun, 23 Aug 2015 10:58:45 +0000 (11:58 +0100)
sapi/phpdbg/phpdbg.c
sapi/phpdbg/phpdbg_bp.c
sapi/phpdbg/tests/phpdbg_break_next.phpt [new file with mode: 0644]

index 4c5dfdea224954c98792d5b1766058b666ba2a2b..8a22ea29ca500c2ad9fcd2581d14411ca5f89bec 100644 (file)
@@ -155,6 +155,11 @@ static void php_phpdbg_destroy_bp_opcode(zval *brake) /* {{{ */
        efree(Z_PTR_P(brake));
 } /* }}} */
 
+static void php_phpdbg_destroy_bp_opline(zval *brake) /* {{{ */
+{
+       efree(Z_PTR_P(brake));
+} /* }}} */
+
 static void php_phpdbg_destroy_bp_methods(zval *brake) /* {{{ */
 {
        zend_hash_destroy(Z_ARRVAL_P(brake));
@@ -188,7 +193,7 @@ static PHP_RINIT_FUNCTION(phpdbg) /* {{{ */
        zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE], 8, NULL, php_phpdbg_destroy_bp_methods, 0);
        zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE], 8, NULL, php_phpdbg_destroy_bp_methods, 0);
        zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE], 8, NULL, php_phpdbg_destroy_bp_methods, 0);
-       zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], 8, NULL, NULL, 0);
+       zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], 8, NULL, php_phpdbg_destroy_bp_opline, 0);
        zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE], 8, NULL, php_phpdbg_destroy_bp_opcode, 0);
        zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], 8, NULL, php_phpdbg_destroy_bp_methods, 0);
        zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], 8, NULL, php_phpdbg_destroy_bp_condition, 0);
@@ -302,11 +307,17 @@ static PHP_FUNCTION(phpdbg_exec)
     instructs phpdbg to insert a breakpoint at the next opcode */
 static PHP_FUNCTION(phpdbg_break_next)
 {
-       if (zend_parse_parameters_none() == FAILURE && EG(current_execute_data)) {
+       zend_execute_data *ex = EG(current_execute_data);
+
+       while (ex && ex->func && !ZEND_USER_CODE(ex->func->type)) {
+               ex = ex->prev_execute_data;
+       }
+
+       if (zend_parse_parameters_none() == FAILURE || !ex) {
                return;
        }
 
-       phpdbg_set_breakpoint_opline_ex((phpdbg_opline_ptr_t) EG(current_execute_data)->opline + 1);
+       phpdbg_set_breakpoint_opline_ex((phpdbg_opline_ptr_t) ex->opline + 1);
 } /* }}} */
 
 /* {{{ proto void phpdbg_break_file(string file, integer line) */
index 7e8292b06639e1605867be358e9cf7c979587704..c90623a03be98e6f53b3ffad9be13032fa51e141 100644 (file)
@@ -212,6 +212,8 @@ PHPDBG_API void phpdbg_export_breakpoints_to_string(char **str) /* {{{ */
                                                                phpdbg_asprintf(&new_str, "%sbreak if %s\n", str, conditional->code);
                                                        }
                                                } break;
+
+                                               default: continue;
                                        }
 
                                        if ((*str)[0]) {
@@ -784,6 +786,7 @@ PHPDBG_API void phpdbg_set_breakpoint_opline_ex(phpdbg_opline_ptr_t opline) /* {
 
                PHPDBG_BREAK_INIT(new_break, PHPDBG_BREAK_OPLINE);
                new_break.opline = (zend_ulong) opline;
+               new_break.base = NULL;
 
                zend_hash_index_update_mem(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], (zend_ulong) opline, &new_break, sizeof(phpdbg_breakline_t));
 
diff --git a/sapi/phpdbg/tests/phpdbg_break_next.phpt b/sapi/phpdbg/tests/phpdbg_break_next.phpt
new file mode 100644 (file)
index 0000000..37ee2e8
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--
+Test phpdbg_break_next() function
+--PHPDBG--
+r
+c
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> A
+[Breakpoint #0 added at %s]
+[Breakpoint #0 in %s at %s:5, hits: 1]
+>00005: echo 'B';
+ 00006: 
+prompt> B
+[Script ended normally]
+prompt> 
+--FILE--
+<?php
+
+echo 'A';
+phpdbg_break_next();
+echo 'B';