]> granicus.if.org Git - php/commitdiff
method printer
authorkrakjoe <joe.watkins@live.co.uk>
Wed, 13 Nov 2013 05:36:01 +0000 (05:36 +0000)
committerkrakjoe <joe.watkins@live.co.uk>
Wed, 13 Nov 2013 05:36:01 +0000 (05:36 +0000)
phpdbg_print.c
phpdbg_print.h
phpdbg_prompt.c
phpdbg_utils.c
phpdbg_utils.h

index 8b2f520cbbda4c2d54a692df034df1308516866e..6ef3d4c37f371289d6656ae4daed8c8fbb383e99 100644 (file)
@@ -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);
index 0af042b1bf592775a6a8c30bdef64b710556b941..d906ab0230dfe4ee106b84ce4bfc5283022e619b 100644 (file)
@@ -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 */
index f9b1bf57936aba9b1810769a5e8f82d7b107f013..60982a9d805b4eb81bbd009030ba9d227eee74dc 100644 (file)
@@ -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
index fb2253528b7d76bf598e89832e3df5f7337e1f72..b567850c2cd139c51941657c6c78a7b126b8fd50 100644 (file)
@@ -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;
-} /* }}} */
index 278019fd1a35fd975968d2042a372ee4b0000dab..7682201493f94bfc1bb6171e9a6fdf2953f70b3a 100644 (file)
@@ -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
  */