Skip to content

Commit 8c91727

Browse files
committed
Merge branch 'master' of https://github.com/krakjoe/phpdbg
2 parents c7b5153 + 6aad2ee commit 8c91727

File tree

8 files changed

+120
-31
lines changed

8 files changed

+120
-31
lines changed

config.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ if test "$PHP_PHPDBG" != "no"; then
99
AC_DEFINE(HAVE_PHPDBG, 1, [ ])
1010

1111
PHP_PHPDBG_CFLAGS="-I$abc_srcdir"
12-
PHP_PHPDBG_FILES="phpdbg.c phpdbg_prompt.c phpdbg_help.c phpdbg_bp.c phpdbg_opcode.c phpdbg_list.c"
12+
PHP_PHPDBG_FILES="phpdbg.c phpdbg_prompt.c phpdbg_help.c phpdbg_bp.c phpdbg_opcode.c phpdbg_list.c phpdbg_utils.c"
1313

1414
PHP_SUBST(PHP_PHPDBG_CFLAGS)
1515
PHP_SUBST(PHP_PHPDBG_FILES)

phpdbg_help.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,7 @@ PHPDBG_HELP(list) /* {{{ */
140140
printf("The list command displays N line from current context file.\n");
141141
printf("\tphpdbg> list 2\n");
142142
printf("Will print next 2 lines from the current file\n");
143+
printf("\tphpdbg> list func\n");
144+
printf("Will print func source code\n");
143145
return SUCCESS;
144146
} /* }}} */

phpdbg_help.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static const phpdbg_command_t phpdbg_help_commands[] = {
6464
PHPDBG_HELP_D(clear, "clearing breakpoints allows you to run code without interruption"),
6565
PHPDBG_HELP_D(back, "show debug backtrace information during execution"),
6666
PHPDBG_HELP_D(quiet, "be quiet during execution"),
67-
PHPDBG_HELP_D(list, "list specified line"),
67+
PHPDBG_HELP_D(list, "list specified line or function"),
6868
{NULL, 0, 0}
6969
};
7070

phpdbg_list.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,17 @@ void phpdbg_list_file(const char *filename, long count, long offset TSRMLS_DC) /
7474
out:
7575
close(fd);
7676
} /* }}} */
77+
78+
void phpdbg_list_function(const zend_function *fbc TSRMLS_DC) /* {{{ */
79+
{
80+
const zend_op_array *ops;
81+
82+
if (fbc->type != ZEND_USER_FUNCTION) {
83+
return;
84+
}
85+
86+
ops = (zend_op_array*)fbc;
87+
88+
phpdbg_list_file(ops->filename,
89+
ops->line_end - ops->line_start + 1, ops->line_start TSRMLS_CC);
90+
} /* }}} */

phpdbg_list.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#ifndef PHPDBG_LIST_H
2121
#define PHPDBG_LIST_H
2222

23+
void phpdbg_list_function(const zend_function* TSRMLS_DC);
2324
void phpdbg_list_file(const char*, long, long TSRMLS_DC);
2425

2526
#endif /* PHPDBG_LIST_H */

phpdbg_prompt.c

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "phpdbg_bp.h"
2727
#include "phpdbg_opcode.h"
2828
#include "phpdbg_list.h"
29+
#include "phpdbg_utils.h"
2930

3031
static const phpdbg_command_t phpdbg_prompt_commands[];
3132

@@ -103,7 +104,7 @@ static PHPDBG_COMMAND(step) /* {{{ */
103104
} else {
104105
PHPDBG_G(flags) &= ~PHPDBG_IS_STEPPING;
105106
}
106-
107+
107108
printf(
108109
"[Stepping %s]\n", (PHPDBG_G(flags) & PHPDBG_IS_STEPPING) ? "on" : "off");
109110
return SUCCESS;
@@ -151,20 +152,20 @@ static PHPDBG_COMMAND(run) /* {{{ */
151152
static PHPDBG_COMMAND(eval) /* {{{ */
152153
{
153154
zval retval;
154-
155+
155156
if (expr_len) {
156157
zend_bool stepping = (PHPDBG_G(flags) & PHPDBG_IS_STEPPING);
157-
158+
158159
/* disable stepping while eval() in progress */
159160
PHPDBG_G(flags) &= ~ PHPDBG_IS_STEPPING;
160-
161+
161162
if (zend_eval_stringl((char*)expr, expr_len-1,
162163
&retval, "eval()'d code" TSRMLS_CC) == SUCCESS) {
163164
zend_print_zval_r(
164165
&retval, 0 TSRMLS_CC);
165166
printf("\n");
166167
}
167-
168+
168169
/* switch stepping back on */
169170
if (stepping) {
170171
PHPDBG_G(flags) |= PHPDBG_IS_STEPPING;
@@ -221,7 +222,7 @@ static PHPDBG_COMMAND(print) /* {{{ */
221222
printf("Compiled\t%s\n", PHPDBG_G(ops) ? "yes" : "no");
222223
printf("Stepping\t%s\n", (PHPDBG_G(flags) & PHPDBG_IS_STEPPING) ? "on" : "off");
223224
printf("Quietness\t%s\n", (PHPDBG_G(flags) & PHPDBG_IS_QUIET) ? "on" : "off");
224-
225+
225226
if (PHPDBG_G(ops)) {
226227
printf("Opcodes\t\t%d\n", PHPDBG_G(ops)->last);
227228

@@ -305,15 +306,15 @@ static PHPDBG_COMMAND(break) /* {{{ */
305306
{
306307
char *line_pos = NULL;
307308
char *func_pos = NULL;
308-
309+
309310
if (!expr_len) {
310311
printf(
311312
"[No expression found]\n");
312313
return FAILURE;
313314
}
314-
315+
315316
line_pos = strchr(expr, ':');
316-
317+
317318
if (line_pos) {
318319
if (!(func_pos=strchr(line_pos+1, ':'))) {
319320
char path[MAXPATHLEN], resolved_name[MAXPATHLEN];
@@ -336,19 +337,19 @@ static PHPDBG_COMMAND(break) /* {{{ */
336337
} else {
337338
char *class;
338339
char *func;
339-
340+
340341
size_t func_len = strlen(func_pos+1),
341342
class_len = (line_pos - expr);
342-
343+
343344
if (func_len) {
344345
class = emalloc(class_len+1);
345346
func = emalloc(func_len+1);
346-
347+
347348
memcpy(class, expr, class_len);
348349
class[class_len]='\0';
349350
memcpy(func, func_pos+1, func_len);
350351
func[func_len]='\0';
351-
352+
352353
phpdbg_set_breakpoint_method(class, class_len, func, func_len TSRMLS_CC);
353354
} else {
354355
printf("[No function found in method expression %s]\n", expr);
@@ -410,15 +411,15 @@ static PHPDBG_COMMAND(clean) /* {{{ */
410411
printf("[\tFunctions: %d]\n", zend_hash_num_elements(EG(function_table)));
411412
printf("[\tConstants: %d]\n", zend_hash_num_elements(EG(zend_constants)));
412413
printf("[\tIncluded: %d]\n", zend_hash_num_elements(&EG(included_files)));
413-
414+
414415
/* this is implicitly required */
415416
if (PHPDBG_G(ops)) {
416417
destroy_op_array(
417418
PHPDBG_G(ops) TSRMLS_CC);
418419
efree(PHPDBG_G(ops));
419420
PHPDBG_G(ops) = NULL;
420421
}
421-
422+
422423
zend_hash_reverse_apply(EG(function_table), (apply_func_t) clean_non_persistent_function_full TSRMLS_CC);
423424
zend_hash_reverse_apply(EG(class_table), (apply_func_t) clean_non_persistent_class_full TSRMLS_CC);
424425
zend_hash_reverse_apply(EG(zend_constants), (apply_func_t) clean_non_persistent_constant_full TSRMLS_CC);
@@ -445,7 +446,7 @@ static PHPDBG_COMMAND(clear) /* {{{ */
445446
printf("[\tSymbols\t%d]\n", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM]));
446447
printf("[\tOplines\t%d]\n", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE]));
447448
printf("[\tMethods\t%d]\n", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD]));
448-
449+
449450
phpdbg_clear_breakpoints(TSRMLS_C);
450451

451452
return SUCCESS;
@@ -497,18 +498,32 @@ static PHPDBG_COMMAND(quiet) { /* {{{ */
497498

498499
static PHPDBG_COMMAND(list) /* {{{ */
499500
{
500-
long offset = 0, count = strtol(expr, NULL, 0);
501-
const char *filename = PHPDBG_G(exec);
502-
503-
if (zend_is_executing(TSRMLS_C)) {
504-
filename = zend_get_executed_filename(TSRMLS_C);
505-
offset = zend_get_executed_lineno(TSRMLS_C);
506-
} else if (!filename) {
507-
printf("[No file to list]\n");
508-
return SUCCESS;
509-
}
501+
if (phpdbg_is_numeric(expr)) {
502+
long offset = 0, count = strtol(expr, NULL, 0);
503+
const char *filename = PHPDBG_G(exec);
504+
505+
if (zend_is_executing(TSRMLS_C)) {
506+
filename = zend_get_executed_filename(TSRMLS_C);
507+
offset = zend_get_executed_lineno(TSRMLS_C);
508+
} else if (!filename) {
509+
printf("[No file to list]\n");
510+
return SUCCESS;
511+
}
510512

511-
phpdbg_list_file(filename, count, offset TSRMLS_CC);
513+
phpdbg_list_file(filename, count, offset TSRMLS_CC);
514+
} else {
515+
zend_function* fbc;
516+
517+
if (!EG(function_table)) {
518+
printf("[No function table loaded]\n");
519+
return SUCCESS;
520+
}
521+
522+
if (zend_hash_find(EG(function_table), expr, strlen(expr)+1,
523+
(void**)&fbc) == SUCCESS) {
524+
phpdbg_list_function(fbc TSRMLS_CC);
525+
}
526+
}
512527

513528
return SUCCESS;
514529
} /* }}} */
@@ -581,7 +596,7 @@ int phpdbg_interactive(TSRMLS_D) /* {{{ */
581596
}
582597
return PHPDBG_NEXT;
583598
}
584-
599+
585600

586601
}
587602
} else if (PHPDBG_G(last)) {
@@ -660,7 +675,7 @@ void phpdbg_execute_ex(zend_execute_data *execute_data TSRMLS_DC) /* {{{ */
660675
}
661676
}
662677
}
663-
678+
664679
if ((PHPDBG_G(flags) & PHPDBG_HAS_OPLINE_BP)
665680
&& phpdbg_find_breakpoint_opline(execute_data->opline TSRMLS_CC) == SUCCESS) {
666681
while (phpdbg_interactive(TSRMLS_C) != PHPDBG_NEXT) {

phpdbg_utils.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| PHP Version 5 |
4+
+----------------------------------------------------------------------+
5+
| Copyright (c) 1997-2013 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+
| [email protected] so we can mail you a copy immediately. |
14+
+----------------------------------------------------------------------+
15+
| Authors: Felipe Pena <[email protected]> |
16+
| Authors: Joe Watkins <[email protected]> |
17+
+----------------------------------------------------------------------+
18+
*/
19+
20+
#include <ctype.h>
21+
#include "phpdbg_utils.h"
22+
23+
int phpdbg_is_numeric(const char *str) /* {{{ */
24+
{
25+
for (; *str; str++) {
26+
if (isspace(*str)) {
27+
continue;
28+
}
29+
return isdigit(*str);
30+
}
31+
return 0;
32+
} /* }}} */

phpdbg_utils.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| PHP Version 5 |
4+
+----------------------------------------------------------------------+
5+
| Copyright (c) 1997-2013 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+
| [email protected] so we can mail you a copy immediately. |
14+
+----------------------------------------------------------------------+
15+
| Authors: Felipe Pena <[email protected]> |
16+
| Authors: Joe Watkins <[email protected]> |
17+
+----------------------------------------------------------------------+
18+
*/
19+
20+
#ifndef PHPDBG_UTILS_H
21+
#define PHPDBG_UTILS_H
22+
23+
int phpdbg_is_numeric(const char *);
24+
25+
#endif /* PHPDBG_UTILS_H */

0 commit comments

Comments
 (0)