phpdbg.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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_H
  21. #define PHPDBG_H
  22. #ifdef PHP_WIN32
  23. # define PHPDBG_API __declspec(dllexport)
  24. #elif defined(__GNUC__) && __GNUC__ >= 4
  25. # define PHPDBG_API __attribute__ ((visibility("default")))
  26. #else
  27. # define PHPDBG_API
  28. #endif
  29. #include "php.h"
  30. #include "php_globals.h"
  31. #include "php_variables.h"
  32. #include "php_getopt.h"
  33. #include "zend_builtin_functions.h"
  34. #include "zend_extensions.h"
  35. #include "zend_modules.h"
  36. #include "zend_globals.h"
  37. #include "zend_ini_scanner.h"
  38. #include "zend_stream.h"
  39. #ifndef _WIN32
  40. # include "zend_signal.h"
  41. #endif
  42. #include "SAPI.h"
  43. #include <fcntl.h>
  44. #include <sys/types.h>
  45. #if defined(_WIN32) && !defined(__MINGW32__)
  46. # include <windows.h>
  47. # include "config.w32.h"
  48. # undef strcasecmp
  49. # undef strncasecmp
  50. # define strcasecmp _stricmp
  51. # define strncasecmp _strnicmp
  52. #else
  53. # include "php_config.h"
  54. #endif
  55. #ifndef O_BINARY
  56. # define O_BINARY 0
  57. #endif
  58. #include "php_main.h"
  59. #ifdef ZTS
  60. # include "TSRM.h"
  61. #endif
  62. #ifdef LIBREADLINE
  63. # include <readline/readline.h>
  64. # include <readline/history.h>
  65. #endif
  66. #ifdef HAVE_LIBEDIT
  67. # include <editline/readline.h>
  68. #endif
  69. #include "phpdbg_lexer.h"
  70. #include "phpdbg_cmd.h"
  71. #include "phpdbg_utils.h"
  72. #include "phpdbg_btree.h"
  73. #include "phpdbg_watch.h"
  74. int phpdbg_do_parse(phpdbg_param_t *stack, char *input TSRMLS_DC);
  75. #ifdef ZTS
  76. # define PHPDBG_G(v) TSRMG(phpdbg_globals_id, zend_phpdbg_globals *, v)
  77. #else
  78. # define PHPDBG_G(v) (phpdbg_globals.v)
  79. #endif
  80. #define PHPDBG_NEXT 2
  81. #define PHPDBG_UNTIL 3
  82. #define PHPDBG_FINISH 4
  83. #define PHPDBG_LEAVE 5
  84. /*
  85. BEGIN: DO NOT CHANGE DO NOT CHANGE DO NOT CHANGE
  86. */
  87. /* {{{ tables */
  88. #define PHPDBG_BREAK_FILE 0
  89. #define PHPDBG_BREAK_SYM 1
  90. #define PHPDBG_BREAK_OPLINE 2
  91. #define PHPDBG_BREAK_METHOD 3
  92. #define PHPDBG_BREAK_COND 4
  93. #define PHPDBG_BREAK_OPCODE 5
  94. #define PHPDBG_BREAK_FUNCTION_OPLINE 6
  95. #define PHPDBG_BREAK_METHOD_OPLINE 7
  96. #define PHPDBG_BREAK_FILE_OPLINE 8
  97. #define PHPDBG_BREAK_MAP 9
  98. #define PHPDBG_BREAK_TABLES 10 /* }}} */
  99. /* {{{ flags */
  100. #define PHPDBG_HAS_FILE_BP (1<<1)
  101. #define PHPDBG_HAS_SYM_BP (1<<2)
  102. #define PHPDBG_HAS_OPLINE_BP (1<<3)
  103. #define PHPDBG_HAS_METHOD_BP (1<<4)
  104. #define PHPDBG_HAS_COND_BP (1<<5)
  105. #define PHPDBG_HAS_OPCODE_BP (1<<6)
  106. #define PHPDBG_HAS_FUNCTION_OPLINE_BP (1<<7)
  107. #define PHPDBG_HAS_METHOD_OPLINE_BP (1<<8)
  108. #define PHPDBG_HAS_FILE_OPLINE_BP (1<<9) /* }}} */
  109. /*
  110. END: DO NOT CHANGE DO NOT CHANGE DO NOT CHANGE
  111. */
  112. #define PHPDBG_IN_COND_BP (1<<10)
  113. #define PHPDBG_IN_EVAL (1<<11)
  114. #define PHPDBG_IS_STEPPING (1<<12)
  115. #define PHPDBG_STEP_OPCODE (1<<13)
  116. #define PHPDBG_IS_QUIET (1<<14)
  117. #define PHPDBG_IS_QUITTING (1<<15)
  118. #define PHPDBG_IS_COLOURED (1<<16)
  119. #define PHPDBG_IS_CLEANING (1<<17)
  120. #define PHPDBG_IN_UNTIL (1<<18)
  121. #define PHPDBG_IN_FINISH (1<<19)
  122. #define PHPDBG_IN_LEAVE (1<<20)
  123. #define PHPDBG_IS_REGISTERED (1<<21)
  124. #define PHPDBG_IS_STEPONEVAL (1<<22)
  125. #define PHPDBG_IS_INITIALIZING (1<<23)
  126. #define PHPDBG_IS_SIGNALED (1<<24)
  127. #define PHPDBG_IS_INTERACTIVE (1<<25)
  128. #define PHPDBG_IS_BP_ENABLED (1<<26)
  129. #define PHPDBG_IS_REMOTE (1<<27)
  130. #define PHPDBG_IS_DISCONNECTED (1<<28)
  131. #define PHPDBG_SHOW_REFCOUNTS (1<<29)
  132. #define PHPDBG_SEEK_MASK (PHPDBG_IN_UNTIL|PHPDBG_IN_FINISH|PHPDBG_IN_LEAVE)
  133. #define PHPDBG_BP_RESOLVE_MASK (PHPDBG_HAS_FUNCTION_OPLINE_BP|PHPDBG_HAS_METHOD_OPLINE_BP|PHPDBG_HAS_FILE_OPLINE_BP)
  134. #define PHPDBG_BP_MASK (PHPDBG_HAS_FILE_BP|PHPDBG_HAS_SYM_BP|PHPDBG_HAS_METHOD_BP|PHPDBG_HAS_OPLINE_BP|PHPDBG_HAS_COND_BP|PHPDBG_HAS_OPCODE_BP|PHPDBG_HAS_FUNCTION_OPLINE_BP|PHPDBG_HAS_METHOD_OPLINE_BP|PHPDBG_HAS_FILE_OPLINE_BP)
  135. #ifndef _WIN32
  136. # define PHPDBG_DEFAULT_FLAGS (PHPDBG_IS_QUIET|PHPDBG_IS_COLOURED|PHPDBG_IS_BP_ENABLED)
  137. #else
  138. # define PHPDBG_DEFAULT_FLAGS (PHPDBG_IS_QUIET|PHPDBG_IS_BP_ENABLED)
  139. #endif /* }}} */
  140. /* {{{ strings */
  141. #define PHPDBG_NAME "phpdbg"
  142. #define PHPDBG_AUTHORS "Felipe Pena, Joe Watkins and Bob Weinand" /* Ordered by last name */
  143. #define PHPDBG_URL "http://phpdbg.com"
  144. #define PHPDBG_ISSUES "http://github.com/krakjoe/phpdbg/issues"
  145. #define PHPDBG_VERSION "0.4.0"
  146. #define PHPDBG_INIT_FILENAME ".phpdbginit"
  147. /* }}} */
  148. /* {{{ output descriptors */
  149. #define PHPDBG_STDIN 0
  150. #define PHPDBG_STDOUT 1
  151. #define PHPDBG_STDERR 2
  152. #define PHPDBG_IO_FDS 3 /* }}} */
  153. /* {{{ structs */
  154. ZEND_BEGIN_MODULE_GLOBALS(phpdbg)
  155. HashTable bp[PHPDBG_BREAK_TABLES]; /* break points */
  156. HashTable registered; /* registered */
  157. HashTable seek; /* seek oplines */
  158. phpdbg_frame_t frame; /* frame */
  159. zend_uint last_line; /* last executed line */
  160. phpdbg_lexer_data lexer; /* lexer data */
  161. phpdbg_param_t *parser_stack; /* param stack during lexer / parser phase */
  162. #ifndef _WIN32
  163. struct sigaction old_sigsegv_signal; /* segv signal handler */
  164. #endif
  165. phpdbg_btree watchpoint_tree; /* tree with watchpoints */
  166. phpdbg_btree watch_HashTables; /* tree with original dtors of watchpoints */
  167. HashTable watchpoints; /* watchpoints */
  168. zend_llist watchlist_mem; /* triggered watchpoints */
  169. zend_bool watchpoint_hit; /* a watchpoint was hit */
  170. void (*original_free_function)(void *); /* the original AG(mm_heap)->_free function */
  171. char *exec; /* file to execute */
  172. size_t exec_len; /* size of exec */
  173. zend_op_array *ops; /* op_array */
  174. zval *retval; /* return value */
  175. int bp_count; /* breakpoint count */
  176. int vmret; /* return from last opcode handler execution */
  177. FILE *oplog; /* opline log */
  178. FILE *io[PHPDBG_IO_FDS]; /* io */
  179. char *prompt[2]; /* prompt */
  180. const phpdbg_color_t *colors[PHPDBG_COLORS]; /* colors */
  181. char *buffer; /* buffer */
  182. zend_ulong flags; /* phpdbg flags */
  183. ZEND_END_MODULE_GLOBALS(phpdbg) /* }}} */
  184. /* the beginning (= the important part) of the _zend_mm_heap struct defined in Zend/zend_alloc.c
  185. Needed for realizing watchpoints */
  186. struct _zend_mm_heap {
  187. int use_zend_alloc;
  188. void *(*_malloc)(size_t);
  189. void (*_free)(void *);
  190. void *(*_realloc)(void *, size_t);
  191. size_t free_bitmap;
  192. size_t large_free_bitmap;
  193. size_t block_size;
  194. size_t compact_size;
  195. zend_mm_segment *segments_list;
  196. zend_mm_storage *storage;
  197. };
  198. #endif /* PHPDBG_H */