phpdbg_watch.h 4.7 KB

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