Skip to content

Commit 60fbd6d

Browse files
authored
replace phpdbg custom opcode dumper with O+ dump (#7227)
1 parent 52d3d0d commit 60fbd6d

23 files changed

+137
-475
lines changed

Zend/Optimizer/zend_dump.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,11 +716,15 @@ ZEND_API void zend_dump_op(const zend_op_array *op_array, const zend_basic_block
716716
}
717717
}
718718

719-
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)
719+
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)
720720
{
721721
int len = 0;
722722
const zend_ssa *ssa = NULL;
723723
zend_ssa_op *ssa_op = NULL;
724+
725+
if (dump_flags & ZEND_DUMP_LINE_NUMBERS) {
726+
fprintf(stderr, "L%04u ", opline->lineno);
727+
}
724728

725729
len = fprintf(stderr, "%04u", (uint32_t)(opline - op_array->opcodes));
726730
fprintf(stderr, "%*c", 5-len, ' ');

Zend/Optimizer/zend_dump.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@
2727
#define ZEND_DUMP_CFG (1<<2)
2828
#define ZEND_DUMP_SSA (1<<3)
2929
#define ZEND_DUMP_LIVE_RANGES (1<<4)
30+
#define ZEND_DUMP_LINE_NUMBERS (1<<5)
3031

3132
BEGIN_EXTERN_C()
3233

3334
ZEND_API void zend_dump_op_array(const zend_op_array *op_array, uint32_t dump_flags, const char *msg, const void *data);
3435
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);
36+
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);
3537
void zend_dump_dominators(const zend_op_array *op_array, const zend_cfg *cfg);
3638
void zend_dump_dfg(const zend_op_array *op_array, const zend_cfg *cfg, const zend_dfg *dfg);
3739
void zend_dump_phi_placement(const zend_op_array *op_array, const zend_ssa *ssa);

sapi/phpdbg/config.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ if test "$BUILD_PHPDBG" = "" && test "$PHP_PHPDBG" != "no"; then
3030
fi
3131

3232
PHP_PHPDBG_CFLAGS="-D_GNU_SOURCE -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1"
33-
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"
33+
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"
3434

3535
AC_MSG_CHECKING([for phpdbg and readline integration])
3636
if test "$PHP_PHPDBG_READLINE" = "yes"; then

sapi/phpdbg/config.w32

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ ARG_ENABLE('phpdbg', 'Build phpdbg', 'no');
22
ARG_ENABLE('phpdbgs', 'Build phpdbg shared', 'no');
33

44
PHPDBG_SOURCES='phpdbg.c phpdbg_prompt.c phpdbg_cmd.c phpdbg_info.c phpdbg_help.c phpdbg_break.c ' +
5-
'phpdbg_print.c phpdbg_bp.c phpdbg_opcode.c phpdbg_list.c phpdbg_utils.c ' +
5+
'phpdbg_print.c phpdbg_bp.c phpdbg_list.c phpdbg_utils.c ' +
66
'phpdbg_set.c phpdbg_frame.c phpdbg_watch.c phpdbg_win.c phpdbg_btree.c '+
77
'phpdbg_parser.c phpdbg_lexer.c phpdbg_sigsafe.c phpdbg_io.c phpdbg_out.c';
88
PHPDBG_DLL='php' + PHP_VERSION + 'phpdbg.dll';

sapi/phpdbg/phpdbg.1.in

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ Override .phpgdbinit location (implies -I)
4949
.B \-I
5050
Ignore .phpdbginit (default init file)
5151
.TP
52-
.B \-O \fIfile\fR
53-
Set oplog output to
54-
.IR file
55-
.TP
5652
.B \-r
5753
Jump straight to run
5854
.TP

sapi/phpdbg/phpdbg.c

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ static inline void php_phpdbg_globals_ctor(zend_phpdbg_globals *pg) /* {{{ */
122122
pg->in_execution = 0;
123123
pg->bp_count = 0;
124124
pg->flags = PHPDBG_DEFAULT_FLAGS;
125-
pg->oplog = NULL;
126125
memset(pg->io, 0, sizeof(pg->io));
127126
pg->frame.num = 0;
128127
pg->sapi_name_ptr = NULL;
@@ -199,11 +198,6 @@ static PHP_MSHUTDOWN_FUNCTION(phpdbg) /* {{{ */
199198
PHPDBG_G(exec) = NULL;
200199
}
201200

202-
if (PHPDBG_G(oplog)) {
203-
fclose(PHPDBG_G(oplog));
204-
PHPDBG_G(oplog) = NULL;
205-
}
206-
207201
if (PHPDBG_G(oplog_list)) {
208202
phpdbg_oplog_list *cur = PHPDBG_G(oplog_list);
209203
do {
@@ -1134,8 +1128,6 @@ int main(int argc, char **argv) /* {{{ */
11341128
char *init_file;
11351129
size_t init_file_len;
11361130
bool init_file_default;
1137-
char *oplog_file;
1138-
size_t oplog_file_len;
11391131
uint64_t flags;
11401132
char *php_optarg;
11411133
int php_optind, opt, show_banner = 1;
@@ -1186,8 +1178,6 @@ int main(int argc, char **argv) /* {{{ */
11861178
init_file = NULL;
11871179
init_file_len = 0;
11881180
init_file_default = 1;
1189-
oplog_file = NULL;
1190-
oplog_file_len = 0;
11911181
flags = PHPDBG_DEFAULT_FLAGS;
11921182
is_exit = 0;
11931183
php_optarg = NULL;
@@ -1281,13 +1271,6 @@ int main(int argc, char **argv) /* {{{ */
12811271
}
12821272
} break;
12831273

1284-
case 'O': { /* set oplog output */
1285-
oplog_file_len = strlen(php_optarg);
1286-
if (oplog_file_len) {
1287-
oplog_file = strdup(php_optarg);
1288-
}
1289-
} break;
1290-
12911274
case 'v': /* set quietness off */
12921275
flags &= ~PHPDBG_IS_QUIET;
12931276
break;
@@ -1442,9 +1425,6 @@ int main(int argc, char **argv) /* {{{ */
14421425
if (exec) {
14431426
free(exec);
14441427
}
1445-
if (oplog_file) {
1446-
free(oplog_file);
1447-
}
14481428
if (init_file) {
14491429
free(init_file);
14501430
}
@@ -1534,15 +1514,6 @@ int main(int argc, char **argv) /* {{{ */
15341514
php_stream_stdio_ops.write = phpdbg_stdiop_write;
15351515
#endif
15361516

1537-
if (oplog_file) { /* open oplog */
1538-
PHPDBG_G(oplog) = fopen(oplog_file, "w+");
1539-
if (!PHPDBG_G(oplog)) {
1540-
phpdbg_error("Failed to open oplog %s", oplog_file);
1541-
}
1542-
free(oplog_file);
1543-
oplog_file = NULL;
1544-
}
1545-
15461517
{
15471518
zval *zv = zend_hash_str_find(php_stream_get_url_stream_wrappers_hash(), ZEND_STRL("php"));
15481519
php_stream_wrapper *tmp_wrapper = Z_PTR_P(zv);
@@ -1757,7 +1728,6 @@ int main(int argc, char **argv) /* {{{ */
17571728
settings->exec = zend_strndup(PHPDBG_G(exec), PHPDBG_G(exec_len));
17581729
settings->exec_len = PHPDBG_G(exec_len);
17591730
}
1760-
settings->oplog = PHPDBG_G(oplog);
17611731
settings->prompt[0] = PHPDBG_G(prompt)[0];
17621732
settings->prompt[1] = PHPDBG_G(prompt)[1];
17631733
memcpy(ZEND_VOIDP(settings->colors), PHPDBG_G(colors), sizeof(settings->colors));

sapi/phpdbg/phpdbg.h

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,6 @@
100100
#define PHPDBG_DEFAULT_PROMPT "prompt>"
101101
/* }}} */
102102

103-
/* Hey, apple. One shouldn't define *functions* from the standard C library as macros. */
104-
#ifdef memcpy
105-
#define memcpy_tmp(...) memcpy(__VA_ARGS__)
106-
#undef memcpy
107-
#define memcpy(...) memcpy_tmp(__VA_ARGS__)
108-
#endif
109-
110-
#if !defined(PHPDBG_WEBDATA_TRANSFER_H) && !defined(PHPDBG_WEBHELPER_H)
111-
112103
#ifdef ZTS
113104
# define PHPDBG_G(v) ZEND_TSRMG(phpdbg_globals_id, zend_phpdbg_globals *, v)
114105
#else
@@ -123,7 +114,6 @@
123114
#include "phpdbg_btree.h"
124115
#include "phpdbg_watch.h"
125116
#include "phpdbg_bp.h"
126-
#include "phpdbg_opcode.h"
127117

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

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

224214
void phpdbg_register_file_handles(void);
225215

216+
typedef struct _phpdbg_oplog_entry phpdbg_oplog_entry;
217+
struct _phpdbg_oplog_entry {
218+
phpdbg_oplog_entry *next;
219+
zend_string *function_name;
220+
zend_class_entry *scope;
221+
zend_string *filename;
222+
zend_op *opcodes;
223+
zend_op *op;
224+
};
225+
226+
typedef struct _phpdbg_oplog_list phpdbg_oplog_list;
227+
struct _phpdbg_oplog_list {
228+
phpdbg_oplog_list *prev;
229+
phpdbg_oplog_entry start; /* Only "next" member used. */
230+
};
231+
232+
226233
/* {{{ structs */
227234
ZEND_BEGIN_MODULE_GLOBALS(phpdbg)
228235
HashTable bp[PHPDBG_BREAK_TABLES]; /* break points */
@@ -266,7 +273,6 @@ ZEND_BEGIN_MODULE_GLOBALS(phpdbg)
266273
zend_op_array *(*compile_string)(zend_string *source_string, const char *filename);
267274
HashTable file_sources;
268275

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

307-
#endif
308-
309313
#endif /* PHPDBG_H */

sapi/phpdbg/phpdbg_bp.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "phpdbg.h"
2222
#include "phpdbg_bp.h"
2323
#include "phpdbg_utils.h"
24-
#include "phpdbg_opcode.h"
2524
#include "zend_globals.h"
2625
#include "ext/standard/php_string.h"
2726

sapi/phpdbg/phpdbg_break.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "phpdbg.h"
2020
#include "phpdbg_print.h"
2121
#include "phpdbg_utils.h"
22-
#include "phpdbg_opcode.h"
2322
#include "phpdbg_break.h"
2423
#include "phpdbg_bp.h"
2524
#include "phpdbg_prompt.h"

sapi/phpdbg/phpdbg_help.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,6 @@ phpdbg_help_text_t phpdbg_help_text[] = {
391391
" **-b** Disable colour" CR
392392
" **-i** **-i**my.init Set .phpdbginit file" CR
393393
" **-I** Ignore default .phpdbginit" CR
394-
" **-O** **-O**my.oplog Sets oplog output file" CR
395394
" **-r** Run execution context" CR
396395
" **-rr** Run execution context and quit after execution (not respecting breakpoints)" CR
397396
" **-e** Generate extended information for debugger/profiler" CR
@@ -872,7 +871,6 @@ phpdbg_help_text_t phpdbg_help_text[] = {
872871
" **prompt** **p** set the prompt" CR
873872
" **color** **c** set color <element> <color>" CR
874873
" **colors** **C** set colors [<on|off>]" CR
875-
" **oplog** **O** set oplog [output]" CR
876874
" **break** **b** set break **id** <on|off>" CR
877875
" **breaks** **B** set breaks [<on|off>]" CR
878876
" **quiet** **q** set quiet [<on|off>]" CR

0 commit comments

Comments
 (0)