phpdbg_utils.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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_UTILS_H
  21. #define PHPDBG_UTILS_H
  22. /**
  23. * Input scan functions
  24. */
  25. PHPDBG_API int phpdbg_is_numeric(const char*);
  26. PHPDBG_API int phpdbg_is_empty(const char*);
  27. PHPDBG_API int phpdbg_is_addr(const char*);
  28. PHPDBG_API int phpdbg_is_class_method(const char*, size_t, char**, char**);
  29. PHPDBG_API const char *phpdbg_current_file(void);
  30. PHPDBG_API char *phpdbg_resolve_path(const char*);
  31. PHPDBG_API char *phpdbg_trim(const char*, size_t, size_t*);
  32. PHPDBG_API const zend_function *phpdbg_get_function(const char*, const char*);
  33. /* {{{ Color Management */
  34. #define PHPDBG_COLOR_LEN 12
  35. #define PHPDBG_COLOR_D(color, code) \
  36. {color, sizeof(color)-1, code}
  37. #define PHPDBG_COLOR_END \
  38. {NULL, 0L, {0}}
  39. #define PHPDBG_ELEMENT_LEN 3
  40. #define PHPDBG_ELEMENT_D(name, id) \
  41. {name, sizeof(name)-1, id}
  42. #define PHPDBG_ELEMENT_END \
  43. {NULL, 0L, 0}
  44. #define PHPDBG_COLOR_INVALID -1
  45. #define PHPDBG_COLOR_PROMPT 0
  46. #define PHPDBG_COLOR_ERROR 1
  47. #define PHPDBG_COLOR_NOTICE 2
  48. #define PHPDBG_COLORS 3
  49. typedef struct _phpdbg_color_t {
  50. char *name;
  51. size_t name_length;
  52. const char code[PHPDBG_COLOR_LEN];
  53. } phpdbg_color_t;
  54. typedef struct _phpdbg_element_t {
  55. char *name;
  56. size_t name_length;
  57. int id;
  58. } phpdbg_element_t;
  59. PHPDBG_API const phpdbg_color_t *phpdbg_get_color(const char *name, size_t name_length);
  60. PHPDBG_API void phpdbg_set_color(int element, const phpdbg_color_t *color);
  61. PHPDBG_API void phpdbg_set_color_ex(int element, const char *name, size_t name_length);
  62. PHPDBG_API const phpdbg_color_t *phpdbg_get_colors(void);
  63. PHPDBG_API int phpdbg_get_element(const char *name, size_t len); /* }}} */
  64. /* {{{ Prompt Management */
  65. PHPDBG_API void phpdbg_set_prompt(const char*);
  66. PHPDBG_API const char *phpdbg_get_prompt(void); /* }}} */
  67. /* {{{ Console size */
  68. PHPDBG_API int phpdbg_get_terminal_width(void);
  69. PHPDBG_API int phpdbg_get_terminal_height(void); /* }}} */
  70. PHPDBG_API void phpdbg_set_async_io(int fd);
  71. int phpdbg_rebuild_symtable(void);
  72. int phpdbg_safe_class_lookup(const char *name, int name_length, zend_class_entry **ce);
  73. char *phpdbg_get_property_key(char *key);
  74. typedef int (*phpdbg_parse_var_func)(char *name, size_t len, char *keyname, size_t keylen, HashTable *parent, zval *zv);
  75. typedef int (*phpdbg_parse_var_with_arg_func)(char *name, size_t len, char *keyname, size_t keylen, HashTable *parent, zval *zv, void *arg);
  76. PHPDBG_API int phpdbg_parse_variable(char *input, size_t len, HashTable *parent, size_t i, phpdbg_parse_var_func callback, zend_bool silent);
  77. 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, zend_bool silent, void *arg);
  78. int phpdbg_is_auto_global(char *name, int len);
  79. PHPDBG_API void phpdbg_xml_var_dump(zval *zv);
  80. char *phpdbg_short_zval_print(zval *zv, int maxlen);
  81. PHPDBG_API zend_bool phpdbg_check_caught_ex(zend_execute_data *ex, zend_object *exception);
  82. static zend_always_inline zend_execute_data *phpdbg_user_execute_data(zend_execute_data *ex) {
  83. while (!ex->func || !ZEND_USER_CODE(ex->func->common.type)) {
  84. ex = ex->prev_execute_data;
  85. ZEND_ASSERT(ex);
  86. }
  87. return ex;
  88. }
  89. #ifdef ZTS
  90. #define PHPDBG_OUTPUT_BACKUP_DEFINES() \
  91. zend_output_globals *output_globals_ptr; \
  92. zend_output_globals original_output_globals; \
  93. output_globals_ptr = (zend_output_globals *) (*((void ***) tsrm_get_ls_cache()))[TSRM_UNSHUFFLE_RSRC_ID(output_globals_id)];
  94. #else
  95. #define PHPDBG_OUTPUT_BACKUP_DEFINES() \
  96. zend_output_globals *output_globals_ptr; \
  97. zend_output_globals original_output_globals; \
  98. output_globals_ptr = &output_globals;
  99. #endif
  100. #define PHPDBG_OUTPUT_BACKUP_SWAP() \
  101. original_output_globals = *output_globals_ptr; \
  102. memset(output_globals_ptr, 0, sizeof(zend_output_globals)); \
  103. php_output_activate();
  104. #define PHPDBG_OUTPUT_BACKUP() \
  105. PHPDBG_OUTPUT_BACKUP_DEFINES() \
  106. PHPDBG_OUTPUT_BACKUP_SWAP()
  107. #define PHPDBG_OUTPUT_BACKUP_RESTORE() \
  108. php_output_deactivate(); \
  109. *output_globals_ptr = original_output_globals;
  110. #endif /* PHPDBG_UTILS_H */