phpdbg_watch.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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_WATCH_H
  19. #define PHPDBG_WATCH_H
  20. #include "phpdbg_cmd.h"
  21. #ifdef _WIN32
  22. # include "phpdbg_win.h"
  23. #endif
  24. #define PHPDBG_WATCH(name) PHPDBG_COMMAND(watch_##name)
  25. /**
  26. * Printer Forward Declarations
  27. */
  28. PHPDBG_WATCH(array);
  29. PHPDBG_WATCH(delete);
  30. PHPDBG_WATCH(recursive);
  31. extern const phpdbg_command_t phpdbg_watch_commands[];
  32. /* Watchpoint functions/typedefs */
  33. /* References are managed through their parent zval *, being a simple WATCH_ON_ZVAL and eventually WATCH_ON_REFCOUNTED */
  34. typedef enum {
  35. WATCH_ON_ZVAL,
  36. WATCH_ON_HASHTABLE,
  37. WATCH_ON_REFCOUNTED,
  38. WATCH_ON_STR,
  39. WATCH_ON_HASHDATA,
  40. WATCH_ON_BUCKET,
  41. } phpdbg_watchtype;
  42. #define PHPDBG_WATCH_SIMPLE 0x01
  43. #define PHPDBG_WATCH_RECURSIVE 0x02
  44. #define PHPDBG_WATCH_ARRAY 0x04
  45. #define PHPDBG_WATCH_OBJECT 0x08
  46. #define PHPDBG_WATCH_NORMAL (PHPDBG_WATCH_SIMPLE | PHPDBG_WATCH_RECURSIVE)
  47. #define PHPDBG_WATCH_IMPLICIT 0x10
  48. #define PHPDBG_WATCH_RECURSIVE_ROOT 0x20
  49. typedef struct _phpdbg_watch_collision phpdbg_watch_collision;
  50. typedef struct _phpdbg_watchpoint_t {
  51. union {
  52. zval *zv;
  53. zend_refcounted *ref;
  54. Bucket *bucket;
  55. void *ptr;
  56. } addr;
  57. size_t size;
  58. phpdbg_watchtype type;
  59. zend_refcounted *ref; /* key to fetch the collision on parents */
  60. HashTable elements;
  61. phpdbg_watch_collision *coll; /* only present on *children* */
  62. union {
  63. zval zv;
  64. Bucket bucket;
  65. zend_refcounted ref;
  66. HashTable ht;
  67. zend_string *str;
  68. } backup;
  69. } phpdbg_watchpoint_t;
  70. struct _phpdbg_watch_collision {
  71. phpdbg_watchpoint_t ref;
  72. phpdbg_watchpoint_t reference;
  73. HashTable parents;
  74. };
  75. typedef struct _phpdbg_watch_element {
  76. uint32_t id;
  77. phpdbg_watchpoint_t *watch;
  78. char flags;
  79. struct _phpdbg_watch_element *child; /* always set for implicit watches */
  80. struct _phpdbg_watch_element *parent;
  81. HashTable child_container; /* children of this watch element for recursive array elements */
  82. HashTable *parent_container; /* container of the value */
  83. zend_string *name_in_parent;
  84. zend_string *str;
  85. union {
  86. zval zv;
  87. zend_refcounted ref;
  88. HashTable ht;
  89. } backup; /* backup for when watchpoint gets dissociated */
  90. } phpdbg_watch_element;
  91. typedef struct {
  92. /* to watch rehashes (yes, this is not *perfect*, but good enough for everything in PHP...) */
  93. phpdbg_watchpoint_t hash_watch; /* must be first element */
  94. Bucket *last;
  95. zend_string *last_str;
  96. zend_ulong last_idx;
  97. HashTable *ht;
  98. size_t data_size;
  99. HashTable watches; /* contains phpdbg_watch_element */
  100. } phpdbg_watch_ht_info;
  101. void phpdbg_setup_watchpoints(void);
  102. void phpdbg_destroy_watchpoints(void);
  103. void phpdbg_purge_watchpoint_tree(void);
  104. #ifndef _WIN32
  105. int phpdbg_watchpoint_segfault_handler(siginfo_t *info, void *context);
  106. #else
  107. int phpdbg_watchpoint_segfault_handler(void *addr);
  108. #endif
  109. void phpdbg_create_addr_watchpoint(void *addr, size_t size, phpdbg_watchpoint_t *watch);
  110. void phpdbg_create_zval_watchpoint(zval *zv, phpdbg_watchpoint_t *watch);
  111. int phpdbg_delete_var_watchpoint(char *input, size_t len);
  112. int phpdbg_create_var_watchpoint(char *input, size_t len);
  113. int phpdbg_print_changed_zvals(void);
  114. void phpdbg_list_watchpoints(void);
  115. void phpdbg_watch_efree(void *ptr);
  116. static long phpdbg_pagesize;
  117. static zend_always_inline void *phpdbg_get_page_boundary(void *addr) {
  118. return (void *) ((size_t) addr & ~(phpdbg_pagesize - 1));
  119. }
  120. static zend_always_inline size_t phpdbg_get_total_page_size(void *addr, size_t size) {
  121. return (size_t) phpdbg_get_page_boundary((void *) ((size_t) addr + size - 1)) - (size_t) phpdbg_get_page_boundary(addr) + phpdbg_pagesize;
  122. }
  123. #endif