]> granicus.if.org Git - php/commitdiff
leave function + help
authorkrakjoe <joe.watkins@live.co.uk>
Sun, 17 Nov 2013 15:39:23 +0000 (15:39 +0000)
committerkrakjoe <joe.watkins@live.co.uk>
Sun, 17 Nov 2013 15:39:23 +0000 (15:39 +0000)
phpdbg.h
phpdbg_help.c
phpdbg_help.h
phpdbg_prompt.c
phpdbg_prompt.h

index 1b23039898cd3593187eb08a1ce21331572f66be..625d0af0870e3e831f6d456e8820d0cced576668 100644 (file)
--- a/phpdbg.h
+++ b/phpdbg.h
 # define PHPDBG_G(v) (phpdbg_globals.v)
 #endif
 
-#define PHPDBG_NEXT 2
+#define PHPDBG_NEXT   2
+#define PHPDBG_UNTIL  3
+#define PHPDBG_FINISH 4
+#define PHPDBG_LEAVE  5
 
 /* {{{ tables */
 #define PHPDBG_BREAK_FILE       0
index 8ae9c9468fe8de00cc41304fc5e2c9b3721fe392..fd09432de572c69fefd586326855f62f57d7b591 100644 (file)
@@ -52,7 +52,8 @@ PHPDBG_HELP(step) /* {{{ */
 PHPDBG_HELP(next) /* {{{ */
 {
     phpdbg_help_header();
-       phpdbg_writeln("While stepping through execution, or after a breakpoint, use the next command to step back into the vm and execute the next opcode");
+       phpdbg_write("While stepping through execution, or after a breakpoint, ");
+       phpdbg_writeln("use the next command to step back into the vm and execute the next opcode");
        phpdbg_help_footer();
        return SUCCESS;
 } /* }}} */
@@ -60,7 +61,8 @@ PHPDBG_HELP(next) /* {{{ */
 PHPDBG_HELP(until) /* {{{ */
 {
     phpdbg_help_header();
-       phpdbg_writeln("While stepping through execution, or after a breakpoint, use the until command to step back into the vm and reaches the next source line");
+       phpdbg_write("While stepping through execution, or after a breakpoint, ");
+       phpdbg_writeln("use the until command to step back into the vm and reaches the next source line");
        phpdbg_help_footer();
        return SUCCESS;
 } /* }}} */
@@ -68,7 +70,19 @@ PHPDBG_HELP(until) /* {{{ */
 PHPDBG_HELP(finish) /* {{{ */
 {
     phpdbg_help_header();
-       phpdbg_writeln("While stepping through execution, or after a breakpoint, use the finish command to step back into the vm and continue until the current function has returned");
+       phpdbg_write("While stepping through execution, or after a breakpoint, ");
+       phpdbg_writeln("use the finish command to step back into the vm and continue until the current scope has returned");
+       phpdbg_writeln("Note: this allows all breakpoints that would otherwise break execution in the current scope to be skipped");
+       phpdbg_help_footer();
+       return SUCCESS;
+} /* }}} */
+
+PHPDBG_HELP(leave) /* {{{ */
+{
+    phpdbg_help_header();
+       phpdbg_write("While stepping through execution, or after a breakpoint, ");
+       phpdbg_writeln("use the finish command to step back into the vm and continue until the current scope is returning");
+       phpdbg_writeln("Note: this allows inspection of the return value from any scope before it is returned");
        phpdbg_help_footer();
        return SUCCESS;
 } /* }}} */
index 758e501b1a73e7a17c02347f24237b4bbb494c03..e73782b4d1dca5f7f2f272989bdfa3547db6e104 100644 (file)
@@ -42,6 +42,7 @@ PHPDBG_HELP(run);
 PHPDBG_HELP(eval);
 PHPDBG_HELP(until);
 PHPDBG_HELP(finish);
+PHPDBG_HELP(leave);
 PHPDBG_HELP(print);
 PHPDBG_HELP(break);
 PHPDBG_HELP(clean);
@@ -63,6 +64,7 @@ static const phpdbg_command_t phpdbg_help_commands[] = {
        PHPDBG_HELP_D(eval,     "access to eval() allows you to affect the environment during execution", 'E'),
        PHPDBG_HELP_D(until,    "continue until the program reaches a source line different than the current one", 'u'),
        PHPDBG_HELP_D(finish,   "continue until the current function has returned", 'f'),
+       PHPDBG_HELP_D(leave,    "continue until the current function is returning", 'L'),
        PHPDBG_HELP_D(print,    "printing allows inspection of the execution environment", 'p'),
        PHPDBG_HELP_D(break,    "breakpoints allow execution interruption", 'b'),
        PHPDBG_HELP_D(clean,    "resetting the environment is useful while debugging and recompiling", 'X'),
index 069f92a7c3acff44451655ba0aae22f5be07fcda..c57b16709d5417ed72a29baf673518d2d1d29dd5 100644 (file)
@@ -39,6 +39,7 @@ static PHPDBG_COMMAND(run);
 static PHPDBG_COMMAND(eval);
 static PHPDBG_COMMAND(until);
 static PHPDBG_COMMAND(finish);
+static PHPDBG_COMMAND(leave);
 static PHPDBG_COMMAND(print);
 static PHPDBG_COMMAND(break);
 static PHPDBG_COMMAND(back);
@@ -60,7 +61,8 @@ static const phpdbg_command_t phpdbg_prompt_commands[] = {
        PHPDBG_COMMAND_EX_D(run,        "attempt execution",                        'r'),
        PHPDBG_COMMAND_EX_D(eval,       "evaluate some code",                       'E'),
        PHPDBG_COMMAND_EX_D(until,      "continue until reaches next line",         'u'),
-       PHPDBG_COMMAND_EX_D(finish,      "continue until reaches next line",        'f'),
+       PHPDBG_COMMAND_EX_D(finish,     "continue past the end of the stack",       'f'),
+       PHPDBG_COMMAND_EX_D(leave,      "continue until the end of the stack",      'L'),
        PHPDBG_COMMANDS_D(print,        "print something",                          'p', phpdbg_print_commands),
        PHPDBG_COMMANDS_D(break,        "set breakpoint",                           'b', phpdbg_break_commands),
        PHPDBG_COMMAND_EX_D(back,       "show trace",                               't'),
@@ -315,6 +317,11 @@ static PHPDBG_COMMAND(finish) /* {{{ */
        return PHPDBG_FINISH;
 } /* }}} */
 
+static PHPDBG_COMMAND(leave) /* {{{ */
+{
+       return PHPDBG_LEAVE;
+} /* }}} */
+
 static PHPDBG_COMMAND(run) /* {{{ */
 {
        if (EG(in_execution)) {
@@ -830,7 +837,8 @@ int phpdbg_interactive(TSRMLS_D) /* {{{ */
                                                phpdbg_error("Failed to execute %s!", cmd);
                                        }
                                break;
-
+       
+                               case PHPDBG_LEAVE:
                                case PHPDBG_FINISH:
                                case PHPDBG_UNTIL:
                                case PHPDBG_NEXT: {
@@ -1024,6 +1032,7 @@ zend_vm_enter:
        \
        do {\
                switch (last_step = phpdbg_interactive(TSRMLS_C)) {\
+                       case PHPDBG_LEAVE:\
                        case PHPDBG_FINISH:\
                        case PHPDBG_UNTIL:\
                        case PHPDBG_NEXT:{\
@@ -1039,6 +1048,7 @@ zend_vm_enter:
                        goto next;
                }
                
+               /* run to next line */
                if (last_step == PHPDBG_UNTIL
                        && last_file == execute_data->op_array->filename
                        && last_lineno == execute_data->opline->lineno) {
@@ -1046,6 +1056,7 @@ zend_vm_enter:
                        goto next;
                }
                
+               /* run to finish */
                if (last_step == PHPDBG_FINISH) {
                        if (execute_data->opline < last_op) {
                                /* skip possible breakpoints */
@@ -1055,11 +1066,26 @@ zend_vm_enter:
                                last_op = NULL;
                        }
                }
+               
+               /* break for leave */
+               if (last_step == PHPDBG_LEAVE) {
+                       if (execute_data->opline == last_op) {
+                               phpdbg_notice(
+                                       "Breaking for leave at %s:%u",
+                                       zend_get_executed_filename(TSRMLS_C),
+                                       zend_get_executed_lineno(TSRMLS_C)
+                               );
+                               DO_INTERACTIVE();
+                       } else {
+                               /* skip possible breakpoints */
+                               goto next;
+                       }
+               }
 
                /* not while in conditionals */
                phpdbg_print_opline(
                        execute_data, 0 TSRMLS_CC);
-
+               
                /* conditions cannot be executed by eval()'d code */
                if (!(PHPDBG_G(flags) & PHPDBG_IN_EVAL)
                        && (PHPDBG_G(flags) & PHPDBG_HAS_COND_BP)
@@ -1102,9 +1128,19 @@ zend_vm_enter:
 next:
                last_lineno = execute_data->opline->lineno;
                last_file   = execute_data->op_array->filename;
-
-               if (last_step == PHPDBG_FINISH && !last_op) {
-                       last_op = &execute_data->op_array->opcodes[execute_data->op_array->last-1];
+               
+               switch (last_step) {
+                       case PHPDBG_FINISH:
+                               if (!last_op) {
+                                       last_op = &execute_data->op_array->opcodes[execute_data->op_array->last-1];
+                               }
+                       break;
+                       
+                       case PHPDBG_LEAVE:
+                               if (!last_op) {
+                                       last_op = &execute_data->op_array->opcodes[execute_data->op_array->last-2];     
+                               }
+                       break;
                }
 
         PHPDBG_G(vmret) = execute_data->opline->handler(execute_data TSRMLS_CC);
index e4e45dd1c4a0aeb42ecfd695830b726df4fd0f71..65148e349779ebdc6a9b53a71c35e92da9734c01 100644 (file)
 
 #define PHPDBG_STRL(s) s, sizeof(s)-1
 
-#define PHPDBG_NEXT   2
-#define PHPDBG_UNTIL  3
-#define PHPDBG_FINISH 4
-
 /**
  * Command Executor
  */