]> granicus.if.org Git - php/commitdiff
- More work on file:line breakpoint
authorFelipe Pena <felipensp@gmail.com>
Sun, 10 Nov 2013 15:11:56 +0000 (13:11 -0200)
committerFelipe Pena <felipensp@gmail.com>
Sun, 10 Nov 2013 15:11:56 +0000 (13:11 -0200)
1  2 
phpdbg.c
phpdbg.h
phpdbg_prompt.c
phpdbg_prompt.h

diff --cc phpdbg.c
Simple merge
diff --cc phpdbg.h
index 8dbf89fe6291e336b6f6af9c4dae2df14610addf,0b1f2daa88508a53d82ee88fdb93677284360b51..26fb118f4a4733ea0207f18571f4e0b48216a9d4
+++ b/phpdbg.h
  # define PHPDBG_G(v) (phpdbg_globals.v)
  #endif
  
+ #define PHPDBG_NEXT 2
  ZEND_BEGIN_MODULE_GLOBALS(phpdbg)
-   HashTable break_files;
-   HashTable break_symbols;
-   char *exec;               /* file to execute */
-   size_t exec_len;          /* size of exec */
-   zend_op_array *ops;       /* op_array */
-   zval *retval;             /* return value */
-   zend_bool has_breakpoint; /* breakpoint has been set */
 -  HashTable breaks;
 -  char *exec;             /* file to execute */
 -  size_t exec_len;        /* size of exec */
 -  zend_op_array *ops;     /* op_array */
 -  zval *retval;           /* return value */
 -  zend_bool stepping;     /* stepping */
 -  int vmret;              /* return from last opcode handler execution */
++      HashTable break_files;
++      HashTable break_symbols;
++      char *exec;             /* file to execute */
++      size_t exec_len;        /* size of exec */
++      zend_op_array *ops;     /* op_array */
++      zval *retval;           /* return value */
++      zend_bool stepping;     /* stepping */
++      int vmret;              /* return from last opcode handler execution */
++      zend_bool has_file_bp;  /* file-based breakpoint has been set */
  ZEND_END_MODULE_GLOBALS(phpdbg)
  
  #include "phpdbg_prompt.h"
diff --cc phpdbg_prompt.c
index 1af00badcf4b73b8e7280bfe180889c6610e2937,0dfe14b1befd3295bbd6b12450e6b1ce6ee67a24..9ab38ae096a4eb080700e873684bce96c9b484d6
@@@ -128,27 -140,8 +140,34 @@@ static PHPDBG_COMMAND(print) { /* {{{ *
    return SUCCESS;
  } /* }}} */
  
 -static PHPDBG_COMMAND(break) { /* {{{ */
 -  return SUCCESS;
 +static PHPDBG_COMMAND(break) /* {{{ */
 +{
 +      const char *line_pos = zend_memrchr(expr, ':', expr_len);
 +
 +      if (line_pos) {
 +              long line_num = strtol(line_pos+1, NULL, 0);
 +              phpdbg_breakfile_t new_break;
-               zend_llist break_files;
++              zend_llist *break_files_ptr;
++
++              size_t name_len = line_pos - expr;
 +
-               new_break.filename = estrndup(expr, line_pos - expr);
++              new_break.filename = estrndup(expr, name_len);
 +              new_break.line = line_num;
 +
-               PHPDBG_G(has_breakpoint) = 1;
++              PHPDBG_G(has_file_bp) = 1;
 +
-               if (zend_hash_find(&PHPDBG_G(break_files), new_break.filename, line_pos - expr, &break_files) == FAILURE) {
++              if (zend_hash_find(&PHPDBG_G(break_files),
++                      new_break.filename, name_len, (void**)&break_files_ptr) == FAILURE) {
++                      zend_llist break_files;
 +                      zend_llist_init(&break_files, sizeof(phpdbg_breakfile_t), NULL, 0);
++
++                      zend_hash_update(&PHPDBG_G(break_files),
++                              new_break.filename, name_len, &break_files, sizeof(zend_llist), (void**)&break_files_ptr);
 +              }
-               zend_llist_add_element(&break_files, &new_break);
++              zend_llist_add_element(break_files_ptr, &new_break);
 +      }
 +
 +      return SUCCESS;
  } /* }}} */
  
  static PHPDBG_COMMAND(quit) /* {{{ */
@@@ -219,12 -214,7 +240,29 @@@ int phpdbg_do_cmd(const phpdbg_command_
        return FAILURE;
  } /* }}} */
  
- void phpdbg_breakpoint(zend_op_array *op_array) /* {{{ */
++int phpdbg_breakpoint(zend_op_array *op_array TSRMLS_DC) /* {{{ */
 +{
-       printf(">> %s\n", op_array->filename);
++      size_t name_len = strlen(op_array->filename);
++      zend_llist *break_list;
++
++      if (zend_hash_find(&PHPDBG_G(break_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;
 +} /* }}} */
 +
void phpdbg_interactive(int argc, char **argv TSRMLS_DC) /* {{{ */
int phpdbg_interactive(int argc, char **argv TSRMLS_DC) /* {{{ */
  {
        char cmd[PHPDBG_MAX_CMD];
  
                }
  
                if (cmd_len) {
-                       if (phpdbg_do_cmd(phpdbg_prompt_commands, cmd, cmd_len TSRMLS_CC) == FAILURE) {
-                         printf("error executing %s !\n", cmd);
-                       }
+                   switch (phpdbg_do_cmd(phpdbg_prompt_commands, cmd, cmd_len TSRMLS_CC)) {
+                       case FAILURE:
+                           printf("error executing %s !\n", cmd);
+                       break;
 -                      
++
+                       case PHPDBG_NEXT:
+                           return PHPDBG_NEXT;
+                   }
                }
  
                printf("phpdbg> ");
        }
 -      
++
+       return SUCCESS;
  } /* }}} */
  
  void phpdbg_execute_ex(zend_execute_data *execute_data TSRMLS_DC)
@@@ -268,13 -264,18 +312,25 @@@ zend_vm_enter
  #endif
  
          printf("[OPLINE: %p]\n", execute_data->opline);
 -        
 -        PHPDBG_G(vmret) = execute_data->opline->handler(execute_data TSRMLS_CC);
 -        
 -        if (PHPDBG_G(stepping)) {
 -            while (phpdbg_interactive(
 -                0, NULL TSRMLS_CC) != PHPDBG_NEXT) {
 -                continue;
 -            }
 -        }
 -        
 +
-         if (PHPDBG_G(has_breakpoint)) {
-                       phpdbg_breakpoint(execute_data->op_array);
++        if (PHPDBG_G(has_file_bp)
++                      && phpdbg_breakpoint(execute_data->op_array TSRMLS_CC) == SUCCESS) {
++                      while (phpdbg_interactive(0, NULL TSRMLS_CC) != PHPDBG_NEXT) {
++                              continue;
++                      }
++              }
++
++              PHPDBG_G(vmret) = execute_data->opline->handler(execute_data TSRMLS_CC);
++
++              if (PHPDBG_G(stepping)) {
++                      while (phpdbg_interactive(
++                              0, NULL TSRMLS_CC) != PHPDBG_NEXT) {
++                              continue;
++                      }
 +              }
 +
-               if ((ret = execute_data->opline->handler(execute_data TSRMLS_CC)) > 0) {
-                       switch (ret) {
+               if (PHPDBG_G(vmret) > 0) {
+                       switch (PHPDBG_G(vmret)) {
                                case 1:
                                        EG(in_execution) = original_in_execution;
                                        return;
diff --cc phpdbg_prompt.h
Simple merge