summaryrefslogtreecommitdiff
path: root/sapi/phpdbg/phpdbg_prompt.c
diff options
context:
space:
mode:
Diffstat (limited to 'sapi/phpdbg/phpdbg_prompt.c')
-rw-r--r--sapi/phpdbg/phpdbg_prompt.c392
1 files changed, 116 insertions, 276 deletions
diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c
index 5e2cc03d50..7ce0cea363 100644
--- a/sapi/phpdbg/phpdbg_prompt.c
+++ b/sapi/phpdbg/phpdbg_prompt.c
@@ -22,6 +22,7 @@
#include <string.h>
#include "zend.h"
#include "zend_compile.h"
+#include "zend_exceptions.h"
#include "phpdbg.h"
#include "phpdbg_help.h"
@@ -104,20 +105,18 @@ static inline int phpdbg_call_register(phpdbg_param_t *stack TSRMLS_DC) /* {{{ *
lc_name = zend_str_tolower_dup(name->str, name->len);
- if (zend_hash_exists(&PHPDBG_G(registered), lc_name, name->len+1)) {
- zval fname, *fretval;
+ if (zend_hash_str_exists(&PHPDBG_G(registered), lc_name, name->len)) {
+ zval fretval;
zend_fcall_info fci;
- ZVAL_STRINGL(&fname, lc_name, name->len, 1);
-
memset(&fci, 0, sizeof(zend_fcall_info));
+ ZVAL_STRINGL(&fci.function_name, lc_name, name->len);
fci.size = sizeof(zend_fcall_info);
fci.function_table = &PHPDBG_G(registered);
- fci.function_name = &fname;
- fci.symbol_table = EG(active_symbol_table);
- fci.object_ptr = NULL;
- fci.retval_ptr_ptr = &fretval;
+ fci.symbol_table = zend_rebuild_symbol_table(TSRMLS_C);
+ fci.object = NULL;
+ fci.retval = &fretval;
fci.no_separation = 1;
if (name->next) {
@@ -133,7 +132,7 @@ static inline int phpdbg_call_register(phpdbg_param_t *stack TSRMLS_DC) /* {{{ *
case OP_PARAM:
case COND_PARAM:
case STR_PARAM:
- add_next_index_stringl(&params, next->str, next->len, 1);
+ add_next_index_stringl(&params, next->str, next->len);
break;
case NUMERIC_PARAM:
@@ -141,33 +140,28 @@ static inline int phpdbg_call_register(phpdbg_param_t *stack TSRMLS_DC) /* {{{ *
break;
case METHOD_PARAM:
- spprintf(&buffered, 0, "%s::%s",
- next->method.class, next->method.name);
- add_next_index_string(&params, buffered, 0);
+ spprintf(&buffered, 0, "%s::%s", next->method.class, next->method.name);
+ add_next_index_string(&params, buffered);
break;
case NUMERIC_METHOD_PARAM:
- spprintf(&buffered, 0, "%s::%s#%ld",
- next->method.class, next->method.name, next->num);
- add_next_index_string(&params, buffered, 0);
+ spprintf(&buffered, 0, "%s::%s#%ld", next->method.class, next->method.name, next->num);
+ add_next_index_string(&params, buffered);
break;
case NUMERIC_FUNCTION_PARAM:
- spprintf(&buffered, 0, "%s#%ld",
- next->str, next->num);
- add_next_index_string(&params, buffered, 0);
+ spprintf(&buffered, 0, "%s#%ld", next->str, next->num);
+ add_next_index_string(&params, buffered);
break;
case FILE_PARAM:
- spprintf(&buffered, 0, "%s:%ld",
- next->file.name, next->file.line);
- add_next_index_string(&params, buffered, 0);
+ spprintf(&buffered, 0, "%s:%ld", next->file.name, next->file.line);
+ add_next_index_string(&params, buffered);
break;
case NUMERIC_FILE_PARAM:
- spprintf(&buffered, 0, "%s:#%ld",
- next->file.name, next->file.line);
- add_next_index_string(&params, buffered, 0);
+ spprintf(&buffered, 0, "%s:#%ld", next->file.name, next->file.line);
+ add_next_index_string(&params, buffered);
break;
default: {
@@ -189,14 +183,13 @@ static inline int phpdbg_call_register(phpdbg_param_t *stack TSRMLS_DC) /* {{{ *
phpdbg_debug("created %d params from arguments", fci.param_count);
- zend_call_function(&fci, NULL TSRMLS_CC);
-
- if (fretval) {
- zend_print_zval_r(fretval, 0 TSRMLS_CC);
+ if (zend_call_function(&fci, NULL TSRMLS_CC) == SUCCESS) {
+ zend_print_zval_r(&fretval, 0 TSRMLS_CC);
phpdbg_out("\n");
+ zval_ptr_dtor(&fretval);
}
- zval_dtor(&fname);
+ zval_dtor(&fci.function_name);
efree(lc_name);
return SUCCESS;
@@ -360,7 +353,7 @@ PHPDBG_COMMAND(exec) /* {{{ */
size_t res_len = strlen(res);
if ((res_len != PHPDBG_G(exec_len)) || (memcmp(res, PHPDBG_G(exec), res_len) != SUCCESS)) {
- if (EG(in_execution)) {
+ if (PHPDBG_G(in_execution)) {
if (phpdbg_ask_user_permission("Do you really want to stop execution to set a new execution context?" TSRMLS_CC) == FAILURE) {
return FAILURE;
}
@@ -388,7 +381,7 @@ PHPDBG_COMMAND(exec) /* {{{ */
phpdbg_notice("exec", "type=\"set\" context=\"%s\"", "Set execution context: %s", PHPDBG_G(exec));
- if (EG(in_execution)) {
+ if (PHPDBG_G(in_execution)) {
phpdbg_clean(1 TSRMLS_CC);
}
@@ -430,7 +423,7 @@ int phpdbg_compile(TSRMLS_D) /* {{{ */
PHPDBG_COMMAND(step) /* {{{ */
{
- if (EG(in_execution)) {
+ if (PHPDBG_G(in_execution)) {
PHPDBG_G(flags) |= PHPDBG_IS_STEPPING;
}
@@ -444,19 +437,19 @@ PHPDBG_COMMAND(continue) /* {{{ */
PHPDBG_COMMAND(until) /* {{{ */
{
- if (!EG(in_execution)) {
+ if (!PHPDBG_G(in_execution)) {
phpdbg_error("inactive", "type=\"noexec\"", "Not executing");
return SUCCESS;
}
PHPDBG_G(flags) |= PHPDBG_IN_UNTIL;
{
- zend_uint next = 0, self = (EG(current_execute_data)->opline - EG(active_op_array)->opcodes);
- zend_op *opline = &EG(active_op_array)->opcodes[self];
+ const zend_op *opline = EG(current_execute_data)->opline;
+ const zend_op_array *op_array = &EG(current_execute_data)->func->op_array;
- for (next = self; next < EG(active_op_array)->last; next++) {
- if (EG(active_op_array)->opcodes[next].lineno != opline->lineno) {
- zend_hash_index_update(&PHPDBG_G(seek), (zend_ulong) &EG(active_op_array)->opcodes[next], &EG(active_op_array)->opcodes[next], sizeof(zend_op), NULL);
+ while (++opline < op_array->opcodes + op_array->last) {
+ if (opline->lineno != EG(current_execute_data)->opline->lineno) {
+ zend_hash_index_update_ptr(&PHPDBG_G(seek), (zend_ulong) opline, (void *) opline);
break;
}
}
@@ -465,58 +458,46 @@ PHPDBG_COMMAND(until) /* {{{ */
return PHPDBG_UNTIL;
} /* }}} */
+static void phpdbg_seek_to_end(TSRMLS_D) {
+ const zend_op *opline = EG(current_execute_data)->opline;
+ const zend_op_array *op_array = &EG(current_execute_data)->func->op_array - 1;
+
+ while (++opline < op_array->opcodes + op_array->last) {
+ switch (opline->opcode) {
+ case ZEND_RETURN:
+ case ZEND_THROW:
+ case ZEND_EXIT:
+#ifdef ZEND_YIELD
+ case ZEND_YIELD:
+#endif
+ zend_hash_index_update_ptr(&PHPDBG_G(seek), (zend_ulong) opline, (void *) opline);
+ return;
+ }
+ }
+}
+
PHPDBG_COMMAND(finish) /* {{{ */
{
- if (!EG(in_execution)) {
+ if (!PHPDBG_G(in_execution)) {
phpdbg_error("inactive", "type=\"noexec\"", "Not executing");
return SUCCESS;
}
PHPDBG_G(flags) |= PHPDBG_IN_FINISH;
- {
- zend_uint next = 0, self = (EG(current_execute_data)->opline - EG(active_op_array)->opcodes);
-
- for (next = self; next < EG(active_op_array)->last; next++) {
- switch (EG(active_op_array)->opcodes[next].opcode) {
- case ZEND_RETURN:
- case ZEND_THROW:
- case ZEND_EXIT:
-#ifdef ZEND_YIELD
- case ZEND_YIELD:
-#endif
- zend_hash_index_update(&PHPDBG_G(seek), (zend_ulong) &EG(active_op_array)->opcodes[next], &EG(active_op_array)->opcodes[next], sizeof(zend_op), NULL);
- break;
- }
- }
- }
+ phpdbg_seek_to_end(TSRMLS_C);
return PHPDBG_FINISH;
} /* }}} */
PHPDBG_COMMAND(leave) /* {{{ */
{
- if (!EG(in_execution)) {
+ if (!PHPDBG_G(in_execution)) {
phpdbg_error("inactive", "type=\"noexec\"", "Not executing");
return SUCCESS;
}
PHPDBG_G(flags) |= PHPDBG_IN_LEAVE;
- {
- zend_uint next = 0, self = (EG(current_execute_data)->opline - EG(active_op_array)->opcodes);
-
- for (next = self; next < EG(active_op_array)->last; next++) {
- switch (EG(active_op_array)->opcodes[next].opcode) {
- case ZEND_RETURN:
- case ZEND_THROW:
- case ZEND_EXIT:
-#ifdef ZEND_YIELD
- case ZEND_YIELD:
-#endif
- zend_hash_index_update(&PHPDBG_G(seek), (zend_ulong) &EG(active_op_array)->opcodes[next], &EG(active_op_array)->opcodes[next], sizeof(zend_op), NULL);
- break;
- }
- }
- }
+ phpdbg_seek_to_end(TSRMLS_C);
return PHPDBG_LEAVE;
} /* }}} */
@@ -535,56 +516,44 @@ PHPDBG_COMMAND(frame) /* {{{ */
static inline void phpdbg_handle_exception(TSRMLS_D) /* }}} */
{
zend_fcall_info fci;
-
- zval fname, *trace, exception;
+ zval trace;
/* get filename and linenumber before unsetting exception */
const char *filename = zend_get_executed_filename(TSRMLS_C);
- zend_uint lineno = zend_get_executed_lineno(TSRMLS_C);
-
- /* copy exception */
- exception = *EG(exception);
- zval_copy_ctor(&exception);
- EG(exception) = NULL;
+ uint32_t lineno = zend_get_executed_lineno(TSRMLS_C);
/* call __toString */
- ZVAL_STRINGL(&fname, "__tostring", sizeof("__tostring")-1, 1);
+ ZVAL_STRINGL(&fci.function_name, "__tostring", sizeof("__tostring") - 1);
fci.size = sizeof(fci);
- fci.function_table = &Z_OBJCE(exception)->function_table;
- fci.function_name = &fname;
+ fci.function_table = &EG(exception)->ce->function_table;
fci.symbol_table = NULL;
- fci.object_ptr = &exception;
- fci.retval_ptr_ptr = &trace;
+ fci.object = EG(exception);
+ fci.retval = &trace;
fci.param_count = 0;
fci.params = NULL;
fci.no_separation = 1;
- zend_call_function(&fci, NULL TSRMLS_CC);
-
- if (trace) {
- phpdbg_writeln("exception", "name=\"%s\" trace=\"%.*s\"", "Uncaught %s!\n%.*s", Z_OBJCE(exception)->name, Z_STRLEN_P(trace), Z_STRVAL_P(trace));
+ if (zend_call_function(&fci, NULL TSRMLS_CC) == SUCCESS) {
+ phpdbg_writeln("exception", "name=\"%s\" trace=\"%.*s\"", "Uncaught %s!\n%.*s", EG(exception)->ce->name->val, Z_STRLEN(trace), Z_STRVAL(trace));
zval_ptr_dtor(&trace);
} else {
- phpdbg_error("exception", "name=\"%s\"", "Uncaught %s!", Z_OBJCE(exception)->name);
+ phpdbg_error("exception", "name=\"%s\"" "Uncaught %s!", EG(exception)->ce->name->val);
}
/* output useful information about address */
- phpdbg_writeln("exception", "opline=\"%p\" file=\"%s\" line=\"%u\"", "Stack entered at %p in %s on line %u", EG(active_op_array)->opcodes, filename, lineno);
+ phpdbg_writeln("exception", "opline=\"%p\" file=\"%s\" line=\"%u\"", "Stack entered at %p in %s on line %u", EG(current_execute_data)->func->op_array.opcodes, filename, lineno);
- zval_dtor(&fname);
- zval_dtor(&exception);
+ zval_dtor(&fci.function_name);
+ zend_clear_exception(TSRMLS_C);
} /* }}} */
PHPDBG_COMMAND(run) /* {{{ */
{
if (PHPDBG_G(ops) || PHPDBG_G(exec)) {
- zend_op **orig_opline = EG(opline_ptr);
- zend_op_array *orig_op_array = EG(active_op_array);
- zval **orig_retval_ptr = EG(return_value_ptr_ptr);
- zend_bool restore = 1;
zend_execute_data *ex = EG(current_execute_data);
+ zend_bool restore = 1;
- if (EG(in_execution)) {
+ if (PHPDBG_G(in_execution)) {
if (phpdbg_ask_user_permission("Do you really want to restart execution?" TSRMLS_CC) == SUCCESS) {
phpdbg_startup_run++;
phpdbg_clean(1 TSRMLS_CC);
@@ -599,21 +568,16 @@ PHPDBG_COMMAND(run) /* {{{ */
}
}
- EG(active_op_array) = PHPDBG_G(ops);
- EG(return_value_ptr_ptr) = &PHPDBG_G(retval);
- if (!EG(active_symbol_table)) {
- zend_rebuild_symbol_table(TSRMLS_C);
- }
-
/* clean up from last execution */
if (ex && ex->symbol_table) {
- zend_hash_clean(ex->symbol_table);
+ zend_hash_clean(&ex->symbol_table->ht);
+ } else {
+ zend_rebuild_symbol_table(TSRMLS_C);
}
/* clean seek state */
PHPDBG_G(flags) &= ~PHPDBG_SEEK_MASK;
- zend_hash_clean(
- &PHPDBG_G(seek));
+ zend_hash_clean(&PHPDBG_G(seek));
/* reset hit counters */
phpdbg_reset_breakpoints(TSRMLS_C);
@@ -644,14 +608,12 @@ PHPDBG_COMMAND(run) /* {{{ */
}
zend_try {
- PHPDBG_G(flags) &= ~PHPDBG_IS_INTERACTIVE;
+ PHPDBG_G(flags) ^= PHPDBG_IS_INTERACTIVE;
PHPDBG_G(flags) |= PHPDBG_IS_RUNNING;
- zend_execute(EG(active_op_array) TSRMLS_CC);
- PHPDBG_G(flags) |= PHPDBG_IS_INTERACTIVE;
+ zend_execute(PHPDBG_G(ops), &PHPDBG_G(retval) TSRMLS_CC);
+ PHPDBG_G(flags) ^= PHPDBG_IS_INTERACTIVE;
} zend_catch {
- EG(active_op_array) = orig_op_array;
- EG(opline_ptr) = orig_opline;
- EG(return_value_ptr_ptr) = orig_retval_ptr;
+ PHPDBG_G(in_execution) = 0;
if (!(PHPDBG_G(flags) & PHPDBG_IS_STOPPING)) {
phpdbg_error("stop", "type=\"bailout\"", "Caught exit/error from VM");
@@ -669,10 +631,6 @@ PHPDBG_COMMAND(run) /* {{{ */
phpdbg_handle_exception(TSRMLS_C);
}
- EG(active_op_array) = orig_op_array;
- EG(opline_ptr) = orig_opline;
- EG(return_value_ptr_ptr) = orig_retval_ptr;
-
phpdbg_clean(1 TSRMLS_CC);
}
@@ -686,10 +644,10 @@ out:
return SUCCESS;
} /* }}} */
-int phpdbg_output_ev_variable(char *name, size_t len, char *keyname, size_t keylen, HashTable *parent, zval **zv TSRMLS_DC) {
+int phpdbg_output_ev_variable(char *name, size_t len, char *keyname, size_t keylen, HashTable *parent, zval *zv TSRMLS_DC) {
phpdbg_notice("eval", "variable=\"%.*s\"", "Printing variable %.*s", (int) len, name);
phpdbg_xml("<eval %r>");
- zend_print_zval_r(*zv, 0 TSRMLS_CC);
+ zend_print_zval_r(zv, 0 TSRMLS_CC);
phpdbg_xml("</eval>");
phpdbg_out("\n");
@@ -704,21 +662,16 @@ PHPDBG_COMMAND(ev) /* {{{ */
zend_bool stepping = ((PHPDBG_G(flags) & PHPDBG_IS_STEPPING) == PHPDBG_IS_STEPPING);
zval retval;
- zend_op **orig_opline = EG(opline_ptr);
- zend_op_array *orig_op_array = EG(active_op_array);
- zval **orig_retval_ptr = EG(return_value_ptr_ptr);
- zend_execute_data *ex = EG(current_execute_data);
- HashTable *original_active_symbol_table = EG(active_symbol_table);
- zval *original_This = EG(This);
+ zend_execute_data *original_execute_data = EG(current_execute_data);
zend_class_entry *original_scope = EG(scope);
- zend_class_entry *original_called_scope = EG(called_scope);
- zend_vm_stack original_stack = EG(argument_stack);
+ zend_vm_stack original_stack = EG(vm_stack);
+ original_stack->top = EG(vm_stack_top);
PHPDBG_OUTPUT_BACKUP();
if (PHPDBG_G(flags) & PHPDBG_IN_SIGNAL_HANDLER) {
phpdbg_try_access {
- phpdbg_parse_variable(param->str, param->len, &EG(symbol_table), 0, phpdbg_output_ev_variable, 0 TSRMLS_CC);
+ phpdbg_parse_variable(param->str, param->len, &EG(symbol_table).ht, 0, phpdbg_output_ev_variable, 0 TSRMLS_CC);
} phpdbg_catch_access {
phpdbg_error("signalsegv", "", "Could not fetch data, invalid data source");
} phpdbg_end_try_access();
@@ -734,27 +687,23 @@ PHPDBG_COMMAND(ev) /* {{{ */
/* disable stepping while eval() in progress */
PHPDBG_G(flags) |= PHPDBG_IN_EVAL;
zend_try {
- if (zend_eval_stringl(param->str, param->len,&retval, "eval()'d code" TSRMLS_CC) == SUCCESS) {
+ if (zend_eval_stringl(param->str, param->len, &retval, "eval()'d code" TSRMLS_CC) == SUCCESS) {
phpdbg_xml("<eval %r>");
if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) {
zval *zvp = &retval;
- phpdbg_xml_var_dump(&zvp TSRMLS_CC);
+ phpdbg_xml_var_dump(zvp TSRMLS_CC);
}
zend_print_zval_r(&retval, 0 TSRMLS_CC);
phpdbg_xml("</eval>");
phpdbg_out("\n");
- zval_dtor(&retval);
+ zval_ptr_dtor(&retval);
}
} zend_catch {
- EG(active_op_array) = orig_op_array;
- EG(opline_ptr) = orig_opline;
- EG(return_value_ptr_ptr) = orig_retval_ptr;
- EG(current_execute_data) = ex;
- EG(active_symbol_table) = original_active_symbol_table;
- EG(This) = original_This;
+ EG(current_execute_data) = original_execute_data;
EG(scope) = original_scope;
- EG(called_scope) = original_called_scope;
- EG(argument_stack) = original_stack;
+ EG(vm_stack_top) = original_stack->top;
+ EG(vm_stack_end) = original_stack->end;
+ EG(vm_stack) = original_stack;
} zend_end_try();
PHPDBG_G(flags) &= ~PHPDBG_IN_EVAL;
@@ -772,7 +721,7 @@ PHPDBG_COMMAND(ev) /* {{{ */
PHPDBG_COMMAND(back) /* {{{ */
{
- if (!EG(in_execution)) {
+ if (!PHPDBG_G(in_execution)) {
phpdbg_error("inactive", "type=\"noexec\"", "Not executing!");
return SUCCESS;
}
@@ -812,8 +761,8 @@ PHPDBG_COMMAND(print) /* {{{ */
phpdbg_writeln("print", "vars=\"%d\"", "Variables %d", PHPDBG_G(ops)->last_var ? PHPDBG_G(ops)->last_var - 1 : 0);
}
- phpdbg_writeln("print", "executing=\"%d\"", "Executing %s", EG(in_execution) ? "yes" : "no");
- if (EG(in_execution)) {
+ phpdbg_writeln("print", "executing=\"%d\"", "Executing %s", PHPDBG_G(in_execution) ? "yes" : "no");
+ if (PHPDBG_G(in_execution)) {
phpdbg_writeln("print", "vmret=\"%d\"", "VM Return %d", PHPDBG_G(vmret));
}
@@ -980,7 +929,7 @@ PHPDBG_API const char *phpdbg_load_module_or_extension(char **path, char **name
*name = new_extension->name;
- zend_register_extension(new_extension, handle);
+ zend_register_extension(new_extension, handle TSRMLS_CC);
if (new_extension->startup) {
if (new_extension->startup(new_extension) != SUCCESS) {
@@ -1121,9 +1070,9 @@ PHPDBG_COMMAND(register) /* {{{ */
char *lcname = zend_str_tolower_dup(param->str, param->len);
size_t lcname_len = strlen(lcname);
- if (!zend_hash_exists(&PHPDBG_G(registered), lcname, lcname_len+1)) {
- if (zend_hash_find(EG(function_table), lcname, lcname_len+1, (void**) &function) == SUCCESS) {
- zend_hash_update(&PHPDBG_G(registered), lcname, lcname_len+1, (void*)&function, sizeof(zend_function), NULL);
+ if (!zend_hash_str_exists(&PHPDBG_G(registered), lcname, lcname_len)) {
+ if ((function = zend_hash_str_find_ptr(EG(function_table), lcname, lcname_len))) {
+ zend_hash_str_update_ptr(&PHPDBG_G(registered), lcname, lcname_len, function);
function_add_ref(function);
phpdbg_notice("register", "function=\"%s\"", "Registered %s", lcname);
@@ -1151,7 +1100,7 @@ PHPDBG_COMMAND(quit) /* {{{ */
PHPDBG_COMMAND(clean) /* {{{ */
{
- if (EG(in_execution)) {
+ if (PHPDBG_G(in_execution)) {
if (phpdbg_ask_user_permission("Do you really want to clean your current environment?" TSRMLS_CC) == FAILURE) {
return SUCCESS;
}
@@ -1280,7 +1229,7 @@ int phpdbg_interactive(zend_bool allow_async_unsafe TSRMLS_DC) /* {{{ */
case PHPDBG_NEXT: {
phpdbg_activate_err_buf(0 TSRMLS_CC);
phpdbg_free_err_buf(TSRMLS_C);
- if (!EG(in_execution) && !(PHPDBG_G(flags) & PHPDBG_IS_STOPPING)) {
+ if (!PHPDBG_G(in_execution) && !(PHPDBG_G(flags) & PHPDBG_IS_STOPPING)) {
phpdbg_error("command", "type=\"noexec\"", "Not running");
}
break;
@@ -1309,7 +1258,7 @@ int phpdbg_interactive(zend_bool allow_async_unsafe TSRMLS_DC) /* {{{ */
PHPDBG_G(req_id) = 0;
}
- if (EG(in_execution)) {
+ if (PHPDBG_G(in_execution)) {
phpdbg_restore_frame(TSRMLS_C);
}
@@ -1336,76 +1285,12 @@ 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) = 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
-} /* }}} */
-
#define DO_INTERACTIVE(allow_async_unsafe) do { \
if (!(PHPDBG_G(flags) & PHPDBG_IN_EVAL)) { \
- phpdbg_list_file( \
- zend_get_executed_filename(TSRMLS_C), \
- 3, \
- zend_get_executed_lineno(TSRMLS_C)-1, \
- zend_get_executed_lineno(TSRMLS_C) \
- TSRMLS_CC \
- ); \
+ const char *file_char = zend_get_executed_filename(TSRMLS_C); \
+ zend_string *file = zend_string_init(file_char, strlen(file_char), 0); \
+ phpdbg_list_file(file, 3, zend_get_executed_lineno(TSRMLS_C)-1, zend_get_executed_lineno(TSRMLS_C) TSRMLS_CC); \
+ efree(file); \
} \
\
switch (phpdbg_interactive(allow_async_unsafe TSRMLS_CC)) { \
@@ -1418,49 +1303,23 @@ static inline zend_execute_data *phpdbg_create_execute_data(zend_op_array *op_ar
} \
} while (0)
-#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) /* {{{ */
-{
- long long flags = 0;
- zend_ulong address = 0L;
- zend_execute_data *execute_data;
- zend_bool nested = 0;
-#endif
- zend_bool original_in_execution = EG(in_execution);
+ zend_bool original_in_execution = PHPDBG_G(in_execution);
HashTable vars;
-#if PHP_VERSION_ID < 50500
- if (EG(exception)) {
- return;
- }
-#endif
+ zend_hash_init(&vars, execute_data->func->op_array.last, NULL, NULL, 0);
if ((PHPDBG_G(flags) & (PHPDBG_IS_STOPPING | PHPDBG_IS_RUNNING)) == PHPDBG_IS_STOPPING) {
zend_bailout();
}
- EG(in_execution) = 1;
-
-#if PHP_VERSION_ID >= 50500
- if (0) {
-zend_vm_enter:
- execute_data = phpdbg_create_execute_data(EG(active_op_array), 1 TSRMLS_CC);
- }
- zend_hash_init(&vars, EG(active_op_array)->last, NULL, NULL, 0);
-#else
-zend_vm_enter:
- execute_data = phpdbg_create_execute_data(op_array, nested TSRMLS_CC);
- nested = 1;
- zend_hash_init(&vars, EG(active_op_array)->last, NULL, NULL, 0);
-#endif
+ PHPDBG_G(in_execution) = 1;
while (1) {
if ((PHPDBG_G(flags) & PHPDBG_BP_RESOLVE_MASK)) {
/* resolve nth opline breakpoints */
- phpdbg_resolve_op_array_breaks(EG(active_op_array) TSRMLS_CC);
+ phpdbg_resolve_op_array_breaks(&execute_data->func->op_array TSRMLS_CC);
}
#ifdef ZEND_WIN32
@@ -1560,38 +1419,19 @@ next:
PHPDBG_G(last_line) = execute_data->opline->lineno;
/* stupid hack to make zend_do_fcall_common_helper return ZEND_VM_ENTER() instead of recursively calling zend_execute() and eventually segfaulting */
- if ((execute_data->opline->opcode == ZEND_DO_FCALL_BY_NAME || execute_data->opline->opcode == ZEND_DO_FCALL) && execute_data->function_state.function->type == ZEND_USER_FUNCTION) {
-#if PHP_VERSION_ID < 50500
- zend_execute = execute;
-#else
+ if (execute_data->opline->opcode == ZEND_DO_FCALL && execute_data->func->type == ZEND_USER_FUNCTION) {
zend_execute_ex = execute_ex;
-#endif
}
PHPDBG_G(vmret) = execute_data->opline->handler(execute_data TSRMLS_CC);
-#if PHP_VERSION_ID < 50500
- zend_execute = phpdbg_execute_ex;
-#else
zend_execute_ex = phpdbg_execute_ex;
-#endif
- if (PHPDBG_G(vmret) > 0) {
- switch (PHPDBG_G(vmret)) {
- case 1:
- EG(in_execution) = original_in_execution;
- zend_hash_destroy(&vars);
- return;
- case 2:
-#if PHP_VERSION_ID < 50500
- op_array = EG(active_op_array);
-#endif
- zend_hash_destroy(&vars);
- goto zend_vm_enter;
- break;
- case 3:
- execute_data = EG(current_execute_data);
- break;
- default:
- break;
+ if (PHPDBG_G(vmret) != 0) {
+ if (PHPDBG_G(vmret) < 0) {
+ zend_hash_destroy(&vars);
+ PHPDBG_G(in_execution) = original_in_execution;
+ return;
+ } else {
+ execute_data = EG(current_execute_data);
}
}
}
@@ -1605,8 +1445,8 @@ void phpdbg_force_interruption(TSRMLS_D) {
PHPDBG_G(flags) |= PHPDBG_IN_SIGNAL_HANDLER;
if (data) {
- if (data->op_array) {
- phpdbg_notice("hardinterrupt", "opline=\"%p\" num=\"%lu\" file=\"%s\" line=\"%u\"", "Current opline: %p (op #%lu) in %s:%u", data->opline, (data->opline - data->op_array->opcodes) / sizeof(data->opline), data->op_array->filename, data->opline->lineno);
+ if (data->func) {
+ phpdbg_notice("hardinterrupt", "opline=\"%p\" num=\"%lu\" file=\"%s\" line=\"%u\"", "Current opline: %p (op #%lu) in %s:%u", data->opline, (data->opline - data->func->op_array.opcodes) / sizeof(data->opline), data->func->op_array.filename, data->opline->lineno);
} else {
phpdbg_notice("hardinterrupt", "opline=\"%p\"", "Current opline: %p (op_array information unavailable)", data->opline);
}