@@ -127,6 +127,7 @@ static void php_phpdbg_destroy_file_source(zval *data) /* {{{ */
127127 if (source -> buf ) {
128128 efree (source -> buf );
129129 }
130+ efree (source -> filename );
130131 efree (source );
131132} /* }}} */
132133
@@ -373,7 +374,7 @@ static PHP_FUNCTION(phpdbg_break_file)
373374 return ;
374375 }
375376
376- phpdbg_set_breakpoint_file (file , line );
377+ phpdbg_set_breakpoint_file (file , 0 , line );
377378} /* }}} */
378379
379380/* {{{ proto void phpdbg_break_method(string class, string method) */
@@ -1076,6 +1077,7 @@ const opt_struct OPTIONS[] = { /* {{{ */
10761077 {'r' , 0 , "run" },
10771078 {'e' , 0 , "generate ext_stmt opcodes" },
10781079 {'E' , 0 , "step-through-eval" },
1080+ {'s' , 1 , "script from stdin" },
10791081 {'S' , 1 , "sapi-name" },
10801082#ifndef _WIN32
10811083 {'l' , 1 , "listen" },
@@ -1374,6 +1376,8 @@ int main(int argc, char **argv) /* {{{ */
13741376 zend_bool ext_stmt = 0 ;
13751377 zend_bool is_exit ;
13761378 int exit_status ;
1379+ char * read_from_stdin = NULL ;
1380+ zend_string * backup_phpdbg_compile = NULL ;
13771381
13781382#ifndef _WIN32
13791383 struct sigaction sigio_struct ;
@@ -1482,6 +1486,12 @@ int main(int argc, char **argv) /* {{{ */
14821486
14831487 /* begin phpdbg options */
14841488
1489+ case 's' : { /* read script from stdin */
1490+ if (settings == NULL ) {
1491+ read_from_stdin = strdup (php_optarg );
1492+ }
1493+ } break ;
1494+
14851495 case 'S' : { /* set SAPI name */
14861496 sapi_name = strdup (php_optarg );
14871497 } break ;
@@ -1593,8 +1603,10 @@ int main(int argc, char **argv) /* {{{ */
15931603 php_optarg = NULL ;
15941604 }
15951605
1606+ quit_immediately = phpdbg_startup_run > 1 ;
1607+
15961608 /* set exec if present on command line */
1597- if (argc > php_optind && (strcmp (argv [php_optind - 1 ], "--" ) != SUCCESS )) {
1609+ if (! read_from_stdin && argc > php_optind && (strcmp (argv [php_optind - 1 ], "--" ) != SUCCESS )) {
15981610 if (!exec && strlen (argv [php_optind ])) {
15991611 exec = strdup (argv [php_optind ]);
16001612 }
@@ -1849,13 +1861,6 @@ int main(int argc, char **argv) /* {{{ */
18491861 if (init_file ) {
18501862 phpdbg_init (init_file , init_file_len , init_file_default );
18511863 }
1852- if (bp_tmp ) {
1853- PHPDBG_G (flags ) |= PHPDBG_DISCARD_OUTPUT ;
1854- phpdbg_string_init (bp_tmp );
1855- free (bp_tmp );
1856- bp_tmp = NULL ;
1857- PHPDBG_G (flags ) &= ~PHPDBG_DISCARD_OUTPUT ;
1858- }
18591864 } zend_end_try ();
18601865 PHPDBG_G (flags ) &= ~PHPDBG_IS_INITIALIZING ;
18611866
@@ -1865,18 +1870,55 @@ int main(int argc, char **argv) /* {{{ */
18651870 }
18661871
18671872 /* auto compile */
1868- if (PHPDBG_G (exec )) {
1873+ if (read_from_stdin ) {
1874+ if (!read_from_stdin [0 ]) {
1875+ if (!quit_immediately ) {
1876+ phpdbg_error ("error" , "" , "Impossible to not specify a stdin delimiter without -rr" );
1877+ PHPDBG_G (flags ) |= PHPDBG_IS_QUITTING ;
1878+ goto phpdbg_out ;
1879+ }
1880+ }
1881+ if (show_banner || read_from_stdin [0 ]) {
1882+ phpdbg_notice ("stdin" , "delimiter=\"%s\"" , "Reading input from stdin; put '%s' followed by a newline on an own line after code to end input" , read_from_stdin );
1883+ }
1884+
1885+ if (phpdbg_startup_run > 0 ) {
1886+ PHPDBG_G (flags ) |= PHPDBG_DISCARD_OUTPUT ;
1887+ }
1888+
1889+ zend_try {
1890+ phpdbg_param_t cmd ;
1891+ cmd .str = read_from_stdin ;
1892+ cmd .len = strlen (read_from_stdin );
1893+ PHPDBG_COMMAND_HANDLER (stdin )(& cmd );
1894+ } zend_end_try ();
1895+
1896+ PHPDBG_G (flags ) &= ~PHPDBG_DISCARD_OUTPUT ;
1897+ } else if (PHPDBG_G (exec )) {
18691898 if (settings || phpdbg_startup_run > 0 ) {
18701899 PHPDBG_G (flags ) |= PHPDBG_DISCARD_OUTPUT ;
18711900 }
18721901
18731902 zend_try {
1874- phpdbg_compile ();
1903+ if (backup_phpdbg_compile ) {
1904+ phpdbg_compile_stdin (backup_phpdbg_compile );
1905+ } else {
1906+ phpdbg_compile ();
1907+ }
18751908 } zend_end_try ();
1909+ backup_phpdbg_compile = NULL ;
18761910
18771911 PHPDBG_G (flags ) &= ~PHPDBG_DISCARD_OUTPUT ;
18781912 }
18791913
1914+ if (bp_tmp ) {
1915+ PHPDBG_G (flags ) |= PHPDBG_DISCARD_OUTPUT | PHPDBG_IS_INITIALIZING ;
1916+ phpdbg_string_init (bp_tmp );
1917+ free (bp_tmp );
1918+ bp_tmp = NULL ;
1919+ PHPDBG_G (flags ) &= ~PHPDBG_DISCARD_OUTPUT & ~PHPDBG_IS_INITIALIZING ;
1920+ }
1921+
18801922 if (settings == (void * ) 0x1 ) {
18811923 if (PHPDBG_G (ops )) {
18821924 phpdbg_print_opcodes (print_opline_func );
@@ -1898,7 +1940,6 @@ int main(int argc, char **argv) /* {{{ */
18981940 do {
18991941 zend_try {
19001942 if (phpdbg_startup_run ) {
1901- quit_immediately = phpdbg_startup_run > 1 ;
19021943 phpdbg_startup_run = 0 ;
19031944 if (quit_immediately ) {
19041945 PHPDBG_G (flags ) = (PHPDBG_G (flags ) & ~PHPDBG_HAS_PAGINATION ) | PHPDBG_IS_INTERACTIVE | PHPDBG_PREVENT_INTERACTIVE ;
@@ -2073,6 +2114,12 @@ int main(int argc, char **argv) /* {{{ */
20732114 wrapper -> wops -> stream_opener = PHPDBG_G (orig_url_wrap_php );
20742115 }
20752116
2117+ if (PHPDBG_G (exec ) && !memcmp ("-" , PHPDBG_G (exec ), 2 )) { /* i.e. execution context has been read from stdin - back it up */
2118+ phpdbg_file_source * data = zend_hash_str_find_ptr (& PHPDBG_G (file_sources ), PHPDBG_G (exec ), PHPDBG_G (exec_len ));
2119+ backup_phpdbg_compile = zend_string_alloc (data -> len + 2 , 1 );
2120+ sprintf (ZSTR_VAL (backup_phpdbg_compile ), "?>%.*s" , (int ) data -> len , data -> buf );
2121+ }
2122+
20762123 zend_try {
20772124 php_module_shutdown ();
20782125 } zend_end_try ();
@@ -2097,6 +2144,11 @@ int main(int argc, char **argv) /* {{{ */
20972144 free (sapi_name );
20982145 }
20992146
2147+ if (read_from_stdin ) {
2148+ free (read_from_stdin );
2149+ read_from_stdin = NULL ;
2150+ }
2151+
21002152#ifdef ZTS
21012153 tsrm_shutdown ();
21022154#endif
@@ -2108,6 +2160,10 @@ int main(int argc, char **argv) /* {{{ */
21082160 goto phpdbg_main ;
21092161 }
21102162
2163+ if (backup_phpdbg_compile ) {
2164+ zend_string_free (backup_phpdbg_compile );
2165+ }
2166+
21112167#ifndef _WIN32
21122168 if (address ) {
21132169 free (address );
0 commit comments