phpdbg_cmd.h 6.1 KB

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