Skip to content

Commit 6318040

Browse files
authored
remove specialized printing from phpdbg (php#7156)
1 parent 82bcc9b commit 6318040

16 files changed

+152
-953
lines changed

sapi/phpdbg/phpdbg.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ static ssize_t phpdbg_stdiop_write(php_stream *stream, const char *buf, size_t c
873873
return count;
874874
}
875875
if (stat[2].st_dev == stat[1].st_dev && stat[2].st_ino == stat[1].st_ino) {
876-
phpdbg_script_ex(PHPDBG_G(io)[PHPDBG_STDERR].fd, P_STDERR, "%.*s", (int) count, buf);
876+
phpdbg_script(P_STDERR, "%.*s", (int) count, buf);
877877
return count;
878878
}
879879
break;
@@ -882,13 +882,6 @@ static ssize_t phpdbg_stdiop_write(php_stream *stream, const char *buf, size_t c
882882
return PHPDBG_G(php_stdiop_write)(stream, buf, count);
883883
}
884884

885-
static inline void php_sapi_phpdbg_flush(void *context) /* {{{ */
886-
{
887-
if (!phpdbg_active_sigsafe_mem()) {
888-
fflush(PHPDBG_G(io)[PHPDBG_STDOUT].ptr);
889-
}
890-
} /* }}} */
891-
892885
/* copied from sapi/cli/php_cli.c cli_register_file_handles */
893886
void phpdbg_register_file_handles(void) /* {{{ */
894887
{
@@ -950,7 +943,7 @@ static sapi_module_struct phpdbg_sapi_module = {
950943
php_sapi_phpdbg_deactivate, /* deactivate */
951944

952945
php_sapi_phpdbg_ub_write, /* unbuffered write */
953-
php_sapi_phpdbg_flush, /* flush */
946+
NULL, /* flush */
954947
NULL, /* get uid */
955948
NULL, /* getenv */
956949

@@ -1425,7 +1418,6 @@ int main(int argc, char **argv) /* {{{ */
14251418
if (show_version || show_help) {
14261419
/* It ain't gonna proceed to real execution anyway,
14271420
but the correct descriptor is needed already. */
1428-
PHPDBG_G(io)[PHPDBG_STDOUT].ptr = stdout;
14291421
PHPDBG_G(io)[PHPDBG_STDOUT].fd = fileno(stdout);
14301422
if (show_help) {
14311423
phpdbg_do_help_cmd(exec);
@@ -1532,11 +1524,9 @@ int main(int argc, char **argv) /* {{{ */
15321524
#endif
15331525
zend_try { zend_signal(SIGINT, phpdbg_sigint_handler); } zend_end_try();
15341526

1535-
PHPDBG_G(io)[PHPDBG_STDIN].ptr = stdin;
1527+
15361528
PHPDBG_G(io)[PHPDBG_STDIN].fd = fileno(stdin);
1537-
PHPDBG_G(io)[PHPDBG_STDOUT].ptr = stdout;
15381529
PHPDBG_G(io)[PHPDBG_STDOUT].fd = fileno(stdout);
1539-
PHPDBG_G(io)[PHPDBG_STDERR].ptr = stderr;
15401530
PHPDBG_G(io)[PHPDBG_STDERR].fd = fileno(stderr);
15411531

15421532
#ifndef _WIN32
@@ -1690,7 +1680,7 @@ int main(int argc, char **argv) /* {{{ */
16901680
PHPDBG_G(flags) &= ~PHPDBG_DISCARD_OUTPUT;
16911681
if (bp_tmp_str) {
16921682
bp_tmp = strdup(bp_tmp_str);
1693-
efree(bp_tmp_str);
1683+
free(bp_tmp_str);
16941684
}
16951685
cleaning = 1;
16961686
} else {

sapi/phpdbg/phpdbg.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ ZEND_BEGIN_MODULE_GLOBALS(phpdbg)
272272
phpdbg_oplog_entry *oplog_cur; /* current oplog entry */
273273

274274
struct {
275-
FILE *ptr;
276275
int fd;
277276
} io[PHPDBG_IO_FDS]; /* io */
278277
ssize_t (*php_stdiop_write)(php_stream *, const char *, size_t);
@@ -302,7 +301,7 @@ ZEND_BEGIN_MODULE_GLOBALS(phpdbg)
302301
uint64_t flags; /* phpdbg flags */
303302

304303
char *sapi_name_ptr; /* store sapi name to free it if necessary to not leak memory */
305-
long lines; /* max number of lines to display */
304+
zend_ulong lines; /* max number of lines to display */
306305
ZEND_END_MODULE_GLOBALS(phpdbg) /* }}} */
307306

308307
#endif

sapi/phpdbg/phpdbg_bp.c

Lines changed: 53 additions & 53 deletions
Large diffs are not rendered by default.

sapi/phpdbg/phpdbg_bp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ typedef struct _phpdbg_breakbase_t {
5454
*/
5555
typedef struct _phpdbg_breakfile_t {
5656
phpdbg_breakbase(filename);
57-
long line;
57+
zend_ulong line;
5858
} phpdbg_breakfile_t;
5959

6060
/**
@@ -123,7 +123,7 @@ PHPDBG_API HashTable *phpdbg_resolve_pending_file_break_ex(const char *file, uin
123123
PHPDBG_API void phpdbg_resolve_pending_file_break(const char *file); /* }}} */
124124

125125
/* {{{ Breakpoint Creation API */
126-
PHPDBG_API void phpdbg_set_breakpoint_file(const char* filename, size_t path_len, long lineno);
126+
PHPDBG_API void phpdbg_set_breakpoint_file(const char* filename, size_t path_len, zend_ulong lineno);
127127
PHPDBG_API void phpdbg_set_breakpoint_symbol(const char* func_name, size_t func_name_len);
128128
PHPDBG_API void phpdbg_set_breakpoint_method(const char* class_name, const char* func_name);
129129
PHPDBG_API void phpdbg_set_breakpoint_opcode(const char* opname, size_t opname_len);

sapi/phpdbg/phpdbg_cmd.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ PHPDBG_API char* phpdbg_param_tostring(const phpdbg_param_t *param, char **point
101101
break;
102102

103103
case NUMERIC_PARAM:
104-
ZEND_IGNORE_VALUE(asprintf(pointer, "%li", param->num));
104+
ZEND_IGNORE_VALUE(asprintf(pointer, ZEND_LONG_FMT, param->num));
105105
break;
106106

107107
case METHOD_PARAM:
@@ -110,18 +110,18 @@ PHPDBG_API char* phpdbg_param_tostring(const phpdbg_param_t *param, char **point
110110

111111
case FILE_PARAM:
112112
if (param->num) {
113-
ZEND_IGNORE_VALUE(asprintf(pointer, "%s:%lu#%lu", param->file.name, param->file.line, param->num));
113+
ZEND_IGNORE_VALUE(asprintf(pointer, "%s:"ZEND_ULONG_FMT"#"ZEND_ULONG_FMT, param->file.name, param->file.line, param->num));
114114
} else {
115-
ZEND_IGNORE_VALUE(asprintf(pointer, "%s:%lu", param->file.name, param->file.line));
115+
ZEND_IGNORE_VALUE(asprintf(pointer, "%s:"ZEND_ULONG_FMT, param->file.name, param->file.line));
116116
}
117117
break;
118118

119119
case NUMERIC_FUNCTION_PARAM:
120-
ZEND_IGNORE_VALUE(asprintf(pointer, "%s#%lu", param->str, param->num));
120+
ZEND_IGNORE_VALUE(asprintf(pointer, "%s#"ZEND_ULONG_FMT, param->str, param->num));
121121
break;
122122

123123
case NUMERIC_METHOD_PARAM:
124-
ZEND_IGNORE_VALUE(asprintf(pointer, "%s::%s#%lu", param->method.class, param->method.name, param->num));
124+
ZEND_IGNORE_VALUE(asprintf(pointer, "%s::%s#"ZEND_ULONG_FMT, param->method.class, param->method.name, param->num));
125125
break;
126126

127127
default:
@@ -331,11 +331,11 @@ PHPDBG_API void phpdbg_param_debug(const phpdbg_param_t *param, const char *msg)
331331
break;
332332

333333
case NUMERIC_FILE_PARAM:
334-
fprintf(stderr, "%s NUMERIC_FILE_PARAM(%s:#%lu)\n", msg, param->file.name, param->file.line);
334+
fprintf(stderr, "%s NUMERIC_FILE_PARAM(%s:#"ZEND_ULONG_FMT")\n", msg, param->file.name, param->file.line);
335335
break;
336336

337337
case FILE_PARAM:
338-
fprintf(stderr, "%s FILE_PARAM(%s:%lu)\n", msg, param->file.name, param->file.line);
338+
fprintf(stderr, "%s FILE_PARAM(%s:"ZEND_ULONG_FMT")\n", msg, param->file.name, param->file.line);
339339
break;
340340

341341
case METHOD_PARAM:
@@ -347,11 +347,11 @@ PHPDBG_API void phpdbg_param_debug(const phpdbg_param_t *param, const char *msg)
347347
break;
348348

349349
case NUMERIC_FUNCTION_PARAM:
350-
fprintf(stderr, "%s NUMERIC_FUNCTION_PARAM(%s::%ld)\n", msg, param->str, param->num);
350+
fprintf(stderr, "%s NUMERIC_FUNCTION_PARAM(%s::"ZEND_LONG_FMT")\n", msg, param->str, param->num);
351351
break;
352352

353353
case NUMERIC_PARAM:
354-
fprintf(stderr, "%s NUMERIC_PARAM(%ld)\n", msg, param->num);
354+
fprintf(stderr, "%s NUMERIC_PARAM("ZEND_LONG_FMT")\n", msg, param->num);
355355
break;
356356

357357
case COND_PARAM:
@@ -468,9 +468,9 @@ PHPDBG_API int phpdbg_stack_verify(const phpdbg_command_t *command, phpdbg_param
468468
char buffer[128] = {0,};
469469
const phpdbg_param_t *top = (stack != NULL) ? *stack : NULL;
470470
const char *arg = command->args;
471-
size_t least = 0L,
472-
received = 0L,
473-
current = 0L;
471+
zend_ulong least = 0L,
472+
received = 0L,
473+
current = 0L;
474474
bool optional = 0;
475475

476476
/* check for arg spec */
@@ -499,14 +499,14 @@ PHPDBG_API int phpdbg_stack_verify(const phpdbg_command_t *command, phpdbg_param
499499

500500
#define verify_arg(e, a, t) if (!(a)) { \
501501
if (!optional) { \
502-
phpdbg_error("The command \"%s\" expected %s and got nothing at parameter %lu", \
502+
phpdbg_error("The command \"%s\" expected %s and got nothing at parameter "ZEND_ULONG_FMT, \
503503
phpdbg_command_name(command, buffer), \
504504
(e), \
505505
current); \
506506
return FAILURE;\
507507
} \
508508
} else if ((a)->type != (t)) { \
509-
phpdbg_error("The command \"%s\" expected %s and got %s at parameter %lu", \
509+
phpdbg_error("The command \"%s\" expected %s and got %s at parameter "ZEND_ULONG_FMT, \
510510
phpdbg_command_name(command, buffer), \
511511
(e),\
512512
phpdbg_get_param_type((a)), \
@@ -554,7 +554,7 @@ PHPDBG_API int phpdbg_stack_verify(const phpdbg_command_t *command, phpdbg_param
554554
#undef verify_arg
555555

556556
if ((received < least)) {
557-
phpdbg_error("The command \"%s\" expected at least %lu arguments (%s) and received %lu",
557+
phpdbg_error("The command \"%s\" expected at least "ZEND_ULONG_FMT" arguments (%s) and received "ZEND_ULONG_FMT,
558558
phpdbg_command_name(command, buffer),
559559
least,
560560
command->args,
@@ -643,7 +643,7 @@ PHPDBG_API const phpdbg_command_t *phpdbg_stack_resolve(const phpdbg_command_t *
643643
}
644644

645645
/* ", " separated matches */
646-
phpdbg_error("The command \"%s\" is ambiguous, matching %lu commands (%s)", name->str, matches, list);
646+
phpdbg_error("The command \"%s\" is ambiguous, matching "ZEND_ULONG_FMT" commands (%s)", name->str, matches, list);
647647
efree(list);
648648

649649
return NULL;

sapi/phpdbg/phpdbg_cmd.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ typedef enum {
5151
typedef struct _phpdbg_param phpdbg_param_t;
5252
struct _phpdbg_param {
5353
phpdbg_param_type type;
54-
long num;
54+
zend_long num;
5555
zend_ulong addr;
5656
struct {
5757
char *name;
58-
long line;
58+
zend_ulong line;
5959
} file;
6060
struct {
6161
char *class;
@@ -175,7 +175,7 @@ PHPDBG_API void phpdbg_param_debug(const phpdbg_param_t *param, const char *msg)
175175
*/
176176
#define phpdbg_default_switch_case() \
177177
default: \
178-
phpdbg_error("command", "type=\"wrongarg\" got=\"%s\"", "Unsupported parameter type (%s) for command", phpdbg_get_param_type(param)); \
178+
phpdbg_error("Unsupported parameter type (%s) for command", phpdbg_get_param_type(param)); \
179179
break
180180

181181
#endif /* PHPDBG_CMD_H */

sapi/phpdbg/phpdbg_frame.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ void phpdbg_dump_backtrace(size_t num) /* {{{ */
279279
if (file) { /* userland */
280280
phpdbg_out("frame #%d: ", i);
281281
phpdbg_dump_prototype(tmp);
282-
phpdbg_out(" at %s:%ld\n", Z_STRVAL_P(file), Z_LVAL_P(line));
282+
phpdbg_out(" at %s:"ZEND_LONG_FMT"\n", Z_STRVAL_P(file), Z_LVAL_P(line));
283283
i++;
284284
} else {
285285
phpdbg_out(" => ");
@@ -292,7 +292,7 @@ void phpdbg_dump_backtrace(size_t num) /* {{{ */
292292
zend_hash_move_forward_ex(Z_ARRVAL(zbacktrace), &position);
293293
}
294294

295-
phpdbg_writeln("frame #%d: {main} at %s:%ld", i, Z_STRVAL_P(file), Z_LVAL_P(line));
295+
phpdbg_writeln("frame #%d: {main} at %s:"ZEND_LONG_FMT, i, Z_STRVAL_P(file), Z_LVAL_P(line));
296296

297297
zval_ptr_dtor_nogc(&zbacktrace);
298298
zend_string_release(Z_STR(startfile));

sapi/phpdbg/phpdbg_help.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,21 @@ void pretty_print(char *text)
4343
char *new, *p, *q;
4444

4545
const char *prompt_escape = phpdbg_get_prompt();
46-
unsigned int prompt_escape_len = strlen(prompt_escape);
47-
unsigned int prompt_len = strlen(PHPDBG_G(prompt)[0]);
46+
size_t prompt_escape_len = strlen(prompt_escape);
47+
size_t prompt_len = strlen(PHPDBG_G(prompt)[0]);
4848

4949
const char *bold_on_escape = PHPDBG_G(flags) & PHPDBG_IS_COLOURED ? "\033[1m" : "";
5050
const char *bold_off_escape = PHPDBG_G(flags) & PHPDBG_IS_COLOURED ? "\033[0m" : "";
51-
unsigned int bold_escape_len = strlen(bold_on_escape);
51+
size_t bold_escape_len = strlen(bold_on_escape);
5252

53-
unsigned int term_width = phpdbg_get_terminal_width();
54-
unsigned int size = 0;
53+
uint32_t term_width = phpdbg_get_terminal_width();
54+
uint32_t size = 0;
5555

5656
int in_bold = 0;
5757

58-
char *last_new_blank = NULL; /* position in new buffer of last blank char */
59-
unsigned int last_blank_count = 0; /* printable char offset of last blank char */
60-
unsigned int line_count = 0; /* number printable chars on current line */
58+
char *last_new_blank = NULL; /* position in new buffer of last blank char */
59+
uint32_t last_blank_count = 0; /* printable char offset of last blank char */
60+
uint32_t line_count = 0; /* number printable chars on current line */
6161

6262
/* First pass calculates a safe size for the pretty print version */
6363
for (p = text; *p; p++) {
@@ -126,7 +126,7 @@ void pretty_print(char *text)
126126
*q++ = '\0';
127127

128128
if ((q-new)>size) {
129-
phpdbg_error("Output overrun of %lu bytes", ((q - new) - size));
129+
phpdbg_error("Output overrun of %" PRIu32 " bytes", (uint32_t) ((q - new) - size));
130130
}
131131

132132
phpdbg_out("%s\n", new);
@@ -279,7 +279,7 @@ PHPDBG_HELP(aliases) /* {{{ */
279279
int len;
280280

281281
/* Print out aliases for all commands except help as this one comes last */
282-
phpdbg_writeln("help", "", "Below are the aliased, short versions of all supported commands");
282+
phpdbg_writeln("Below are the aliased, short versions of all supported commands");
283283

284284
for(c = phpdbg_prompt_commands; c->name; c++) {
285285
if (c->alias && c->alias != 'h') {

sapi/phpdbg/phpdbg_info.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ PHPDBG_INFO(error) /* {{{ */
8383
{
8484
if (PG(last_error_message)) {
8585
phpdbg_try_access {
86-
phpdbg_writeln("Last error: %s at %s line %d", PG(last_error_message), ZSTR_VAL(PG(last_error_file)), PG(last_error_lineno));
86+
phpdbg_writeln("Last error: %s at %s line %d",
87+
ZSTR_VAL(PG(last_error_message)),
88+
ZSTR_VAL(PG(last_error_file)),
89+
PG(last_error_lineno));
8790
} phpdbg_catch_access {
8891
phpdbg_notice("No error found!");
8992
} phpdbg_end_try_access();
@@ -140,7 +143,7 @@ PHPDBG_INFO(constants) /* {{{ */
140143
VARIABLEINFO("\nbool (false)");
141144
break;
142145
case IS_LONG:
143-
VARIABLEINFO("\nint (%ld)", Z_LVAL(data->value));
146+
VARIABLEINFO("\nint ("ZEND_LONG_FMT")", Z_LVAL(data->value));
144147
break;
145148
case IS_DOUBLE:
146149
VARIABLEINFO("\ndouble (%lf)", Z_DVAL(data->value));
@@ -261,7 +264,7 @@ static int phpdbg_print_symbols(bool show_globals) {
261264
VARIABLEINFO("\nbool (false)");
262265
break;
263266
case IS_LONG:
264-
VARIABLEINFO("\nint (%ld)", Z_LVAL_P(data));
267+
VARIABLEINFO("\nint ("ZEND_LONG_FMT")", Z_LVAL_P(data));
265268
break;
266269
case IS_DOUBLE:
267270
VARIABLEINFO("\ndouble (%lf)", Z_DVAL_P(data));

sapi/phpdbg/phpdbg_opcode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ void phpdbg_print_opline_ex(zend_execute_data *execute_data, bool ignore_flags)
162162
}
163163

164164
if (!ignore_flags && PHPDBG_G(oplog)) {
165-
phpdbg_log_ex(fileno(PHPDBG_G(oplog)), "L%-5u %16p %s %s\n",
165+
phpdbg_log_internal(fileno(PHPDBG_G(oplog)), "L%-5u %16p %s %s\n",
166166
opline->lineno,
167167
opline,
168168
decode,

0 commit comments

Comments
 (0)