phpdbg_set.c 7.6 KB

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