Skip to content

remove specialized printing from phpdbg #7156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions sapi/phpdbg/phpdbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ static ssize_t phpdbg_stdiop_write(php_stream *stream, const char *buf, size_t c
return count;
}
if (stat[2].st_dev == stat[1].st_dev && stat[2].st_ino == stat[1].st_ino) {
phpdbg_script_ex(PHPDBG_G(io)[PHPDBG_STDERR].fd, P_STDERR, "%.*s", (int) count, buf);
phpdbg_script(P_STDERR, "%.*s", (int) count, buf);
return count;
}
break;
Expand All @@ -882,13 +882,6 @@ static ssize_t phpdbg_stdiop_write(php_stream *stream, const char *buf, size_t c
return PHPDBG_G(php_stdiop_write)(stream, buf, count);
}

static inline void php_sapi_phpdbg_flush(void *context) /* {{{ */
{
if (!phpdbg_active_sigsafe_mem()) {
fflush(PHPDBG_G(io)[PHPDBG_STDOUT].ptr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering why this is gone now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We no longer write buffered (FILE*) streams anywhere, this looks like a left over relic rather than necessary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense.

}
} /* }}} */

/* copied from sapi/cli/php_cli.c cli_register_file_handles */
void phpdbg_register_file_handles(void) /* {{{ */
{
Expand Down Expand Up @@ -950,7 +943,7 @@ static sapi_module_struct phpdbg_sapi_module = {
php_sapi_phpdbg_deactivate, /* deactivate */

php_sapi_phpdbg_ub_write, /* unbuffered write */
php_sapi_phpdbg_flush, /* flush */
NULL, /* flush */
NULL, /* get uid */
NULL, /* getenv */

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

PHPDBG_G(io)[PHPDBG_STDIN].ptr = stdin;

PHPDBG_G(io)[PHPDBG_STDIN].fd = fileno(stdin);
PHPDBG_G(io)[PHPDBG_STDOUT].ptr = stdout;
PHPDBG_G(io)[PHPDBG_STDOUT].fd = fileno(stdout);
PHPDBG_G(io)[PHPDBG_STDERR].ptr = stderr;
PHPDBG_G(io)[PHPDBG_STDERR].fd = fileno(stderr);

#ifndef _WIN32
Expand Down Expand Up @@ -1690,7 +1680,7 @@ int main(int argc, char **argv) /* {{{ */
PHPDBG_G(flags) &= ~PHPDBG_DISCARD_OUTPUT;
if (bp_tmp_str) {
bp_tmp = strdup(bp_tmp_str);
efree(bp_tmp_str);
free(bp_tmp_str);
}
cleaning = 1;
} else {
Expand Down
3 changes: 1 addition & 2 deletions sapi/phpdbg/phpdbg.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ ZEND_BEGIN_MODULE_GLOBALS(phpdbg)
phpdbg_oplog_entry *oplog_cur; /* current oplog entry */

struct {
FILE *ptr;
int fd;
} io[PHPDBG_IO_FDS]; /* io */
ssize_t (*php_stdiop_write)(php_stream *, const char *, size_t);
Expand Down Expand Up @@ -302,7 +301,7 @@ ZEND_BEGIN_MODULE_GLOBALS(phpdbg)
uint64_t flags; /* phpdbg flags */

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

#endif
Expand Down
106 changes: 53 additions & 53 deletions sapi/phpdbg/phpdbg_bp.c

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions sapi/phpdbg/phpdbg_bp.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ typedef struct _phpdbg_breakbase_t {
*/
typedef struct _phpdbg_breakfile_t {
phpdbg_breakbase(filename);
long line;
zend_ulong line;
} phpdbg_breakfile_t;

/**
Expand Down Expand Up @@ -123,7 +123,7 @@ PHPDBG_API HashTable *phpdbg_resolve_pending_file_break_ex(const char *file, uin
PHPDBG_API void phpdbg_resolve_pending_file_break(const char *file); /* }}} */

/* {{{ Breakpoint Creation API */
PHPDBG_API void phpdbg_set_breakpoint_file(const char* filename, size_t path_len, long lineno);
PHPDBG_API void phpdbg_set_breakpoint_file(const char* filename, size_t path_len, zend_ulong lineno);
PHPDBG_API void phpdbg_set_breakpoint_symbol(const char* func_name, size_t func_name_len);
PHPDBG_API void phpdbg_set_breakpoint_method(const char* class_name, const char* func_name);
PHPDBG_API void phpdbg_set_breakpoint_opcode(const char* opname, size_t opname_len);
Expand Down
32 changes: 16 additions & 16 deletions sapi/phpdbg/phpdbg_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ PHPDBG_API char* phpdbg_param_tostring(const phpdbg_param_t *param, char **point
break;

case NUMERIC_PARAM:
ZEND_IGNORE_VALUE(asprintf(pointer, "%li", param->num));
ZEND_IGNORE_VALUE(asprintf(pointer, ZEND_LONG_FMT, param->num));
break;

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

case FILE_PARAM:
if (param->num) {
ZEND_IGNORE_VALUE(asprintf(pointer, "%s:%lu#%lu", param->file.name, param->file.line, param->num));
ZEND_IGNORE_VALUE(asprintf(pointer, "%s:"ZEND_ULONG_FMT"#"ZEND_ULONG_FMT, param->file.name, param->file.line, param->num));
} else {
ZEND_IGNORE_VALUE(asprintf(pointer, "%s:%lu", param->file.name, param->file.line));
ZEND_IGNORE_VALUE(asprintf(pointer, "%s:"ZEND_ULONG_FMT, param->file.name, param->file.line));
}
break;

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

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

default:
Expand Down Expand Up @@ -331,11 +331,11 @@ PHPDBG_API void phpdbg_param_debug(const phpdbg_param_t *param, const char *msg)
break;

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

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

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

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

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

case COND_PARAM:
Expand Down Expand Up @@ -468,9 +468,9 @@ PHPDBG_API int phpdbg_stack_verify(const phpdbg_command_t *command, phpdbg_param
char buffer[128] = {0,};
const phpdbg_param_t *top = (stack != NULL) ? *stack : NULL;
const char *arg = command->args;
size_t least = 0L,
received = 0L,
current = 0L;
zend_ulong least = 0L,
received = 0L,
current = 0L;
bool optional = 0;

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

#define verify_arg(e, a, t) if (!(a)) { \
if (!optional) { \
phpdbg_error("The command \"%s\" expected %s and got nothing at parameter %lu", \
phpdbg_error("The command \"%s\" expected %s and got nothing at parameter "ZEND_ULONG_FMT, \
phpdbg_command_name(command, buffer), \
(e), \
current); \
return FAILURE;\
} \
} else if ((a)->type != (t)) { \
phpdbg_error("The command \"%s\" expected %s and got %s at parameter %lu", \
phpdbg_error("The command \"%s\" expected %s and got %s at parameter "ZEND_ULONG_FMT, \
phpdbg_command_name(command, buffer), \
(e),\
phpdbg_get_param_type((a)), \
Expand Down Expand Up @@ -554,7 +554,7 @@ PHPDBG_API int phpdbg_stack_verify(const phpdbg_command_t *command, phpdbg_param
#undef verify_arg

if ((received < least)) {
phpdbg_error("The command \"%s\" expected at least %lu arguments (%s) and received %lu",
phpdbg_error("The command \"%s\" expected at least "ZEND_ULONG_FMT" arguments (%s) and received "ZEND_ULONG_FMT,
phpdbg_command_name(command, buffer),
least,
command->args,
Expand Down Expand Up @@ -643,7 +643,7 @@ PHPDBG_API const phpdbg_command_t *phpdbg_stack_resolve(const phpdbg_command_t *
}

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

return NULL;
Expand Down
6 changes: 3 additions & 3 deletions sapi/phpdbg/phpdbg_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ typedef enum {
typedef struct _phpdbg_param phpdbg_param_t;
struct _phpdbg_param {
phpdbg_param_type type;
long num;
zend_long num;
zend_ulong addr;
struct {
char *name;
long line;
zend_ulong line;
} file;
struct {
char *class;
Expand Down Expand Up @@ -175,7 +175,7 @@ PHPDBG_API void phpdbg_param_debug(const phpdbg_param_t *param, const char *msg)
*/
#define phpdbg_default_switch_case() \
default: \
phpdbg_error("command", "type=\"wrongarg\" got=\"%s\"", "Unsupported parameter type (%s) for command", phpdbg_get_param_type(param)); \
phpdbg_error("Unsupported parameter type (%s) for command", phpdbg_get_param_type(param)); \
break

#endif /* PHPDBG_CMD_H */
4 changes: 2 additions & 2 deletions sapi/phpdbg/phpdbg_frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ void phpdbg_dump_backtrace(size_t num) /* {{{ */
if (file) { /* userland */
phpdbg_out("frame #%d: ", i);
phpdbg_dump_prototype(tmp);
phpdbg_out(" at %s:%ld\n", Z_STRVAL_P(file), Z_LVAL_P(line));
phpdbg_out(" at %s:"ZEND_LONG_FMT"\n", Z_STRVAL_P(file), Z_LVAL_P(line));
i++;
} else {
phpdbg_out(" => ");
Expand All @@ -292,7 +292,7 @@ void phpdbg_dump_backtrace(size_t num) /* {{{ */
zend_hash_move_forward_ex(Z_ARRVAL(zbacktrace), &position);
}

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

zval_ptr_dtor_nogc(&zbacktrace);
zend_string_release(Z_STR(startfile));
Expand Down
20 changes: 10 additions & 10 deletions sapi/phpdbg/phpdbg_help.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ void pretty_print(char *text)
char *new, *p, *q;

const char *prompt_escape = phpdbg_get_prompt();
unsigned int prompt_escape_len = strlen(prompt_escape);
unsigned int prompt_len = strlen(PHPDBG_G(prompt)[0]);
size_t prompt_escape_len = strlen(prompt_escape);
size_t prompt_len = strlen(PHPDBG_G(prompt)[0]);

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

unsigned int term_width = phpdbg_get_terminal_width();
unsigned int size = 0;
uint32_t term_width = phpdbg_get_terminal_width();
uint32_t size = 0;

int in_bold = 0;

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

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

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

phpdbg_out("%s\n", new);
Expand Down Expand Up @@ -279,7 +279,7 @@ PHPDBG_HELP(aliases) /* {{{ */
int len;

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

for(c = phpdbg_prompt_commands; c->name; c++) {
if (c->alias && c->alias != 'h') {
Expand Down
9 changes: 6 additions & 3 deletions sapi/phpdbg/phpdbg_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ PHPDBG_INFO(error) /* {{{ */
{
if (PG(last_error_message)) {
phpdbg_try_access {
phpdbg_writeln("Last error: %s at %s line %d", PG(last_error_message), ZSTR_VAL(PG(last_error_file)), PG(last_error_lineno));
phpdbg_writeln("Last error: %s at %s line %d",
ZSTR_VAL(PG(last_error_message)),
ZSTR_VAL(PG(last_error_file)),
PG(last_error_lineno));
} phpdbg_catch_access {
phpdbg_notice("No error found!");
} phpdbg_end_try_access();
Expand Down Expand Up @@ -140,7 +143,7 @@ PHPDBG_INFO(constants) /* {{{ */
VARIABLEINFO("\nbool (false)");
break;
case IS_LONG:
VARIABLEINFO("\nint (%ld)", Z_LVAL(data->value));
VARIABLEINFO("\nint ("ZEND_LONG_FMT")", Z_LVAL(data->value));
break;
case IS_DOUBLE:
VARIABLEINFO("\ndouble (%lf)", Z_DVAL(data->value));
Expand Down Expand Up @@ -261,7 +264,7 @@ static int phpdbg_print_symbols(bool show_globals) {
VARIABLEINFO("\nbool (false)");
break;
case IS_LONG:
VARIABLEINFO("\nint (%ld)", Z_LVAL_P(data));
VARIABLEINFO("\nint ("ZEND_LONG_FMT")", Z_LVAL_P(data));
break;
case IS_DOUBLE:
VARIABLEINFO("\ndouble (%lf)", Z_DVAL_P(data));
Expand Down
2 changes: 1 addition & 1 deletion sapi/phpdbg/phpdbg_opcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void phpdbg_print_opline_ex(zend_execute_data *execute_data, bool ignore_flags)
}

if (!ignore_flags && PHPDBG_G(oplog)) {
phpdbg_log_ex(fileno(PHPDBG_G(oplog)), "L%-5u %16p %s %s\n",
phpdbg_log_internal(fileno(PHPDBG_G(oplog)), "L%-5u %16p %s %s\n",
opline->lineno,
opline,
decode,
Expand Down
Loading