Skip to content

Commit 916164c

Browse files
committed
more on disassembler
1 parent 0488640 commit 916164c

File tree

1 file changed

+57
-14
lines changed

1 file changed

+57
-14
lines changed

phpdbg_prompt.c

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,22 +1029,21 @@ static inline char *phpdbg_decode_op(zend_op_array *ops, znode_op *op, zend_uint
10291029
{
10301030
char *decode = NULL;
10311031

1032-
switch (type) {
1032+
switch (type &~ EXT_TYPE_UNUSED) {
10331033
case IS_CV:
10341034
asprintf(&decode, "$%s", ops->vars[op->var].name);
10351035
break;
10361036

10371037
case IS_VAR:
10381038
case IS_TMP_VAR: {
1039-
zend_ulong id = 0;
1040-
if (zend_hash_index_find(vars, (zend_ulong) ops->vars - op->var, (void**) &id) != SUCCESS) {
1039+
zend_ulong id = 0, *pid = NULL;
1040+
if (zend_hash_index_find(vars, (zend_ulong) ops->vars - op->var, (void**) &pid) != SUCCESS) {
10411041
id = zend_hash_num_elements(vars);
10421042
zend_hash_index_update(
10431043
vars, (zend_ulong) ops->vars - op->var,
10441044
(void**) &id,
10451045
sizeof(zend_ulong), NULL);
1046-
}
1047-
1046+
} else id = *pid;
10481047
asprintf(&decode, "@%lu", id);
10491048
} break;
10501049

@@ -1061,22 +1060,66 @@ static inline char *phpdbg_decode_op(zend_op_array *ops, znode_op *op, zend_uint
10611060

10621061
char *phpdbg_decode_opline(zend_op_array *ops, zend_op *op, HashTable *vars TSRMLS_DC) /*{{{ */
10631062
{
1064-
char *decode[3];
1065-
1066-
decode[1] = phpdbg_decode_op(ops, &op->op1, op->op1_type, vars TSRMLS_CC);
1067-
decode[2] = phpdbg_decode_op(ops, &op->op2, op->op2_type, vars TSRMLS_CC);
1068-
1063+
char *decode[4] = {NULL, NULL, NULL, NULL};
1064+
10691065
switch (op->opcode) {
1070-
default: asprintf(
1071-
&decode[0], "%-20s %-20s",
1072-
decode[1], decode[2]
1073-
);
1066+
case ZEND_JMP:
1067+
#ifdef ZEND_GOTO
1068+
case ZEND_GOTO:
1069+
#endif
1070+
#ifdef ZEND_FAST_CALL
1071+
case ZEND_FAST_CALL:
1072+
#endif
1073+
asprintf(&decode[1], "#%lu", op->op1.jmp_addr - ops->opcodes);
1074+
goto format;
1075+
1076+
1077+
case ZEND_JMPZNZ:
1078+
decode[1] = phpdbg_decode_op(ops, &op->op1, op->op1_type, vars TSRMLS_CC);
1079+
asprintf(
1080+
&decode[2], "#%lu or #%lu", op->op2.opline_num, op->extended_value);
1081+
goto result;
1082+
1083+
case ZEND_JMPZ:
1084+
case ZEND_JMPNZ:
1085+
case ZEND_JMPZ_EX:
1086+
case ZEND_JMPNZ_EX:
1087+
1088+
#ifdef ZEND_JMP_SET
1089+
case ZEND_JMP_SET:
1090+
#endif
1091+
#ifdef ZEND_JMP_SET_VAR
1092+
case ZEND_JMP_SET_VAR:
1093+
#endif
1094+
decode[1] = phpdbg_decode_op(ops, &op->op1, op->op1_type, vars TSRMLS_CC);
1095+
asprintf(
1096+
&decode[2], "#%lu", op->op2.jmp_addr - ops->opcodes);
1097+
goto result;
1098+
1099+
case ZEND_RECV_INIT:
1100+
goto result;
1101+
1102+
default: {
1103+
decode[1] = phpdbg_decode_op(ops, &op->op1, op->op1_type, vars TSRMLS_CC);
1104+
decode[2] = phpdbg_decode_op(ops, &op->op2, op->op2_type, vars TSRMLS_CC);
1105+
result:
1106+
decode[3] = phpdbg_decode_op(ops, &op->result, op->result_type, vars TSRMLS_CC);
1107+
format:
1108+
asprintf(
1109+
&decode[0],
1110+
"%-20s %-20s %-20s",
1111+
decode[1] ? decode[1] : "",
1112+
decode[2] ? decode[2] : "",
1113+
decode[3] ? decode[3] : "");
1114+
}
10741115
}
10751116

10761117
if (decode[1])
10771118
free(decode[1]);
10781119
if (decode[2])
10791120
free(decode[2]);
1121+
if (decode[3])
1122+
free(decode[3]);
10801123

10811124
return decode[0];
10821125
} /* }}} */

0 commit comments

Comments
 (0)