summaryrefslogtreecommitdiff
path: root/sapi/phpdbg/phpdbg_print.c
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@zend.com>2014-04-26 00:32:51 +0400
committerDmitry Stogov <dmitry@zend.com>2014-04-26 00:32:51 +0400
commitf9927a6c97208c60d922f9a4e98feb8079c57d1f (patch)
tree35815b69d1bf7d47fb41e857ff8d2b024ddac153 /sapi/phpdbg/phpdbg_print.c
parent4e7cbf3f5842abe6688c11ce3cc11d2eabf0695f (diff)
parentb82d077f988606580e5c06a9da18fe4f60ddb7cb (diff)
downloadphp-git-f9927a6c97208c60d922f9a4e98feb8079c57d1f.tar.gz
Merge mainstream 'master' branch into refactoring
During merge I had to revert: Nikita's patch for php_splice() (it probably needs to be applyed again) Bob Weinand's patches related to constant expression handling (we need to review them carefully) I also reverted all our attempts to support sapi/phpdbg (we didn't test it anyway) Conflicts: Zend/zend.h Zend/zend_API.c Zend/zend_ast.c Zend/zend_compile.c Zend/zend_compile.h Zend/zend_constants.c Zend/zend_exceptions.c Zend/zend_execute.c Zend/zend_execute.h Zend/zend_execute_API.c Zend/zend_hash.c Zend/zend_highlight.c Zend/zend_language_parser.y Zend/zend_language_scanner.c Zend/zend_language_scanner_defs.h Zend/zend_variables.c Zend/zend_vm_def.h Zend/zend_vm_execute.h ext/date/php_date.c ext/dom/documenttype.c ext/hash/hash.c ext/iconv/iconv.c ext/mbstring/tests/zend_multibyte-10.phpt ext/mbstring/tests/zend_multibyte-11.phpt ext/mbstring/tests/zend_multibyte-12.phpt ext/mysql/php_mysql.c ext/mysqli/mysqli.c ext/mysqlnd/mysqlnd_reverse_api.c ext/mysqlnd/php_mysqlnd.c ext/opcache/ZendAccelerator.c ext/opcache/zend_accelerator_util_funcs.c ext/opcache/zend_persist.c ext/opcache/zend_persist_calc.c ext/pcre/php_pcre.c ext/pdo/pdo_dbh.c ext/pdo/pdo_stmt.c ext/pdo_pgsql/pgsql_driver.c ext/pgsql/pgsql.c ext/reflection/php_reflection.c ext/session/session.c ext/spl/spl_array.c ext/spl/spl_observer.c ext/standard/array.c ext/standard/basic_functions.c ext/standard/html.c ext/standard/mail.c ext/standard/php_array.h ext/standard/proc_open.c ext/standard/streamsfuncs.c ext/standard/user_filters.c ext/standard/var_unserializer.c ext/standard/var_unserializer.re main/php_variables.c sapi/phpdbg/phpdbg.c sapi/phpdbg/phpdbg_bp.c sapi/phpdbg/phpdbg_frame.c sapi/phpdbg/phpdbg_help.c sapi/phpdbg/phpdbg_list.c sapi/phpdbg/phpdbg_print.c sapi/phpdbg/phpdbg_prompt.c
Diffstat (limited to 'sapi/phpdbg/phpdbg_print.c')
-rw-r--r--sapi/phpdbg/phpdbg_print.c208
1 files changed, 97 insertions, 111 deletions
diff --git a/sapi/phpdbg/phpdbg_print.c b/sapi/phpdbg/phpdbg_print.c
index 131862ceb8..76321a5042 100644
--- a/sapi/phpdbg/phpdbg_print.c
+++ b/sapi/phpdbg/phpdbg_print.c
@@ -26,6 +26,19 @@
ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
+#define PHPDBG_PRINT_COMMAND_D(f, h, a, m, l, s) \
+ PHPDBG_COMMAND_D_EXP(f, h, a, m, l, s, &phpdbg_prompt_commands[9])
+
+const phpdbg_command_t phpdbg_print_commands[] = {
+ PHPDBG_PRINT_COMMAND_D(exec, "print out the instructions in the execution context", 'e', print_exec, NULL, 0),
+ PHPDBG_PRINT_COMMAND_D(opline, "print out the instruction in the current opline", 'o', print_opline, NULL, 0),
+ PHPDBG_PRINT_COMMAND_D(class, "print out the instructions in the specified class", 'c', print_class, NULL, "s"),
+ PHPDBG_PRINT_COMMAND_D(method, "print out the instructions in the specified method", 'm', print_method, NULL, "m"),
+ PHPDBG_PRINT_COMMAND_D(func, "print out the instructions in the specified function", 'f', print_func, NULL, "s"),
+ PHPDBG_PRINT_COMMAND_D(stack, "print out the instructions in the current stack", 's', print_stack, NULL, 0),
+ PHPDBG_END_COMMAND
+};
+
PHPDBG_PRINT(opline) /* {{{ */
{
if (EG(in_execution) && EG(current_execute_data)) {
@@ -52,15 +65,15 @@ static inline void phpdbg_print_function_helper(zend_function *method TSRMLS_DC)
if (method->common.scope) {
phpdbg_writeln("\tL%d-%d %s::%s() %s",
op_array->line_start, op_array->line_end,
- method->common.scope->name->val,
- method->common.function_name->val,
- op_array->filename ? op_array->filename->val : "unknown");
+ method->common.scope->name,
+ method->common.function_name,
+ op_array->filename ? op_array->filename : "unknown");
} else {
phpdbg_writeln("\tL%d-%d %s() %s",
method->common.function_name ? op_array->line_start : 0,
method->common.function_name ? op_array->line_end : 0,
- method->common.function_name ? method->common.function_name->val : "{main}",
- op_array->filename ? op_array->filename->val : "unknown");
+ method->common.function_name ? method->common.function_name : "{main}",
+ op_array->filename ? op_array->filename : "unknown");
}
zend_hash_init(&vars, op_array->last, NULL, NULL, 0);
@@ -77,16 +90,16 @@ static inline void phpdbg_print_function_helper(zend_function *method TSRMLS_DC)
phpdbg_error("\tFailed to decode opline %16p", opline);
}
opline++;
- } while (++opcode < end);
+ } while (opcode++ < end);
zend_hash_destroy(&vars);
}
} break;
default: {
if (method->common.scope) {
- phpdbg_writeln("\tInternal %s::%s()", method->common.scope->name->val, method->common.function_name->val);
+ phpdbg_writeln("\tInternal %s::%s()", method->common.scope->name, method->common.function_name);
} else {
- phpdbg_writeln("\tInternal %s()", method->common.function_name->val);
+ phpdbg_writeln("\tInternal %s()", method->common.function_name);
}
}
}
@@ -118,13 +131,13 @@ PHPDBG_PRINT(stack) /* {{{ */
if (EG(in_execution) && ops) {
if (ops->function_name) {
if (ops->scope) {
- phpdbg_notice("Stack in %s::%s()", ops->scope->name->val, ops->function_name->val);
+ phpdbg_notice("Stack in %s::%s()", ops->scope->name, ops->function_name);
} else {
- phpdbg_notice("Stack in %s()", ops->function_name->val);
+ phpdbg_notice("Stack in %s()", ops->function_name);
}
} else {
if (ops->filename) {
- phpdbg_notice("Stack in %s", ops->filename->val);
+ phpdbg_notice("Stack in %s", ops->filename);
} else {
phpdbg_notice("Stack @ %p", ops);
}
@@ -139,42 +152,32 @@ PHPDBG_PRINT(stack) /* {{{ */
PHPDBG_PRINT(class) /* {{{ */
{
- zend_class_entry *ce;
-
- switch (param->type) {
- case STR_PARAM: {
- zval tmp; /* param->str need to be zend_string later */
- ZVAL_STRINGL(&tmp, param->str, param->len);
- if ((ce = zend_lookup_class(Z_STR(tmp) TSRMLS_CC)) != NULL) {
- zval_ptr_dtor(&tmp);
- phpdbg_notice("%s %s: %s",
- (ce->type == ZEND_USER_CLASS) ?
- "User" : "Internal",
- (ce->ce_flags & ZEND_ACC_INTERFACE) ?
- "Interface" :
- (ce->ce_flags & ZEND_ACC_ABSTRACT) ?
- "Abstract Class" :
- "Class",
- ce->name->val);
-
- phpdbg_writeln("Methods (%d):", zend_hash_num_elements(&ce->function_table));
- if (zend_hash_num_elements(&ce->function_table)) {
- HashPosition position;
- zend_function *method;
-
- for (zend_hash_internal_pointer_reset_ex(&ce->function_table, &position);
- (method = zend_hash_get_current_data_ptr_ex(&ce->function_table, &position)) != NULL;
- zend_hash_move_forward_ex(&ce->function_table, &position)) {
- phpdbg_print_function_helper(method TSRMLS_CC);
- }
- }
- } else {
- phpdbg_error("The class %s could not be found", param->str);
- zval_ptr_dtor(&tmp);
+ zend_class_entry **ce;
+
+ if (zend_lookup_class(param->str, param->len, &ce TSRMLS_CC) == SUCCESS) {
+ phpdbg_notice("%s %s: %s",
+ ((*ce)->type == ZEND_USER_CLASS) ?
+ "User" : "Internal",
+ ((*ce)->ce_flags & ZEND_ACC_INTERFACE) ?
+ "Interface" :
+ ((*ce)->ce_flags & ZEND_ACC_ABSTRACT) ?
+ "Abstract Class" :
+ "Class",
+ (*ce)->name);
+
+ phpdbg_writeln("Methods (%d):", zend_hash_num_elements(&(*ce)->function_table));
+ if (zend_hash_num_elements(&(*ce)->function_table)) {
+ HashPosition position;
+ zend_function *method;
+
+ for (zend_hash_internal_pointer_reset_ex(&(*ce)->function_table, &position);
+ zend_hash_get_current_data_ex(&(*ce)->function_table, (void**) &method, &position) == SUCCESS;
+ zend_hash_move_forward_ex(&(*ce)->function_table, &position)) {
+ phpdbg_print_function_helper(method TSRMLS_CC);
}
- } break;
-
- phpdbg_default_switch_case();
+ }
+ } else {
+ phpdbg_error("The class %s could not be found", param->str);
}
return SUCCESS;
@@ -182,36 +185,25 @@ PHPDBG_PRINT(class) /* {{{ */
PHPDBG_PRINT(method) /* {{{ */
{
- switch (param->type) {
- case METHOD_PARAM: {
- zend_class_entry *ce;
- zval tmp;
-
- ZVAL_STRING(&tmp, param->method.class);
- if ((ce = zend_lookup_class(Z_STR(tmp) TSRMLS_CC)) != NULL) {
- zend_function *fbc;
- char *lcname = zend_str_tolower_dup(param->method.name, strlen(param->method.name));
+ zend_class_entry **ce;
- zval_ptr_dtor(&tmp);
+ if (zend_lookup_class(param->method.class, strlen(param->method.class), &ce TSRMLS_CC) == SUCCESS) {
+ zend_function *fbc;
+ char *lcname = zend_str_tolower_dup(param->method.name, strlen(param->method.name));
- if ((fbc = zend_hash_str_find_ptr(&ce->function_table, lcname, strlen(lcname))) != NULL) {
- phpdbg_notice("%s Method %s",
- (fbc->type == ZEND_USER_FUNCTION) ? "User" : "Internal",
- fbc->common.function_name->val);
+ if (zend_hash_find(&(*ce)->function_table, lcname, strlen(lcname)+1, (void**)&fbc) == SUCCESS) {
+ phpdbg_notice("%s Method %s",
+ (fbc->type == ZEND_USER_FUNCTION) ? "User" : "Internal",
+ fbc->common.function_name);
- phpdbg_print_function_helper(fbc TSRMLS_CC);
- } else {
- phpdbg_error("The method %s could not be found", param->method.name);
- }
-
- efree(lcname);
- } else {
- zval_ptr_dtor(&tmp);
- phpdbg_error("The class %s could not be found", param->method.class);
- }
- } break;
+ phpdbg_print_function_helper(fbc TSRMLS_CC);
+ } else {
+ phpdbg_error("The method %s could not be found", param->method.name);
+ }
- phpdbg_default_switch_case();
+ efree(lcname);
+ } else {
+ phpdbg_error("The class %s could not be found", param->method.class);
}
return SUCCESS;
@@ -219,49 +211,43 @@ PHPDBG_PRINT(method) /* {{{ */
PHPDBG_PRINT(func) /* {{{ */
{
- switch (param->type) {
- case STR_PARAM: {
- HashTable *func_table = EG(function_table);
- zend_function* fbc;
- const char *func_name = param->str;
- size_t func_name_len = param->len;
- char *lcname;
- /* search active scope if begins with period */
- if (func_name[0] == '.') {
- if (EG(scope)) {
- func_name++;
- func_name_len--;
-
- func_table = &EG(scope)->function_table;
- } else {
- phpdbg_error("No active class");
- return SUCCESS;
- }
- } else if (!EG(function_table)) {
- phpdbg_error("No function table loaded");
- return SUCCESS;
- } else {
- func_table = EG(function_table);
- }
-
- lcname = zend_str_tolower_dup(func_name, func_name_len);
-
- if ((fbc = zend_hash_str_find_ptr(func_table, lcname, strlen(lcname))) != NULL) {
- phpdbg_notice("%s %s %s",
- (fbc->type == ZEND_USER_FUNCTION) ? "User" : "Internal",
- (fbc->common.scope) ? "Method" : "Function",
- fbc->common.function_name->val);
+ HashTable *func_table = EG(function_table);
+ zend_function* fbc;
+ const char *func_name = param->str;
+ size_t func_name_len = param->len;
+ char *lcname;
+ /* search active scope if begins with period */
+ if (func_name[0] == '.') {
+ if (EG(scope)) {
+ func_name++;
+ func_name_len--;
+
+ func_table = &EG(scope)->function_table;
+ } else {
+ phpdbg_error("No active class");
+ return SUCCESS;
+ }
+ } else if (!EG(function_table)) {
+ phpdbg_error("No function table loaded");
+ return SUCCESS;
+ } else {
+ func_table = EG(function_table);
+ }
- phpdbg_print_function_helper(fbc TSRMLS_CC);
- } else {
- phpdbg_error("The function %s could not be found", func_name);
- }
+ lcname = zend_str_tolower_dup(func_name, func_name_len);
- efree(lcname);
- } break;
+ if (zend_hash_find(func_table, lcname, strlen(lcname)+1, (void**)&fbc) == SUCCESS) {
+ phpdbg_notice("%s %s %s",
+ (fbc->type == ZEND_USER_FUNCTION) ? "User" : "Internal",
+ (fbc->common.scope) ? "Method" : "Function",
+ fbc->common.function_name);
- phpdbg_default_switch_case();
+ phpdbg_print_function_helper(fbc TSRMLS_CC);
+ } else {
+ phpdbg_error("The function %s could not be found", func_name);
}
+ efree(lcname);
+
return SUCCESS;
} /* }}} */