26
26
#include "phpdbg_bp.h"
27
27
#include "phpdbg_opcode.h"
28
28
#include "phpdbg_list.h"
29
+ #include "phpdbg_utils.h"
29
30
30
31
static const phpdbg_command_t phpdbg_prompt_commands [];
31
32
@@ -103,7 +104,7 @@ static PHPDBG_COMMAND(step) /* {{{ */
103
104
} else {
104
105
PHPDBG_G (flags ) &= ~PHPDBG_IS_STEPPING ;
105
106
}
106
-
107
+
107
108
printf (
108
109
"[Stepping %s]\n" , (PHPDBG_G (flags ) & PHPDBG_IS_STEPPING ) ? "on" : "off" );
109
110
return SUCCESS ;
@@ -151,20 +152,20 @@ static PHPDBG_COMMAND(run) /* {{{ */
151
152
static PHPDBG_COMMAND (eval ) /* {{{ */
152
153
{
153
154
zval retval ;
154
-
155
+
155
156
if (expr_len ) {
156
157
zend_bool stepping = (PHPDBG_G (flags ) & PHPDBG_IS_STEPPING );
157
-
158
+
158
159
/* disable stepping while eval() in progress */
159
160
PHPDBG_G (flags ) &= ~ PHPDBG_IS_STEPPING ;
160
-
161
+
161
162
if (zend_eval_stringl ((char * )expr , expr_len - 1 ,
162
163
& retval , "eval()'d code" TSRMLS_CC ) == SUCCESS ) {
163
164
zend_print_zval_r (
164
165
& retval , 0 TSRMLS_CC );
165
166
printf ("\n" );
166
167
}
167
-
168
+
168
169
/* switch stepping back on */
169
170
if (stepping ) {
170
171
PHPDBG_G (flags ) |= PHPDBG_IS_STEPPING ;
@@ -221,7 +222,7 @@ static PHPDBG_COMMAND(print) /* {{{ */
221
222
printf ("Compiled\t%s\n" , PHPDBG_G (ops ) ? "yes" : "no" );
222
223
printf ("Stepping\t%s\n" , (PHPDBG_G (flags ) & PHPDBG_IS_STEPPING ) ? "on" : "off" );
223
224
printf ("Quietness\t%s\n" , (PHPDBG_G (flags ) & PHPDBG_IS_QUIET ) ? "on" : "off" );
224
-
225
+
225
226
if (PHPDBG_G (ops )) {
226
227
printf ("Opcodes\t\t%d\n" , PHPDBG_G (ops )-> last );
227
228
@@ -305,15 +306,15 @@ static PHPDBG_COMMAND(break) /* {{{ */
305
306
{
306
307
char * line_pos = NULL ;
307
308
char * func_pos = NULL ;
308
-
309
+
309
310
if (!expr_len ) {
310
311
printf (
311
312
"[No expression found]\n" );
312
313
return FAILURE ;
313
314
}
314
-
315
+
315
316
line_pos = strchr (expr , ':' );
316
-
317
+
317
318
if (line_pos ) {
318
319
if (!(func_pos = strchr (line_pos + 1 , ':' ))) {
319
320
char path [MAXPATHLEN ], resolved_name [MAXPATHLEN ];
@@ -336,19 +337,19 @@ static PHPDBG_COMMAND(break) /* {{{ */
336
337
} else {
337
338
char * class ;
338
339
char * func ;
339
-
340
+
340
341
size_t func_len = strlen (func_pos + 1 ),
341
342
class_len = (line_pos - expr );
342
-
343
+
343
344
if (func_len ) {
344
345
class = emalloc (class_len + 1 );
345
346
func = emalloc (func_len + 1 );
346
-
347
+
347
348
memcpy (class , expr , class_len );
348
349
class [class_len ]= '\0' ;
349
350
memcpy (func , func_pos + 1 , func_len );
350
351
func [func_len ]= '\0' ;
351
-
352
+
352
353
phpdbg_set_breakpoint_method (class , class_len , func , func_len TSRMLS_CC );
353
354
} else {
354
355
printf ("[No function found in method expression %s]\n" , expr );
@@ -410,15 +411,15 @@ static PHPDBG_COMMAND(clean) /* {{{ */
410
411
printf ("[\tFunctions: %d]\n" , zend_hash_num_elements (EG (function_table )));
411
412
printf ("[\tConstants: %d]\n" , zend_hash_num_elements (EG (zend_constants )));
412
413
printf ("[\tIncluded: %d]\n" , zend_hash_num_elements (& EG (included_files )));
413
-
414
+
414
415
/* this is implicitly required */
415
416
if (PHPDBG_G (ops )) {
416
417
destroy_op_array (
417
418
PHPDBG_G (ops ) TSRMLS_CC );
418
419
efree (PHPDBG_G (ops ));
419
420
PHPDBG_G (ops ) = NULL ;
420
421
}
421
-
422
+
422
423
zend_hash_reverse_apply (EG (function_table ), (apply_func_t ) clean_non_persistent_function_full TSRMLS_CC );
423
424
zend_hash_reverse_apply (EG (class_table ), (apply_func_t ) clean_non_persistent_class_full TSRMLS_CC );
424
425
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) /* {{{ */
445
446
printf ("[\tSymbols\t%d]\n" , zend_hash_num_elements (& PHPDBG_G (bp )[PHPDBG_BREAK_SYM ]));
446
447
printf ("[\tOplines\t%d]\n" , zend_hash_num_elements (& PHPDBG_G (bp )[PHPDBG_BREAK_OPLINE ]));
447
448
printf ("[\tMethods\t%d]\n" , zend_hash_num_elements (& PHPDBG_G (bp )[PHPDBG_BREAK_METHOD ]));
448
-
449
+
449
450
phpdbg_clear_breakpoints (TSRMLS_C );
450
451
451
452
return SUCCESS ;
@@ -497,18 +498,32 @@ static PHPDBG_COMMAND(quiet) { /* {{{ */
497
498
498
499
static PHPDBG_COMMAND (list ) /* {{{ */
499
500
{
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
+ }
510
512
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
+ }
512
527
513
528
return SUCCESS ;
514
529
} /* }}} */
@@ -581,7 +596,7 @@ int phpdbg_interactive(TSRMLS_D) /* {{{ */
581
596
}
582
597
return PHPDBG_NEXT ;
583
598
}
584
-
599
+
585
600
586
601
}
587
602
} else if (PHPDBG_G (last )) {
@@ -660,7 +675,7 @@ void phpdbg_execute_ex(zend_execute_data *execute_data TSRMLS_DC) /* {{{ */
660
675
}
661
676
}
662
677
}
663
-
678
+
664
679
if ((PHPDBG_G (flags ) & PHPDBG_HAS_OPLINE_BP )
665
680
&& phpdbg_find_breakpoint_opline (execute_data -> opline TSRMLS_CC ) == SUCCESS ) {
666
681
while (phpdbg_interactive (TSRMLS_C ) != PHPDBG_NEXT ) {
0 commit comments