]> granicus.if.org Git - php/commitdiff
bit more work on menu
authorkrakjoe <joe.watkins@live.co.uk>
Sun, 10 Nov 2013 10:44:42 +0000 (10:44 +0000)
committerkrakjoe <joe.watkins@live.co.uk>
Sun, 10 Nov 2013 10:44:42 +0000 (10:44 +0000)
implement helper menu
name some macros to help with declarations (sorry Felipe :))

config.m4
phpdbg.c
phpdbg_help.c [new file with mode: 0644]
phpdbg_help.h [new file with mode: 0644]
phpdbg_prompt.c
phpdbg_prompt.h

index d2dac4acb3d6e3aa284948482bac734aeec62857..b62d099ad4065a538bf00c63f4ab9f91bf8f2980 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"
+  PHP_PHPDBG_FILES="phpdbg.c phpdbg_prompt.c phpdbg_help.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 d1f127d032737ea3f3b66fb45b6bba5271921de8..b5ba10a232d53972c9570e3668e62b00a67a5f1d 100644 (file)
--- a/phpdbg.c
+++ b/phpdbg.c
    +----------------------------------------------------------------------+
 */
 
-#include "php.h"
-#include "php_globals.h"
-#include "php_variables.h"
-#include "zend_modules.h"
-#include "php.h"
-#include "zend_ini_scanner.h"
-#include "zend_globals.h"
-#include "zend_stream.h"
-#include "SAPI.h"
-#include <php_config.h>
-#include "php_main.h"
-#include "phpdbg_prompt.h"
+#include "phpdbg.h"
+
+ZEND_DECLARE_MODULE_GLOBALS(phpdbg);
+
+static inline void php_phpdbg_globals_ctor(zend_phpdbg_globals *pg) {}
+
+static PHP_MINIT_FUNCTION(phpdbg) {
+  ZEND_INIT_MODULE_GLOBALS(phpdbg, php_phpdbg_globals_ctor, NULL);
+  
+  return SUCCESS;
+}
+
+static inline void php_phpdbg_destroy_break(void *brake) {
+  
+}
+
+static PHP_RINIT_FUNCTION(phpdbg) {
+  zend_hash_init(&PHPDBG_G(breaks), 8, NULL, php_phpdbg_destroy_break, 0);
+  
+  return SUCCESS;
+}
+
+static PHP_RSHUTDOWN_FUNCTION(phpdbg) {
+  zend_hash_destroy(&PHPDBG_G(breaks));
+}
 
 static zend_module_entry sapi_phpdbg_module_entry = {
        STANDARD_MODULE_HEADER,
        "phpdbg",
        NULL,
+       PHP_MINIT(phpdbg),
        NULL,
-       NULL,
-       NULL,
-       NULL,
+       PHP_RINIT(phpdbg),
+       PHP_RSHUTDOWN(phpdbg),
        NULL,
        "0.1",
        STANDARD_MODULE_PROPERTIES
@@ -121,7 +134,7 @@ int main(int argc, char **argv) /* {{{ */
                } zend_end_try();
 
                zend_try {
-                       phpdbg_iteractive(argc, argv);
+                       phpdbg_interactive(argc, argv TSRMLS_CC);
                } zend_end_try();
 
                if (PG(modules_activated)) {
diff --git a/phpdbg_help.c b/phpdbg_help.c
new file mode 100644 (file)
index 0000000..5cb2d20
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+   +----------------------------------------------------------------------+
+   | 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 <stdio.h>
+#include <string.h>
+#include "zend.h"
+#include "phpdbg.h"
+#include "phpdbg_help.h"
+
+PHPDBG_HELP(print) /* {{{ */ 
+{
+  printf("doing print help: %s\n", expr);
+  
+  return SUCCESS;
+} /* }}} */
+
+PHPDBG_HELP(brake) /* {{{ */
+{
+    printf("doing brake help: %s\n", expr);
+    
+    return SUCCESS;
+} /* }}} */
diff --git a/phpdbg_help.h b/phpdbg_help.h
new file mode 100644 (file)
index 0000000..f2a2e2d
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+   +----------------------------------------------------------------------+
+   | 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_HELP_H
+#define PHPDBG_HELP_H
+
+/**
+ * Command Declarators
+ */
+#define PHPDBG_HELP_D(name, tip) \
+  {PHPDBG_STRL(#name), tip, sizeof(tip)-1, phpdbg_do_help_##name}
+#define PHPDBG_HELP(name) \
+  int phpdbg_do_help_##name(const char *expr, size_t expr_len TSRMLS_DC)
+
+/**
+ * Helper Forward Declarations
+ */
+PHPDBG_HELP(print);
+PHPDBG_HELP(brake);
+
+/**
+ * Commands
+ */
+static const phpdbg_command_t phpdbg_help_commands[] = {
+  PHPDBG_HELP_D(print, "printing allows inspection of the execution environment"),
+  PHPDBG_HELP_D(brake, "brake points allow execution interruption"),
+  {NULL, 0, 0}
+};
+
+#endif /* PHPDBG_HELP_H */
index 79544921897e05a50c050a8eb07536b17cb484fd..be33353a995798bbfb7b5b2fb1c12e6291b5789a 100644 (file)
    | 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 <stdio.h>
 #include <string.h>
 #include "zend.h"
-#include "phpdbg_prompt.h"
+#include "phpdbg.h"
+#include "phpdbg_help.h"
 
-static void do_quit(const char *params) /* {{{ */
+static const phpdbg_command_t phpdbg_prompt_commands[];
+
+static PHPDBG_COMMAND(print) { /* {{{ */ 
+  printf("%s", expr);
+  
+  return SUCCESS;
+} /* }}} */
+
+static PHPDBG_COMMAND(brake) { /* {{{ */
+  return SUCCESS;
+} /* }}} */
+
+static PHPDBG_COMMAND(quit) /* {{{ */
 {
        zend_bailout();
+       
+       return SUCCESS;
 } /* }}} */
 
-static const phpdbg_command prompt_commands[] = {
-       {PHPDBG_STRL("quit"), do_quit},
+static PHPDBG_COMMAND(help) /* {{{ */
+{
+  printf("Welcome to phpdbg, the interactive PHP debugger.\n");
+  if (!expr_len) {
+    printf("To get help regarding a specific command type \"help command\"\n");
+    printf("Commands:\n");
+    {
+      const phpdbg_command_t *command = phpdbg_prompt_commands;
+      while (command && command->name) {
+        printf(
+          "\t%s\t%s\n", command->name, command->tip);
+        command++;
+      }
+    }
+    printf("Helpers Loaded:\n");
+    {
+      const phpdbg_command_t *command = phpdbg_help_commands;
+      while (command && command->name) {
+        printf(
+          "\t%s\t%s\n", command->name, command->tip);
+        command++;
+      }
+    }
+  } else {
+    if (phpdbg_do_cmd(phpdbg_help_commands, expr, expr_len TSRMLS_CC) == FAILURE) {
+      printf("failed to find help command: %s\n", expr);
+    }
+  }
+  printf("Please report bugs to <http://theman.in/themoon>\n");
+  
+  return SUCCESS;
+} /* }}} */
+
+static const phpdbg_command_t phpdbg_prompt_commands[] = {  
+  PHPDBG_COMMAND_D(print, "print something"),
+       PHPDBG_COMMAND_D(brake, "set brake point"),
+       PHPDBG_COMMAND_D(help,  "show help menu"),
+       PHPDBG_COMMAND_D(quit,  "exit phpdbg"),
        {NULL, 0, 0}
 };
 
-static void do_cmd(char *cmd_line) /* {{{ */
+int phpdbg_do_cmd(const phpdbg_command_t *command, char *cmd_line, size_t cmd_len TSRMLS_DC) /* {{{ */
 {
-       const phpdbg_command *command = prompt_commands;
        char *params = NULL;
        const char *cmd = strtok_r(cmd_line, " ", &params);
-       size_t cmd_len = cmd ? strlen(cmd) : 0;
-
+       size_t expr_len = cmd != NULL ? strlen(cmd) : 0;
+       
        while (command && command->name) {
-               if (command->name_len == cmd_len
-                       && memcmp(cmd, command->name, cmd_len) == 0) {
-                       /* Command found! */
-                       command->handler(params);
-                       return;
+               if (command->name_len == expr_len
+                       && memcmp(cmd, command->name, expr_len) == 0) {
+                       return command->handler(params, cmd_len - expr_len TSRMLS_CC);
                }
                ++command;
        }
 
-       printf("command not found!\n");
-
+       return FAILURE;
 } /* }}} */
 
-void phpdbg_iteractive(int argc, char **argv) /* {{{ */
+void phpdbg_interactive(int argc, char **argv TSRMLS_DC) /* {{{ */
 {
        char cmd[PHPDBG_MAX_CMD];
 
@@ -61,12 +109,16 @@ void phpdbg_iteractive(int argc, char **argv) /* {{{ */
        while (fgets(cmd, PHPDBG_MAX_CMD, stdin) != NULL) {
                size_t cmd_len = strlen(cmd) - 1;
 
-               if (cmd[cmd_len] == '\n') {
+               while (cmd[cmd_len] == '\n') {
                        cmd[cmd_len] = 0;
                }
+               
                if (cmd_len) {
-                       do_cmd(cmd);
+                       if (phpdbg_do_cmd(phpdbg_prompt_commands, cmd, cmd_len TSRMLS_CC) == FAILURE) {
+                         printf("error executing %s !\n", cmd);
+                       }
                }
+               
                printf("phpdbg> ");
        }
 } /* }}} */
index 09a5028a3617134ac8d30a2adb291afebfbde7ca..b1238ece64008e645b5b768f945eb63c476a40af 100644 (file)
@@ -13,6 +13,7 @@
    | 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>                        |
    +----------------------------------------------------------------------+
 */
 
 /**
  * Command handler
  */
-typedef void (*phpdbg_command_handler)(const char*);
+typedef int (*phpdbg_command_handler_t)(const char* expr, size_t expr_len TSRMLS_DC);
 
 /**
  * Command representation
  */
-typedef struct _phpdbg_command {
+typedef struct _phpdbg_command_t {
        const char *name;                   /* Command name */
        size_t name_len;                    /* Command name length */
-       phpdbg_command_handler handler;     /* Command handler */
-} phpdbg_command;
+       const char *tip;                    /* Menu tip */
+       size_t tip_len;                     /* Menu tip length */
+       phpdbg_command_handler_t handler;   /* Command handler */
+} phpdbg_command_t;
 
-void phpdbg_iteractive(int, char**);
+/**
+ * Command Executor
+ */
+int phpdbg_do_cmd(const phpdbg_command_t *command, char *cmd_line, size_t cmd_len TSRMLS_DC);
+
+/**
+ * Command Declarators
+ */
+#define PHPDBG_COMMAND_D(name, tip) \
+  {PHPDBG_STRL(#name), tip, sizeof(tip)-1, phpdbg_do_##name}
+#define PHPDBG_COMMAND(name) \
+  int phpdbg_do_##name(const char *expr, size_t expr_len TSRMLS_DC)
+
+void phpdbg_interactive(int argc, char** argv TSRMLS_DC);
 
 #endif /* PHPDBG_PROMPT_H */