root/sapi/phpdbg/phpdbg_cmd.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


   1 /*
   2    +----------------------------------------------------------------------+
   3    | PHP Version 5                                                        |
   4    +----------------------------------------------------------------------+
   5    | Copyright (c) 1997-2016 The PHP Group                                |
   6    +----------------------------------------------------------------------+
   7    | This source file is subject to version 3.01 of the PHP license,      |
   8    | that is bundled with this package in the file LICENSE, and is        |
   9    | available through the world-wide-web at the following url:           |
  10    | http://www.php.net/license/3_01.txt                                  |
  11    | If you did not receive a copy of the PHP license and are unable to   |
  12    | obtain it through the world-wide-web, please send a note to          |
  13    | license@php.net so we can mail you a copy immediately.               |
  14    +----------------------------------------------------------------------+
  15    | Authors: Felipe Pena <felipe@php.net>                                |
  16    | Authors: Joe Watkins <joe.watkins@live.co.uk>                        |
  17    | Authors: Bob Weinand <bwoebi@php.net>                                |
  18    +----------------------------------------------------------------------+
  19 */
  20 
  21 #ifndef PHPDBG_CMD_H
  22 #define PHPDBG_CMD_H
  23 
  24 #include "TSRM.h"
  25 
  26 /* {{{ Command and Parameter */
  27 enum {
  28         NO_ARG = 0,
  29         REQUIRED_ARG,
  30         OPTIONAL_ARG
  31 };
  32 
  33 typedef enum {
  34         EMPTY_PARAM = 0,
  35         ADDR_PARAM,
  36         FILE_PARAM,
  37         NUMERIC_FILE_PARAM,
  38         METHOD_PARAM,
  39         STR_PARAM,
  40         NUMERIC_PARAM,
  41         NUMERIC_FUNCTION_PARAM,
  42         NUMERIC_METHOD_PARAM,
  43         STACK_PARAM,
  44         EVAL_PARAM,
  45         SHELL_PARAM,
  46         COND_PARAM,
  47         OP_PARAM,
  48         ORIG_PARAM,
  49         RUN_PARAM
  50 } phpdbg_param_type;
  51 
  52 typedef struct _phpdbg_param phpdbg_param_t;
  53 struct _phpdbg_param {
  54         phpdbg_param_type type;
  55         long num;
  56         zend_ulong addr;
  57         struct {
  58                 char *name;
  59                 long line;
  60         } file;
  61         struct {
  62                 char *class;
  63                 char *name;
  64         } method;
  65         char *str;
  66         size_t len;
  67         phpdbg_param_t *next;
  68         phpdbg_param_t *top;
  69 };
  70 
  71 #define phpdbg_init_param(v, t) do{ \
  72         (v)->type = (t); \
  73         (v)->addr = 0; \
  74         (v)->num = 0; \
  75         (v)->file.name = NULL; \
  76         (v)->file.line = 0; \
  77         (v)->method.class = NULL; \
  78         (v)->method.name = NULL; \
  79         (v)->str = NULL; \
  80         (v)->len = 0; \
  81         (v)->next = NULL; \
  82         (v)->top = NULL; \
  83 } while(0)
  84 
  85 #ifndef YYSTYPE
  86 #define YYSTYPE phpdbg_param_t
  87 #endif
  88 
  89 typedef int (*phpdbg_command_handler_t)(const phpdbg_param_t* TSRMLS_DC);
  90 
  91 typedef struct _phpdbg_command_t phpdbg_command_t;
  92 struct _phpdbg_command_t {
  93         const char *name;                   /* Command name */
  94         size_t name_len;                    /* Command name length */
  95         const char *tip;                    /* Menu tip */
  96         size_t tip_len;                     /* Menu tip length */
  97         char alias;                         /* Alias */
  98         phpdbg_command_handler_t handler;   /* Command handler */
  99         const phpdbg_command_t *subs;       /* Sub Commands */
 100         char *args;                                                     /* Argument Spec */
 101         const phpdbg_command_t *parent;         /* Parent Command */                                                    
 102 };
 103 /* }}} */
 104 
 105 /* {{{ misc */
 106 #define PHPDBG_STRL(s) s, sizeof(s)-1
 107 #define PHPDBG_MAX_CMD 500
 108 #define PHPDBG_FRAME(v) (PHPDBG_G(frame).v)
 109 #define PHPDBG_EX(v) (EG(current_execute_data)->v) 
 110 
 111 typedef struct {
 112         int num;
 113         zend_execute_data *execute_data;
 114 } phpdbg_frame_t;
 115 /* }}} */
 116 
 117 /*
 118 * Workflow:
 119 * 1) the lexer/parser creates a stack of commands and arguments from input
 120 * 2) the commands at the top of the stack are resolved sensibly using aliases, abbreviations and case insensitive matching
 121 * 3) the remaining arguments in the stack are verified (optionally) against the handlers declared argument specification
 122 * 4) the handler is called passing the top of the stack as the only parameter
 123 * 5) the stack is destroyed upon return from the handler
 124 */
 125 
 126 /*
 127 * Input Management
 128 */
 129 PHPDBG_API char* phpdbg_read_input(char *buffered TSRMLS_DC);
 130 PHPDBG_API void phpdbg_destroy_input(char** TSRMLS_DC);
 131 
 132 /**
 133  * Stack Management
 134  */
 135 PHPDBG_API void phpdbg_stack_push(phpdbg_param_t *stack, phpdbg_param_t *param);
 136 PHPDBG_API const phpdbg_command_t* phpdbg_stack_resolve(const phpdbg_command_t *commands, const phpdbg_command_t *parent, phpdbg_param_t **top, char **why);
 137 PHPDBG_API int phpdbg_stack_verify(const phpdbg_command_t *command, phpdbg_param_t **stack, char **why TSRMLS_DC);
 138 PHPDBG_API int phpdbg_stack_execute(phpdbg_param_t *stack, char **why TSRMLS_DC);
 139 PHPDBG_API void phpdbg_stack_free(phpdbg_param_t *stack);
 140 
 141 /*
 142 * Parameter Management
 143 */
 144 PHPDBG_API void phpdbg_clear_param(phpdbg_param_t* TSRMLS_DC);
 145 PHPDBG_API void phpdbg_copy_param(const phpdbg_param_t*, phpdbg_param_t* TSRMLS_DC);
 146 PHPDBG_API zend_bool phpdbg_match_param(const phpdbg_param_t *, const phpdbg_param_t * TSRMLS_DC);
 147 PHPDBG_API zend_ulong phpdbg_hash_param(const phpdbg_param_t * TSRMLS_DC);
 148 PHPDBG_API const char* phpdbg_get_param_type(const phpdbg_param_t* TSRMLS_DC);
 149 PHPDBG_API char* phpdbg_param_tostring(const phpdbg_param_t *param, char **pointer TSRMLS_DC);
 150 PHPDBG_API void phpdbg_param_debug(const phpdbg_param_t *param, const char *msg);
 151 
 152 /**
 153  * Command Declarators
 154  */
 155 #define PHPDBG_COMMAND_HANDLER(name) phpdbg_do_##name
 156 
 157 #define PHPDBG_COMMAND_D_EXP(name, tip, alias, handler, children, args, parent) \
 158         {PHPDBG_STRL(#name), tip, sizeof(tip)-1, alias, phpdbg_do_##handler, children, args, parent}
 159 
 160 #define PHPDBG_COMMAND_D_EX(name, tip, alias, handler, children, args) \
 161         {PHPDBG_STRL(#name), tip, sizeof(tip)-1, alias, phpdbg_do_##handler, children, args, NULL}
 162 
 163 #define PHPDBG_COMMAND_D(name, tip, alias, children, args) \
 164         {PHPDBG_STRL(#name), tip, sizeof(tip)-1, alias, phpdbg_do_##name, children, args, NULL}
 165 
 166 #define PHPDBG_COMMAND(name) int phpdbg_do_##name(const phpdbg_param_t *param TSRMLS_DC)
 167 
 168 #define PHPDBG_COMMAND_ARGS param TSRMLS_CC
 169 
 170 #define PHPDBG_END_COMMAND {NULL, 0, NULL, 0, '\0', NULL, NULL, '\0', NULL}
 171 
 172 /*
 173 * Default Switch Case
 174 */
 175 #define phpdbg_default_switch_case() \
 176         default: \
 177                 phpdbg_error("Unsupported parameter type (%s) for command", phpdbg_get_param_type(param TSRMLS_CC)); \
 178         break
 179 
 180 #endif /* PHPDBG_CMD_H */

/* [<][>][^][v][top][bottom][index][help] */