phpdbg_set.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. #include "phpdbg.h"
  19. #include "phpdbg_cmd.h"
  20. #include "phpdbg_set.h"
  21. #include "phpdbg_utils.h"
  22. #include "phpdbg_bp.h"
  23. #include "phpdbg_prompt.h"
  24. ZEND_EXTERN_MODULE_GLOBALS(phpdbg)
  25. #define PHPDBG_SET_COMMAND_D(f, h, a, m, l, s, flags) \
  26. PHPDBG_COMMAND_D_EXP(f, h, a, m, l, s, &phpdbg_prompt_commands[17], flags)
  27. const phpdbg_command_t phpdbg_set_commands[] = {
  28. PHPDBG_SET_COMMAND_D(prompt, "usage: set prompt [<string>]", 'p', set_prompt, NULL, "|s", 0),
  29. PHPDBG_SET_COMMAND_D(pagination, "usage: set pagination [<on|off>]", 'P', set_pagination, NULL, "|b", PHPDBG_ASYNC_SAFE),
  30. #ifndef _WIN32
  31. PHPDBG_SET_COMMAND_D(color, "usage: set color <element> <color>", 'c', set_color, NULL, "ss", PHPDBG_ASYNC_SAFE),
  32. PHPDBG_SET_COMMAND_D(colors, "usage: set colors [<on|off>]", 'C', set_colors, NULL, "|b", PHPDBG_ASYNC_SAFE),
  33. #endif
  34. PHPDBG_SET_COMMAND_D(break, "usage: set break id [<on|off>]", 'b', set_break, NULL, "l|b", PHPDBG_ASYNC_SAFE),
  35. PHPDBG_SET_COMMAND_D(breaks, "usage: set breaks [<on|off>]", 'B', set_breaks, NULL, "|b", PHPDBG_ASYNC_SAFE),
  36. PHPDBG_SET_COMMAND_D(quiet, "usage: set quiet [<on|off>]", 'q', set_quiet, NULL, "|b", PHPDBG_ASYNC_SAFE),
  37. PHPDBG_SET_COMMAND_D(stepping, "usage: set stepping [<line|op>]", 's', set_stepping, NULL, "|s", PHPDBG_ASYNC_SAFE),
  38. PHPDBG_SET_COMMAND_D(refcount, "usage: set refcount [<on|off>]", 'r', set_refcount, NULL, "|b", PHPDBG_ASYNC_SAFE),
  39. PHPDBG_SET_COMMAND_D(lines, "usage: set lines [<number>]", 'l', set_lines, NULL, "|l", PHPDBG_ASYNC_SAFE),
  40. PHPDBG_END_COMMAND
  41. };
  42. PHPDBG_SET(prompt) /* {{{ */
  43. {
  44. if (!param || param->type == EMPTY_PARAM) {
  45. phpdbg_writeln("Current prompt: %s", phpdbg_get_prompt());
  46. } else {
  47. phpdbg_set_prompt(param->str);
  48. }
  49. return SUCCESS;
  50. } /* }}} */
  51. PHPDBG_SET(pagination) /* {{{ */
  52. {
  53. if (!param || param->type == EMPTY_PARAM) {
  54. phpdbg_writeln("Pagination %s", PHPDBG_G(flags) & PHPDBG_HAS_PAGINATION ? "on" : "off");
  55. } else switch (param->type) {
  56. case NUMERIC_PARAM: {
  57. if (param->num) {
  58. PHPDBG_G(flags) |= PHPDBG_HAS_PAGINATION;
  59. } else {
  60. PHPDBG_G(flags) &= ~PHPDBG_HAS_PAGINATION;
  61. }
  62. } break;
  63. default:
  64. phpdbg_error("set pagination used incorrectly: set pagination <on|off>");
  65. }
  66. return SUCCESS;
  67. } /* }}} */
  68. PHPDBG_SET(lines) /* {{{ */
  69. {
  70. if (!param || param->type == EMPTY_PARAM) {
  71. phpdbg_writeln("Lines "ZEND_ULONG_FMT, PHPDBG_G(lines));
  72. } else switch (param->type) {
  73. case NUMERIC_PARAM: {
  74. PHPDBG_G(lines) = param->num;
  75. } break;
  76. default:
  77. phpdbg_error("set lines used incorrectly: set lines <number>");
  78. }
  79. return SUCCESS;
  80. } /* }}} */
  81. PHPDBG_SET(break) /* {{{ */
  82. {
  83. switch (param->type) {
  84. case NUMERIC_PARAM: {
  85. if (param->next) {
  86. if (param->next->num) {
  87. phpdbg_enable_breakpoint(param->num);
  88. } else {
  89. phpdbg_disable_breakpoint(param->num);
  90. }
  91. } else {
  92. phpdbg_breakbase_t *brake = phpdbg_find_breakbase(param->num);
  93. if (brake) {
  94. phpdbg_writeln("Breakpoint #"ZEND_LONG_FMT" %s", param->num, brake->disabled ? "off" : "on");
  95. } else {
  96. phpdbg_error("Failed to find breakpoint #"ZEND_LONG_FMT, param->num);
  97. }
  98. }
  99. } break;
  100. default:
  101. phpdbg_error("set break used incorrectly: set break [id] <on|off>");
  102. }
  103. return SUCCESS;
  104. } /* }}} */
  105. PHPDBG_SET(breaks) /* {{{ */
  106. {
  107. if (!param || param->type == EMPTY_PARAM) {
  108. phpdbg_writeln("Breakpoints %s",PHPDBG_G(flags) & PHPDBG_IS_BP_ENABLED ? "on" : "off");
  109. } else switch (param->type) {
  110. case NUMERIC_PARAM: {
  111. if (param->num) {
  112. phpdbg_enable_breakpoints();
  113. } else {
  114. phpdbg_disable_breakpoints();
  115. }
  116. } break;
  117. default:
  118. phpdbg_error("set breaks used incorrectly: set breaks <on|off>");
  119. }
  120. return SUCCESS;
  121. } /* }}} */
  122. #ifndef _WIN32
  123. PHPDBG_SET(color) /* {{{ */
  124. {
  125. const phpdbg_color_t *color = phpdbg_get_color(param->next->str, param->next->len);
  126. if (!color) {
  127. phpdbg_error("Failed to find the requested color (%s)", param->next->str);
  128. return SUCCESS;
  129. }
  130. switch (phpdbg_get_element(param->str, param->len)) {
  131. case PHPDBG_COLOR_PROMPT:
  132. phpdbg_notice("setting prompt color to %s (%s)", color->name, color->code);
  133. if (PHPDBG_G(prompt)[1]) {
  134. free(PHPDBG_G(prompt)[1]);
  135. PHPDBG_G(prompt)[1]=NULL;
  136. }
  137. phpdbg_set_color(PHPDBG_COLOR_PROMPT, color);
  138. break;
  139. case PHPDBG_COLOR_ERROR:
  140. phpdbg_notice("setting error color to %s (%s)", color->name, color->code);
  141. phpdbg_set_color(PHPDBG_COLOR_ERROR, color);
  142. break;
  143. case PHPDBG_COLOR_NOTICE:
  144. phpdbg_notice("setting notice color to %s (%s)", color->name, color->code);
  145. phpdbg_set_color(PHPDBG_COLOR_NOTICE, color);
  146. break;
  147. default:
  148. phpdbg_error("Failed to find the requested element (%s)", param->str);
  149. }
  150. return SUCCESS;
  151. } /* }}} */
  152. PHPDBG_SET(colors) /* {{{ */
  153. {
  154. if (!param || param->type == EMPTY_PARAM) {
  155. phpdbg_writeln("Colors %s", PHPDBG_G(flags) & PHPDBG_IS_COLOURED ? "on" : "off");
  156. } else switch (param->type) {
  157. case NUMERIC_PARAM: {
  158. if (param->num) {
  159. PHPDBG_G(flags) |= PHPDBG_IS_COLOURED;
  160. } else {
  161. PHPDBG_G(flags) &= ~PHPDBG_IS_COLOURED;
  162. }
  163. } break;
  164. default:
  165. phpdbg_error("set colors used incorrectly: set colors <on|off>");
  166. }
  167. return SUCCESS;
  168. } /* }}} */
  169. #endif
  170. PHPDBG_SET(quiet) /* {{{ */
  171. {
  172. if (!param || param->type == EMPTY_PARAM) {
  173. phpdbg_writeln("Quietness %s", PHPDBG_G(flags) & PHPDBG_IS_QUIET ? "on" : "off");
  174. } else switch (param->type) {
  175. case NUMERIC_PARAM: {
  176. if (param->num) {
  177. PHPDBG_G(flags) |= PHPDBG_IS_QUIET;
  178. } else {
  179. PHPDBG_G(flags) &= ~PHPDBG_IS_QUIET;
  180. }
  181. } break;
  182. phpdbg_default_switch_case();
  183. }
  184. return SUCCESS;
  185. } /* }}} */
  186. PHPDBG_SET(stepping) /* {{{ */
  187. {
  188. if (!param || param->type == EMPTY_PARAM) {
  189. phpdbg_writeln("Stepping %s", PHPDBG_G(flags) & PHPDBG_STEP_OPCODE ? "opcode" : "line");
  190. } else switch (param->type) {
  191. case STR_PARAM: {
  192. if (param->len == sizeof("opcode") - 1 && !memcmp(param->str, "opcode", sizeof("opcode"))) {
  193. PHPDBG_G(flags) |= PHPDBG_STEP_OPCODE;
  194. } else if (param->len == sizeof("line") - 1 && !memcmp(param->str, "line", sizeof("line"))) {
  195. PHPDBG_G(flags) &= ~PHPDBG_STEP_OPCODE;
  196. } else {
  197. phpdbg_error("usage set stepping [<opcode|line>]");
  198. }
  199. } break;
  200. phpdbg_default_switch_case();
  201. }
  202. return SUCCESS;
  203. } /* }}} */
  204. PHPDBG_SET(refcount) /* {{{ */
  205. {
  206. if (!param || param->type == EMPTY_PARAM) {
  207. phpdbg_writeln("Showing refcounts %s", PHPDBG_G(flags) & PHPDBG_IS_QUIET ? "on" : "off");
  208. } else switch (param->type) {
  209. case NUMERIC_PARAM: {
  210. if (param->num) {
  211. PHPDBG_G(flags) |= PHPDBG_SHOW_REFCOUNTS;
  212. } else {
  213. PHPDBG_G(flags) &= ~PHPDBG_SHOW_REFCOUNTS;
  214. }
  215. } break;
  216. phpdbg_default_switch_case();
  217. }
  218. return SUCCESS;
  219. } /* }}} */