phpdbg_help.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933
  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. | Authors: Terry Ellison <terry@ellisons.org.uk> |
  19. +----------------------------------------------------------------------+
  20. */
  21. #include "phpdbg.h"
  22. #include "phpdbg_help.h"
  23. #include "phpdbg_prompt.h"
  24. #include "zend.h"
  25. ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
  26. /* {{{ Commands Table */
  27. #define PHPDBG_COMMAND_HELP_D(name, tip, alias, action) \
  28. {PHPDBG_STRL(#name), tip, sizeof(tip)-1, alias, action, NULL, 0}
  29. const phpdbg_command_t phpdbg_help_commands[] = {
  30. PHPDBG_COMMAND_HELP_D(aliases, "show alias list", 'a', phpdbg_do_help_aliases),
  31. PHPDBG_COMMAND_HELP_D(options, "command line options", 0, NULL),
  32. PHPDBG_COMMAND_HELP_D(overview, "help overview", 0, NULL),
  33. PHPDBG_COMMAND_HELP_D(phpdbginit, "phpdbginit file format", 0, NULL),
  34. PHPDBG_COMMAND_HELP_D(syntax, "syntax overview", 0, NULL),
  35. PHPDBG_END_COMMAND
  36. }; /* }}} */
  37. /* {{{ pretty_print. Formatting escapes and wrapping text in a string before printing it. */
  38. void pretty_print(char *text TSRMLS_DC)
  39. {
  40. char *new, *p, *q;
  41. const char *prompt_escape = phpdbg_get_prompt(TSRMLS_C);
  42. unsigned int prompt_escape_len = strlen(prompt_escape);
  43. unsigned int prompt_len = strlen(PHPDBG_G(prompt)[0]);
  44. const char *bold_on_escape = PHPDBG_G(flags) & PHPDBG_IS_COLOURED ? "\033[1m" : "";
  45. const char *bold_off_escape = PHPDBG_G(flags) & PHPDBG_IS_COLOURED ? "\033[0m" : "";
  46. unsigned int bold_escape_len = strlen(bold_on_escape);
  47. unsigned int term_width = phpdbg_get_terminal_width(TSRMLS_C);
  48. unsigned int size = 0;
  49. int in_bold = 0;
  50. char *last_new_blank = NULL; /* position in new buffer of last blank char */
  51. unsigned int last_blank_count = 0; /* printable char offset of last blank char */
  52. unsigned int line_count = 0; /* number printable chars on current line */
  53. /* First pass calculates a safe size for the pretty print version */
  54. for (p = text; *p; p++) {
  55. if (UNEXPECTED(p[0] == '*') && p[1] == '*') {
  56. size += bold_escape_len - 2;
  57. p++;
  58. } else if (UNEXPECTED(p[0] == '$') && p[1] == 'P') {
  59. size += prompt_escape_len - 2;
  60. p++;
  61. } else if (UNEXPECTED(p[0] == '\\')) {
  62. p++;
  63. }
  64. }
  65. size += (p-text)+1;
  66. new = emalloc(size);
  67. /*
  68. * Second pass substitutes the bold and prompt escape sequences and line wrap
  69. *
  70. * ** toggles bold on and off if PHPDBG_IS_COLOURED flag is set
  71. * $P substitutes the prompt sequence
  72. * Lines are wrapped by replacing the last blank with a CR before <term width>
  73. * characters. (This defaults to 100 if the width can't be detected). In the
  74. * pathelogical case where no blanks are found, then the wrap occurs at the
  75. * first blank.
  76. */
  77. for (p = text, q = new; *p; p++) {
  78. if (UNEXPECTED(*p == ' ')) {
  79. last_new_blank = q;
  80. last_blank_count = line_count++;
  81. *q++ = ' ';
  82. } else if (UNEXPECTED(*p == '\n')) {
  83. last_new_blank = NULL;
  84. *q++ = *p;
  85. last_blank_count = 0;
  86. line_count = 0;
  87. } else if (UNEXPECTED(p[0] == '*') && p[1] == '*') {
  88. if (bold_escape_len) {
  89. in_bold = !in_bold;
  90. memcpy (q, in_bold ? bold_on_escape : bold_off_escape, bold_escape_len);
  91. q += bold_escape_len;
  92. /* bold on/off has zero print width so line count is unchanged */
  93. }
  94. p++;
  95. } else if (UNEXPECTED(p[0] == '$') && p[1] == 'P') {
  96. memcpy (q, prompt_escape, prompt_escape_len);
  97. q += prompt_escape_len;
  98. line_count += prompt_len;
  99. p++;
  100. } else if (UNEXPECTED(p[0] == '\\')) {
  101. p++;
  102. *q++ = *p;
  103. line_count++;
  104. } else {
  105. *q++ = *p;
  106. line_count++;
  107. }
  108. if (UNEXPECTED(line_count>=term_width) && last_new_blank) {
  109. *last_new_blank = '\n';
  110. last_new_blank = NULL;
  111. line_count -= last_blank_count;
  112. last_blank_count = 0;
  113. }
  114. }
  115. *q++ = '\0';
  116. if ((q-new)>size) {
  117. phpdbg_error("Output overrun of %lu bytes", ((q-new) - size));
  118. }
  119. phpdbg_write("%s\n", new);
  120. efree(new);
  121. } /* }}} */
  122. /* {{{ summary_print. Print a summary line giving, the command, its alias and tip */
  123. void summary_print(phpdbg_command_t const * const cmd TSRMLS_DC)
  124. {
  125. char *summary;
  126. spprintf(&summary, 0, "Command: **%s** Alias: **%c** **%s**\n", cmd->name, cmd->alias, cmd->tip);
  127. pretty_print(summary TSRMLS_CC);
  128. efree(summary);
  129. }
  130. /* {{{ get_help. Retries and formats text from the phpdbg help text table */
  131. static char *get_help(const char * const key TSRMLS_DC)
  132. {
  133. phpdbg_help_text_t *p;
  134. /* Note that phpdbg_help_text is not assumed to be collated in key order. This is an
  135. inconvience that means that help can't be logically grouped Not worth
  136. the savings */
  137. for (p = phpdbg_help_text; p->key; p++) {
  138. if (!strcmp(p->key, key)) {
  139. return p->text;
  140. }
  141. }
  142. return ""; /* return empty string to denote no match found */
  143. } /* }}} */
  144. /* {{{ get_command. Return number of matching commands from a command table.
  145. * Unlike the command parser, the help search is sloppy that is partial matches can occur
  146. * * Any single character key is taken as an alias.
  147. * * Other keys are matched again the table on the first len characters.
  148. * * This means that non-unique keys can generate multiple matches.
  149. * * The first matching command is returned as an OUT parameter. *
  150. * The rationale here is to assist users in finding help on commands. So unique matches
  151. * will be used to generate a help message but non-unique one will be used to list alternatives.
  152. */
  153. static int get_command(
  154. const char *key, size_t len, /* pointer and length of key */
  155. phpdbg_command_t const **command, /* address of first matching command */
  156. phpdbg_command_t const * commands /* command table to be scanned */
  157. TSRMLS_DC)
  158. {
  159. const phpdbg_command_t *c;
  160. unsigned int num_matches = 0;
  161. if (len == 1) {
  162. for (c=commands; c->name; c++) {
  163. if (c->alias == key[0]) {
  164. num_matches++;
  165. if ( num_matches == 1 && command) {
  166. *command = c;
  167. }
  168. }
  169. }
  170. } else {
  171. for (c=commands; c->name; c++) {
  172. if (!strncmp(c->name, key, len)) {
  173. ++num_matches;
  174. if ( num_matches == 1 && command) {
  175. *command = c;
  176. }
  177. }
  178. }
  179. }
  180. return num_matches;
  181. } /* }}} */
  182. PHPDBG_COMMAND(help) /* {{{ */
  183. {
  184. phpdbg_command_t const *cmd;
  185. int n;
  186. if (!param || param->type == EMPTY_PARAM) {
  187. pretty_print(get_help("overview!" TSRMLS_CC) TSRMLS_CC);
  188. return SUCCESS;
  189. }
  190. if (param && param->type == STR_PARAM) {
  191. n = get_command(param->str, param->len, &cmd, phpdbg_prompt_commands TSRMLS_CC);
  192. if (n==1) {
  193. summary_print(cmd TSRMLS_CC);
  194. pretty_print(get_help(cmd->name TSRMLS_CC) TSRMLS_CC);
  195. return SUCCESS;
  196. } else if (n>1) {
  197. if (param->len > 1) {
  198. for (cmd=phpdbg_prompt_commands; cmd->name; cmd++) {
  199. if (!strncmp(cmd->name, param->str, param->len)) {
  200. summary_print(cmd TSRMLS_CC);
  201. }
  202. }
  203. pretty_print(get_help("duplicate!" TSRMLS_CC) TSRMLS_CC);
  204. return SUCCESS;
  205. } else {
  206. phpdbg_error("Internal help error, non-unique alias \"%c\"", param->str[0]);
  207. return FAILURE;
  208. }
  209. } else { /* no prompt command found so try help topic */
  210. n = get_command( param->str, param->len, &cmd, phpdbg_help_commands TSRMLS_CC);
  211. if (n>0) {
  212. if (cmd->alias == 'a') { /* help aliases executes a canned routine */
  213. return cmd->handler(param TSRMLS_CC);
  214. } else {
  215. pretty_print(get_help(cmd->name TSRMLS_CC) TSRMLS_CC);
  216. return SUCCESS;
  217. }
  218. }
  219. }
  220. }
  221. return FAILURE;
  222. } /* }}} */
  223. PHPDBG_HELP(aliases) /* {{{ */
  224. {
  225. const phpdbg_command_t *c, *c_sub;
  226. int len;
  227. /* Print out aliases for all commands except help as this one comes last */
  228. phpdbg_writeln("Below are the aliased, short versions of all supported commands");
  229. for(c = phpdbg_prompt_commands; c->name; c++) {
  230. if (c->alias && c->alias != 'h') {
  231. phpdbg_writeln(" %c %-20s %s", c->alias, c->name, c->tip);
  232. if (c->subs) {
  233. len = 20 - 1 - c->name_len;
  234. for(c_sub = c->subs; c_sub->alias; c_sub++) {
  235. if (c_sub->alias) {
  236. phpdbg_writeln(" %c %c %s %-*s %s",
  237. c->alias, c_sub->alias, (char *)c->name, len, c_sub->name, c_sub->tip);
  238. }
  239. }
  240. }
  241. }
  242. }
  243. /* Print out aliases for help as this one comes last, with the added text on how aliases are used */
  244. get_command("h", 1, &c, phpdbg_prompt_commands TSRMLS_CC);
  245. phpdbg_writeln(" %c %-20s %s\n", c->alias, c->name, c->tip);
  246. len = 20 - 1 - c->name_len;
  247. for(c_sub = c->subs; c_sub->alias; c_sub++) {
  248. if (c_sub->alias) {
  249. phpdbg_writeln(" %c %c %s %-*s %s",
  250. c->alias, c_sub->alias, c->name, len, c_sub->name, c_sub->tip);
  251. }
  252. }
  253. pretty_print(get_help("aliases!" TSRMLS_CC) TSRMLS_CC);
  254. return SUCCESS;
  255. } /* }}} */
  256. /* {{{ Help Text Table
  257. * Contains help text entries keyed by a lowercase ascii key.
  258. * Text is in ascii and enriched by a simple markup:
  259. * ** toggles bold font emphasis.
  260. * $P insert an bold phpdbg> prompt.
  261. * \ escapes the following character. Note that this is itself escaped inside string
  262. * constants so \\\\ is required to output a single \ e.g. as in namespace names.
  263. *
  264. * Text will be wrapped according to the STDOUT terminal width, so paragraphs are
  265. * flowed using the C stringizing and the CR definition. Also note that entries
  266. * are collated in alphabetic order on key.
  267. *
  268. * Also note the convention that help text not directly referenceable as a help param
  269. * has a key ending in !
  270. */
  271. #define CR "\n"
  272. phpdbg_help_text_t phpdbg_help_text[] = {
  273. /******************************** General Help Topics ********************************/
  274. {"overview!", CR
  275. "**phpdbg** is a lightweight, powerful and easy to use debugging platform for PHP5.4+" CR
  276. "It supports the following commands:" CR CR
  277. "**Information**" CR
  278. " **list** list PHP source" CR
  279. " **info** displays information on the debug session" CR
  280. " **print** show opcodes" CR
  281. " **frame** select a stack frame and print a stack frame summary" CR
  282. " **back** shows the current backtrace" CR
  283. " **help** provide help on a topic" CR CR
  284. "**Starting and Stopping Execution**" CR
  285. " **exec** set execution context" CR
  286. " **run** attempt execution" CR
  287. " **step** continue execution until other line is reached" CR
  288. " **continue** continue execution" CR
  289. " **until** continue execution up to the given location" CR
  290. " **finish** continue up to end of the current execution frame" CR
  291. " **leave** continue up to end of the current execution frame and halt after the calling instruction" CR
  292. " **break** set a breakpoint at the specified target" CR
  293. " **watch** set a watchpoint on $variable" CR
  294. " **clear** clear one or all breakpoints" CR
  295. " **clean** clean the execution environment" CR CR
  296. "**Miscellaneous**" CR
  297. " **set** set the phpdbg configuration" CR
  298. " **source** execute a phpdbginit script" CR
  299. " **register** register a phpdbginit function as a command alias" CR
  300. " **sh** shell a command" CR
  301. " **ev** evaluate some code" CR
  302. " **quit** exit phpdbg" CR CR
  303. "Type **help <command>** or (**help alias**) to get detailed help on any of the above commands, "
  304. "for example **help list** or **h l**. Note that help will also match partial commands if unique "
  305. "(and list out options if not unique), so **help clea** will give help on the **clean** command, "
  306. "but **help cl** will list the summary for **clean** and **clear**." CR CR
  307. "Type **help aliases** to show a full alias list, including any registered phpdginit functions" CR
  308. "Type **help syntax** for a general introduction to the command syntax." CR
  309. "Type **help options** for a list of phpdbg command line options." CR
  310. "Type **help phpdbginit** to show how to customise the debugger environment."
  311. },
  312. {"options", CR
  313. "Below are the command line options supported by phpdbg" CR CR
  314. /* note the extra 4 space index in because of the extra **** */
  315. "**Command Line Options and Flags**" CR
  316. " **Option** **Example Argument** **Description**" CR
  317. " **-c** **-c**/my/php.ini Set php.ini file to load" CR
  318. " **-d** **-d**memory_limit=4G Set a php.ini directive" CR
  319. " **-n** Disable default php.ini" CR
  320. " **-q** Supress welcome banner" CR
  321. " **-v** Enable oplog output" CR
  322. " **-s** Enable stepping" CR
  323. " **-b** Disable colour" CR
  324. " **-i** **-i**my.init Set .phpdbginit file" CR
  325. " **-I** Ignore default .phpdbginit" CR
  326. " **-O** **-O**my.oplog Sets oplog output file" CR
  327. " **-r** Run execution context" CR
  328. " **-rr** Run execution context and quit after execution" CR
  329. " **-E** Enable step through eval, careful!" CR
  330. " **-S** **-S**cli Override SAPI name, careful!" CR
  331. " **-l** **-l**4000 Setup remote console ports" CR
  332. " **-a** **-a**192.168.0.3 Setup remote console bind address" CR
  333. " **-V** Print version number" CR
  334. " **--** **--** arg1 arg2 Use to delimit phpdbg arguments and php $argv; append any $argv "
  335. "argument after it" CR CR
  336. "**Remote Console Mode**" CR CR
  337. "This mode is enabled by specifying the **-a** option. Phpdbg will bind only to the loopback "
  338. "interface by default, and this can only be overridden by explicitly setting the remote console "
  339. "bind address using the **-a** option. If **-a** is specied without an argument, then phpdbg "
  340. "will bind to all available interfaces. You should be aware of the security implications of "
  341. "doing this, so measures should be taken to secure this service if bound to a publicly accessible "
  342. "interface/port." CR CR
  343. "Specify both stdin and stdout with -lstdin/stdout; by default stdout is stdin * 2."
  344. },
  345. {"phpdbginit", CR
  346. "Phpdgb uses an debugger script file to initialize the debugger context. By default, phpdbg looks "
  347. "for the file named **.phpdbginit** in the current working directory. This location can be "
  348. "overridden on the command line using the **-i** switch (see **help options** for a more "
  349. "details)." CR CR
  350. "Debugger scripts can also be executed using the **source** command." CR CR
  351. "A script file can contain a sequence of valid debugger commands, comments and embedded PHP "
  352. "code. " CR CR
  353. "Comment lines are prefixed by the **#** character. Note that comments are only allowed in script "
  354. "files and not in interactive sessions." CR CR
  355. "PHP code is delimited by the start and end escape tags **<:** and **:>**. PHP code can be used "
  356. "to define application context for a debugging session and also to extend the debugger by defining "
  357. "and **register** PHP functions as new commands." CR CR
  358. "Also note that executing a **clear** command will cause the current **phpdbginit** to be reparsed "
  359. "/ reloaded."
  360. },
  361. {"syntax", CR
  362. "Commands start with a keyword, and some (**break**, "
  363. "**info**, **set**, **print** and **list**) may include a subcommand keyword. All keywords are "
  364. "lower case but also have a single letter alias that may be used as an alternative to typing in the"
  365. "keyword in full. Note some aliases are uppercase, and that keywords cannot be abbreviated other "
  366. "than by substitution by the alias." CR CR
  367. "Some commands take an argument. Arguments are typed according to their format:" CR
  368. " * **omitted**" CR
  369. " * **address** **0x** followed by a hex string" CR
  370. " * **number** an optionally signed number" CR
  371. " * **method** a valid **Class::methodName** expression" CR
  372. " * **func#op** a valid **Function name** follow by # and an integer" CR
  373. " * **method#op** a valid **Class::methodName** follow by # and an integer" CR
  374. " * **string** a general string" CR
  375. " * **function** a valid **Function name**" CR
  376. " * **file:line** a valid **filename** follow by : and an integer" CR CR
  377. "In some cases the type of the argument enables the second keyword to be omitted." CR CR
  378. "Type **help** for an overview of all commands and type **help <command>** to get detailed help "
  379. "on any specific command." CR CR
  380. "**Valid Examples**" CR CR
  381. " $P quit" CR
  382. " $P q" CR
  383. " Quit the debugger" CR CR
  384. " $P ev $total[2]" CR
  385. " Evaluate and print the variable $total[2] in the current stack frame" CR
  386. " " CR
  387. " $P break 200" CR
  388. " $P b my_source.php:200" CR
  389. " Break at line 200 in the current source and in file **my_source.php**. " CR CR
  390. " $P b @ ClassX::get_args if $arg[0] == \"fred\"" CR
  391. " $P b ~ 3" CR
  392. " Break at ClassX::get_args() if $arg[0] == \"fred\" and delete breakpoint 3" CR CR
  393. "**Examples of invalid commands**" CR
  394. " $P #This is a comment" CR
  395. " Comments introduced by the **#** character are only allowed in **phpdbginit** script files."
  396. },
  397. /******************************** Help Codicils ********************************/
  398. {"aliases!", CR
  399. "Note that aliases can be used for either command or sub-command keywords or both, so **info b** "
  400. "is a synomyn for **info break** and **l func** for **list func**, etc." CR CR
  401. "Note that help will also accept any alias as a parameter and provide help on that command, for example **h p** will provide help on the print command."
  402. },
  403. {"duplicate!", CR
  404. "Parameter is not unique. For detailed help select help on one of the above commands."
  405. },
  406. /******************************** Help on Commands ********************************/
  407. {"back",
  408. "Provide a formatted backtrace using the standard debug_backtrace() functionality. An optional "
  409. "unsigned integer argument specifying the maximum number of frames to be traced; if omitted then "
  410. "a complete backtrace is given." CR CR
  411. "**Examples**" CR CR
  412. " $P back 5" CR
  413. " $P t " CR
  414. " " CR
  415. "A backtrace can be executed at any time during execution."
  416. },
  417. {"break",
  418. "Breakpoints can be set at a range of targets within the execution environment. Execution will "
  419. "be paused if the program flow hits a breakpoint. The break target can be one of the following "
  420. "types:" CR CR
  421. " **Target** **Alias** **Purpose**" CR
  422. " **at** **A** specify breakpoint by location and condition" CR
  423. " **del** **d** delete breakpoint by breakpoint identifier number" CR CR
  424. "**Break at** takes two arguments. The first is any valid target. The second "
  425. "is a valid PHP expression which will trigger the break in "
  426. "execution, if evaluated as true in a boolean context at the specified target." CR CR
  427. "Note that breakpoints can also be disabled and re-enabled by the **set break** command." CR CR
  428. "**Examples**" CR CR
  429. " $P break test.php:100" CR
  430. " $P b test.php:100" CR
  431. " Break execution at line 100 of test.php" CR CR
  432. " $P break 200" CR
  433. " $P b 200" CR
  434. " Break execution at line 200 of the currently PHP script file" CR CR
  435. " $P break \\\\mynamespace\\\\my_function" CR
  436. " $P b \\\\mynamespace\\\\my_function" CR
  437. " Break execution on entry to \\\\mynamespace\\\\my_function" CR CR
  438. " $P break classX::method" CR
  439. " $P b classX::method" CR
  440. " Break execution on entry to classX::method" CR CR
  441. " $P break 0x7ff68f570e08" CR
  442. " $P b 0x7ff68f570e08" CR
  443. " Break at the opline at the address 0x7ff68f570e08" CR CR
  444. " $P break my_function#14" CR
  445. " $P b my_function#14" CR
  446. " Break at the opline #14 of the function my_function" CR CR
  447. " $P break \\\\my\\\\class::method#2" CR
  448. " $P b \\\\my\\\\class::method#2" CR
  449. " Break at the opline #2 of the method \\\\my\\\\class::method" CR CR
  450. " $P break test.php:#3" CR
  451. " $P b test.php:#3" CR
  452. " Break at opline #3 in test.php" CR CR
  453. " $P break if $cnt > 10" CR
  454. " $P b if $cnt > 10" CR
  455. " Break when the condition ($cnt > 10) evaluates to true" CR CR
  456. " $P break at phpdbg::isGreat if $opt == 'S'" CR
  457. " $P break @ phpdbg::isGreat if $opt == 'S'" CR
  458. " Break at any opcode in phpdbg::isGreat when the condition ($opt == 'S') is true" CR CR
  459. " $P break at test.php:20 if !isset($x)" CR
  460. " Break at every opcode on line 20 of test.php when the condition evaluates to true" CR CR
  461. " $P break ZEND_ADD" CR
  462. " $P b ZEND_ADD" CR
  463. " Break on any occurence of the opcode ZEND_ADD" CR CR
  464. " $P break del 2" CR
  465. " $P b ~ 2" CR
  466. " Remove breakpoint 2" CR CR
  467. "Note: Conditional breaks are costly in terms of runtime overhead. Use them only when required "
  468. "as they significantly slow execution." CR CR
  469. "Note: An address is only valid for the current compilation."
  470. },
  471. {"clean",
  472. "Classes, constants or functions can only be declared once in PHP. You may experience errors "
  473. "during a debug session if you attempt to recompile a PHP source. The clean command clears "
  474. "the Zend runtime tables which holds the sets of compiled classes, constants and functions, "
  475. "releasing any associated storage back into the storage pool. This enables recompilation to "
  476. "take place." CR CR
  477. "Note that you cannot selectively trim any of these resource pools. You can only do a complete "
  478. "clean."
  479. },
  480. {"clear",
  481. "Clearing breakpoints means you can once again run code without interruption." CR CR
  482. "Note: use break delete N to clear a specific breakpoint." CR CR
  483. "Note: if all breakpoints are cleared, then the PHP script will run until normal completion."
  484. },
  485. {"ev",
  486. "The **ev** command takes a string expression which it evaluates and then displays. It "
  487. "evaluates in the context of the lowest (that is the executing) frame, unless this has first "
  488. "been explicitly changed by issuing a **frame** command. " CR CR
  489. "**Examples**" CR CR
  490. " $P ev $variable" CR
  491. " Will print_r($variable) on the console, if it is defined" CR CR
  492. " $P ev $variable = \"Hello phpdbg :)\"" CR
  493. " Will set $variable in the current scope" CR CR
  494. "Note that **ev** allows any valid PHP expression including assignments, function calls and "
  495. "other write statements. This enables you to change the environment during execution, so care "
  496. "is needed here. You can even call PHP functions which have breakpoints defined. " CR CR
  497. "Note: **ev** will always show the result, so do not prefix the code with **return**"
  498. },
  499. {"exec",
  500. "The **exec** command sets the execution context, that is the script to be executed. The "
  501. "execution context must be defined either by executing the **exec** command or by using the "
  502. "**-e** command line option." CR CR
  503. "Note that the **exec** command also can be used to replace a previously defined execution "
  504. "context." CR CR
  505. "**Examples**" CR CR
  506. " $P exec /tmp/script.php" CR
  507. " $P e /tmp/script.php" CR
  508. " Set the execution context to **/tmp/script.php**"
  509. },
  510. //*********** Does F skip any breakpoints lower stack frames or only the current??
  511. {"finish",
  512. "The **finish** command causes control to be passed back to the vm, continuing execution. Any "
  513. "breakpoints that are encountered within the current stack frame will be skipped. Execution "
  514. "will then continue until the next breakpoint after leaving the stack frame or until "
  515. "completion of the script" CR CR
  516. "Note when **step**ping is enabled, any opcode steps within the current stack frame are also "
  517. "skipped. "CR CR
  518. "Note **finish** will trigger a \"not executing\" error if not executing."
  519. },
  520. {"frame",
  521. "The **frame** takes an optional integer argument. If omitted, then the current frame is displayed "
  522. "If specified then the current scope is set to the corresponding frame listed in a **back** trace. " "This can be used to allowing access to the variables in a higher stack frame than that currently "
  523. "being executed." CR CR
  524. "**Examples**" CR CR
  525. " $P frame 2" CR
  526. " $P ev $count" CR
  527. " Go to frame 2 and print out variable **$count** in that frame" CR CR
  528. "Note that this frame scope is discarded when execution continues, with the execution frame "
  529. "then reset to the lowest executiong frame."
  530. },
  531. {"info",
  532. "**info** commands provide quick access to various types of information about the PHP environment" CR
  533. "Specific info commands are show below:" CR CR
  534. " **Target** **Alias** **Purpose**" CR
  535. " **break** **b** show current breakpoints" CR
  536. " **files** **F** show included files" CR
  537. " **classes** **c** show loaded classes" CR
  538. " **funcs** **f** show loaded classes" CR
  539. " **error** **e** show last error" CR
  540. " **vars** **v** show active variables" CR
  541. " **literal** **l** show active literal constants" CR
  542. " **memory** **m** show memory manager stats"
  543. },
  544. // ******** same issue about breakpoints in called frames
  545. {"leave",
  546. "The **leave** command causes control to be passed back to the vm, continuing execution. Any "
  547. "breakpoints that are encountered within the current stack frame will be skipped. In effect a "
  548. "temporary breakpoint is associated with any return opcode, so that a break in execution occurs "
  549. "before leaving the current stack frame. This allows inspection / modification of any frame "
  550. "variables including the return value before it is returned" CR CR
  551. "**Examples**" CR CR
  552. " $P leave" CR
  553. " $P L" CR CR
  554. "Note when **step**ping is enabled, any opcode steps within the current stack frame are also "
  555. "skipped. "CR CR
  556. "Note **leave** will trigger a \"not executing\" error if not executing."
  557. },
  558. {"list",
  559. "The list command displays source code for the given argument. The target type is specficied by "
  560. "a second subcommand keyword:" CR CR
  561. " **Type** **Alias** **Purpose**" CR
  562. " **lines** **l** List N lines from the current execution point" CR
  563. " **func** **f** List the complete source for a specified function" CR
  564. " **method** **m** List the complete source for a specified class::method" CR
  565. " **class** **c** List the complete source for a specified class" CR CR
  566. "Note that the context of **lines**, **func** and **method** can be determined by parsing the "
  567. "argument, so these subcommands are optional. However, you must specify the **class** keyword "
  568. "to list off a class." CR CR
  569. "**Examples**" CR CR
  570. " $P list 2" CR
  571. " $P l l 2" CR
  572. " List the next 2 lines from the current file" CR CR
  573. " $P list my_function" CR
  574. " $P l f my_function" CR
  575. " List the source of the function **my_function**" CR CR
  576. //************ ????
  577. " $P list func .mine" CR
  578. " $P l f .mine" CR
  579. " List the source of the method **mine** from the active class in scope" CR CR
  580. " $P list m my::method" CR
  581. " $P l my::method" CR
  582. " List the source of **my::method**" CR CR
  583. " $P list c myClass" CR
  584. " $P l c myClass" CR
  585. " List the source of **myClass**" CR CR
  586. "Note that functions and classes can only be listed if the corresponding classes and functions "
  587. "table in the Zend executor has a corresponding entry. You can use the compile command to "
  588. "populate these tables for a given execution context."
  589. },
  590. {"continue",
  591. "Continue with execution after hitting a break or watchpoint" CR CR
  592. "**Examples**" CR CR
  593. " $P continue" CR
  594. " $P c" CR
  595. " Continue executing until the next break or watchpoint" CR CR
  596. "Note **continue** will trigger a \"not running\" error if not executing."
  597. },
  598. {"print",
  599. "By default, print will show information about the current execution context." CR
  600. "Other printing commands give access to instruction information." CR
  601. "Specific printers loaded are show below:" CR CR
  602. " **Type** **Alias** **Purpose**" CR
  603. " **exec** **e** print out the instructions in the execution context" CR
  604. " **opline** **o** print out the instruction in the current opline" CR
  605. " **class** **c** print out the instructions in the specified class" CR
  606. " **method** **m** print out the instructions in the specified method" CR
  607. " **func** **f** print out the instructions in the specified function" CR
  608. " **stack** **s** print out the instructions in the current stack" CR CR
  609. "**Examples**" CR CR
  610. " $P print class \\\\my\\\\class" CR
  611. " $P p c \\\\my\\\\class" CR
  612. " Print the instructions for the methods in \\\\my\\\\class" CR CR
  613. " $P print method \\\\my\\\\class::method" CR
  614. " $P p m \\\\my\\\\class::method" CR
  615. " Print the instructions for \\\\my\\\\class::method" CR CR
  616. " $P print func .getSomething" CR
  617. " $P p f .getSomething" CR
  618. //************* Check this local method scope
  619. " Print the instructions for ::getSomething in the active scope" CR CR
  620. " $P print func my_function" CR
  621. " $P p f my_function" CR
  622. " Print the instructions for the global function my_function" CR CR
  623. " $P print opline" CR
  624. " $P p o" CR
  625. " Print the instruction for the current opline" CR CR
  626. " $P print exec" CR
  627. " $P p e" CR
  628. " Print the instructions for the execution context" CR CR
  629. " $P print stack" CR
  630. " $P p s" CR
  631. " Print the instructions for the current stack"
  632. },
  633. {"register",
  634. //******* Needs a general explanation of the how registered functions work
  635. "Register any global function for use as a command in phpdbg console" CR CR
  636. "**Examples**" CR CR
  637. " $P register scandir" CR
  638. " $P R scandir" CR
  639. " Will register the scandir function for use in phpdbg" CR CR
  640. "Note: arguments passed as strings, return (if present) print_r'd on console"
  641. },
  642. {"run",
  643. "Enter the vm, starting execution. Execution will then continue until the next breakpoint "
  644. "or completion of the script. Add parameters you want to use as $argv" CR CR
  645. "**Examples**" CR CR
  646. " $P run" CR
  647. " $P r" CR
  648. " Will cause execution of the context, if it is set" CR CR
  649. " $P r test" CR
  650. " Will execute with $argv[1] == \"test\"" CR CR
  651. "Note that the execution context must be set. If not previously compiled, then the script will "
  652. "be compiled before execution." CR CR
  653. "Note that attempting to run a script that is already executing will result in an \"execution "
  654. "in progress\" error."
  655. },
  656. {"set",
  657. "The **set** command is used to configure how phpdbg looks and behaves. Specific set commands "
  658. "are as follows:" CR CR
  659. " **Type** **Alias** **Purpose**" CR
  660. " **prompt** **p** set the prompt" CR
  661. " **color** **c** set color <element> <color>" CR
  662. " **colors** **C** set colors [<on|off>]" CR
  663. " **oplog** **O** set oplog [output]" CR
  664. " **break** **b** set break **id** <on|off>" CR
  665. " **breaks** **B** set breaks [<on|off>]" CR
  666. " **quiet** **q** set quiet [<on|off>]" CR
  667. " **stepping** **s** set stepping [<opcode|line>]" CR
  668. " **refcount** **r** set refcount [<on|off>] " CR CR
  669. "Valid colors are **none**, **white**, **red**, **green**, **yellow**, **blue**, **purple**, "
  670. "**cyan** and **black**. All colours except **none** can be followed by an optional "
  671. "**-bold** or **-underline** qualifier." CR CR
  672. "Color elements can be one of **prompt**, **notice**, or **error**." CR CR
  673. "**Examples**" CR CR
  674. " $P S C on" CR
  675. " Set colors on" CR CR
  676. " $P set p >" CR
  677. " $P set color prompt white-bold" CR
  678. " Set the prompt to a bold >" CR CR
  679. " $P S c error red-bold" CR
  680. " Use red bold for errors" CR CR
  681. " $P S refcount on" CR
  682. " Enable refcount display when hitting watchpoints" CR CR
  683. " $P S b 4 off" CR
  684. " Temporarily disable breakpoint 4. This can be subsequently reenabled by a **s b 4 on**." CR
  685. //*********** check oplog syntax
  686. },
  687. {"sh",
  688. "Direct access to shell commands saves having to switch windows/consoles" CR CR
  689. "**Examples**" CR CR
  690. " $P sh ls /usr/src/php-src" CR
  691. " Will execute ls /usr/src/php-src, displaying the output in the console"
  692. //*********** what does this mean????Note: read only commands please!
  693. },
  694. {"source",
  695. "Sourcing a **phpdbginit** script during your debugging session might save some time." CR CR
  696. "**Examples**" CR CR
  697. " $P source /my/init" CR
  698. " $P < /my/init" CR
  699. " Will execute the phpdbginit file at /my/init" CR CR
  700. },
  701. {"export",
  702. "Exporting breakpoints allows you to share, and or save your current debugging session" CR CR
  703. "**Examples**" CR CR
  704. " $P export /my/exports" CR
  705. " $P > /my/exports" CR
  706. " Will export all breakpoints to /my/exports" CR CR
  707. },
  708. {"step",
  709. "Execute opcodes until next line" CR CR
  710. "**Examples**" CR CR
  711. " $P s" CR
  712. " Will continue and break again in the next encountered line" CR CR
  713. },
  714. {"until",
  715. "The **until** command causes control to be passed back to the vm, continuing execution. Any "
  716. "breakpoints that are encountered before the next source line will be skipped. Execution "
  717. "will then continue until the next breakpoint or completion of the script" CR CR
  718. "Note when **step**ping is enabled, any opcode steps within the current line are also skipped. "CR CR
  719. "Note that if the next line is **not** executed then **all** subsequent breakpoints will be "
  720. "skipped. " CR CR
  721. "Note **until** will trigger a \"not executing\" error if not executing."
  722. },
  723. {"watch",
  724. "Sets watchpoints on variables as long as they are defined" CR
  725. "Passing no parameter to **watch**, lists all actually active watchpoints" CR CR
  726. "**Format for $variable**" CR CR
  727. " **$var** Variable $var" CR
  728. " **$var[]** All array elements of $var" CR
  729. " **$var->** All properties of $var" CR
  730. " **$var->a** Property $var->a" CR
  731. " **$var[b]** Array element with key b in array $var" CR CR
  732. "Subcommands of **watch**:" CR CR
  733. " **Type** **Alias** **Purpose**" CR
  734. " **array** **a** Sets watchpoint on array/object to observe if an entry is added or removed" CR
  735. " **recursive** **r** Watches variable recursively and automatically adds watchpoints if some entry is added to an array/object" CR
  736. " **delete** **d** Removes watchpoint" CR CR
  737. "Note when **recursive** watchpoints are removed, watchpoints on all the children are removed too" CR CR
  738. "**Examples**" CR CR
  739. " $P watch" CR
  740. " List currently active watchpoints" CR CR
  741. " $P watch $array" CR
  742. " $P w $array" CR
  743. " Set watchpoint on $array" CR CR
  744. " $P watch recursive $obj->" CR
  745. " $P w r $obj->" CR
  746. " Set recursive watchpoint on $obj->" CR CR
  747. " $P watch delete $obj->a" CR
  748. " $P w d $obj->a" CR
  749. " Remove watchpoint $obj->a" CR CR
  750. "Technical note: If using this feature with a debugger, you will get many segmentation faults, each time when a memory page containing a watched address is hit." CR
  751. " You then you can continue, phpdbg will remove the write protection, so that the program can continue." CR
  752. " If phpdbg could not handle that segfault, the same segfault is triggered again and this time phpdbg will abort."
  753. },
  754. {NULL, NULL /* end of table marker */}
  755. }; /* }}} */