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)])
+----------------------------------------------------------------------+
*/
-#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
} zend_end_try();
zend_try {
- phpdbg_iteractive(argc, argv);
+ phpdbg_interactive(argc, argv TSRMLS_CC);
} zend_end_try();
if (PG(modules_activated)) {
--- /dev/null
+/*
+ +----------------------------------------------------------------------+
+ | 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;
+} /* }}} */
--- /dev/null
+/*
+ +----------------------------------------------------------------------+
+ | 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 */
| 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, " ", ¶ms);
- 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];
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> ");
}
} /* }}} */
| 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 */