You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

184 lines
6.0 KiB

12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2014 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. #define PHPDBG_ASYNC_SAFE 1
  82. typedef int (*phpdbg_command_handler_t)(const phpdbg_param_t*);
  83. typedef struct _phpdbg_command_t phpdbg_command_t;
  84. struct _phpdbg_command_t {
  85. const char *name; /* Command name */
  86. size_t name_len; /* Command name length */
  87. const char *tip; /* Menu tip */
  88. size_t tip_len; /* Menu tip length */
  89. char alias; /* Alias */
  90. phpdbg_command_handler_t handler; /* Command handler */
  91. const phpdbg_command_t *subs; /* Sub Commands */
  92. char *args; /* Argument Spec */
  93. const phpdbg_command_t *parent; /* Parent Command */
  94. zend_bool flags; /* General flags */
  95. };
  96. /* }}} */
  97. /* {{{ misc */
  98. #define PHPDBG_STRL(s) s, sizeof(s)-1
  99. #define PHPDBG_MAX_CMD 500
  100. #define PHPDBG_FRAME(v) (PHPDBG_G(frame).v)
  101. #define PHPDBG_EX(v) (EG(current_execute_data)->v)
  102. typedef struct {
  103. int num;
  104. zend_execute_data *execute_data;
  105. } phpdbg_frame_t;
  106. /* }}} */
  107. /*
  108. * Workflow:
  109. * 1) the lexer/parser creates a stack of commands and arguments from input
  110. * 2) the commands at the top of the stack are resolved sensibly using aliases, abbreviations and case insensitive matching
  111. * 3) the remaining arguments in the stack are verified (optionally) against the handlers declared argument specification
  112. * 4) the handler is called passing the top of the stack as the only parameter
  113. * 5) the stack is destroyed upon return from the handler
  114. */
  115. /*
  116. * Input Management
  117. */
  118. PHPDBG_API char* phpdbg_read_input(char *buffered);
  119. PHPDBG_API void phpdbg_destroy_input(char**);
  120. PHPDBG_API int phpdbg_ask_user_permission(const char *question);
  121. /**
  122. * Stack Management
  123. */
  124. PHPDBG_API void phpdbg_stack_push(phpdbg_param_t *stack, phpdbg_param_t *param);
  125. PHPDBG_API const phpdbg_command_t *phpdbg_stack_resolve(const phpdbg_command_t *commands, const phpdbg_command_t *parent, phpdbg_param_t **top);
  126. PHPDBG_API int phpdbg_stack_verify(const phpdbg_command_t *command, phpdbg_param_t **stack);
  127. PHPDBG_API int phpdbg_stack_execute(phpdbg_param_t *stack, zend_bool allow_async_unsafe);
  128. PHPDBG_API void phpdbg_stack_free(phpdbg_param_t *stack);
  129. /*
  130. * Parameter Management
  131. */
  132. PHPDBG_API void phpdbg_clear_param(phpdbg_param_t*);
  133. PHPDBG_API void phpdbg_copy_param(const phpdbg_param_t*, phpdbg_param_t*);
  134. PHPDBG_API zend_bool phpdbg_match_param(const phpdbg_param_t *, const phpdbg_param_t *);
  135. PHPDBG_API zend_ulong phpdbg_hash_param(const phpdbg_param_t *);
  136. PHPDBG_API const char* phpdbg_get_param_type(const phpdbg_param_t*);
  137. PHPDBG_API char* phpdbg_param_tostring(const phpdbg_param_t *param, char **pointer);
  138. PHPDBG_API void phpdbg_param_debug(const phpdbg_param_t *param, const char *msg);
  139. /**
  140. * Command Declarators
  141. */
  142. #define PHPDBG_COMMAND_HANDLER(name) phpdbg_do_##name
  143. #define PHPDBG_COMMAND_D_EXP(name, tip, alias, handler, children, args, parent, flags) \
  144. {PHPDBG_STRL(#name), tip, sizeof(tip)-1, alias, phpdbg_do_##handler, children, args, parent, flags}
  145. #define PHPDBG_COMMAND_D_EX(name, tip, alias, handler, children, args, flags) \
  146. {PHPDBG_STRL(#name), tip, sizeof(tip)-1, alias, phpdbg_do_##handler, children, args, NULL, flags}
  147. #define PHPDBG_COMMAND_D(name, tip, alias, children, args, flags) \
  148. {PHPDBG_STRL(#name), tip, sizeof(tip)-1, alias, phpdbg_do_##name, children, args, NULL, flags}
  149. #define PHPDBG_COMMAND(name) int phpdbg_do_##name(const phpdbg_param_t *param)
  150. #define PHPDBG_COMMAND_ARGS param
  151. #define PHPDBG_END_COMMAND {NULL, 0, NULL, 0, '\0', NULL, NULL, NULL, NULL, 0}
  152. /*
  153. * Default Switch Case
  154. */
  155. #define phpdbg_default_switch_case() \
  156. default: \
  157. phpdbg_error("command", "type=\"wrongarg\" got=\"%s\"", "Unsupported parameter type (%s) for command", phpdbg_get_param_type(param)); \
  158. break
  159. #endif /* PHPDBG_CMD_H */