Skip to content

replace custom opcode dumper with O+ dump #7227

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 8 commits into from
Jul 13, 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
6 changes: 5 additions & 1 deletion Zend/Optimizer/zend_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -716,11 +716,15 @@ ZEND_API void zend_dump_op(const zend_op_array *op_array, const zend_basic_block
}
}

static void zend_dump_op_line(const zend_op_array *op_array, const zend_basic_block *b, const zend_op *opline, uint32_t dump_flags, const void *data)
ZEND_API void zend_dump_op_line(const zend_op_array *op_array, const zend_basic_block *b, const zend_op *opline, uint32_t dump_flags, const void *data)
{
int len = 0;
const zend_ssa *ssa = NULL;
zend_ssa_op *ssa_op = NULL;

if (dump_flags & ZEND_DUMP_LINE_NUMBERS) {
fprintf(stderr, "L%04u ", opline->lineno);
}

len = fprintf(stderr, "%04u", (uint32_t)(opline - op_array->opcodes));
fprintf(stderr, "%*c", 5-len, ' ');
Expand Down
2 changes: 2 additions & 0 deletions Zend/Optimizer/zend_dump.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
#define ZEND_DUMP_CFG (1<<2)
#define ZEND_DUMP_SSA (1<<3)
#define ZEND_DUMP_LIVE_RANGES (1<<4)
#define ZEND_DUMP_LINE_NUMBERS (1<<5)

BEGIN_EXTERN_C()

ZEND_API void zend_dump_op_array(const zend_op_array *op_array, uint32_t dump_flags, const char *msg, const void *data);
ZEND_API void zend_dump_op(const zend_op_array *op_array, const zend_basic_block *b, const zend_op *opline, uint32_t dump_flags, const zend_ssa *ssa, const zend_ssa_op *ssa_op);
ZEND_API void zend_dump_op_line(const zend_op_array *op_array, const zend_basic_block *b, const zend_op *opline, uint32_t dump_flags, const void *data);
void zend_dump_dominators(const zend_op_array *op_array, const zend_cfg *cfg);
void zend_dump_dfg(const zend_op_array *op_array, const zend_cfg *cfg, const zend_dfg *dfg);
void zend_dump_phi_placement(const zend_op_array *op_array, const zend_ssa *ssa);
Expand Down
2 changes: 1 addition & 1 deletion sapi/phpdbg/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if test "$BUILD_PHPDBG" = "" && test "$PHP_PHPDBG" != "no"; then
fi

PHP_PHPDBG_CFLAGS="-D_GNU_SOURCE -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1"
PHP_PHPDBG_FILES="phpdbg.c phpdbg_parser.c phpdbg_lexer.c phpdbg_prompt.c phpdbg_help.c phpdbg_break.c phpdbg_print.c phpdbg_bp.c phpdbg_opcode.c phpdbg_list.c phpdbg_utils.c phpdbg_info.c phpdbg_cmd.c phpdbg_set.c phpdbg_frame.c phpdbg_watch.c phpdbg_btree.c phpdbg_sigsafe.c phpdbg_io.c phpdbg_out.c"
PHP_PHPDBG_FILES="phpdbg.c phpdbg_parser.c phpdbg_lexer.c phpdbg_prompt.c phpdbg_help.c phpdbg_break.c phpdbg_print.c phpdbg_bp.c phpdbg_list.c phpdbg_utils.c phpdbg_info.c phpdbg_cmd.c phpdbg_set.c phpdbg_frame.c phpdbg_watch.c phpdbg_btree.c phpdbg_sigsafe.c phpdbg_io.c phpdbg_out.c"

AC_MSG_CHECKING([for phpdbg and readline integration])
if test "$PHP_PHPDBG_READLINE" = "yes"; then
Expand Down
2 changes: 1 addition & 1 deletion sapi/phpdbg/config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ARG_ENABLE('phpdbg', 'Build phpdbg', 'no');
ARG_ENABLE('phpdbgs', 'Build phpdbg shared', 'no');

PHPDBG_SOURCES='phpdbg.c phpdbg_prompt.c phpdbg_cmd.c phpdbg_info.c phpdbg_help.c phpdbg_break.c ' +
'phpdbg_print.c phpdbg_bp.c phpdbg_opcode.c phpdbg_list.c phpdbg_utils.c ' +
'phpdbg_print.c phpdbg_bp.c phpdbg_list.c phpdbg_utils.c ' +
'phpdbg_set.c phpdbg_frame.c phpdbg_watch.c phpdbg_win.c phpdbg_btree.c '+
'phpdbg_parser.c phpdbg_lexer.c phpdbg_sigsafe.c phpdbg_io.c phpdbg_out.c';
PHPDBG_DLL='php' + PHP_VERSION + 'phpdbg.dll';
Expand Down
4 changes: 0 additions & 4 deletions sapi/phpdbg/phpdbg.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ Override .phpgdbinit location (implies -I)
.B \-I
Ignore .phpdbginit (default init file)
.TP
.B \-O \fIfile\fR
Set oplog output to
.IR file
.TP
.B \-r
Jump straight to run
.TP
Expand Down
30 changes: 0 additions & 30 deletions sapi/phpdbg/phpdbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ static inline void php_phpdbg_globals_ctor(zend_phpdbg_globals *pg) /* {{{ */
pg->in_execution = 0;
pg->bp_count = 0;
pg->flags = PHPDBG_DEFAULT_FLAGS;
pg->oplog = NULL;
memset(pg->io, 0, sizeof(pg->io));
pg->frame.num = 0;
pg->sapi_name_ptr = NULL;
Expand Down Expand Up @@ -199,11 +198,6 @@ static PHP_MSHUTDOWN_FUNCTION(phpdbg) /* {{{ */
PHPDBG_G(exec) = NULL;
}

if (PHPDBG_G(oplog)) {
fclose(PHPDBG_G(oplog));
PHPDBG_G(oplog) = NULL;
}

if (PHPDBG_G(oplog_list)) {
phpdbg_oplog_list *cur = PHPDBG_G(oplog_list);
do {
Expand Down Expand Up @@ -1134,8 +1128,6 @@ int main(int argc, char **argv) /* {{{ */
char *init_file;
size_t init_file_len;
bool init_file_default;
char *oplog_file;
size_t oplog_file_len;
uint64_t flags;
char *php_optarg;
int php_optind, opt, show_banner = 1;
Expand Down Expand Up @@ -1186,8 +1178,6 @@ int main(int argc, char **argv) /* {{{ */
init_file = NULL;
init_file_len = 0;
init_file_default = 1;
oplog_file = NULL;
oplog_file_len = 0;
flags = PHPDBG_DEFAULT_FLAGS;
is_exit = 0;
php_optarg = NULL;
Expand Down Expand Up @@ -1281,13 +1271,6 @@ int main(int argc, char **argv) /* {{{ */
}
} break;

case 'O': { /* set oplog output */
oplog_file_len = strlen(php_optarg);
if (oplog_file_len) {
oplog_file = strdup(php_optarg);
}
} break;

case 'v': /* set quietness off */
flags &= ~PHPDBG_IS_QUIET;
break;
Expand Down Expand Up @@ -1442,9 +1425,6 @@ int main(int argc, char **argv) /* {{{ */
if (exec) {
free(exec);
}
if (oplog_file) {
free(oplog_file);
}
if (init_file) {
free(init_file);
}
Expand Down Expand Up @@ -1534,15 +1514,6 @@ int main(int argc, char **argv) /* {{{ */
php_stream_stdio_ops.write = phpdbg_stdiop_write;
#endif

if (oplog_file) { /* open oplog */
PHPDBG_G(oplog) = fopen(oplog_file, "w+");
if (!PHPDBG_G(oplog)) {
phpdbg_error("Failed to open oplog %s", oplog_file);
}
free(oplog_file);
oplog_file = NULL;
}

{
zval *zv = zend_hash_str_find(php_stream_get_url_stream_wrappers_hash(), ZEND_STRL("php"));
php_stream_wrapper *tmp_wrapper = Z_PTR_P(zv);
Expand Down Expand Up @@ -1757,7 +1728,6 @@ int main(int argc, char **argv) /* {{{ */
settings->exec = zend_strndup(PHPDBG_G(exec), PHPDBG_G(exec_len));
settings->exec_len = PHPDBG_G(exec_len);
}
settings->oplog = PHPDBG_G(oplog);
settings->prompt[0] = PHPDBG_G(prompt)[0];
settings->prompt[1] = PHPDBG_G(prompt)[1];
memcpy(ZEND_VOIDP(settings->colors), PHPDBG_G(colors), sizeof(settings->colors));
Expand Down
30 changes: 17 additions & 13 deletions sapi/phpdbg/phpdbg.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,6 @@
#define PHPDBG_DEFAULT_PROMPT "prompt>"
/* }}} */

/* Hey, apple. One shouldn't define *functions* from the standard C library as macros. */
#ifdef memcpy
#define memcpy_tmp(...) memcpy(__VA_ARGS__)
#undef memcpy
#define memcpy(...) memcpy_tmp(__VA_ARGS__)
#endif

#if !defined(PHPDBG_WEBDATA_TRANSFER_H) && !defined(PHPDBG_WEBHELPER_H)

#ifdef ZTS
# define PHPDBG_G(v) ZEND_TSRMG(phpdbg_globals_id, zend_phpdbg_globals *, v)
#else
Expand All @@ -123,7 +114,6 @@
#include "phpdbg_btree.h"
#include "phpdbg_watch.h"
#include "phpdbg_bp.h"
#include "phpdbg_opcode.h"

int phpdbg_do_parse(phpdbg_param_t *stack, char *input);

Expand Down Expand Up @@ -223,6 +213,23 @@ int phpdbg_do_parse(phpdbg_param_t *stack, char *input);

void phpdbg_register_file_handles(void);

typedef struct _phpdbg_oplog_entry phpdbg_oplog_entry;
struct _phpdbg_oplog_entry {
phpdbg_oplog_entry *next;
zend_string *function_name;
zend_class_entry *scope;
zend_string *filename;
zend_op *opcodes;
zend_op *op;
};

typedef struct _phpdbg_oplog_list phpdbg_oplog_list;
struct _phpdbg_oplog_list {
phpdbg_oplog_list *prev;
phpdbg_oplog_entry start; /* Only "next" member used. */
};


/* {{{ structs */
ZEND_BEGIN_MODULE_GLOBALS(phpdbg)
HashTable bp[PHPDBG_BREAK_TABLES]; /* break points */
Expand Down Expand Up @@ -266,7 +273,6 @@ ZEND_BEGIN_MODULE_GLOBALS(phpdbg)
zend_op_array *(*compile_string)(zend_string *source_string, const char *filename);
HashTable file_sources;

FILE *oplog; /* opline log */
zend_arena *oplog_arena; /* arena for storing oplog */
phpdbg_oplog_list *oplog_list; /* list of oplog starts */
phpdbg_oplog_entry *oplog_cur; /* current oplog entry */
Expand Down Expand Up @@ -304,6 +310,4 @@ ZEND_BEGIN_MODULE_GLOBALS(phpdbg)
zend_ulong lines; /* max number of lines to display */
ZEND_END_MODULE_GLOBALS(phpdbg) /* }}} */

#endif

#endif /* PHPDBG_H */
1 change: 0 additions & 1 deletion sapi/phpdbg/phpdbg_bp.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "phpdbg.h"
#include "phpdbg_bp.h"
#include "phpdbg_utils.h"
#include "phpdbg_opcode.h"
#include "zend_globals.h"
#include "ext/standard/php_string.h"

Expand Down
1 change: 0 additions & 1 deletion sapi/phpdbg/phpdbg_break.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "phpdbg.h"
#include "phpdbg_print.h"
#include "phpdbg_utils.h"
#include "phpdbg_opcode.h"
#include "phpdbg_break.h"
#include "phpdbg_bp.h"
#include "phpdbg_prompt.h"
Expand Down
2 changes: 0 additions & 2 deletions sapi/phpdbg/phpdbg_help.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,6 @@ phpdbg_help_text_t phpdbg_help_text[] = {
" **-b** Disable colour" CR
" **-i** **-i**my.init Set .phpdbginit file" CR
" **-I** Ignore default .phpdbginit" CR
" **-O** **-O**my.oplog Sets oplog output file" CR
" **-r** Run execution context" CR
" **-rr** Run execution context and quit after execution (not respecting breakpoints)" CR
" **-e** Generate extended information for debugger/profiler" CR
Expand Down Expand Up @@ -872,7 +871,6 @@ phpdbg_help_text_t phpdbg_help_text[] = {
" **prompt** **p** set the prompt" CR
" **color** **c** set color <element> <color>" CR
" **colors** **C** set colors [<on|off>]" CR
" **oplog** **O** set oplog [output]" CR
" **break** **b** set break **id** <on|off>" CR
" **breaks** **B** set breaks [<on|off>]" CR
" **quiet** **q** set quiet [<on|off>]" CR
Expand Down
Loading