From: krakjoe Date: Wed, 13 Nov 2013 05:36:01 +0000 (+0000) Subject: method printer X-Git-Tag: php-5.6.0alpha1~110^2~390 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=99bbc8e8118804367cf4a77f0c9b66118135229f;p=php method printer --- diff --git a/phpdbg_print.c b/phpdbg_print.c index 8b2f520cbb..6ef3d4c37f 100644 --- a/phpdbg_print.c +++ b/phpdbg_print.c @@ -124,6 +124,41 @@ PHPDBG_PRINT(class) /* {{{ */ return SUCCESS; } /* }}} */ +PHPDBG_PRINT(method) /* {{{ */ +{ + if (expr && expr_len > 0L) { + char *class_name = NULL; + char *func_name = NULL; + + if (phpdbg_is_class_method(expr, expr_len, &class_name, &func_name)) { + zend_class_entry **ce; + + if (zend_lookup_class(class_name, strlen(class_name), &ce TSRMLS_CC) == SUCCESS) { + zend_function *fbc; + + if (zend_hash_find(&(*ce)->function_table, func_name, strlen(func_name), (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", func_name); + } + } + + efree(class_name); + efree(func_name); + } else { + phpdbg_error("The expression provided is not a valid method %s", expr); + } + } else { + phpdbg_error("No expression provided"); + } + return SUCCESS; +} /* }}} */ + PHPDBG_PRINT(func) /* {{{ */ { if (expr && expr_len > 0L) { @@ -152,8 +187,9 @@ PHPDBG_PRINT(func) /* {{{ */ if (zend_hash_find(func_table, func_name, func_name_len+1, (void**)&fbc) == SUCCESS) { phpdbg_notice( - "%s Function %s", + "%s %s %s", (fbc->type == ZEND_USER_FUNCTION) ? "User" : "Internal", + (fbc->common.scope) ? "Method" : "Function", fbc->common.function_name); phpdbg_print_function_helper(fbc TSRMLS_CC); diff --git a/phpdbg_print.h b/phpdbg_print.h index 0af042b1bf..d906ab0230 100644 --- a/phpdbg_print.h +++ b/phpdbg_print.h @@ -36,6 +36,7 @@ */ PHPDBG_PRINT(opline); PHPDBG_PRINT(class); +PHPDBG_PRINT(method); PHPDBG_PRINT(func); /** @@ -44,8 +45,9 @@ PHPDBG_PRINT(func); static const phpdbg_command_t phpdbg_print_commands[] = { PHPDBG_PRINT_D(opline, "print the current opline information"), PHPDBG_PRINT_D(class, "print out the instructions in the specified class"), + PHPDBG_PRINT_D(method, "print out the instructions in the specified method"), PHPDBG_PRINT_D(func, "print out the instructions in the specified function"), - {NULL, 0, 0} + {0, 0, 0, 0} }; #endif /* PHPDBG_PRINT_H */ diff --git a/phpdbg_prompt.c b/phpdbg_prompt.c index f9b1bf5793..60982a9d80 100644 --- a/phpdbg_prompt.c +++ b/phpdbg_prompt.c @@ -208,7 +208,8 @@ static PHPDBG_COMMAND(back) /* {{{ */ static PHPDBG_COMMAND(print) /* {{{ */ { if (expr && expr_len > 0L) { - if (phpdbg_do_cmd(phpdbg_print_commands, (char*)expr, expr_len TSRMLS_CC) == FAILURE) { + if (phpdbg_print_commands && + phpdbg_do_cmd(phpdbg_print_commands, (char*)expr, expr_len TSRMLS_CC) == FAILURE) { phpdbg_error("Failed to find print command %s", expr); } return SUCCESS; @@ -521,7 +522,7 @@ int phpdbg_do_cmd(const phpdbg_command_t *command, char *cmd_line, size_t cmd_le #endif size_t expr_len = (cmd != NULL) ? strlen(cmd) : 0; - while (command && command->name) { + while (command && command->name && command->handler) { if (command->name_len == expr_len && memcmp(cmd, command->name, expr_len) == 0) { @@ -546,20 +547,19 @@ int phpdbg_interactive(TSRMLS_D) /* {{{ */ #ifndef HAVE_LIBREADLINE char cmd[PHPDBG_MAX_CMD]; -phpdbg_interactive_enter: - phpdbg_write(PROMPT); - while (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING) && - fgets(cmd, PHPDBG_MAX_CMD, stdin) != NULL) { + phpdbg_write(PROMPT) && + (fgets(cmd, PHPDBG_MAX_CMD, stdin) != NULL)) { cmd_len = strlen(cmd) - 1; #else char *cmd = NULL; -phpdbg_interactive_enter: while (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) { cmd = readline(PROMPT); - cmd_len = strlen(cmd); + if (cmd) { + cmd_len = strlen(cmd); + } else cmd_len = 0L; #endif /* trim space from end of input */ @@ -595,15 +595,10 @@ phpdbg_interactive_enter: cmd = NULL; } #endif - } else if (PHPDBG_G(last)) { PHPDBG_G(last)->handler( PHPDBG_G(last_params), PHPDBG_G(last_params_len) TSRMLS_CC); } - - if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) { - goto phpdbg_interactive_enter; - } } #ifdef HAVE_LIBREADLINE diff --git a/phpdbg_utils.c b/phpdbg_utils.c index fb2253528b..b567850c2c 100644 --- a/phpdbg_utils.c +++ b/phpdbg_utils.c @@ -74,7 +74,7 @@ int phpdbg_is_class_method(const char *str, size_t len, char **class, char **met void phpdbg_print(int type TSRMLS_DC, const char *format, ...) /* {{{ */ { char *buffer = NULL; - va_list args = {0}; + va_list args; if (format != NULL && strlen(format) > 0L) { va_start(args, format); @@ -122,19 +122,3 @@ void phpdbg_print(int type TSRMLS_DC, const char *format, ...) /* {{{ */ efree(buffer); } } /* }}} */ - -char *phpdbg_trim(const char *expr, size_t *expr_len) /* {{{ */ -{ - char *pointer = expr; - - while (*pointer && isspace(*pointer)) { - pointer++; - (*expr_len)--; - } - - while (expr_len > 0L && isspace(pointer[(*expr_len)-1])) { - pointer[--(*expr_len)]='\0'; - } - - return pointer; -} /* }}} */ diff --git a/phpdbg_utils.h b/phpdbg_utils.h index 278019fd1a..7682201493 100644 --- a/phpdbg_utils.h +++ b/phpdbg_utils.h @@ -28,12 +28,6 @@ int phpdbg_is_empty(const char*); int phpdbg_is_addr(const char*); int phpdbg_is_class_method(const char*, size_t, char**, char**); -/** - * Input trim function - * NOTE: efree all the things - */ -char *phpdbg_trim(const char*, size_t*); - /** * Error/notice/formatting helper */