phpdbg_cmd.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. #ifndef PHPDBG_CMD_H
  21. #define PHPDBG_CMD_H
  22. #include "TSRM.h"
  23. /* {{{ Command and Parameter */
  24. enum {
  25. NO_ARG = 0,
  26. REQUIRED_ARG,
  27. OPTIONAL_ARG
  28. };
  29. typedef enum {
  30. EMPTY_PARAM = 0,
  31. ADDR_PARAM,
  32. FILE_PARAM,
  33. NUMERIC_FILE_PARAM,
  34. METHOD_PARAM,
  35. STR_PARAM,
  36. NUMERIC_PARAM,
  37. NUMERIC_FUNCTION_PARAM,
  38. NUMERIC_METHOD_PARAM,
  39. STACK_PARAM,
  40. EVAL_PARAM,
  41. SHELL_PARAM,
  42. COND_PARAM,
  43. OP_PARAM,
  44. ORIG_PARAM,
  45. RUN_PARAM
  46. } phpdbg_param_type;
  47. typedef struct _phpdbg_param phpdbg_param_t;
  48. struct _phpdbg_param {
  49. phpdbg_param_type type;
  50. long num;
  51. zend_ulong addr;
  52. struct {
  53. char *name;
  54. long line;
  55. } file;
  56. struct {
  57. char *class;
  58. char *name;
  59. } method;
  60. char *str;
  61. size_t len;
  62. phpdbg_param_t *next;
  63. phpdbg_param_t *top;
  64. };
  65. #define phpdbg_init_param(v, t) do{ \
  66. (v)->type = (t); \
  67. (v)->addr = 0; \
  68. (v)->num = 0; \
  69. (v)->file.name = NULL; \
  70. (v)->file.line = 0; \
  71. (v)->method.class = NULL; \
  72. (v)->method.name = NULL; \
  73. (v)->str = NULL; \
  74. (v)->len = 0; \
  75. (v)->next = NULL; \
  76. (v)->top = NULL; \
  77. } while(0)
  78. #ifndef YYSTYPE
  79. #define YYSTYPE phpdbg_param_t
  80. #endif
  81. typedef int (*phpdbg_command_handler_t)(const phpdbg_param_t* TSRMLS_DC);
  82. typedef struct _phpdbg_command_t phpdbg_command_t;
  83. struct _phpdbg_command_t {
  84. const char *name; /* Command name */
  85. size_t name_len; /* Command name length */
  86. const char *tip; /* Menu tip */
  87. size_t tip_len; /* Menu tip length */
  88. char alias; /* Alias */
  89. phpdbg_command_handler_t handler; /* Command handler */
  90. const phpdbg_command_t *subs; /* Sub Commands */
  91. char *args; /* Argument Spec */
  92. const phpdbg_command_t *parent; /* Parent Command */
  93. };
  94. /* }}} */
  95. /* {{{ misc */
  96. #define PHPDBG_STRL(s) s, sizeof(s)-1
  97. #define PHPDBG_MAX_CMD 500
  98. #define PHPDBG_FRAME(v) (PHPDBG_G(frame).v)
  99. #define PHPDBG_EX(v) (EG(current_execute_data)->v)
  100. typedef struct {
  101. int num;
  102. zend_execute_data *execute_data;
  103. } phpdbg_frame_t;
  104. /* }}} */
  105. /*
  106. * Workflow:
  107. * 1) the lexer/parser creates a stack of commands and arguments from input
  108. * 2) the commands at the top of the stack are resolved sensibly using aliases, abbreviations and case insensitive matching
  109. * 3) the remaining arguments in the stack are verified (optionally) against the handlers declared argument specification
  110. * 4) the handler is called passing the top of the stack as the only parameter
  111. * 5) the stack is destroyed upon return from the handler
  112. */
  113. /*
  114. * Input Management
  115. */
  116. PHPDBG_API char* phpdbg_read_input(char *buffered TSRMLS_DC);
  117. PHPDBG_API void phpdbg_destroy_input(char** TSRMLS_DC);
  118. /**
  119. * Stack Management
  120. */
  121. PHPDBG_API void phpdbg_stack_push(phpdbg_param_t *stack, phpdbg_param_t *param);
  122. 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);
  123. PHPDBG_API int phpdbg_stack_verify(const phpdbg_command_t *command, phpdbg_param_t **stack, char **why TSRMLS_DC);
  124. PHPDBG_API int phpdbg_stack_execute(phpdbg_param_t *stack, char **why TSRMLS_DC);
  125. PHPDBG_API void phpdbg_stack_free(phpdbg_param_t *stack);
  126. /*
  127. * Parameter Management
  128. */
  129. PHPDBG_API void phpdbg_clear_param(phpdbg_param_t* TSRMLS_DC);
  130. PHPDBG_API void phpdbg_copy_param(const phpdbg_param_t*, phpdbg_param_t* TSRMLS_DC);
  131. PHPDBG_API zend_bool phpdbg_match_param(const phpdbg_param_t *, const phpdbg_param_t * TSRMLS_DC);
  132. PHPDBG_API zend_ulong phpdbg_hash_param(const phpdbg_param_t * TSRMLS_DC);
  133. PHPDBG_API const char* phpdbg_get_param_type(const phpdbg_param_t* TSRMLS_DC);
  134. PHPDBG_API char* phpdbg_param_tostring(const phpdbg_param_t *param, char **pointer TSRMLS_DC);
  135. PHPDBG_API void phpdbg_param_debug(const phpdbg_param_t *param, const char *msg);
  136. /**
  137. * Command Declarators
  138. */
  139. #define PHPDBG_COMMAND_HANDLER(name) phpdbg_do_##name
  140. #define PHPDBG_COMMAND_D_EXP(name, tip, alias, handler, children, args, parent) \
  141. {PHPDBG_STRL(#name), tip, sizeof(tip)-1, alias, phpdbg_do_##handler, children, args, parent}
  142. #define PHPDBG_COMMAND_D_EX(name, tip, alias, handler, children, args) \
  143. {PHPDBG_STRL(#name), tip, sizeof(tip)-1, alias, phpdbg_do_##handler, children, args, NULL}
  144. #define PHPDBG_COMMAND_D(name, tip, alias, children, args) \
  145. {PHPDBG_STRL(#name), tip, sizeof(tip)-1, alias, phpdbg_do_##name, children, args, NULL}
  146. #define PHPDBG_COMMAND(name) int phpdbg_do_##name(const phpdbg_param_t *param TSRMLS_DC)
  147. #define PHPDBG_COMMAND_ARGS param TSRMLS_CC
  148. #define PHPDBG_END_COMMAND {NULL, 0, NULL, 0, '\0', NULL, NULL, '\0', NULL}
  149. /*
  150. * Default Switch Case
  151. */
  152. #define phpdbg_default_switch_case() \
  153. default: \
  154. phpdbg_error("Unsupported parameter type (%s) for command", phpdbg_get_param_type(param TSRMLS_CC)); \
  155. break
  156. #endif /* PHPDBG_CMD_H */