]> granicus.if.org Git - php/commitdiff
eval()
authorkrakjoe <joe.watkins@live.co.uk>
Sun, 10 Nov 2013 14:43:46 +0000 (14:43 +0000)
committerkrakjoe <joe.watkins@live.co.uk>
Sun, 10 Nov 2013 14:43:46 +0000 (14:43 +0000)
phpdbg.c
phpdbg_help.c
phpdbg_help.h
phpdbg_prompt.c
test.php

index 1379b6b7bf208be060456b7aaace8f28d6ecd5c0..282588967fc9c160d314a7a299390a0f5e8ef480 100644 (file)
--- a/phpdbg.c
+++ b/phpdbg.c
@@ -27,6 +27,7 @@ static inline void php_phpdbg_globals_ctor(zend_phpdbg_globals *pg) {
     pg->exec = NULL;
     pg->ops = NULL;
     pg->stepping = 0;
+    pg->vmret = 0;
 }
 
 static PHP_MINIT_FUNCTION(phpdbg) {
index a72f53fd13c6ad11c4a03dfa221b60b1d0e12a10..b3971988417c03ec93d5aafb5417654a0609c3b9 100644 (file)
@@ -72,6 +72,12 @@ PHPDBG_HELP(run) /* {{{ */
     return SUCCESS;
 } /* }}} */
 
+PHPDBG_HELP(eval) /* {{{ */
+{
+    printf("Access to eval() allows you to change the environment during execution, careful though !!");
+    return SUCCESS;
+} /* }}} */
+
 PHPDBG_HELP(break) /* {{{ */
 {
   printf("doing break help: %s\n", expr);
index 69b710f782ddfea77c7c99d4245effe459b38030..7359812b700a75e070f7f594809b0146faacb0ad 100644 (file)
@@ -36,6 +36,7 @@ PHPDBG_HELP(compile);
 PHPDBG_HELP(step);
 PHPDBG_HELP(next);
 PHPDBG_HELP(run);
+PHPDBG_HELP(eval);
 PHPDBG_HELP(print);
 PHPDBG_HELP(break);
 
@@ -48,6 +49,7 @@ static const phpdbg_command_t phpdbg_help_commands[] = {
   PHPDBG_HELP_D(step,     "stepping through execution allows inspection of the opline after every opcode"),
   PHPDBG_HELP_D(next,     "execute the next opcode"),
   PHPDBG_HELP_D(run,      "execution inside the phpdbg vm allows detailed inspection and debugging"),
+  PHPDBG_HELP_D(eval,     "access to eval() allows you to affect the environment during execution"),
   PHPDBG_HELP_D(print,    "printing allows inspection of the execution environment"),
   PHPDBG_HELP_D(break,    "breakpoints allow execution interruption"),
   {NULL, 0, 0}
index 0dfe14b1befd3295bbd6b12450e6b1ce6ee67a24..326aa442a0fc823c576eb3e4ea2ad7a9b914bd45 100644 (file)
@@ -115,11 +115,27 @@ static PHPDBG_COMMAND(run) { /* {{{ */
         
         return SUCCESS;
     } else {
-        printf("Nothing to execute !");
+        printf("Nothing to execute !\n");
         return FAILURE;
     }
 } /* }}} */
 
+static PHPDBG_COMMAND(eval) { /* {{{ */
+    zval retval;
+    
+    if (expr) {
+        if (zend_eval_stringl((char*)expr, expr_len-1, &retval, "eval()'d code" TSRMLS_CC) == SUCCESS) {
+            printf("Success\n");
+            zval_dtor(&retval);
+        }
+    } else {
+        printf("No expression provided !\n");
+        return FAILURE;
+    }
+    
+    return SUCCESS;
+} /* }}} */
+
 static PHPDBG_COMMAND(print) { /* {{{ */
   if (!expr_len) {
     printf("Showing Execution Context Information:\n");
@@ -132,6 +148,10 @@ static PHPDBG_COMMAND(print) { /* {{{ */
         printf("Variables\t%d\n", PHPDBG_G(ops)->last_var-1);
       } else printf("Variables\tNone\n");
     }
+    printf("Executing\t:%s\n", EG(in_execution) ? "yes" : "no");
+    if (EG(in_execution)) {
+        printf("VM Return\t%d\n", PHPDBG_G(vmret));
+    }
   } else {
     printf(
       "%s\n", expr);
@@ -190,6 +210,7 @@ static const phpdbg_command_t phpdbg_prompt_commands[] = {
        PHPDBG_COMMAND_D(step,      "step through execution"),
        PHPDBG_COMMAND_D(next,      "next opcode"),
        PHPDBG_COMMAND_D(run,       "attempt execution"),
+       PHPDBG_COMMAND_D(eval,      "evaluate some code"),
        PHPDBG_COMMAND_D(print,     "print something"),
        PHPDBG_COMMAND_D(break,     "set breakpoint"),
        PHPDBG_COMMAND_D(help,      "show help menu"),
index 2f3600c6a0c2468fa71ee510d7c41182eb887b38..cbb2641e4faa7e9f48fcb5ca62fc2af77df5adbb 100644 (file)
--- a/test.php
+++ b/test.php
@@ -1,3 +1,6 @@
 <?php
 echo "Hello World\n";
+if (isset($greeting)) {
+    echo $greeting;
+}
 ?>