]> granicus.if.org Git - php/commitdiff
- Added separated file to handle breakpoint feature
authorFelipe Pena <felipensp@gmail.com>
Sun, 10 Nov 2013 18:06:41 +0000 (16:06 -0200)
committerFelipe Pena <felipensp@gmail.com>
Sun, 10 Nov 2013 18:06:41 +0000 (16:06 -0200)
config.m4
phpdbg.h
phpdbg_bp.c [new file with mode: 0644]
phpdbg_bp.h [new file with mode: 0644]
phpdbg_help.h
phpdbg_prompt.c
phpdbg_prompt.h

index b62d099ad4065a538bf00c63f4ab9f91bf8f2980..4f98bb92bf71c89e90ae750fdf92cff9fe4fb607 100644 (file)
--- a/config.m4
+++ b/config.m4
@@ -9,7 +9,7 @@ if test "$PHP_PHPDBG" != "no"; then
   AC_DEFINE(HAVE_PHPDBG, 1, [ ])
 
   PHP_PHPDBG_CFLAGS=-I$abs_srcdir/sapi/phpdbg
-  PHP_PHPDBG_FILES="phpdbg.c phpdbg_prompt.c phpdbg_help.c"
+  PHP_PHPDBG_FILES="phpdbg.c phpdbg_prompt.c phpdbg_help.c phpdbg_bp.c"
 
   PHP_ADD_MAKEFILE_FRAGMENT([$abs_srcdir/sapi/phpdbg/Makefile.frag])
   PHP_SELECT_SAPI(phpdbg, program, $PHP_PHPDBG_FILES, $PHP_PHPDBG_CFLAGS, [$(SAPI_PHPDBG_PATH)])
index 427d22aa968d482013427d31af910d5f2cb37fc9..437fe8a24413682e4053b59adfe9b35a77a4e43b 100644 (file)
--- a/phpdbg.h
+++ b/phpdbg.h
    | Authors: Joe Watkins <joe.watkins@live.co.uk>                        |
    +----------------------------------------------------------------------+
 */
+
+#ifndef PHPDBG_H
+#define PHPDBG_H
+
 #include "php.h"
 #include "php_globals.h"
 #include "php_variables.h"
@@ -54,4 +58,4 @@ ZEND_BEGIN_MODULE_GLOBALS(phpdbg)
        zend_bool quitting;     /* quitting flag */
 ZEND_END_MODULE_GLOBALS(phpdbg)
 
-#include "phpdbg_prompt.h"
+#endif /* PHPDBG_H */
diff --git a/phpdbg_bp.c b/phpdbg_bp.c
new file mode 100644 (file)
index 0000000..a45ab16
--- /dev/null
@@ -0,0 +1,147 @@
+/*
+   +----------------------------------------------------------------------+
+   | PHP Version 5                                                        |
+   +----------------------------------------------------------------------+
+   | Copyright (c) 1997-2013 The PHP Group                                |
+   +----------------------------------------------------------------------+
+   | This source file is subject to version 3.01 of the PHP license,      |
+   | that is bundled with this package in the file LICENSE, and is        |
+   | available through the world-wide-web at the following url:           |
+   | http://www.php.net/license/3_01.txt                                  |
+   | If you did not receive a copy of the PHP license and are unable to   |
+   | obtain it through the world-wide-web, please send a note to          |
+   | license@php.net so we can mail you a copy immediately.               |
+   +----------------------------------------------------------------------+
+   | Authors: Felipe Pena <felipe@php.net>                                |
+   | Authors: Joe Watkins <joe.watkins@live.co.uk>                        |
+   +----------------------------------------------------------------------+
+*/
+
+#include "zend.h"
+#include "zend_hash.h"
+#include "phpdbg.h"
+#include "phpdbg_bp.h"
+
+ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
+
+static void phpdbg_llist_breakfile_dtor(void *data) /* {{{ */
+{
+       phpdbg_breakfile_t *bp = (phpdbg_breakfile_t*) data;
+
+       efree((char*)bp->filename);
+} /* }}} */
+
+static void phpdbg_llist_breaksym_dtor(void *data) /* {{{ */
+{
+       phpdbg_breaksymbol_t *bp = (phpdbg_breaksymbol_t*) data;
+
+       efree((char*)bp->symbol);
+} /* }}} */
+
+void phpdbg_set_breakpoint_file(const char *expr, const char *line_pos TSRMLS_DC) /* {{{ */
+{
+       char resolved_name[MAXPATHLEN];
+       long line_num = strtol(line_pos+1, NULL, 0);
+       phpdbg_breakfile_t new_break;
+       zend_llist *break_files_ptr;
+       size_t name_len;
+       char *path = estrndup(expr, line_pos - expr);
+
+       if (expand_filepath(path, resolved_name TSRMLS_CC) == NULL) {
+               efree(path);
+               return;
+       }
+       efree(path);
+
+       name_len = strlen(resolved_name);
+       new_break.filename = estrndup(resolved_name, name_len + 1);
+       new_break.line = line_num;
+
+       PHPDBG_G(has_file_bp) = 1;
+
+       if (zend_hash_find(&PHPDBG_G(bp_files),
+               new_break.filename, name_len, (void**)&break_files_ptr) == FAILURE) {
+               zend_llist break_files;
+
+               zend_llist_init(&break_files, sizeof(phpdbg_breakfile_t),
+                       phpdbg_llist_breakfile_dtor, 0);
+
+               zend_hash_update(&PHPDBG_G(bp_files),
+                       new_break.filename, name_len, &break_files, sizeof(zend_llist),
+                       (void**)&break_files_ptr);
+       }
+       zend_llist_add_element(break_files_ptr, &new_break);
+} /* }}} */
+
+void phpdbg_set_breakpoint_symbol(const char *expr, const char *opline_num_pos TSRMLS_DC) /* {{{ */
+{
+       long opline_num = opline_num_pos ? strtol(opline_num_pos+1, NULL, 0) : 0;
+       phpdbg_breaksymbol_t new_break;
+       zend_llist *break_sym_ptr;
+       size_t name_len = opline_num_pos ? opline_num_pos - expr : strlen(expr);
+
+       new_break.symbol = estrndup(expr, name_len);
+       new_break.opline_num = opline_num;
+
+       PHPDBG_G(has_sym_bp) = 1;
+
+       if (zend_hash_find(&PHPDBG_G(bp_symbols),
+               new_break.symbol, name_len, (void**)&break_sym_ptr) == FAILURE) {
+               zend_llist break_syms;
+
+               zend_llist_init(&break_syms, sizeof(phpdbg_breaksymbol_t),
+                       phpdbg_llist_breaksym_dtor, 0);
+
+               zend_hash_update(&PHPDBG_G(bp_symbols),
+                       new_break.symbol, name_len, &break_syms, sizeof(zend_llist),
+                       (void**)&break_sym_ptr);
+       }
+       zend_llist_add_element(break_sym_ptr, &new_break);
+} /* }}} */
+
+int phpdbg_breakpoint_file(zend_op_array *op_array TSRMLS_DC) /* {{{ */
+{
+       size_t name_len = strlen(op_array->filename);
+       zend_llist *break_list;
+
+       if (zend_hash_find(&PHPDBG_G(bp_files), op_array->filename, name_len,
+               (void**)&break_list) == SUCCESS) {
+               zend_llist_element *le;
+
+               for (le = break_list->head; le; le = le->next) {
+                       phpdbg_breakfile_t *bp = (phpdbg_breakfile_t*) le->data;
+
+                       if (bp->line == (*EG(opline_ptr))->lineno) {
+                               printf("breakpoint reached!\n");
+                               return SUCCESS;
+                       }
+               }
+       }
+
+       return FAILURE;
+} /* }}} */
+
+int phpdbg_breakpoint_symbol(zend_function *fbc TSRMLS_DC) /* {{{ */
+{
+       const char *fname;
+       zend_llist *break_list;
+
+       if (fbc->type != ZEND_USER_FUNCTION) {
+               return FAILURE;
+       }
+
+       fname = ((zend_op_array*)fbc)->function_name;
+
+       if (!fname) {
+               fname = "main";
+       }
+
+       if (zend_hash_find(&PHPDBG_G(bp_symbols), fname, strlen(fname),
+               (void**)&break_list) == SUCCESS) {
+               printf("breakpoint reached!\n");
+               return SUCCESS;
+       }
+
+       return FAILURE;
+}
+/* }}} */
diff --git a/phpdbg_bp.h b/phpdbg_bp.h
new file mode 100644 (file)
index 0000000..87aea82
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+   +----------------------------------------------------------------------+
+   | PHP Version 5                                                        |
+   +----------------------------------------------------------------------+
+   | Copyright (c) 1997-2013 The PHP Group                                |
+   +----------------------------------------------------------------------+
+   | This source file is subject to version 3.01 of the PHP license,      |
+   | that is bundled with this package in the file LICENSE, and is        |
+   | available through the world-wide-web at the following url:           |
+   | http://www.php.net/license/3_01.txt                                  |
+   | If you did not receive a copy of the PHP license and are unable to   |
+   | obtain it through the world-wide-web, please send a note to          |
+   | license@php.net so we can mail you a copy immediately.               |
+   +----------------------------------------------------------------------+
+   | Authors: Felipe Pena <felipe@php.net>                                |
+   | Authors: Joe Watkins <joe.watkins@live.co.uk>                        |
+   +----------------------------------------------------------------------+
+*/
+
+#ifndef PHPDBG_BP_H
+#define PHPDBG_BP_H
+
+/**
+ * Breakpoint file-based representation
+ */
+typedef struct _phpdbg_breakfile_t {
+       const char *filename;
+       long line;
+} phpdbg_breakfile_t;
+
+/**
+ * Breakpoint symbol-based representation
+ */
+typedef struct _phpdbg_breaksymbol_t {
+       const char *symbol;
+       long opline_num;
+} phpdbg_breaksymbol_t;
+
+#endif /* PHPDBG_BP_H */
index 1051d61fc932152fb7b38740d0dde1f0b90cf72a..8ce6f9691d2605fac684812106de074f1a025650 100644 (file)
@@ -20,6 +20,8 @@
 #ifndef PHPDBG_HELP_H
 #define PHPDBG_HELP_H
 
+#include "phpdbg_prompt.h"
+
 /**
  * Command Declarators
  */
index fe81c8cb9dd69adebb1d0342a6620bf1a3729cea..5e795b624b355408fdd74201db7e4dbeb69dad2c 100644 (file)
 #include "zend_compile.h"
 #include "phpdbg.h"
 #include "phpdbg_help.h"
+#include "phpdbg_bp.h"
 
 static const phpdbg_command_t phpdbg_prompt_commands[];
 
 ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
 
-static void phpdbg_llist_breakfile_dtor(void *data)
-{
-       phpdbg_breakfile_t *bp = (phpdbg_breakfile_t*) data;
-
-       efree((char*)bp->filename);
-}
-
-static void phpdbg_llist_breaksym_dtor(void *data)
-{
-       phpdbg_breaksymbol_t *bp = (phpdbg_breaksymbol_t*) data;
-
-       efree((char*)bp->symbol);
-}
-
 static PHPDBG_COMMAND(exec) { /* {{{ */
   if (PHPDBG_G(exec)) {
     printf(
@@ -142,7 +129,7 @@ static PHPDBG_COMMAND(run) { /* {{{ */
 
 static PHPDBG_COMMAND(eval) { /* {{{ */
     zval retval;
-    
+
     if (expr) {
         if (zend_eval_stringl((char*)expr, expr_len-1, &retval, "eval()'d code" TSRMLS_CC) == SUCCESS) {
             printf("Success: ");
@@ -219,61 +206,11 @@ static PHPDBG_COMMAND(break) /* {{{ */
        const char *line_pos = zend_memrchr(expr, ':', expr_len);
 
        if (line_pos) {
-               char resolved_name[MAXPATHLEN];
-               long line_num = strtol(line_pos+1, NULL, 0);
-               phpdbg_breakfile_t new_break;
-               zend_llist *break_files_ptr;
-               size_t name_len;
-               char *path = estrndup(expr, line_pos - expr);
-
-               if (expand_filepath(path, resolved_name TSRMLS_CC) == NULL) {
-                       efree(path);
-                       return FAILURE;
-               }
-               efree(path);
-
-               name_len = strlen(resolved_name);
-               new_break.filename = estrndup(resolved_name, name_len + 1);
-               new_break.line = line_num;
-
-               PHPDBG_G(has_file_bp) = 1;
-
-               if (zend_hash_find(&PHPDBG_G(bp_files),
-                       new_break.filename, name_len, (void**)&break_files_ptr) == FAILURE) {
-                       zend_llist break_files;
-
-                       zend_llist_init(&break_files, sizeof(phpdbg_breakfile_t),
-                               phpdbg_llist_breakfile_dtor, 0);
-
-                       zend_hash_update(&PHPDBG_G(bp_files),
-                               new_break.filename, name_len, &break_files, sizeof(zend_llist),
-                               (void**)&break_files_ptr);
-               }
-               zend_llist_add_element(break_files_ptr, &new_break);
+               phpdbg_set_breakpoint_file(expr, line_pos TSRMLS_CC);
        } else {
                const char *opline_num_pos = zend_memrchr(expr, '#', expr_len);
-               long opline_num = opline_num_pos ? strtol(opline_num_pos+1, NULL, 0) : 0;
-               phpdbg_breaksymbol_t new_break;
-               zend_llist *break_sym_ptr;
-               size_t name_len = opline_num_pos ? opline_num_pos - expr : strlen(expr);
-
-               new_break.symbol = estrndup(expr, name_len);
-               new_break.opline_num = opline_num;
-
-               PHPDBG_G(has_sym_bp) = 1;
 
-               if (zend_hash_find(&PHPDBG_G(bp_symbols),
-                       new_break.symbol, name_len, (void**)&break_sym_ptr) == FAILURE) {
-                       zend_llist break_syms;
-
-                       zend_llist_init(&break_syms, sizeof(phpdbg_breaksymbol_t),
-                               phpdbg_llist_breaksym_dtor, 0);
-
-                       zend_hash_update(&PHPDBG_G(bp_symbols),
-                               new_break.symbol, name_len, &break_syms, sizeof(zend_llist),
-                               (void**)&break_sym_ptr);
-               }
-               zend_llist_add_element(break_sym_ptr, &new_break);
+               phpdbg_set_breakpoint_symbol(expr, opline_num_pos TSRMLS_CC);
        }
 
        return SUCCESS;
@@ -282,7 +219,7 @@ static PHPDBG_COMMAND(break) /* {{{ */
 static PHPDBG_COMMAND(quit) /* {{{ */
 {
     PHPDBG_G(quitting)=1;
-    
+
        zend_bailout();
 
        return SUCCESS;
@@ -354,59 +291,13 @@ int phpdbg_do_cmd(const phpdbg_command_t *command, char *cmd_line, size_t cmd_le
        return FAILURE;
 } /* }}} */
 
-int phpdbg_breakpoint_file(zend_op_array *op_array TSRMLS_DC) /* {{{ */
-{
-       size_t name_len = strlen(op_array->filename);
-       zend_llist *break_list;
-
-       if (zend_hash_find(&PHPDBG_G(bp_files), op_array->filename, name_len,
-               (void**)&break_list) == SUCCESS) {
-               zend_llist_element *le;
-
-               for (le = break_list->head; le; le = le->next) {
-                       phpdbg_breakfile_t *bp = (phpdbg_breakfile_t*) le->data;
-
-                       if (bp->line == (*EG(opline_ptr))->lineno) {
-                               printf("breakpoint reached!\n");
-                               return SUCCESS;
-                       }
-               }
-       }
-
-       return FAILURE;
-} /* }}} */
-
-int phpdbg_breakpoint_symbol(zend_function *fbc TSRMLS_DC)
-{
-       const char *fname;
-       zend_llist *break_list;
-
-       if (fbc->type != ZEND_USER_FUNCTION) {
-               return FAILURE;
-       }
-
-       fname = ((zend_op_array*)fbc)->function_name;
-
-       if (!fname) {
-               fname = "main";
-       }
-
-       if (zend_hash_find(&PHPDBG_G(bp_symbols), fname, strlen(fname),
-               (void**)&break_list) == SUCCESS) {
-               printf("breakpoint reached!\n");
-               return SUCCESS;
-       }
-
-       return FAILURE;
-}
-
 int phpdbg_interactive(int argc, char **argv TSRMLS_DC) /* {{{ */
 {
        char cmd[PHPDBG_MAX_CMD];
 
        printf("phpdbg> ");
 
-       while (!PHPDBG_G(quitting) && 
+       while (!PHPDBG_G(quitting) &&
               fgets(cmd, PHPDBG_MAX_CMD, stdin) != NULL) {
                size_t cmd_len = strlen(cmd) - 1;
 
index 0f938e0051eb2701edea6d222ff5b2a35f983705..b6921d671e446c223327bfd26f4cda130566bc54 100644 (file)
@@ -43,23 +43,6 @@ typedef struct _phpdbg_command_t {
        phpdbg_command_handler_t handler;   /* Command handler */
 } phpdbg_command_t;
 
-
-/**
- * Breakpoint file-based representation
- */
-typedef struct _phpdbg_breakfile_t {
-       const char *filename;
-       long line;
-} phpdbg_breakfile_t;
-
-/**
- * Breakpoint symbol-based representation
- */
-typedef struct _phpdbg_breaksymbol_t {
-       const char *symbol;
-       long opline_num;
-} phpdbg_breaksymbol_t;
-
 /**
  * Command Executor
  */