Skip to content

Commit 417a8ef

Browse files
committed
Fix run command args passing when inmidst execution
1 parent 9d53795 commit 417a8ef

9 files changed

+288
-254
lines changed

Diff for: sapi/phpdbg/phpdbg.c

+21-5
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ static void php_sapi_phpdbg_log_message(char *message) /* {{{ */
834834
}
835835

836836
do {
837-
switch (phpdbg_interactive(1)) {
837+
switch (phpdbg_interactive(1, NULL)) {
838838
case PHPDBG_LEAVE:
839839
case PHPDBG_FINISH:
840840
case PHPDBG_UNTIL:
@@ -942,7 +942,7 @@ static inline void php_sapi_phpdbg_flush(void *context) /* {{{ */
942942
} /* }}} */
943943

944944
/* copied from sapi/cli/php_cli.c cli_register_file_handles */
945-
static void phpdbg_register_file_handles(void) /* {{{ */
945+
void phpdbg_register_file_handles(void) /* {{{ */
946946
{
947947
zval zin, zout, zerr;
948948
php_stream *s_in, *s_out, *s_err;
@@ -974,18 +974,21 @@ static void phpdbg_register_file_handles(void) /* {{{ */
974974
ic.flags = CONST_CS;
975975
ic.name = zend_string_init(ZEND_STRL("STDIN"), 0);
976976
ic.module_number = 0;
977+
zend_hash_del(EG(zend_constants), ic.name);
977978
zend_register_constant(&ic);
978979

979980
oc.value = zout;
980981
oc.flags = CONST_CS;
981982
oc.name = zend_string_init(ZEND_STRL("STDOUT"), 0);
982983
oc.module_number = 0;
984+
zend_hash_del(EG(zend_constants), oc.name);
983985
zend_register_constant(&oc);
984986

985987
ec.value = zerr;
986988
ec.flags = CONST_CS;
987989
ec.name = zend_string_init(ZEND_STRL("STDERR"), 0);
988990
ec.module_number = 0;
991+
zend_hash_del(EG(zend_constants), ec.name);
989992
zend_register_constant(&ec);
990993
}
991994
/* }}} */
@@ -1318,6 +1321,7 @@ int main(int argc, char **argv) /* {{{ */
13181321
zend_bool ini_ignore;
13191322
char *ini_override;
13201323
char *exec = NULL;
1324+
char *first_command = NULL;
13211325
char *init_file;
13221326
size_t init_file_len;
13231327
zend_bool init_file_default;
@@ -1800,7 +1804,6 @@ int main(int argc, char **argv) /* {{{ */
18001804
/* set default prompt */
18011805
phpdbg_set_prompt(PHPDBG_DEFAULT_PROMPT);
18021806

1803-
/* refactor to preserve run commands on force run command */
18041807
{
18051808
php_stream_wrapper *wrapper = zend_hash_str_find_ptr(php_stream_get_url_stream_wrappers_hash(), ZEND_STRL("php"));
18061809
PHPDBG_G(orig_url_wrap_php) = wrapper->wops->stream_opener;
@@ -1886,7 +1889,11 @@ int main(int argc, char **argv) /* {{{ */
18861889
PHPDBG_G(flags) |= PHPDBG_IS_INTERACTIVE;
18871890
}
18881891
zend_try {
1889-
PHPDBG_COMMAND_HANDLER(run)(NULL);
1892+
if (first_command) {
1893+
phpdbg_interactive(1, estrdup(first_command));
1894+
} else {
1895+
PHPDBG_COMMAND_HANDLER(run)(NULL);
1896+
}
18901897
} zend_end_try();
18911898
if (quit_immediately) {
18921899
/* if -r is on the command line more than once just quit */
@@ -1897,7 +1904,7 @@ int main(int argc, char **argv) /* {{{ */
18971904
}
18981905

18991906
CG(unclean_shutdown) = 0;
1900-
phpdbg_interactive(1);
1907+
phpdbg_interactive(1, NULL);
19011908
} zend_catch {
19021909
if ((PHPDBG_G(flags) & PHPDBG_IS_CLEANING)) {
19031910
char *bp_tmp_str;
@@ -1955,6 +1962,11 @@ int main(int argc, char **argv) /* {{{ */
19551962
phpdbg_out:
19561963
#endif
19571964

1965+
if (first_command) {
1966+
free(first_command);
1967+
first_command = NULL;
1968+
}
1969+
19581970
if (cleaning <= 0) {
19591971
PHPDBG_G(flags) &= ~PHPDBG_IS_CLEANING;
19601972
cleaning = -1;
@@ -2006,13 +2018,17 @@ int main(int argc, char **argv) /* {{{ */
20062018
settings->input_buflen = PHPDBG_G(input_buflen);
20072019
memcpy(settings->input_buffer, PHPDBG_G(input_buffer), settings->input_buflen);
20082020
settings->flags = PHPDBG_G(flags) & PHPDBG_PRESERVE_FLAGS_MASK;
2021+
first_command = PHPDBG_G(cur_command);
20092022
} else {
20102023
if (PHPDBG_G(prompt)[0]) {
20112024
free(PHPDBG_G(prompt)[0]);
20122025
}
20132026
if (PHPDBG_G(prompt)[1]) {
20142027
free(PHPDBG_G(prompt)[1]);
20152028
}
2029+
if (PHPDBG_G(cur_command)) {
2030+
free(PHPDBG_G(cur_command));
2031+
}
20162032
}
20172033

20182034
/* hack to restore mm_heap->use_custom_heap in order to receive memory leak info */

Diff for: sapi/phpdbg/phpdbg.h

+3
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ int phpdbg_do_parse(phpdbg_param_t *stack, char *input);
232232
}
233233

234234

235+
void phpdbg_register_file_handles(void);
236+
235237
/* {{{ structs */
236238
ZEND_BEGIN_MODULE_GLOBALS(phpdbg)
237239
HashTable bp[PHPDBG_BREAK_TABLES]; /* break points */
@@ -242,6 +244,7 @@ ZEND_BEGIN_MODULE_GLOBALS(phpdbg)
242244
phpdbg_frame_t frame; /* frame */
243245
uint32_t last_line; /* last executed line */
244246

247+
char *cur_command; /* current command */
245248
phpdbg_lexer_data lexer; /* lexer data */
246249
phpdbg_param_t *parser_stack; /* param stack during lexer / parser phase */
247250

0 commit comments

Comments
 (0)