Skip to content

Commit 8743afb

Browse files
committed
move opcode stuff to opcode.c
1 parent a13583d commit 8743afb

File tree

3 files changed

+113
-112
lines changed

3 files changed

+113
-112
lines changed

phpdbg_opcode.c

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,118 @@
2121
#include "zend_compile.h"
2222
#include "phpdbg_opcode.h"
2323

24+
static inline zend_uint phpdbg_decode_literal(zend_op_array *ops, zend_literal *literal TSRMLS_DC) /* {{{ */
25+
{
26+
zend_uint iter = 0;
27+
28+
while (iter < ops->last_literal) {
29+
if (literal == &ops->literals[iter]) {
30+
return iter;
31+
}
32+
iter++;
33+
}
34+
35+
return 0;
36+
} /* }}} */
37+
38+
static inline char *phpdbg_decode_op(zend_op_array *ops, znode_op *op, zend_uint type, HashTable *vars TSRMLS_DC) /* {{{ */
39+
{
40+
char *decode = NULL;
41+
42+
switch (type &~ EXT_TYPE_UNUSED) {
43+
case IS_CV:
44+
asprintf(&decode, "$%s", ops->vars[op->var].name);
45+
break;
46+
47+
case IS_VAR:
48+
case IS_TMP_VAR: {
49+
zend_ulong id = 0, *pid = NULL;
50+
if (zend_hash_index_find(vars, (zend_ulong) ops->vars - op->var, (void**) &pid) != SUCCESS) {
51+
id = zend_hash_num_elements(vars);
52+
zend_hash_index_update(
53+
vars, (zend_ulong) ops->vars - op->var,
54+
(void**) &id,
55+
sizeof(zend_ulong), NULL);
56+
} else id = *pid;
57+
asprintf(&decode, "@%lu", id);
58+
} break;
59+
60+
case IS_CONST:
61+
asprintf(&decode, "C%lu", phpdbg_decode_literal(ops, op->literal TSRMLS_CC));
62+
break;
63+
64+
case IS_UNUSED:
65+
asprintf(&decode, "<unused>");
66+
break;
67+
}
68+
return decode;
69+
} /* }}} */
70+
71+
char *phpdbg_decode_opline(zend_op_array *ops, zend_op *op, HashTable *vars TSRMLS_DC) /*{{{ */
72+
{
73+
char *decode[4] = {NULL, NULL, NULL, NULL};
74+
75+
switch (op->opcode) {
76+
case ZEND_JMP:
77+
#ifdef ZEND_GOTO
78+
case ZEND_GOTO:
79+
#endif
80+
#ifdef ZEND_FAST_CALL
81+
case ZEND_FAST_CALL:
82+
#endif
83+
asprintf(&decode[1], "#%lu", op->op1.jmp_addr - ops->opcodes);
84+
goto format;
85+
86+
case ZEND_JMPZNZ:
87+
decode[1] = phpdbg_decode_op(ops, &op->op1, op->op1_type, vars TSRMLS_CC);
88+
asprintf(
89+
&decode[2], "#%lu or #%lu", op->op2.opline_num, op->extended_value);
90+
goto result;
91+
92+
case ZEND_JMPZ:
93+
case ZEND_JMPNZ:
94+
case ZEND_JMPZ_EX:
95+
case ZEND_JMPNZ_EX:
96+
97+
#ifdef ZEND_JMP_SET
98+
case ZEND_JMP_SET:
99+
#endif
100+
#ifdef ZEND_JMP_SET_VAR
101+
case ZEND_JMP_SET_VAR:
102+
#endif
103+
decode[1] = phpdbg_decode_op(ops, &op->op1, op->op1_type, vars TSRMLS_CC);
104+
asprintf(
105+
&decode[2], "#%lu", op->op2.jmp_addr - ops->opcodes);
106+
goto result;
107+
108+
case ZEND_RECV_INIT:
109+
goto result;
110+
111+
default: {
112+
decode[1] = phpdbg_decode_op(ops, &op->op1, op->op1_type, vars TSRMLS_CC);
113+
decode[2] = phpdbg_decode_op(ops, &op->op2, op->op2_type, vars TSRMLS_CC);
114+
result:
115+
decode[3] = phpdbg_decode_op(ops, &op->result, op->result_type, vars TSRMLS_CC);
116+
format:
117+
asprintf(
118+
&decode[0],
119+
"%-20s %-20s %-20s",
120+
decode[1] ? decode[1] : "",
121+
decode[2] ? decode[2] : "",
122+
decode[3] ? decode[3] : "");
123+
}
124+
}
125+
126+
if (decode[1])
127+
free(decode[1]);
128+
if (decode[2])
129+
free(decode[2]);
130+
if (decode[3])
131+
free(decode[3]);
132+
133+
return decode[0];
134+
} /* }}} */
135+
24136
const char *phpdbg_decode_opcode(zend_uchar opcode) /* {{{ */
25137
{
26138
#define CASE(s) case s: return #s

phpdbg_opcode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@
2323
#include "zend_types.h"
2424

2525
const char *phpdbg_decode_opcode(zend_uchar);
26+
char *phpdbg_decode_opline(zend_op_array *ops, zend_op *op, HashTable *vars TSRMLS_DC);
2627

2728
#endif /* PHPDBG_OPCODE_H */

phpdbg_prompt.c

Lines changed: 0 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,118 +1025,6 @@ int phpdbg_interactive(TSRMLS_D) /* {{{ */
10251025
return ret;
10261026
} /* }}} */
10271027

1028-
static inline zend_uint phpdbg_decode_literal(zend_op_array *ops, zend_literal *literal TSRMLS_DC) /* {{{ */
1029-
{
1030-
zend_uint iter = 0;
1031-
1032-
while (iter < ops->last_literal) {
1033-
if (literal == &ops->literals[iter]) {
1034-
return iter;
1035-
}
1036-
iter++;
1037-
}
1038-
1039-
return 0;
1040-
} /* }}} */
1041-
1042-
static inline char *phpdbg_decode_op(zend_op_array *ops, znode_op *op, zend_uint type, HashTable *vars TSRMLS_DC) /* {{{ */
1043-
{
1044-
char *decode = NULL;
1045-
1046-
switch (type &~ EXT_TYPE_UNUSED) {
1047-
case IS_CV:
1048-
asprintf(&decode, "$%s", ops->vars[op->var].name);
1049-
break;
1050-
1051-
case IS_VAR:
1052-
case IS_TMP_VAR: {
1053-
zend_ulong id = 0, *pid = NULL;
1054-
if (zend_hash_index_find(vars, (zend_ulong) ops->vars - op->var, (void**) &pid) != SUCCESS) {
1055-
id = zend_hash_num_elements(vars);
1056-
zend_hash_index_update(
1057-
vars, (zend_ulong) ops->vars - op->var,
1058-
(void**) &id,
1059-
sizeof(zend_ulong), NULL);
1060-
} else id = *pid;
1061-
asprintf(&decode, "@%lu", id);
1062-
} break;
1063-
1064-
case IS_CONST:
1065-
asprintf(&decode, "C%lu", phpdbg_decode_literal(ops, op->literal TSRMLS_CC));
1066-
break;
1067-
1068-
case IS_UNUSED:
1069-
asprintf(&decode, "<unused>");
1070-
break;
1071-
}
1072-
return decode;
1073-
} /* }}} */
1074-
1075-
char *phpdbg_decode_opline(zend_op_array *ops, zend_op *op, HashTable *vars TSRMLS_DC) /*{{{ */
1076-
{
1077-
char *decode[4] = {NULL, NULL, NULL, NULL};
1078-
1079-
switch (op->opcode) {
1080-
case ZEND_JMP:
1081-
#ifdef ZEND_GOTO
1082-
case ZEND_GOTO:
1083-
#endif
1084-
#ifdef ZEND_FAST_CALL
1085-
case ZEND_FAST_CALL:
1086-
#endif
1087-
asprintf(&decode[1], "#%lu", op->op1.jmp_addr - ops->opcodes);
1088-
goto format;
1089-
1090-
case ZEND_JMPZNZ:
1091-
decode[1] = phpdbg_decode_op(ops, &op->op1, op->op1_type, vars TSRMLS_CC);
1092-
asprintf(
1093-
&decode[2], "#%lu or #%lu", op->op2.opline_num, op->extended_value);
1094-
goto result;
1095-
1096-
case ZEND_JMPZ:
1097-
case ZEND_JMPNZ:
1098-
case ZEND_JMPZ_EX:
1099-
case ZEND_JMPNZ_EX:
1100-
1101-
#ifdef ZEND_JMP_SET
1102-
case ZEND_JMP_SET:
1103-
#endif
1104-
#ifdef ZEND_JMP_SET_VAR
1105-
case ZEND_JMP_SET_VAR:
1106-
#endif
1107-
decode[1] = phpdbg_decode_op(ops, &op->op1, op->op1_type, vars TSRMLS_CC);
1108-
asprintf(
1109-
&decode[2], "#%lu", op->op2.jmp_addr - ops->opcodes);
1110-
goto result;
1111-
1112-
case ZEND_RECV_INIT:
1113-
goto result;
1114-
1115-
default: {
1116-
decode[1] = phpdbg_decode_op(ops, &op->op1, op->op1_type, vars TSRMLS_CC);
1117-
decode[2] = phpdbg_decode_op(ops, &op->op2, op->op2_type, vars TSRMLS_CC);
1118-
result:
1119-
decode[3] = phpdbg_decode_op(ops, &op->result, op->result_type, vars TSRMLS_CC);
1120-
format:
1121-
asprintf(
1122-
&decode[0],
1123-
"%-20s %-20s %-20s",
1124-
decode[1] ? decode[1] : "",
1125-
decode[2] ? decode[2] : "",
1126-
decode[3] ? decode[3] : "");
1127-
}
1128-
}
1129-
1130-
if (decode[1])
1131-
free(decode[1]);
1132-
if (decode[2])
1133-
free(decode[2]);
1134-
if (decode[3])
1135-
free(decode[3]);
1136-
1137-
return decode[0];
1138-
} /* }}} */
1139-
11401028
void phpdbg_print_opline_ex(zend_execute_data *execute_data, HashTable *vars, zend_bool ignore_flags TSRMLS_DC) /* {{{ */
11411029
{
11421030
/* force out a line while stepping so the user knows what is happening */

0 commit comments

Comments
 (0)