phpdbg_watch.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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_WATCH_H
  21. #define PHPDBG_WATCH_H
  22. #include "TSRM.h"
  23. #include "phpdbg_cmd.h"
  24. #ifdef _WIN32
  25. # include "phpdbg_win.h"
  26. #endif
  27. #define PHPDBG_WATCH(name) PHPDBG_COMMAND(watch_##name)
  28. /**
  29. * Printer Forward Declarations
  30. */
  31. PHPDBG_WATCH(array);
  32. PHPDBG_WATCH(delete);
  33. PHPDBG_WATCH(recursive);
  34. /**
  35. * Commands
  36. */
  37. static const phpdbg_command_t phpdbg_watch_commands[] = {
  38. PHPDBG_COMMAND_D_EX(array, "create watchpoint on an array", 'a', watch_array, NULL, "s"),
  39. PHPDBG_COMMAND_D_EX(delete, "delete watchpoint", 'd', watch_delete, NULL, "s"),
  40. PHPDBG_COMMAND_D_EX(recursive, "create recursive watchpoints", 'r', watch_recursive, NULL, "s"),
  41. PHPDBG_END_COMMAND
  42. };
  43. /* Watchpoint functions/typedefs */
  44. typedef enum {
  45. WATCH_ON_ZVAL,
  46. WATCH_ON_HASHTABLE,
  47. } phpdbg_watchtype;
  48. #define PHPDBG_WATCH_SIMPLE 0x0
  49. #define PHPDBG_WATCH_RECURSIVE 0x1
  50. typedef struct _phpdbg_watchpoint_t phpdbg_watchpoint_t;
  51. struct _phpdbg_watchpoint_t {
  52. phpdbg_watchpoint_t *parent;
  53. HashTable *parent_container;
  54. char *name_in_parent;
  55. size_t name_in_parent_len;
  56. char *str;
  57. size_t str_len;
  58. union {
  59. zval *zv;
  60. HashTable *ht;
  61. void *ptr;
  62. } addr;
  63. size_t size;
  64. phpdbg_watchtype type;
  65. char flags;
  66. };
  67. void phpdbg_setup_watchpoints(TSRMLS_D);
  68. #ifndef _WIN32
  69. int phpdbg_watchpoint_segfault_handler(siginfo_t *info, void *context TSRMLS_DC);
  70. #else
  71. int phpdbg_watchpoint_segfault_handler(void *addr TSRMLS_DC);
  72. #endif
  73. void phpdbg_create_addr_watchpoint(void *addr, size_t size, phpdbg_watchpoint_t *watch);
  74. void phpdbg_create_zval_watchpoint(zval *zv, phpdbg_watchpoint_t *watch);
  75. int phpdbg_delete_var_watchpoint(char *input, size_t len TSRMLS_DC);
  76. int phpdbg_create_var_watchpoint(char *input, size_t len TSRMLS_DC);
  77. int phpdbg_print_changed_zvals(TSRMLS_D);
  78. void phpdbg_list_watchpoints(TSRMLS_D);
  79. void phpdbg_watch_efree(void *ptr);
  80. static long phpdbg_pagesize;
  81. static zend_always_inline void *phpdbg_get_page_boundary(void *addr) {
  82. return (void *)((size_t)addr & ~(phpdbg_pagesize - 1));
  83. }
  84. static zend_always_inline size_t phpdbg_get_total_page_size(void *addr, size_t size) {
  85. return (size_t)phpdbg_get_page_boundary((void *)((size_t)addr + size - 1)) - (size_t)phpdbg_get_page_boundary(addr) + phpdbg_pagesize;
  86. }
  87. #endif