phpdbg_utils.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Copyright (c) The PHP Group |
  4. +----------------------------------------------------------------------+
  5. | This source file is subject to version 3.01 of the PHP license, |
  6. | that is bundled with this package in the file LICENSE, and is |
  7. | available through the world-wide-web at the following url: |
  8. | https://www.php.net/license/3_01.txt |
  9. | If you did not receive a copy of the PHP license and are unable to |
  10. | obtain it through the world-wide-web, please send a note to |
  11. | license@php.net so we can mail you a copy immediately. |
  12. +----------------------------------------------------------------------+
  13. | Authors: Felipe Pena <felipe@php.net> |
  14. | Authors: Joe Watkins <joe.watkins@live.co.uk> |
  15. | Authors: Bob Weinand <bwoebi@php.net> |
  16. +----------------------------------------------------------------------+
  17. */
  18. #ifndef PHPDBG_UTILS_H
  19. #define PHPDBG_UTILS_H
  20. /**
  21. * Input scan functions
  22. */
  23. PHPDBG_API int phpdbg_is_numeric(const char*);
  24. PHPDBG_API int phpdbg_is_empty(const char*);
  25. PHPDBG_API int phpdbg_is_addr(const char*);
  26. PHPDBG_API int phpdbg_is_class_method(const char*, size_t, char**, char**);
  27. PHPDBG_API const char *phpdbg_current_file(void);
  28. PHPDBG_API char *phpdbg_resolve_path(const char*);
  29. PHPDBG_API char *phpdbg_trim(const char*, size_t, size_t*);
  30. PHPDBG_API const zend_function *phpdbg_get_function(const char*, const char*);
  31. /* {{{ Color Management */
  32. #define PHPDBG_COLOR_LEN 12
  33. #define PHPDBG_COLOR_D(color, code) \
  34. {color, sizeof(color)-1, code}
  35. #define PHPDBG_COLOR_END \
  36. {NULL, 0L, {0}}
  37. #define PHPDBG_ELEMENT_LEN 3
  38. #define PHPDBG_ELEMENT_D(name, id) \
  39. {name, sizeof(name)-1, id}
  40. #define PHPDBG_ELEMENT_END \
  41. {NULL, 0L, 0}
  42. #define PHPDBG_COLOR_INVALID -1
  43. #define PHPDBG_COLOR_PROMPT 0
  44. #define PHPDBG_COLOR_ERROR 1
  45. #define PHPDBG_COLOR_NOTICE 2
  46. #define PHPDBG_COLORS 3
  47. typedef struct _phpdbg_color_t {
  48. char *name;
  49. size_t name_length;
  50. const char code[PHPDBG_COLOR_LEN];
  51. } phpdbg_color_t;
  52. typedef struct _phpdbg_element_t {
  53. char *name;
  54. size_t name_length;
  55. int id;
  56. } phpdbg_element_t;
  57. PHPDBG_API const phpdbg_color_t *phpdbg_get_color(const char *name, size_t name_length);
  58. PHPDBG_API void phpdbg_set_color(int element, const phpdbg_color_t *color);
  59. PHPDBG_API void phpdbg_set_color_ex(int element, const char *name, size_t name_length);
  60. PHPDBG_API const phpdbg_color_t *phpdbg_get_colors(void);
  61. PHPDBG_API int phpdbg_get_element(const char *name, size_t len); /* }}} */
  62. /* {{{ Prompt Management */
  63. PHPDBG_API void phpdbg_set_prompt(const char*);
  64. PHPDBG_API const char *phpdbg_get_prompt(void); /* }}} */
  65. /* {{{ Console size */
  66. PHPDBG_API uint32_t phpdbg_get_terminal_width(void);
  67. PHPDBG_API uint32_t phpdbg_get_terminal_height(void); /* }}} */
  68. PHPDBG_API void phpdbg_set_async_io(int fd);
  69. int phpdbg_rebuild_symtable(void);
  70. int phpdbg_safe_class_lookup(const char *name, int name_length, zend_class_entry **ce);
  71. char *phpdbg_get_property_key(char *key);
  72. typedef int (*phpdbg_parse_var_func)(char *name, size_t len, char *keyname, size_t keylen, HashTable *parent, zval *zv);
  73. typedef int (*phpdbg_parse_var_with_arg_func)(char *name, size_t len, char *keyname, size_t keylen, HashTable *parent, zval *zv, void *arg);
  74. PHPDBG_API int phpdbg_parse_variable(char *input, size_t len, HashTable *parent, size_t i, phpdbg_parse_var_func callback, bool silent);
  75. PHPDBG_API int phpdbg_parse_variable_with_arg(char *input, size_t len, HashTable *parent, size_t i, phpdbg_parse_var_with_arg_func callback, phpdbg_parse_var_with_arg_func step_cb, bool silent, void *arg);
  76. int phpdbg_is_auto_global(char *name, int len);
  77. char *phpdbg_short_zval_print(zval *zv, int maxlen);
  78. PHPDBG_API bool phpdbg_check_caught_ex(zend_execute_data *ex, zend_object *exception);
  79. static zend_always_inline zend_execute_data *phpdbg_user_execute_data(zend_execute_data *ex) {
  80. while (!ex->func || !ZEND_USER_CODE(ex->func->common.type)) {
  81. ex = ex->prev_execute_data;
  82. ZEND_ASSERT(ex);
  83. }
  84. return ex;
  85. }
  86. #ifdef ZTS
  87. #define PHPDBG_OUTPUT_BACKUP_DEFINES() \
  88. zend_output_globals *output_globals_ptr; \
  89. zend_output_globals original_output_globals; \
  90. output_globals_ptr = TSRMG_BULK_STATIC(output_globals_id, zend_output_globals *);
  91. #else
  92. #define PHPDBG_OUTPUT_BACKUP_DEFINES() \
  93. zend_output_globals *output_globals_ptr; \
  94. zend_output_globals original_output_globals; \
  95. output_globals_ptr = &output_globals;
  96. #endif
  97. #define PHPDBG_OUTPUT_BACKUP_SWAP() \
  98. original_output_globals = *output_globals_ptr; \
  99. memset(output_globals_ptr, 0, sizeof(zend_output_globals)); \
  100. php_output_activate();
  101. #define PHPDBG_OUTPUT_BACKUP() \
  102. PHPDBG_OUTPUT_BACKUP_DEFINES() \
  103. PHPDBG_OUTPUT_BACKUP_SWAP()
  104. #define PHPDBG_OUTPUT_BACKUP_RESTORE() \
  105. php_output_deactivate(); \
  106. *output_globals_ptr = original_output_globals;
  107. #endif /* PHPDBG_UTILS_H */