]> granicus.if.org Git - php/commitdiff
implement 5.4 support
authorkrakjoe <joe.watkins@live.co.uk>
Fri, 15 Nov 2013 11:19:26 +0000 (11:19 +0000)
committerkrakjoe <joe.watkins@live.co.uk>
Fri, 15 Nov 2013 11:19:26 +0000 (11:19 +0000)
phpdbg.c
phpdbg_opcode.c
phpdbg_prompt.c
phpdbg_prompt.h
phpdbg_utils.h

index 0b4e1c7362a8cdc4403cb406d6520a846baafe00..831fc56077cb3670cdda900f6874ae75ed1e9aeb 100644 (file)
--- a/phpdbg.c
+++ b/phpdbg.c
 
 ZEND_DECLARE_MODULE_GLOBALS(phpdbg);
 
+#if PHP_VERSION_ID >= 50500
 void (*zend_execute_old)(zend_execute_data *execute_data TSRMLS_DC);
-void (*zend_execute_internal_old)(zend_execute_data *execute_data_ptr, zend_fcall_info *fci, int return_value_used TSRMLS_DC);
+#else
+void (*zend_execute_old)(zend_op_array *op_array TSRMLS_DC);
+#endif
 
 static inline void php_phpdbg_globals_ctor(zend_phpdbg_globals *pg) /* {{{ */
 {
@@ -43,9 +46,13 @@ static inline void php_phpdbg_globals_ctor(zend_phpdbg_globals *pg) /* {{{ */
 static PHP_MINIT_FUNCTION(phpdbg) /* {{{ */
 {
     ZEND_INIT_MODULE_GLOBALS(phpdbg, php_phpdbg_globals_ctor, NULL);
-
+#if PHP_VERSION_ID >= 50500
     zend_execute_old = zend_execute_ex;
     zend_execute_ex = phpdbg_execute_ex;
+#else
+    zend_execute_old = zend_execute;
+    zend_execute = phpdbg_execute_ex;
+#endif
 
     return SUCCESS;
 } /* }}} */
index 39a51692b19df8c5297fecee71f70062dfce8d82..fe9470f5d870d5df6b9aa47da8efa21b6e7b1cbb 100644 (file)
@@ -178,9 +178,15 @@ const char *phpdbg_decode_opcode(zend_uchar opcode) /* {{{ */
 #ifdef ZEND_JMP_SET_VAR
                CASE(ZEND_JMP_SET_VAR);
 #endif
+#ifdef ZEND_DISCARD_EXCEPTION
                CASE(ZEND_DISCARD_EXCEPTION);
+#endif
+#ifdef ZEND_YIELD
                CASE(ZEND_YIELD);
-               CASE(ZEND_GENERATOR_RETURN);
+#endif
+#ifdef ZEND_GENERATOR_RETURN
+        CASE(ZEND_GENERATOR_RETURN);
+#endif
 #ifdef ZEND_FAST_CALL
                CASE(ZEND_FAST_CALL);
 #endif
index a7f689bb8e8659d3481d829e33ccd6059d09af4a..3d693afa58947e2ee9bc81e364684fddf0a2e453 100644 (file)
@@ -298,9 +298,10 @@ static PHPDBG_COMMAND(eval) /* {{{ */
        PHPDBG_G(flags) |= PHPDBG_IN_EVAL;
        if (zend_eval_stringl((char*)expr, expr_len,
                &retval, "eval()'d code" TSRMLS_CC) == SUCCESS) {
-               zend_print_zval_r(&retval, 0 TSRMLS_CC);
-               zval_dtor(&retval);
+               zend_print_zval_r(
+                   &retval, 0 TSRMLS_CC);
                phpdbg_writeln(EMPTY);
+               zval_dtor(&retval);
        }
        PHPDBG_G(flags) &= ~PHPDBG_IN_EVAL;
 
@@ -742,14 +743,16 @@ void phpdbg_print_opline(zend_execute_data *execute_data, zend_bool ignore_flags
              /* output line info */
                    phpdbg_notice("#%lu %p %s %s",
                opline->lineno,
-               opline, phpdbg_decode_opcode(opline->opcode),
+               opline, 
+               phpdbg_decode_opcode(opline->opcode),
                execute_data->op_array->filename ? execute_data->op_array->filename : "unknown");
         }
 
         if (!ignore_flags && PHPDBG_G(oplog)) {
             phpdbg_log_ex(PHPDBG_G(oplog), "#%lu %p %s %s",
                 opline->lineno,
-                opline, phpdbg_decode_opcode(opline->opcode),
+                opline, 
+                phpdbg_decode_opcode(opline->opcode),
                 execute_data->op_array->filename ? execute_data->op_array->filename : "unknown");
         }
     }
@@ -772,16 +775,96 @@ void phpdbg_clean(zend_bool full TSRMLS_DC) /* {{{ */
     }
 } /* }}} */
 
+static inline zend_execute_data *phpdbg_create_execute_data(zend_op_array *op_array, zend_bool nested TSRMLS_DC) /* {{{ */
+{
+#if PHP_VERSION_ID >= 50500
+    return zend_create_execute_data_from_op_array(op_array, nested TSRMLS_CC);
+#else
+
+#undef EX
+#define EX(element) execute_data->element
+#undef EX_CV
+#define EX_CV(var) EX(CVs)[var]
+#undef EX_CVs
+#define EX_CVs() EX(CVs)
+#undef EX_T
+#define EX_T(offset) (*(temp_variable *)((char *) EX(Ts) + offset))
+#undef EX_Ts
+#define EX_Ts() EX(Ts)
+
+    zend_execute_data *execute_data = (zend_execute_data *)zend_vm_stack_alloc(
+               ZEND_MM_ALIGNED_SIZE(sizeof(zend_execute_data)) +
+               ZEND_MM_ALIGNED_SIZE(sizeof(zval**) * op_array->last_var * (EG(active_symbol_table) ? 1 : 2)) +
+               ZEND_MM_ALIGNED_SIZE(sizeof(temp_variable)) * op_array->T TSRMLS_CC);
+
+       EX(CVs) = (zval***)((char*)execute_data + ZEND_MM_ALIGNED_SIZE(sizeof(zend_execute_data)));
+       memset(EX(CVs), 0, sizeof(zval**) * op_array->last_var);
+       EX(Ts) = (temp_variable *)(((char*)EX(CVs)) + ZEND_MM_ALIGNED_SIZE(sizeof(zval**) * op_array->last_var * (EG(active_symbol_table) ? 1 : 2)));
+       EX(fbc) = NULL;
+       EX(called_scope) = NULL;
+       EX(object) = NULL;
+       EX(old_error_reporting) = NULL;
+       EX(op_array) = op_array;
+       EX(symbol_table) = EG(active_symbol_table);
+       EX(prev_execute_data) = EG(current_execute_data);
+       EG(current_execute_data) = execute_data;
+       EX(nested) = nested;
+
+       if (!op_array->run_time_cache && op_array->last_cache_slot) {
+               op_array->run_time_cache = ecalloc(op_array->last_cache_slot, sizeof(void*));
+       }
+
+       if (op_array->this_var != -1 && EG(This)) {
+               Z_ADDREF_P(EG(This)); /* For $this pointer */
+               if (!EG(active_symbol_table)) {
+                       EX_CV(op_array->this_var) = (zval**)EX_CVs() + (op_array->last_var + op_array->this_var);
+                       *EX_CV(op_array->this_var) = EG(This);
+               } else {
+                       if (zend_hash_add(EG(active_symbol_table), "this", sizeof("this"), &EG(This), sizeof(zval *), (void**)&EX_CV(op_array->this_var))==FAILURE) {
+                               Z_DELREF_P(EG(This));
+                       }
+               }
+       }
+
+       EX(opline) = UNEXPECTED((op_array->fn_flags & ZEND_ACC_INTERACTIVE) != 0) && EG(start_op) ? EG(start_op) : op_array->opcodes;
+       EG(opline_ptr) = &EX(opline);
+
+       EX(function_state).function = (zend_function *) op_array;
+       EX(function_state).arguments = NULL;
+       
+       return execute_data;
+#endif
+} /* }}} */
+
+#if PHP_VERSION_ID >= 50500
 void phpdbg_execute_ex(zend_execute_data *execute_data TSRMLS_DC) /* {{{ */
 {
+#else
+void phpdbg_execute_ex(zend_op_array *op_array TSRMLS_DC) /* {{{ */
+{
+    zend_execute_data *execute_data;
+    zend_bool nested = 0;
+#endif
        zend_bool original_in_execution = EG(in_execution);
 
+#if PHP_VERSION_ID < 50500
+    if (EG(exception)) {
+        return;
+    }
+#endif
+
        EG(in_execution) = 1;
 
+#if PHP_VERSION_ID >= 50500
        if (0) {
 zend_vm_enter:
-               execute_data = zend_create_execute_data_from_op_array(EG(active_op_array), 1 TSRMLS_CC);
+               execute_data = phpdbg_create_execute_data(EG(active_op_array), 1 TSRMLS_CC);
        }
+#else
+zend_vm_enter:
+        execute_data = phpdbg_create_execute_data(op_array, nested TSRMLS_CC);
+        nested = 1;
+#endif
 
        while (1) {
 #ifdef ZEND_WIN32
@@ -853,6 +936,9 @@ next:
                     EG(in_execution) = original_in_execution;
                     return;
                 case 2:
+#if PHP_VERSION_ID < 50500
+                    op_array = EG(active_op_array);
+#endif
                     goto zend_vm_enter;
                     break;
                 case 3:
index 1f6afc207d7f1f488cffbb921a9a0d657b585734..690d767693496ce07f6f431a905607d0fcb3a3f4 100644 (file)
@@ -64,8 +64,13 @@ int phpdbg_do_cmd(const phpdbg_command_t *command, char *cmd_line, size_t cmd_le
 void phpdbg_init(char *init_file, size_t init_file_len, zend_bool use_default TSRMLS_DC);
 void phpdbg_welcome(zend_bool cleaning TSRMLS_DC);
 int phpdbg_interactive(TSRMLS_D);
-void phpdbg_execute_ex(zend_execute_data *execute_data TSRMLS_DC);
 void phpdbg_print_opline(zend_execute_data *execute_data, zend_bool ignore_flags TSRMLS_DC);
 void phpdbg_clean(zend_bool full TSRMLS_DC);
 
+#if PHP_VERSION_ID >= 50500
+void phpdbg_execute_ex(zend_execute_data *execute_data TSRMLS_DC);
+#else
+void phpdbg_execute_ex(zend_op_array *op_array TSRMLS_DC);
+#endif
+
 #endif /* PHPDBG_PROMPT_H */
index 57fa23c509b3db576c3f6c18736c2cf38605ecf8..4174f164129af0e586204235bb321bea5c7b52d6 100644 (file)
@@ -72,11 +72,11 @@ enum {
 
 int phpdbg_print(int TSRMLS_DC, FILE*, const char*, ...);
 
-#define phpdbg_error(fmt, ...)              phpdbg_print(P_ERROR   TSRMLS_CC, stderr, fmt, ##__VA_ARGS__)
-#define phpdbg_notice(fmt, ...)             phpdbg_print(P_NOTICE  TSRMLS_CC, stderr, fmt, ##__VA_ARGS__)
-#define phpdbg_writeln(fmt, ...)            phpdbg_print(P_WRITELN TSRMLS_CC, stderr, fmt, ##__VA_ARGS__)
-#define phpdbg_write(fmt, ...)              phpdbg_print(P_WRITE   TSRMLS_CC, stderr, fmt, ##__VA_ARGS__)
-#define phpdbg_log(fmt, ...)                phpdbg_print(P_LOG     TSRMLS_CC, stderr, fmt, ##__VA_ARGS__)
+#define phpdbg_error(fmt, ...)              phpdbg_print(P_ERROR   TSRMLS_CC, stdout, fmt, ##__VA_ARGS__)
+#define phpdbg_notice(fmt, ...)             phpdbg_print(P_NOTICE  TSRMLS_CC, stdout, fmt, ##__VA_ARGS__)
+#define phpdbg_writeln(fmt, ...)            phpdbg_print(P_WRITELN TSRMLS_CC, stdout, fmt, ##__VA_ARGS__)
+#define phpdbg_write(fmt, ...)              phpdbg_print(P_WRITE   TSRMLS_CC, stdout, fmt, ##__VA_ARGS__)
+#define phpdbg_log(fmt, ...)                phpdbg_print(P_LOG     TSRMLS_CC, stdout, fmt, ##__VA_ARGS__)
 
 #define phpdbg_error_ex(out, fmt, ...)      phpdbg_print(P_ERROR   TSRMLS_CC, out, fmt, ##__VA_ARGS__)
 #define phpdbg_notice_ex(out, fmt, ...)     phpdbg_print(P_NOTICE  TSRMLS_CC, out, fmt, ##__VA_ARGS__)