From: krakjoe Date: Sun, 10 Nov 2013 10:44:42 +0000 (+0000) Subject: bit more work on menu X-Git-Tag: php-5.6.0alpha1~110^2~550 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2089caed53dd3e4e83b847b6786cb5969edd5b49;p=php bit more work on menu implement helper menu name some macros to help with declarations (sorry Felipe :)) --- diff --git a/config.m4 b/config.m4 index d2dac4acb3..b62d099ad4 100644 --- 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)]) diff --git a/phpdbg.c b/phpdbg.c index d1f127d032..b5ba10a232 100644 --- a/phpdbg.c +++ b/phpdbg.c @@ -16,27 +16,40 @@ +----------------------------------------------------------------------+ */ -#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 -#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 index 0000000000..5cb2d209d6 --- /dev/null +++ b/phpdbg_help.c @@ -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 | + | Authors: Joe Watkins | + +----------------------------------------------------------------------+ +*/ + +#include +#include +#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 index 0000000000..f2a2e2dd88 --- /dev/null +++ b/phpdbg_help.h @@ -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 | + | Authors: Joe Watkins | + +----------------------------------------------------------------------+ +*/ + +#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 */ diff --git a/phpdbg_prompt.c b/phpdbg_prompt.c index 7954492189..be33353a99 100644 --- a/phpdbg_prompt.c +++ b/phpdbg_prompt.c @@ -13,46 +13,94 @@ | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Felipe Pena | + | Authors: Joe Watkins | +----------------------------------------------------------------------+ */ #include #include #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 \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]; @@ -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> "); } } /* }}} */ diff --git a/phpdbg_prompt.h b/phpdbg_prompt.h index 09a5028a36..b1238ece64 100644 --- a/phpdbg_prompt.h +++ b/phpdbg_prompt.h @@ -13,6 +13,7 @@ | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Felipe Pena | + | Authors: Joe Watkins | +----------------------------------------------------------------------+ */ @@ -29,17 +30,32 @@ /** * 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 */